Merge remote-tracking branch 'origin/master'

pull/576/head
Jeff Becker 5 years ago
commit a2912ff860
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -8,7 +8,9 @@ project(${PROJECT_NAME} C CXX)
option(USE_AVX2 "enable avx2 code" ) option(USE_AVX2 "enable avx2 code" )
option(USE_NETNS "enable networking namespace support. Linux only" ) option(USE_NETNS "enable networking namespace support. Linux only" )
option(AMD_RYZEN_HACK "hack for AMD Ryzen FPU bug (support FMA3 and FMA4 in FPU, but does not show in CPUID)" ) option(AMD_RYZEN_HACK "hack for AMD Ryzen FPU bug (support FMA3 and FMA4 in FPU, but does not show in CPUID)" )
if (NOT MSVC)
option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads") option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads")
endif()
option(NON_PC_TARGET "non-pc target build: iphone, andriod, embedded non-i386 SBC, etc" ) option(NON_PC_TARGET "non-pc target build: iphone, andriod, embedded non-i386 SBC, etc" )
option(SHADOW "use shadow testing framework. linux only" ) option(SHADOW "use shadow testing framework. linux only" )
option(ASAN "use address sanitiser, if your system has it" ) option(ASAN "use address sanitiser, if your system has it" )
@ -76,8 +78,10 @@ if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW)
endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW) endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW)
if (WIN32 AND NOT STATIC_LINK_RUNTIME) if (WIN32 AND NOT STATIC_LINK_RUNTIME)
message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll") if(NOT MSVC)
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options") message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll")
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options")
endif()
endif(WIN32 AND NOT STATIC_LINK_RUNTIME) endif(WIN32 AND NOT STATIC_LINK_RUNTIME)
add_subdirectory(vendor/cxxopts) add_subdirectory(vendor/cxxopts)

@ -186,7 +186,7 @@ main(int argc, char *argv[])
// does this file exist? // does this file exist?
if(genconfigOnly) if(genconfigOnly)
{ {
if(!llarp_ensure_config(conffname.c_str(), basedir.c_str(), overWrite, if(!llarp_ensure_config(conffname.c_str(), basedir.string().c_str(), overWrite,
asRouter)) asRouter))
return 1; return 1;
} }

@ -222,19 +222,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

@ -135,7 +135,7 @@ namespace llarp
/// relay a dht message from a local path to the main network /// relay a dht message from a local path to the main network
bool bool
RelayRequestForPath(const llarp::PathID_t& localPath, RelayRequestForPath(const llarp::PathID_t& localPath,
const IMessage* msg) override; const IMessage& msg) override;
/// send introset to peer from source with S counter and excluding peers /// send introset to peer from source with S counter and excluding peers
void void
@ -540,15 +540,15 @@ namespace llarp
} }
bool bool
Context::RelayRequestForPath(const llarp::PathID_t& id, const IMessage* msg) Context::RelayRequestForPath(const llarp::PathID_t& id, const IMessage& msg)
{ {
llarp::routing::DHTMessage reply; llarp::routing::DHTMessage reply;
if(!msg->HandleMessage(router->dht(), reply.M)) if(!msg.HandleMessage(router->dht(), reply.M))
return false; return false;
if(!reply.M.empty()) if(!reply.M.empty())
{ {
auto path = router->pathContext().GetByUpstream(router->pubkey(), id); auto path = router->pathContext().GetByUpstream(router->pubkey(), id);
return path && path->SendRoutingMessage(&reply, router); return path && path->SendRoutingMessage(reply, router);
} }
return true; return true;
} }

@ -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>
@ -107,7 +107,7 @@ namespace llarp
std::vector< std::unique_ptr< IMessage > >& replies) = 0; std::vector< std::unique_ptr< IMessage > >& replies) = 0;
virtual bool virtual bool
RelayRequestForPath(const PathID_t& localPath, const IMessage* msg) = 0; RelayRequestForPath(const PathID_t& localPath, const IMessage& msg) = 0;
/// send introset to peer from source with S counter and excluding peers /// send introset to peer from source with S counter and excluding peers
virtual void virtual void

