mirror of https://github.com/oxen-io/lokinet
fix crash on premature close of event loop (also make format)
This commit is contained in:
parent
82af91213a
commit
622ed8d12e
|
@ -37,7 +37,7 @@ extern "C"
|
|||
|
||||
/// give main context a vpn file descriptor (android/ios)
|
||||
void
|
||||
llarp_main_inject_vpn_fd(struct llarp_main * m, int fd);
|
||||
llarp_main_inject_vpn_fd(struct llarp_main *m, int fd);
|
||||
|
||||
/// setup main context
|
||||
int
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace llarp
|
|||
|
||||
int num_nethreads = 1;
|
||||
bool singleThreaded = false;
|
||||
std::vector< std::thread > netio_threads;
|
||||
llarp_crypto crypto;
|
||||
llarp_router *router = nullptr;
|
||||
llarp_threadpool *worker = nullptr;
|
||||
|
|
|
@ -407,11 +407,10 @@ namespace llarp
|
|||
llarp_time_t
|
||||
Now();
|
||||
|
||||
|
||||
void
|
||||
ExploreNetworkVia(const Key_t& peer);
|
||||
|
||||
private:
|
||||
private:
|
||||
void
|
||||
ScheduleCleanupTimer();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ struct dns_tracker
|
|||
struct dns_msg_header
|
||||
{
|
||||
uint16_t id;
|
||||
|
||||
|
||||
uint8_t qr : 1;
|
||||
uint8_t opcode : 4;
|
||||
uint8_t aa : 1;
|
||||
|
@ -62,12 +62,13 @@ struct dns_msg_header
|
|||
uint8_t cd : 1;
|
||||
uint8_t rcode : 4;
|
||||
|
||||
uint16_t fields() const
|
||||
uint16_t
|
||||
fields() const
|
||||
{
|
||||
return (qr << 15) | (opcode << 14) | (aa << 10) | (tc << 9) | (rd << 8) << (ra << 7) | (z << 6) | rcode;
|
||||
return (qr << 15) | (opcode << 14) | (aa << 10) | (tc << 9)
|
||||
| (rd << 8) << (ra << 7) | (z << 6) | rcode;
|
||||
}
|
||||
|
||||
|
||||
uint16_t qdCount;
|
||||
uint16_t anCount;
|
||||
uint16_t nsCount;
|
||||
|
@ -128,7 +129,7 @@ extern "C"
|
|||
get32bits(const char *&buffer) throw();
|
||||
|
||||
bool
|
||||
decode_hdr(llarp_buffer_t * buffer, dns_msg_header * hdr);
|
||||
decode_hdr(llarp_buffer_t *buffer, dns_msg_header *hdr);
|
||||
|
||||
dns_msg_question *
|
||||
decode_question(const char *buffer, uint32_t *pos);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "dnsd.hpp"
|
||||
|
||||
using map_address_hook_func =
|
||||
std::function< bool(const byte_t* addr,bool isSNode, uint32_t ip) >;
|
||||
std::function< bool(const byte_t *addr, bool isSNode, uint32_t ip) >;
|
||||
|
||||
/// dotLokiLookup context/config
|
||||
struct dotLokiLookup
|
||||
|
@ -35,6 +35,6 @@ struct dotLokiLookup
|
|||
|
||||
dnsd_query_hook_response *
|
||||
llarp_dotlokilookup_handler(std::string name,
|
||||
const dnsd_question_request * request);
|
||||
const dnsd_question_request *request);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -68,7 +68,8 @@ write404_dnss_response(const dnsd_question_request *request);
|
|||
|
||||
/// for hook functions to use
|
||||
void
|
||||
writecname_dnss_response(std::string cname, const dnsd_question_request *request);
|
||||
writecname_dnss_response(std::string cname,
|
||||
const dnsd_question_request *request);
|
||||
// FIXME: llarp::Addr
|
||||
|
||||
/// send an A record found response
|
||||
|
@ -79,7 +80,8 @@ writesend_dnss_response(llarp::huint32_t *hostRes,
|
|||
|
||||
/// send an PTR record found response
|
||||
void
|
||||
writesend_dnss_revresponse(std::string reverse, const dnsd_question_request *request);
|
||||
writesend_dnss_revresponse(std::string reverse,
|
||||
const dnsd_question_request *request);
|
||||
// FIXME: llarp::Addr
|
||||
|
||||
//
|
||||
|
|
|
@ -167,13 +167,11 @@ llarp_tcp_acceptor_close(struct llarp_tcp_acceptor *);
|
|||
#define IFNAMSIZ (16)
|
||||
#endif
|
||||
|
||||
|
||||
struct llarp_fd_promise;
|
||||
|
||||
/// wait until the fd promise is set
|
||||
int
|
||||
llarp_fd_promise_wait_for_value(struct llarp_fd_promise * promise);
|
||||
|
||||
llarp_fd_promise_wait_for_value(struct llarp_fd_promise *promise);
|
||||
|
||||
struct llarp_tun_io
|
||||
{
|
||||
|
@ -185,9 +183,9 @@ struct llarp_tun_io
|
|||
void *user;
|
||||
void *impl;
|
||||
|
||||
/// functor for getting a promise that returns the vpn fd
|
||||
/// functor for getting a promise that returns the vpn fd
|
||||
/// dont set me if you don't know how to use this
|
||||
struct llarp_fd_promise * (*get_fd_promise)(struct llarp_tun_io *);
|
||||
struct llarp_fd_promise *(*get_fd_promise)(struct llarp_tun_io *);
|
||||
|
||||
struct llarp_ev_loop *parent;
|
||||
/// called when we are able to write right before we write
|
||||
|
@ -203,7 +201,6 @@ struct llarp_tun_io
|
|||
bool
|
||||
llarp_ev_add_tun(struct llarp_ev_loop *ev, struct llarp_tun_io *tun);
|
||||
|
||||
|
||||
/// async write a packet on tun interface
|
||||
/// returns true if queued, returns false on drop
|
||||
bool
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace llarp
|
|||
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const;
|
||||
|
||||
/// return true if this endpoint looks dead right now
|
||||
bool
|
||||
bool
|
||||
LooksDead(llarp_time_t now, llarp_time_t timeout = 10000) const;
|
||||
|
||||
/// tick ourself, reset tx/rx rates
|
||||
|
@ -105,27 +105,30 @@ namespace llarp
|
|||
uint64_t m_TxRate, m_RxRate;
|
||||
llarp_time_t m_LastActive;
|
||||
bool m_RewriteSource;
|
||||
using InboundTrafficQueue_t = std::deque<llarp::routing::TransferTrafficMessage>;
|
||||
using TieredQueue = std::map<uint8_t, InboundTrafficQueue_t>;
|
||||
using InboundTrafficQueue_t =
|
||||
std::deque< llarp::routing::TransferTrafficMessage >;
|
||||
using TieredQueue = std::map< uint8_t, InboundTrafficQueue_t >;
|
||||
// maps number of fragments the message will fit in to the queue for it
|
||||
TieredQueue m_DownstreamQueues;
|
||||
|
||||
struct UpstreamBuffer
|
||||
{
|
||||
UpstreamBuffer(const llarp::net::IPv4Packet & p, uint64_t c) : pkt(p), counter(c)
|
||||
UpstreamBuffer(const llarp::net::IPv4Packet& p, uint64_t c)
|
||||
: pkt(p), counter(c)
|
||||
{
|
||||
}
|
||||
|
||||
llarp::net::IPv4Packet pkt;
|
||||
uint64_t counter;
|
||||
|
||||
bool operator<(const UpstreamBuffer & other) const
|
||||
bool
|
||||
operator<(const UpstreamBuffer& other) const
|
||||
{
|
||||
return counter < other.counter;
|
||||
}
|
||||
};
|
||||
|
||||
using UpstreamQueue_t = std::priority_queue<UpstreamBuffer>;
|
||||
using UpstreamQueue_t = std::priority_queue< UpstreamBuffer >;
|
||||
UpstreamQueue_t m_UpstreamQueue;
|
||||
uint64_t m_Counter;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace llarp
|
|||
{
|
||||
namespace exit
|
||||
{
|
||||
|
||||
/// a persisiting exit session with an exit router
|
||||
struct BaseSession : public llarp::path::Builder
|
||||
{
|
||||
|
@ -38,16 +37,15 @@ namespace llarp
|
|||
bool
|
||||
FlushUpstreamTraffic();
|
||||
|
||||
bool
|
||||
bool
|
||||
IsReady() const;
|
||||
|
||||
|
||||
protected:
|
||||
llarp::RouterID m_ExitRouter;
|
||||
std::function< bool(llarp_buffer_t) > m_WritePacket;
|
||||
|
||||
virtual void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const = 0;
|
||||
|
||||
virtual void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const = 0;
|
||||
|
||||
bool
|
||||
HandleTrafficDrop(llarp::path::Path* p, const llarp::PathID_t& path,
|
||||
|
@ -59,9 +57,10 @@ namespace llarp
|
|||
bool
|
||||
HandleTraffic(llarp::path::Path* p, llarp_buffer_t buf);
|
||||
|
||||
private:
|
||||
using UpstreamTrafficQueue_t = std::deque<llarp::routing::TransferTrafficMessage>;
|
||||
using TieredQueue_t = std::map<uint8_t, UpstreamTrafficQueue_t>;
|
||||
private:
|
||||
using UpstreamTrafficQueue_t =
|
||||
std::deque< llarp::routing::TransferTrafficMessage >;
|
||||
using TieredQueue_t = std::map< uint8_t, UpstreamTrafficQueue_t >;
|
||||
TieredQueue_t m_Upstream;
|
||||
uint64_t m_Counter;
|
||||
llarp::SecretKey m_ExitIdentity;
|
||||
|
@ -70,14 +69,15 @@ namespace llarp
|
|||
struct ExitSession final : public BaseSession
|
||||
{
|
||||
ExitSession(const llarp::RouterID& snodeRouter,
|
||||
std::function< bool(llarp_buffer_t) > writepkt,
|
||||
llarp_router* r, size_t numpaths, size_t hoplen) : BaseSession(snodeRouter, writepkt, r,numpaths, hoplen) {};
|
||||
|
||||
~ExitSession() {};
|
||||
std::function< bool(llarp_buffer_t) > writepkt,
|
||||
llarp_router* r, size_t numpaths, size_t hoplen)
|
||||
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen){};
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const override
|
||||
~ExitSession(){};
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override
|
||||
{
|
||||
// TODO: set expiration time
|
||||
msg.X = 0;
|
||||
|
@ -88,14 +88,15 @@ namespace llarp
|
|||
struct SNodeSession final : public BaseSession
|
||||
{
|
||||
SNodeSession(const llarp::RouterID& snodeRouter,
|
||||
std::function< bool(llarp_buffer_t) > writepkt,
|
||||
llarp_router* r, size_t numpaths, size_t hoplen) : BaseSession(snodeRouter, writepkt, r,numpaths, hoplen) {};
|
||||
std::function< bool(llarp_buffer_t) > writepkt,
|
||||
llarp_router* r, size_t numpaths, size_t hoplen)
|
||||
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen){};
|
||||
|
||||
~SNodeSession() {};
|
||||
~SNodeSession(){};
|
||||
|
||||
protected:
|
||||
void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const override
|
||||
protected:
|
||||
void
|
||||
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const override
|
||||
{
|
||||
// TODO: set expiration time
|
||||
msg.X = 0;
|
||||
|
|
|
@ -2,30 +2,34 @@
|
|||
#define LLARP_HANDLERS_NULL_HPP
|
||||
#include <llarp/service/endpoint.hpp>
|
||||
|
||||
namespace llarp
|
||||
namespace llarp
|
||||
{
|
||||
namespace handlers
|
||||
namespace handlers
|
||||
{
|
||||
struct NullEndpoint final : public llarp::service::Endpoint
|
||||
{
|
||||
NullEndpoint(const std::string & name, llarp_router *r) : llarp::service::Endpoint(name, r) {};
|
||||
NullEndpoint(const std::string &name, llarp_router *r)
|
||||
: llarp::service::Endpoint(name, r){};
|
||||
|
||||
bool HandleWriteIPPacket(llarp_buffer_t, std::function<huint32_t(void)>) override
|
||||
bool HandleWriteIPPacket(llarp_buffer_t,
|
||||
std::function< huint32_t(void) >) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
huint32_t ObtainIPForAddr(const byte_t*, bool) override
|
||||
huint32_t
|
||||
ObtainIPForAddr(const byte_t *, bool) override
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
bool HasAddress(const byte_t *) const override
|
||||
|
||||
bool
|
||||
HasAddress(const byte_t *) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace handlers
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
|
@ -13,7 +13,6 @@ namespace llarp
|
|||
{
|
||||
namespace handlers
|
||||
{
|
||||
|
||||
static const int DefaultTunNetmask = 16;
|
||||
static const char DefaultTunIfname[] = "lokinet0";
|
||||
static const char DefaultTunDstAddr[] = "10.10.0.1";
|
||||
|
@ -39,7 +38,7 @@ namespace llarp
|
|||
bool
|
||||
Start();
|
||||
|
||||
bool
|
||||
bool
|
||||
IsSNode() const;
|
||||
|
||||
/// set up tun interface, blocking
|
||||
|
@ -53,7 +52,8 @@ namespace llarp
|
|||
/// overrides Endpoint
|
||||
/// handle inbound traffic
|
||||
bool
|
||||
HandleWriteIPPacket(llarp_buffer_t buf, std::function<huint32_t(void)> getFromIP) override;
|
||||
HandleWriteIPPacket(llarp_buffer_t buf,
|
||||
std::function< huint32_t(void) > getFromIP) override;
|
||||
|
||||
/// queue outbound packet to the world
|
||||
bool
|
||||
|
@ -77,7 +77,7 @@ namespace llarp
|
|||
#endif
|
||||
|
||||
llarp_tun_io tunif;
|
||||
std::unique_ptr<llarp_fd_promise> Promise;
|
||||
std::unique_ptr< llarp_fd_promise > Promise;
|
||||
|
||||
/// called before writing to tun interface
|
||||
static void
|
||||
|
@ -155,8 +155,10 @@ namespace llarp
|
|||
AlignedBuffer< 32 >::Hash >
|
||||
m_AddrToIP;
|
||||
|
||||
/// maps key to true if key is a service node, maps key to false if key is a hidden service
|
||||
std::unordered_map<AlignedBuffer<32>, bool, AlignedBuffer<32>::Hash> m_SNodes;
|
||||
/// maps key to true if key is a service node, maps key to false if key is
|
||||
/// a hidden service
|
||||
std::unordered_map< AlignedBuffer< 32 >, bool, AlignedBuffer< 32 >::Hash >
|
||||
m_SNodes;
|
||||
|
||||
private:
|
||||
bool
|
||||
|
@ -177,7 +179,7 @@ namespace llarp
|
|||
std::promise< bool > m_TunSetupResult;
|
||||
#endif
|
||||
|
||||
std::promise<int> m_VPNPromise;
|
||||
std::promise< int > m_VPNPromise;
|
||||
|
||||
/// DNS server per tun
|
||||
struct dnsd_context dnsd;
|
||||
|
|
|
@ -10,13 +10,14 @@ namespace llarp
|
|||
namespace routing
|
||||
{
|
||||
constexpr size_t ExitPadSize = 512 - 48;
|
||||
constexpr size_t MaxExitMTU = 1500;
|
||||
constexpr size_t MaxExitMTU = 1500;
|
||||
struct TransferTrafficMessage final : public IMessage
|
||||
{
|
||||
std::vector<llarp::Encrypted> X;
|
||||
std::vector< llarp::Encrypted > X;
|
||||
size_t _size = 0;
|
||||
|
||||
size_t Size() const
|
||||
size_t
|
||||
Size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
|
|
@ -254,9 +254,7 @@ namespace llarp
|
|||
constexpr uint32_t
|
||||
__netmask_ipv4_bits(uint32_t numset)
|
||||
{
|
||||
return (32 - numset)
|
||||
? (1 << numset) | __netmask_ipv4_bits(numset + 1)
|
||||
: 0;
|
||||
return (32 - numset) ? (1 << numset) | __netmask_ipv4_bits(numset + 1) : 0;
|
||||
}
|
||||
|
||||
/// get an ipv4 netmask given some /N range
|
||||
|
|
|
@ -190,8 +190,8 @@ namespace llarp
|
|||
return *i.first.data_l() ^ *i.second.data_l();
|
||||
}
|
||||
};
|
||||
using Mtx_t = llarp::util::Mutex;
|
||||
using Lock_t = llarp::util::Lock;
|
||||
using Mtx_t = llarp::util::Mutex;
|
||||
using Lock_t = llarp::util::Lock;
|
||||
using PathMap_t = std::unordered_map< PathInfo_t, Path*, PathInfoHash >;
|
||||
mutable Mtx_t m_PathsMutex;
|
||||
PathMap_t m_Paths;
|
||||
|
|
|
@ -13,10 +13,10 @@ namespace llarp
|
|||
private:
|
||||
llarp::PubKey enckey;
|
||||
llarp::PubKey signkey;
|
||||
|
||||
|
||||
public:
|
||||
VanityNonce vanity;
|
||||
|
||||
|
||||
ServiceInfo() = default;
|
||||
|
||||
ServiceInfo(ServiceInfo&& other)
|
||||
|
@ -58,7 +58,8 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
Update(const byte_t* enc, const byte_t* sign, const byte_t * nonce=nullptr)
|
||||
Update(const byte_t* enc, const byte_t* sign,
|
||||
const byte_t* nonce = nullptr)
|
||||
{
|
||||
enckey = enc;
|
||||
signkey = sign;
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace llarp
|
|||
getFirstEndpoint();
|
||||
|
||||
bool
|
||||
FindBestAddressFor(const byte_t* addr, bool isSNode, huint32_t &);
|
||||
FindBestAddressFor(const byte_t *addr, bool isSNode, huint32_t &);
|
||||
|
||||
/// DRY refactor
|
||||
llarp::handlers::TunEndpoint *
|
||||
|
|
|
@ -128,8 +128,9 @@ namespace llarp
|
|||
bool
|
||||
HandleDataMessage(const PathID_t&, ProtocolMessage* msg);
|
||||
|
||||
virtual
|
||||
bool HandleWriteIPPacket(llarp_buffer_t pkt, std::function<huint32_t(void)> getFromIP) = 0;
|
||||
virtual bool
|
||||
HandleWriteIPPacket(llarp_buffer_t pkt,
|
||||
std::function< huint32_t(void) > getFromIP) = 0;
|
||||
|
||||
bool
|
||||
ProcessDataMessage(ProtocolMessage* msg);
|
||||
|
@ -154,10 +155,11 @@ namespace llarp
|
|||
HandlePathBuilt(path::Path* path);
|
||||
|
||||
bool
|
||||
SendToServiceOrQueue(const byte_t* addr, llarp_buffer_t payload, ProtocolType t);
|
||||
SendToServiceOrQueue(const byte_t* addr, llarp_buffer_t payload,
|
||||
ProtocolType t);
|
||||
|
||||
bool
|
||||
SendToSNodeOrQueue(const byte_t * addr, llarp_buffer_t payload);
|
||||
SendToSNodeOrQueue(const byte_t* addr, llarp_buffer_t payload);
|
||||
|
||||
struct PendingBuffer
|
||||
{
|
||||
|
@ -329,14 +331,15 @@ namespace llarp
|
|||
EnsurePathToService(const Address& remote, PathEnsureHook h,
|
||||
uint64_t timeoutMS, bool lookupOnRandomPath = false);
|
||||
|
||||
using SNodeEnsureHook = std::function<void(RouterID, llarp::exit::BaseSession *)>;
|
||||
using SNodeEnsureHook =
|
||||
std::function< void(RouterID, llarp::exit::BaseSession*) >;
|
||||
|
||||
/// ensure a path to a service node by public key
|
||||
void
|
||||
EnsurePathToSNode(const RouterID & remote);
|
||||
EnsurePathToSNode(const RouterID& remote);
|
||||
|
||||
bool
|
||||
HasPathToSNode(const RouterID &remote) const;
|
||||
HasPathToSNode(const RouterID& remote) const;
|
||||
|
||||
void
|
||||
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info);
|
||||
|
@ -445,7 +448,10 @@ namespace llarp
|
|||
|
||||
Sessions m_DeadSessions;
|
||||
|
||||
using SNodeSessions = std::unordered_multimap<RouterID, std::unique_ptr<llarp::exit::BaseSession>, RouterID::Hash>;
|
||||
using SNodeSessions =
|
||||
std::unordered_multimap< RouterID,
|
||||
std::unique_ptr< llarp::exit::BaseSession >,
|
||||
RouterID::Hash >;
|
||||
|
||||
SNodeSessions m_SNodeSessions;
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ extern "C"
|
|||
/** set me on ios and android to block on a promise for the fd */
|
||||
int (*obtain_fd)(struct device *);
|
||||
/** user data */
|
||||
void * user;
|
||||
void *user;
|
||||
t_tun tun_fd;
|
||||
int ctrl_sock;
|
||||
int flags; /* ifr.ifr_flags on Unix */
|
||||
|
|
|
@ -326,8 +326,8 @@ interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
|
|||
for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize);
|
||||
l_rta = RTA_NEXT(l_rta, l_rtaSize))
|
||||
{
|
||||
void *l_rtaData = RTA_DATA(l_rta);
|
||||
(void) l_rtaData;
|
||||
void *l_rtaData = RTA_DATA(l_rta);
|
||||
(void)l_rtaData;
|
||||
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
|
||||
switch(l_rta->rta_type)
|
||||
{
|
||||
|
@ -454,8 +454,8 @@ interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
|
|||
for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize);
|
||||
l_rta = RTA_NEXT(l_rta, l_rtaSize))
|
||||
{
|
||||
void *l_rtaData = RTA_DATA(l_rta);
|
||||
(void) l_rtaData;
|
||||
void *l_rtaData = RTA_DATA(l_rta);
|
||||
(void)l_rtaData;
|
||||
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
|
||||
|
||||
switch(l_rta->rta_type)
|
||||
|
|
|
@ -182,7 +182,9 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
|
|||
|
||||
f << "# bootstrap settings" << std::endl;
|
||||
f << "[bootstrap]" << std::endl;
|
||||
f << "# add a bootstrap node's signed identity to the list of nodes we want to bootstrap from" << std::endl;
|
||||
f << "# add a bootstrap node's signed identity to the list of nodes we want "
|
||||
"to bootstrap from"
|
||||
<< std::endl;
|
||||
f << "# if we don't have any peers we connect to this router" << std::endl;
|
||||
f << "add-node=" << basepath << "bootstrap.signed" << std::endl;
|
||||
f << "# add another bootstrap node" << std::endl;
|
||||
|
@ -265,9 +267,12 @@ llarp_ensure_client_config(std::ofstream &f, std::string basepath)
|
|||
f << "# network settings " << std::endl;
|
||||
f << "[network]" << std::endl;
|
||||
f << "profiles=" << basepath << "profiles.dat" << std::endl;
|
||||
f << "# uncomment next line to add router with pubkey to list of routers we connect directly to" << std::endl;
|
||||
f << "# uncomment next line to add router with pubkey to list of routers we "
|
||||
"connect directly to"
|
||||
<< std::endl;
|
||||
f << "#strict-connect=pubkey" << std::endl;
|
||||
f << "# uncomment next line to use router with pubkey as an exit node" << std::endl;
|
||||
f << "# uncomment next line to use router with pubkey as an exit node"
|
||||
<< std::endl;
|
||||
f << "#exit-node=pubkey" << std::endl;
|
||||
// pick ip
|
||||
std::string ip = llarp::findFreePrivateRange();
|
||||
|
@ -355,9 +360,9 @@ extern "C"
|
|||
{
|
||||
iter->conf = conf;
|
||||
std::map< std::string, llarp::Config::section_t & > sections = {
|
||||
{"network", conf->impl.network}, {"connect", conf->impl.connect},
|
||||
{"network", conf->impl.network}, {"connect", conf->impl.connect},
|
||||
{"bootstrap", conf->impl.bootstrap}, {"system", conf->impl.system},
|
||||
{"netdb", conf->impl.netdb}, {"api", conf->impl.api},
|
||||
{"netdb", conf->impl.netdb}, {"api", conf->impl.api},
|
||||
{"services", conf->impl.services}};
|
||||
|
||||
for(const auto item : conf->impl.router)
|
||||
|
|
|
@ -162,20 +162,15 @@ namespace llarp
|
|||
int
|
||||
Context::Run()
|
||||
{
|
||||
// just check to make sure it's not already set up (either this or we add a
|
||||
// bool and/or add another function)
|
||||
if(!this->router)
|
||||
if(router == nullptr)
|
||||
{
|
||||
// set up all requirements
|
||||
if(this->Setup())
|
||||
{
|
||||
llarp::LogError("Failed to setup router");
|
||||
return 1;
|
||||
}
|
||||
// we are not set up so we should die
|
||||
llarp::LogError("cannot run non configured context");
|
||||
return 1;
|
||||
}
|
||||
// run
|
||||
if(!llarp_run_router(router, nodedb))
|
||||
return 1; // success
|
||||
return 1;
|
||||
// run net io thread
|
||||
llarp::LogInfo("running mainloop");
|
||||
llarp_ev_loop_run_single_process(mainloop, worker, logic);
|
||||
|
@ -208,6 +203,14 @@ namespace llarp
|
|||
void
|
||||
Context::Close()
|
||||
{
|
||||
llarp::LogDebug("stopping logic");
|
||||
if(logic)
|
||||
llarp_logic_stop(logic);
|
||||
|
||||
llarp::LogDebug("stopping event loop");
|
||||
if(mainloop)
|
||||
llarp_ev_loop_stop(mainloop);
|
||||
|
||||
llarp::LogDebug("stop router");
|
||||
if(router)
|
||||
llarp_stop_router(router);
|
||||
|
@ -220,11 +223,6 @@ namespace llarp
|
|||
if(worker)
|
||||
llarp_threadpool_join(worker);
|
||||
|
||||
llarp::LogDebug("stop logic");
|
||||
|
||||
if(logic)
|
||||
llarp_logic_stop(logic);
|
||||
|
||||
llarp::LogDebug("free config");
|
||||
llarp_free_config(&config);
|
||||
|
||||
|
@ -242,14 +240,6 @@ namespace llarp
|
|||
|
||||
llarp::LogDebug("free logic");
|
||||
llarp_free_logic(&logic);
|
||||
|
||||
for(auto &t : netio_threads)
|
||||
{
|
||||
llarp::LogDebug("join netio thread");
|
||||
t.join();
|
||||
}
|
||||
|
||||
netio_threads.clear();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -296,10 +286,11 @@ extern "C"
|
|||
ptr->ctx->HandleSignal(sig);
|
||||
}
|
||||
|
||||
void
|
||||
llarp_main_inject_vpn_fd(struct llarp_main * ptr, int fd)
|
||||
void
|
||||
llarp_main_inject_vpn_fd(struct llarp_main *ptr, int fd)
|
||||
{
|
||||
llarp::handlers::TunEndpoint * tun = ptr->ctx->router->hiddenServiceContext.getFirstTun();
|
||||
llarp::handlers::TunEndpoint *tun =
|
||||
ptr->ctx->router->hiddenServiceContext.getFirstTun();
|
||||
if(!tun)
|
||||
return;
|
||||
if(!tun->Promise)
|
||||
|
|
|
@ -78,7 +78,10 @@ namespace llarp
|
|||
for(const auto &pk : valuesFound)
|
||||
{
|
||||
// lookup router
|
||||
parent->LookupRouter(pk, std::bind(&llarp_router::HandleDHTLookupForExplore, parent->router, pk, std::placeholders::_1));
|
||||
parent->LookupRouter(
|
||||
pk,
|
||||
std::bind(&llarp_router::HandleDHTLookupForExplore,
|
||||
parent->router, pk, std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -238,7 +238,7 @@ packet2bytes(dns_packet &in)
|
|||
|
||||
int fields = (in.header.qr << 15); // QR => message type, 1 = response
|
||||
fields += (in.header.opcode << 14); // I think opcode is always 0
|
||||
fields += in.header.rcode; // response code (3 => not found, 0 = Ok)
|
||||
fields += in.header.rcode; // response code (3 => not found, 0 = Ok)
|
||||
vput16bits(write_buffer, fields);
|
||||
|
||||
// don't pull these from the header, trust what we actually have more
|
||||
|
@ -308,14 +308,14 @@ extern "C"
|
|||
}
|
||||
|
||||
bool
|
||||
decode_hdr(llarp_buffer_t * buffer, dns_msg_header * hdr)
|
||||
decode_hdr(llarp_buffer_t *buffer, dns_msg_header *hdr)
|
||||
{
|
||||
uint16_t fields;
|
||||
|
||||
// reads as HOST byte order
|
||||
if(!llarp_buffer_read_uint16(buffer, &hdr->id))
|
||||
return false;
|
||||
if(!llarp_buffer_read_uint16(buffer, &fields))
|
||||
if(!llarp_buffer_read_uint16(buffer, &fields))
|
||||
return false;
|
||||
if(!llarp_buffer_read_uint16(buffer, &hdr->qdCount))
|
||||
return false;
|
||||
|
|
|
@ -31,27 +31,30 @@ struct check_query_simple_request
|
|||
std::unordered_map< std::string, struct dnsd_query_hook_response * >
|
||||
loki_tld_lookup_cache;
|
||||
|
||||
static bool decode_request_name(const std::string & name, llarp::AlignedBuffer<32> & addr, bool &isSNode)
|
||||
static bool
|
||||
decode_request_name(const std::string &name, llarp::AlignedBuffer< 32 > &addr,
|
||||
bool &isSNode)
|
||||
{
|
||||
llarp::service::Address serviceAddr;
|
||||
llarp::RouterID snodeAddr;
|
||||
auto pos = name.find(".snode");
|
||||
if(pos != std::string::npos)
|
||||
{
|
||||
if(!llarp::HexDecode(name.substr(0, pos).c_str(), serviceAddr.data(), serviceAddr.size()))
|
||||
if(!llarp::HexDecode(name.substr(0, pos).c_str(), serviceAddr.data(),
|
||||
serviceAddr.size()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
addr = snodeAddr.data();
|
||||
addr = snodeAddr.data();
|
||||
isSNode = true;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if(!serviceAddr.FromString(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
addr = serviceAddr.data();
|
||||
addr = serviceAddr.data();
|
||||
isSNode = false;
|
||||
}
|
||||
return true;
|
||||
|
@ -80,7 +83,7 @@ llarp_dotlokilookup_checkQuery(void *u, __attribute__((unused)) uint64_t orig,
|
|||
// if so send that
|
||||
// else
|
||||
// if we have a free private ip, send that
|
||||
|
||||
|
||||
/*
|
||||
// cache hit
|
||||
auto itr = loki_tld_lookup_cache.find(addr.ToString());
|
||||
|
@ -109,7 +112,7 @@ llarp_dotlokilookup_checkQuery(void *u, __attribute__((unused)) uint64_t orig,
|
|||
return;
|
||||
}
|
||||
llarp::huint32_t serviceIP;
|
||||
llarp::AlignedBuffer<32> addr;
|
||||
llarp::AlignedBuffer< 32 > addr;
|
||||
bool isSNode = false;
|
||||
if(!decode_request_name(qr->request->question.name, addr, isSNode))
|
||||
{
|
||||
|
@ -125,7 +128,6 @@ llarp_dotlokilookup_checkQuery(void *u, __attribute__((unused)) uint64_t orig,
|
|||
delete qr;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
bool mapResult = routerHiddenServiceContext->MapAddressAll(
|
||||
|
@ -260,7 +262,7 @@ ReverseHandlerIter(struct llarp::service::Context::endpoint_iter *endpointCfg)
|
|||
llarp::iprange_ipv4(std::stoi(tokensCheck[0]), std::stoi(tokensCheck[1]),
|
||||
std::stoi(tokensCheck[2]), std::stoi(tokensCheck[3]),
|
||||
tunEndpoint->tunif.netmask); // create range
|
||||
|
||||
|
||||
llarp::huint32_t searchIPv4 = llarp::ipaddr_ipv4_bits(
|
||||
std::stoi(tokensSearch[searchTokens - 3]),
|
||||
std::stoi(tokensSearch[searchTokens - 4]),
|
||||
|
@ -273,26 +275,25 @@ ReverseHandlerIter(struct llarp::service::Context::endpoint_iter *endpointCfg)
|
|||
llarp::Addr searchAddr(searchIp);
|
||||
llarp::Addr checkAddr(checkIp);
|
||||
llarp::LogInfo(searchIPv4, " vs ", range, " = ",
|
||||
inRange ? "inRange" : "not match");
|
||||
inRange ? "inRange" : "not match");
|
||||
|
||||
if(inRange)
|
||||
{
|
||||
llarp::AlignedBuffer<32> addr =
|
||||
tunEndpoint->ObtainAddrForIP< llarp::AlignedBuffer<32> >(
|
||||
searchIPv4, false);
|
||||
llarp::AlignedBuffer< 32 > addr =
|
||||
tunEndpoint->ObtainAddrForIP< llarp::AlignedBuffer< 32 > >(searchIPv4,
|
||||
false);
|
||||
if(addr.IsZero())
|
||||
{
|
||||
addr =
|
||||
tunEndpoint->ObtainAddrForIP< llarp::AlignedBuffer<32> >(
|
||||
searchIPv4, true);
|
||||
addr = tunEndpoint->ObtainAddrForIP< llarp::AlignedBuffer< 32 > >(
|
||||
searchIPv4, true);
|
||||
if(!addr.IsZero())
|
||||
{
|
||||
char stack[128] = {0};
|
||||
char stack[128] = {0};
|
||||
std::string saddr = llarp::HexEncode(addr, stack);
|
||||
saddr += ".snode";
|
||||
writesend_dnss_revresponse(saddr, context->request);
|
||||
}
|
||||
else
|
||||
else
|
||||
write404_dnss_response(context->request);
|
||||
}
|
||||
else
|
||||
|
@ -306,11 +307,13 @@ ReverseHandlerIter(struct llarp::service::Context::endpoint_iter *endpointCfg)
|
|||
return true; // we don't do anything with the result yet
|
||||
}
|
||||
|
||||
static bool should_intercept_query_with_name(const std::string & lName)
|
||||
static bool
|
||||
should_intercept_query_with_name(const std::string &lName)
|
||||
{
|
||||
// null terminated list
|
||||
static const char * const matches[] = { ".loki", ".snode", ".loki.", ".snode.", 0};
|
||||
size_t idx = 0;
|
||||
static const char *const matches[] = {".loki", ".snode", ".loki.", ".snode.",
|
||||
0};
|
||||
size_t idx = 0;
|
||||
while(matches[idx])
|
||||
{
|
||||
std::string match_str(matches[idx]);
|
||||
|
@ -323,7 +326,7 @@ static bool should_intercept_query_with_name(const std::string & lName)
|
|||
|
||||
dnsd_query_hook_response *
|
||||
llarp_dotlokilookup_handler(std::string name,
|
||||
const dnsd_question_request * request)
|
||||
const dnsd_question_request *request)
|
||||
{
|
||||
dnsd_query_hook_response *response = new dnsd_query_hook_response;
|
||||
response->dontLookUp = false;
|
||||
|
@ -362,7 +365,7 @@ llarp_dotlokilookup_handler(std::string name,
|
|||
if(!res)
|
||||
{
|
||||
llarp::LogDebug("Reverse is ours");
|
||||
response->dontLookUp = true;
|
||||
response->dontLookUp = true;
|
||||
response->dontSendResponse = true; // should have already sent it
|
||||
}
|
||||
else
|
||||
|
@ -384,11 +387,11 @@ llarp_dotlokilookup_handler(std::string name,
|
|||
}
|
||||
|
||||
// decode address
|
||||
llarp::AlignedBuffer<32> addr;
|
||||
llarp::AlignedBuffer< 32 > addr;
|
||||
bool isSNode = false;
|
||||
if(!decode_request_name(lName, addr, isSNode))
|
||||
{
|
||||
response->dontLookUp = true;
|
||||
response->dontLookUp = true;
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -647,8 +647,8 @@ raw_resolve_host(struct dnsc_context *const dnsc, const char *url,
|
|||
if(request)
|
||||
{
|
||||
request->packet.header = hdr;
|
||||
generic_handle_dnsc_recvfrom(tracker->client_request[hdr.id].get(),
|
||||
lbuffer, &hdr);
|
||||
generic_handle_dnsc_recvfrom(tracker->client_request[hdr.id].get(), lbuffer,
|
||||
&hdr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -672,7 +672,7 @@ llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
|
|||
llarp::LogError("failed to decode dns header");
|
||||
return;
|
||||
}
|
||||
buf.cur = buf.base; // reset cursor to beginning
|
||||
buf.cur = buf.base; // reset cursor to beginning
|
||||
|
||||
llarp::LogDebug("Header got client responses for id: ", hdr.id);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ write404_dnss_response(const dnsd_question_request *request)
|
|||
// build header
|
||||
put16bits(write_buffer, request->hdr.id);
|
||||
// not found flag set
|
||||
put16bits(write_buffer, (1 << 15) | request->hdr.fields() | 3);
|
||||
put16bits(write_buffer, (1 << 15) | request->hdr.fields() | 3);
|
||||
|
||||
put16bits(write_buffer, 1); // QD (number of questions)
|
||||
put16bits(write_buffer, 0); // AN (number of answers)
|
||||
|
@ -63,11 +63,13 @@ write404_dnss_response(const dnsd_question_request *request)
|
|||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending 404, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, request->from, llarp::InitBuffer(buf, out_bytes));
|
||||
request->sendto_hook(request->user, request->from,
|
||||
llarp::InitBuffer(buf, out_bytes));
|
||||
}
|
||||
|
||||
void
|
||||
writecname_dnss_response(std::string cname, const dnsd_question_request *request)
|
||||
writecname_dnss_response(std::string cname,
|
||||
const dnsd_question_request *request)
|
||||
{
|
||||
char buf[BUFFER_SIZE] = {0};
|
||||
|
||||
|
@ -127,11 +129,13 @@ writecname_dnss_response(std::string cname, const dnsd_question_request *request
|
|||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending cname, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, request->from, llarp::InitBuffer(buf, out_bytes));
|
||||
request->sendto_hook(request->user, request->from,
|
||||
llarp::InitBuffer(buf, out_bytes));
|
||||
}
|
||||
|
||||
void
|
||||
writesend_dnss_revresponse(std::string reverse, const dnsd_question_request *request)
|
||||
writesend_dnss_revresponse(std::string reverse,
|
||||
const dnsd_question_request *request)
|
||||
{
|
||||
char buf[BUFFER_SIZE] = {0};
|
||||
|
||||
|
@ -140,7 +144,7 @@ writesend_dnss_revresponse(std::string reverse, const dnsd_question_request *req
|
|||
// build header
|
||||
put16bits(write_buffer, request->hdr.id);
|
||||
// response
|
||||
put16bits(write_buffer,request->hdr.fields() | (1 << 15) | (1 << 10));
|
||||
put16bits(write_buffer, request->hdr.fields() | (1 << 15) | (1 << 10));
|
||||
|
||||
put16bits(write_buffer, 1); // QD (number of questions)
|
||||
put16bits(write_buffer, 1); // AN (number of answers)
|
||||
|
@ -156,14 +160,15 @@ writesend_dnss_revresponse(std::string reverse, const dnsd_question_request *req
|
|||
code_domain(write_buffer, request->question.name); // com, type=6, ttl=0
|
||||
put16bits(write_buffer, request->question.type);
|
||||
put16bits(write_buffer, request->question.qClass);
|
||||
put32bits(write_buffer, 1); // ttl
|
||||
put32bits(write_buffer, 1); // ttl
|
||||
put16bits(write_buffer, reverse.size() + 2); // rdLength
|
||||
code_domain(write_buffer, reverse);
|
||||
|
||||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending reverse: ", reverse, " ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, request->from, llarp::InitBuffer(buf, out_bytes));
|
||||
request->sendto_hook(request->user, request->from,
|
||||
llarp::InitBuffer(buf, out_bytes));
|
||||
}
|
||||
|
||||
// FIXME: we need an DNS answer not a sockaddr
|
||||
|
@ -228,7 +233,8 @@ writesend_dnss_response(llarp::huint32_t *hostRes,
|
|||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, request->from, llarp::InitBuffer(buf, out_bytes));
|
||||
request->sendto_hook(request->user, request->from,
|
||||
llarp::InitBuffer(buf, out_bytes));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -323,7 +329,7 @@ handle_dnsc_result(dnsc_answer_request *client_request)
|
|||
}
|
||||
|
||||
client_request->packet.header.id = server_request->hdr.id; // stomp ID
|
||||
std::vector< byte_t > test = packet2bytes(client_request->packet);
|
||||
std::vector< byte_t > test = packet2bytes(client_request->packet);
|
||||
// llarp::LogInfo("packet2bytes figures we should send ", test.size(), "
|
||||
// bytes");
|
||||
|
||||
|
@ -371,7 +377,7 @@ handle_dnsc_result(dnsc_answer_request *client_request)
|
|||
|
||||
// our generic version
|
||||
void
|
||||
handle_recvfrom(llarp_buffer_t * buffer, dnsd_question_request *request)
|
||||
handle_recvfrom(llarp_buffer_t *buffer, dnsd_question_request *request)
|
||||
{
|
||||
const size_t HDR_OFFSET = 12;
|
||||
const char *p_buffer = (const char *)buffer->base;
|
||||
|
@ -379,7 +385,6 @@ handle_recvfrom(llarp_buffer_t * buffer, dnsd_question_request *request)
|
|||
int rcode = (buffer->base[3] & 0x0F);
|
||||
llarp::LogDebug("dnsd rcode ", rcode);
|
||||
|
||||
|
||||
if(!decode_hdr(buffer, &request->hdr))
|
||||
{
|
||||
llarp::LogError("failed to decode dns header");
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace llarp
|
|||
UpdateBuffer();
|
||||
}
|
||||
|
||||
Encrypted::Encrypted(Encrypted && other)
|
||||
Encrypted::Encrypted(Encrypted&& other)
|
||||
{
|
||||
_data = std::move(other._data);
|
||||
UpdateBuffer();
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#error No async event loop for your platform, subclass llarp_ev_loop
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
llarp_ev_loop_alloc(struct llarp_ev_loop **ev)
|
||||
{
|
||||
|
@ -58,7 +57,8 @@ llarp_ev_loop_run(struct llarp_ev_loop *ev, struct llarp_logic *logic)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int llarp_fd_promise_wait_for_value(struct llarp_fd_promise * p)
|
||||
int
|
||||
llarp_fd_promise_wait_for_value(struct llarp_fd_promise *p)
|
||||
{
|
||||
return p->Get();
|
||||
}
|
||||
|
|
14
llarp/ev.hpp
14
llarp/ev.hpp
|
@ -612,15 +612,19 @@ namespace llarp
|
|||
|
||||
struct llarp_fd_promise
|
||||
{
|
||||
llarp_fd_promise(std::promise<int> * p) : _impl(p) {}
|
||||
std::promise<int> * _impl;
|
||||
|
||||
void Set(int fd)
|
||||
llarp_fd_promise(std::promise< int >* p) : _impl(p)
|
||||
{
|
||||
}
|
||||
std::promise< int >* _impl;
|
||||
|
||||
void
|
||||
Set(int fd)
|
||||
{
|
||||
_impl->set_value(fd);
|
||||
}
|
||||
|
||||
int Get()
|
||||
int
|
||||
Get()
|
||||
{
|
||||
auto future = _impl->get_future();
|
||||
future.wait();
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace llarp
|
|||
{
|
||||
llarp_buffer_t b;
|
||||
b.base = buf;
|
||||
b.cur = b.base;
|
||||
b.cur = b.base;
|
||||
sockaddr_in6 src;
|
||||
socklen_t slen = sizeof(sockaddr_in6);
|
||||
sockaddr* addr = (sockaddr*)&src;
|
||||
|
@ -217,7 +217,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
int
|
||||
read(byte_t * buf, size_t sz)
|
||||
read(byte_t* buf, size_t sz)
|
||||
{
|
||||
ssize_t ret = tuntap_read(tunif, buf, sz);
|
||||
if(ret > 0 && t->recvpkt)
|
||||
|
@ -228,12 +228,13 @@ namespace llarp
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int wait_for_fd_promise(struct device * dev)
|
||||
static int
|
||||
wait_for_fd_promise(struct device* dev)
|
||||
{
|
||||
llarp::tun *t = static_cast<llarp::tun *>(dev->user);
|
||||
llarp::tun* t = static_cast< llarp::tun* >(dev->user);
|
||||
if(t->t->get_fd_promise)
|
||||
{
|
||||
struct llarp_fd_promise * promise = t->t->get_fd_promise(t->t);
|
||||
struct llarp_fd_promise* promise = t->t->get_fd_promise(t->t);
|
||||
if(promise)
|
||||
return llarp_fd_promise_wait_for_value(promise);
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ namespace llarp
|
|||
if(t->get_fd_promise)
|
||||
{
|
||||
tunif->obtain_fd = &wait_for_fd_promise;
|
||||
tunif->user = this;
|
||||
tunif->user = this;
|
||||
}
|
||||
llarp::LogDebug("set ifname to ", t->ifname);
|
||||
strncpy(tunif->if_name, t->ifname, sizeof(tunif->if_name));
|
||||
|
@ -513,8 +514,8 @@ struct llarp_epoll_loop : public llarp_ev_loop
|
|||
llarp::tun* t = new llarp::tun(tun, this);
|
||||
if(tun->get_fd_promise)
|
||||
{
|
||||
|
||||
} else if(t->setup())
|
||||
}
|
||||
else if(t->setup())
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
@ -577,6 +578,14 @@ struct llarp_epoll_loop : public llarp_ev_loop
|
|||
void
|
||||
stop()
|
||||
{
|
||||
// close all handlers before closing the epoll fd
|
||||
auto itr = handlers.begin();
|
||||
while(itr != handler.end())
|
||||
{
|
||||
close_ev(itr->get());
|
||||
itr = handlers.erase(itr);
|
||||
}
|
||||
|
||||
if(epollfd != -1)
|
||||
close(epollfd);
|
||||
epollfd = -1;
|
||||
|
|
|
@ -67,11 +67,12 @@ namespace llarp
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Endpoint::LooksDead(llarp_time_t now, llarp_time_t timeout) const
|
||||
bool
|
||||
Endpoint::LooksDead(llarp_time_t now, llarp_time_t timeout) const
|
||||
{
|
||||
if(ExpiresSoon(now, timeout))
|
||||
return true;
|
||||
if (now > m_LastActive)
|
||||
if(now > m_LastActive)
|
||||
return now - m_LastActive > timeout;
|
||||
return true;
|
||||
}
|
||||
|
@ -82,11 +83,11 @@ namespace llarp
|
|||
// queue overflow
|
||||
if(m_UpstreamQueue.size() > MaxUpstreamQueueSize)
|
||||
return false;
|
||||
|
||||
|
||||
llarp::net::IPv4Packet pkt;
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
|
||||
|
||||
huint32_t dst;
|
||||
if(m_RewriteSource)
|
||||
dst = m_Parent->GetIfAddr();
|
||||
|
@ -103,8 +104,8 @@ namespace llarp
|
|||
Endpoint::QueueInboundTraffic(llarp_buffer_t buf)
|
||||
{
|
||||
llarp::net::IPv4Packet pkt;
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
|
||||
huint32_t src;
|
||||
if(m_RewriteSource)
|
||||
|
@ -112,15 +113,15 @@ namespace llarp
|
|||
else
|
||||
src = pkt.src();
|
||||
pkt.UpdateIPv4PacketOnDst(src, m_IP);
|
||||
auto pktbuf = pkt.Buffer();
|
||||
auto pktbuf = pkt.Buffer();
|
||||
uint8_t queue_idx = pktbuf.sz / llarp::routing::ExitPadSize;
|
||||
auto & queue = m_DownstreamQueues[queue_idx];
|
||||
auto& queue = m_DownstreamQueues[queue_idx];
|
||||
if(queue.size() == 0)
|
||||
{
|
||||
queue.emplace_back();
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
auto & msg = queue.back();
|
||||
auto& msg = queue.back();
|
||||
if(msg.Size() + pktbuf.sz > llarp::routing::ExitPadSize)
|
||||
{
|
||||
queue.emplace_back();
|
||||
|
@ -130,7 +131,7 @@ namespace llarp
|
|||
return msg.PutBuffer(pktbuf, m_Counter++);
|
||||
}
|
||||
|
||||
bool
|
||||
bool
|
||||
Endpoint::Flush()
|
||||
{
|
||||
// flush upstream queue
|
||||
|
@ -144,13 +145,13 @@ namespace llarp
|
|||
bool sent = path != nullptr;
|
||||
if(path)
|
||||
{
|
||||
for(auto & item : m_DownstreamQueues)
|
||||
for(auto& item : m_DownstreamQueues)
|
||||
{
|
||||
auto & queue = item.second;
|
||||
auto& queue = item.second;
|
||||
while(queue.size())
|
||||
{
|
||||
auto & msg = queue.front();
|
||||
msg.S = path->NextSeqNo();
|
||||
auto& msg = queue.front();
|
||||
msg.S = path->NextSeqNo();
|
||||
if(path->SendRoutingMessage(&msg, m_Parent->Router()))
|
||||
{
|
||||
m_RxRate += msg.Size();
|
||||
|
@ -160,7 +161,7 @@ namespace llarp
|
|||
}
|
||||
}
|
||||
}
|
||||
for(auto & item : m_DownstreamQueues)
|
||||
for(auto& item : m_DownstreamQueues)
|
||||
item.second.clear();
|
||||
return sent;
|
||||
}
|
||||
|
|
|
@ -99,10 +99,11 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
BaseSession::QueueUpstreamTraffic(llarp::net::IPv4Packet pkt, const size_t N)
|
||||
BaseSession::QueueUpstreamTraffic(llarp::net::IPv4Packet pkt,
|
||||
const size_t N)
|
||||
{
|
||||
auto buf = pkt.Buffer();
|
||||
auto & queue = m_Upstream[buf.sz / N];
|
||||
auto buf = pkt.Buffer();
|
||||
auto& queue = m_Upstream[buf.sz / N];
|
||||
// queue overflow
|
||||
if(queue.size() >= MaxUpstreamQueueLength)
|
||||
return false;
|
||||
|
@ -111,41 +112,41 @@ namespace llarp
|
|||
queue.emplace_back();
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
auto & back = queue.back();
|
||||
auto& back = queue.back();
|
||||
// pack to nearest N
|
||||
if(back.Size() + buf.sz > N)
|
||||
{
|
||||
queue.emplace_back();
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
queue.emplace_back();
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
else
|
||||
return back.PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
|
||||
bool
|
||||
BaseSession::IsReady() const
|
||||
BaseSession::IsReady() const
|
||||
{
|
||||
return AvailablePaths(llarp::path::ePathRoleExit) > 0;
|
||||
}
|
||||
|
||||
bool
|
||||
bool
|
||||
BaseSession::FlushUpstreamTraffic()
|
||||
{
|
||||
auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit);
|
||||
if(!path)
|
||||
{
|
||||
// discard
|
||||
for(auto & item : m_Upstream)
|
||||
for(auto& item : m_Upstream)
|
||||
item.second.clear();
|
||||
return false;
|
||||
}
|
||||
for (auto & item : m_Upstream)
|
||||
for(auto& item : m_Upstream)
|
||||
{
|
||||
auto & queue = item.second;
|
||||
auto& queue = item.second;
|
||||
while(queue.size())
|
||||
{
|
||||
auto & msg = queue.front();
|
||||
msg.S = path->NextSeqNo();
|
||||
auto& msg = queue.front();
|
||||
msg.S = path->NextSeqNo();
|
||||
path->SendRoutingMessage(&msg, router);
|
||||
queue.pop_front();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace llarp
|
|||
if(buf.sz > MaxExitMTU)
|
||||
return false;
|
||||
X.emplace_back(buf.sz + 8);
|
||||
byte_t * ptr = X.back().data();
|
||||
byte_t* ptr = X.back().data();
|
||||
htobe64buf(ptr, counter);
|
||||
ptr += 8;
|
||||
memcpy(ptr, buf.base, buf.sz);
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace llarp
|
|||
{
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
llarp_time_t
|
||||
ExitEndpoint::Now() const
|
||||
{
|
||||
return m_Router->Now();
|
||||
|
@ -73,17 +73,19 @@ namespace llarp
|
|||
}
|
||||
++itr;
|
||||
}
|
||||
|
||||
|
||||
if(ep == nullptr)
|
||||
{
|
||||
// we may have all dead sessions, wtf now?
|
||||
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk, " as we have no working endpoints");
|
||||
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk,
|
||||
" as we have no working endpoints");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!ep->QueueInboundTraffic(pkt.Buffer()))
|
||||
{
|
||||
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk, " as we are overloaded (probably)");
|
||||
llarp::LogWarn(Name(), " dropped inbound traffic for session ", pk,
|
||||
" as we are overloaded (probably)");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace llarp
|
|||
{
|
||||
namespace handlers
|
||||
{
|
||||
|
||||
static llarp_fd_promise * get_tun_fd_promise(llarp_tun_io * tun)
|
||||
static llarp_fd_promise *
|
||||
get_tun_fd_promise(llarp_tun_io *tun)
|
||||
{
|
||||
return static_cast<TunEndpoint *>(tun->user)->Promise.get();
|
||||
return static_cast< TunEndpoint * >(tun->user)->Promise.get();
|
||||
}
|
||||
|
||||
TunEndpoint::TunEndpoint(const std::string &nickname, llarp_router *r)
|
||||
|
@ -25,10 +25,10 @@ namespace llarp
|
|||
, m_UserToNetworkPktQueue(nickname + "_sendq", r->netloop, r->netloop)
|
||||
, m_NetworkToUserPktQueue(nickname + "_recvq", r->netloop, r->netloop)
|
||||
{
|
||||
#ifdef ANDROID
|
||||
#ifdef ANDROID
|
||||
tunif.get_fd_promise = &get_tun_fd_promise;
|
||||
Promise.reset(new llarp_fd_promise(&m_VPNPromise));
|
||||
#else
|
||||
#else
|
||||
tunif.get_fd_promise = nullptr;
|
||||
#endif
|
||||
tunif.user = this;
|
||||
|
@ -180,7 +180,8 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
TunEndpoint::MapAddress(const service::Address &addr, huint32_t ip, bool SNode)
|
||||
TunEndpoint::MapAddress(const service::Address &addr, huint32_t ip,
|
||||
bool SNode)
|
||||
{
|
||||
auto itr = m_IPToAddr.find(ip);
|
||||
if(itr != m_IPToAddr.end())
|
||||
|
@ -192,9 +193,9 @@ namespace llarp
|
|||
}
|
||||
llarp::LogInfo(Name() + " map ", addr.ToString(), " to ", ip);
|
||||
|
||||
m_IPToAddr[ip] = addr.data();
|
||||
m_IPToAddr[ip] = addr.data();
|
||||
m_AddrToIP[addr.data()] = ip;
|
||||
m_SNodes[addr.data()] = SNode;
|
||||
m_SNodes[addr.data()] = SNode;
|
||||
MarkIPActiveForever(ip);
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +243,8 @@ namespace llarp
|
|||
#endif
|
||||
}
|
||||
|
||||
bool TunEndpoint::IsSNode() const
|
||||
bool
|
||||
TunEndpoint::IsSNode() const
|
||||
{
|
||||
// TODO : implement me
|
||||
return false;
|
||||
|
@ -365,30 +367,34 @@ namespace llarp
|
|||
TunEndpoint::FlushSend()
|
||||
{
|
||||
m_UserToNetworkPktQueue.Process([&](net::IPv4Packet &pkt) {
|
||||
std::function<bool(llarp_buffer_t)> sendFunc;
|
||||
std::function< bool(llarp_buffer_t) > sendFunc;
|
||||
auto itr = m_IPToAddr.find(pkt.dst());
|
||||
if(itr == m_IPToAddr.end())
|
||||
{
|
||||
if(m_Exit)
|
||||
{
|
||||
pkt.UpdateIPv4PacketOnDst({0}, pkt.dst());
|
||||
m_Exit->QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize);
|
||||
m_Exit->QueueUpstreamTraffic(std::move(pkt),
|
||||
llarp::routing::ExitPadSize);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogWarn(Name(), " has no endpoint for ", pkt.dst());
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_SNodes.at(itr->second))
|
||||
{
|
||||
sendFunc = std::bind(&TunEndpoint::SendToSNodeOrQueue, this, itr->second.data(), std::placeholders::_1);
|
||||
sendFunc = std::bind(&TunEndpoint::SendToSNodeOrQueue, this,
|
||||
itr->second.data(), std::placeholders::_1);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
sendFunc = std::bind(&TunEndpoint::SendToServiceOrQueue, this, itr->second.data(), std::placeholders::_1, service::eProtocolTraffic);
|
||||
sendFunc = std::bind(&TunEndpoint::SendToServiceOrQueue, this,
|
||||
itr->second.data(), std::placeholders::_1,
|
||||
service::eProtocolTraffic);
|
||||
}
|
||||
// prepare packet for insertion into network
|
||||
// this includes clearing IP addresses, recalculating checksums, etc
|
||||
|
@ -404,35 +410,36 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
TunEndpoint::HandleWriteIPPacket(llarp_buffer_t buf, std::function<huint32_t(void)> getFromIP)
|
||||
TunEndpoint::HandleWriteIPPacket(llarp_buffer_t buf,
|
||||
std::function< huint32_t(void) > getFromIP)
|
||||
{
|
||||
// llarp::LogInfo("got packet from ", msg->sender.Addr());
|
||||
auto themIP = getFromIP();
|
||||
// llarp::LogInfo("themIP ", themIP);
|
||||
auto usIP = m_OurIP;
|
||||
return m_NetworkToUserPktQueue.EmplaceIf(
|
||||
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
|
||||
// load
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
// filter out:
|
||||
// - packets smaller than minimal IPv4 header
|
||||
// - non-IPv4 packets
|
||||
// - packets with weird src/dst addresses
|
||||
// (0.0.0.0/8 but not 0.0.0.0)
|
||||
// - packets with 0 src but non-0 dst and oposite
|
||||
auto hdr = pkt.Header();
|
||||
if(pkt.sz < sizeof(*hdr) || hdr->version != 4
|
||||
|| (hdr->saddr != 0 && *(byte_t *)&(hdr->saddr) == 0)
|
||||
|| (hdr->daddr != 0 && *(byte_t *)&(hdr->daddr) == 0)
|
||||
|| ((hdr->saddr == 0) != (hdr->daddr == 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// update packet to use proper addresses, recalc checksums
|
||||
pkt.UpdateIPv4PacketOnDst(themIP, usIP);
|
||||
return true;
|
||||
});
|
||||
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
|
||||
// load
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
// filter out:
|
||||
// - packets smaller than minimal IPv4 header
|
||||
// - non-IPv4 packets
|
||||
// - packets with weird src/dst addresses
|
||||
// (0.0.0.0/8 but not 0.0.0.0)
|
||||
// - packets with 0 src but non-0 dst and oposite
|
||||
auto hdr = pkt.Header();
|
||||
if(pkt.sz < sizeof(*hdr) || hdr->version != 4
|
||||
|| (hdr->saddr != 0 && *(byte_t *)&(hdr->saddr) == 0)
|
||||
|| (hdr->daddr != 0 && *(byte_t *)&(hdr->daddr) == 0)
|
||||
|| ((hdr->saddr == 0) != (hdr->daddr == 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// update packet to use proper addresses, recalc checksums
|
||||
pkt.UpdateIPv4PacketOnDst(themIP, usIP);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
huint32_t
|
||||
|
@ -469,7 +476,7 @@ namespace llarp
|
|||
{
|
||||
m_AddrToIP[ident] = nextIP;
|
||||
m_IPToAddr[nextIP] = ident;
|
||||
m_SNodes[ident] = snode;
|
||||
m_SNodes[ident] = snode;
|
||||
llarp::LogInfo(Name(), " mapped ", ident, " to ", nextIP);
|
||||
MarkIPActive(nextIP);
|
||||
return nextIP;
|
||||
|
@ -498,7 +505,7 @@ namespace llarp
|
|||
// remap address
|
||||
m_IPToAddr[oldest.first] = ident;
|
||||
m_AddrToIP[ident] = oldest.first;
|
||||
m_SNodes[ident] = snode;
|
||||
m_SNodes[ident] = snode;
|
||||
nextIP = oldest.first;
|
||||
|
||||
// mark ip active
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
llarp_buffer_t
|
||||
IPv4Packet::ConstBuffer() const
|
||||
IPv4Packet::ConstBuffer() const
|
||||
{
|
||||
return llarp::InitBuffer(buf, sz);
|
||||
}
|
||||
|
|
|
@ -801,12 +801,13 @@ namespace llarp
|
|||
if(!m_ExitTrafficHandler)
|
||||
return false;
|
||||
bool sent = msg->X.size() > 0;
|
||||
for(const auto & pkt : msg->X)
|
||||
for(const auto& pkt : msg->X)
|
||||
{
|
||||
if(pkt.size() <= 8)
|
||||
return false;
|
||||
uint64_t counter = bufbe64toh(pkt.data());
|
||||
m_ExitTrafficHandler(this, llarp::InitBuffer(pkt.data() +8, pkt.size()-8), counter);
|
||||
m_ExitTrafficHandler(
|
||||
this, llarp::InitBuffer(pkt.data() + 8, pkt.size() - 8), counter);
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
|
|
@ -180,7 +180,8 @@ namespace llarp
|
|||
{
|
||||
(void)roles;
|
||||
if(hop == 0)
|
||||
return router->NumberOfConnectedRouters() && router->GetRandomConnectedRouter(cur);
|
||||
return router->NumberOfConnectedRouters()
|
||||
&& router->GetRandomConnectedRouter(cur);
|
||||
|
||||
size_t tries = 5;
|
||||
do
|
||||
|
|
|
@ -242,7 +242,7 @@ namespace llarp
|
|||
intros.clear();
|
||||
size_t count = 0;
|
||||
Lock_t l(m_PathsMutex);
|
||||
auto itr = m_Paths.begin();
|
||||
auto itr = m_Paths.begin();
|
||||
while(itr != m_Paths.end())
|
||||
{
|
||||
if(itr->second->IsReady() && filter(itr->second->intro))
|
||||
|
@ -262,7 +262,7 @@ namespace llarp
|
|||
intros.clear();
|
||||
size_t count = 0;
|
||||
Lock_t l(m_PathsMutex);
|
||||
auto itr = m_Paths.begin();
|
||||
auto itr = m_Paths.begin();
|
||||
while(itr != m_Paths.end())
|
||||
{
|
||||
if(itr->second->IsReady())
|
||||
|
@ -287,7 +287,7 @@ namespace llarp
|
|||
intro.Clear();
|
||||
bool found = false;
|
||||
Lock_t l(m_PathsMutex);
|
||||
auto itr = m_Paths.begin();
|
||||
auto itr = m_Paths.begin();
|
||||
while(itr != m_Paths.end())
|
||||
{
|
||||
if(itr->second->IsReady()
|
||||
|
|
|
@ -427,8 +427,8 @@ llarp_router::handle_router_ticker(void *user, uint64_t orig, uint64_t left)
|
|||
self->ScheduleTicker(orig);
|
||||
}
|
||||
|
||||
bool
|
||||
llarp_router::ConnectionToRouterAllowed(const llarp::RouterID & router) const
|
||||
bool
|
||||
llarp_router::ConnectionToRouterAllowed(const llarp::RouterID &router) const
|
||||
{
|
||||
if(strictConnectPubkeys.size() && strictConnectPubkeys.count(router) == 0)
|
||||
return false;
|
||||
|
@ -438,12 +438,13 @@ llarp_router::ConnectionToRouterAllowed(const llarp::RouterID & router) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
llarp_router::HandleDHTLookupForExplore(llarp::RouterID remote, const std::vector< llarp::RouterContact > &results)
|
||||
void
|
||||
llarp_router::HandleDHTLookupForExplore(
|
||||
llarp::RouterID remote, const std::vector< llarp::RouterContact > &results)
|
||||
{
|
||||
if(results.size() == 0)
|
||||
return;
|
||||
for(const auto & rc: results)
|
||||
for(const auto &rc : results)
|
||||
{
|
||||
if(rc.Verify(&crypto))
|
||||
llarp_nodedb_put_rc(nodedb, rc);
|
||||
|
@ -461,7 +462,8 @@ llarp_router::TryEstablishTo(const llarp::RouterID &remote)
|
|||
{
|
||||
if(!ConnectionToRouterAllowed(remote))
|
||||
{
|
||||
llarp::LogWarn("not connecting to ", remote, " as it's not permitted by config");
|
||||
llarp::LogWarn("not connecting to ", remote,
|
||||
" as it's not permitted by config");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -566,7 +568,7 @@ llarp_router::Tick()
|
|||
// TODO: only connect to random subset
|
||||
if(bootstrapRCList.size())
|
||||
{
|
||||
for(const auto & rc : bootstrapRCList)
|
||||
for(const auto &rc : bootstrapRCList)
|
||||
{
|
||||
llarp_router_try_connect(this, rc, 4);
|
||||
dht->impl.ExploreNetworkVia(rc.pubkey.data());
|
||||
|
@ -935,7 +937,6 @@ llarp_router::InitServiceNode()
|
|||
return exitContext.AddExitEndpoint("default-connectivity", netConfig);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
llarp_router::HasSessionTo(const llarp::RouterID &remote) const
|
||||
{
|
||||
|
@ -1309,10 +1310,11 @@ namespace llarp
|
|||
self->netConfig.emplace(std::make_pair("local-dns", val));
|
||||
}
|
||||
}
|
||||
else if(StrEq(section, "connect") || (StrEq(section, "bootstrap") && StrEq(key, "add-node")))
|
||||
else if(StrEq(section, "connect")
|
||||
|| (StrEq(section, "bootstrap") && StrEq(key, "add-node")))
|
||||
{
|
||||
self->bootstrapRCList.emplace_back();
|
||||
auto & rc = self->bootstrapRCList.back();
|
||||
auto &rc = self->bootstrapRCList.back();
|
||||
if(rc.Read(val) && rc.Verify(&self->crypto))
|
||||
{
|
||||
llarp::LogInfo("Added bootstrap node ", rc.pubkey);
|
||||
|
|
|
@ -106,11 +106,12 @@ struct llarp_router
|
|||
/// default network config for default network interface
|
||||
NetConfig_t netConfig;
|
||||
|
||||
/// identity keys whitelist of routers we will connect to directly (not for service nodes)
|
||||
std::set<llarp::PubKey> strictConnectPubkeys;
|
||||
/// identity keys whitelist of routers we will connect to directly (not for
|
||||
/// service nodes)
|
||||
std::set< llarp::PubKey > strictConnectPubkeys;
|
||||
|
||||
/// bootstrap RCs
|
||||
std::list<llarp::RouterContact> bootstrapRCList;
|
||||
std::list< llarp::RouterContact > bootstrapRCList;
|
||||
|
||||
bool
|
||||
ExitEnabled() const
|
||||
|
@ -213,17 +214,14 @@ struct llarp_router
|
|||
void
|
||||
PersistSessionUntil(const llarp::RouterID &remote, llarp_time_t until);
|
||||
|
||||
|
||||
|
||||
bool
|
||||
EnsureIdentity();
|
||||
|
||||
bool
|
||||
EnsureEncryptionKey();
|
||||
|
||||
bool
|
||||
ConnectionToRouterAllowed(const llarp::RouterID & router) const;
|
||||
|
||||
bool
|
||||
ConnectionToRouterAllowed(const llarp::RouterID &router) const;
|
||||
|
||||
bool
|
||||
SaveRC();
|
||||
|
@ -271,8 +269,9 @@ struct llarp_router
|
|||
void
|
||||
TryEstablishTo(const llarp::RouterID &remote);
|
||||
|
||||
void
|
||||
HandleDHTLookupForExplore(llarp::RouterID remote, const std::vector< llarp::RouterContact > &results);
|
||||
void
|
||||
HandleDHTLookupForExplore(llarp::RouterID remote,
|
||||
const std::vector< llarp::RouterContact > &results);
|
||||
|
||||
void
|
||||
ForEachPeer(
|
||||
|
|
|
@ -262,8 +262,8 @@ namespace llarp
|
|||
inf.read((char*)buf.base, sz);
|
||||
if(!BDecode(&buf))
|
||||
return false;
|
||||
|
||||
const byte_t * ptr = nullptr;
|
||||
|
||||
const byte_t* ptr = nullptr;
|
||||
if(!vanity.IsZero())
|
||||
ptr = vanity.data();
|
||||
// update pubkeys
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace llarp
|
|||
llarp::LogError("No endpoints found");
|
||||
return nullptr;
|
||||
}
|
||||
auto itr = m_Endpoints.begin();
|
||||
auto itr = m_Endpoints.begin();
|
||||
if(itr == m_Endpoints.end())
|
||||
return nullptr;
|
||||
return itr->second.get();
|
||||
|
@ -101,8 +101,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
Context::FindBestAddressFor(const byte_t * addr, bool isSNode,
|
||||
huint32_t &ip)
|
||||
Context::FindBestAddressFor(const byte_t *addr, bool isSNode, huint32_t &ip)
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while(itr != m_Endpoints.end())
|
||||
|
@ -142,7 +141,6 @@ namespace llarp
|
|||
10000);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
MapAddressAllIter(struct Context::endpoint_iter *endpointCfg)
|
||||
{
|
||||
|
@ -155,8 +153,8 @@ namespace llarp
|
|||
llarp::LogError("No tunnel endpoint found");
|
||||
return true; // still continue
|
||||
}
|
||||
return tunEndpoint->MapAddress(context->serviceAddr,
|
||||
context->localPrivateIpAddr.xtohl(), false);
|
||||
return tunEndpoint->MapAddress(
|
||||
context->serviceAddr, context->localPrivateIpAddr.xtohl(), false);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -197,7 +197,8 @@ namespace llarp
|
|||
continue;
|
||||
byte_t tmp[1024] = {0};
|
||||
auto buf = StackBuffer< decltype(tmp) >(tmp);
|
||||
if(!SendToServiceOrQueue(introset.A.Addr().data(), buf, eProtocolText))
|
||||
if(!SendToServiceOrQueue(introset.A.Addr().data(), buf,
|
||||
eProtocolText))
|
||||
{
|
||||
llarp::LogWarn(Name(), " failed to send/queue data to ",
|
||||
introset.A.Addr(), " for tag ", tag.ToString());
|
||||
|
@ -784,12 +785,12 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
Endpoint::HasPathToSNode(const llarp::RouterID & ident) const
|
||||
Endpoint::HasPathToSNode(const llarp::RouterID& ident) const
|
||||
{
|
||||
auto range = m_SNodeSessions.equal_range(ident);
|
||||
auto itr = range.first;
|
||||
auto itr = range.first;
|
||||
while(itr != range.second)
|
||||
{
|
||||
{
|
||||
if(itr->second->IsReady())
|
||||
{
|
||||
return true;
|
||||
|
@ -800,14 +801,16 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
Endpoint::ProcessDataMessage(ProtocolMessage *msg)
|
||||
Endpoint::ProcessDataMessage(ProtocolMessage* msg)
|
||||
{
|
||||
if(msg->proto == eProtocolTraffic)
|
||||
{
|
||||
auto buf = llarp::Buffer(msg->payload);
|
||||
return HandleWriteIPPacket(buf, std::bind(&Endpoint::ObtainIPForAddr, this, msg->sender.Addr().data(), false));
|
||||
auto buf = llarp::Buffer(msg->payload);
|
||||
return HandleWriteIPPacket(buf,
|
||||
std::bind(&Endpoint::ObtainIPForAddr, this,
|
||||
msg->sender.Addr().data(), false));
|
||||
}
|
||||
else if (msg->proto == eProtocolText)
|
||||
else if(msg->proto == eProtocolText)
|
||||
{
|
||||
// TODO: implement me (?)
|
||||
return true;
|
||||
|
@ -1064,29 +1067,38 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
Endpoint::EnsurePathToSNode(const RouterID & snode)
|
||||
Endpoint::EnsurePathToSNode(const RouterID& snode)
|
||||
{
|
||||
auto range = m_SNodeSessions.equal_range(snode);
|
||||
if(range.first == range.second)
|
||||
{
|
||||
auto themIP = ObtainIPForAddr(snode, true);
|
||||
m_SNodeSessions.emplace(std::make_pair(snode, std::unique_ptr<llarp::exit::BaseSession>(new llarp::exit::SNodeSession(snode, std::bind(&Endpoint::HandleWriteIPPacket, this, std::placeholders::_1, [themIP]() -> huint32_t {return themIP;}), m_Router, 2, numHops))));
|
||||
m_SNodeSessions.emplace(std::make_pair(
|
||||
snode,
|
||||
std::unique_ptr< llarp::exit::BaseSession >(
|
||||
new llarp::exit::SNodeSession(
|
||||
snode,
|
||||
std::bind(&Endpoint::HandleWriteIPPacket, this,
|
||||
std::placeholders::_1,
|
||||
[themIP]() -> huint32_t { return themIP; }),
|
||||
m_Router, 2, numHops))));
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::SendToSNodeOrQueue(const byte_t * addr, llarp_buffer_t buf)
|
||||
Endpoint::SendToSNodeOrQueue(const byte_t* addr, llarp_buffer_t buf)
|
||||
{
|
||||
llarp::net::IPv4Packet pkt;
|
||||
if(!pkt.Load(buf))
|
||||
return false;
|
||||
auto range = m_SNodeSessions.equal_range(addr);
|
||||
auto itr = range.first;
|
||||
auto itr = range.first;
|
||||
while(itr != range.second)
|
||||
{
|
||||
if(itr->second->IsReady())
|
||||
{
|
||||
if(itr->second->QueueUpstreamTraffic(pkt, llarp::routing::ExitPadSize))
|
||||
if(itr->second->QueueUpstreamTraffic(pkt,
|
||||
llarp::routing::ExitPadSize))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1098,7 +1110,7 @@ namespace llarp
|
|||
|
||||
bool
|
||||
Endpoint::SendToServiceOrQueue(const byte_t* addr, llarp_buffer_t data,
|
||||
ProtocolType t)
|
||||
ProtocolType t)
|
||||
{
|
||||
service::Address remote(addr);
|
||||
|
||||
|
|
|
@ -259,13 +259,14 @@ namespace llarp
|
|||
if(endpoint)
|
||||
{
|
||||
bool sent = true;
|
||||
for(const auto & pkt : msg->X)
|
||||
for(const auto& pkt : msg->X)
|
||||
{
|
||||
// check short packet buffer
|
||||
if(pkt.size() <= 8)
|
||||
continue;
|
||||
uint64_t counter = bufbe64toh(pkt.data());
|
||||
sent &= endpoint->QueueOutboundTraffic(llarp::InitBuffer(pkt.data() + 8, pkt.size() - 8), counter);
|
||||
sent &= endpoint->QueueOutboundTraffic(
|
||||
llarp::InitBuffer(pkt.data() + 8, pkt.size() - 8), counter);
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue