make path latency tests work

pull/3/head
Jeff Becker 6 years ago
parent 5439947781
commit 92d1f50203
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -143,6 +143,7 @@ set(LIB_SRC
llarp/api/parser.cpp
llarp/routing/message_parser.cpp
llarp/routing/path_confirm.cpp
llarp/routing/path_latency.cpp
vendor/cppbackport-master/lib/fs/rename.cpp
vendor/cppbackport-master/lib/fs/filestatus.cpp
vendor/cppbackport-master/lib/fs/filetype.cpp

@ -528,8 +528,6 @@ sent inside a TDFM encrypted to the hidden service's public encryption key.
transfer data fragment message (TDFM)
variant 1 (with path id):
transfer data between paths.
{
@ -544,12 +542,12 @@ transfer data to another path with id P on the local router place Y and T values
into y and z values into a LRDM message (respectively) and send it in the
downstream direction.
variant 2 (no path id):
transfer ip traffic message (TITM)
transfer ip traffic for exit
{
A: "T",
A: "E",
V: 0,
X: "<N bytes ipv6 packet>",
Y: "<16 bytes nounce>",
@ -563,7 +561,7 @@ cannot be found or the signature is invalid this message is dropped, otherwise
the X value is sent on the appropriate exit network interface.
When we recieve an ip packet from the internet to an exit address, we put it
into a TDFM, signed with the exit info's signing key and send it downstream the
into a TITM, signed with the exit info's signing key and send it downstream the
corrisponding path in an LRDM.
update exit path message (UXPM)

@ -25,7 +25,7 @@ namespace llarp
BDecode(llarp_buffer_t* buf);
bool
HandleMessage(IMessageHandler* h) const;
HandleMessage(IMessageHandler* h, llarp_router* r) const;
};
} // namespace routing
} // namespace llarp

@ -20,7 +20,7 @@ namespace llarp
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val);
bool
HandleMessage(IMessageHandler* r) const;
HandleMessage(IMessageHandler* h, llarp_router* r) const;
};
} // namespace routing
} // namespace llarp

@ -0,0 +1,22 @@
#ifndef LLARP_MESSAGES_PATH_TRANSFER_HPP
#define LLARP_MESSAGES_PATH_TRANSFER_HPP
#include <llarp/crypto.hpp>
#include <llarp/encrypted.hpp>
#include <llarp/routing/message.hpp>
namespace llarp
{
namespace routing
{
struct PathTransferMessage : public IMessage
{
PathID_t P;
Encrypted T;
TunnelNonce Y;
};
} // namespace routing
} // namespace llarp
#endif

@ -112,9 +112,10 @@ namespace llarp
llarp_router* r) = 0;
};
struct TransitHop : public IHopHandler
struct TransitHop : public IHopHandler,
public llarp::routing::IMessageHandler
{
TransitHop() = default;
TransitHop();
TransitHop(const TransitHop& other);
@ -125,6 +126,8 @@ namespace llarp
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME;
llarp_proto_version_t version;
llarp::routing::InboundMessageParser m_MessageParser;
friend std::ostream&
operator<<(std::ostream& out, const TransitHop& h)
{
@ -135,9 +138,31 @@ namespace llarp
bool
Expired(llarp_time_t now) const;
// send routing message when end of path
bool
SendRoutingMessage(const llarp::routing::IMessage* msg, llarp_router* r);
// handle routing message when end of path
bool
HandleRoutingMessage(const llarp::routing::IMessage* msg,
llarp_router* r);
bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg,
llarp_router* r);
bool
HandlePathTransferMessage(const llarp::routing::PathTransferMessage* msg,
llarp_router* r);
bool
HandlePathLatencyMessage(const llarp::routing::PathLatencyMessage* msg,
llarp_router* r);
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);
@ -190,19 +215,25 @@ namespace llarp
SendRoutingMessage(const llarp::routing::IMessage* msg, llarp_router* r);
bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg);
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg,
llarp_router* r);
bool
HandlePathLatencyMessage(const llarp::routing::PathLatencyMessage* msg);
HandlePathLatencyMessage(const llarp::routing::PathLatencyMessage* msg,
llarp_router* r);
bool
HandleDHTMessage(const llarp::dht::IMessage* msg);
HandlePathTransferMessage(const llarp::routing::PathTransferMessage* msg,
llarp_router* r);
bool
HandleDHTMessage(const llarp::dht::IMessage* msg, llarp_router* r);
bool
HandleRoutingMessage(llarp_buffer_t buf, llarp_router* r);
bool
HandleHiddenServiceData(llarp_buffer_t buf);
HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r);
// handle data in upstream direction
bool
@ -223,11 +254,15 @@ namespace llarp
RouterID
Upstream() const;
llarp_time_t Latency = 0;
protected:
llarp::routing::InboundMessageParser m_InboundMessageParser;
private:
BuildResultHookFunc m_BuiltHook;
llarp_time_t m_LastLatencyTestTime = 0;
uint64_t m_LastLatencyTestID = 0;
};
enum PathBuildStatus

