pull/5/head
Jeff Becker 6 years ago
parent acec52a2c7
commit 5bbaae4e2e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -175,6 +175,7 @@ set(LIB_SRC
llarp/dht/context.cpp
llarp/dht/decode.cpp
llarp/dht/dht_immediate.cpp
llarp/dht/find_intro.cpp
llarp/dht/find_router.cpp
llarp/dht/got_intro.cpp
llarp/dht/got_router.cpp

@ -516,7 +516,7 @@ B is set to a backoff value.
R contains additional metadata text describing why the exit was rejected.
hidden service frame message (HSFM)
hidden service frame (HSF)
TODO: document this better
@ -562,7 +562,7 @@ transfer data between paths.
{
A: "T",
P: "<16 bytes path id>",
T: "<N bytes data>",
T: message_transfered_between_paths,
V: 0
}

@ -23,10 +23,6 @@ llarp_main_init(const char *fname, bool multiProcess);
void
llarp_main_signal(struct llarp_main *ptr, int sig);
/// set custom dht message handler function
void
llarp_main_set_dht_handler(struct llarp_main *ptr, llarp_dht_msg_handler h);
/// setup main context
int
llarp_main_setup(struct llarp_main *ptr);

@ -18,15 +18,14 @@ namespace llarp
bool singleThreaded = false;
std::vector< std::thread > netio_threads;
llarp_crypto crypto;
llarp_router *router = nullptr;
llarp_threadpool *worker = nullptr;
llarp_logic *logic = nullptr;
llarp_config *config = nullptr;
llarp_nodedb *nodedb = nullptr;
llarp_ev_loop *mainloop = nullptr;
llarp_dht_msg_handler custom_dht_func = nullptr;
char nodedb_dir[256] = {0};
char conatctFile[256] = "router.signed";
llarp_router *router = nullptr;
llarp_threadpool *worker = nullptr;
llarp_logic *logic = nullptr;
llarp_config *config = nullptr;
llarp_nodedb *nodedb = nullptr;
llarp_ev_loop *mainloop = nullptr;
char nodedb_dir[256] = {0};
char conatctFile[256] = "router.signed";
bool
LoadConfig(const std::string &fname);

@ -20,23 +20,10 @@ llarp_dht_context_new(struct llarp_router* parent);
void
llarp_dht_context_free(struct llarp_dht_context* dht);
struct llarp_dht_msg;
/// handler function
/// f(outmsg, inmsg)
/// returns true if outmsg has been filled otherwise returns false
typedef bool (*llarp_dht_msg_handler)(struct llarp_dht_msg*,
struct llarp_dht_msg*);
/// start dht context with our location in keyspace
void
llarp_dht_context_start(struct llarp_dht_context* ctx, const byte_t* key);
// override dht message handler with custom handler
void
llarp_dht_set_msg_handler(struct llarp_dht_context* ctx,
llarp_dht_msg_handler func);
struct llarp_router_lookup_job;
typedef void (*llarp_router_lookup_handler)(struct llarp_router_lookup_job*);

@ -20,14 +20,19 @@ namespace llarp
Context();
~Context();
llarp_dht_msg_handler custom_handler = nullptr;
SearchJob*
FindPendingTX(const Key_t& owner, uint64_t txid);
void
RemovePendingLookup(const Key_t& owner, uint64_t txid);
void
LookupServiceDirect(const Key_t& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,
SearchJob::IntroSetHookFunc handler,
bool iterateive = false,
std::set< Key_t > excludes = {});
void
LookupRouter(const Key_t& target, const Key_t& whoasked,
uint64_t whoaskedTX, const Key_t& askpeer,

@ -9,7 +9,8 @@ namespace llarp
{
struct FindIntroMessage : public IMessage
{
uint64_t R = 0;
uint64_t R = 0;
bool iterative = false;
llarp::service::Address S;
uint64_t T = 0;
@ -25,6 +26,6 @@ namespace llarp
HandleMessage(llarp_dht_context* ctx,
std::vector< IMessage* >& replies) const;
};
}
}
} // namespace dht
} // namespace llarp
#endif

@ -165,9 +165,6 @@ namespace llarp
bool
HandleDHTMessage(const llarp::dht::IMessage* msg, llarp_router* r);
bool
HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r);
// handle data in upstream direction
bool
HandleUpstream(llarp_buffer_t X, const TunnelNonce& Y, llarp_router* r);
@ -246,9 +243,6 @@ namespace llarp
bool
HandleRoutingMessage(llarp_buffer_t buf, llarp_router* r);
bool
HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r);
// handle data in upstream direction
bool
HandleUpstream(llarp_buffer_t X, const TunnelNonce& Y, llarp_router* r);

