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_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)" )
if (NOT MSVC)
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(SHADOW "use shadow testing framework. linux only" )
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)
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")
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options")
if(NOT MSVC)
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)
add_subdirectory(vendor/cxxopts)

@ -186,7 +186,7 @@ main(int argc, char *argv[])
// does this file exist?
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))
return 1;
}

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

@ -135,7 +135,7 @@ namespace llarp
/// relay a dht message from a local path to the main network
bool
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
void
@ -540,15 +540,15 @@ namespace llarp
}
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;
if(!msg->HandleMessage(router->dht(), reply.M))
if(!msg.HandleMessage(router->dht(), reply.M))
return false;
if(!reply.M.empty())
{
auto path = router->pathContext().GetByUpstream(router->pubkey(), id);
return path && path->SendRoutingMessage(&reply, router);
return path && path->SendRoutingMessage(reply, router);
}
return true;
}

@ -10,7 +10,7 @@
#include <dht/tx.hpp>
#include <dht/txholder.hpp>
#include <dht/txowner.hpp>
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <util/time.hpp>
#include <util/status.hpp>
@ -107,7 +107,7 @@ namespace llarp
std::vector< std::unique_ptr< IMessage > >& replies) = 0;
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
virtual void

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -275,7 +275,7 @@ namespace llarp
self->context->PutTransitHop(self->hop);
// send path confirmation
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 ",
self->hop->info);

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

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

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

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

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

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

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

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

@ -61,7 +61,7 @@ namespace llarp
PathTransferMessage::HandleMessage(IMessageHandler* h,
AbstractRouter* r) const
{
return h->HandlePathTransferMessage(this, r);
return h->HandlePathTransferMessage(*this, r);
}
} // 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
#include <crypto/types.hpp>
#include <service/Identity.hpp>
#include <service/identity.hpp>
#include <service/protocol.hpp>
namespace llarp

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

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

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

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

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

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

@ -2,7 +2,7 @@
#define LLARP_SERVICE_HIDDEN_SERVICE_ADDRESS_LOOKUP_HPP
#include <messages/dht.hpp>
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <service/lookup.hpp>
namespace llarp
@ -27,7 +27,7 @@ namespace llarp
bool
HandleResponse(const std::set< IntroSet >& results);
routing::IMessage*
std::unique_ptr< routing::IMessage >
BuildRequestMessage();
};
} // namespace service

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

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

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

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

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

@ -1,4 +1,4 @@
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <path/path.hpp>
@ -6,12 +6,6 @@ namespace llarp
{
namespace service
{
IntroSet::~IntroSet()
{
if(W)
delete W;
}
util::StatusObject
IntroSet::ExtractStatus() const
{
@ -49,9 +43,7 @@ namespace llarp
if(key == "w")
{
if(W)
delete W;
W = new PoW();
W = absl::make_optional< PoW >();
return W->BDecode(buf);
}
@ -122,7 +114,7 @@ namespace llarp
}
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;
llarp_buffer_t buf(tmp);
@ -156,17 +148,19 @@ namespace llarp
{
if(W
&& intro.expiresAt - W->extendedLifetime > path::default_lifetime)
{
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;
}
}
}
if(IsExpired(now))
{
llarp::LogWarn("introset expired: ", *this);
LogWarn("introset expired: ", *this);
return false;
}
return true;
@ -201,7 +195,14 @@ namespace llarp
}
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("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();
if(!msg)
return false;
auto result = path->SendRoutingMessage(msg, r);
auto result = path->SendRoutingMessage(*msg, r);
endpoint = path->Endpoint();
delete msg;
return result;
}
} // namespace service

