More refactoring to continue to make dependency graph acylic

pull/223/head
Michael 5 years ago
parent 6e38e85a79
commit da6cdfc0b2
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -491,12 +491,12 @@ set(LIB_SRC
${DNSLIB_SRC}
${EV_SRC}
${UTP_SRC}
llarp/address_info.cpp
llarp/config.cpp
llarp/context.cpp
llarp/crypto/constants.cpp
llarp/crypto/crypto.cpp
llarp/crypto/crypto_libsodium.cpp
llarp/crypto/crypto.cpp
llarp/crypto/encrypted_frame.cpp
llarp/crypto/encrypted.cpp
llarp/crypto/types.cpp
llarp/dht/bucket.cpp
@ -522,8 +522,6 @@ set(LIB_SRC
llarp/dns.cpp
llarp/dnsc.cpp
llarp/dnsd.cpp
llarp/encrypted_frame.cpp
llarp/establish_job.cpp
llarp/exit/close_exit.cpp
llarp/exit/context.cpp
llarp/exit/endpoint.cpp
@ -534,53 +532,50 @@ set(LIB_SRC
llarp/exit/session.cpp
llarp/exit/transfer_traffic.cpp
llarp/exit/update_exit.cpp
llarp/exit_info.cpp
llarp/handlers/exit.cpp
llarp/handlers/null.cpp
llarp/handlers/tun.cpp
llarp/ip.cpp
llarp/link/curvecp.cpp
llarp/link/encoder.cpp
llarp/link/iwp.cpp
llarp/link/server.cpp
llarp/link/session.cpp
llarp/link/utp.cpp
llarp/link_intro.cpp
llarp/link_message.cpp
llarp/messages/dht.cpp
llarp/messages/dht_immediate.cpp
llarp/messages/discard.cpp
llarp/messages/exit.cpp
llarp/messages/link_intro.cpp
llarp/messages/link_message.cpp
llarp/messages/path_confirm.cpp
llarp/messages/path_latency.cpp
llarp/messages/path_transfer.cpp
llarp/messages/relay.cpp
llarp/messages/relay_commit.cpp
llarp/messages/transfer_traffic.cpp
llarp/net/address_info.cpp
llarp/net/exit_info.cpp
llarp/net/ip.cpp
llarp/net/net_int.cpp
llarp/nodedb.cpp
llarp/path/path.cpp
llarp/path/path_types.cpp
llarp/path/pathbuilder.cpp
llarp/path/pathset.cpp
llarp/path/transit_hop.cpp
llarp/pow.cpp
llarp/profiling.cpp
llarp/proofofwork.cpp
llarp/relay_commit.cpp
llarp/relay_up_down.cpp
llarp/router.cpp
llarp/router/router.cpp
llarp/router_contact.cpp
llarp/router_id.cpp
llarp/routing/dht_message.cpp
llarp/routing/handler.cpp
llarp/routing/message.cpp
llarp/routing/message_parser.cpp
llarp/routing/message.cpp
llarp/routing/path_confirm.cpp
llarp/routing/path_latency.cpp
llarp/routing/path_transfer.cpp
llarp/routing_endpoint.cpp
llarp/rpc.cpp
llarp/rpc/rpc.cpp
llarp/service/Identity.cpp
llarp/service/Intro.cpp
llarp/service/IntroSet.cpp
@ -596,7 +591,6 @@ set(LIB_SRC
llarp/service/types.cpp
llarp/service/vanity.cpp
llarp/testnet.c
llarp/transit_hop.cpp
)
set(RC_SRC

Binary file not shown.

Before

Width:  |  Height:  |  Size: 425 KiB

After

Width:  |  Height:  |  Size: 414 KiB

@ -1,11 +1,6 @@
digraph {
constants -> util;
util -> constants;
util -> win32;
android -> linux;
crypto -> constants;
crypto -> llarp;
crypto -> util;
@ -28,12 +23,11 @@ digraph {
ev -> net;
ev -> util;
ev -> win32;
exit -> crypto;
exit -> handlers;
exit -> llarp;
exit -> messages;
exit -> net;
exit -> path;
exit -> routing;
exit -> util;
@ -41,7 +35,6 @@ digraph {
handlers -> dns;
handlers -> ev;
handlers -> exit;
handlers -> llarp;
handlers -> net;
handlers -> service;
handlers -> util;
@ -49,24 +42,21 @@ digraph {
link -> constants;
link -> crypto;
link -> ev;
link -> linux;
link -> messages;
link -> net;
link -> util;
linux -> util;
messages -> crypto;
messages -> dht;
messages -> exit;
messages -> link;
messages -> llarp;
messages -> path;
messages -> routing;
messages -> service;
messages -> util;
net -> android;
net -> llarp;
net -> crypto;
net -> util;
path -> crypto;
@ -93,6 +83,8 @@ digraph {
service -> routing;
service -> util;
util -> constants;
llarp -> constants;
llarp -> crypto;
llarp -> dht;
@ -105,5 +97,6 @@ digraph {
llarp -> net;
llarp -> path;
llarp -> routing;
llarp -> service;
llarp -> util;
}

@ -6,7 +6,7 @@
#include <dnsd.hpp>
#include <ev/ev.hpp>
#include <nodedb.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/logger.h>
#include <getopt.h>

@ -1,4 +1,4 @@
#include <encrypted_frame.hpp>
#include <crypto/encrypted_frame.hpp>
#include <crypto/crypto.hpp>
#include <util/logger.hpp>

@ -1,8 +1,9 @@
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <messages/dht.hpp>
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <vector>
@ -731,7 +732,8 @@ namespace llarp
void
Start(const TXOwner &peer) override
{
parent->DHTSendTo(peer.node.as_array(), new FindRouterMessage(peer.txid, target));
parent->DHTSendTo(peer.node.as_array(),
new FindRouterMessage(peer.txid, target));
}
virtual void

@ -1,6 +1,6 @@
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,8 +1,9 @@
#include <dht/context.hpp>
#include <dht/messages/findrouter.hpp>
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,7 +1,7 @@
#include <dht/context.hpp>
#include <dht/messages/gotintro.hpp>
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,7 +1,7 @@
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -2,7 +2,7 @@
#include <dht/messages/pubintro.hpp>
#include <messages/dht.hpp>
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1 +0,0 @@
#include <establish_job.hpp>

@ -1,35 +0,0 @@
#ifndef LLARP_ESTABLISH_JOB_HPP
#define LLARP_ESTABLISH_JOB_HPP
#include <router_contact.hpp>
namespace llarp
{
struct OutboundLinkEstablishJob
{
RouterContact rc;
OutboundLinkEstablishJob(const RouterContact& remote) : rc(remote)
{
}
virtual ~OutboundLinkEstablishJob(){};
virtual void
Success() = 0;
virtual void
Failed() = 0;
virtual void
AttemptTimedout() = 0;
virtual void
Attempt() = 0;
virtual bool
ShouldRetry() const = 0;
};
} // namespace llarp
#endif

@ -1,6 +1,6 @@
#include <exit/endpoint.hpp>
#include <handlers/exit.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -2,7 +2,7 @@
#define LLARP_EXIT_ENDPOINT_HPP
#include <crypto/types.hpp>
#include <ip.hpp>
#include <net/ip.hpp>
#include <path/path.hpp>
#include <util/time.hpp>

@ -1,6 +1,6 @@
#include <exit/session.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,9 +1,9 @@
#ifndef LLARP_EXIT_SESSION_HPP
#define LLARP_EXIT_SESSION_HPP
#include <ip.hpp>
#include <messages/exit.hpp>
#include <messages/transfer_traffic.hpp>
#include <net/ip.hpp>
#include <path/pathbuilder.hpp>
#include <deque>

@ -2,7 +2,7 @@
#include <dns/dns.hpp>
#include <net/net.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/str.hpp>
#include <cassert>

@ -10,7 +10,7 @@
#include <dns/dns.hpp>
#include <ev/ev.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -3,7 +3,7 @@
#include <dns/server.hpp>
#include <ev/ev.h>
#include <ip.hpp>
#include <net/ip.hpp>
#include <net/net.hpp>
#include <service/endpoint.hpp>
#include <util/codel.hpp>

@ -1,5 +1,5 @@
#include <link/iwp_internal.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -3,7 +3,7 @@
#include <link/server.hpp>
#include <messages/discard.hpp>
#include <messages/link_intro.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1,175 +0,0 @@
#include <messages/link_intro.hpp>
#include <router_contact.hpp>
#include <router.hpp>
#include <util/bencode.h>
#include <util/logger.hpp>
namespace llarp
{
LinkIntroMessage::~LinkIntroMessage()
{
}
bool
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "a"))
{
llarp_buffer_t strbuf;
if(!bencode_read_string(buf, &strbuf))
return false;
if(strbuf.sz != 1)
return false;
return *strbuf.cur == 'i';
}
if(llarp_buffer_eq(key, "n"))
{
if(N.BDecode(buf))
return true;
llarp::LogWarn("failed to decode nonce in LIM");
return false;
}
if(llarp_buffer_eq(key, "p"))
{
return bencode_read_integer(buf, &P);
}
if(llarp_buffer_eq(key, "r"))
{
if(rc.BDecode(buf))
return true;
llarp::LogWarn("failed to decode RC in LIM");
llarp::DumpBuffer(*buf);
return false;
}
else if(llarp_buffer_eq(key, "v"))
{
if(!bencode_read_integer(buf, &version))
return false;
if(version != LLARP_PROTO_VERSION)
{
llarp::LogWarn("llarp protocol version missmatch ", version,
" != ", LLARP_PROTO_VERSION);
return false;
}
llarp::LogDebug("LIM version ", version);
return true;
}
else if(llarp_buffer_eq(key, "z"))
{
return Z.BDecode(buf);
}
else
{
llarp::LogWarn("invalid LIM key: ", *key.cur);
return false;
}
}
bool
LinkIntroMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!bencode_write_bytestring(buf, "a", 1))
return false;
if(!bencode_write_bytestring(buf, "i", 1))
return false;
if(!bencode_write_bytestring(buf, "n", 1))
return false;
if(!N.BEncode(buf))
return false;
if(!bencode_write_bytestring(buf, "p", 1))
return false;
if(!bencode_write_uint64(buf, P))
return false;
if(!bencode_write_bytestring(buf, "r", 1))
return false;
if(!rc.BEncode(buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(!bencode_write_bytestring(buf, "z", 1))
return false;
if(!Z.BEncode(buf))
return false;
return bencode_end(buf);
}
LinkIntroMessage&
LinkIntroMessage::operator=(const LinkIntroMessage& msg)
{
version = msg.version;
Z = msg.Z;
rc = msg.rc;
N = msg.N;
P = msg.P;
return *this;
}
bool
LinkIntroMessage::HandleMessage(llarp::Router* router) const
{
if(!Verify(&router->crypto))
return false;
return session->GotLIM(this);
}
void
LinkIntroMessage::Clear()
{
P = 0;
N.Zero();
rc.Clear();
Z.Zero();
}
bool
LinkIntroMessage::Sign(
std::function< bool(Signature&, llarp_buffer_t) > signer)
{
Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
return signer(Z, buf);
}
bool
LinkIntroMessage::Verify(llarp::Crypto* c) const
{
LinkIntroMessage copy;
copy = *this;
copy.Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!copy.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// outer signature
if(!c->verify(rc.pubkey, buf, Z))
{
llarp::LogError("outer signature failure");
return false;
}
// verify RC
if(!rc.Verify(c, llarp::time_now_ms()))
{
llarp::LogError("invalid RC in link intro");
return false;
}
return true;
}
} // namespace llarp

@ -2,7 +2,7 @@
#define LLARP_MESSAGES_DHT_IMMEDIATE_HPP
#include <dht/message.hpp>
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <vector>

@ -1,7 +1,7 @@
#ifndef LLARP_MESSAGES_DISCARD_HPP
#define LLARP_MESSAGES_DISCARD_HPP
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <routing/handler.hpp>
#include <routing/message.hpp>
#include <util/bencode.hpp>
@ -61,7 +61,10 @@ namespace llarp
version = LLARP_PROTO_VERSION;
}
void Clear() override {}
void
Clear() override
{
}
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override

@ -1 +1,175 @@
#include <messages/link_intro.hpp>
#include <router_contact.hpp>
#include <router/router.hpp>
#include <util/bencode.h>
#include <util/logger.hpp>
namespace llarp
{
LinkIntroMessage::~LinkIntroMessage()
{
}
bool
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "a"))
{
llarp_buffer_t strbuf;
if(!bencode_read_string(buf, &strbuf))
return false;
if(strbuf.sz != 1)
return false;
return *strbuf.cur == 'i';
}
if(llarp_buffer_eq(key, "n"))
{
if(N.BDecode(buf))
return true;
llarp::LogWarn("failed to decode nonce in LIM");
return false;
}
if(llarp_buffer_eq(key, "p"))
{
return bencode_read_integer(buf, &P);
}
if(llarp_buffer_eq(key, "r"))
{
if(rc.BDecode(buf))
return true;
llarp::LogWarn("failed to decode RC in LIM");
llarp::DumpBuffer(*buf);
return false;
}
else if(llarp_buffer_eq(key, "v"))
{
if(!bencode_read_integer(buf, &version))
return false;
if(version != LLARP_PROTO_VERSION)
{
llarp::LogWarn("llarp protocol version missmatch ", version,
" != ", LLARP_PROTO_VERSION);
return false;
}
llarp::LogDebug("LIM version ", version);
return true;
}
else if(llarp_buffer_eq(key, "z"))
{
return Z.BDecode(buf);
}
else
{
llarp::LogWarn("invalid LIM key: ", *key.cur);
return false;
}
}
bool
LinkIntroMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!bencode_write_bytestring(buf, "a", 1))
return false;
if(!bencode_write_bytestring(buf, "i", 1))
return false;
if(!bencode_write_bytestring(buf, "n", 1))
return false;
if(!N.BEncode(buf))
return false;
if(!bencode_write_bytestring(buf, "p", 1))
return false;
if(!bencode_write_uint64(buf, P))
return false;
if(!bencode_write_bytestring(buf, "r", 1))
return false;
if(!rc.BEncode(buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(!bencode_write_bytestring(buf, "z", 1))
return false;
if(!Z.BEncode(buf))
return false;
return bencode_end(buf);
}
LinkIntroMessage&
LinkIntroMessage::operator=(const LinkIntroMessage& msg)
{
version = msg.version;
Z = msg.Z;
rc = msg.rc;
N = msg.N;
P = msg.P;
return *this;
}
bool
LinkIntroMessage::HandleMessage(llarp::Router* router) const
{
if(!Verify(&router->crypto))
return false;
return session->GotLIM(this);
}
void
LinkIntroMessage::Clear()
{
P = 0;
N.Zero();
rc.Clear();
Z.Zero();
}
bool
LinkIntroMessage::Sign(
std::function< bool(Signature&, llarp_buffer_t) > signer)
{
Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
return signer(Z, buf);
}
bool
LinkIntroMessage::Verify(llarp::Crypto* c) const
{
LinkIntroMessage copy;
copy = *this;
copy.Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!copy.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// outer signature
if(!c->verify(rc.pubkey, buf, Z))
{
llarp::LogError("outer signature failure");
return false;
}
// verify RC
if(!rc.Verify(c, llarp::time_now_ms()))
{
llarp::LogError("invalid RC in link intro");
return false;
}
return true;
}
} // namespace llarp

@ -2,7 +2,7 @@
#define LLARP_MESSAGES_LINK_INTRO_HPP
#include <crypto/types.hpp>
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <router_contact.hpp>
namespace llarp

@ -1,4 +1,4 @@
#include <link_message_parser.hpp>
#include <messages/link_message_parser.hpp>
#include <router_contact.hpp>
#include <util/buffer.hpp>

@ -1,10 +1,10 @@
#ifndef LLARP_LINK_MESSAGE_PARSER_HPP
#define LLARP_LINK_MESSAGE_PARSER_HPP
#include <link_message.hpp>
#include <messages/discard.hpp>
#include <messages/dht_immediate.hpp>
#include <messages/link_intro.hpp>
#include <messages/link_message.hpp>
#include <messages/relay.hpp>
#include <messages/relay_commit.hpp>

@ -1 +1,132 @@
#include <messages/relay.hpp>
#include <router/router.hpp>
#include <util/bencode.hpp>
namespace llarp
{
RelayUpstreamMessage::RelayUpstreamMessage() : ILinkMessage()
{
}
RelayUpstreamMessage::~RelayUpstreamMessage()
{
}
void
RelayUpstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayUpstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "u"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayUpstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByDownstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, r);
}
return false;
}
RelayDownstreamMessage::RelayDownstreamMessage() : ILinkMessage()
{
}
RelayDownstreamMessage::~RelayDownstreamMessage()
{
}
void
RelayDownstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayDownstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "d"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayDownstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayDownstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByUpstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleDownstream(X.Buffer(), Y, r);
}
llarp::LogWarn("unhandled downstream message");
return false;
}
} // namespace llarp