@ -47,7 +47,7 @@ namespace llarp
routing::DHTMessage msg; routing::DHTMessage msg;
msg.M.emplace_back(new GotRouterMessage(parent->OurKey(), whoasked.txid, msg.M.emplace_back(new GotRouterMessage(parent->OurKey(), whoasked.txid,
valuesFound, true)); valuesFound, true));
if(!path->SendRoutingMessage(&msg, parent->GetRouter())) if(!path->SendRoutingMessage(msg, parent->GetRouter()))
{ {
llarp::LogWarn( llarp::LogWarn(
"failed to send routing message when informing result of dht " "failed to send routing message when informing result of dht "

@ -47,7 +47,7 @@ namespace llarp
} }
routing::DHTMessage msg; routing::DHTMessage msg;
msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid)); msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid));
if(!path->SendRoutingMessage(&msg, parent->GetRouter())) if(!path->SendRoutingMessage(msg, parent->GetRouter()))
{ {
llarp::LogWarn( llarp::LogWarn(
"failed to send routing message when informing result of dht " "failed to send routing message when informing result of dht "

@ -33,7 +33,7 @@ namespace llarp
} }
routing::DHTMessage msg; routing::DHTMessage msg;
msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid)); msg.M.emplace_back(new GotIntroMessage(valuesFound, whoasked.txid));
if(!path->SendRoutingMessage(&msg, parent->GetRouter())) if(!path->SendRoutingMessage(msg, parent->GetRouter()))
{ {
llarp::LogWarn( llarp::LogWarn(
"failed to send routing message when informing result of dht " "failed to send routing message when informing result of dht "

@ -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
{ {

@ -35,6 +35,7 @@ namespace llarp
{ {
std::set< service::IntroSet > found(valuesFound.begin(), std::set< service::IntroSet > found(valuesFound.begin(),
valuesFound.end()); valuesFound.end());
// collect our local values if we haven't hit a limit // collect our local values if we haven't hit a limit
if(found.size() < 2) if(found.size() < 2)
{ {

@ -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

@ -79,7 +79,7 @@ namespace llarp
bool bool
CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
{ {
return h->HandleCloseExitMessage(this, r); return h->HandleCloseExitMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -176,7 +176,7 @@ namespace llarp
{ {
auto& msg = queue.front(); auto& msg = queue.front();
msg.S = path->NextSeqNo(); msg.S = path->NextSeqNo();
if(path->SendRoutingMessage(&msg, m_Parent->GetRouter())) if(path->SendRoutingMessage(msg, m_Parent->GetRouter()))
{ {
m_RxRate += msg.Size(); m_RxRate += msg.Size();
sent = true; sent = true;

@ -85,7 +85,7 @@ namespace llarp
bool bool
GrantExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const GrantExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
{ {
return h->HandleGrantExitMessage(this, r); return h->HandleGrantExitMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -96,7 +96,7 @@ namespace llarp
ObtainExitMessage::HandleMessage(IMessageHandler* h, ObtainExitMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandleObtainExitMessage(this, r); return h->HandleObtainExitMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -96,7 +96,7 @@ namespace llarp
RejectExitMessage::HandleMessage(IMessageHandler* h, RejectExitMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandleRejectExitMessage(this, r); return h->HandleRejectExitMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -107,7 +107,7 @@ namespace llarp
llarp::LogError("Failed to sign exit request"); llarp::LogError("Failed to sign exit request");
return; return;
} }
if(p->SendExitRequest(&obtain, router)) if(p->SendExitRequest(obtain, router))
llarp::LogInfo("asking ", m_ExitRouter, " for exit"); llarp::LogInfo("asking ", m_ExitRouter, " for exit");
else else
llarp::LogError("failed to send exit request"); llarp::LogError("failed to send exit request");
@ -156,7 +156,7 @@ namespace llarp
llarp::LogInfo(p->Name(), " closing exit path"); llarp::LogInfo(p->Name(), " closing exit path");
llarp::routing::CloseExitMessage msg; llarp::routing::CloseExitMessage msg;
if(!(msg.Sign(router->crypto(), m_ExitIdentity) if(!(msg.Sign(router->crypto(), m_ExitIdentity)
&& p->SendExitClose(&msg, router))) && p->SendExitClose(msg, router)))
llarp::LogWarn(p->Name(), " failed to send exit close message"); llarp::LogWarn(p->Name(), " failed to send exit close message");
} }
}; };
@ -244,7 +244,7 @@ namespace llarp
{ {
auto& msg = queue.front(); auto& msg = queue.front();
msg.S = path->NextSeqNo(); msg.S = path->NextSeqNo();
if(path->SendRoutingMessage(&msg, router)) if(path->SendRoutingMessage(msg, router))
m_LastUse = now; m_LastUse = now;
queue.pop_front(); queue.pop_front();
} }

@ -66,7 +66,7 @@ namespace llarp
TransferTrafficMessage::HandleMessage(IMessageHandler* h, TransferTrafficMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandleTransferTrafficMessage(this, r); return h->HandleTransferTrafficMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -87,7 +87,7 @@ namespace llarp
UpdateExitMessage::HandleMessage(IMessageHandler* h, UpdateExitMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandleUpdateExitMessage(this, r); return h->HandleUpdateExitMessage(*this, r);
} }
bool bool
@ -124,7 +124,7 @@ namespace llarp
UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h, UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandleUpdateExitVerifyMessage(this, r); return h->HandleUpdateExitVerifyMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -75,7 +75,7 @@ namespace llarp
bool bool
HandleMessage(IMessageHandler* h, AbstractRouter* r) const override HandleMessage(IMessageHandler* h, AbstractRouter* r) const override
{ {
return h->HandleDataDiscardMessage(this, r); return h->HandleDataDiscardMessage(*this, r);
} }
bool bool

@ -275,7 +275,7 @@ namespace llarp
self->context->PutTransitHop(self->hop); self->context->PutTransitHop(self->hop);
// send path confirmation // send path confirmation
llarp::routing::PathConfirmMessage confirm(self->hop->lifetime); llarp::routing::PathConfirmMessage confirm(self->hop->lifetime);
if(!self->hop->SendRoutingMessage(&confirm, self->context->Router())) if(!self->hop->SendRoutingMessage(confirm, self->context->Router()))
{ {
llarp::LogError("failed to send path confirmation for ", llarp::LogError("failed to send path confirmation for ",
self->hop->info); self->hop->info);

@ -174,7 +174,7 @@ namespace llarp
{ {
auto own = MapGet( auto own = MapGet(
m_OurPaths, id, m_OurPaths, id,
[](__attribute__((unused)) const PathSet* s) -> bool { [](ABSL_ATTRIBUTE_UNUSED const PathSet* s) -> bool {
// TODO: is this right? // TODO: is this right?
return true; return true;
}, },
@ -574,7 +574,7 @@ namespace llarp
latency.T = randint(); latency.T = randint();
m_LastLatencyTestID = latency.T; m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = now; m_LastLatencyTestTime = now;
SendRoutingMessage(&latency, r); SendRoutingMessage(latency, r);
return; return;
} }
if(m_LastRecvMessage && now > m_LastRecvMessage) if(m_LastRecvMessage && now > m_LastRecvMessage)
@ -667,15 +667,15 @@ namespace llarp
bool bool
Path::HandleUpdateExitVerifyMessage( Path::HandleUpdateExitVerifyMessage(
const routing::UpdateExitVerifyMessage* msg, AbstractRouter* r) const routing::UpdateExitVerifyMessage& msg, AbstractRouter* r)
{ {
(void)r; (void)r;
if(m_UpdateExitTX && msg->T == m_UpdateExitTX) if(m_UpdateExitTX && msg.T == m_UpdateExitTX)
{ {
if(m_ExitUpdated) if(m_ExitUpdated)
return m_ExitUpdated(this); return m_ExitUpdated(this);
} }
if(m_CloseExitTX && msg->T == m_CloseExitTX) if(m_CloseExitTX && msg.T == m_CloseExitTX)
{ {
if(m_ExitClosed) if(m_ExitClosed)
return m_ExitClosed(this); return m_ExitClosed(this);
@ -684,15 +684,15 @@ namespace llarp
} }
bool bool
Path::SendRoutingMessage(const routing::IMessage* msg, AbstractRouter* r) Path::SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r)
{ {
std::array< byte_t, MAX_LINK_MSG_SIZE / 2 > tmp; std::array< byte_t, MAX_LINK_MSG_SIZE / 2 > tmp;
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
// should help prevent bad paths with uninitialized members // should help prevent bad paths with uninitialized members
// FIXME: Why would we get uninitialized IMessages? // FIXME: Why would we get uninitialized IMessages?
if(msg->version != LLARP_PROTO_VERSION) if(msg.version != LLARP_PROTO_VERSION)
return false; return false;
if(!msg->BEncode(&buf)) if(!msg.BEncode(&buf))
{ {
LogError("Bencode failed"); LogError("Bencode failed");
DumpBuffer(buf); DumpBuffer(buf);
@ -714,9 +714,9 @@ namespace llarp
} }
bool bool
Path::HandlePathTransferMessage(__attribute__((unused)) Path::HandlePathTransferMessage(
const routing::PathTransferMessage* msg, ABSL_ATTRIBUTE_UNUSED const routing::PathTransferMessage& msg,
__attribute__((unused)) AbstractRouter* r) ABSL_ATTRIBUTE_UNUSED AbstractRouter* r)
{ {
LogWarn("unwarranted path transfer message on tx=", TXID(), LogWarn("unwarranted path transfer message on tx=", TXID(),
" rx=", RXID()); " rx=", RXID());
@ -724,19 +724,19 @@ namespace llarp
} }
bool bool
Path::HandleDataDiscardMessage(const routing::DataDiscardMessage* msg, Path::HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
MarkActive(r->Now()); MarkActive(r->Now());
if(m_DropHandler) if(m_DropHandler)
return m_DropHandler(this, msg->P, msg->S); return m_DropHandler(this, msg.P, msg.S);
return true; return true;
} }
bool bool
Path::HandlePathConfirmMessage(__attribute__((unused)) Path::HandlePathConfirmMessage(
const routing::PathConfirmMessage* msg, ABSL_ATTRIBUTE_UNUSED const routing::PathConfirmMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
auto now = r->Now(); auto now = r->Now();
if(_status == ePathBuilding) if(_status == ePathBuilding)
@ -754,7 +754,7 @@ namespace llarp
latency.T = randint(); latency.T = randint();
m_LastLatencyTestID = latency.T; m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = now; m_LastLatencyTestTime = now;
return SendRoutingMessage(&latency, r); return SendRoutingMessage(latency, r);
} }
LogWarn("got unwarranted path confirm message on tx=", RXID(), LogWarn("got unwarranted path confirm message on tx=", RXID(),
" rx=", RXID()); " rx=", RXID());
@ -762,19 +762,19 @@ namespace llarp
} }
bool bool
Path::HandleHiddenServiceFrame(const service::ProtocolFrame* frame) Path::HandleHiddenServiceFrame(const service::ProtocolFrame& frame)
{ {
MarkActive(m_PathSet->Now()); MarkActive(m_PathSet->Now());
return m_DataHandler && m_DataHandler(this, frame); return m_DataHandler && m_DataHandler(this, frame);
} }
bool bool
Path::HandlePathLatencyMessage(const routing::PathLatencyMessage* msg, Path::HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
auto now = r->Now(); auto now = r->Now();
MarkActive(now); MarkActive(now);
if(msg->L == m_LastLatencyTestID) if(msg.L == m_LastLatencyTestID)
{ {
intro.latency = now - m_LastLatencyTestTime; intro.latency = now - m_LastLatencyTestTime;
m_LastLatencyTestID = 0; m_LastLatencyTestID = 0;
@ -793,25 +793,25 @@ namespace llarp
} }
bool bool
Path::HandleDHTMessage(const dht::IMessage* msg, AbstractRouter* r) Path::HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r)
{ {
MarkActive(r->Now()); MarkActive(r->Now());
routing::DHTMessage reply; routing::DHTMessage reply;
if(!msg->HandleMessage(r->dht(), reply.M)) if(!msg.HandleMessage(r->dht(), reply.M))
return false; return false;
if(reply.M.size()) if(reply.M.size())
return SendRoutingMessage(&reply, r); return SendRoutingMessage(reply, r);
return true; return true;
} }
bool bool
Path::HandleCloseExitMessage(const routing::CloseExitMessage* msg, Path::HandleCloseExitMessage(const routing::CloseExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
/// allows exits to close from their end /// allows exits to close from their end
if(SupportsAnyRoles(ePathRoleExit | ePathRoleSVC)) if(SupportsAnyRoles(ePathRoleExit | ePathRoleSVC))
{ {
if(msg->Verify(r->crypto(), EndpointPubKey())) if(msg.Verify(r->crypto(), EndpointPubKey()))
{ {
LogInfo(Name(), " had its exit closed"); LogInfo(Name(), " had its exit closed");
_role &= ~ePathRoleExit; _role &= ~ePathRoleExit;
@ -826,16 +826,16 @@ namespace llarp
} }
bool bool
Path::SendExitRequest(const routing::ObtainExitMessage* msg, Path::SendExitRequest(const routing::ObtainExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
LogInfo(Name(), " sending exit request to ", Endpoint()); LogInfo(Name(), " sending exit request to ", Endpoint());
m_ExitObtainTX = msg->T; m_ExitObtainTX = msg.T;
return SendRoutingMessage(msg, r); return SendRoutingMessage(msg, r);
} }
bool bool
Path::SendExitClose(const routing::CloseExitMessage* msg, AbstractRouter* r) Path::SendExitClose(const routing::CloseExitMessage& msg, AbstractRouter* r)
{ {
LogInfo(Name(), " closing exit to ", Endpoint()); LogInfo(Name(), " closing exit to ", Endpoint());
// mark as not exit anymore // mark as not exit anymore
@ -844,7 +844,7 @@ namespace llarp
} }
bool bool
Path::HandleObtainExitMessage(const routing::ObtainExitMessage* msg, Path::HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
(void)msg; (void)msg;
@ -854,7 +854,7 @@ namespace llarp
} }
bool bool
Path::HandleUpdateExitMessage(const routing::UpdateExitMessage* msg, Path::HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
(void)msg; (void)msg;
@ -864,31 +864,31 @@ namespace llarp
} }
bool bool
Path::HandleRejectExitMessage(const routing::RejectExitMessage* msg, Path::HandleRejectExitMessage(const routing::RejectExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
if(m_ExitObtainTX && msg->T == m_ExitObtainTX) if(m_ExitObtainTX && msg.T == m_ExitObtainTX)
{ {
if(!msg->Verify(r->crypto(), EndpointPubKey())) if(!msg.Verify(r->crypto(), EndpointPubKey()))
{ {
LogError(Name(), "RXM invalid signature"); LogError(Name(), "RXM invalid signature");
return false; return false;
} }
LogInfo(Name(), " ", Endpoint(), " Rejected exit"); LogInfo(Name(), " ", Endpoint(), " Rejected exit");
MarkActive(r->Now()); MarkActive(r->Now());
return InformExitResult(msg->B); return InformExitResult(msg.B);
} }
LogError(Name(), " got unwarranted RXM"); LogError(Name(), " got unwarranted RXM");
return false; return false;
} }
bool bool
Path::HandleGrantExitMessage(const routing::GrantExitMessage* msg, Path::HandleGrantExitMessage(const routing::GrantExitMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
if(m_ExitObtainTX && msg->T == m_ExitObtainTX) if(m_ExitObtainTX && msg.T == m_ExitObtainTX)
{ {
if(!msg->Verify(r->crypto(), EndpointPubKey())) if(!msg.Verify(r->crypto(), EndpointPubKey()))
{ {
LogError(Name(), " GXM signature failed"); LogError(Name(), " GXM signature failed");
return false; return false;
@ -915,7 +915,7 @@ namespace llarp
bool bool
Path::HandleTransferTrafficMessage( Path::HandleTransferTrafficMessage(
const routing::TransferTrafficMessage* msg, AbstractRouter* r) const routing::TransferTrafficMessage& msg, AbstractRouter* r)
{ {
// check if we can handle exit data // check if we can handle exit data
if(!SupportsAnyRoles(ePathRoleExit | ePathRoleSVC)) if(!SupportsAnyRoles(ePathRoleExit | ePathRoleSVC))
@ -923,8 +923,8 @@ namespace llarp
// handle traffic if we have a handler // handle traffic if we have a handler
if(!m_ExitTrafficHandler) if(!m_ExitTrafficHandler)
return false; return false;
bool sent = msg->X.size() > 0; bool sent = msg.X.size() > 0;
for(const auto& pkt : msg->X) for(const auto& pkt : msg.X)
{ {
if(pkt.size() <= 8) if(pkt.size() <= 8)
return false; return false;

@ -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>
@ -123,8 +123,7 @@ namespace llarp
/// send routing message and increment sequence number /// send routing message and increment sequence number
virtual bool virtual bool
SendRoutingMessage(const llarp::routing::IMessage* msg, SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r) = 0;
llarp::AbstractRouter* r) = 0;
// handle data in upstream direction // handle data in upstream direction
virtual bool virtual bool
@ -150,8 +149,7 @@ namespace llarp
uint64_t m_SequenceNum = 0; uint64_t m_SequenceNum = 0;
}; };
struct TransitHop : public IHopHandler, struct TransitHop : public IHopHandler, public routing::IMessageHandler
public llarp::routing::IMessageHandler
{ {
TransitHop(); TransitHop();
@ -195,72 +193,68 @@ namespace llarp
// send routing message when end of path // send routing message when end of path
bool bool
SendRoutingMessage(const llarp::routing::IMessage* msg, SendRoutingMessage(const routing::IMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
// handle routing message when end of path // handle routing message when end of path
bool bool
HandleRoutingMessage(const llarp::routing::IMessage* msg, HandleRoutingMessage(const routing::IMessage& msg, AbstractRouter* r);
AbstractRouter* r);
bool bool
HandleDataDiscardMessage(const llarp::routing::DataDiscardMessage* msg, HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg, HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathTransferMessage(const llarp::routing::PathTransferMessage* msg, HandlePathTransferMessage(const routing::PathTransferMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathLatencyMessage(const llarp::routing::PathLatencyMessage* msg, HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleObtainExitMessage(const llarp::routing::ObtainExitMessage* msg, HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleUpdateExitVerifyMessage( HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
const llarp::routing::UpdateExitVerifyMessage* msg, AbstractRouter* r) override;
AbstractRouter* r) override;
bool bool
HandleTransferTrafficMessage( HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
const llarp::routing::TransferTrafficMessage* msg, AbstractRouter* r) override;
AbstractRouter* r) override;
bool bool
HandleUpdateExitMessage(const llarp::routing::UpdateExitMessage* msg, HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleGrantExitMessage(const llarp::routing::GrantExitMessage* msg, HandleGrantExitMessage(const routing::GrantExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleRejectExitMessage(const llarp::routing::RejectExitMessage* msg, HandleRejectExitMessage(const routing::RejectExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleCloseExitMessage(const llarp::routing::CloseExitMessage* msg, HandleCloseExitMessage(const routing::CloseExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleHiddenServiceFrame(__attribute__(( HandleHiddenServiceFrame(
unused)) const llarp::service::ProtocolFrame* frame) override ABSL_ATTRIBUTE_UNUSED const service::ProtocolFrame& frame) override
{ {
/// TODO: implement me /// TODO: implement me
llarp::LogWarn("Got hidden service data on transit hop"); LogWarn("Got hidden service data on transit hop");
return false; return false;
} }
bool bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg); HandleGotIntroMessage(const dht::GotIntroMessage& msg);
bool bool
HandleDHTMessage(const llarp::dht::IMessage* msg, HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
AbstractRouter* r) override;
// handle data in upstream direction // handle data in upstream direction
bool bool
@ -307,7 +301,7 @@ namespace llarp
}; };
/// A path we made /// A path we made
struct Path : public IHopHandler, public llarp::routing::IMessageHandler struct Path : public IHopHandler, public routing::IMessageHandler
{ {
using BuildResultHookFunc = std::function< void(Path*) >; using BuildResultHookFunc = std::function< void(Path*) >;
using CheckForDeadFunc = std::function< bool(Path*, llarp_time_t) >; using CheckForDeadFunc = std::function< bool(Path*, llarp_time_t) >;
@ -315,7 +309,7 @@ namespace llarp
std::function< bool(Path*, const PathID_t&, uint64_t) >; std::function< bool(Path*, const PathID_t&, uint64_t) >;
using HopList = std::vector< PathHopConfig >; using HopList = std::vector< PathHopConfig >;
using DataHandlerFunc = using DataHandlerFunc =
std::function< bool(Path*, const service::ProtocolFrame*) >; std::function< bool(Path*, const service::ProtocolFrame&) >;
using ExitUpdatedFunc = std::function< bool(Path*) >; using ExitUpdatedFunc = std::function< bool(Path*) >;
using ExitClosedFunc = std::function< bool(Path*) >; using ExitClosedFunc = std::function< bool(Path*) >;
using ExitTrafficHandlerFunc = using ExitTrafficHandlerFunc =
@ -327,7 +321,7 @@ namespace llarp
PathSet* m_PathSet; PathSet* m_PathSet;
llarp::service::Introduction intro; service::Introduction intro;
llarp_time_t buildStarted; llarp_time_t buildStarted;
@ -439,63 +433,59 @@ namespace llarp
Tick(llarp_time_t now, AbstractRouter* r); Tick(llarp_time_t now, AbstractRouter* r);
bool bool
SendRoutingMessage(const llarp::routing::IMessage* msg, SendRoutingMessage(const routing::IMessage& msg,
llarp::AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleObtainExitMessage(const llarp::routing::ObtainExitMessage* msg, HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleUpdateExitVerifyMessage( HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
const llarp::routing::UpdateExitVerifyMessage* msg, AbstractRouter* r) override;
AbstractRouter* r) override;
bool bool
HandleTransferTrafficMessage( HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
const llarp::routing::TransferTrafficMessage* msg, AbstractRouter* r) override;
AbstractRouter* r) override;
bool bool
HandleUpdateExitMessage(const llarp::routing::UpdateExitMessage* msg, HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleCloseExitMessage(const llarp::routing::CloseExitMessage* msg, HandleCloseExitMessage(const routing::CloseExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleGrantExitMessage(const llarp::routing::GrantExitMessage* msg, HandleGrantExitMessage(const routing::GrantExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleRejectExitMessage(const llarp::routing::RejectExitMessage* msg, HandleRejectExitMessage(const routing::RejectExitMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleDataDiscardMessage(const llarp::routing::DataDiscardMessage* msg, HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg, HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathLatencyMessage(const llarp::routing::PathLatencyMessage* msg, HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandlePathTransferMessage(const llarp::routing::PathTransferMessage* msg, HandlePathTransferMessage(const routing::PathTransferMessage& msg,
AbstractRouter* r) override; AbstractRouter* r) override;
bool bool
HandleHiddenServiceFrame( HandleHiddenServiceFrame(const service::ProtocolFrame& frame) override;
const llarp::service::ProtocolFrame* frame) override;
bool bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg); HandleGotIntroMessage(const dht::GotIntroMessage& msg);
bool bool
HandleDHTMessage(const llarp::dht::IMessage* msg, HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
AbstractRouter* r) override;
bool bool
HandleRoutingMessage(const llarp_buffer_t& buf, AbstractRouter* r); HandleRoutingMessage(const llarp_buffer_t& buf, AbstractRouter* r);
@ -543,12 +533,10 @@ namespace llarp
} }
bool bool
SendExitRequest(const llarp::routing::ObtainExitMessage* msg, SendExitRequest(const routing::ObtainExitMessage& msg, AbstractRouter* r);
AbstractRouter* r);
bool bool
SendExitClose(const llarp::routing::CloseExitMessage* msg, SendExitClose(const routing::CloseExitMessage& msg, AbstractRouter* r);
AbstractRouter* r);
private: private:
/// call obtained exit hooks /// call obtained exit hooks
@ -615,7 +603,7 @@ namespace llarp
HasTransitHop(const TransitHopInfo& info); HasTransitHop(const TransitHopInfo& info);
bool bool
HandleRelayCommit(const LR_CommitMessage* msg); HandleRelayCommit(const LR_CommitMessage& msg);
void void
PutTransitHop(std::shared_ptr< TransitHop > hop); PutTransitHop(std::shared_ptr< TransitHop > hop);
@ -646,10 +634,10 @@ namespace llarp
HopIsUs(const RouterID& k) const; HopIsUs(const RouterID& k) const;
bool bool
HandleLRUM(const RelayUpstreamMessage* msg); HandleLRUM(const RelayUpstreamMessage& msg);
bool bool
HandleLRDM(const RelayDownstreamMessage* msg); HandleLRDM(const RelayDownstreamMessage& msg);
void void
AddOwnPath(PathSet* set, Path* p); AddOwnPath(PathSet* set, Path* p);
@ -684,13 +672,13 @@ namespace llarp
llarp::Crypto* llarp::Crypto*
Crypto(); Crypto();
llarp::Logic* Logic*
Logic(); Logic();
AbstractRouter* AbstractRouter*
Router(); Router();
const llarp::SecretKey& const SecretKey&
EncryptionSecretKey(); EncryptionSecretKey();
const byte_t* const byte_t*

@ -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>

@ -59,7 +59,7 @@ namespace llarp
} }
bool bool
TransitHop::SendRoutingMessage(const llarp::routing::IMessage* msg, TransitHop::SendRoutingMessage(const routing::IMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
if(!IsEndpoint(r->pubkey())) if(!IsEndpoint(r->pubkey()))
@ -67,7 +67,7 @@ namespace llarp
std::array< byte_t, MAX_LINK_MSG_SIZE - 128 > tmp; std::array< byte_t, MAX_LINK_MSG_SIZE - 128 > tmp;
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
if(!msg->BEncode(&buf)) if(!msg.BEncode(&buf))
{ {
llarp::LogError("failed to encode routing message"); llarp::LogError("failed to encode routing message");
return false; return false;
@ -126,7 +126,7 @@ namespace llarp
} }
bool bool
TransitHop::HandleDHTMessage(const llarp::dht::IMessage* msg, TransitHop::HandleDHTMessage(const llarp::dht::IMessage& msg,
AbstractRouter* r) AbstractRouter* r)
{ {
return r->dht()->impl->RelayRequestForPath(info.rxID, msg); return r->dht()->impl->RelayRequestForPath(info.rxID, msg);
@ -134,16 +134,16 @@ namespace llarp
bool bool
TransitHop::HandlePathLatencyMessage( TransitHop::HandlePathLatencyMessage(
const llarp::routing::PathLatencyMessage* msg, AbstractRouter* r) const llarp::routing::PathLatencyMessage& msg, AbstractRouter* r)
{ {
llarp::routing::PathLatencyMessage reply; llarp::routing::PathLatencyMessage reply;
reply.L = msg->T; reply.L = msg.T;
return SendRoutingMessage(&reply, r); return SendRoutingMessage(reply, r);
} }
bool bool
TransitHop::HandlePathConfirmMessage( TransitHop::HandlePathConfirmMessage(
__attribute__((unused)) const llarp::routing::PathConfirmMessage* msg, __attribute__((unused)) const llarp::routing::PathConfirmMessage& msg,
__attribute__((unused)) AbstractRouter* r) __attribute__((unused)) AbstractRouter* r)
{ {
llarp::LogWarn("unwarranted path confirm message on ", info); llarp::LogWarn("unwarranted path confirm message on ", info);
@ -152,7 +152,7 @@ namespace llarp
bool bool
TransitHop::HandleDataDiscardMessage( TransitHop::HandleDataDiscardMessage(
__attribute__((unused)) const llarp::routing::DataDiscardMessage* msg, __attribute__((unused)) const llarp::routing::DataDiscardMessage& msg,
__attribute__((unused)) AbstractRouter* r) __attribute__((unused)) AbstractRouter* r)
{ {
llarp::LogWarn("unwarranted path data discard message on ", info); llarp::LogWarn("unwarranted path data discard message on ", info);
@ -161,55 +161,55 @@ namespace llarp
bool bool
TransitHop::HandleObtainExitMessage( TransitHop::HandleObtainExitMessage(
const llarp::routing::ObtainExitMessage* msg, AbstractRouter* r) const llarp::routing::ObtainExitMessage& msg, AbstractRouter* r)
{ {
if(msg->Verify(r->crypto()) if(msg.Verify(r->crypto())
&& r->exitContext().ObtainNewExit(msg->I, info.rxID, msg->E != 0)) && r->exitContext().ObtainNewExit(msg.I, info.rxID, msg.E != 0))
{ {
llarp::routing::GrantExitMessage grant; llarp::routing::GrantExitMessage grant;
grant.S = NextSeqNo(); grant.S = NextSeqNo();
grant.T = msg->T; grant.T = msg.T;
if(!grant.Sign(r->crypto(), r->identity())) if(!grant.Sign(r->crypto(), r->identity()))
{ {
llarp::LogError("Failed to sign grant exit message"); llarp::LogError("Failed to sign grant exit message");
return false; return false;
} }
return SendRoutingMessage(&grant, r); return SendRoutingMessage(grant, r);
} }
// TODO: exponential backoff // TODO: exponential backoff
// TODO: rejected policies // TODO: rejected policies
llarp::routing::RejectExitMessage reject; llarp::routing::RejectExitMessage reject;
reject.S = NextSeqNo(); reject.S = NextSeqNo();
reject.T = msg->T; reject.T = msg.T;
if(!reject.Sign(r->crypto(), r->identity())) if(!reject.Sign(r->crypto(), r->identity()))
{ {
llarp::LogError("Failed to sign reject exit message"); llarp::LogError("Failed to sign reject exit message");
return false; return false;
} }
return SendRoutingMessage(&reject, r); return SendRoutingMessage(reject, r);
} }
bool bool
TransitHop::HandleCloseExitMessage( TransitHop::HandleCloseExitMessage(
const llarp::routing::CloseExitMessage* msg, AbstractRouter* r) const llarp::routing::CloseExitMessage& msg, AbstractRouter* r)
{ {
llarp::routing::DataDiscardMessage discard(info.rxID, msg->S); llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
auto ep = r->exitContext().FindEndpointForPath(info.rxID); auto ep = r->exitContext().FindEndpointForPath(info.rxID);
if(ep && msg->Verify(r->crypto(), ep->PubKey())) if(ep && msg.Verify(r->crypto(), ep->PubKey()))
{ {
ep->Close(); ep->Close();
// ep is now gone af // ep is now gone af
llarp::routing::CloseExitMessage reply; llarp::routing::CloseExitMessage reply;
reply.S = NextSeqNo(); reply.S = NextSeqNo();
if(reply.Sign(r->crypto(), r->identity())) if(reply.Sign(r->crypto(), r->identity()))
return SendRoutingMessage(&reply, r); return SendRoutingMessage(reply, r);
} }
return SendRoutingMessage(&discard, r); return SendRoutingMessage(discard, r);
} }
bool bool
TransitHop::HandleUpdateExitVerifyMessage( TransitHop::HandleUpdateExitVerifyMessage(
const llarp::routing::UpdateExitVerifyMessage* msg, AbstractRouter* r) const llarp::routing::UpdateExitVerifyMessage& msg, AbstractRouter* r)
{ {
(void)msg; (void)msg;
(void)r; (void)r;
@ -219,30 +219,30 @@ namespace llarp
bool bool
TransitHop::HandleUpdateExitMessage( TransitHop::HandleUpdateExitMessage(
const llarp::routing::UpdateExitMessage* msg, AbstractRouter* r) const llarp::routing::UpdateExitMessage& msg, AbstractRouter* r)
{ {
auto ep = r->exitContext().FindEndpointForPath(msg->P); auto ep = r->exitContext().FindEndpointForPath(msg.P);
if(ep) if(ep)
{ {
if(!msg->Verify(r->crypto(), ep->PubKey())) if(!msg.Verify(r->crypto(), ep->PubKey()))
return false; return false;
if(ep->UpdateLocalPath(info.rxID)) if(ep->UpdateLocalPath(info.rxID))
{ {
llarp::routing::UpdateExitVerifyMessage reply; llarp::routing::UpdateExitVerifyMessage reply;
reply.T = msg->T; reply.T = msg.T;
reply.S = NextSeqNo(); reply.S = NextSeqNo();
return SendRoutingMessage(&reply, r); return SendRoutingMessage(reply, r);
} }
} }
// on fail tell message was discarded // on fail tell message was discarded
llarp::routing::DataDiscardMessage discard(info.rxID, msg->S); llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
return SendRoutingMessage(&discard, r); return SendRoutingMessage(discard, r);
} }
bool bool
TransitHop::HandleRejectExitMessage( TransitHop::HandleRejectExitMessage(
const llarp::routing::RejectExitMessage* msg, AbstractRouter* r) const llarp::routing::RejectExitMessage& msg, AbstractRouter* r)
{ {
(void)msg; (void)msg;
(void)r; (void)r;
@ -252,7 +252,7 @@ namespace llarp
bool bool
TransitHop::HandleGrantExitMessage( TransitHop::HandleGrantExitMessage(
const llarp::routing::GrantExitMessage* msg, AbstractRouter* r) const llarp::routing::GrantExitMessage& msg, AbstractRouter* r)
{ {
(void)msg; (void)msg;
(void)r; (void)r;
@ -262,13 +262,13 @@ namespace llarp
bool bool
TransitHop::HandleTransferTrafficMessage( TransitHop::HandleTransferTrafficMessage(
const llarp::routing::TransferTrafficMessage* msg, AbstractRouter* r) const llarp::routing::TransferTrafficMessage& msg, AbstractRouter* r)
{ {
auto endpoint = r->exitContext().FindEndpointForPath(info.rxID); auto endpoint = r->exitContext().FindEndpointForPath(info.rxID);
if(endpoint) if(endpoint)
{ {
bool sent = true; bool sent = true;
for(const auto& pkt : msg->X) for(const auto& pkt : msg.X)
{ {
// check short packet buffer // check short packet buffer
if(pkt.size() <= 8) if(pkt.size() <= 8)
@ -283,35 +283,35 @@ namespace llarp
else else
llarp::LogError("No exit endpoint on ", info); llarp::LogError("No exit endpoint on ", info);
// discarded // discarded
llarp::routing::DataDiscardMessage discard(info.rxID, msg->S); llarp::routing::DataDiscardMessage discard(info.rxID, msg.S);
return SendRoutingMessage(&discard, r); return SendRoutingMessage(discard, r);
} }
bool bool
TransitHop::HandlePathTransferMessage( TransitHop::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, AbstractRouter* r) const llarp::routing::PathTransferMessage& msg, AbstractRouter* r)
{ {
auto path = r->pathContext().GetPathForTransfer(msg->P); auto path = r->pathContext().GetPathForTransfer(msg.P);
llarp::routing::DataDiscardMessage discarded(msg->P, msg->S); llarp::routing::DataDiscardMessage discarded(msg.P, msg.S);
if(path == nullptr || msg->T.F != info.txID) if(path == nullptr || msg.T.F != info.txID)
{ {
return SendRoutingMessage(&discarded, r); return SendRoutingMessage(discarded, r);
} }
std::array< byte_t, service::MAX_PROTOCOL_MESSAGE_SIZE > tmp; std::array< byte_t, service::MAX_PROTOCOL_MESSAGE_SIZE > tmp;
llarp_buffer_t buf(tmp); llarp_buffer_t buf(tmp);
if(!msg->T.BEncode(&buf)) if(!msg.T.BEncode(&buf))
{ {
llarp::LogWarn(info, " failed to transfer data message, encode failed"); llarp::LogWarn(info, " failed to transfer data message, encode failed");
return SendRoutingMessage(&discarded, r); return SendRoutingMessage(discarded, r);
} }
// rewind // rewind
buf.sz = buf.cur - buf.base; buf.sz = buf.cur - buf.base;
buf.cur = buf.base; buf.cur = buf.base;
// send // send
if(path->HandleDownstream(buf, msg->Y, r)) if(path->HandleDownstream(buf, msg.Y, r))
return true; return true;
return SendRoutingMessage(&discarded, r); return SendRoutingMessage(discarded, r);
} }
} // namespace path } // namespace path

@ -58,7 +58,7 @@ namespace llarp
{ {
msg->From = us; msg->From = us;
msg->pathID = from; msg->pathID = from;
if(!h->HandleDHTMessage(msg.get(), r)) if(!h->HandleDHTMessage(*msg, r))
return false; return false;
} }
return true; return true;

@ -33,53 +33,53 @@ namespace llarp
struct IMessageHandler struct IMessageHandler
{ {
virtual bool virtual bool
HandleObtainExitMessage(const ObtainExitMessage *msg, HandleObtainExitMessage(const ObtainExitMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleGrantExitMessage(const GrantExitMessage *msg, HandleGrantExitMessage(const GrantExitMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleRejectExitMessage(const RejectExitMessage *msg, HandleRejectExitMessage(const RejectExitMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleTransferTrafficMessage(const TransferTrafficMessage *msg, HandleTransferTrafficMessage(const TransferTrafficMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleUpdateExitMessage(const UpdateExitMessage *msg, HandleUpdateExitMessage(const UpdateExitMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleUpdateExitVerifyMessage(const UpdateExitVerifyMessage *msg, HandleUpdateExitVerifyMessage(const UpdateExitVerifyMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleCloseExitMessage(const CloseExitMessage *msg, HandleCloseExitMessage(const CloseExitMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleDataDiscardMessage(const DataDiscardMessage *msg, HandleDataDiscardMessage(const DataDiscardMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandlePathTransferMessage(const PathTransferMessage *msg, HandlePathTransferMessage(const PathTransferMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleHiddenServiceFrame(const service::ProtocolFrame *msg) = 0; HandleHiddenServiceFrame(const service::ProtocolFrame& msg) = 0;
virtual bool virtual bool
HandlePathConfirmMessage(const PathConfirmMessage *msg, HandlePathConfirmMessage(const PathConfirmMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandlePathLatencyMessage(const PathLatencyMessage *msg, HandlePathLatencyMessage(const PathLatencyMessage& msg,
AbstractRouter *r) = 0; AbstractRouter *r) = 0;
virtual bool virtual bool
HandleDHTMessage(const dht::IMessage *msg, AbstractRouter *r) = 0; HandleDHTMessage(const dht::IMessage& msg, AbstractRouter *r) = 0;
}; };
} // namespace routing } // namespace routing
} // namespace llarp } // namespace llarp

@ -55,7 +55,7 @@ namespace llarp
PathConfirmMessage::HandleMessage(IMessageHandler* h, PathConfirmMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h && h->HandlePathConfirmMessage(this, r); return h && h->HandlePathConfirmMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -49,7 +49,7 @@ namespace llarp
PathLatencyMessage::HandleMessage(IMessageHandler* h, PathLatencyMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h && h->HandlePathLatencyMessage(this, r); return h && h->HandlePathLatencyMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -61,7 +61,7 @@ namespace llarp
PathTransferMessage::HandleMessage(IMessageHandler* h, PathTransferMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const AbstractRouter* r) const
{ {
return h->HandlePathTransferMessage(this, r); return h->HandlePathTransferMessage(*this, r);
} }
} // namespace routing } // namespace routing

@ -1,150 +0,0 @@
#ifndef LLARP_SERVICE_INTROSET_HPP
#define LLARP_SERVICE_INTROSET_HPP
#include <crypto/types.hpp>
#include <pow.hpp>
#include <service/Info.hpp>
#include <service/Intro.hpp>
#include <service/tag.hpp>
#include <util/bencode.hpp>
#include <util/time.hpp>
#include <util/status.hpp>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
namespace llarp
{
struct Crypto;
namespace service
{
constexpr std::size_t MAX_INTROSET_SIZE = 4096;
// 10 seconds clock skew permitted for introset expiration
constexpr llarp_time_t MAX_INTROSET_TIME_DELTA = (10 * 1000);
struct IntroSet final : public llarp::IBEncodeMessage
{
util::StatusObject
ExtractStatus() const;
ServiceInfo A;
std::vector< Introduction > I;
PQPubKey K;
Tag topic;
llarp_time_t T = 0;
llarp::PoW* W = nullptr;
llarp::Signature Z;
IntroSet() = default;
IntroSet(IntroSet&& other) : IBEncodeMessage(other.version)
{
A = std::move(other.A);
I = std::move(other.I);
K = std::move(other.K);
T = std::move(other.T);
version = std::move(other.version);
topic = std::move(other.topic);
W = std::move(other.W);
Z = std::move(other.Z);
}
IntroSet(const IntroSet& other) : IBEncodeMessage(other.version)
{
A = other.A;
I = other.I;
K = other.K;
T = other.T;
version = other.version;
topic = other.topic;
if(other.W)
W = new llarp::PoW(*other.W);
Z = other.Z;
}
~IntroSet();
IntroSet&
operator=(const IntroSet& other)
{
I.clear();
A = other.A;
I = other.I;
K = other.K;
T = other.T;
version = other.version;
topic = other.topic;
if(W)
{
delete W;
W = nullptr;
}
if(other.W)
W = new llarp::PoW(*other.W);
Z = other.Z;
return *this;
}
bool
operator<(const IntroSet& other) const
{
return A < other.A;
}
bool
operator==(const IntroSet& other) const
{
return A == other.A && I == other.I && K == other.K && T == other.T
&& version == other.version && topic == other.topic && W == other.W
&& Z == other.Z;
}
bool
operator!=(const IntroSet& other) const
{
return !(*this == other);
}
bool
OtherIsNewer(const IntroSet& other) const
{
return T < other.T;
}
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
llarp_time_t
GetNewestIntroExpiration() const;
bool
HasExpiredIntros(llarp_time_t now) const;
bool
IsExpired(llarp_time_t now) const;
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
Verify(llarp::Crypto* crypto, llarp_time_t now) const;
};
inline std::ostream&
operator<<(std::ostream& out, const IntroSet& i)
{
return i.print(out, -1, -1);
}
using IntroSetLookupHandler =
std::function< void(const std::vector< IntroSet >&) >;
} // namespace service
} // namespace llarp
#endif

@ -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;
} }
} }
@ -309,22 +309,23 @@ namespace llarp
if(option.first == "keyfile") if(option.first == "keyfile")
keyfile = option.second; keyfile = option.second;
} }
std::unique_ptr< llarp::service::Endpoint > service;
static std::map< std::string, std::unique_ptr< service::Endpoint > service;
std::function< llarp::service::Endpoint *(
const std::string &, AbstractRouter *, static std::map<
llarp::service::Context *) > > std::string,
std::function< std::unique_ptr< service::Endpoint >(
const std::string &, AbstractRouter *, service::Context *) > >
endpointConstructors = { endpointConstructors = {
{"tun", {"tun",
[](const std::string &nick, AbstractRouter *r, [](const std::string &nick, AbstractRouter *r,
llarp::service::Context *c) -> llarp::service::Endpoint * { service::Context *c) -> std::unique_ptr< service::Endpoint > {
return new llarp::handlers::TunEndpoint(nick, r, c); return std::make_unique< handlers::TunEndpoint >(nick, r, c);
}}, }},
{"null", {"null",
[](const std::string &nick, AbstractRouter *r, [](const std::string &nick, AbstractRouter *r,
llarp::service::Context *c) -> llarp::service::Endpoint * { service::Context *c) -> std::unique_ptr< service::Endpoint > {
return new llarp::handlers::NullEndpoint(nick, r, c); return std::make_unique< handlers::NullEndpoint >(nick, r, c);
}}}; }}};
{ {
@ -332,12 +333,12 @@ 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;
} }
// construct // construct
service.reset(itr->second(conf.first, m_Router, this)); service = itr->second(conf.first, m_Router, this);
// if ephemeral, then we need to regen key // if ephemeral, then we need to regen key
// if privkey file, then set it and load it // if privkey file, then set it and load it
@ -346,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
} }
@ -359,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;
} }
} }
@ -369,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

@ -670,11 +670,12 @@ namespace llarp
{ {
} }
routing::IMessage* std::unique_ptr< routing::IMessage >
BuildRequestMessage() BuildRequestMessage()
{ {
routing::DHTMessage* msg = new routing::DHTMessage(); auto msg = std::make_unique< routing::DHTMessage >();
msg->M.emplace_back(new dht::PublishIntroMessage(m_IntroSet, txid, 1)); msg->M.emplace_back(
std::make_unique< dht::PublishIntroMessage >(m_IntroSet, txid, 1));
return msg; return msg;
} }
@ -795,8 +796,8 @@ namespace llarp
return; return;
} }
OutboundContext* ctx = new OutboundContext(introset, this); auto it = m_RemoteSessions.emplace(
m_RemoteSessions.emplace(addr, std::unique_ptr< OutboundContext >(ctx)); addr, std::make_unique< OutboundContext >(introset, this));
LogInfo("Created New outbound context for ", addr.ToString()); LogInfo("Created New outbound context for ", addr.ToString());
// inform pending // inform pending
@ -804,7 +805,7 @@ namespace llarp
auto itr = range.first; auto itr = range.first;
if(itr != range.second) if(itr != range.second)
{ {
itr->second(addr, ctx); itr->second(addr, it->second.get());
++itr; ++itr;
} }
m_PendingServiceLookups.erase(addr); m_PendingServiceLookups.erase(addr);
@ -851,9 +852,10 @@ namespace llarp
auto path = GetEstablishedPathClosestTo(router); auto path = GetEstablishedPathClosestTo(router);
routing::DHTMessage msg; routing::DHTMessage msg;
auto txid = GenTXID(); auto txid = GenTXID();
msg.M.emplace_back(new dht::FindRouterMessage(txid, router)); msg.M.emplace_back(
std::make_unique< dht::FindRouterMessage >(txid, router));
if(path && path->SendRoutingMessage(&msg, m_Router)) if(path && path->SendRoutingMessage(msg, m_Router))
{ {
LogInfo(Name(), " looking up ", router); LogInfo(Name(), " looking up ", router);
m_PendingRouters.emplace(router, RouterLookupJob(this)); m_PendingRouters.emplace(router, RouterLookupJob(this));
@ -868,15 +870,11 @@ namespace llarp
void void
Endpoint::HandlePathBuilt(path::Path* p) Endpoint::HandlePathBuilt(path::Path* p)
{ {
p->SetDataHandler(std::bind(&Endpoint::HandleHiddenServiceFrame, this, using namespace std::placeholders;
std::placeholders::_1, p->SetDataHandler(
std::placeholders::_2)); std::bind(&Endpoint::HandleHiddenServiceFrame, this, _1, _2));
p->SetDropHandler(std::bind(&Endpoint::HandleDataDrop, this, p->SetDropHandler(std::bind(&Endpoint::HandleDataDrop, this, _1, _2, _3));
std::placeholders::_1, std::placeholders::_2, p->SetDeadChecker(std::bind(&Endpoint::CheckPathIsDead, this, _1, _2));
std::placeholders::_3));
p->SetDeadChecker(std::bind(&Endpoint::CheckPathIsDead, this,
std::placeholders::_1,
std::placeholders::_2));
path::Builder::HandlePathBuilt(p); path::Builder::HandlePathBuilt(p);
} }
@ -949,34 +947,35 @@ namespace llarp
bool bool
Endpoint::HandleHiddenServiceFrame(path::Path* p, Endpoint::HandleHiddenServiceFrame(path::Path* p,
const ProtocolFrame* frame) const ProtocolFrame& frame)
{ {
if(frame->R) if(frame.R)
{ {
// handle discard // handle discard
ServiceInfo si; ServiceInfo si;
if(!GetSenderFor(frame->T, si)) if(!GetSenderFor(frame.T, si))
return false; return false;
// verify source // verify source
if(!frame->Verify(GetCrypto(), si)) if(!frame->Verify(GetCrypto(), si))
return false; return false;
// remove convotag it doesn't exist // remove convotag it doesn't exist
LogWarn("remove convotag T=", frame->T); LogWarn("remove convotag T=", frame.T);
RemoveConvoTag(frame->T); RemoveConvoTag(frame.T);
return true; return true;
} }
if(!frame->AsyncDecryptAndVerify(EndpointLogic(), GetCrypto(), p, if(!frame.AsyncDecryptAndVerify(EndpointLogic(), GetCrypto(), p,
Worker(), m_Identity, m_DataHandler)) Worker(), m_Identity, m_DataHandler))
{ {
// send discard // send discard
ProtocolFrame f; ProtocolFrame f;
f.R = 1; f.R = 1;
f.T = frame->T; f.T = frame.T;
f.F = p->intro.pathID; f.F = p->intro.pathID;
if(!f.Sign(GetCrypto(), m_Identity)) if(!f.Sign(GetCrypto(), m_Identity))
return false; return false;
const routing::PathTransferMessage d(f, frame->F); const routing::PathTransferMessage d(f, frame.F);
return p->SendRoutingMessage(&d, router); return p->SendRoutingMessage(d, router);
} }
return true; return true;
} }
@ -1051,11 +1050,10 @@ namespace llarp
return false; return false;
} }
using namespace std::placeholders;
HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup( HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(
this, this, std::bind(&Endpoint::OnLookup, this, _1, _2, _3), remote,
std::bind(&Endpoint::OnLookup, this, std::placeholders::_1, GenTXID());
std::placeholders::_2, std::placeholders::_3),
remote, GenTXID());
LogInfo("doing lookup for ", remote, " via ", path->Endpoint()); LogInfo("doing lookup for ", remote, " via ", path->Endpoint());
if(job->SendRequestViaPath(path, Router())) if(job->SendRequestViaPath(path, Router()))
{ {
@ -1069,6 +1067,7 @@ namespace llarp
void void
Endpoint::EnsurePathToSNode(const RouterID& snode, SNodeEnsureHook h) Endpoint::EnsurePathToSNode(const RouterID& snode, SNodeEnsureHook h)
{ {
using namespace std::placeholders;
if(m_SNodeSessions.count(snode) == 0) if(m_SNodeSessions.count(snode) == 0)
{ {
auto themIP = ObtainIPForAddr(snode, true); auto themIP = ObtainIPForAddr(snode, true);
@ -1076,8 +1075,7 @@ namespace llarp
snode, snode,
std::make_unique< exit::SNodeSession >( std::make_unique< exit::SNodeSession >(
snode, snode,
std::bind(&Endpoint::HandleWriteIPPacket, this, std::bind(&Endpoint::HandleWriteIPPacket, this, _1,
std::placeholders::_1,
[themIP]() -> huint32_t { return themIP; }), [themIP]() -> huint32_t { return themIP; }),
m_Router, 2, numHops)); m_Router, 2, numHops));
} }
@ -1088,7 +1086,7 @@ namespace llarp
if(itr->second->IsReady()) if(itr->second->IsReady())
h(snode, itr->second.get()); h(snode, itr->second.get());
else else
itr->second->AddReadyHook(std::bind(h, snode, std::placeholders::_1)); itr->second->AddReadyHook(std::bind(h, snode, _1));
++itr; ++itr;
} }
} }
@ -1176,7 +1174,7 @@ namespace llarp
return false; return false;
} }
LogDebug(Name(), " send ", data.sz, " via ", remoteIntro.router); LogDebug(Name(), " send ", data.sz, " via ", remoteIntro.router);
return p->SendRoutingMessage(&transfer, Router()); return p->SendRoutingMessage(transfer, Router());
} }
} }
} }

@ -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>
@ -138,7 +138,7 @@ namespace llarp
bool bool
HandleHiddenServiceFrame(path::Path* p, HandleHiddenServiceFrame(path::Path* p,
const service::ProtocolFrame* msg); const service::ProtocolFrame& msg);
/// return true if we have an established path to a hidden service /// return true if we have an established path to a hidden service
bool bool

@ -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

@ -33,11 +33,12 @@ namespace llarp
return handle(remote, nullptr, endpoint); return handle(remote, nullptr, endpoint);
} }
routing::IMessage* std::unique_ptr< routing::IMessage >
HiddenServiceAddressLookup::BuildRequestMessage() HiddenServiceAddressLookup::BuildRequestMessage()
{ {
routing::DHTMessage* msg = new routing::DHTMessage(); auto msg = std::make_unique< routing::DHTMessage >();
msg->M.emplace_back(new dht::FindIntroMessage(txid, remote, 0)); msg->M.emplace_back(
std::make_unique< dht::FindIntroMessage >(txid, remote, 0));
return msg; return msg;
} }

@ -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
@ -27,7 +27,7 @@ namespace llarp
bool bool
HandleResponse(const std::set< IntroSet >& results); HandleResponse(const std::set< IntroSet >& results);
routing::IMessage* std::unique_ptr< routing::IMessage >
BuildRequestMessage(); BuildRequestMessage();
}; };
} // namespace service } // namespace service

@ -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

@ -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);

@ -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
{ {

@ -1,4 +1,4 @@
#include <service/IntroSet.hpp> #include <service/intro_set.hpp>
#include <path/path.hpp> #include <path/path.hpp>
@ -6,12 +6,6 @@ namespace llarp
{ {
namespace service namespace service
{ {
IntroSet::~IntroSet()
{
if(W)
delete W;
}
util::StatusObject util::StatusObject
IntroSet::ExtractStatus() const IntroSet::ExtractStatus() const
{ {
@ -49,9 +43,7 @@ namespace llarp
if(key == "w") if(key == "w")
{ {
if(W) W = absl::make_optional< PoW >();
delete W;
W = new PoW();
return W->BDecode(buf); return W->BDecode(buf);
} }
@ -122,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);
@ -156,17 +148,19 @@ namespace llarp
{ {
if(W if(W
&& intro.expiresAt - W->extendedLifetime > path::default_lifetime) && intro.expiresAt - W->extendedLifetime > path::default_lifetime)
{
return false; return false;
else if(W == nullptr) }
else if(!W.has_value())
{ {
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;
@ -201,7 +195,14 @@ namespace llarp
} }
printer.printAttribute("T", T); printer.printAttribute("T", T);
printer.printAttribute("W", W); if(W)
{
printer.printAttribute("W", W.value());
}
else
{
printer.printAttribute("W", "NULL");
}
printer.printAttribute("V", version); printer.printAttribute("V", version);
printer.printAttribute("Z", Z); printer.printAttribute("Z", Z);

@ -0,0 +1,102 @@
#ifndef LLARP_SERVICE_INTRO_SET_HPP
#define LLARP_SERVICE_INTRO_SET_HPP
#include <crypto/types.hpp>
#include <pow.hpp>
#include <service/info.hpp>
#include <service/intro.hpp>
#include <service/tag.hpp>
#include <util/bencode.hpp>
#include <util/time.hpp>
#include <util/status.hpp>
#include <absl/types/optional.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
namespace llarp
{
struct Crypto;
namespace service
{
constexpr std::size_t MAX_INTROSET_SIZE = 4096;
// 10 seconds clock skew permitted for introset expiration
constexpr llarp_time_t MAX_INTROSET_TIME_DELTA = (10 * 1000);
struct IntroSet final : public IBEncodeMessage
{
ServiceInfo A;
std::vector< Introduction > I;
PQPubKey K;
Tag topic;
llarp_time_t T = 0;
absl::optional< PoW > W;
Signature Z;
bool
OtherIsNewer(const IntroSet& other) const
{
return T < other.T;
}
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
llarp_time_t
GetNewestIntroExpiration() const;
bool
HasExpiredIntros(llarp_time_t now) const;
bool
IsExpired(llarp_time_t now) const;
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
Verify(Crypto* crypto, llarp_time_t now) const;
util::StatusObject
ExtractStatus() const;
};
inline bool
operator<(const IntroSet& lhs, const IntroSet& rhs)
{
return lhs.A < rhs.A;
}
inline bool
operator==(const IntroSet& lhs, const IntroSet& rhs)
{
return std::tie(lhs.A, lhs.I, lhs.K, lhs.T, lhs.version, lhs.topic, lhs.W,
lhs.Z)
== std::tie(rhs.A, rhs.I, rhs.K, rhs.T, rhs.version, rhs.topic, rhs.W,
rhs.Z);
}
inline bool
operator!=(const IntroSet& lhs, const IntroSet& rhs)
{
return !(lhs == rhs);
}
inline std::ostream&
operator<<(std::ostream& out, const IntroSet& i)
{
return i.print(out, -1, -1);
}
using IntroSetLookupHandler =
std::function< void(const std::vector< IntroSet >&) >;
} // namespace service
} // namespace llarp
#endif

@ -23,9 +23,8 @@ namespace llarp
auto msg = BuildRequestMessage(); auto msg = BuildRequestMessage();
if(!msg) if(!msg)
return false; return false;
auto result = path->SendRoutingMessage(msg, r); auto result = path->SendRoutingMessage(*msg, r);
endpoint = path->Endpoint(); endpoint = path->Endpoint();
delete msg;
return result; return result;
} }
} // namespace service } // namespace service

@ -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>
@ -43,12 +43,12 @@ namespace llarp
} }
/// build request message for service lookup /// build request message for service lookup
virtual llarp::routing::IMessage* virtual std::unique_ptr< routing::IMessage >
BuildRequestMessage() = 0; BuildRequestMessage() = 0;
/// build a new requset 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},

@ -535,7 +535,7 @@ namespace llarp
bool bool
OutboundContext::HandleHiddenServiceFrame(path::Path* p, OutboundContext::HandleHiddenServiceFrame(path::Path* p,
const ProtocolFrame* frame) const ProtocolFrame& frame)
{ {
return m_Endpoint->HandleHiddenServiceFrame(p, frame); return m_Endpoint->HandleHiddenServiceFrame(p, frame);
} }

@ -81,10 +81,10 @@ 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);
std::string std::string
Name() const override; Name() const override;

@ -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,7 +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");
DumpBuffer(*buf);
delete self->msg; delete self->msg;
delete self; delete self;
return; return;
@ -296,8 +295,10 @@ 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->msg->Dump< MAX_PROTOCOL_MESSAGE_SIZE >();
delete self->msg; delete self->msg;
delete self; delete self;
return; return;
@ -305,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;
@ -321,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;
@ -361,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,
@ -369,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
@ -381,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;
} }
@ -416,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
@ -427,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;
} }
@ -439,11 +440,10 @@ namespace llarp
} }
bool bool
ProtocolFrame::HandleMessage(llarp::routing::IMessageHandler* h, ProtocolFrame::HandleMessage(routing::IMessageHandler* h,
__attribute__((unused)) ABSL_ATTRIBUTE_UNUSED AbstractRouter* r) const
AbstractRouter* r) const
{ {
return h->HandleHiddenServiceFrame(this); return h->HandleHiddenServiceFrame(*this);
} }
} // namespace service } // namespace service

@ -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>

@ -28,20 +28,19 @@ namespace llarp
if(path) if(path)
{ {
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,28 +85,28 @@ 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;
} }
msg.P = remoteIntro.pathID; msg.P = remoteIntro.pathID;
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)
{ {
} }

@ -42,11 +42,11 @@ namespace llarp
} }
} }
routing::IMessage* std::unique_ptr< routing::IMessage >
CachedTagResult::BuildRequestMessage(uint64_t txid) CachedTagResult::BuildRequestMessage(uint64_t txid)
{ {
routing::DHTMessage* msg = new routing::DHTMessage(); auto msg = std::make_unique< routing::DHTMessage >();
msg->M.emplace_back(new dht::FindIntroMessage(tag, txid)); msg->M.emplace_back(std::make_unique< dht::FindIntroMessage >(tag, txid));
lastRequest = parent->Now(); lastRequest = parent->Now();
return msg; return msg;
} }

@ -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>
@ -43,7 +43,7 @@ namespace llarp
return (now - lastRequest) > TTL; return (now - lastRequest) > TTL;
} }
llarp::routing::IMessage* std::unique_ptr< routing::IMessage >
BuildRequestMessage(uint64_t txid); BuildRequestMessage(uint64_t txid);
bool bool
@ -58,7 +58,7 @@ namespace llarp
{ {
} }
llarp::routing::IMessage* std::unique_ptr< routing::IMessage >
BuildRequestMessage() override BuildRequestMessage() override
{ {
return m_result->BuildRequestMessage(txid); return m_result->BuildRequestMessage(txid);

@ -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

@ -64,7 +64,7 @@ namespace llarp
std::vector< std::unique_ptr< dht::IMessage > >& replies)); std::vector< std::unique_ptr< dht::IMessage > >& replies));
MOCK_METHOD2(RelayRequestForPath, MOCK_METHOD2(RelayRequestForPath,
bool(const PathID_t& localPath, const dht::IMessage* msg)); bool(const PathID_t& localPath, const dht::IMessage& msg));
MOCK_CONST_METHOD2(GetRCFromNodeDB, MOCK_CONST_METHOD2(GetRCFromNodeDB,
bool(const dht::Key_t& k, RouterContact& rc)); bool(const dht::Key_t& k, RouterContact& rc));

@ -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>
@ -204,9 +204,13 @@ TEST_F(TestDhtTagLookup, send_reply)
{ {
tagLookup.valuesFound.clear(); tagLookup.valuesFound.clear();
tagLookup.valuesFound.emplace_back(); tagLookup.valuesFound.emplace_back();
tagLookup.valuesFound.back().T = 1; tagLookup.valuesFound.back().T = 1;
tagLookup.valuesFound.back().A.vanity[0] = 1;
tagLookup.valuesFound.back().A.UpdateAddr();
tagLookup.valuesFound.emplace_back(); tagLookup.valuesFound.emplace_back();
tagLookup.valuesFound.back().T = 2; tagLookup.valuesFound.back().T = 2;
tagLookup.valuesFound.back().A.vanity[0] = 2;
tagLookup.valuesFound.back().A.UpdateAddr();
// clang-format off // clang-format off
EXPECT_CALL(context, FindRandomIntroSetsWithTagExcluding(_, _, _)).Times(0); EXPECT_CALL(context, FindRandomIntroSetsWithTagExcluding(_, _, _)).Times(0);

@ -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