Tidy up more parts of the service/ directory

pull/540/head
Michael 5 years ago
parent 385dfe68bd
commit 98e691f315
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -221,19 +221,18 @@ set(LIB_SRC
service/endpoint.cpp service/endpoint.cpp
service/handler.cpp service/handler.cpp
service/hidden_service_address_lookup.cpp service/hidden_service_address_lookup.cpp
service/Identity.cpp service/identity.cpp
service/info.cpp service/info.cpp
service/Intro.cpp service/intro_set.cpp
service/IntroSet.cpp service/intro.cpp
service/lookup.cpp service/lookup.cpp
service/outbound_context.cpp service/outbound_context.cpp
service/pendingbuffer.cpp service/pendingbuffer.cpp
service/protocol.cpp service/protocol.cpp
service/sendcontext.cpp service/sendcontext.cpp
service/session.cpp service/session.cpp
service/tag.cpp
service/tag_lookup_job.cpp service/tag_lookup_job.cpp
service/types.cpp service/tag.cpp
service/vanity.cpp service/vanity.cpp
utp/inbound_message.cpp utp/inbound_message.cpp
utp/linklayer.cpp utp/linklayer.cpp

@ -10,7 +10,7 @@
#include <dht/tx.hpp> #include <dht/tx.hpp>
#include <dht/txholder.hpp> #include <dht/txholder.hpp>
#include <dht/txowner.hpp> #include <dht/txowner.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <util/time.hpp> #include <util/time.hpp>
#include <util/status.hpp> #include <util/status.hpp>

@ -2,7 +2,7 @@
#define LLARP_DHT_MESSAGES_GOT_INTRO_HPP #define LLARP_DHT_MESSAGES_GOT_INTRO_HPP
#include <dht/message.hpp> #include <dht/message.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <vector> #include <vector>

@ -1,7 +1,7 @@
#ifndef LLARP_DHT_MESSAGES_PUB_INTRO_HPP #ifndef LLARP_DHT_MESSAGES_PUB_INTRO_HPP
#define LLARP_DHT_MESSAGES_PUB_INTRO_HPP #define LLARP_DHT_MESSAGES_PUB_INTRO_HPP
#include <dht/message.hpp> #include <dht/message.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <vector> #include <vector>

@ -3,7 +3,7 @@
#include <dht/key.hpp> #include <dht/key.hpp>
#include <router_contact.hpp> #include <router_contact.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
namespace llarp namespace llarp
{ {

@ -4,7 +4,7 @@
#include <dht/tx.hpp> #include <dht/tx.hpp>
#include <dht/txowner.hpp> #include <dht/txowner.hpp>
#include <service/address.hpp> #include <service/address.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <set> #include <set>

@ -4,7 +4,7 @@
#include <dht/key.hpp> #include <dht/key.hpp>
#include <dht/tx.hpp> #include <dht/tx.hpp>
#include <service/address.hpp> #include <service/address.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
namespace llarp namespace llarp
{ {

@ -2,7 +2,7 @@
#define LLARP_DHT_TAGLOOKUP #define LLARP_DHT_TAGLOOKUP
#include <dht/tx.hpp> #include <dht/tx.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <service/tag.hpp> #include <service/tag.hpp>
namespace llarp namespace llarp

@ -10,7 +10,7 @@
#include <router_id.hpp> #include <router_id.hpp>
#include <routing/handler.hpp> #include <routing/handler.hpp>
#include <routing/message.hpp> #include <routing/message.hpp>
#include <service/Intro.hpp> #include <service/intro.hpp>
#include <util/aligned.hpp> #include <util/aligned.hpp>
#include <util/threading.hpp> #include <util/threading.hpp>
#include <util/time.hpp> #include <util/time.hpp>

@ -4,7 +4,7 @@
#include <path/path_types.hpp> #include <path/path_types.hpp>
#include <router_id.hpp> #include <router_id.hpp>
#include <routing/message.hpp> #include <routing/message.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <service/lookup.hpp> #include <service/lookup.hpp>
#include <util/status.hpp> #include <util/status.hpp>
#include <util/threading.hpp> #include <util/threading.hpp>

@ -1,4 +1,4 @@
#include <service/Identity.hpp> #include <service/identity.hpp>
#include <util/fs.hpp> #include <util/fs.hpp>
@ -57,12 +57,11 @@ namespace llarp
} }
void void
Identity::RegenerateKeys(llarp::Crypto* crypto) Identity::RegenerateKeys(Crypto* crypto)
{ {
crypto->encryption_keygen(enckey); crypto->encryption_keygen(enckey);
crypto->identity_keygen(signkey); crypto->identity_keygen(signkey);
pub.Update(llarp::seckey_topublic(enckey), pub.Update(seckey_topublic(enckey), seckey_topublic(signkey));
llarp::seckey_topublic(signkey));
crypto->pqe_keygen(pq); crypto->pqe_keygen(pq);
} }
@ -81,7 +80,7 @@ namespace llarp
} }
bool bool
Identity::EnsureKeys(const std::string& fname, llarp::Crypto* c) Identity::EnsureKeys(const std::string& fname, Crypto* c)
{ {
std::array< byte_t, 4096 > tmp; std::array< byte_t, 4096 > tmp;
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
@ -91,7 +90,7 @@ namespace llarp
{ {
if(ec) if(ec)
{ {
llarp::LogError(ec); LogError(ec);
return false; return false;
} }
// regen and encode // regen and encode
@ -125,14 +124,12 @@ namespace llarp
if(!vanity.IsZero()) if(!vanity.IsZero())
van = vanity; van = vanity;
// update pubkeys // update pubkeys
pub.Update(llarp::seckey_topublic(enckey), pub.Update(seckey_topublic(enckey), seckey_topublic(signkey), van);
llarp::seckey_topublic(signkey), van);
return true; return true;
} }
bool bool
Identity::SignIntroSet(IntroSet& i, llarp::Crypto* crypto, Identity::SignIntroSet(IntroSet& i, Crypto* crypto, llarp_time_t now) const
llarp_time_t now) const
{ {
if(i.I.size() == 0) if(i.I.size() == 0)
return false; return false;

@ -2,9 +2,9 @@
#define LLARP_SERVICE_IDENTITY_HPP #define LLARP_SERVICE_IDENTITY_HPP
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <service/Info.hpp> #include <service/info.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <service/types.hpp> #include <service/vanity.hpp>
#include <util/bencode.hpp> #include <util/bencode.hpp>
namespace llarp namespace llarp
@ -14,11 +14,11 @@ namespace llarp
namespace service namespace service
{ {
// private keys // private keys
struct Identity final : public llarp::IBEncodeMessage struct Identity final : public IBEncodeMessage
{ {
llarp::SecretKey enckey; SecretKey enckey;
llarp::SecretKey signkey; SecretKey signkey;
llarp::PQKeyPair pq; PQKeyPair pq;
uint64_t version = 0; uint64_t version = 0;
VanityNonce vanity; VanityNonce vanity;
@ -29,7 +29,7 @@ namespace llarp
// regenerate secret keys // regenerate secret keys
void void
RegenerateKeys(llarp::Crypto* c); RegenerateKeys(Crypto* c);
// load from file // load from file
bool bool
@ -39,20 +39,20 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override; BEncode(llarp_buffer_t* buf) const override;
bool bool
EnsureKeys(const std::string& fpath, llarp::Crypto* c); EnsureKeys(const std::string& fpath, Crypto* c);
bool bool
KeyExchange(llarp::path_dh_func dh, SharedSecret& sharedkey, KeyExchange(path_dh_func dh, SharedSecret& sharedkey,
const ServiceInfo& other, const KeyExchangeNonce& N) const; const ServiceInfo& other, const KeyExchangeNonce& N) const;
bool bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override; DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool bool
SignIntroSet(IntroSet& i, llarp::Crypto* c, llarp_time_t now) const; SignIntroSet(IntroSet& i, Crypto* c, llarp_time_t now) const;
bool bool
Sign(llarp::Crypto*, Signature& sig, const llarp_buffer_t& buf) const; Sign(Crypto*, Signature& sig, const llarp_buffer_t& buf) const;
}; };
} // namespace service } // namespace service
} // namespace llarp } // namespace llarp

@ -2,7 +2,8 @@
#define LLARP_SERVICE_INFO_HPP #define LLARP_SERVICE_INFO_HPP
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <service/types.hpp> #include <service/address.hpp>
#include <service/vanity.hpp>
#include <util/bencode.hpp> #include <util/bencode.hpp>
#include <absl/types/optional.h> #include <absl/types/optional.h>
@ -13,11 +14,11 @@ namespace llarp
namespace service namespace service
{ {
struct ServiceInfo final : public llarp::IBEncodeMessage struct ServiceInfo final : public IBEncodeMessage
{ {
private: private:
llarp::PubKey enckey; PubKey enckey;
llarp::PubKey signkey; PubKey signkey;
public: public:
VanityNonce vanity; VanityNonce vanity;
@ -52,7 +53,7 @@ namespace llarp
} }
bool bool
Verify(llarp::Crypto* crypto, const llarp_buffer_t& payload, Verify(Crypto* crypto, const llarp_buffer_t& payload,
const Signature& sig) const; const Signature& sig) const;
const PubKey& const PubKey&

@ -1,4 +1,4 @@
#include <service/Intro.hpp> #include <service/intro.hpp>
namespace llarp namespace llarp
{ {

@ -2,7 +2,7 @@
#define LLARP_SERVICE_ASYNC_KEY_EXCHANGE_HPP #define LLARP_SERVICE_ASYNC_KEY_EXCHANGE_HPP
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <service/Identity.hpp> #include <service/identity.hpp>
#include <service/protocol.hpp> #include <service/protocol.hpp>
namespace llarp namespace llarp

@ -9,12 +9,12 @@ namespace llarp
bool bool
Config::Load(const std::string& fname) Config::Load(const std::string& fname)
{ {
llarp::ConfigParser parser; ConfigParser parser;
if(!parser.LoadFile(fname.c_str())) if(!parser.LoadFile(fname.c_str()))
return false; return false;
parser.IterAll([&](const llarp::ConfigParser::String_t& name, parser.IterAll([&](const ConfigParser::String_t& name,
const llarp::ConfigParser::Section_t& section) { const ConfigParser::Section_t& section) {
llarp::service::Config::section_t values; Config::section_t values;
values.first.assign(name.begin(), name.end()); values.first.assign(name.begin(), name.end());
for(const auto& item : section) for(const auto& item : section)
values.second.emplace_back(string_view_string(item.first), values.second.emplace_back(string_view_string(item.first),

@ -118,12 +118,12 @@ namespace llarp
return m_Endpoints.size() ? true : false; return m_Endpoints.size() ? true : false;
} }
llarp::service::Endpoint * service::Endpoint *
Context::getFirstEndpoint() Context::getFirstEndpoint()
{ {
if(!m_Endpoints.size()) if(!m_Endpoints.size())
{ {
llarp::LogError("No endpoints found"); LogError("No endpoints found");
return nullptr; return nullptr;
} }
auto itr = m_Endpoints.begin(); auto itr = m_Endpoints.begin();
@ -137,11 +137,11 @@ namespace llarp
{ {
if(!m_Endpoints.size()) if(!m_Endpoints.size())
{ {
llarp::LogError("No endpoints found"); LogError("No endpoints found");
return false; return false;
} }
i.index = 0; i.index = 0;
// llarp::util::Lock lock(access); // util::Lock lock(access);
auto itr = m_Endpoints.begin(); auto itr = m_Endpoints.begin();
while(itr != m_Endpoints.end()) while(itr != m_Endpoints.end())
{ {
@ -155,34 +155,34 @@ namespace llarp
return true; return true;
} }
llarp::handlers::TunEndpoint * handlers::TunEndpoint *
Context::getFirstTun() Context::getFirstTun()
{ {
llarp::service::Endpoint *endpointer = this->getFirstEndpoint(); service::Endpoint *endpointer = this->getFirstEndpoint();
if(!endpointer) if(!endpointer)
{ {
return nullptr; return nullptr;
} }
llarp::handlers::TunEndpoint *tunEndpoint = handlers::TunEndpoint *tunEndpoint =
static_cast< llarp::handlers::TunEndpoint * >(endpointer); static_cast< handlers::TunEndpoint * >(endpointer);
return tunEndpoint; return tunEndpoint;
} }
llarp_tun_io * llarp_tun_io *
Context::getRange() Context::getRange()
{ {
llarp::handlers::TunEndpoint *tunEndpoint = this->getFirstTun(); handlers::TunEndpoint *tunEndpoint = this->getFirstTun();
if(!tunEndpoint) if(!tunEndpoint)
{ {
llarp::LogError("No tunnel endpoint found"); LogError("No tunnel endpoint found");
return nullptr; return nullptr;
} }
return &tunEndpoint->tunif; return &tunEndpoint->tunif;
} }
bool bool
Context::FindBestAddressFor(const llarp::AlignedBuffer< 32 > &addr, Context::FindBestAddressFor(const AlignedBuffer< 32 > &addr, bool isSNode,
bool isSNode, huint32_t &ip) huint32_t &ip)
{ {
auto itr = m_Endpoints.begin(); auto itr = m_Endpoints.begin();
while(itr != m_Endpoints.end()) while(itr != m_Endpoints.end())
@ -204,12 +204,12 @@ namespace llarp
} }
bool bool
Context::Prefetch(const llarp::service::Address &addr) Context::Prefetch(const service::Address &addr)
{ {
llarp::handlers::TunEndpoint *tunEndpoint = this->getFirstTun(); handlers::TunEndpoint *tunEndpoint = this->getFirstTun();
if(!tunEndpoint) if(!tunEndpoint)
{ {
llarp::LogError("No tunnel endpoint found"); LogError("No tunnel endpoint found");
return false; return false;
} }
// HiddenServiceAddresslookup *lookup = new // HiddenServiceAddresslookup *lookup = new
@ -227,11 +227,11 @@ namespace llarp
{ {
Context::mapAddressAll_context *context = Context::mapAddressAll_context *context =
(Context::mapAddressAll_context *)endpointCfg->user; (Context::mapAddressAll_context *)endpointCfg->user;
llarp::handlers::TunEndpoint *tunEndpoint = handlers::TunEndpoint *tunEndpoint =
(llarp::handlers::TunEndpoint *)endpointCfg->endpoint; (handlers::TunEndpoint *)endpointCfg->endpoint;
if(!tunEndpoint) if(!tunEndpoint)
{ {
llarp::LogError("No tunnel endpoint found"); LogError("No tunnel endpoint found");
return true; // still continue return true; // still continue
} }
return tunEndpoint->MapAddress( return tunEndpoint->MapAddress(
@ -239,8 +239,8 @@ namespace llarp
} }
bool bool
Context::MapAddressAll(const llarp::service::Address &addr, Context::MapAddressAll(const service::Address &addr,
llarp::Addr &localPrivateIpAddr) Addr &localPrivateIpAddr)
{ {
struct Context::mapAddressAll_context context; struct Context::mapAddressAll_context context;
context.serviceAddr = addr; context.serviceAddr = addr;
@ -278,10 +278,10 @@ namespace llarp
{ {
if(!itr->second->Start()) if(!itr->second->Start())
{ {
llarp::LogError(itr->first, " failed to start"); LogError(itr->first, " failed to start");
return false; return false;
} }
llarp::LogInfo(itr->first, " started"); LogInfo(itr->first, " started");
++itr; ++itr;
} }
return true; return true;
@ -294,8 +294,8 @@ namespace llarp
auto itr = m_Endpoints.find(conf.first); auto itr = m_Endpoints.find(conf.first);
if(itr != m_Endpoints.end()) if(itr != m_Endpoints.end())
{ {
llarp::LogError("cannot add hidden service with duplicate name: ", LogError("cannot add hidden service with duplicate name: ",
conf.first); conf.first);
return false; return false;
} }
} }
@ -319,8 +319,7 @@ namespace llarp
endpointConstructors = { endpointConstructors = {
{"tun", {"tun",
[](const std::string &nick, AbstractRouter *r, [](const std::string &nick, AbstractRouter *r,
llarp::service::Context *c) service::Context *c) -> std::unique_ptr< service::Endpoint > {
-> std::unique_ptr< service::Endpoint > {
return std::make_unique< handlers::TunEndpoint >(nick, r, c); return std::make_unique< handlers::TunEndpoint >(nick, r, c);
}}, }},
{"null", {"null",
@ -334,7 +333,7 @@ namespace llarp
auto itr = endpointConstructors.find(endpointType); auto itr = endpointConstructors.find(endpointType);
if(itr == endpointConstructors.end()) if(itr == endpointConstructors.end())
{ {
llarp::LogError("no such endpoint type: ", endpointType); LogError("no such endpoint type: ", endpointType);
return false; return false;
} }
@ -348,7 +347,7 @@ namespace llarp
service->SetOption("keyfile", keyfile); service->SetOption("keyfile", keyfile);
// load keyfile, so we have the correct name for logging // load keyfile, so we have the correct name for logging
} }
llarp::LogInfo("Establishing endpoint identity"); LogInfo("Establishing endpoint identity");
service->LoadKeyFile(); // only start endpoint not tun service->LoadKeyFile(); // only start endpoint not tun
// now Name() will be correct // now Name() will be correct
} }
@ -361,8 +360,8 @@ namespace llarp
auto &v = option.second; auto &v = option.second;
if(!service->SetOption(k, v)) if(!service->SetOption(k, v))
{ {
llarp::LogError("failed to set ", k, "=", v, LogError("failed to set ", k, "=", v, " for hidden service endpoint ",
" for hidden service endpoint ", conf.first); conf.first);
return false; return false;
} }
} }
@ -371,17 +370,16 @@ namespace llarp
// start // start
if(service->Start()) if(service->Start())
{ {
llarp::LogInfo("autostarting hidden service endpoint ", LogInfo("autostarting hidden service endpoint ", service->Name());
service->Name());
m_Endpoints.emplace(conf.first, std::move(service)); m_Endpoints.emplace(conf.first, std::move(service));
return true; return true;
} }
llarp::LogError("failed to start hidden service endpoint ", conf.first); LogError("failed to start hidden service endpoint ", conf.first);
return false; return false;
} }
else else
{ {
llarp::LogInfo("added hidden service endpoint ", service->Name()); LogInfo("added hidden service endpoint ", service->Name());
m_Endpoints.emplace(conf.first, std::move(service)); m_Endpoints.emplace(conf.first, std::move(service));
return true; return true;
} }

@ -15,7 +15,7 @@ namespace llarp
/// holds all the hidden service endpoints we own /// holds all the hidden service endpoints we own
struct Context struct Context
{ {
Context(AbstractRouter *r); explicit Context(AbstractRouter *r);
~Context(); ~Context();
void void
@ -32,15 +32,15 @@ namespace llarp
hasEndpoints(); hasEndpoints();
/// DRY refactor /// DRY refactor
llarp::service::Endpoint * service::Endpoint *
getFirstEndpoint(); getFirstEndpoint();
bool bool
FindBestAddressFor(const llarp::AlignedBuffer< 32 > &addr, bool isSNode, FindBestAddressFor(const AlignedBuffer< 32 > &addr, bool isSNode,
huint32_t &); huint32_t &);
/// DRY refactor /// DRY refactor
llarp::handlers::TunEndpoint * handlers::TunEndpoint *
getFirstTun(); getFirstTun();
/// punch a hole to get ip range from first tun endpoint /// punch a hole to get ip range from first tun endpoint
@ -49,14 +49,14 @@ namespace llarp
struct mapAddressAll_context struct mapAddressAll_context
{ {
llarp::service::Address serviceAddr; service::Address serviceAddr;
llarp::Addr localPrivateIpAddr; Addr localPrivateIpAddr;
}; };
struct endpoint_iter struct endpoint_iter
{ {
void *user; void *user;
llarp::service::Endpoint *endpoint; service::Endpoint *endpoint;
size_t index; size_t index;
bool (*visit)(struct endpoint_iter *); bool (*visit)(struct endpoint_iter *);
}; };
@ -72,11 +72,10 @@ namespace llarp
/// hint at possible path usage and trigger building early /// hint at possible path usage and trigger building early
bool bool
Prefetch(const llarp::service::Address &addr); Prefetch(const service::Address &addr);
bool bool
MapAddressAll(const llarp::service::Address &addr, MapAddressAll(const service::Address &addr, Addr &localPrivateIpAddr);
llarp::Addr &localPrivateIpAddr);
/// add default endpoint with options /// add default endpoint with options
bool bool

@ -8,7 +8,7 @@
#include <path/pathbuilder.hpp> #include <path/pathbuilder.hpp>
#include <service/address.hpp> #include <service/address.hpp>
#include <service/handler.hpp> #include <service/handler.hpp>
#include <service/Identity.hpp> #include <service/identity.hpp>
#include <service/pendingbuffer.hpp> #include <service/pendingbuffer.hpp>
#include <service/protocol.hpp> #include <service/protocol.hpp>
#include <service/sendcontext.hpp> #include <service/sendcontext.hpp>

@ -3,14 +3,14 @@
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <path/path_types.hpp> #include <path/path_types.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <util/aligned.hpp> #include <util/aligned.hpp>
namespace llarp namespace llarp
{ {
namespace service namespace service
{ {
using ConvoTag = llarp::AlignedBuffer< 16 >; using ConvoTag = AlignedBuffer< 16 >;
struct ProtocolMessage; struct ProtocolMessage;
struct IDataHandler struct IDataHandler

@ -2,7 +2,7 @@
#define LLARP_SERVICE_HIDDEN_SERVICE_ADDRESS_LOOKUP_HPP #define LLARP_SERVICE_HIDDEN_SERVICE_ADDRESS_LOOKUP_HPP
#include <messages/dht.hpp> #include <messages/dht.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <service/lookup.hpp> #include <service/lookup.hpp>
namespace llarp namespace llarp

@ -1,4 +1,4 @@
#include <service/Info.hpp> #include <service/info.hpp>
#include <crypto/crypto.hpp> #include <crypto/crypto.hpp>
#include <service/address.hpp> #include <service/address.hpp>
@ -13,7 +13,7 @@ namespace llarp
namespace service namespace service
{ {
bool bool
ServiceInfo::Verify(llarp::Crypto* crypto, const llarp_buffer_t& payload, ServiceInfo::Verify(Crypto* crypto, const llarp_buffer_t& payload,
const Signature& sig) const const Signature& sig) const
{ {
return crypto->verify(signkey, payload, sig); return crypto->verify(signkey, payload, sig);

@ -1,4 +1,4 @@
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <path/path.hpp> #include <path/path.hpp>
@ -114,7 +114,7 @@ namespace llarp
} }
bool bool
IntroSet::Verify(llarp::Crypto* crypto, llarp_time_t now) const IntroSet::Verify(Crypto* crypto, llarp_time_t now) const
{ {
std::array< byte_t, MAX_INTROSET_SIZE > tmp; std::array< byte_t, MAX_INTROSET_SIZE > tmp;
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
@ -153,14 +153,14 @@ namespace llarp
} }
else if(W == nullptr) else if(W == nullptr)
{ {
llarp::LogWarn("intro has too high expire time"); LogWarn("intro has too high expire time");
return false; return false;
} }
} }
} }
if(IsExpired(now)) if(IsExpired(now))
{ {
llarp::LogWarn("introset expired: ", *this); LogWarn("introset expired: ", *this);
return false; return false;
} }
return true; return true;

@ -1,10 +1,10 @@
#ifndef LLARP_SERVICE_INTROSET_HPP #ifndef LLARP_SERVICE_INTRO_SET_HPP
#define LLARP_SERVICE_INTROSET_HPP #define LLARP_SERVICE_INTRO_SET_HPP
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <pow.hpp> #include <pow.hpp>
#include <service/Info.hpp> #include <service/info.hpp>
#include <service/Intro.hpp> #include <service/intro.hpp>
#include <service/tag.hpp> #include <service/tag.hpp>
#include <util/bencode.hpp> #include <util/bencode.hpp>
#include <util/time.hpp> #include <util/time.hpp>

@ -2,7 +2,7 @@
#define LLARP_SERVICE_LOOKUP_HPP #define LLARP_SERVICE_LOOKUP_HPP
#include <routing/message.hpp> #include <routing/message.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <set> #include <set>
@ -48,7 +48,7 @@ namespace llarp
/// build a new request message and send it via a path /// build a new request message and send it via a path
bool bool
SendRequestViaPath(llarp::path::Path* p, AbstractRouter* r); SendRequestViaPath(path::Path* p, AbstractRouter* r);
ILookupHolder* parent; ILookupHolder* parent;
uint64_t txid; uint64_t txid;
@ -58,7 +58,7 @@ namespace llarp
util::StatusObject util::StatusObject
ExtractStatus() const ExtractStatus() const
{ {
auto now = llarp::time_now_ms(); auto now = time_now_ms();
util::StatusObject obj{{"txid", txid}, util::StatusObject obj{{"txid", txid},
{"endpoint", endpoint.ToHex()}, {"endpoint", endpoint.ToHex()},
{"name", name}, {"name", name},

@ -81,7 +81,7 @@ namespace llarp
bool bool
SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur, SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur,
size_t hop, llarp::path::PathRole roles) override; size_t hop, path::PathRole roles) override;
bool bool
HandleHiddenServiceFrame(path::Path* p, const ProtocolFrame& frame); HandleHiddenServiceFrame(path::Path* p, const ProtocolFrame& frame);

@ -34,7 +34,7 @@ namespace llarp
{ {
ProtocolMessage* self = static_cast< ProtocolMessage* >(user); ProtocolMessage* self = static_cast< ProtocolMessage* >(user);
if(!self->handler->HandleDataMessage(self->srcPath, self)) if(!self->handler->HandleDataMessage(self->srcPath, self))
llarp::LogWarn("failed to handle data message from ", self->srcPath); LogWarn("failed to handle data message from ", self->srcPath);
delete self; delete self;
} }
@ -170,7 +170,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::DecryptPayloadInto(llarp::Crypto* crypto, ProtocolFrame::DecryptPayloadInto(Crypto* crypto,
const SharedSecret& sharedkey, const SharedSecret& sharedkey,
ProtocolMessage& msg) const ProtocolMessage& msg) const
{ {
@ -181,7 +181,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::Sign(llarp::Crypto* crypto, const Identity& localIdent) ProtocolFrame::Sign(Crypto* crypto, const Identity& localIdent)
{ {
Z.Zero(); Z.Zero();
std::array< byte_t, MAX_PROTOCOL_MESSAGE_SIZE > tmp; std::array< byte_t, MAX_PROTOCOL_MESSAGE_SIZE > tmp;
@ -189,7 +189,7 @@ namespace llarp
// encode // encode
if(!BEncode(&buf)) if(!BEncode(&buf))
{ {
llarp::LogError("message too big to encode"); LogError("message too big to encode");
return false; return false;
} }
// rewind // rewind
@ -200,8 +200,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::EncryptAndSign(llarp::Crypto* crypto, ProtocolFrame::EncryptAndSign(Crypto* crypto, const ProtocolMessage& msg,
const ProtocolMessage& msg,
const SharedSecret& sessionKey, const SharedSecret& sessionKey,
const Identity& localIdent) const Identity& localIdent)
{ {
@ -210,7 +209,7 @@ namespace llarp
// encode message // encode message
if(!msg.BEncode(&buf)) if(!msg.BEncode(&buf))
{ {
llarp::LogError("message too big to encode"); LogError("message too big to encode");
return false; return false;
} }
// rewind // rewind
@ -226,8 +225,8 @@ namespace llarp
// encode frame // encode frame
if(!BEncode(&buf2)) if(!BEncode(&buf2))
{ {
llarp::LogError("frame too big to encode"); LogError("frame too big to encode");
llarp::DumpBuffer(buf2); DumpBuffer(buf2);
return false; return false;
} }
// rewind // rewind
@ -236,7 +235,7 @@ namespace llarp
// sign // sign
if(!localIdent.Sign(crypto, Z, buf2)) if(!localIdent.Sign(crypto, Z, buf2))
{ {
llarp::LogError("failed to sign? wtf?!"); LogError("failed to sign? wtf?!");
return false; return false;
} }
return true; return true;
@ -244,18 +243,17 @@ namespace llarp
struct AsyncFrameDecrypt struct AsyncFrameDecrypt
{ {
llarp::Crypto* crypto; Crypto* crypto;
llarp::Logic* logic; Logic* logic;
ProtocolMessage* msg; ProtocolMessage* msg;
const Identity& m_LocalIdentity; const Identity& m_LocalIdentity;
IDataHandler* handler; IDataHandler* handler;
const ProtocolFrame frame; const ProtocolFrame frame;
const Introduction fromIntro; const Introduction fromIntro;
AsyncFrameDecrypt(llarp::Logic* l, llarp::Crypto* c, AsyncFrameDecrypt(Logic* l, Crypto* c, const Identity& localIdent,
const Identity& localIdent, IDataHandler* h, IDataHandler* h, ProtocolMessage* m,
ProtocolMessage* m, const ProtocolFrame& f, const ProtocolFrame& f, const Introduction& recvIntro)
const Introduction& recvIntro)
: crypto(c) : crypto(c)
, logic(l) , logic(l)
, msg(m) , msg(m)
@ -278,7 +276,7 @@ namespace llarp
if(!crypto->pqe_decrypt(self->frame.C, K, if(!crypto->pqe_decrypt(self->frame.C, K,
pq_keypair_to_secret(self->m_LocalIdentity.pq))) pq_keypair_to_secret(self->m_LocalIdentity.pq)))
{ {
llarp::LogError("pqke failed C=", self->frame.C); LogError("pqke failed C=", self->frame.C);
delete self->msg; delete self->msg;
delete self; delete self;
return; return;
@ -288,8 +286,8 @@ namespace llarp
crypto->xchacha20(*buf, K, self->frame.N); crypto->xchacha20(*buf, K, self->frame.N);
if(!self->msg->BDecode(buf)) if(!self->msg->BDecode(buf))
{ {
llarp::LogError("failed to decode inner protocol message"); LogError("failed to decode inner protocol message");
llarp::DumpBuffer(*buf); DumpBuffer(*buf);
delete self->msg; delete self->msg;
delete self; delete self;
return; return;
@ -297,8 +295,8 @@ namespace llarp
// verify signature of outer message after we parsed the inner message // verify signature of outer message after we parsed the inner message
if(!self->frame.Verify(crypto, self->msg->sender)) if(!self->frame.Verify(crypto, self->msg->sender))
{ {
llarp::LogError("intro frame has invalid signature Z=", self->frame.Z, LogError("intro frame has invalid signature Z=", self->frame.Z,
" from ", self->msg->sender.Addr()); " from ", self->msg->sender.Addr());
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >(); self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
self->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >(); self->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
delete self->msg; delete self->msg;
@ -308,7 +306,7 @@ namespace llarp
if(self->handler->HasConvoTag(self->msg->tag)) if(self->handler->HasConvoTag(self->msg->tag))
{ {
llarp::LogError("dropping duplicate convo tag T=", self->msg->tag); LogError("dropping duplicate convo tag T=", self->msg->tag);
// TODO: send convotag reset // TODO: send convotag reset
delete self->msg; delete self->msg;
delete self; delete self;
@ -324,7 +322,7 @@ namespace llarp
if(!self->m_LocalIdentity.KeyExchange(dh_server, sharedSecret, if(!self->m_LocalIdentity.KeyExchange(dh_server, sharedSecret,
self->msg->sender, self->frame.N)) self->msg->sender, self->frame.N))
{ {
llarp::LogError("x25519 key exchange failed"); LogError("x25519 key exchange failed");
self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >(); self->frame.Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
delete self->msg; delete self->msg;
delete self; delete self;
@ -364,7 +362,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::AsyncDecryptAndVerify(llarp::Logic* logic, llarp::Crypto* c, ProtocolFrame::AsyncDecryptAndVerify(Logic* logic, Crypto* c,
path::Path* recvPath, path::Path* recvPath,
llarp_threadpool* worker, llarp_threadpool* worker,
const Identity& localIdent, const Identity& localIdent,
@ -372,7 +370,7 @@ namespace llarp
{ {
if(T.IsZero()) if(T.IsZero())
{ {
llarp::LogInfo("Got protocol frame with new convo"); LogInfo("Got protocol frame with new convo");
ProtocolMessage* msg = new ProtocolMessage(); ProtocolMessage* msg = new ProtocolMessage();
msg->srcPath = recvPath->RXID(); msg->srcPath = recvPath->RXID();
// we need to dh // we need to dh
@ -384,24 +382,24 @@ namespace llarp
SharedSecret shared; SharedSecret shared;
if(!handler->GetCachedSessionKeyFor(T, shared)) if(!handler->GetCachedSessionKeyFor(T, shared))
{ {
llarp::LogError("No cached session for T=", T); LogError("No cached session for T=", T);
return false; return false;
} }
ServiceInfo si; ServiceInfo si;
if(!handler->GetSenderFor(T, si)) if(!handler->GetSenderFor(T, si))
{ {
llarp::LogError("No sender for T=", T); LogError("No sender for T=", T);
return false; return false;
} }
if(!Verify(c, si)) if(!Verify(c, si))
{ {
llarp::LogError("Signature failure from ", si.Addr()); LogError("Signature failure from ", si.Addr());
return false; return false;
} }
ProtocolMessage* msg = new ProtocolMessage(); ProtocolMessage* msg = new ProtocolMessage();
if(!DecryptPayloadInto(c, shared, *msg)) if(!DecryptPayloadInto(c, shared, *msg))
{ {
llarp::LogError("failed to decrypt message"); LogError("failed to decrypt message");
delete msg; delete msg;
return false; return false;
} }
@ -419,7 +417,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::Verify(llarp::Crypto* crypto, const ServiceInfo& from) const ProtocolFrame::Verify(Crypto* crypto, const ServiceInfo& from) const
{ {
ProtocolFrame copy(*this); ProtocolFrame copy(*this);
// save signature // save signature
@ -430,7 +428,7 @@ namespace llarp
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
if(!copy.BEncode(&buf)) if(!copy.BEncode(&buf))
{ {
llarp::LogError("bencode fail"); LogError("bencode fail");
return false; return false;
} }
@ -442,7 +440,7 @@ namespace llarp
} }
bool bool
ProtocolFrame::HandleMessage(llarp::routing::IMessageHandler* h, ProtocolFrame::HandleMessage(routing::IMessageHandler* h,
ABSL_ATTRIBUTE_UNUSED AbstractRouter* r) const ABSL_ATTRIBUTE_UNUSED AbstractRouter* r) const
{ {
return h->HandleHiddenServiceFrame(*this); return h->HandleHiddenServiceFrame(*this);

@ -5,9 +5,9 @@
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <dht/message.hpp> #include <dht/message.hpp>
#include <routing/message.hpp> #include <routing/message.hpp>
#include <service/Identity.hpp> #include <service/identity.hpp>
#include <service/Info.hpp> #include <service/info.hpp>
#include <service/Intro.hpp> #include <service/intro.hpp>
#include <service/handler.hpp> #include <service/handler.hpp>
#include <util/bencode.hpp> #include <util/bencode.hpp>
#include <util/time.hpp> #include <util/time.hpp>

@ -30,18 +30,17 @@ namespace llarp
const routing::PathTransferMessage transfer(msg, remoteIntro.pathID); const routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(path->SendRoutingMessage(transfer, m_Endpoint->Router())) if(path->SendRoutingMessage(transfer, m_Endpoint->Router()))
{ {
llarp::LogInfo("sent intro to ", remoteIntro.pathID, " on ", LogInfo("sent intro to ", remoteIntro.pathID, " on ",
remoteIntro.router, " seqno=", sequenceNo); remoteIntro.router, " seqno=", sequenceNo);
lastGoodSend = m_Endpoint->Now(); lastGoodSend = m_Endpoint->Now();
++sequenceNo; ++sequenceNo;
return true; return true;
} }
else else
llarp::LogError("Failed to send frame on path"); LogError("Failed to send frame on path");
} }
else else
llarp::LogError("cannot send because we have no path to ", LogError("cannot send because we have no path to ", remoteIntro.router);
remoteIntro.router);
return false; return false;
} }
@ -63,14 +62,13 @@ namespace llarp
// shift intro // shift intro
if(MarkCurrentIntroBad(now)) if(MarkCurrentIntroBad(now))
{ {
llarp::LogInfo("intro shifted"); LogInfo("intro shifted");
} }
} }
auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router); auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
if(!path) if(!path)
{ {
llarp::LogError("cannot encrypt and send: no path for intro ", LogError("cannot encrypt and send: no path for intro ", remoteIntro);
remoteIntro);
return; return;
} }
@ -87,13 +85,13 @@ namespace llarp
m.PutBuffer(payload); m.PutBuffer(payload);
if(!f.EncryptAndSign(crypto, m, shared, m_Endpoint->GetIdentity())) if(!f.EncryptAndSign(crypto, m, shared, m_Endpoint->GetIdentity()))
{ {
llarp::LogError("failed to sign"); LogError("failed to sign");
return; return;
} }
} }
else else
{ {
llarp::LogError("No cached session key"); LogError("No cached session key");
return; return;
} }
@ -101,14 +99,14 @@ namespace llarp
msg.Y.Randomize(); msg.Y.Randomize();
if(path->SendRoutingMessage(msg, m_Endpoint->Router())) if(path->SendRoutingMessage(msg, m_Endpoint->Router()))
{ {
llarp::LogDebug("sent message via ", remoteIntro.pathID, " on ", LogDebug("sent message via ", remoteIntro.pathID, " on ",
remoteIntro.router); remoteIntro.router);
++sequenceNo; ++sequenceNo;
lastGoodSend = now; lastGoodSend = now;
} }
else else
{ {
llarp::LogWarn("Failed to send routing message for data"); LogWarn("Failed to send routing message for data");
} }
} }
@ -121,7 +119,7 @@ namespace llarp
{ {
if(!MarkCurrentIntroBad(now)) if(!MarkCurrentIntroBad(now))
{ {
llarp::LogWarn("no good path yet, your message may drop"); LogWarn("no good path yet, your message may drop");
} }
} }
if(sequenceNo) if(sequenceNo)

@ -2,7 +2,7 @@
#define LLARP_SERVICE_SENDCONTEXT_HPP #define LLARP_SERVICE_SENDCONTEXT_HPP
#include <path/pathset.hpp> #include <path/pathset.hpp>
#include <service/Intro.hpp> #include <service/intro.hpp>
#include <service/protocol.hpp> #include <service/protocol.hpp>
#include <util/buffer.hpp> #include <util/buffer.hpp>
#include <util/types.hpp> #include <util/types.hpp>

@ -3,8 +3,8 @@
#include <crypto/types.hpp> #include <crypto/types.hpp>
#include <path/path.hpp> #include <path/path.hpp>
#include <service/Info.hpp> #include <service/info.hpp>
#include <service/Intro.hpp> #include <service/intro.hpp>
#include <util/status.hpp> #include <util/status.hpp>
#include <util/types.hpp> #include <util/types.hpp>

@ -15,13 +15,13 @@ namespace llarp
{ {
namespace service namespace service
{ {
struct Tag : public llarp::AlignedBuffer< 16 > struct Tag : public AlignedBuffer< 16 >
{ {
Tag() : llarp::AlignedBuffer< SIZE >() Tag() : AlignedBuffer< SIZE >()
{ {
} }
Tag(const byte_t* d) : llarp::AlignedBuffer< SIZE >(d) Tag(const byte_t* d) : AlignedBuffer< SIZE >(d)
{ {
} }

@ -2,7 +2,7 @@
#define LLARP_SERVICE_TAG_LOOKUP_JOB_HPP #define LLARP_SERVICE_TAG_LOOKUP_JOB_HPP
#include <routing/message.hpp> #include <routing/message.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <service/lookup.hpp> #include <service/lookup.hpp>
#include <service/tag.hpp> #include <service/tag.hpp>
#include <util/types.hpp> #include <util/types.hpp>

@ -1 +0,0 @@
#include <service/types.hpp>

@ -1,6 +0,0 @@
#ifndef LLARP_SERVICE_TYPES_HPP
#define LLARP_SERVICE_TYPES_HPP
#include <service/address.hpp>
#include <service/vanity.hpp>
#endif

@ -10,7 +10,7 @@ namespace llarp
{ {
/// hidden service address /// hidden service address
using VanityNonce = llarp::AlignedBuffer< 16 >; using VanityNonce = AlignedBuffer< 16 >;
} // namespace service } // namespace service
} // namespace llarp } // namespace llarp
#endif #endif

@ -3,7 +3,7 @@
#include <crypto/mock_crypto.hpp> #include <crypto/mock_crypto.hpp>
#include <dht/mock_context.hpp> #include <dht/mock_context.hpp>
#include <dht/messages/gotintro.hpp> #include <dht/messages/gotintro.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <test_util.hpp> #include <test_util.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>

@ -3,7 +3,7 @@
#include <crypto/mock_crypto.hpp> #include <crypto/mock_crypto.hpp>
#include <dht/mock_context.hpp> #include <dht/mock_context.hpp>
#include <dht/messages/gotintro.hpp> #include <dht/messages/gotintro.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <test_util.hpp> #include <test_util.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>

@ -2,8 +2,8 @@
#include <crypto/crypto_libsodium.hpp> #include <crypto/crypto_libsodium.hpp>
#include <path/path.hpp> #include <path/path.hpp>
#include <service/address.hpp> #include <service/address.hpp>
#include <service/Identity.hpp> #include <service/identity.hpp>
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <util/time.hpp> #include <util/time.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>

Loading…
Cancel
Save