2019-06-17 23:19:39 +00:00
|
|
|
#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>
|
2019-06-04 18:31:17 +00:00
|
|
|
#include <router/i_outbound_message_handler.hpp>
|
2019-06-17 23:19:39 +00:00
|
|
|
#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);
|
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
void
|
2019-09-16 10:21:12 +00:00
|
|
|
PumpUpstream();
|
|
|
|
|
|
|
|
void
|
|
|
|
PumpDownstream();
|
2019-09-05 17:39:09 +00:00
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
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);
|
|
|
|
|
2019-11-21 14:48:31 +00:00
|
|
|
TransitHop_ptr
|
2019-06-17 23:19:39 +00:00
|
|
|
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,
|
2019-06-04 18:31:17 +00:00
|
|
|
const std::array< EncryptedFrame, 8 >& frames,
|
|
|
|
SendStatusHandler handler);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-09-04 12:24:17 +00:00
|
|
|
using Mutex_t = util::NullMutex;
|
|
|
|
using Lock_t = util::NullLock;
|
|
|
|
|
|
|
|
Mutex_t first; // protects second
|
2019-06-17 23:19:39 +00:00
|
|
|
TransitHopsMap_t second GUARDED_BY(first);
|
|
|
|
|
|
|
|
void
|
|
|
|
ForEach(std::function< void(const TransitHop_ptr&) > visit)
|
2019-08-07 23:18:56 +00:00
|
|
|
LOCKS_EXCLUDED(first)
|
2019-06-17 23:19:39 +00:00
|
|
|
{
|
2019-09-04 12:24:17 +00:00
|
|
|
Lock_t lock(&first);
|
2019-06-17 23:19:39 +00:00
|
|
|
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
|
|
|
|
{
|
2019-09-04 12:24:17 +00:00
|
|
|
using Mutex_t = util::Mutex;
|
|
|
|
using Lock_t = util::Lock;
|
|
|
|
Mutex_t first; // protects second
|
2019-06-17 23:19:39 +00:00
|
|
|
OwnedPathsMap_t second GUARDED_BY(first);
|
|
|
|
|
|
|
|
void
|
|
|
|
ForEach(std::function< void(const PathSet_ptr&) > visit)
|
|
|
|
{
|
2019-09-04 12:24:17 +00:00
|
|
|
Lock_t lock(&first);
|
2019-06-17 23:19:39 +00:00
|
|
|
for(const auto& item : second)
|
|
|
|
visit(item.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-09 13:47:24 +00:00
|
|
|
std::shared_ptr< thread::ThreadPool >
|
2019-06-17 23:19:39 +00:00
|
|
|
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
|