mirror of https://github.com/oxen-io/lokinet
Merge remote-tracking branch 'origin/master' into ipv6-tun
This commit is contained in:
commit
5c61df08b5
|
@ -18,7 +18,7 @@ Currently:
|
|||
- succesful ping to snode (1 per second after a snode is discovered)
|
||||
- session with snode established
|
||||
- got a router from exploration
|
||||
- Hanlding DHT S or R message
|
||||
- Handling DHT S or R message
|
||||
- a path is built
|
||||
- obtained an exit via
|
||||
- granted exit
|
||||
|
|
|
@ -151,6 +151,7 @@ extern "C"
|
|||
#endif
|
||||
#if defined(__sun)
|
||||
int ip_fd;
|
||||
int reserved;
|
||||
char internal_name[IF_NAMESIZE];
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(LIB_UTIL_SRC
|
||||
constants/defaults.cpp
|
||||
constants/link_layer.cpp
|
||||
constants/path.cpp
|
||||
constants/proto.cpp
|
||||
constants/version.cpp
|
||||
util/aligned.cpp
|
||||
|
@ -162,16 +163,11 @@ set(LIB_SRC
|
|||
dns.cpp
|
||||
dnsc.cpp
|
||||
dnsd.cpp
|
||||
exit/close_exit.cpp
|
||||
exit/context.cpp
|
||||
exit/endpoint.cpp
|
||||
exit/grant_exit.cpp
|
||||
exit/obtain_exit.cpp
|
||||
exit/exit_messages.cpp
|
||||
exit/policy.cpp
|
||||
exit/reject_exit.cpp
|
||||
exit/session.cpp
|
||||
exit/transfer_traffic.cpp
|
||||
exit/update_exit.cpp
|
||||
handlers/exit.cpp
|
||||
handlers/null.cpp
|
||||
handlers/tun.cpp
|
||||
|
@ -182,22 +178,19 @@ set(LIB_SRC
|
|||
link/server.cpp
|
||||
link/session.cpp
|
||||
messages/dht_immediate.cpp
|
||||
messages/dht.cpp
|
||||
messages/discard.cpp
|
||||
messages/exit.cpp
|
||||
messages/link_intro.cpp
|
||||
messages/link_message_parser.cpp
|
||||
messages/link_message.cpp
|
||||
messages/path_confirm.cpp
|
||||
messages/path_latency.cpp
|
||||
messages/path_transfer.cpp
|
||||
messages/relay.cpp
|
||||
messages/relay_commit.cpp
|
||||
messages/transfer_traffic.cpp
|
||||
net/address_info.cpp
|
||||
net/exit_info.cpp
|
||||
nodedb.cpp
|
||||
path/path.cpp
|
||||
path/ihophandler.cpp
|
||||
path/path_context.cpp
|
||||
path/path_types.cpp
|
||||
path/path.cpp
|
||||
path/pathbuilder.cpp
|
||||
path/pathset.cpp
|
||||
path/transit_hop.cpp
|
||||
|
@ -211,9 +204,10 @@ set(LIB_SRC
|
|||
routing/handler.cpp
|
||||
routing/message_parser.cpp
|
||||
routing/message.cpp
|
||||
routing/path_confirm.cpp
|
||||
routing/path_latency.cpp
|
||||
routing/path_transfer.cpp
|
||||
routing/path_confirm_message.cpp
|
||||
routing/path_latency_message.cpp
|
||||
routing/path_transfer_message.cpp
|
||||
routing/transfer_traffic_message.cpp
|
||||
rpc/rpc.cpp
|
||||
service/address.cpp
|
||||
service/async_key_exchange.cpp
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include <constants/path.hpp>
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef LLARP_CONSTANTS_PATH_HPP
|
||||
#define LLARP_CONSTANTS_PATH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <util/types.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace path
|
||||
{
|
||||
/// maximum path length
|
||||
constexpr std::size_t max_len = 8;
|
||||
/// default path length
|
||||
constexpr std::size_t default_len = 4;
|
||||
/// pad messages to the nearest this many bytes
|
||||
constexpr std::size_t pad_size = 128;
|
||||
/// default path lifetime in ms
|
||||
constexpr llarp_time_t default_lifetime = 10 * 60 * 1000;
|
||||
/// after this many ms a path build times out
|
||||
constexpr llarp_time_t build_timeout = 30000;
|
||||
|
||||
/// measure latency every this interval ms
|
||||
constexpr llarp_time_t latency_interval = 5000;
|
||||
|
||||
/// if a path is inactive for this amount of time it's dead
|
||||
constexpr llarp_time_t alive_timeout = 60000;
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -118,6 +118,14 @@ namespace llarp
|
|||
if(singleThreaded)
|
||||
num_nethreads = 0;
|
||||
}
|
||||
else if(!strcmp(key, "netid"))
|
||||
{
|
||||
metricTags["netid"] = val;
|
||||
}
|
||||
else if(!strcmp(key, "nickname"))
|
||||
{
|
||||
metricTags["nickname"] = val;
|
||||
}
|
||||
}
|
||||
if(!strcmp(section, "netdb"))
|
||||
{
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
#include <dht/recursiverouterlookup.hpp>
|
||||
#include <dht/serviceaddresslookup.hpp>
|
||||
#include <dht/taglookup.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <messages/dht_immediate.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <util/logic.hpp>
|
||||
#include <nodedb.hpp>
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <util/logger.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <util/logger.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <dht/messages/gotintro.hpp>
|
||||
|
||||
#include <dht/context.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <dht/messages/gotintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <messages/dht_immediate.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
#include <util/logic.hpp>
|
||||
#include <util/mem.hpp>
|
||||
#include <util/string_view.hpp>
|
||||
#include "net/net_addr.hpp"
|
||||
#include <net/net_addr.hpp>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
// We libuv now
|
||||
#ifndef _WIN32
|
||||
|
@ -90,7 +91,6 @@ llarp_ev_udp_sendto(struct llarp_udp_io *udp, const sockaddr *to,
|
|||
return udp->sendto(udp, to, buf.base, buf.sz);
|
||||
}
|
||||
|
||||
#include <string.h>
|
||||
bool
|
||||
llarp_ev_add_tun(struct llarp_ev_loop *loop, struct llarp_tun_io *tun)
|
||||
{
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
#include <crypto/crypto.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
CloseExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "C"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
CloseExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleCloseExitMessage(*this, r);
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -1,5 +1,7 @@
|
|||
#include <exit/endpoint.hpp>
|
||||
|
||||
#include <handlers/exit.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -0,0 +1,425 @@
|
|||
#include <exit/exit_messages.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
ObtainExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 1024 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
I = seckey_topublic(sk);
|
||||
Z.Zero();
|
||||
if(!BEncode(&buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::Verify() const
|
||||
{
|
||||
std::array< byte_t, 1024 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
ObtainExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// rewind buffer
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(I, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "O"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictArray("B", B, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("E", E, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("I", I, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictArray("W", W, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("X", X, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictList("B", B, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("E", E, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("I", I, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictList("W", W, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("X", X, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleObtainExitMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "G"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
GrantExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleGrantExitMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "J"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("B", B, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictList("R", R, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("B", B, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictList("R", R, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
RejectExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleRejectExitMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("P", P, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
UpdateExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleUpdateExitMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::DecodeKey(const llarp_buffer_t& k,
|
||||
llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleUpdateExitVerifyMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "C"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
CloseExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
CloseExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleCloseExitMessage(*this, r);
|
||||
}
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef LLARP_MESSAGES_EXIT_HPP
|
||||
#define LLARP_MESSAGES_EXIT_HPP
|
||||
#ifndef LLARP_EXIT_MESSAGES_HPP
|
||||
#define LLARP_EXIT_MESSAGES_HPP
|
||||
|
||||
#include <crypto/types.hpp>
|
||||
#include <exit/policy.hpp>
|
|
@ -1,81 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
GrantExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "G"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
GrantExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
GrantExitMessage::HandleMessage(IMessageHandler* h, AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleGrantExitMessage(*this, r);
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -1,103 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
ObtainExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 1024 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
I = seckey_topublic(sk);
|
||||
Z.Zero();
|
||||
if(!BEncode(&buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::Verify() const
|
||||
{
|
||||
std::array< byte_t, 1024 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
ObtainExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// rewind buffer
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(I, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "O"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictArray("B", B, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("E", E, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("I", I, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictArray("W", W, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("X", X, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictList("B", B, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("E", E, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("I", I, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictList("W", W, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("X", X, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
ObtainExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleObtainExitMessage(*this, r);
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -1,90 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
RejectExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "J"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("B", B, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictList("R", R, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("B", B, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictList("R", R, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Y", Y, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Z.Zero();
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
RejectExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
RejectExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleRejectExitMessage(*this, r);
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <util/memfn.hpp>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef LLARP_EXIT_SESSION_HPP
|
||||
#define LLARP_EXIT_SESSION_HPP
|
||||
|
||||
#include <messages/exit.hpp>
|
||||
#include <messages/transfer_traffic.hpp>
|
||||
#include <exit/exit_messages.hpp>
|
||||
#include <net/ip.hpp>
|
||||
#include <path/pathbuilder.hpp>
|
||||
#include <routing/transfer_traffic_message.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
bool
|
||||
UpdateExitMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("P", P, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", Z, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::Verify(const llarp::PubKey& pk) const
|
||||
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
UpdateExitMessage copy;
|
||||
copy = *this;
|
||||
copy.Z.Zero();
|
||||
if(!copy.BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->verify(pk, buf, Z);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::Sign(const llarp::SecretKey& sk)
|
||||
{
|
||||
std::array< byte_t, 512 > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
Y.Randomize();
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
return CryptoManager::instance()->sign(Z, sk, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleUpdateExitMessage(*this, r);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "V"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("T", T, buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt("V", version, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::DecodeKey(const llarp_buffer_t& k,
|
||||
llarp_buffer_t* buf)
|
||||
{
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("T", T, read, k, buf))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
UpdateExitVerifyMessage::HandleMessage(IMessageHandler* h,
|
||||
AbstractRouter* r) const
|
||||
{
|
||||
return h->HandleUpdateExitVerifyMessage(*this, r);
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <dns/dns.hpp>
|
||||
#include <net/net.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <util/str.hpp>
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include <messages/dht.hpp>
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
namespace llarp
|
||||
{
|
||||
DHTImmediateMessage::~DHTImmediateMessage()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DHTImmediateMessage::Clear()
|
||||
{
|
||||
|
|
|
@ -8,13 +8,10 @@
|
|||
|
||||
namespace llarp
|
||||
{
|
||||
struct DHTImmediateMessage : public ILinkMessage
|
||||
struct DHTImmediateMessage final : public ILinkMessage
|
||||
{
|
||||
DHTImmediateMessage() : ILinkMessage()
|
||||
{
|
||||
}
|
||||
|
||||
~DHTImmediateMessage();
|
||||
DHTImmediateMessage() = default;
|
||||
~DHTImmediateMessage() = default;
|
||||
|
||||
std::vector< std::unique_ptr< dht::IMessage > > msgs;
|
||||
|
||||
|
|
|
@ -57,9 +57,7 @@ namespace llarp
|
|||
{
|
||||
PathID_t P;
|
||||
|
||||
DataDiscardMessage() : IMessage()
|
||||
{
|
||||
}
|
||||
DataDiscardMessage() = default;
|
||||
|
||||
DataDiscardMessage(const PathID_t& dst, uint64_t s) : P(dst)
|
||||
{
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include <messages/exit.hpp>
|
|
@ -1,148 +1 @@
|
|||
#include <messages/link_message_parser.hpp>
|
||||
|
||||
#include <messages/dht_immediate.hpp>
|
||||
#include <messages/discard.hpp>
|
||||
#include <messages/link_intro.hpp>
|
||||
#include <messages/link_message.hpp>
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <messages/relay.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/logger.hpp>
|
||||
#include <util/metrics.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct InboundMessageParser::msg_holder_t
|
||||
{
|
||||
LinkIntroMessage i;
|
||||
RelayDownstreamMessage d;
|
||||
RelayUpstreamMessage u;
|
||||
DHTImmediateMessage m;
|
||||
LR_CommitMessage c;
|
||||
DiscardMessage x;
|
||||
|
||||
msg_holder_t() = default;
|
||||
};
|
||||
|
||||
InboundMessageParser::InboundMessageParser(AbstractRouter* _router)
|
||||
: router(_router), from(nullptr), msg(nullptr), holder(new msg_holder_t())
|
||||
{
|
||||
}
|
||||
|
||||
InboundMessageParser::~InboundMessageParser()
|
||||
{
|
||||
delete holder;
|
||||
}
|
||||
|
||||
bool
|
||||
InboundMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
|
||||
{
|
||||
// we are reading the first key
|
||||
if(firstkey)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
// check for empty dict
|
||||
if(!key)
|
||||
return false;
|
||||
// we are expecting the first key to be 'a'
|
||||
if(!(*key == "a"))
|
||||
{
|
||||
llarp::LogWarn("message has no message type");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!bencode_read_string(buffer, &strbuf))
|
||||
{
|
||||
llarp::LogWarn("could not read value of message type");
|
||||
return false;
|
||||
}
|
||||
// bad key size
|
||||
if(strbuf.sz != 1)
|
||||
{
|
||||
llarp::LogWarn("bad mesage type size: ", strbuf.sz);
|
||||
return false;
|
||||
}
|
||||
// create the message to parse based off message type
|
||||
llarp::LogDebug("inbound message ", *strbuf.cur);
|
||||
bool isLIM = false;
|
||||
switch(*strbuf.cur)
|
||||
{
|
||||
case 'i':
|
||||
msg = &holder->i;
|
||||
isLIM = true;
|
||||
break;
|
||||
case 'd':
|
||||
msg = &holder->d;
|
||||
break;
|
||||
case 'u':
|
||||
msg = &holder->u;
|
||||
break;
|
||||
case 'm':
|
||||
msg = &holder->m;
|
||||
break;
|
||||
case 'c':
|
||||
msg = &holder->c;
|
||||
break;
|
||||
case 'x':
|
||||
msg = &holder->x;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!isLIM)
|
||||
{
|
||||
metrics::integerTick(msg->Name(), "RX", 1, "id",
|
||||
RouterID(from->GetPubKey()).ToString());
|
||||
}
|
||||
|
||||
msg->session = from;
|
||||
firstkey = false;
|
||||
return true;
|
||||
}
|
||||
// check for last element
|
||||
if(!key)
|
||||
return MessageDone();
|
||||
|
||||
return msg->DecodeKey(*key, buffer);
|
||||
}
|
||||
|
||||
bool
|
||||
InboundMessageParser::MessageDone()
|
||||
{
|
||||
bool result = false;
|
||||
if(msg)
|
||||
{
|
||||
result = msg->HandleMessage(router);
|
||||
}
|
||||
Reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
InboundMessageParser::ProcessFrom(ILinkSession* src,
|
||||
const llarp_buffer_t& buf)
|
||||
{
|
||||
if(!src)
|
||||
{
|
||||
llarp::LogWarn("no link session");
|
||||
return false;
|
||||
}
|
||||
|
||||
from = src;
|
||||
firstkey = true;
|
||||
ManagedBuffer copy(buf);
|
||||
return bencode_read_dict(*this, ©.underlying);
|
||||
}
|
||||
|
||||
void
|
||||
InboundMessageParser::Reset()
|
||||
{
|
||||
if(msg)
|
||||
msg->Clear();
|
||||
msg = nullptr;
|
||||
}
|
||||
} // namespace llarp
|
||||
|
|
|
@ -21,9 +21,7 @@ namespace llarp
|
|||
|
||||
ILinkMessage() = default;
|
||||
|
||||
virtual ~ILinkMessage()
|
||||
{
|
||||
}
|
||||
virtual ~ILinkMessage() = default;
|
||||
|
||||
virtual bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) = 0;
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
#include <messages/link_message_parser.hpp>
|
||||
|
||||
#include <messages/dht_immediate.hpp>
|
||||
#include <messages/discard.hpp>
|
||||
#include <messages/link_intro.hpp>
|
||||
#include <messages/link_message.hpp>
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <messages/relay.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/logger.hpp>
|
||||
#include <util/metrics.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct LinkMessageParser::msg_holder_t
|
||||
{
|
||||
LinkIntroMessage i;
|
||||
RelayDownstreamMessage d;
|
||||
RelayUpstreamMessage u;
|
||||
DHTImmediateMessage m;
|
||||
LR_CommitMessage c;
|
||||
DiscardMessage x;
|
||||
|
||||
msg_holder_t() = default;
|
||||
};
|
||||
|
||||
LinkMessageParser::LinkMessageParser(AbstractRouter* _router)
|
||||
: router(_router)
|
||||
, from(nullptr)
|
||||
, msg(nullptr)
|
||||
, holder(std::make_unique< msg_holder_t >())
|
||||
{
|
||||
}
|
||||
|
||||
LinkMessageParser::~LinkMessageParser()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
LinkMessageParser::operator()(llarp_buffer_t* buffer, llarp_buffer_t* key)
|
||||
{
|
||||
// we are reading the first key
|
||||
if(firstkey)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
// check for empty dict
|
||||
if(!key)
|
||||
return false;
|
||||
// we are expecting the first key to be 'a'
|
||||
if(!(*key == "a"))
|
||||
{
|
||||
llarp::LogWarn("message has no message type");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!bencode_read_string(buffer, &strbuf))
|
||||
{
|
||||
llarp::LogWarn("could not read value of message type");
|
||||
return false;
|
||||
}
|
||||
// bad key size
|
||||
if(strbuf.sz != 1)
|
||||
{
|
||||
llarp::LogWarn("bad mesage type size: ", strbuf.sz);
|
||||
return false;
|
||||
}
|
||||
// create the message to parse based off message type
|
||||
llarp::LogDebug("inbound message ", *strbuf.cur);
|
||||
bool isLIM = false;
|
||||
switch(*strbuf.cur)
|
||||
{
|
||||
case 'i':
|
||||
msg = &holder->i;
|
||||
isLIM = true;
|
||||
break;
|
||||
case 'd':
|
||||
msg = &holder->d;
|
||||
break;
|
||||
case 'u':
|
||||
msg = &holder->u;
|
||||
break;
|
||||
case 'm':
|
||||
msg = &holder->m;
|
||||
break;
|
||||
case 'c':
|
||||
msg = &holder->c;
|
||||
break;
|
||||
case 'x':
|
||||
msg = &holder->x;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!isLIM)
|
||||
{
|
||||
metrics::integerTick(msg->Name(), "RX", 1, "id",
|
||||
RouterID(from->GetPubKey()).ToString());
|
||||
}
|
||||
|
||||
msg->session = from;
|
||||
firstkey = false;
|
||||
return true;
|
||||
}
|
||||
// check for last element
|
||||
if(!key)
|
||||
return MessageDone();
|
||||
|
||||
return msg->DecodeKey(*key, buffer);
|
||||
}
|
||||
|
||||
bool
|
||||
LinkMessageParser::MessageDone()
|
||||
{
|
||||
bool result = false;
|
||||
if(msg)
|
||||
{
|
||||
result = msg->HandleMessage(router);
|
||||
}
|
||||
Reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
LinkMessageParser::ProcessFrom(ILinkSession* src, const llarp_buffer_t& buf)
|
||||
{
|
||||
if(!src)
|
||||
{
|
||||
llarp::LogWarn("no link session");
|
||||
return false;
|
||||
}
|
||||
|
||||
from = src;
|
||||
firstkey = true;
|
||||
ManagedBuffer copy(buf);
|
||||
return bencode_read_dict(*this, ©.underlying);
|
||||
}
|
||||
|
||||
void
|
||||
LinkMessageParser::Reset()
|
||||
{
|
||||
if(msg)
|
||||
msg->Clear();
|
||||
msg = nullptr;
|
||||
}
|
||||
} // namespace llarp
|
|
@ -12,10 +12,10 @@ namespace llarp
|
|||
struct ILinkMessage;
|
||||
struct ILinkSession;
|
||||
|
||||
struct InboundMessageParser
|
||||
struct LinkMessageParser
|
||||
{
|
||||
InboundMessageParser(AbstractRouter* router);
|
||||
~InboundMessageParser();
|
||||
LinkMessageParser(AbstractRouter* router);
|
||||
~LinkMessageParser();
|
||||
|
||||
bool
|
||||
operator()(llarp_buffer_t* buffer, llarp_buffer_t* key);
|
||||
|
@ -44,7 +44,8 @@ namespace llarp
|
|||
ILinkMessage* msg;
|
||||
|
||||
struct msg_holder_t;
|
||||
msg_holder_t* holder;
|
||||
|
||||
std::unique_ptr< msg_holder_t > holder;
|
||||
};
|
||||
} // namespace llarp
|
||||
#endif
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include <messages/path_confirm.hpp>
|
|
@ -1 +0,0 @@
|
|||
#include <messages/path_latency.hpp>
|
|
@ -1 +0,0 @@
|
|||
#include <messages/path_transfer.hpp>
|
|
@ -1,19 +1,11 @@
|
|||
#include <messages/relay.hpp>
|
||||
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <util/bencode.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
RelayUpstreamMessage::RelayUpstreamMessage() : ILinkMessage()
|
||||
{
|
||||
}
|
||||
|
||||
RelayUpstreamMessage::~RelayUpstreamMessage()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RelayUpstreamMessage::Clear()
|
||||
{
|
||||
|
@ -69,14 +61,6 @@ namespace llarp
|
|||
return false;
|
||||
}
|
||||
|
||||
RelayDownstreamMessage::RelayDownstreamMessage() : ILinkMessage()
|
||||
{
|
||||
}
|
||||
|
||||
RelayDownstreamMessage::~RelayDownstreamMessage()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RelayDownstreamMessage::Clear()
|
||||
{
|
||||
|
|
|
@ -16,10 +16,6 @@ namespace llarp
|
|||
Encrypted< MAX_LINK_MSG_SIZE - 128 > X;
|
||||
TunnelNonce Y;
|
||||
|
||||
RelayUpstreamMessage();
|
||||
RelayUpstreamMessage(ILinkSession* from);
|
||||
~RelayUpstreamMessage();
|
||||
|
||||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
|
||||
|
||||
|
@ -44,9 +40,6 @@ namespace llarp
|
|||
PathID_t pathid;
|
||||
Encrypted< MAX_LINK_MSG_SIZE - 128 > X;
|
||||
TunnelNonce Y;
|
||||
RelayDownstreamMessage();
|
||||
RelayDownstreamMessage(ILinkSession* from);
|
||||
~RelayDownstreamMessage();
|
||||
|
||||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
#include <messages/relay_commit.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <messages/path_confirm.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <path/transit_hop.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/path_confirm_message.hpp>
|
||||
#include <util/bencode.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/logger.hpp>
|
||||
#include <util/logic.hpp>
|
||||
#include <util/memfn.hpp>
|
||||
#include <nodedb.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
LR_CommitMessage::~LR_CommitMessage()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
LR_CommitMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
|
||||
{
|
||||
|
@ -37,14 +34,7 @@ namespace llarp
|
|||
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();
|
||||
std::for_each(frames.begin(), frames.end(), [](auto& f) { f.Clear(); });
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -54,11 +54,9 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
LR_CommitMessage() : ILinkMessage()
|
||||
{
|
||||
}
|
||||
LR_CommitMessage() = default;
|
||||
|
||||
~LR_CommitMessage();
|
||||
~LR_CommitMessage() = default;
|
||||
|
||||
void
|
||||
Clear() override;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include <messages/transfer_traffic.hpp>
|
|
@ -124,6 +124,10 @@ namespace llarp
|
|||
absl::StrAppend(&tagStr, ";", tag.first, "=",
|
||||
absl::visit(overloaded, tag.second));
|
||||
}
|
||||
if(!tags.empty())
|
||||
{
|
||||
absl::StrAppend(&tagStr, ";");
|
||||
}
|
||||
return tagStr;
|
||||
}
|
||||
|
||||
|
@ -336,26 +340,6 @@ namespace llarp
|
|||
#endif
|
||||
}
|
||||
|
||||
if(tags.count("user") == 0)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
const char *username = getlogin();
|
||||
if(username != nullptr)
|
||||
{
|
||||
tags["user"] = username;
|
||||
}
|
||||
else
|
||||
{
|
||||
tags["user"] = "unknown";
|
||||
}
|
||||
#else
|
||||
char username[UNLEN + 1];
|
||||
DWORD username_len = UNLEN + 1;
|
||||
GetUserName(username, &username_len);
|
||||
tags["user"] = username;
|
||||
#endif
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include <path/ihophandler.hpp>
|
|
@ -0,0 +1,65 @@
|
|||
#ifndef LLARP_PATH_IHOPHANDLER_HPP
|
||||
#define LLARP_PATH_IHOPHANDLER_HPP
|
||||
|
||||
#include <crypto/types.hpp>
|
||||
#include <util/types.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct llarp_buffer_t;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct AbstractRouter;
|
||||
|
||||
namespace routing
|
||||
{
|
||||
struct IMessage;
|
||||
}
|
||||
|
||||
namespace path
|
||||
{
|
||||
struct IHopHandler
|
||||
{
|
||||
virtual ~IHopHandler()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool
|
||||
Expired(llarp_time_t now) const = 0;
|
||||
|
||||
virtual bool
|
||||
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const = 0;
|
||||
|
||||
/// send routing message and increment sequence number
|
||||
virtual bool
|
||||
SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r) = 0;
|
||||
|
||||
// handle data in upstream direction
|
||||
virtual bool
|
||||
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) = 0;
|
||||
|
||||
// handle data in downstream direction
|
||||
virtual bool
|
||||
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) = 0;
|
||||
|
||||
/// return timestamp last remote activity happened at
|
||||
virtual llarp_time_t
|
||||
LastRemoteActivityAt() const = 0;
|
||||
|
||||
uint64_t
|
||||
NextSeqNo()
|
||||
{
|
||||
return m_SequenceNum++;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint64_t m_SequenceNum = 0;
|
||||
};
|
||||
|
||||
using HopHandler_ptr = std::shared_ptr< IHopHandler >;
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
#endif
|
|
@ -1,14 +1,15 @@
|
|||
#include <path/path.hpp>
|
||||
|
||||
#include <messages/dht.hpp>
|
||||
#include <exit/exit_messages.hpp>
|
||||
#include <messages/discard.hpp>
|
||||
#include <messages/exit.hpp>
|
||||
#include <messages/path_latency.hpp>
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <messages/transfer_traffic.hpp>
|
||||
#include <path/pathbuilder.hpp>
|
||||
#include <path/transit_hop.hpp>
|
||||
#include <profiling.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <routing/path_latency_message.hpp>
|
||||
#include <routing/transfer_traffic_message.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/endian.hpp>
|
||||
|
||||
|
@ -18,365 +19,6 @@ namespace llarp
|
|||
{
|
||||
namespace path
|
||||
{
|
||||
std::ostream&
|
||||
TransitHopInfo::print(std::ostream& stream, int level, int spaces) const
|
||||
{
|
||||
Printer printer(stream, level, spaces);
|
||||
printer.printAttribute("tx", txID);
|
||||
printer.printAttribute("rx", rxID);
|
||||
printer.printAttribute("upstream", upstream);
|
||||
printer.printAttribute("downstream", downstream);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
PathContext::PathContext(AbstractRouter* router)
|
||||
: m_Router(router), m_AllowTransit(false)
|
||||
{
|
||||
}
|
||||
|
||||
PathContext::~PathContext()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::AllowTransit()
|
||||
{
|
||||
m_AllowTransit = true;
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::AllowingTransit() const
|
||||
{
|
||||
return m_AllowTransit;
|
||||
}
|
||||
|
||||
llarp_threadpool*
|
||||
PathContext::Worker()
|
||||
{
|
||||
return m_Router->threadpool();
|
||||
}
|
||||
|
||||
std::shared_ptr< Logic >
|
||||
PathContext::logic()
|
||||
{
|
||||
return m_Router->logic();
|
||||
}
|
||||
|
||||
const SecretKey&
|
||||
PathContext::EncryptionSecretKey()
|
||||
{
|
||||
return m_Router->encryption();
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::HopIsUs(const RouterID& k) const
|
||||
{
|
||||
return std::equal(m_Router->pubkey(), m_Router->pubkey() + PUBKEYSIZE,
|
||||
k.begin());
|
||||
}
|
||||
|
||||
PathContext::EndpointPathPtrSet
|
||||
PathContext::FindOwnedPathsWithEndpoint(const RouterID& r)
|
||||
{
|
||||
EndpointPathPtrSet found;
|
||||
m_OurPaths.ForEach([&](const PathSet_ptr& set) {
|
||||
set->ForEachPath([&](const Path_ptr& p) {
|
||||
if(p->Endpoint() == r && p->IsReady())
|
||||
found.insert(p);
|
||||
});
|
||||
});
|
||||
return found;
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::ForwardLRCM(const RouterID& nextHop,
|
||||
const std::array< EncryptedFrame, 8 >& frames)
|
||||
{
|
||||
auto msg = std::make_shared< const LR_CommitMessage >(frames);
|
||||
|
||||
LogDebug("forwarding LRCM to ", nextHop);
|
||||
if(m_Router->HasSessionTo(nextHop))
|
||||
{
|
||||
return m_Router->SendToOrQueue(nextHop, msg.get());
|
||||
}
|
||||
const RouterID router = nextHop;
|
||||
AbstractRouter* const r = m_Router;
|
||||
m_Router->EnsureRouter(
|
||||
nextHop, [msg, r, router](const std::vector< RouterContact >& found) {
|
||||
if(found.size())
|
||||
{
|
||||
r->TryConnectAsync(found[0], 1);
|
||||
r->SendToOrQueue(router, msg.get());
|
||||
}
|
||||
else
|
||||
LogError("dropped LRCM to ", router,
|
||||
" as we cannot find in via DHT");
|
||||
});
|
||||
LogInfo("we are not directly connected to ", router,
|
||||
" so we need to do a lookup");
|
||||
return true;
|
||||
}
|
||||
template < typename Map_t, typename Key_t, typename CheckValue_t,
|
||||
typename GetFunc_t >
|
||||
HopHandler_ptr
|
||||
MapGet(Map_t& map, const Key_t& k, CheckValue_t check, GetFunc_t get)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(check(i->second))
|
||||
return get(i->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename CheckValue_t >
|
||||
bool
|
||||
MapHas(Map_t& map, const Key_t& k, CheckValue_t check)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(check(i->second))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename Value_t >
|
||||
void
|
||||
MapPut(Map_t& map, const Key_t& k, const Value_t& v)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
map.second.emplace(k, v);
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Visit_t >
|
||||
void
|
||||
MapIter(Map_t& map, Visit_t v)
|
||||
{
|
||||
util::Lock lock(map.first);
|
||||
for(const auto& item : map.second)
|
||||
v(item);
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename Check_t >
|
||||
void
|
||||
MapDel(Map_t& map, const Key_t& k, Check_t check)
|
||||
{
|
||||
util::Lock lock(map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second;)
|
||||
{
|
||||
if(check(i->second))
|
||||
i = map.second.erase(i);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::AddOwnPath(PathSet_ptr set, Path_ptr path)
|
||||
{
|
||||
set->AddPath(path);
|
||||
MapPut(m_OurPaths, path->TXID(), set);
|
||||
MapPut(m_OurPaths, path->RXID(), set);
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::HasTransitHop(const TransitHopInfo& info)
|
||||
{
|
||||
return MapHas(m_TransitPaths, info.txID,
|
||||
[info](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return info == hop->info;
|
||||
});
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
|
||||
{
|
||||
auto own = MapGet(m_OurPaths, id,
|
||||
[](const PathSet_ptr) -> bool {
|
||||
// TODO: is this right?
|
||||
return true;
|
||||
},
|
||||
[remote, id](PathSet_ptr p) -> HopHandler_ptr {
|
||||
return p->GetByUpstream(remote, id);
|
||||
});
|
||||
if(own)
|
||||
return own;
|
||||
|
||||
return MapGet(
|
||||
m_TransitPaths, id,
|
||||
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return hop->info.upstream == remote;
|
||||
},
|
||||
[](const std::shared_ptr< TransitHop >& h) -> HopHandler_ptr {
|
||||
return h;
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::TransitHopPreviousIsRouter(const PathID_t& path,
|
||||
const RouterID& otherRouter)
|
||||
{
|
||||
util::Lock lock(&m_TransitPaths.first);
|
||||
auto itr = m_TransitPaths.second.find(path);
|
||||
if(itr == m_TransitPaths.second.end())
|
||||
return false;
|
||||
return itr->second->info.downstream == otherRouter;
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetByDownstream(const RouterID& remote, const PathID_t& id)
|
||||
{
|
||||
return MapGet(
|
||||
m_TransitPaths, id,
|
||||
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return hop->info.downstream == remote;
|
||||
},
|
||||
[](const std::shared_ptr< TransitHop >& h) -> HopHandler_ptr {
|
||||
return h;
|
||||
});
|
||||
}
|
||||
|
||||
PathSet_ptr
|
||||
PathContext::GetLocalPathSet(const PathID_t& id)
|
||||
{
|
||||
auto& map = m_OurPaths;
|
||||
util::Lock lock(&map.first);
|
||||
auto itr = map.second.find(id);
|
||||
if(itr != map.second.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const byte_t*
|
||||
PathContext::OurRouterID() const
|
||||
{
|
||||
return m_Router->pubkey();
|
||||
}
|
||||
|
||||
AbstractRouter*
|
||||
PathContext::Router()
|
||||
{
|
||||
return m_Router;
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetPathForTransfer(const PathID_t& id)
|
||||
{
|
||||
RouterID us(OurRouterID());
|
||||
auto& map = m_TransitPaths;
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(id);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(i->second->info.upstream == us)
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::PutTransitHop(std::shared_ptr< TransitHop > hop)
|
||||
{
|
||||
MapPut(m_TransitPaths, hop->info.txID, hop);
|
||||
MapPut(m_TransitPaths, hop->info.rxID, hop);
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::ExpirePaths(llarp_time_t now)
|
||||
{
|
||||
{
|
||||
util::Lock lock(&m_TransitPaths.first);
|
||||
auto& map = m_TransitPaths.second;
|
||||
auto itr = map.begin();
|
||||
while(itr != map.end())
|
||||
{
|
||||
if(itr->second->Expired(now))
|
||||
{
|
||||
itr = map.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
{
|
||||
util::Lock lock(&m_OurPaths.first);
|
||||
auto& map = m_OurPaths.second;
|
||||
for(auto& item : map)
|
||||
{
|
||||
item.second->ExpirePaths(now);
|
||||
}
|
||||
}
|
||||
}
|
||||
routing::MessageHandler_ptr
|
||||
PathContext::GetHandler(const PathID_t& id)
|
||||
{
|
||||
routing::MessageHandler_ptr h = nullptr;
|
||||
auto pathset = GetLocalPathSet(id);
|
||||
if(pathset)
|
||||
{
|
||||
h = pathset->GetPathByID(id);
|
||||
}
|
||||
if(h)
|
||||
return h;
|
||||
const RouterID us(OurRouterID());
|
||||
auto& map = m_TransitPaths;
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(id);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(i->second->info.upstream == us)
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::RemovePathSet(PathSet_ptr set)
|
||||
{
|
||||
util::Lock lock(&m_OurPaths.first);
|
||||
auto& map = m_OurPaths.second;
|
||||
auto itr = map.begin();
|
||||
while(itr != map.end())
|
||||
{
|
||||
if(itr->second.get() == set.get())
|
||||
itr = map.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
TransitHop::print(std::ostream& stream, int level, int spaces) const
|
||||
{
|
||||
Printer printer(stream, level, spaces);
|
||||
printer.printAttribute("TransitHop", info);
|
||||
printer.printAttribute("started", started);
|
||||
printer.printAttribute("lifetime", lifetime);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
PathHopConfig::PathHopConfig()
|
||||
{
|
||||
}
|
||||
|
||||
PathHopConfig::~PathHopConfig()
|
||||
{
|
||||
}
|
||||
|
||||
Path::Path(const std::vector< RouterContact >& h, PathSet* parent,
|
||||
PathRole startingRoles)
|
||||
: m_PathSet(parent), _role(startingRoles)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef LLARP_PATH_HPP
|
||||
#define LLARP_PATH_HPP
|
||||
|
||||
#include <constants/path.hpp>
|
||||
#include <crypto/encrypted_frame.hpp>
|
||||
#include <crypto/types.hpp>
|
||||
#include <messages/relay.hpp>
|
||||
#include <path/ihophandler.hpp>
|
||||
#include <path/path_types.hpp>
|
||||
#include <path/pathbuilder.hpp>
|
||||
#include <path/pathset.hpp>
|
||||
|
@ -28,254 +30,14 @@ namespace llarp
|
|||
class Logic;
|
||||
struct AbstractRouter;
|
||||
struct LR_CommitMessage;
|
||||
struct LR_CommitRecord;
|
||||
|
||||
namespace path
|
||||
{
|
||||
/// maximum path length
|
||||
constexpr size_t max_len = 8;
|
||||
/// default path length
|
||||
constexpr size_t default_len = 4;
|
||||
/// pad messages to the nearest this many bytes
|
||||
constexpr size_t pad_size = 128;
|
||||
/// default path lifetime in ms
|
||||
constexpr llarp_time_t default_lifetime = 10 * 60 * 1000;
|
||||
/// after this many ms a path build times out
|
||||
constexpr llarp_time_t build_timeout = 30000;
|
||||
|
||||
/// measure latency every this interval ms
|
||||
constexpr llarp_time_t latency_interval = 5000;
|
||||
|
||||
/// if a path is inactive for this amount of time it's dead
|
||||
constexpr llarp_time_t alive_timeout = 60000;
|
||||
|
||||
struct TransitHopInfo
|
||||
{
|
||||
TransitHopInfo() = default;
|
||||
TransitHopInfo(const RouterID& down, const LR_CommitRecord& record);
|
||||
|
||||
PathID_t txID, rxID;
|
||||
RouterID upstream;
|
||||
RouterID downstream;
|
||||
|
||||
std::ostream&
|
||||
print(std::ostream& stream, int level, int spaces) const;
|
||||
|
||||
bool
|
||||
operator==(const TransitHopInfo& other) const
|
||||
{
|
||||
return txID == other.txID && rxID == other.rxID
|
||||
&& upstream == other.upstream && downstream == other.downstream;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(const TransitHopInfo& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(const TransitHopInfo& other) const
|
||||
{
|
||||
return txID < other.txID || rxID < other.rxID
|
||||
|| upstream < other.upstream || downstream < other.downstream;
|
||||
}
|
||||
|
||||
struct PathIDHash
|
||||
{
|
||||
std::size_t
|
||||
operator()(const PathID_t& a) const
|
||||
{
|
||||
return AlignedBuffer< PathID_t::SIZE >::Hash()(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Hash
|
||||
{
|
||||
std::size_t
|
||||
operator()(TransitHopInfo const& a) const
|
||||
{
|
||||
std::size_t idx0 = RouterID::Hash()(a.upstream);
|
||||
std::size_t idx1 = RouterID::Hash()(a.downstream);
|
||||
std::size_t idx2 = PathIDHash()(a.txID);
|
||||
std::size_t idx3 = PathIDHash()(a.rxID);
|
||||
return idx0 ^ idx1 ^ idx2 ^ idx3;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const TransitHopInfo& info)
|
||||
{
|
||||
return info.print(out, -1, -1);
|
||||
}
|
||||
|
||||
struct IHopHandler
|
||||
{
|
||||
virtual ~IHopHandler()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool
|
||||
Expired(llarp_time_t now) const = 0;
|
||||
|
||||
virtual bool
|
||||
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const = 0;
|
||||
|
||||
/// send routing message and increment sequence number
|
||||
virtual bool
|
||||
SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r) = 0;
|
||||
|
||||
// handle data in upstream direction
|
||||
virtual bool
|
||||
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) = 0;
|
||||
|
||||
// handle data in downstream direction
|
||||
virtual bool
|
||||
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) = 0;
|
||||
|
||||
/// return timestamp last remote activity happened at
|
||||
virtual llarp_time_t
|
||||
LastRemoteActivityAt() const = 0;
|
||||
|
||||
uint64_t
|
||||
NextSeqNo()
|
||||
{
|
||||
return m_SequenceNum++;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint64_t m_SequenceNum = 0;
|
||||
};
|
||||
|
||||
using HopHandler_ptr = std::shared_ptr< IHopHandler >;
|
||||
|
||||
struct TransitHop : public IHopHandler, public routing::IMessageHandler
|
||||
{
|
||||
TransitHop();
|
||||
|
||||
TransitHopInfo info;
|
||||
SharedSecret pathKey;
|
||||
ShortHash nonceXOR;
|
||||
llarp_time_t started = 0;
|
||||
// 10 minutes default
|
||||
llarp_time_t lifetime = default_lifetime;
|
||||
llarp_proto_version_t version;
|
||||
llarp_time_t m_LastActivity = 0;
|
||||
|
||||
bool
|
||||
IsEndpoint(const RouterID& us) const
|
||||
{
|
||||
return info.upstream == us;
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
ExpireTime() const;
|
||||
|
||||
llarp_time_t
|
||||
LastRemoteActivityAt() const override
|
||||
{
|
||||
return m_LastActivity;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
print(std::ostream& stream, int level, int spaces) const;
|
||||
|
||||
bool
|
||||
Expired(llarp_time_t now) const override;
|
||||
|
||||
bool
|
||||
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const override
|
||||
{
|
||||
return now >= ExpireTime() - dlt;
|
||||
}
|
||||
|
||||
// send routing message when end of path
|
||||
bool
|
||||
SendRoutingMessage(const routing::IMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
// handle routing message when end of path
|
||||
bool
|
||||
HandleRoutingMessage(const routing::IMessage& msg, AbstractRouter* r);
|
||||
|
||||
bool
|
||||
HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandlePathTransferMessage(const routing::PathTransferMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleGrantExitMessage(const routing::GrantExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandleRejectExitMessage(const routing::RejectExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleCloseExitMessage(const routing::CloseExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleHiddenServiceFrame(
|
||||
ABSL_ATTRIBUTE_UNUSED const service::ProtocolFrame& frame) override
|
||||
{
|
||||
/// TODO: implement me
|
||||
LogWarn("Got hidden service data on transit hop");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HandleGotIntroMessage(const dht::GotIntroMessage& msg);
|
||||
|
||||
bool
|
||||
HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
|
||||
|
||||
// handle data in upstream direction
|
||||
bool
|
||||
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
// handle data in downstream direction
|
||||
bool
|
||||
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) override;
|
||||
};
|
||||
struct TransitHop;
|
||||
struct TransitHopInfo;
|
||||
|
||||
using TransitHop_ptr = std::shared_ptr< TransitHop >;
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const TransitHop& h)
|
||||
{
|
||||
return h.print(out, -1, -1);
|
||||
}
|
||||
|
||||
/// configuration for a single hop when building a path
|
||||
struct PathHopConfig
|
||||
{
|
||||
|
@ -296,21 +58,17 @@ namespace llarp
|
|||
// lifetime
|
||||
llarp_time_t lifetime = default_lifetime;
|
||||
|
||||
~PathHopConfig();
|
||||
PathHopConfig();
|
||||
|
||||
util::StatusObject
|
||||
ExtractStatus() const;
|
||||
|
||||
bool
|
||||
operator<(const PathHopConfig& other) const
|
||||
{
|
||||
return std::tie(txID, rxID, rc, upstream, lifetime)
|
||||
< std::tie(other.txID, other.rxID, other.rc, other.upstream,
|
||||
other.lifetime);
|
||||
}
|
||||
};
|
||||
|
||||
inline bool
|
||||
operator<(const PathHopConfig& lhs, const PathHopConfig& rhs)
|
||||
{
|
||||
return std::tie(lhs.txID, lhs.rxID, lhs.rc, lhs.upstream, lhs.lifetime)
|
||||
< std::tie(rhs.txID, rhs.rxID, rhs.rc, rhs.upstream, rhs.lifetime);
|
||||
}
|
||||
|
||||
/// A path we made
|
||||
struct Path : public IHopHandler,
|
||||
public routing::IMessageHandler,
|
||||
|
@ -591,137 +349,6 @@ namespace llarp
|
|||
PathStatus _status;
|
||||
PathRole _role;
|
||||
};
|
||||
|
||||
enum PathBuildStatus
|
||||
{
|
||||
ePathBuildSuccess,
|
||||
ePathBuildTimeout,
|
||||
ePathBuildReject
|
||||
};
|
||||
|
||||
struct PathContext
|
||||
{
|
||||
PathContext(AbstractRouter* router);
|
||||
~PathContext();
|
||||
|
||||
/// called from router tick function
|
||||
void
|
||||
ExpirePaths(llarp_time_t now);
|
||||
|
||||
void
|
||||
AllowTransit();
|
||||
|
||||
void
|
||||
RejectTransit();
|
||||
|
||||
bool
|
||||
AllowingTransit() const;
|
||||
|
||||
bool
|
||||
HasTransitHop(const TransitHopInfo& info);
|
||||
|
||||
bool
|
||||
HandleRelayCommit(const LR_CommitMessage& msg);
|
||||
|
||||
void
|
||||
PutTransitHop(std::shared_ptr< TransitHop > hop);
|
||||
|
||||
HopHandler_ptr
|
||||
GetByUpstream(const RouterID& id, const PathID_t& path);
|
||||
|
||||
bool
|
||||
TransitHopPreviousIsRouter(const PathID_t& path, const RouterID& r);
|
||||
|
||||
HopHandler_ptr
|
||||
GetPathForTransfer(const PathID_t& topath);
|
||||
|
||||
HopHandler_ptr
|
||||
GetByDownstream(const RouterID& id, const PathID_t& path);
|
||||
|
||||
PathSet_ptr
|
||||
GetLocalPathSet(const PathID_t& id);
|
||||
|
||||
routing::MessageHandler_ptr
|
||||
GetHandler(const PathID_t& id);
|
||||
|
||||
using EndpointPathPtrSet = std::set< Path_ptr, ComparePtr< Path_ptr > >;
|
||||
/// get a set of all paths that we own who's endpoint is r
|
||||
EndpointPathPtrSet
|
||||
FindOwnedPathsWithEndpoint(const RouterID& r);
|
||||
|
||||
bool
|
||||
ForwardLRCM(const RouterID& nextHop,
|
||||
const std::array< EncryptedFrame, 8 >& frames);
|
||||
|
||||
bool
|
||||
HopIsUs(const RouterID& k) const;
|
||||
|
||||
bool
|
||||
HandleLRUM(const RelayUpstreamMessage& msg);
|
||||
|
||||
bool
|
||||
HandleLRDM(const RelayDownstreamMessage& msg);
|
||||
|
||||
void
|
||||
AddOwnPath(PathSet_ptr set, Path_ptr p);
|
||||
|
||||
void
|
||||
RemovePathSet(PathSet_ptr set);
|
||||
|
||||
using TransitHopsMap_t = std::multimap< PathID_t, TransitHop_ptr >;
|
||||
|
||||
struct SyncTransitMap_t
|
||||
{
|
||||
util::Mutex first; // protects second
|
||||
TransitHopsMap_t second GUARDED_BY(first);
|
||||
|
||||
void
|
||||
ForEach(std::function< void(const TransitHop_ptr&) > visit)
|
||||
{
|
||||
util::Lock lock(&first);
|
||||
for(const auto& item : second)
|
||||
visit(item.second);
|
||||
}
|
||||
};
|
||||
|
||||
// maps path id -> pathset owner of path
|
||||
using OwnedPathsMap_t = std::map< PathID_t, PathSet_ptr >;
|
||||
|
||||
struct SyncOwnedPathsMap_t
|
||||
{
|
||||
util::Mutex first; // protects second
|
||||
OwnedPathsMap_t second GUARDED_BY(first);
|
||||
|
||||
void
|
||||
ForEach(std::function< void(const PathSet_ptr&) > visit)
|
||||
{
|
||||
util::Lock lock(&first);
|
||||
for(const auto& item : second)
|
||||
visit(item.second);
|
||||
}
|
||||
};
|
||||
|
||||
llarp_threadpool*
|
||||
Worker();
|
||||
|
||||
std::shared_ptr< Logic >
|
||||
logic();
|
||||
|
||||
AbstractRouter*
|
||||
Router();
|
||||
|
||||
const SecretKey&
|
||||
EncryptionSecretKey();
|
||||
|
||||
const byte_t*
|
||||
OurRouterID() const;
|
||||
|
||||
private:
|
||||
AbstractRouter* m_Router;
|
||||
SyncTransitMap_t m_TransitPaths;
|
||||
SyncOwnedPathsMap_t m_OurPaths;
|
||||
bool m_AllowTransit;
|
||||
};
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
||||
|
|
|
@ -0,0 +1,336 @@
|
|||
#include <path/path_context.hpp>
|
||||
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace path
|
||||
{
|
||||
PathContext::PathContext(AbstractRouter* router)
|
||||
: m_Router(router), m_AllowTransit(false)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::AllowTransit()
|
||||
{
|
||||
m_AllowTransit = true;
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::AllowingTransit() const
|
||||
{
|
||||
return m_AllowTransit;
|
||||
}
|
||||
|
||||
llarp_threadpool*
|
||||
PathContext::Worker()
|
||||
{
|
||||
return m_Router->threadpool();
|
||||
}
|
||||
|
||||
std::shared_ptr< Logic >
|
||||
PathContext::logic()
|
||||
{
|
||||
return m_Router->logic();
|
||||
}
|
||||
|
||||
const SecretKey&
|
||||
PathContext::EncryptionSecretKey()
|
||||
{
|
||||
return m_Router->encryption();
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::HopIsUs(const RouterID& k) const
|
||||
{
|
||||
return std::equal(m_Router->pubkey(), m_Router->pubkey() + PUBKEYSIZE,
|
||||
k.begin());
|
||||
}
|
||||
|
||||
PathContext::EndpointPathPtrSet
|
||||
PathContext::FindOwnedPathsWithEndpoint(const RouterID& r)
|
||||
{
|
||||
EndpointPathPtrSet found;
|
||||
m_OurPaths.ForEach([&](const PathSet_ptr& set) {
|
||||
set->ForEachPath([&](const Path_ptr& p) {
|
||||
if(p->Endpoint() == r && p->IsReady())
|
||||
found.insert(p);
|
||||
});
|
||||
});
|
||||
return found;
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::ForwardLRCM(const RouterID& nextHop,
|
||||
const std::array< EncryptedFrame, 8 >& frames)
|
||||
{
|
||||
auto msg = std::make_shared< const LR_CommitMessage >(frames);
|
||||
|
||||
LogDebug("forwarding LRCM to ", nextHop);
|
||||
if(m_Router->HasSessionTo(nextHop))
|
||||
{
|
||||
return m_Router->SendToOrQueue(nextHop, msg.get());
|
||||
}
|
||||
const RouterID router = nextHop;
|
||||
AbstractRouter* const r = m_Router;
|
||||
m_Router->EnsureRouter(
|
||||
nextHop, [msg, r, router](const std::vector< RouterContact >& found) {
|
||||
if(found.size())
|
||||
{
|
||||
r->TryConnectAsync(found[0], 1);
|
||||
r->SendToOrQueue(router, msg.get());
|
||||
}
|
||||
else
|
||||
LogError("dropped LRCM to ", router,
|
||||
" as we cannot find in via DHT");
|
||||
});
|
||||
LogInfo("we are not directly connected to ", router,
|
||||
" so we need to do a lookup");
|
||||
return true;
|
||||
}
|
||||
template < typename Map_t, typename Key_t, typename CheckValue_t,
|
||||
typename GetFunc_t >
|
||||
HopHandler_ptr
|
||||
MapGet(Map_t& map, const Key_t& k, CheckValue_t check, GetFunc_t get)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(check(i->second))
|
||||
return get(i->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename CheckValue_t >
|
||||
bool
|
||||
MapHas(Map_t& map, const Key_t& k, CheckValue_t check)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(check(i->second))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename Value_t >
|
||||
void
|
||||
MapPut(Map_t& map, const Key_t& k, const Value_t& v)
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
map.second.emplace(k, v);
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Visit_t >
|
||||
void
|
||||
MapIter(Map_t& map, Visit_t v)
|
||||
{
|
||||
util::Lock lock(map.first);
|
||||
for(const auto& item : map.second)
|
||||
v(item);
|
||||
}
|
||||
|
||||
template < typename Map_t, typename Key_t, typename Check_t >
|
||||
void
|
||||
MapDel(Map_t& map, const Key_t& k, Check_t check)
|
||||
{
|
||||
util::Lock lock(map.first);
|
||||
auto range = map.second.equal_range(k);
|
||||
for(auto i = range.first; i != range.second;)
|
||||
{
|
||||
if(check(i->second))
|
||||
i = map.second.erase(i);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::AddOwnPath(PathSet_ptr set, Path_ptr path)
|
||||
{
|
||||
set->AddPath(path);
|
||||
MapPut(m_OurPaths, path->TXID(), set);
|
||||
MapPut(m_OurPaths, path->RXID(), set);
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::HasTransitHop(const TransitHopInfo& info)
|
||||
{
|
||||
return MapHas(m_TransitPaths, info.txID,
|
||||
[info](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return info == hop->info;
|
||||
});
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
|
||||
{
|
||||
auto own = MapGet(
|
||||
m_OurPaths, id,
|
||||
[](const PathSet_ptr) -> bool {
|
||||
// TODO: is this right?
|
||||
return true;
|
||||
},
|
||||
[remote, id](PathSet_ptr p) -> HopHandler_ptr {
|
||||
return p->GetByUpstream(remote, id);
|
||||
});
|
||||
if(own)
|
||||
return own;
|
||||
|
||||
return MapGet(
|
||||
m_TransitPaths, id,
|
||||
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return hop->info.upstream == remote;
|
||||
},
|
||||
[](const std::shared_ptr< TransitHop >& h) -> HopHandler_ptr {
|
||||
return h;
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
PathContext::TransitHopPreviousIsRouter(const PathID_t& path,
|
||||
const RouterID& otherRouter)
|
||||
{
|
||||
util::Lock lock(&m_TransitPaths.first);
|
||||
auto itr = m_TransitPaths.second.find(path);
|
||||
if(itr == m_TransitPaths.second.end())
|
||||
return false;
|
||||
return itr->second->info.downstream == otherRouter;
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetByDownstream(const RouterID& remote, const PathID_t& id)
|
||||
{
|
||||
return MapGet(
|
||||
m_TransitPaths, id,
|
||||
[remote](const std::shared_ptr< TransitHop >& hop) -> bool {
|
||||
return hop->info.downstream == remote;
|
||||
},
|
||||
[](const std::shared_ptr< TransitHop >& h) -> HopHandler_ptr {
|
||||
return h;
|
||||
});
|
||||
}
|
||||
|
||||
PathSet_ptr
|
||||
PathContext::GetLocalPathSet(const PathID_t& id)
|
||||
{
|
||||
auto& map = m_OurPaths;
|
||||
util::Lock lock(&map.first);
|
||||
auto itr = map.second.find(id);
|
||||
if(itr != map.second.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const byte_t*
|
||||
PathContext::OurRouterID() const
|
||||
{
|
||||
return m_Router->pubkey();
|
||||
}
|
||||
|
||||
AbstractRouter*
|
||||
PathContext::Router()
|
||||
{
|
||||
return m_Router;
|
||||
}
|
||||
|
||||
HopHandler_ptr
|
||||
PathContext::GetPathForTransfer(const PathID_t& id)
|
||||
{
|
||||
RouterID us(OurRouterID());
|
||||
auto& map = m_TransitPaths;
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(id);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(i->second->info.upstream == us)
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::PutTransitHop(std::shared_ptr< TransitHop > hop)
|
||||
{
|
||||
MapPut(m_TransitPaths, hop->info.txID, hop);
|
||||
MapPut(m_TransitPaths, hop->info.rxID, hop);
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::ExpirePaths(llarp_time_t now)
|
||||
{
|
||||
{
|
||||
util::Lock lock(&m_TransitPaths.first);
|
||||
auto& map = m_TransitPaths.second;
|
||||
auto itr = map.begin();
|
||||
while(itr != map.end())
|
||||
{
|
||||
if(itr->second->Expired(now))
|
||||
{
|
||||
itr = map.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
{
|
||||
util::Lock lock(&m_OurPaths.first);
|
||||
auto& map = m_OurPaths.second;
|
||||
for(auto& item : map)
|
||||
{
|
||||
item.second->ExpirePaths(now);
|
||||
}
|
||||
}
|
||||
}
|
||||
routing::MessageHandler_ptr
|
||||
PathContext::GetHandler(const PathID_t& id)
|
||||
{
|
||||
routing::MessageHandler_ptr h = nullptr;
|
||||
auto pathset = GetLocalPathSet(id);
|
||||
if(pathset)
|
||||
{
|
||||
h = pathset->GetPathByID(id);
|
||||
}
|
||||
if(h)
|
||||
return h;
|
||||
const RouterID us(OurRouterID());
|
||||
auto& map = m_TransitPaths;
|
||||
{
|
||||
util::Lock lock(&map.first);
|
||||
auto range = map.second.equal_range(id);
|
||||
for(auto i = range.first; i != range.second; ++i)
|
||||
{
|
||||
if(i->second->info.upstream == us)
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::RemovePathSet(PathSet_ptr set)
|
||||
{
|
||||
util::Lock lock(&m_OurPaths.first);
|
||||
auto& map = m_OurPaths.second;
|
||||
auto itr = map.begin();
|
||||
while(itr != map.end())
|
||||
{
|
||||
if(itr->second.get() == set.get())
|
||||
itr = map.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
} // namespace path
|
||||
} // namespace llarp
|
|
@ -0,0 +1,156 @@
|
|||
#ifndef LLARP_PATH_CONTEXT_HPP
|
||||
#define LLARP_PATH_CONTEXT_HPP
|
||||
|
||||
#include <crypto/encrypted_frame.hpp>
|
||||
#include <path/ihophandler.hpp>
|
||||
#include <path/path_types.hpp>
|
||||
#include <path/pathset.hpp>
|
||||
#include <path/transit_hop.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/compare_ptr.hpp>
|
||||
#include <util/types.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
class Logic;
|
||||
struct AbstractRouter;
|
||||
struct LR_CommitMessage;
|
||||
struct RelayDownstreamMessage;
|
||||
struct RelayUpstreamMessage;
|
||||
struct RouterID;
|
||||
|
||||
namespace path
|
||||
{
|
||||
struct TransitHop;
|
||||
struct TransitHopInfo;
|
||||
|
||||
using TransitHop_ptr = std::shared_ptr< TransitHop >;
|
||||
|
||||
struct PathContext
|
||||
{
|
||||
PathContext(AbstractRouter* router);
|
||||
|
||||
/// called from router tick function
|
||||
void
|
||||
ExpirePaths(llarp_time_t now);
|
||||
|
||||
void
|
||||
AllowTransit();
|
||||
|
||||
void
|
||||
RejectTransit();
|
||||
|
||||
bool
|
||||
AllowingTransit() const;
|
||||
|
||||
bool
|
||||
HasTransitHop(const TransitHopInfo& info);
|
||||
|
||||
bool
|
||||
HandleRelayCommit(const LR_CommitMessage& msg);
|
||||
|
||||
void
|
||||
PutTransitHop(std::shared_ptr< TransitHop > hop);
|
||||
|
||||
HopHandler_ptr
|
||||
GetByUpstream(const RouterID& id, const PathID_t& path);
|
||||
|
||||
bool
|
||||
TransitHopPreviousIsRouter(const PathID_t& path, const RouterID& r);
|
||||
|
||||
HopHandler_ptr
|
||||
GetPathForTransfer(const PathID_t& topath);
|
||||
|
||||
HopHandler_ptr
|
||||
GetByDownstream(const RouterID& id, const PathID_t& path);
|
||||
|
||||
PathSet_ptr
|
||||
GetLocalPathSet(const PathID_t& id);
|
||||
|
||||
routing::MessageHandler_ptr
|
||||
GetHandler(const PathID_t& id);
|
||||
|
||||
using EndpointPathPtrSet = std::set< Path_ptr, ComparePtr< Path_ptr > >;
|
||||
/// get a set of all paths that we own who's endpoint is r
|
||||
EndpointPathPtrSet
|
||||
FindOwnedPathsWithEndpoint(const RouterID& r);
|
||||
|
||||
bool
|
||||
ForwardLRCM(const RouterID& nextHop,
|
||||
const std::array< EncryptedFrame, 8 >& frames);
|
||||
|
||||
bool
|
||||
HopIsUs(const RouterID& k) const;
|
||||
|
||||
bool
|
||||
HandleLRUM(const RelayUpstreamMessage& msg);
|
||||
|
||||
bool
|
||||
HandleLRDM(const RelayDownstreamMessage& msg);
|
||||
|
||||
void
|
||||
AddOwnPath(PathSet_ptr set, Path_ptr p);
|
||||
|
||||
void
|
||||
RemovePathSet(PathSet_ptr set);
|
||||
|
||||
using TransitHopsMap_t = std::multimap< PathID_t, TransitHop_ptr >;
|
||||
|
||||
struct SyncTransitMap_t
|
||||
{
|
||||
util::Mutex first; // protects second
|
||||
TransitHopsMap_t second GUARDED_BY(first);
|
||||
|
||||
void
|
||||
ForEach(std::function< void(const TransitHop_ptr&) > visit)
|
||||
{
|
||||
util::Lock lock(&first);
|
||||
for(const auto& item : second)
|
||||
visit(item.second);
|
||||
}
|
||||
};
|
||||
|
||||
// maps path id -> pathset owner of path
|
||||
using OwnedPathsMap_t = std::map< PathID_t, PathSet_ptr >;
|
||||
|
||||
struct SyncOwnedPathsMap_t
|
||||
{
|
||||
util::Mutex first; // protects second
|
||||
OwnedPathsMap_t second GUARDED_BY(first);
|
||||
|
||||
void
|
||||
ForEach(std::function< void(const PathSet_ptr&) > visit)
|
||||
{
|
||||
util::Lock lock(&first);
|
||||
for(const auto& item : second)
|
||||
visit(item.second);
|
||||
}
|
||||
};
|
||||
|
||||
llarp_threadpool*
|
||||
Worker();
|
||||
|
||||
std::shared_ptr< Logic >
|
||||
logic();
|
||||
|
||||
AbstractRouter*
|
||||
Router();
|
||||
|
||||
const SecretKey&
|
||||
EncryptionSecretKey();
|
||||
|
||||
const byte_t*
|
||||
OurRouterID() const;
|
||||
|
||||
private:
|
||||
AbstractRouter* m_Router;
|
||||
SyncTransitMap_t m_TransitPaths;
|
||||
SyncOwnedPathsMap_t m_OurPaths;
|
||||
bool m_AllowTransit;
|
||||
};
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -3,7 +3,7 @@
|
|||
#include <crypto/crypto.hpp>
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <profiling.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef LLARP_PATHBUILDER_HPP_
|
||||
#define LLARP_PATHBUILDER_HPP_
|
||||
#ifndef LLARP_PATHBUILDER_HPP
|
||||
#define LLARP_PATHBUILDER_HPP
|
||||
|
||||
#include <path/pathset.hpp>
|
||||
#include <util/status.hpp>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <path/pathset.hpp>
|
||||
|
||||
#include <dht/messages/pubintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
#include <dht/context.hpp>
|
||||
#include <exit/context.hpp>
|
||||
#include <exit/exit_messages.hpp>
|
||||
#include <messages/discard.hpp>
|
||||
#include <messages/exit.hpp>
|
||||
#include <messages/path_latency.hpp>
|
||||
#include <messages/path_transfer.hpp>
|
||||
#include <messages/relay_commit.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <path/transit_hop.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/path_latency_message.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/endian.hpp>
|
||||
|
@ -16,6 +18,18 @@ namespace llarp
|
|||
{
|
||||
namespace path
|
||||
{
|
||||
std::ostream&
|
||||
TransitHopInfo::print(std::ostream& stream, int level, int spaces) const
|
||||
{
|
||||
Printer printer(stream, level, spaces);
|
||||
printer.printAttribute("tx", txID);
|
||||
printer.printAttribute("rx", rxID);
|
||||
printer.printAttribute("upstream", upstream);
|
||||
printer.printAttribute("downstream", downstream);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
TransitHop::TransitHop()
|
||||
{
|
||||
}
|
||||
|
@ -303,5 +317,15 @@ namespace llarp
|
|||
return SendRoutingMessage(discarded, r);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
TransitHop::print(std::ostream& stream, int level, int spaces) const
|
||||
{
|
||||
Printer printer(stream, level, spaces);
|
||||
printer.printAttribute("TransitHop", info);
|
||||
printer.printAttribute("started", started);
|
||||
printer.printAttribute("lifetime", lifetime);
|
||||
|
||||
return stream;
|
||||
}
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
#ifndef LLARP_PATH_TRANSIT_HOP_HPP
|
||||
#define LLARP_PATH_TRANSIT_HOP_HPP
|
||||
|
||||
#include <constants/path.hpp>
|
||||
#include <path/ihophandler.hpp>
|
||||
#include <path/path_types.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
#include <router_id.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct LR_CommitRecord;
|
||||
|
||||
namespace dht
|
||||
{
|
||||
struct GotIntroMessage;
|
||||
}
|
||||
|
||||
namespace path
|
||||
{
|
||||
struct TransitHopInfo
|
||||
{
|
||||
TransitHopInfo() = default;
|
||||
TransitHopInfo(const RouterID& down, const LR_CommitRecord& record);
|
||||
|
||||
PathID_t txID, rxID;
|
||||
RouterID upstream;
|
||||
RouterID downstream;
|
||||
|
||||
std::ostream&
|
||||
print(std::ostream& stream, int level, int spaces) const;
|
||||
|
||||
struct PathIDHash
|
||||
{
|
||||
std::size_t
|
||||
operator()(const PathID_t& a) const
|
||||
{
|
||||
return AlignedBuffer< PathID_t::SIZE >::Hash()(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Hash
|
||||
{
|
||||
std::size_t
|
||||
operator()(TransitHopInfo const& a) const
|
||||
{
|
||||
std::size_t idx0 = RouterID::Hash()(a.upstream);
|
||||
std::size_t idx1 = RouterID::Hash()(a.downstream);
|
||||
std::size_t idx2 = PathIDHash()(a.txID);
|
||||
std::size_t idx3 = PathIDHash()(a.rxID);
|
||||
return idx0 ^ idx1 ^ idx2 ^ idx3;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
inline bool
|
||||
operator==(const TransitHopInfo& lhs, const TransitHopInfo& rhs)
|
||||
{
|
||||
return std::tie(lhs.txID, lhs.rxID, lhs.upstream, lhs.downstream)
|
||||
== std::tie(rhs.txID, rhs.rxID, rhs.upstream, rhs.downstream);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(const TransitHopInfo& lhs, const TransitHopInfo& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator<(const TransitHopInfo& lhs, const TransitHopInfo& rhs)
|
||||
{
|
||||
return std::tie(lhs.txID, lhs.rxID, lhs.upstream, lhs.downstream)
|
||||
< std::tie(rhs.txID, rhs.rxID, rhs.upstream, rhs.downstream);
|
||||
}
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const TransitHopInfo& info)
|
||||
{
|
||||
return info.print(out, -1, -1);
|
||||
}
|
||||
|
||||
struct TransitHop : public IHopHandler, public routing::IMessageHandler
|
||||
{
|
||||
TransitHop();
|
||||
|
||||
TransitHopInfo info;
|
||||
SharedSecret pathKey;
|
||||
ShortHash nonceXOR;
|
||||
llarp_time_t started = 0;
|
||||
// 10 minutes default
|
||||
llarp_time_t lifetime = default_lifetime;
|
||||
llarp_proto_version_t version;
|
||||
llarp_time_t m_LastActivity = 0;
|
||||
|
||||
bool
|
||||
IsEndpoint(const RouterID& us) const
|
||||
{
|
||||
return info.upstream == us;
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
ExpireTime() const;
|
||||
|
||||
llarp_time_t
|
||||
LastRemoteActivityAt() const override
|
||||
{
|
||||
return m_LastActivity;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
print(std::ostream& stream, int level, int spaces) const;
|
||||
|
||||
bool
|
||||
Expired(llarp_time_t now) const override;
|
||||
|
||||
bool
|
||||
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const override
|
||||
{
|
||||
return now >= ExpireTime() - dlt;
|
||||
}
|
||||
|
||||
// send routing message when end of path
|
||||
bool
|
||||
SendRoutingMessage(const routing::IMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
// handle routing message when end of path
|
||||
bool
|
||||
HandleRoutingMessage(const routing::IMessage& msg, AbstractRouter* r);
|
||||
|
||||
bool
|
||||
HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandlePathTransferMessage(const routing::PathTransferMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleGrantExitMessage(const routing::GrantExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
bool
|
||||
HandleRejectExitMessage(const routing::RejectExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleCloseExitMessage(const routing::CloseExitMessage& msg,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
bool
|
||||
HandleHiddenServiceFrame(
|
||||
ABSL_ATTRIBUTE_UNUSED const service::ProtocolFrame& frame) override
|
||||
{
|
||||
/// TODO: implement me
|
||||
LogWarn("Got hidden service data on transit hop");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HandleGotIntroMessage(const dht::GotIntroMessage& msg);
|
||||
|
||||
bool
|
||||
HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
|
||||
|
||||
// handle data in upstream direction
|
||||
bool
|
||||
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) override;
|
||||
|
||||
// handle data in downstream direction
|
||||
bool
|
||||
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
||||
AbstractRouter* r) override;
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const TransitHop& h)
|
||||
{
|
||||
return h.print(out, -1, -1);
|
||||
}
|
||||
} // namespace path
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -11,7 +11,7 @@
|
|||
#include <link/server.hpp>
|
||||
#include <messages/link_message_parser.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <path/path.hpp>
|
||||
#include <path/path_context.hpp>
|
||||
#include <profiling.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
@ -211,7 +211,7 @@ namespace llarp
|
|||
|
||||
uint32_t ticker_job_id = 0;
|
||||
|
||||
InboundMessageParser inbound_link_msg_parser;
|
||||
LinkMessageParser inbound_link_msg_parser;
|
||||
routing::InboundMessageParser inbound_routing_msg_parser;
|
||||
|
||||
service::Context _hiddenServiceContext;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <messages/dht.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/handler.hpp>
|
||||
|
@ -7,10 +7,6 @@ namespace llarp
|
|||
{
|
||||
namespace routing
|
||||
{
|
||||
DHTMessage::~DHTMessage()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
DHTMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val)
|
||||
{
|
||||
|
@ -63,6 +59,5 @@ namespace llarp
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace llarp
|
|||
std::vector< llarp::dht::IMessage::Ptr_t > M;
|
||||
uint64_t V = 0;
|
||||
|
||||
~DHTMessage();
|
||||
~DHTMessage() = default;
|
||||
|
||||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
|
@ -1,13 +1,13 @@
|
|||
#include <routing/message_parser.hpp>
|
||||
|
||||
#include <messages/dht.hpp>
|
||||
#include <exit/exit_messages.hpp>
|
||||
#include <messages/discard.hpp>
|
||||
#include <messages/exit.hpp>
|
||||
#include <messages/path_confirm.hpp>
|
||||
#include <messages/path_latency.hpp>
|
||||
#include <messages/path_transfer.hpp>
|
||||
#include <messages/transfer_traffic.hpp>
|
||||
#include <path/path_types.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <routing/path_confirm_message.hpp>
|
||||
#include <routing/path_latency_message.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
#include <routing/transfer_traffic_message.hpp>
|
||||
#include <util/mem.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <messages/path_confirm.hpp>
|
||||
#include <routing/path_confirm_message.hpp>
|
||||
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/bencode.hpp>
|
||||
|
@ -8,10 +8,6 @@ namespace llarp
|
|||
{
|
||||
namespace routing
|
||||
{
|
||||
PathConfirmMessage::PathConfirmMessage() : pathLifetime(0), pathCreated(0)
|
||||
{
|
||||
}
|
||||
|
||||
PathConfirmMessage::PathConfirmMessage(uint64_t lifetime)
|
||||
: pathLifetime(lifetime), pathCreated(time_now_ms())
|
||||
{
|
|
@ -9,13 +9,12 @@ namespace llarp
|
|||
{
|
||||
struct PathConfirmMessage final : public IMessage
|
||||
{
|
||||
uint64_t pathLifetime;
|
||||
uint64_t pathCreated;
|
||||
PathConfirmMessage();
|
||||
uint64_t pathLifetime = 0;
|
||||
uint64_t pathCreated = 0;
|
||||
|
||||
PathConfirmMessage() = default;
|
||||
PathConfirmMessage(uint64_t lifetime);
|
||||
~PathConfirmMessage()
|
||||
{
|
||||
}
|
||||
~PathConfirmMessage() = default;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const override;
|
|
@ -1,4 +1,5 @@
|
|||
#include <messages/path_latency.hpp>
|
||||
#include <routing/path_latency_message.hpp>
|
||||
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/bencode.hpp>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <messages/path_transfer.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
|
@ -7,14 +7,6 @@ namespace llarp
|
|||
{
|
||||
namespace routing
|
||||
{
|
||||
PathTransferMessage::PathTransferMessage() : IMessage()
|
||||
{
|
||||
}
|
||||
|
||||
PathTransferMessage::~PathTransferMessage()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
PathTransferMessage::DecodeKey(const llarp_buffer_t& key,
|
||||
llarp_buffer_t* val)
|
|
@ -16,13 +16,13 @@ namespace llarp
|
|||
service::ProtocolFrame T;
|
||||
TunnelNonce Y;
|
||||
|
||||
PathTransferMessage();
|
||||
PathTransferMessage() = default;
|
||||
PathTransferMessage(const service::ProtocolFrame& f, const PathID_t& p)
|
||||
: P(p), T(f)
|
||||
{
|
||||
Y.Randomize();
|
||||
}
|
||||
~PathTransferMessage();
|
||||
~PathTransferMessage() = default;
|
||||
|
||||
bool
|
||||
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
|
@ -1,4 +1,4 @@
|
|||
#include <messages/transfer_traffic.hpp>
|
||||
#include <routing/transfer_traffic_message.hpp>
|
||||
|
||||
#include <routing/handler.hpp>
|
||||
#include <util/bencode.hpp>
|
|
@ -5,11 +5,11 @@
|
|||
#include <dht/messages/gotintro.hpp>
|
||||
#include <dht/messages/gotrouter.hpp>
|
||||
#include <dht/messages/pubintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <messages/path_transfer.hpp>
|
||||
#include <nodedb.hpp>
|
||||
#include <profiling.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
#include <service/endpoint_util.hpp>
|
||||
#include <service/hidden_service_address_lookup.hpp>
|
||||
#include <service/outbound_context.hpp>
|
||||
|
@ -1163,18 +1163,18 @@ namespace llarp
|
|||
}
|
||||
m_PendingTraffic[remote].emplace_back(data, t);
|
||||
// no converstation
|
||||
return EnsurePathToService(remote,
|
||||
[&](Address r, OutboundContext* c) {
|
||||
if(c)
|
||||
{
|
||||
c->UpdateIntroSet(true);
|
||||
for(auto& pending : m_PendingTraffic[r])
|
||||
c->AsyncEncryptAndSendTo(
|
||||
pending.Buffer(), pending.protocol);
|
||||
}
|
||||
m_PendingTraffic.erase(r);
|
||||
},
|
||||
5000, true);
|
||||
return EnsurePathToService(
|
||||
remote,
|
||||
[&](Address r, OutboundContext* c) {
|
||||
if(c)
|
||||
{
|
||||
c->UpdateIntroSet(true);
|
||||
for(auto& pending : m_PendingTraffic[r])
|
||||
c->AsyncEncryptAndSendTo(pending.Buffer(), pending.protocol);
|
||||
}
|
||||
m_PendingTraffic.erase(r);
|
||||
},
|
||||
5000, true);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LLARP_SERVICE_HIDDEN_SERVICE_ADDRESS_LOOKUP_HPP
|
||||
#define LLARP_SERVICE_HIDDEN_SERVICE_ADDRESS_LOOKUP_HPP
|
||||
|
||||
#include <messages/dht.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <service/intro_set.hpp>
|
||||
#include <service/lookup.hpp>
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <service/sendcontext.hpp>
|
||||
|
||||
#include <messages/path_transfer.hpp>
|
||||
#include <service/endpoint.hpp>
|
||||
#include <router/abstractrouter.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
#include <service/endpoint.hpp>
|
||||
#include <util/logic.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#ifndef LLARP_SERVICE_SENDCONTEXT_HPP
|
||||
#define LLARP_SERVICE_SENDCONTEXT_HPP
|
||||
#include <messages/path_transfer.hpp>
|
||||
|
||||
#include <path/pathset.hpp>
|
||||
#include <routing/path_transfer_message.hpp>
|
||||
#include <service/intro.hpp>
|
||||
#include <service/protocol.hpp>
|
||||
#include <util/buffer.hpp>
|
||||
#include <util/types.hpp>
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace llarp
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <service/tag_lookup_job.hpp>
|
||||
|
||||
#include <dht/messages/findintro.hpp>
|
||||
#include <messages/dht.hpp>
|
||||
#include <routing/dht_message.hpp>
|
||||
#include <service/endpoint.hpp>
|
||||
|
||||
namespace llarp
|
||||
|
|
14
readme.md
14
readme.md
|
@ -1,6 +1,6 @@
|
|||
# LokiNet
|
||||
# Lokinet
|
||||
|
||||
LokiNet is the reference implementation of LLARP (low latency anonymous routing protocol), a layer 3 onion routing protocol.
|
||||
Lokinet is the reference implementation of LLARP (low latency anonymous routing protocol), a layer 3 onion routing protocol.
|
||||
|
||||
You can learn more about the high level design of LLARP [here](docs/high-level.txt)
|
||||
|
||||
|
@ -13,7 +13,7 @@ You can view documentation on how to get started [here](https://loki-project.git
|
|||
|
||||
## Usage
|
||||
|
||||
see the [documentation](https://loki-project.github.io/loki-docs/Lokinet/LokinetOverview/) on how to get started.
|
||||
See the [documentation](https://loki-project.github.io/loki-docs/Lokinet/LokinetOverview/) on how to get started.
|
||||
|
||||
Also read the [Public Testing Guide](https://lokidocs.com/Lokinet/Guides/PublicTestingGuide/#1-lokinet-installation) for installation and other helpful information.
|
||||
|
||||
|
@ -29,7 +29,7 @@ to run as client:
|
|||
|
||||
to run as relay:
|
||||
|
||||
$ lokinet -r
|
||||
$ lokinet -r -g
|
||||
$ lokinet-bootstrap
|
||||
$ lokinet
|
||||
|
||||
|
@ -47,7 +47,7 @@ to run as client:
|
|||
|
||||
to run as relay:
|
||||
|
||||
$ lokinet -r
|
||||
$ lokinet -r -g
|
||||
$ lokinet-bootstrap
|
||||
$ sudo lokinet
|
||||
|
||||
|
@ -67,7 +67,7 @@ Build requirements:
|
|||
* CMake
|
||||
* C++ 17 capable C++ compiler
|
||||
* gcovr (if generating test coverage with gcc)
|
||||
* libuv >= 1.27.0
|
||||
* libuv >= 1.27.0
|
||||
|
||||
### Linux
|
||||
|
||||
|
@ -76,7 +76,7 @@ build:
|
|||
$ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev
|
||||
$ git clone https://github.com/loki-project/loki-network
|
||||
$ cd loki-network
|
||||
$ make -j8
|
||||
$ make
|
||||
|
||||
install:
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <messages/transfer_traffic.hpp>
|
||||
#include <routing/transfer_traffic_message.hpp>
|
||||
|
||||
using TransferTrafficMessage = llarp::routing::TransferTrafficMessage;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <messages/exit.hpp>
|
||||
#include <exit/exit_messages.hpp>
|
||||
|
||||
#include <crypto/crypto.hpp>
|
||||
#include <crypto/crypto_libsodium.hpp>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
static int
|
||||
tuntap_sys_create_dev(struct device *dev, int tun)
|
||||
{
|
||||
int if_fd, ip_muxid, ppa = -1;
|
||||
int fd, strm_fd, ip_muxid, ppa = -1;
|
||||
struct lifreq lifr;
|
||||
struct ifreq ifr;
|
||||
const char *ptr = NULL;
|
||||
|
@ -74,7 +74,7 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ((dev->tun_fd = open("/dev/tun", O_RDWR, 0)) < 0)
|
||||
if ((fd = open("/dev/tun", O_RDWR, 0)) < 0)
|
||||
{
|
||||
tuntap_log(TUNTAP_LOG_ERR, "Can't open /dev/tun");
|
||||
return -1;
|
||||
|
@ -102,7 +102,7 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
bool found_one = false;
|
||||
while (!found_one && ppa < 64)
|
||||
{
|
||||
int new_ppa = ioctl(dev->tun_fd, I_STR, &strioc_ppa);
|
||||
int new_ppa = ioctl(fd, I_STR, &strioc_ppa);
|
||||
if (new_ppa >= 0)
|
||||
{
|
||||
char* msg = alloca(512);
|
||||
|
@ -127,7 +127,7 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
}
|
||||
else /* try this particular one */
|
||||
{
|
||||
if ((ppa = ioctl(dev->tun_fd, I_STR, &strioc_ppa)) < 0)
|
||||
if ((ppa = ioctl(fd, I_STR, &strioc_ppa)) < 0)
|
||||
{
|
||||
char *msg = alloca(512);
|
||||
sprintf(msg, "Can't assign PPA for new interface (tun%i)", ppa);
|
||||
|
@ -136,20 +136,21 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
}
|
||||
}
|
||||
|
||||
if ((if_fd = open("/dev/tun", O_RDWR, 0)) < 0)
|
||||
// Open a new handle to link up the STREAMS
|
||||
if ((strm_fd = open("/dev/tun", O_RDWR, 0)) < 0)
|
||||
{
|
||||
tuntap_log(TUNTAP_LOG_ERR, "Can't open /dev/tun (2)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(if_fd, I_PUSH, "ip") < 0)
|
||||
if (ioctl(strm_fd, I_PUSH, "ip") < 0)
|
||||
{
|
||||
tuntap_log(TUNTAP_LOG_ERR, "Can't push IP module");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Assign ppa according to the unit number returned by tun device */
|
||||
if (ioctl(if_fd, IF_UNITSEL, (char *) &ppa) < 0)
|
||||
if (ioctl(strm_fd, IF_UNITSEL, (char *) &ppa) < 0)
|
||||
{
|
||||
char *msg = alloca(512);
|
||||
sprintf(msg, "Can't set PPA %i", ppa);
|
||||
|
@ -159,7 +160,7 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
|
||||
snprintf(dev->internal_name, IF_NAMESIZE, "%s%d", "tun", ppa);
|
||||
|
||||
if ((ip_muxid = ioctl(dev->ip_fd, I_PLINK, if_fd)) < 0)
|
||||
if ((ip_muxid = ioctl(dev->ip_fd, I_PLINK, strm_fd)) < 0)
|
||||
{
|
||||
tuntap_log(TUNTAP_LOG_ERR, "Can't link tun device to IP");
|
||||
return -1;
|
||||
|
@ -177,8 +178,8 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
return -1;
|
||||
}
|
||||
|
||||
fcntl(dev->tun_fd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(dev->tun_fd, F_SETFD, FD_CLOEXEC);
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
fcntl(dev->ip_fd, F_SETFD, FD_CLOEXEC);
|
||||
char *msg = alloca(512);
|
||||
sprintf(msg, "TUN device %s opened as %s", dev->if_name, dev->internal_name);
|
||||
|
@ -194,7 +195,8 @@ tuntap_sys_create_dev(struct device *dev, int tun)
|
|||
}
|
||||
/* Save flags for tuntap_{up, down} */
|
||||
dev->flags = ifr.ifr_flags;
|
||||
return 0;
|
||||
dev->reserved = strm_fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -245,6 +247,8 @@ tuntap_sys_destroy(struct device *dev)
|
|||
}
|
||||
|
||||
close(dev->ip_fd);
|
||||
close(dev->reserved);
|
||||
dev->reserved = -1;
|
||||
dev->ip_fd = -1;
|
||||
}
|
||||
|
||||
|
@ -254,9 +258,12 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t bits)
|
|||
{
|
||||
struct lifreq ifr;
|
||||
struct sockaddr_in mask;
|
||||
struct in_addr net;
|
||||
char *src, *dst, *netmask;
|
||||
|
||||
(void)memset(&ifr, '\0', sizeof ifr);
|
||||
(void)memcpy(ifr.lifr_name, dev->internal_name, sizeof dev->internal_name);
|
||||
net.s_addr = htonl(ntohl(s4->s_addr) - 1); // this gets us x.x.x.0
|
||||
|
||||
/* Set the IP address first */
|
||||
(void)memcpy(&(((struct sockaddr_in *)&ifr.lifr_addr)->sin_addr), s4,
|
||||
|
@ -271,6 +278,20 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t bits)
|
|||
/* Reinit the struct ifr */
|
||||
(void)memset(&ifr.lifr_addr, '\0', sizeof ifr.lifr_addr);
|
||||
|
||||
/* Set the tunnel endpoint */
|
||||
(void)memcpy(&(((struct sockaddr_in *)&ifr.lifr_dstaddr)->sin_addr), s4,
|
||||
sizeof(struct in_addr));
|
||||
ifr.lifr_addr.ss_family = AF_INET;
|
||||
if(ioctl(dev->ctrl_sock, SIOCSLIFDSTADDR, &ifr) == -1)
|
||||
{
|
||||
tuntap_log(TUNTAP_LOG_ERR, "Can't set IP address");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Reinit the struct ifr */
|
||||
(void)memset(&ifr.lifr_addr, '\0', sizeof ifr.lifr_addr);
|
||||
(void)memset(&ifr.lifr_addr, '\0', sizeof ifr.lifr_dstaddr);
|
||||
|
||||
/* Then set the netmask */
|
||||
(void)memset(&mask, '\0', sizeof mask);
|
||||
mask.sin_family = AF_INET;
|
||||
|
@ -282,7 +303,16 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t bits)
|
|||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Now set the route, yup even ovpn does this :-/
|
||||
char* cmd = alloca(512);
|
||||
src = alloca(16);
|
||||
dst = alloca(16);
|
||||
netmask = alloca(16);
|
||||
strlcpy(src, inet_ntoa(net), 16);
|
||||
strlcpy(dst, inet_ntoa(*s4), 16);
|
||||
strlcpy(netmask, inet_ntoa(mask.sin_addr), 16);
|
||||
sprintf(cmd, "route add %s -netmask %s %s 0", src, netmask, dst);
|
||||
return system(cmd);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -318,4 +348,4 @@ tuntap_sys_set_descr(struct device *dev, const char *descr, size_t len)
|
|||
tuntap_log(TUNTAP_LOG_NOTICE,
|
||||
"Your system does not support tuntap_set_descr()");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,14 +173,14 @@ tuntap_set_ifname(struct device *dev, const char *ifname)
|
|||
int
|
||||
tuntap_up(struct device *dev)
|
||||
{
|
||||
/* On Solaris, the interface automatically comes up when an IP
|
||||
* address is first assigned.
|
||||
*/
|
||||
#ifndef __sun
|
||||
struct ifreq ifr;
|
||||
|
||||
(void)memset(&ifr, '\0', sizeof ifr);
|
||||
#ifndef __sun
|
||||
(void)memcpy(ifr.ifr_name, dev->if_name, sizeof dev->if_name);
|
||||
#else
|
||||
(void)memcpy(ifr.ifr_name, dev->internal_name, sizeof dev->internal_name);
|
||||
#endif
|
||||
ifr.ifr_flags = (short int)dev->flags;
|
||||
ifr.ifr_flags |= IFF_UP;
|
||||
|
||||
|
@ -190,7 +190,6 @@ tuntap_up(struct device *dev)
|
|||
}
|
||||
|
||||
dev->flags = ifr.ifr_flags;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -200,7 +199,11 @@ tuntap_down(struct device *dev)
|
|||
struct ifreq ifr;
|
||||
|
||||
(void)memset(&ifr, '\0', sizeof ifr);
|
||||
#ifndef __sun
|
||||
(void)memcpy(ifr.ifr_name, dev->if_name, sizeof dev->if_name);
|
||||
#else
|
||||
(void)memcpy(ifr.ifr_name, dev->internal_name, sizeof dev->internal_name);
|
||||
#endif
|
||||
ifr.ifr_flags = (short)dev->flags;
|
||||
ifr.ifr_flags &= ~IFF_UP;
|
||||
|
||||
|
|
Loading…
Reference in New Issue