@ -2,28 +2,37 @@
#define LLARP_ROUTING_HANDLER_HPP
#include <llarp/buffer.h>
#include <llarp/router.h>
#include <llarp/dht.hpp>
#include <llarp/messages/path_confirm.hpp>
#include <llarp/messages/path_latency.hpp>
#include <llarp/messages/path_transfer.hpp>
namespace llarp
{
namespace routing
{
// handles messages on owned paths
// handles messages on the routing level
struct IMessageHandler
{
virtual bool
HandleHiddenServiceData(llarp_buffer_t buf) = 0;
HandlePathTransferMessage(const PathTransferMessage* msg,
llarp_router* r) = 0;
virtual bool
HandlePathConfirmMessage(const PathConfirmMessage* msg) = 0;
HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r) = 0;
virtual bool
HandlePathLatencyMessage(const PathLatencyMessage* msg) = 0;
HandlePathConfirmMessage(const PathConfirmMessage* msg,
llarp_router* r) = 0;
virtual bool
HandleDHTMessage(const llarp::dht::IMessage* msg) = 0;
HandlePathLatencyMessage(const PathLatencyMessage* msg,
llarp_router* r) = 0;
virtual bool
HandleDHTMessage(const llarp::dht::IMessage* msg, llarp_router* r) = 0;
};
} // namespace routing
} // namespace llarp

@ -17,14 +17,15 @@ namespace llarp
llarp::PathID_t from;
virtual bool
HandleMessage(IMessageHandler* r) const = 0;
HandleMessage(IMessageHandler* h, llarp_router* r) const = 0;
};
struct InboundMessageParser
{
InboundMessageParser();
bool
ParseMessageBuffer(llarp_buffer_t buf, IMessageHandler* handler);
ParseMessageBuffer(llarp_buffer_t buf, IMessageHandler* handler,
llarp_router* r);
private:
static bool

@ -340,7 +340,7 @@ namespace llarp
}
bool
Path::HandleHiddenServiceData(llarp_buffer_t buf)
Path::HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r)
{
// TODO: implement me
return false;
@ -349,7 +349,7 @@ namespace llarp
bool
Path::HandleRoutingMessage(llarp_buffer_t buf, llarp_router* r)
{
if(!m_InboundMessageParser.ParseMessageBuffer(buf, this))
if(!m_InboundMessageParser.ParseMessageBuffer(buf, this, r))
{
llarp::Warn("Failed to parse inbound routing message");
return false;
@ -374,9 +374,18 @@ namespace llarp
return HandleUpstream(buf, N, r);
}
bool
Path::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, llarp_router* r)
{
llarp::Warn("unwarrented path transfer message on tx=", TXID(),
" rx=", RXID());
return false;
}
bool
Path::HandlePathConfirmMessage(
const llarp::routing::PathConfirmMessage* msg)
const llarp::routing::PathConfirmMessage* msg, llarp_router* r)
{
if(status == ePathBuilding)
{
@ -386,7 +395,11 @@ namespace llarp
if(m_BuiltHook)
m_BuiltHook(this);
m_BuiltHook = nullptr;
return true;
llarp::routing::PathLatencyMessage latency;
latency.T = rand();
m_LastLatencyTestID = latency.T;
m_LastLatencyTestTime = llarp_time_now_ms();
return SendRoutingMessage(&latency, r);
}
llarp::Warn("got unwarrented path confirm message on rx=", RXID(),
" tx=", TXID());
@ -395,14 +408,19 @@ namespace llarp
bool
Path::HandlePathLatencyMessage(
const llarp::routing::PathLatencyMessage* msg)
const llarp::routing::PathLatencyMessage* msg, llarp_router* r)
{
// TODO: implement me
if(msg->L == m_LastLatencyTestID)
{
Latency = llarp_time_now_ms() - m_LastLatencyTestTime;
llarp::Info("path latency is ", Latency, " ms");
return true;
}
return false;
}
bool
Path::HandleDHTMessage(const llarp::dht::IMessage* msg)
Path::HandleDHTMessage(const llarp::dht::IMessage* msg, llarp_router* r)
{
// TODO: implement me
return false;

@ -21,20 +21,51 @@ namespace llarp
bool
RelayUpstreamMessage::BEncode(llarp_buffer_t *buf) const
{
// TODO: implement me
return false;
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "u"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt(buf, "v", LLARP_PROTO_VERSION))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
return false;
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayUpstreamMessage::HandleMessage(llarp_router *router) const
{
return false;
auto path = router->paths.GetByDownstream(remote, pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, router);
}
else
{
llarp::Warn("No such path downstream=", remote, " pathid=", pathid);
return false;
}
}
RelayDownstreamMessage::RelayDownstreamMessage(const RouterID &from)

