mirror of https://github.com/oxen-io/lokinet
ALMOST got path building working
parent
50402820e1
commit
39c63432be
@ -0,0 +1,30 @@
|
||||
#ifndef LLARP_MESSAGE_PATH_CONFIRM_HPP
|
||||
#define LLARP_MESSAGE_PATH_CONFIRM_HPP
|
||||
|
||||
#include <llarp/routing_message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
struct PathConfirmMessage : public IMessage
|
||||
{
|
||||
uint64_t pathLifetime;
|
||||
uint64_t pathCreated;
|
||||
|
||||
PathConfirmMessage(uint64_t lifetime);
|
||||
~PathConfirmMessage(){};
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const;
|
||||
|
||||
bool
|
||||
BDecode(llarp_buffer_t* buf);
|
||||
|
||||
bool
|
||||
HandleMessage(llarp_router* r) const;
|
||||
};
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
#ifndef LLARP_ROUTING_MESSAGE_HPP
|
||||
#define LLARP_ROUTING_MESSAGE_HPP
|
||||
|
||||
#include <llarp/buffer.h>
|
||||
#include <llarp/router.h>
|
||||
#include <llarp/path_types.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
struct IMessage
|
||||
{
|
||||
llarp::PathID_t from;
|
||||
|
||||
virtual ~IMessage(){};
|
||||
|
||||
virtual bool
|
||||
BEncode(llarp_buffer_t* buf) const = 0;
|
||||
|
||||
virtual bool
|
||||
BDecode(llarp_buffer_t* buf) = 0;
|
||||
|
||||
virtual bool
|
||||
HandleMessage(llarp_router* r) const = 0;
|
||||
};
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,41 @@
|
||||
#include <llarp/time.h>
|
||||
#include <llarp/bencode.hpp>
|
||||
#include <llarp/messages/path_confirm.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
PathConfirmMessage::PathConfirmMessage(uint64_t lifetime)
|
||||
: pathLifetime(lifetime), pathCreated(llarp_time_now_ms())
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
PathConfirmMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictMsgType(buf, "A", "P"))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt(buf, "L", pathLifetime))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt(buf, "S", pathCreated))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
PathConfirmMessage::BDecode(llarp_buffer_t* buf)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
PathConfirmMessage::HandleMessage(llarp_router* r) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
@ -0,0 +1,84 @@
|
||||
#include <llarp/path.hpp>
|
||||
#include "buffer.hpp"
|
||||
#include "router.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
bool
|
||||
TransitHop::Expired(llarp_time_t now) const
|
||||
{
|
||||
return now - started > lifetime;
|
||||
}
|
||||
|
||||
TransitHopInfo::TransitHopInfo(const TransitHopInfo& other)
|
||||
: pathID(other.pathID)
|
||||
, upstream(other.upstream)
|
||||
, downstream(other.downstream)
|
||||
{
|
||||
}
|
||||
|
||||
TransitHopInfo::TransitHopInfo(const RouterID& down,
|
||||
const LR_CommitRecord& record)
|
||||
: pathID(record.pathid), upstream(record.nextHop), downstream(down)
|
||||
{
|
||||
}
|
||||
|
||||
TransitHop::TransitHop(const TransitHop& other)
|
||||
: info(other.info)
|
||||
, pathKey(other.pathKey)
|
||||
, started(other.started)
|
||||
, lifetime(other.lifetime)
|
||||
, version(other.version)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
TransitHop::SendRoutingMessage(const llarp::routing::IMessage* msg,
|
||||
llarp_router* r)
|
||||
{
|
||||
byte_t tmp[MAX_LINK_MSG_SIZE / 2];
|
||||
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
||||
if(!msg->BEncode(&buf))
|
||||
{
|
||||
llarp::Error("failed to encode routing message");
|
||||
return false;
|
||||
}
|
||||
TunnelNonce N;
|
||||
N.Randomize();
|
||||
// rewind
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
return HandleDownstream(buf, N, r);
|
||||
}
|
||||
|
||||
bool
|
||||
TransitHop::HandleDownstream(llarp_buffer_t buf, const TunnelNonce& Y,
|
||||
llarp_router* r)
|
||||
{
|
||||
RelayDownstreamMessage* msg = new RelayDownstreamMessage;
|
||||
msg->pathid = info.rxID;
|
||||
msg->Y = Y;
|
||||
|
||||
r->crypto.xchacha20(buf, pathKey, Y);
|
||||
msg->X = buf;
|
||||
llarp::Info("relay ", msg->X.size(), " bytes downstream from ",
|
||||
info.upstream, " to ", info.downstream);
|
||||
return r->SendToOrQueue(info.downstream, msg);
|
||||
}
|
||||
|
||||
bool
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace llarp
|
Loading…
Reference in New Issue