@ -20,7 +20,7 @@ struct llarp_pathbuilder_context;
/// alloc
struct llarp_pathbuilder_context*
llarp_pathbuilder_context_new(struct llarp_router* router,
struct llarp_dht_context* dht);
struct llarp_dht_context* dht, size_t numpaths);
/// dealloc
void
llarp_pathbuilder_context_free(struct llarp_pathbuilder_context* ctx);

@ -10,7 +10,7 @@ struct llarp_pathbuilder_context : public llarp::path::PathSet
struct llarp_dht_context* dht;
/// construct
llarp_pathbuilder_context(llarp_router* p_router,
struct llarp_dht_context* p_dht);
struct llarp_dht_context* p_dht, size_t numPaths);
virtual ~llarp_pathbuilder_context(){};

@ -1,6 +1,7 @@
#ifndef LLARP_PATHSET_HPP
#define LLARP_PATHSET_HPP
#include <llarp/time.h>
#include <functional>
#include <list>
#include <llarp/path_types.hpp>
#include <llarp/router_id.hpp>
@ -81,6 +82,18 @@ namespace llarp
PublishIntroSet(const llarp::service::IntroSet& introset,
llarp_router* r);
typedef std::function< void(const llarp::service::IntroSet*) >
ServiceLookupHandler;
/// return false if we are already pending a lookup for this address
bool
LookupService(const llarp::service::Address& addr,
ServiceLookupHandler handler);
protected:
void
IssueServiceLookup(const llarp::service::Address& addr);
private:
typedef std::pair< RouterID, PathID_t > PathInfo_t;
typedef std::map< PathInfo_t, Path* > PathMap_t;
@ -88,6 +101,9 @@ namespace llarp
size_t m_NumPaths;
PathMap_t m_Paths;
uint64_t m_CurrentPublishTX = 0;
std::unordered_map< llarp::service::Address, ServiceLookupHandler,
llarp::service::Address::Hash >
m_ServiceLookups;
};
} // namespace path

@ -4,6 +4,7 @@
#include <llarp/buffer.h>
#include <llarp/router.h>
#include <llarp/dht.hpp>
#include <llarp/messages/hidden_service.hpp>
#include <llarp/messages/path_confirm.hpp>
#include <llarp/messages/path_latency.hpp>
#include <llarp/messages/path_transfer.hpp>
@ -20,7 +21,10 @@ namespace llarp
llarp_router *r) = 0;
virtual bool
HandleHiddenServiceData(llarp_buffer_t buf, llarp_router *r) = 0;
HandleHiddenServiceFrame(const HiddenServiceFrame *msg)
{
return false;
}
virtual bool
HandlePathConfirmMessage(const PathConfirmMessage *msg,

@ -20,6 +20,16 @@ namespace llarp
Address(const byte_t* data) : llarp::AlignedBuffer< 32 >(data)
{
}
struct Hash
{
size_t
operator()(const Address& addr) const
{
size_t idx = 0;
memcpy(&idx, addr, sizeof(idx));
return idx;
}
};
};
} // namespace service

@ -1,5 +1,6 @@
#ifndef LLARP_SERVICE_ENDPOINT_HPP
#define LLARP_SERVICE_ENDPOINT_HPP
#include <llarp/messages/hidden_service.hpp>
#include <llarp/pathbuilder.hpp>
#include <llarp/service/Identity.hpp>
@ -24,11 +25,70 @@ namespace llarp
bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg);
bool
HandleHiddenServiceFrame(const llarp::routing::HiddenServiceFrame* msg);
/// return true if we have an established path to a hidden service
bool
HasPathToService(const Address& remote) const;
/// return false if we don't have a path to the service
/// return true if we did and we removed it
bool
ForgetPathToService(const Address& remote);
/// context needed to initiate an outbound hidden service session
struct OutboundContext : public llarp_pathbuilder_context
{
OutboundContext(Endpoint* parent);
~OutboundContext();
/// the remote hidden service's curren intro set
IntroSet currentIntroSet;
uint64_t sequenceNo = 0;
/// encrypt asynchronously and send to remote endpoint from us
/// returns false if we cannot send yet otherwise returns true
bool
AsyncEncryptAndSendTo(llarp_buffer_t D);
/// issues a lookup to find the current intro set of the remote service
void
UpdateIntroSet();
bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg);
private:
llarp::SharedSecret sharedKey;
Endpoint* m_Parent;
};
// passed a sendto context when we have a path established otherwise
// nullptr if the path was not made before the timeout
typedef std::function< void(OutboundContext*) > PathEnsureHook;
/// return false if we have already called this function before for this
/// address
bool
EnsurePathToService(const Address& remote, PathEnsureHook h,
uint64_t timeoutMS);
virtual bool
HandleAuthenticatedDataFrom(const Address& remote, llarp_buffer_t data)
{
/// TODO: imlement me
return true;
}
private:
llarp_router* m_Router;
std::string m_Keyfile;
std::string m_Name;
Identity m_Identity;
std::unordered_map< Address, OutboundContext*, Address::Hash >
m_RemoteSessions;
};
} // namespace service
} // namespace llarp