@ -32,7 +32,7 @@ llarp_router::llarp_router()
: ready(false)
, paths(this)
, dht(llarp_dht_context_new(this))
, inbound_msg_parser(this)
, inbound_link_msg_parser(this)
, explorePool(llarp_pathbuilder_context_new(this, dht))
{
@ -49,7 +49,7 @@ bool
llarp_router::HandleRecvLinkMessage(llarp_link_session *session,
llarp_buffer_t buf)
{
return inbound_msg_parser.ProcessFrom(session, buf);
return inbound_link_msg_parser.ProcessFrom(session, buf);
}
bool

@ -14,6 +14,7 @@
#include <llarp/dht.hpp>
#include <llarp/link_message.hpp>
#include <llarp/routing/handler.hpp>
#include "crypto.hpp"
#include "fs.hpp"
@ -27,6 +28,11 @@ namespace llarp
llarp_ai addr;
};
// forward declare
namespace path
{
struct TransitHop;
}
} // namespace llarp
/// c++
@ -74,7 +80,8 @@ struct llarp_router
uint32_t ticker_job_id = 0;
llarp::InboundMessageParser inbound_msg_parser;
llarp::InboundMessageParser inbound_link_msg_parser;
llarp::routing::InboundMessageParser inbound_routing_msg_parser;
llarp_pathbuilder_select_hop_func selectHopFunc = nullptr;
llarp_pathbuilder_context *explorePool = nullptr;
@ -93,7 +100,7 @@ struct llarp_router
std::map< llarp::PubKey, llarp_link_establish_job > pendingEstablishJobs;
llarp_router();
~llarp_router();
virtual ~llarp_router();
bool
HandleRecvLinkMessage(struct llarp_link_session *from, llarp_buffer_t msg);
@ -174,9 +181,6 @@ struct llarp_router
void
Tick();
void
BuildExploritoryPath();
/// schedule ticker to call i ms from now
void
ScheduleTicker(uint64_t i = 1000);

@ -1,4 +1,5 @@
#include <llarp/messages/path_confirm.hpp>
#include <llarp/messages/path_latency.hpp>
#include <llarp/routing/message.hpp>
namespace llarp
@ -36,6 +37,9 @@ namespace llarp
return false;
switch(*strbuf.cur)
{
case 'L':
self->msg = new PathLatencyMessage;
break;
case 'P':
self->msg = new PathConfirmMessage;
break;
@ -53,14 +57,15 @@ namespace llarp
bool
InboundMessageParser::ParseMessageBuffer(llarp_buffer_t buf,
IMessageHandler* h)
IMessageHandler* h,
llarp_router* r)
{
bool result = false;
msg = nullptr;
firstKey = true;
if(bencode_read_dict(&buf, &reader))
{
result = msg->HandleMessage(h);
result = msg->HandleMessage(h, r);
delete msg;
}
else

@ -42,9 +42,9 @@ namespace llarp
}
bool
PathConfirmMessage::HandleMessage(IMessageHandler* h) const
PathConfirmMessage::HandleMessage(IMessageHandler* h, llarp_router* r) const
{
return h && h->HandlePathConfirmMessage(this);
return h && h->HandlePathConfirmMessage(this, r);
}
} // namespace routing