@ -3,7 +3,7 @@
#include <crypto/encrypted.hpp>
#include <crypto/types.hpp>
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <path/path_types.hpp>
#include <vector>

@ -1 +1,345 @@
#include <messages/relay_commit.hpp>
#include <messages/path_confirm.hpp>
#include <path/path.hpp>
#include <router/router.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
namespace llarp
{
LR_CommitMessage::~LR_CommitMessage()
{
}
bool
LR_CommitMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "c"))
{
return BEncodeReadArray(frames, buf);
}
bool read = false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
return read;
}
void
LR_CommitMessage::Clear()
{
frames[0].Clear();
frames[1].Clear();
frames[2].Clear();
frames[3].Clear();
frames[4].Clear();
frames[5].Clear();
frames[6].Clear();
frames[7].Clear();
}
bool
LR_CommitMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
// msg type
if(!BEncodeWriteDictMsgType(buf, "a", "c"))
return false;
// frames
if(!BEncodeWriteDictArray("c", frames, buf))
return false;
// version
if(!bencode_write_version_entry(buf))
return false;
return bencode_end(buf);
}
bool
LR_CommitMessage::HandleMessage(llarp::Router* router) const
{
if(frames.size() != MAXHOPS)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
return false;
}
if(!router->paths.AllowingTransit())
{
llarp::LogError("got LRCM when not permitting transit");
return false;
}
return AsyncDecrypt(&router->paths);
}
bool
LR_CommitRecord::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("c", commkey, buf))
return false;
if(!BEncodeWriteDictEntry("i", nextHop, buf))
return false;
if(lifetime > 10 && lifetime < 600)
{
if(!BEncodeWriteDictInt("i", lifetime, buf))
return false;
}
if(!BEncodeWriteDictEntry("n", tunnelNonce, buf))
return false;
if(!BEncodeWriteDictEntry("r", rxid, buf))
return false;
if(!BEncodeWriteDictEntry("t", txid, buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(work && !BEncodeWriteDictEntry("w", *work, buf))
return false;
return bencode_end(buf);
}
LR_CommitRecord::~LR_CommitRecord()
{
if(work)
delete work;
}
bool
LR_CommitRecord::OnKey(dict_reader* r, llarp_buffer_t* key)
{
if(!key)
return true;
LR_CommitRecord* self = static_cast< LR_CommitRecord* >(r->user);
bool read = false;
if(!BEncodeMaybeReadDictEntry("c", self->commkey, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("i", self->nextHop, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictInt("l", self->lifetime, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("n", self->tunnelNonce, read, *key,
r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("r", self->rxid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("t", self->txid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadVersion("v", self->version, LLARP_PROTO_VERSION, read,
*key, r->buffer))
return false;
if(llarp_buffer_eq(*key, "w"))
{
// check for duplicate
if(self->work)
{
llarp::LogWarn("duplicate POW in LRCR");
return false;
}
self->work = new PoW();
return self->work->BDecode(r->buffer);
}
return read;
}
bool
LR_CommitRecord::BDecode(llarp_buffer_t* buf)
{
dict_reader r;
r.user = this;
r.on_key = &OnKey;
return bencode_read_dict(buf, &r);
}
bool
LR_CommitRecord::operator==(const LR_CommitRecord& other) const
{
if(work && other.work)
{
if(*work != *other.work)
return false;
}
return nextHop == other.nextHop && commkey == other.commkey
&& txid == other.txid && rxid == other.rxid;
}
struct LRCMFrameDecrypt
{
typedef llarp::path::PathContext Context;
typedef llarp::path::TransitHop Hop;
typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter;
Decrypter* decrypter;
std::array< EncryptedFrame, 8 > frames;
Context* context;
// decrypted record
LR_CommitRecord record;
// the actual hop
std::shared_ptr< Hop > hop;
LRCMFrameDecrypt(Context* ctx, Decrypter* dec,
const LR_CommitMessage* commit)
: decrypter(dec), frames(commit->frames), context(ctx), hop(new Hop())
{
hop->info.downstream = commit->session->GetPubKey();
}
~LRCMFrameDecrypt()
{
delete decrypter;
}
/// this is done from logic thread
static void
SendLRCM(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist sessions to upstream and downstream routers until the commit
// ends
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// forward to next hop
self->context->ForwardLRCM(self->hop->info.upstream, self->frames);
self->hop = nullptr;
delete self;
}
// this is called from the logic thread
static void
SendPathConfirm(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist session to downstream until path expiration
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// send path confirmation
llarp::routing::PathConfirmMessage confirm(self->hop->lifetime);
if(!self->hop->SendRoutingMessage(&confirm, self->context->Router()))
{
llarp::LogError("failed to send path confirmation for ",
self->hop->info);
}
self->hop = nullptr;
delete self;
}
static void
HandleDecrypted(llarp_buffer_t* buf, LRCMFrameDecrypt* self)
{
auto now = self->context->Router()->Now();
auto& info = self->hop->info;
if(!buf)
{
llarp::LogError("LRCM decrypt failed from ", info.downstream);
delete self;
return;
}
buf->cur = buf->base + EncryptedFrameOverheadSize;
llarp::LogDebug("decrypted LRCM from ", info.downstream);
// successful decrypt
if(!self->record.BDecode(buf))
{
llarp::LogError("malformed frame inside LRCM from ", info.downstream);
delete self;
return;
}
info.txID = self->record.txid;
info.rxID = self->record.rxid;
info.upstream = self->record.nextHop;
if(self->context->HasTransitHop(info))
{
llarp::LogError("duplicate transit hop ", info);
delete self;
return;
}
// generate path key as we are in a worker thread
auto DH = self->context->Crypto()->dh_server;
if(!DH(self->hop->pathKey, self->record.commkey,
self->context->EncryptionSecretKey(), self->record.tunnelNonce))
{
llarp::LogError("LRCM DH Failed ", info);
delete self;
return;
}
// generate hash of hop key for nonce mutation
self->context->Crypto()->shorthash(self->hop->nonceXOR,
self->hop->pathKey.as_buffer());
if(self->record.work
&& self->record.work->IsValid(self->context->Crypto()->shorthash, now))
{
llarp::LogDebug("LRCM extended lifetime by ",
self->record.work->extendedLifetime, " seconds for ",
info);
self->hop->lifetime += 1000 * self->record.work->extendedLifetime;
}
else if(self->record.lifetime < 600 && self->record.lifetime > 10)
{
self->hop->lifetime = self->record.lifetime;
llarp::LogDebug("LRCM short lifespan set to ", self->hop->lifetime,
" seconds for ", info);
}
// TODO: check if we really want to accept it
self->hop->started = now;
size_t sz = self->frames[0].size();
// shift
std::array< EncryptedFrame, 8 > frames;
frames[0] = self->frames[1];
frames[1] = self->frames[2];
frames[2] = self->frames[3];
frames[3] = self->frames[4];
frames[4] = self->frames[5];
frames[5] = self->frames[6];
frames[6] = self->frames[7];
// put our response on the end
frames[7] = EncryptedFrame(sz - EncryptedFrameOverheadSize);
// random junk for now
frames[7].Randomize();
self->frames = std::move(frames);
if(self->context->HopIsUs(info.upstream))
{
// we are the farthest hop
llarp::LogDebug("We are the farthest hop for ", info);
// send a LRAM down the path
self->context->Logic()->queue_job({self, &SendPathConfirm});
}
else
{
// forward upstream
// we are still in the worker thread so post job to logic
self->context->Logic()->queue_job({self, &SendLRCM});
}
}
};
bool
LR_CommitMessage::AsyncDecrypt(llarp::path::PathContext* context) const
{
LRCMFrameDecrypt::Decrypter* decrypter = new LRCMFrameDecrypt::Decrypter(
context->Crypto(), context->EncryptionSecretKey(),
&LRCMFrameDecrypt::HandleDecrypted);
// copy frames so we own them
LRCMFrameDecrypt* frames = new LRCMFrameDecrypt(context, decrypter, this);
// decrypt frames async
decrypter->AsyncDecrypt(context->Worker(), frames->frames[0], frames);
return true;
}
} // namespace llarp

@ -1,9 +1,9 @@
#ifndef LLARP_RELAY_COMMIT_HPP
#define LLARP_RELAY_COMMIT_HPP
#include <crypto/encrypted_frame.hpp>
#include <crypto/types.hpp>
#include <encrypted_frame.hpp>
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <path/path_types.hpp>
#include <pow.hpp>

@ -1,4 +1,5 @@
#include <address_info.hpp>
#include <net/address_info.hpp>
#ifndef _WIN32
#include <arpa/inet.h>
#endif

@ -2,7 +2,7 @@
#include <arpa/inet.h>
#endif
#include <exit_info.hpp>
#include <net/exit_info.hpp>
#include <util/bencode.h>
#include <util/mem.h>

@ -1,4 +1,4 @@
#include <ip.hpp>
#include <net/ip.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_NET_HPP
#define LLARP_NET_HPP
#include <address_info.hpp>
#include <net/address_info.hpp>
#include <net/net_int.hpp>
#include <net/net.h>
#include <util/logger.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_NET_ADDR_HPP
#define LLARP_NET_ADDR_HPP
#include <address_info.hpp>
#include <net/address_info.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/string_view.hpp>

@ -1,10 +1,9 @@
#include <path/path.hpp>
#include <encrypted_frame.hpp>
#include <messages/dht.hpp>
#include <messages/discard.hpp>
#include <path/pathbuilder.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1,8 +1,8 @@
#ifndef LLARP_PATH_HPP
#define LLARP_PATH_HPP
#include <crypto/encrypted_frame.hpp>
#include <crypto/types.hpp>
#include <messages/relay_commit.hpp>
#include <messages/relay.hpp>
#include <path/path_types.hpp>
#include <path/pathbuilder.hpp>
@ -33,6 +33,8 @@
namespace llarp
{
struct Crypto;
struct LR_CommitMessage;
struct LR_CommitRecord;
namespace path
{
struct TransitHopInfo

@ -2,7 +2,7 @@
#include <nodedb.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <functional>

@ -2,7 +2,7 @@
#include <dht/context.hpp>
#include <messages/discard.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1 +1,58 @@
#include <pow.hpp>
#include <util/buffer.hpp>
#include <cmath>
namespace llarp
{
PoW::~PoW()
{
}
bool
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
return false;
}
bool
PoW::BEncode(llarp_buffer_t* buf) const
{
// TODO: implement me
if(!bencode_start_dict(buf))
return false;
return bencode_end(buf);
}
bool
PoW::IsValid(shorthash_func hashfunc, llarp_time_t now) const
{
if(now - timestamp > (uint64_t(extendedLifetime) * 1000))
return false;
ShortHash digest;
byte_t tmp[MaxSize];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
// encode
if(!BEncode(&buf))
return false;
// rewind
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// hash
if(!hashfunc(digest, buf))
return false;
// check bytes required
uint32_t required = std::floor(std::log(extendedLifetime));
for(uint32_t idx = 0; idx < required; ++idx)
{
if(digest[idx])
return false;
}
return true;
}
} // namespace llarp

@ -1,58 +0,0 @@
#include <pow.hpp>
#include <util/buffer.hpp>
#include <cmath>
namespace llarp
{
PoW::~PoW()
{
}
bool
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
return false;
}
bool
PoW::BEncode(llarp_buffer_t* buf) const
{
// TODO: implement me
if(!bencode_start_dict(buf))
return false;
return bencode_end(buf);
}
bool
PoW::IsValid(shorthash_func hashfunc, llarp_time_t now) const
{
if(now - timestamp > (uint64_t(extendedLifetime) * 1000))
return false;
ShortHash digest;
byte_t tmp[MaxSize];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
// encode
if(!BEncode(&buf))
return false;
// rewind
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// hash
if(!hashfunc(digest, buf))
return false;
// check bytes required
uint32_t required = std::floor(std::log(extendedLifetime));
for(uint32_t idx = 0; idx < required; ++idx)
{
if(digest[idx])
return false;
}
return true;
}
} // namespace llarp

@ -1,344 +0,0 @@
#include <messages/path_confirm.hpp>
#include <messages/relay_commit.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
namespace llarp
{
LR_CommitMessage::~LR_CommitMessage()
{
}
bool
LR_CommitMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "c"))
{
return BEncodeReadArray(frames, buf);
}
bool read = false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
return read;
}
void
LR_CommitMessage::Clear()
{
frames[0].Clear();
frames[1].Clear();
frames[2].Clear();
frames[3].Clear();
frames[4].Clear();
frames[5].Clear();
frames[6].Clear();
frames[7].Clear();
}
bool
LR_CommitMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
// msg type
if(!BEncodeWriteDictMsgType(buf, "a", "c"))
return false;
// frames
if(!BEncodeWriteDictArray("c", frames, buf))
return false;
// version
if(!bencode_write_version_entry(buf))
return false;
return bencode_end(buf);
}
bool
LR_CommitMessage::HandleMessage(llarp::Router* router) const
{
if(frames.size() != MAXHOPS)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
return false;
}
if(!router->paths.AllowingTransit())
{
llarp::LogError("got LRCM when not permitting transit");
return false;
}
return AsyncDecrypt(&router->paths);
}
bool
LR_CommitRecord::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("c", commkey, buf))
return false;
if(!BEncodeWriteDictEntry("i", nextHop, buf))
return false;
if(lifetime > 10 && lifetime < 600)
{
if(!BEncodeWriteDictInt("i", lifetime, buf))
return false;
}
if(!BEncodeWriteDictEntry("n", tunnelNonce, buf))
return false;
if(!BEncodeWriteDictEntry("r", rxid, buf))
return false;
if(!BEncodeWriteDictEntry("t", txid, buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(work && !BEncodeWriteDictEntry("w", *work, buf))
return false;
return bencode_end(buf);
}
LR_CommitRecord::~LR_CommitRecord()
{
if(work)
delete work;
}
bool
LR_CommitRecord::OnKey(dict_reader* r, llarp_buffer_t* key)
{
if(!key)
return true;
LR_CommitRecord* self = static_cast< LR_CommitRecord* >(r->user);
bool read = false;
if(!BEncodeMaybeReadDictEntry("c", self->commkey, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("i", self->nextHop, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictInt("l", self->lifetime, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("n", self->tunnelNonce, read, *key,
r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("r", self->rxid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("t", self->txid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadVersion("v", self->version, LLARP_PROTO_VERSION, read,
*key, r->buffer))
return false;
if(llarp_buffer_eq(*key, "w"))
{
// check for duplicate
if(self->work)
{
llarp::LogWarn("duplicate POW in LRCR");
return false;
}
self->work = new PoW();
return self->work->BDecode(r->buffer);
}
return read;
}
bool
LR_CommitRecord::BDecode(llarp_buffer_t* buf)
{
dict_reader r;
r.user = this;
r.on_key = &OnKey;
return bencode_read_dict(buf, &r);
}
bool
LR_CommitRecord::operator==(const LR_CommitRecord& other) const
{
if(work && other.work)
{
if(*work != *other.work)
return false;
}
return nextHop == other.nextHop && commkey == other.commkey
&& txid == other.txid && rxid == other.rxid;
}
struct LRCMFrameDecrypt
{
typedef llarp::path::PathContext Context;
typedef llarp::path::TransitHop Hop;
typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter;
Decrypter* decrypter;
std::array< EncryptedFrame, 8 > frames;
Context* context;
// decrypted record
LR_CommitRecord record;
// the actual hop
std::shared_ptr< Hop > hop;
LRCMFrameDecrypt(Context* ctx, Decrypter* dec,
const LR_CommitMessage* commit)
: decrypter(dec), frames(commit->frames), context(ctx), hop(new Hop())
{
hop->info.downstream = commit->session->GetPubKey();
}
~LRCMFrameDecrypt()
{
delete decrypter;
}
/// this is done from logic thread
static void
SendLRCM(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist sessions to upstream and downstream routers until the commit
// ends
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// forward to next hop
self->context->ForwardLRCM(self->hop->info.upstream, self->frames);
self->hop = nullptr;
delete self;
}
// this is called from the logic thread
static void
SendPathConfirm(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist session to downstream until path expiration
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// send path confirmation
llarp::routing::PathConfirmMessage confirm(self->hop->lifetime);
if(!self->hop->SendRoutingMessage(&confirm, self->context->Router()))
{
llarp::LogError("failed to send path confirmation for ",
self->hop->info);
}
self->hop = nullptr;
delete self;
}
static void
HandleDecrypted(llarp_buffer_t* buf, LRCMFrameDecrypt* self)
{
auto now = self->context->Router()->Now();
auto& info = self->hop->info;
if(!buf)
{
llarp::LogError("LRCM decrypt failed from ", info.downstream);
delete self;
return;
}
buf->cur = buf->base + EncryptedFrameOverheadSize;
llarp::LogDebug("decrypted LRCM from ", info.downstream);
// successful decrypt
if(!self->record.BDecode(buf))
{
llarp::LogError("malformed frame inside LRCM from ", info.downstream);
delete self;
return;
}
info.txID = self->record.txid;
info.rxID = self->record.rxid;
info.upstream = self->record.nextHop;
if(self->context->HasTransitHop(info))
{
llarp::LogError("duplicate transit hop ", info);
delete self;
return;
}
// generate path key as we are in a worker thread
auto DH = self->context->Crypto()->dh_server;
if(!DH(self->hop->pathKey, self->record.commkey,
self->context->EncryptionSecretKey(), self->record.tunnelNonce))
{
llarp::LogError("LRCM DH Failed ", info);
delete self;
return;
}
// generate hash of hop key for nonce mutation
self->context->Crypto()->shorthash(self->hop->nonceXOR,
self->hop->pathKey.as_buffer());
if(self->record.work
&& self->record.work->IsValid(self->context->Crypto()->shorthash, now))
{
llarp::LogDebug("LRCM extended lifetime by ",
self->record.work->extendedLifetime, " seconds for ",
info);
self->hop->lifetime += 1000 * self->record.work->extendedLifetime;
}
else if(self->record.lifetime < 600 && self->record.lifetime > 10)
{
self->hop->lifetime = self->record.lifetime;
llarp::LogDebug("LRCM short lifespan set to ", self->hop->lifetime,
" seconds for ", info);
}
// TODO: check if we really want to accept it
self->hop->started = now;
size_t sz = self->frames[0].size();
// shift
std::array< EncryptedFrame, 8 > frames;
frames[0] = self->frames[1];
frames[1] = self->frames[2];
frames[2] = self->frames[3];
frames[3] = self->frames[4];
frames[4] = self->frames[5];
frames[5] = self->frames[6];
frames[6] = self->frames[7];
// put our response on the end
frames[7] = EncryptedFrame(sz - EncryptedFrameOverheadSize);
// random junk for now
frames[7].Randomize();
self->frames = std::move(frames);
if(self->context->HopIsUs(info.upstream))
{
// we are the farthest hop
llarp::LogDebug("We are the farthest hop for ", info);
// send a LRAM down the path
self->context->Logic()->queue_job({self, &SendPathConfirm});
}
else
{
// forward upstream
// we are still in the worker thread so post job to logic
self->context->Logic()->queue_job({self, &SendLRCM});
}
}
};
bool
LR_CommitMessage::AsyncDecrypt(llarp::path::PathContext* context) const
{
LRCMFrameDecrypt::Decrypter* decrypter = new LRCMFrameDecrypt::Decrypter(
context->Crypto(), context->EncryptionSecretKey(),
&LRCMFrameDecrypt::HandleDecrypted);
// copy frames so we own them
LRCMFrameDecrypt* frames = new LRCMFrameDecrypt(context, decrypter, this);
// decrypt frames async
decrypter->AsyncDecrypt(context->Worker(), frames->frames[0], frames);
return true;
}
} // namespace llarp

@ -1,131 +0,0 @@
#include <messages/relay.hpp>
#include <router.hpp>
#include <util/bencode.hpp>
namespace llarp
{
RelayUpstreamMessage::RelayUpstreamMessage() : ILinkMessage()
{
}
RelayUpstreamMessage::~RelayUpstreamMessage()
{
}
void
RelayUpstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayUpstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "u"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayUpstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByDownstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, r);
}
return false;
}
RelayDownstreamMessage::RelayDownstreamMessage() : ILinkMessage()
{
}
RelayDownstreamMessage::~RelayDownstreamMessage()
{
}
void
RelayDownstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayDownstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "d"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayDownstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayDownstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByUpstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleDownstream(X.Buffer(), Y, r);
}
llarp::LogWarn("unhandled downstream message");
return false;
}
} // namespace llarp

@ -1,14 +1,14 @@
#include <router.hpp>
#include <router/router.hpp>
#include <constants/proto.hpp>
#include <crypto/crypto.hpp>
#include <dht/context.hpp>
#include <link_message.hpp>
#include <link/iwp.hpp>
#include <link/server.hpp>
#include <link/utp.hpp>
#include <messages/link_message.hpp>
#include <net/net.hpp>
#include <rpc.hpp>
#include <rpc/rpc.hpp>
#include <util/buffer.hpp>
#include <util/encode.hpp>
#include <util/logger.hpp>

@ -4,18 +4,17 @@
#include <config.h>
#include <constants/link_layer.hpp>
#include <crypto/types.hpp>
#include <establish_job.hpp>
#include <ev/ev.h>
#include <exit/context.hpp>
#include <handlers/tun.hpp>
#include <link_message_parser.hpp>
#include <messages/link_message_parser.hpp>
#include <nodedb.hpp>
#include <path/path.hpp>
#include <profiling.hpp>
#include <router_contact.hpp>
#include <routing/handler.hpp>
#include <routing/message_parser.hpp>
#include <rpc.hpp>
#include <rpc/rpc.hpp>
#include <service/context.hpp>
#include <util/buffer.h>
#include <util/fs.hpp>

@ -1,10 +1,10 @@
#ifndef LLARP_RC_HPP
#define LLARP_RC_HPP
#include <address_info.hpp>
#include <constants/version.hpp>
#include <crypto/types.hpp>
#include <exit_info.hpp>
#include <net/address_info.hpp>
#include <net/exit_info.hpp>
#include <util/aligned.hpp>
#include <util/bencode.hpp>

@ -1,5 +1,6 @@
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,6 +1,6 @@
#include <messages/path_transfer.hpp>
#include <router.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
namespace llarp

@ -1 +0,0 @@
#include <routing_endpoint.hpp>

@ -1,18 +0,0 @@
#ifndef LLARP_ROUTING_ENDPOINT_HPP
#define LLARP_ROUTING_ENDPOINT_HPP
#include <util/aligned.hpp>
#include <util/buffer.h>
namespace llarp
{
using RoutingEndpoint_t = AlignedBuffer< 32 >;
/// Interface for end to end crypto between endpoints
struct IRoutingEndpoint
{
virtual ~IRoutingEndpoint(){};
};
} // namespace llarp
#endif

@ -1,9 +1,11 @@
#include <router.hpp>
#include <rpc.hpp>
#include <rpc/rpc.hpp>
#include <router/router.hpp>
#ifdef USE_ABYSS
#include <libabyss.hpp>
#endif
namespace llarp
{
namespace rpc
@ -51,7 +53,7 @@ namespace llarp
struct GetServiceNodeListHandler final : public CallerHandler
{
using PubkeyList_t = std::vector< llarp::PubKey >;
using PubkeyList_t = std::vector< PubKey >;
using Callback_t = std::function< void(const PubkeyList_t&, bool) >;
~GetServiceNodeListHandler()
@ -90,7 +92,8 @@ namespace llarp
if(key_itr->IsString())
{
keys.emplace_back();
if(!HexDecode(key_itr->GetString(), keys.back().begin(), decltype(keys)::value_type::SIZE))
if(!HexDecode(key_itr->GetString(), keys.back().begin(),
decltype(keys)::value_type::SIZE))
{
keys.pop_back();
}
@ -110,12 +113,12 @@ namespace llarp
struct CallerImpl : public ::abyss::http::JSONRPC
{
llarp::Router* router;
Router* router;
llarp_time_t m_NextKeyUpdate;
const llarp_time_t KeyUpdateInterval = 1000 * 60 * 2;
using PubkeyList_t = GetServiceNodeListHandler::PubkeyList_t;
CallerImpl(llarp::Router* r) : ::abyss::http::JSONRPC(), router(r)
CallerImpl(Router* r) : ::abyss::http::JSONRPC(), router(r)
{
}
@ -133,7 +136,7 @@ namespace llarp
void
AsyncUpdatePubkeyList()
{
llarp::LogInfo("Updating service node list");
LogInfo("Updating service node list");
::abyss::json::Value params;
params.SetObject();
QueueRPC("/get_all_service_node_keys", std::move(params),
@ -165,11 +168,11 @@ namespace llarp
for(const auto& pk : list)
router->lokinetRouters.insert(std::make_pair(
pk.data(), std::numeric_limits< llarp_time_t >::max()));
llarp::LogInfo("updated service node list, we have ",
router->lokinetRouters.size(), " authorized routers");
LogInfo("updated service node list, we have ",
router->lokinetRouters.size(), " authorized routers");
}
else
llarp::LogError("service node list not updated");
LogError("service node list not updated");
}
~CallerImpl()
@ -179,8 +182,8 @@ namespace llarp
struct Handler : public ::abyss::httpd::IRPCHandler
{
llarp::Router* router;
Handler(::abyss::httpd::ConnImpl* conn, llarp::Router* r)
Router* router;
Handler(::abyss::httpd::ConnImpl* conn, Router* r)
: ::abyss::httpd::IRPCHandler(conn), router(r)
{
}
@ -192,7 +195,7 @@ namespace llarp
bool
ListExitLevels(Response& resp) const
{
llarp::exit::Context::TrafficStats stats;
exit::Context::TrafficStats stats;
router->exitContext.CalculateExitTraffic(stats);
auto& alloc = resp.GetAllocator();
abyss::json::Value exits;
@ -219,23 +222,22 @@ namespace llarp
auto& alloc = resp.GetAllocator();
abyss::json::Value peers;
peers.SetArray();
router->ForEachPeer(
[&](const llarp::ILinkSession* session, bool outbound) {
abyss::json::Value peer;
peer.SetObject();
abyss::json::Value ident_val, addr_val;
auto ident = RouterID(session->GetPubKey()).ToString();
ident_val.SetString(ident.c_str(), alloc);
auto addr = session->GetRemoteEndpoint().ToString();
addr_val.SetString(addr.c_str(), alloc);
peer.AddMember("addr", addr_val, alloc);
peer.AddMember("ident", ident_val, alloc);
peer.AddMember("outbound", abyss::json::Value(outbound), alloc);
peers.PushBack(peer, alloc);
});
router->ForEachPeer([&](const ILinkSession* session, bool outbound) {
abyss::json::Value peer;
peer.SetObject();
abyss::json::Value ident_val, addr_val;
auto ident = RouterID(session->GetPubKey()).ToString();
ident_val.SetString(ident.c_str(), alloc);
auto addr = session->GetRemoteEndpoint().ToString();
addr_val.SetString(addr.c_str(), alloc);
peer.AddMember("addr", addr_val, alloc);
peer.AddMember("ident", ident_val, alloc);
peer.AddMember("outbound", abyss::json::Value(outbound), alloc);
peers.PushBack(peer, alloc);
});
resp.AddMember("result", peers, alloc);
return true;
}
@ -259,11 +261,11 @@ namespace llarp
struct ReqHandlerImpl : public ::abyss::httpd::BaseReqHandler
{
ReqHandlerImpl(llarp::Router* r, llarp_time_t reqtimeout)
ReqHandlerImpl(Router* r, llarp_time_t reqtimeout)
: ::abyss::httpd::BaseReqHandler(reqtimeout), router(r)
{
}
llarp::Router* router;
Router* router;
::abyss::httpd::IRPCHandler*
CreateHandler(::abyss::httpd::ConnImpl* conn)
{
@ -273,10 +275,10 @@ namespace llarp
struct ServerImpl
{
llarp::Router* router;
Router* router;
ReqHandlerImpl _handler;
ServerImpl(llarp::Router* r) : router(r), _handler(r, 2000)
ServerImpl(Router* r) : router(r), _handler(r, 2000)
{
}
@ -295,11 +297,11 @@ namespace llarp
{
uint16_t port = 0;
auto idx = addr.find_first_of(':');
llarp::Addr netaddr;
Addr netaddr;
if(idx != std::string::npos)
{
port = std::stoi(addr.substr(1 + idx));
netaddr = llarp::Addr(addr.substr(0, idx));
netaddr = Addr(addr.substr(0, idx));
}
sockaddr_in saddr;
saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@ -312,7 +314,7 @@ namespace llarp
#else
struct ServerImpl
{
ServerImpl(__attribute__((unused)) llarp::Router* r){};
ServerImpl(__attribute__((unused)) Router* r){};
bool
Start(__attribute__((unused)) const std::string& addr)
@ -328,7 +330,7 @@ namespace llarp
struct CallerImpl
{
CallerImpl(__attribute__((unused)) llarp::Router* r)
CallerImpl(__attribute__((unused)) Router* r)
{
}
@ -356,7 +358,7 @@ namespace llarp
#endif
Caller::Caller(llarp::Router* r) : m_Impl(new CallerImpl(r))
Caller::Caller(Router* r) : m_Impl(new CallerImpl(r))
{
}
@ -383,7 +385,7 @@ namespace llarp
m_Impl->Tick(now);
}
Server::Server(llarp::Router* r) : m_Impl(new ServerImpl(r))
Server::Server(Router* r) : m_Impl(new ServerImpl(r))
{
}

@ -1,7 +1,6 @@
#ifndef LLARP_RPC_HPP
#define LLARP_RPC_HPP
#include <ev/ev.h>
#include <util/time.hpp>
#include <string>
@ -9,6 +8,7 @@
namespace llarp
{
struct PubKey;
struct Router;
namespace rpc
@ -18,7 +18,7 @@ namespace llarp
/// jsonrpc server
struct Server
{
Server(llarp::Router* r);
Server(Router* r);
~Server();
bool
@ -37,7 +37,7 @@ namespace llarp
/// jsonrpc caller
struct Caller
{
Caller(llarp::Router* r);
Caller(Router* r);
~Caller();
/// start with jsonrpc endpoint address
@ -50,7 +50,7 @@ namespace llarp
/// test if a router is valid
bool
VerifyRouter(const llarp::PubKey& pk);
VerifyRouter(const PubKey& pk);
/// do per second tick
void

@ -1,8 +1,9 @@
#include <service/context.hpp>
#include <handlers/null.hpp>
#include <handlers/tun.hpp>
#include <service/context.hpp>
#include <router/router.hpp>
#include <service/endpoint.hpp>
#include <router.hpp>
namespace llarp
{

@ -2,7 +2,7 @@
#include <dht/messages/findintro.hpp>
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <service/protocol.hpp>
#include <util/logic.hpp>

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include <exit/context.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <gtest/gtest.h>
struct ExitTest : public ::testing::Test
{

@ -1,6 +1,6 @@
#include <crypto/crypto.hpp>
#include <crypto/encrypted_frame.hpp>
#include <encrypted_frame.hpp>
#include <crypto/crypto.hpp>
#include <messages/relay_commit.hpp>
#include <gtest/gtest.h>

@ -1,4 +1,5 @@
#include <router.hpp>
#include <router/router.hpp>
#include <crypto/crypto.hpp>
#include <functional>

Loading…
Cancel
Save