@ -2,7 +2,7 @@
#define LLARP_SERVICE_LOOKUP_HPP
#include <routing/message.hpp>
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <set>
@ -43,12 +43,12 @@ namespace llarp
}
/// build request message for service lookup
virtual llarp::routing::IMessage*
virtual std::unique_ptr< routing::IMessage >
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
SendRequestViaPath(llarp::path::Path* p, AbstractRouter* r);
SendRequestViaPath(path::Path* p, AbstractRouter* r);
ILookupHolder* parent;
uint64_t txid;
@ -58,7 +58,7 @@ namespace llarp
util::StatusObject
ExtractStatus() const
{
auto now = llarp::time_now_ms();
auto now = time_now_ms();
util::StatusObject obj{{"txid", txid},
{"endpoint", endpoint.ToHex()},
{"name", name},

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

@ -81,10 +81,10 @@ namespace llarp
bool
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
HandleHiddenServiceFrame(path::Path* p, const ProtocolFrame* frame);
HandleHiddenServiceFrame(path::Path* p, const ProtocolFrame& frame);
std::string
Name() const override;

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

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

@ -28,20 +28,19 @@ namespace llarp
if(path)
{
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 ",
remoteIntro.router, " seqno=", sequenceNo);
LogInfo("sent intro to ", remoteIntro.pathID, " on ",
remoteIntro.router, " seqno=", sequenceNo);
lastGoodSend = m_Endpoint->Now();
++sequenceNo;
return true;
}
else
llarp::LogError("Failed to send frame on path");
LogError("Failed to send frame on path");
}
else
llarp::LogError("cannot send because we have no path to ",
remoteIntro.router);
LogError("cannot send because we have no path to ", remoteIntro.router);
return false;
}
@ -63,14 +62,13 @@ namespace llarp
// shift intro
if(MarkCurrentIntroBad(now))
{
llarp::LogInfo("intro shifted");
LogInfo("intro shifted");
}
}
auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
if(!path)
{
llarp::LogError("cannot encrypt and send: no path for intro ",
remoteIntro);
LogError("cannot encrypt and send: no path for intro ", remoteIntro);
return;
}
@ -87,28 +85,28 @@ namespace llarp
m.PutBuffer(payload);
if(!f.EncryptAndSign(crypto, m, shared, m_Endpoint->GetIdentity()))
{
llarp::LogError("failed to sign");
LogError("failed to sign");
return;
}
}
else
{
llarp::LogError("No cached session key");
LogError("No cached session key");
return;
}
msg.P = remoteIntro.pathID;
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 ",
remoteIntro.router);
LogDebug("sent message via ", remoteIntro.pathID, " on ",
remoteIntro.router);
++sequenceNo;
lastGoodSend = now;
}
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))
{
llarp::LogWarn("no good path yet, your message may drop");
LogWarn("no good path yet, your message may drop");
}
}
if(sequenceNo)

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

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

@ -15,13 +15,13 @@ namespace llarp
{
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)
{
routing::DHTMessage* msg = new routing::DHTMessage();
msg->M.emplace_back(new dht::FindIntroMessage(tag, txid));
auto msg = std::make_unique< routing::DHTMessage >();
msg->M.emplace_back(std::make_unique< dht::FindIntroMessage >(tag, txid));
lastRequest = parent->Now();
return msg;
}

@ -2,7 +2,7 @@
#define LLARP_SERVICE_TAG_LOOKUP_JOB_HPP
#include <routing/message.hpp>
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <service/lookup.hpp>
#include <service/tag.hpp>
#include <util/types.hpp>
@ -43,7 +43,7 @@ namespace llarp
return (now - lastRequest) > TTL;
}
llarp::routing::IMessage*
std::unique_ptr< routing::IMessage >
BuildRequestMessage(uint64_t txid);
bool
@ -58,7 +58,7 @@ namespace llarp
{
}
llarp::routing::IMessage*
std::unique_ptr< routing::IMessage >
BuildRequestMessage() override
{
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
using VanityNonce = llarp::AlignedBuffer< 16 >;
using VanityNonce = AlignedBuffer< 16 >;
} // namespace service
} // namespace llarp
#endif

@ -64,7 +64,7 @@ namespace llarp
std::vector< std::unique_ptr< dht::IMessage > >& replies));
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,
bool(const dht::Key_t& k, RouterContact& rc));

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

@ -3,7 +3,7 @@
#include <crypto/mock_crypto.hpp>
#include <dht/mock_context.hpp>
#include <dht/messages/gotintro.hpp>
#include <service/IntroSet.hpp>
#include <service/intro_set.hpp>
#include <test_util.hpp>
#include <gtest/gtest.h>
@ -204,9 +204,13 @@ TEST_F(TestDhtTagLookup, send_reply)
{
tagLookup.valuesFound.clear();
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.back().T = 2;
tagLookup.valuesFound.back().T = 2;
tagLookup.valuesFound.back().A.vanity[0] = 2;
tagLookup.valuesFound.back().A.UpdateAddr();
// clang-format off
EXPECT_CALL(context, FindRandomIntroSetsWithTagExcluding(_, _, _)).Times(0);

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

Loading…
Cancel
Save