@ -1,4 +1,5 @@
#include <llarp/messages/path_latency.hpp>
#include <llarp/routing/handler.hpp>
namespace llarp
{
@ -7,5 +8,43 @@ namespace llarp
PathLatencyMessage::PathLatencyMessage()
{
}
bool
PathLatencyMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("L", L, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("T", T, read, key, val))
return false;
return read;
}
bool
PathLatencyMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "L"))
return false;
if(L)
{
if(!BEncodeWriteDictInt(buf, "L", L))
return false;
}
if(T)
{
if(!BEncodeWriteDictInt(buf, "T", T))
return false;
}
return bencode_end(buf);
}
bool
PathLatencyMessage::HandleMessage(IMessageHandler* h, llarp_router* r) const
{
return h && h->HandlePathLatencyMessage(this, r);
}
} // namespace routing
} // namespace llarp

@ -1,4 +1,5 @@
#include <llarp/path.hpp>
#include <llarp/routing/handler.hpp>
#include "buffer.hpp"
#include "router.hpp"
@ -6,6 +7,10 @@ namespace llarp
{
namespace path
{
TransitHop::TransitHop()
{
}
bool
TransitHop::Expired(llarp_time_t now) const
{
@ -76,15 +81,69 @@ namespace llarp
TransitHop::HandleUpstream(llarp_buffer_t buf, const TunnelNonce& Y,
llarp_router* r)
{
RelayUpstreamMessage* msg = new RelayUpstreamMessage;
msg->pathid = info.txID;
msg->Y = Y;
r->crypto.xchacha20(buf, pathKey, Y);
msg->X = buf;
llarp::Info("relay ", msg->X.size(), " bytes upstream from ",
info.downstream, " to ", info.upstream);
return r->SendToOrQueue(info.upstream, msg);
if(info.upstream == RouterID(r->pubkey()))
{
return m_MessageParser.ParseMessageBuffer(buf, this, r);
}
else
{
RelayUpstreamMessage* msg = new RelayUpstreamMessage;
msg->pathid = info.txID;
msg->Y = Y;
msg->X = buf;
llarp::Info("relay ", msg->X.size(), " bytes upstream from ",
info.downstream, " to ", info.upstream);
return r->SendToOrQueue(info.upstream, msg);
}
}
bool
TransitHop::HandleDHTMessage(const llarp::dht::IMessage* msg,
llarp_router* r)
{
// TODO: implement me
return false;
}
bool
TransitHop::HandlePathLatencyMessage(
const llarp::routing::PathLatencyMessage* msg, llarp_router* r)
{
llarp::routing::PathLatencyMessage reply;
reply.L = msg->T;
llarp::Info("got latency message ", msg->T);
return SendRoutingMessage(&reply, r);
}
bool
TransitHop::HandlePathConfirmMessage(
const llarp::routing::PathConfirmMessage* msg, llarp_router* r)
{
llarp::Warn("unwarrented path confirm message on ", info);
return false;
}
bool
TransitHop::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, llarp_router* r)
{
auto path = r->paths.GetByDownstream(r->pubkey(), msg->P);
if(path)
{
return path->HandleDownstream(msg->T.Buffer(), msg->Y, r);
}
llarp::Warn("No such path for path transfer pathid=", msg->P);
return false;
}
bool
TransitHop::HandleHiddenServiceData(llarp_buffer_t buf, llarp_router* r)
{
llarp::Warn("unwarrented hidden service data on ", info);
return false;
}
} // namespace path
} // namespace llarp

Loading…
Cancel
Save