@ -161,11 +161,6 @@ namespace llarp
llarp::LogError("Failed to configure router");
return 1;
}
if(custom_dht_func)
{
llarp::LogInfo("using custom dht function");
llarp_dht_set_msg_handler(router->dht, custom_dht_func);
}
// set nodedb, load our RC, establish DHT
llarp_run_router(router, nodedb);
@ -325,12 +320,6 @@ llarp_main_init(const char *fname, bool multiProcess)
return m;
}
void
llarp_main_set_dht_handler(struct llarp_main *ptr, llarp_dht_msg_handler func)
{
ptr->ctx->custom_dht_func = func;
}
void
llarp_main_signal(struct llarp_main *ptr, int sig)
{

@ -34,13 +34,6 @@ llarp_dht_remove_peer(struct llarp_dht_context *ctx, const byte_t *id)
ctx->impl.nodes->DelNode(k);
}
void
llarp_dht_set_msg_handler(struct llarp_dht_context *ctx,
llarp_dht_msg_handler handler)
{
ctx->impl.custom_handler = handler;
}
void
llarp_dht_allow_transit(llarp_dht_context *ctx)
{

@ -0,0 +1,11 @@
#include <llarp/dht/messages/findintro.hpp>
namespace llarp
{
namespace dht
{
FindIntroMessage::~FindIntroMessage()
{
}
} // namespace dht
} // namespace llarp

@ -381,13 +381,6 @@ namespace llarp
return HandleRoutingMessage(buf, r);
}
bool
Path::HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r)
{
// TODO: implement me
return false;
}
bool
Path::HandleRoutingMessage(llarp_buffer_t buf, llarp_router* r)
{

@ -175,9 +175,8 @@ namespace llarp
} // namespace llarp
llarp_pathbuilder_context::llarp_pathbuilder_context(
llarp_router* p_router, struct llarp_dht_context* p_dht)
// TODO: hardcoded value
: llarp::path::PathSet(4), router(p_router), dht(p_dht)
llarp_router* p_router, struct llarp_dht_context* p_dht, size_t pathNum)
: llarp::path::PathSet(pathNum), router(p_router), dht(p_dht)
{
p_router->paths.AddPathBuilder(this);
}
@ -196,9 +195,9 @@ llarp_pathbuilder_context::BuildOne()
struct llarp_pathbuilder_context*
llarp_pathbuilder_context_new(struct llarp_router* router,
struct llarp_dht_context* dht)
struct llarp_dht_context* dht, size_t sz)
{
return new llarp_pathbuilder_context(router, dht);
return new llarp_pathbuilder_context(router, dht, sz);
}
void

@ -34,7 +34,6 @@ llarp_router::llarp_router()
, paths(this)
, dht(llarp_dht_context_new(this))
, inbound_link_msg_parser(this)
, explorePool(llarp_pathbuilder_context_new(this, dht))
, hiddenServiceContext(this)
{

@ -6,7 +6,7 @@ namespace llarp
namespace service
{
Endpoint::Endpoint(const std::string& name, llarp_router* r)
: llarp_pathbuilder_context(r, r->dht), m_Router(r), m_Name(name)
: llarp_pathbuilder_context(r, r->dht, 2), m_Router(r), m_Name(name)
{
}
@ -96,5 +96,23 @@ namespace llarp
Endpoint::~Endpoint()
{
}
}
}
Endpoint::OutboundContext::OutboundContext(Endpoint* parent)
: llarp_pathbuilder_context(parent->m_Router, parent->m_Router->dht, 2)
, m_Parent(parent)
{
}
Endpoint::OutboundContext::~OutboundContext()
{
}
bool
Endpoint::OutboundContext::HandleGotIntroMessage(
const llarp::dht::GotIntroMessage* msg)
{
// TODO: implement me
return false;
}
} // namespace service
} // namespace llarp

@ -136,12 +136,5 @@ namespace llarp
return false;
}
bool
TransitHop::HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r)
{
llarp::LogWarn("unwarrented hidden service data on ", info);
return false;
}
} // namespace path
} // namespace llarp

Loading…
Cancel
Save