2018-06-10 14:05:48 +00:00
|
|
|
#ifndef LLARP_PATH_HPP
|
|
|
|
#define LLARP_PATH_HPP
|
2018-12-12 02:04:32 +00:00
|
|
|
|
2019-01-14 21:46:07 +00:00
|
|
|
#include <crypto/encrypted_frame.hpp>
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <messages/relay.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/path_types.hpp>
|
|
|
|
#include <path/pathbuilder.hpp>
|
|
|
|
#include <path/pathset.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <router_id.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/handler.hpp>
|
|
|
|
#include <routing/message.hpp>
|
2019-04-22 18:35:19 +00:00
|
|
|
#include <service/intro.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/aligned.hpp>
|
|
|
|
#include <util/threading.hpp>
|
|
|
|
#include <util/time.hpp>
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2019-04-19 18:24:33 +00:00
|
|
|
#include <algorithm>
|
2018-07-11 13:20:14 +00:00
|
|
|
#include <functional>
|
2018-06-19 17:11:24 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2018-06-10 14:05:48 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
class Logic;
|
2019-01-29 02:16:31 +00:00
|
|
|
struct AbstractRouter;
|
2019-01-13 16:30:07 +00:00
|
|
|
struct Crypto;
|
2019-01-14 21:46:07 +00:00
|
|
|
struct LR_CommitMessage;
|
|
|
|
struct LR_CommitRecord;
|
2019-02-11 19:45:42 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
namespace path
|
2018-06-10 14:05:48 +00:00
|
|
|
{
|
2019-04-05 14:58:22 +00:00
|
|
|
/// 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 = 15000;
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
struct TransitHopInfo
|
|
|
|
{
|
|
|
|
TransitHopInfo() = default;
|
|
|
|
TransitHopInfo(const TransitHopInfo& other);
|
|
|
|
TransitHopInfo(const RouterID& down, const LR_CommitRecord& record);
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
PathID_t txID, rxID;
|
|
|
|
RouterID upstream;
|
|
|
|
RouterID downstream;
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
std::ostream&
|
|
|
|
print(std::ostream& stream, int level, int spaces) const;
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
operator==(const TransitHopInfo& other) const
|
|
|
|
{
|
|
|
|
return txID == other.txID && rxID == other.rxID
|
|
|
|
&& upstream == other.upstream && downstream == other.downstream;
|
|
|
|
}
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
operator!=(const TransitHopInfo& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
operator<(const TransitHopInfo& other) const
|
|
|
|
{
|
|
|
|
return txID < other.txID || rxID < other.rxID
|
|
|
|
|| upstream < other.upstream || downstream < other.downstream;
|
|
|
|
}
|
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
struct PathIDHash
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
|
|
|
std::size_t
|
2019-01-02 01:04:04 +00:00
|
|
|
operator()(const PathID_t& a) const
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
return AlignedBuffer< PathID_t::SIZE >::Hash()(a);
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
};
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
struct Hash
|
2018-06-10 14:05:48 +00:00
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2018-06-10 14:05:48 +00:00
|
|
|
};
|
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& out, const TransitHopInfo& info)
|
|
|
|
{
|
|
|
|
return info.print(out, -1, -1);
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
struct IHopHandler
|
2018-06-18 22:03:50 +00:00
|
|
|
{
|
2019-04-24 23:27:31 +00:00
|
|
|
virtual ~IHopHandler()
|
|
|
|
{
|
|
|
|
}
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
virtual bool
|
|
|
|
Expired(llarp_time_t now) const = 0;
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
virtual bool
|
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const = 0;
|
|
|
|
|
2018-07-24 22:34:46 +00:00
|
|
|
/// send routing message and increment sequence number
|
2018-06-25 15:12:08 +00:00
|
|
|
virtual bool
|
2019-04-22 17:38:29 +00:00
|
|
|
SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r) = 0;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in upstream direction
|
|
|
|
virtual bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) = 0;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in downstream direction
|
|
|
|
virtual bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) = 0;
|
2018-07-24 22:34:46 +00:00
|
|
|
|
2018-12-27 14:32:37 +00:00
|
|
|
/// return timestamp last remote activity happened at
|
|
|
|
virtual llarp_time_t
|
|
|
|
LastRemoteActivityAt() const = 0;
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
uint64_t
|
|
|
|
NextSeqNo()
|
|
|
|
{
|
|
|
|
return m_SequenceNum++;
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:34:46 +00:00
|
|
|
protected:
|
|
|
|
uint64_t m_SequenceNum = 0;
|
2018-06-25 15:12:08 +00:00
|
|
|
};
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2019-04-23 16:13:22 +00:00
|
|
|
using HopHandler_ptr = std::shared_ptr< IHopHandler >;
|
2019-04-23 14:28:59 +00:00
|
|
|
|
2019-04-22 17:38:29 +00:00
|
|
|
struct TransitHop : public IHopHandler, public routing::IMessageHandler
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2018-06-26 16:23:43 +00:00
|
|
|
TransitHop();
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
TransitHop(const TransitHop& other);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
TransitHopInfo info;
|
|
|
|
SharedSecret pathKey;
|
2018-07-28 22:20:32 +00:00
|
|
|
ShortHash nonceXOR;
|
2018-06-25 15:12:08 +00:00
|
|
|
llarp_time_t started = 0;
|
|
|
|
// 10 minutes default
|
2019-04-05 14:58:22 +00:00
|
|
|
llarp_time_t lifetime = default_lifetime;
|
2018-06-25 15:12:08 +00:00
|
|
|
llarp_proto_version_t version;
|
2018-12-27 14:32:37 +00:00
|
|
|
llarp_time_t m_LastActivity = 0;
|
2018-06-25 15:12:08 +00:00
|
|
|
|
2018-10-03 10:41:36 +00:00
|
|
|
bool
|
|
|
|
IsEndpoint(const RouterID& us) const
|
2018-10-02 15:00:34 +00:00
|
|
|
{
|
|
|
|
return info.upstream == us;
|
|
|
|
}
|
2018-10-03 10:41:36 +00:00
|
|
|
|
2018-08-22 16:19:51 +00:00
|
|
|
llarp_time_t
|
|
|
|
ExpireTime() const;
|
2018-12-27 14:32:37 +00:00
|
|
|
|
|
|
|
llarp_time_t
|
|
|
|
LastRemoteActivityAt() const override
|
|
|
|
{
|
|
|
|
return m_LastActivity;
|
|
|
|
}
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
std::ostream&
|
|
|
|
print(std::ostream& stream, int level, int spaces) const;
|
2018-06-25 15:12:08 +00:00
|
|
|
|
|
|
|
bool
|
2018-11-14 18:02:27 +00:00
|
|
|
Expired(llarp_time_t now) const override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const override
|
|
|
|
{
|
|
|
|
return now >= ExpireTime() - dlt;
|
|
|
|
}
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
// send routing message when end of path
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
SendRoutingMessage(const routing::IMessage& msg,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
// handle routing message when end of path
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleRoutingMessage(const routing::IMessage& msg, AbstractRouter* r);
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-09-11 15:28:36 +00:00
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathTransferMessage(const routing::PathTransferMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
|
|
|
|
AbstractRouter* r) override;
|
2018-11-14 12:23:08 +00:00
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
|
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleGrantExitMessage(const routing::GrantExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleRejectExitMessage(const routing::RejectExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleCloseExitMessage(const routing::CloseExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleHiddenServiceFrame(
|
|
|
|
ABSL_ATTRIBUTE_UNUSED const service::ProtocolFrame& frame) override
|
2018-08-02 00:48:43 +00:00
|
|
|
{
|
|
|
|
/// TODO: implement me
|
2019-04-22 17:38:29 +00:00
|
|
|
LogWarn("Got hidden service data on transit hop");
|
2018-08-02 00:48:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleGotIntroMessage(const dht::GotIntroMessage& msg);
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in upstream direction
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in downstream direction
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-25 15:12:08 +00:00
|
|
|
};
|
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& out, const TransitHop& h)
|
|
|
|
{
|
|
|
|
return h.print(out, -1, -1);
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
/// configuration for a single hop when building a path
|
2019-04-19 15:10:26 +00:00
|
|
|
struct PathHopConfig
|
2018-06-22 00:25:30 +00:00
|
|
|
{
|
2018-06-25 15:12:08 +00:00
|
|
|
/// path id
|
|
|
|
PathID_t txID, rxID;
|
|
|
|
// router contact of router
|
2018-08-30 18:48:43 +00:00
|
|
|
RouterContact rc;
|
2018-06-25 15:12:08 +00:00
|
|
|
// temp public encryption key
|
|
|
|
SecretKey commkey;
|
|
|
|
/// shared secret at this hop
|
|
|
|
SharedSecret shared;
|
2018-07-28 22:20:32 +00:00
|
|
|
/// hash of shared secret used for nonce mutation
|
|
|
|
ShortHash nonceXOR;
|
2018-06-25 15:12:08 +00:00
|
|
|
/// next hop's router id
|
|
|
|
RouterID upstream;
|
|
|
|
/// nonce for key exchange
|
|
|
|
TunnelNonce nonce;
|
|
|
|
// lifetime
|
2019-04-05 14:58:22 +00:00
|
|
|
llarp_time_t lifetime = default_lifetime;
|
2018-06-25 15:12:08 +00:00
|
|
|
|
|
|
|
~PathHopConfig();
|
|
|
|
PathHopConfig();
|
2019-02-11 17:14:43 +00:00
|
|
|
|
|
|
|
util::StatusObject
|
2019-04-19 15:10:26 +00:00
|
|
|
ExtractStatus() const;
|
2018-06-25 15:12:08 +00:00
|
|
|
};
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
/// A path we made
|
2019-04-23 16:13:22 +00:00
|
|
|
struct Path : public IHopHandler,
|
|
|
|
public routing::IMessageHandler,
|
|
|
|
public std::enable_shared_from_this< Path >
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2019-04-23 14:28:59 +00:00
|
|
|
using BuildResultHookFunc = std::function< void(Path_ptr) >;
|
|
|
|
using CheckForDeadFunc = std::function< bool(Path_ptr, llarp_time_t) >;
|
2018-11-22 23:59:03 +00:00
|
|
|
using DropHandlerFunc =
|
2019-04-23 14:28:59 +00:00
|
|
|
std::function< bool(Path_ptr, const PathID_t&, uint64_t) >;
|
2018-11-22 23:59:03 +00:00
|
|
|
using HopList = std::vector< PathHopConfig >;
|
|
|
|
using DataHandlerFunc =
|
2019-04-23 14:28:59 +00:00
|
|
|
std::function< bool(Path_ptr, const service::ProtocolFrame&) >;
|
|
|
|
using ExitUpdatedFunc = std::function< bool(Path_ptr) >;
|
|
|
|
using ExitClosedFunc = std::function< bool(Path_ptr) >;
|
2018-11-22 23:59:03 +00:00
|
|
|
using ExitTrafficHandlerFunc =
|
2019-04-23 14:28:59 +00:00
|
|
|
std::function< bool(Path_ptr, const llarp_buffer_t&, uint64_t) >;
|
2018-11-14 18:02:27 +00:00
|
|
|
/// (path, backoff) backoff is 0 on success
|
2019-04-23 14:28:59 +00:00
|
|
|
using ObtainedExitHandler = std::function< bool(Path_ptr, llarp_time_t) >;
|
2018-08-02 00:48:43 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
HopList hops;
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2019-04-23 16:13:22 +00:00
|
|
|
PathSet* const m_PathSet;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
2019-04-22 17:38:29 +00:00
|
|
|
service::Introduction intro;
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
llarp_time_t buildStarted;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
Path(const std::vector< RouterContact >& routers, PathSet* parent,
|
|
|
|
PathRole startingRoles);
|
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
2019-04-19 15:10:26 +00:00
|
|
|
ExtractStatus() const;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
PathRole
|
|
|
|
Role() const
|
|
|
|
{
|
|
|
|
return _role;
|
|
|
|
}
|
|
|
|
|
2018-11-16 14:22:13 +00:00
|
|
|
void
|
2018-11-16 14:21:23 +00:00
|
|
|
MarkActive(llarp_time_t now)
|
|
|
|
{
|
2018-12-20 15:03:37 +00:00
|
|
|
m_LastRecvMessage = std::max(now, m_LastRecvMessage);
|
2018-11-16 14:21:23 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 12:31:36 +00:00
|
|
|
/// return true if ALL of the specified roles are supported
|
2018-11-14 18:02:27 +00:00
|
|
|
bool
|
2018-11-21 12:31:36 +00:00
|
|
|
SupportsAllRoles(PathRole roles) const
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
|
|
|
return (_role & roles) == roles;
|
|
|
|
}
|
|
|
|
|
2018-11-21 12:31:36 +00:00
|
|
|
/// return true if ANY of the specified roles are supported
|
|
|
|
bool
|
|
|
|
SupportsAnyRoles(PathRole roles) const
|
|
|
|
{
|
2018-11-21 14:30:14 +00:00
|
|
|
return roles == ePathRoleAny || (_role & roles) != 0;
|
2018-11-21 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
PathStatus
|
|
|
|
Status() const
|
|
|
|
{
|
|
|
|
return _status;
|
|
|
|
}
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2019-03-11 13:58:31 +00:00
|
|
|
std::string
|
|
|
|
HopsString() const;
|
|
|
|
|
2018-12-27 14:32:37 +00:00
|
|
|
llarp_time_t
|
|
|
|
LastRemoteActivityAt() const override
|
|
|
|
{
|
|
|
|
return m_LastRecvMessage;
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
|
|
|
SetBuildResultHook(BuildResultHookFunc func);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
void
|
|
|
|
SetExitTrafficHandler(ExitTrafficHandlerFunc handler)
|
|
|
|
{
|
|
|
|
m_ExitTrafficHandler = handler;
|
|
|
|
}
|
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
void
|
|
|
|
SetCloseExitFunc(ExitClosedFunc handler)
|
|
|
|
{
|
|
|
|
m_ExitClosed = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetUpdateExitFunc(ExitUpdatedFunc handler)
|
|
|
|
{
|
|
|
|
m_ExitUpdated = handler;
|
|
|
|
}
|
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
void
|
|
|
|
SetDataHandler(DataHandlerFunc func)
|
|
|
|
{
|
|
|
|
m_DataHandler = func;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
void
|
|
|
|
SetDropHandler(DropHandlerFunc func)
|
|
|
|
{
|
|
|
|
m_DropHandler = func;
|
|
|
|
}
|
|
|
|
|
2018-09-13 12:27:28 +00:00
|
|
|
void
|
|
|
|
SetDeadChecker(CheckForDeadFunc func)
|
|
|
|
{
|
|
|
|
m_CheckForDead = func;
|
|
|
|
}
|
|
|
|
|
2018-09-13 13:07:00 +00:00
|
|
|
void
|
2018-10-29 16:48:36 +00:00
|
|
|
EnterState(PathStatus st, llarp_time_t now);
|
2018-09-13 13:07:00 +00:00
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
llarp_time_t
|
|
|
|
ExpireTime() const
|
|
|
|
{
|
|
|
|
return buildStarted + hops[0].lifetime;
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
bool
|
2018-11-19 13:39:35 +00:00
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const override
|
2018-11-14 18:02:27 +00:00
|
|
|
{
|
|
|
|
return now >= (ExpireTime() - dlt);
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2018-11-19 13:39:35 +00:00
|
|
|
Expired(llarp_time_t now) const override;
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2019-05-06 14:54:05 +00:00
|
|
|
/// build a new path on the same set of hops as us
|
|
|
|
/// regenerates keys
|
|
|
|
void
|
|
|
|
Rebuild();
|
|
|
|
|
2018-06-29 16:02:39 +00:00
|
|
|
void
|
2019-02-11 19:45:42 +00:00
|
|
|
Tick(llarp_time_t now, AbstractRouter* r);
|
2018-06-29 16:02:39 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
SendRoutingMessage(const routing::IMessage& msg,
|
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleObtainExitMessage(const routing::ObtainExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleUpdateExitVerifyMessage(const routing::UpdateExitVerifyMessage& msg,
|
|
|
|
AbstractRouter* r) override;
|
2018-11-14 12:23:08 +00:00
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleTransferTrafficMessage(const routing::TransferTrafficMessage& msg,
|
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleUpdateExitMessage(const routing::UpdateExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleCloseExitMessage(const routing::CloseExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleGrantExitMessage(const routing::GrantExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleRejectExitMessage(const routing::RejectExitMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleDataDiscardMessage(const routing::DataDiscardMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-09-11 15:28:36 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathConfirmMessage(const routing::PathConfirmMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathLatencyMessage(const routing::PathLatencyMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandlePathTransferMessage(const routing::PathTransferMessage& msg,
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-26 16:23:43 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleHiddenServiceFrame(const service::ProtocolFrame& frame) override;
|
2018-08-02 00:48:43 +00:00
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleGotIntroMessage(const dht::GotIntroMessage& msg);
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-06-26 16:23:43 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleDHTMessage(const dht::IMessage& msg, AbstractRouter* r) override;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-01-29 02:16:31 +00:00
|
|
|
HandleRoutingMessage(const llarp_buffer_t& buf, AbstractRouter* r);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in upstream direction
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// handle data in downstream direction
|
|
|
|
bool
|
2019-02-01 01:58:06 +00:00
|
|
|
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-01-29 02:16:31 +00:00
|
|
|
AbstractRouter* r) override;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-07-11 16:11:19 +00:00
|
|
|
bool
|
|
|
|
IsReady() const;
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// Is this deprecated?
|
|
|
|
// nope not deprecated :^DDDD
|
2018-12-18 19:03:50 +00:00
|
|
|
PathID_t
|
2018-06-25 15:12:08 +00:00
|
|
|
TXID() const;
|
2018-06-23 11:28:37 +00:00
|
|
|
|
2018-07-23 07:38:29 +00:00
|
|
|
RouterID
|
|
|
|
Endpoint() const;
|
|
|
|
|
2018-12-10 17:22:59 +00:00
|
|
|
PubKey
|
|
|
|
EndpointPubKey() const;
|
|
|
|
|
2018-09-24 11:36:47 +00:00
|
|
|
bool
|
|
|
|
IsEndpoint(const RouterID& router, const PathID_t& path) const;
|
|
|
|
|
2018-12-18 19:03:50 +00:00
|
|
|
PathID_t
|
2018-06-25 15:12:08 +00:00
|
|
|
RXID() const;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
RouterID
|
|
|
|
Upstream() const;
|
2018-06-22 13:59:28 +00:00
|
|
|
|
2018-09-13 13:07:00 +00:00
|
|
|
std::string
|
|
|
|
Name() const;
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
void
|
|
|
|
AddObtainExitHandler(ObtainedExitHandler handler)
|
|
|
|
{
|
|
|
|
m_ObtainedExitHooks.push_back(handler);
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
SendExitRequest(const routing::ObtainExitMessage& msg, AbstractRouter* r);
|
2018-11-14 18:02:27 +00:00
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
SendExitClose(const routing::CloseExitMessage& msg, AbstractRouter* r);
|
2018-12-24 16:09:05 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
private:
|
2018-11-14 18:02:27 +00:00
|
|
|
/// call obtained exit hooks
|
|
|
|
bool
|
|
|
|
InformExitResult(llarp_time_t b);
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
BuildResultHookFunc m_BuiltHook;
|
2018-08-02 00:48:43 +00:00
|
|
|
DataHandlerFunc m_DataHandler;
|
2018-09-11 15:28:36 +00:00
|
|
|
DropHandlerFunc m_DropHandler;
|
2018-09-13 12:27:28 +00:00
|
|
|
CheckForDeadFunc m_CheckForDead;
|
2018-11-14 12:23:08 +00:00
|
|
|
ExitUpdatedFunc m_ExitUpdated;
|
|
|
|
ExitClosedFunc m_ExitClosed;
|
2018-11-14 18:02:27 +00:00
|
|
|
ExitTrafficHandlerFunc m_ExitTrafficHandler;
|
|
|
|
std::vector< ObtainedExitHandler > m_ObtainedExitHooks;
|
2018-09-24 11:36:47 +00:00
|
|
|
llarp_time_t m_LastRecvMessage = 0;
|
2018-06-26 16:23:43 +00:00
|
|
|
llarp_time_t m_LastLatencyTestTime = 0;
|
|
|
|
uint64_t m_LastLatencyTestID = 0;
|
2018-11-14 12:23:08 +00:00
|
|
|
uint64_t m_UpdateExitTX = 0;
|
|
|
|
uint64_t m_CloseExitTX = 0;
|
2018-11-14 18:02:27 +00:00
|
|
|
uint64_t m_ExitObtainTX = 0;
|
|
|
|
PathStatus _status;
|
|
|
|
PathRole _role;
|
2018-06-25 15:12:08 +00:00
|
|
|
};
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
enum PathBuildStatus
|
|
|
|
{
|
|
|
|
ePathBuildSuccess,
|
|
|
|
ePathBuildTimeout,
|
|
|
|
ePathBuildReject
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PathContext
|
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
PathContext(AbstractRouter* router);
|
2018-06-25 15:12:08 +00:00
|
|
|
~PathContext();
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
/// called from router tick function
|
|
|
|
void
|
2018-10-29 16:48:36 +00:00
|
|
|
ExpirePaths(llarp_time_t now);
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
|
|
|
AllowTransit();
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
|
|
|
RejectTransit();
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
AllowingTransit() const;
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
HasTransitHop(const TransitHopInfo& info);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleRelayCommit(const LR_CommitMessage& msg);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
2018-10-21 13:07:33 +00:00
|
|
|
PutTransitHop(std::shared_ptr< TransitHop > hop);
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
HopHandler_ptr
|
2018-06-25 15:12:08 +00:00
|
|
|
GetByUpstream(const RouterID& id, const PathID_t& path);
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2018-12-13 16:14:44 +00:00
|
|
|
bool
|
|
|
|
TransitHopPreviousIsRouter(const PathID_t& path, const RouterID& r);
|
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
HopHandler_ptr
|
2018-10-09 17:09:45 +00:00
|
|
|
GetPathForTransfer(const PathID_t& topath);
|
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
HopHandler_ptr
|
2018-06-25 15:12:08 +00:00
|
|
|
GetByDownstream(const RouterID& id, const PathID_t& path);
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
PathSet_ptr
|
2018-07-09 17:32:11 +00:00
|
|
|
GetLocalPathSet(const PathID_t& id);
|
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
routing::MessageHandler_ptr
|
2018-08-10 21:34:11 +00:00
|
|
|
GetHandler(const PathID_t& id);
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
|
|
|
ForwardLRCM(const RouterID& nextHop,
|
2018-08-30 18:48:43 +00:00
|
|
|
const std::array< EncryptedFrame, 8 >& frames);
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2018-12-10 17:22:59 +00:00
|
|
|
HopIsUs(const RouterID& k) const;
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleLRUM(const RelayUpstreamMessage& msg);
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
bool
|
2019-04-22 17:38:29 +00:00
|
|
|
HandleLRDM(const RelayDownstreamMessage& msg);
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
AddOwnPath(PathSet_ptr set, Path_ptr p);
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2018-08-18 14:01:21 +00:00
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
RemovePathSet(PathSet_ptr set);
|
2018-08-18 14:01:21 +00:00
|
|
|
|
2018-11-22 23:59:03 +00:00
|
|
|
using TransitHopsMap_t =
|
|
|
|
std::multimap< PathID_t, std::shared_ptr< TransitHop > >;
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2019-03-03 20:51:47 +00:00
|
|
|
struct SyncTransitMap_t
|
|
|
|
{
|
|
|
|
util::Mutex first; // protects second
|
|
|
|
TransitHopsMap_t second GUARDED_BY(first);
|
|
|
|
};
|
2018-06-19 17:11:24 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
// maps path id -> pathset owner of path
|
2019-04-23 14:28:59 +00:00
|
|
|
using OwnedPathsMap_t = std::map< PathID_t, PathSet_ptr >;
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2019-03-03 20:51:47 +00:00
|
|
|
struct SyncOwnedPathsMap_t
|
|
|
|
{
|
|
|
|
util::Mutex first; // protects second
|
|
|
|
OwnedPathsMap_t second GUARDED_BY(first);
|
|
|
|
};
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
llarp_threadpool*
|
|
|
|
Worker();
|
2018-06-15 14:33:38 +00:00
|
|
|
|
2018-12-11 00:53:11 +00:00
|
|
|
llarp::Crypto*
|
2019-04-28 17:33:27 +00:00
|
|
|
crypto();
|
2018-06-22 00:25:30 +00:00
|
|
|
|
2019-04-22 17:38:29 +00:00
|
|
|
Logic*
|
2019-04-28 15:57:41 +00:00
|
|
|
logic();
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter*
|
2018-06-25 15:12:08 +00:00
|
|
|
Router();
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2019-04-22 17:38:29 +00:00
|
|
|
const SecretKey&
|
2018-06-25 15:12:08 +00:00
|
|
|
EncryptionSecretKey();
|
2018-06-12 16:45:12 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
const byte_t*
|
|
|
|
OurRouterID() const;
|
|
|
|
|
|
|
|
private:
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* m_Router;
|
2018-06-25 15:12:08 +00:00
|
|
|
SyncTransitMap_t m_TransitPaths;
|
|
|
|
SyncOwnedPathsMap_t m_OurPaths;
|
|
|
|
bool m_AllowTransit;
|
|
|
|
};
|
|
|
|
} // namespace path
|
2018-06-18 22:03:50 +00:00
|
|
|
} // namespace llarp
|
2018-06-10 14:05:48 +00:00
|
|
|
|
2018-06-14 20:13:07 +00:00
|
|
|
#endif
|