mirror of https://github.com/oxen-io/lokinet
onion routing downstream traffic relaying works on testnet
parent
2f8cde8e07
commit
f2c42e4e5a
@ -0,0 +1,14 @@
|
||||
#ifndef LLARP_ROUTING_HANDLER_HPP
|
||||
#define LLARP_ROUTING_HANDLER_HPP
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
struct IMessageHandler
|
||||
{
|
||||
};
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,46 @@
|
||||
#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 IMessageHandler;
|
||||
|
||||
struct IMessage
|
||||
{
|
||||
llarp::PathID_t from;
|
||||
|
||||
virtual ~IMessage(){};
|
||||
|
||||
virtual bool
|
||||
BEncode(llarp_buffer_t* buf) const = 0;
|
||||
|
||||
virtual bool
|
||||
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) = 0;
|
||||
|
||||
virtual bool
|
||||
HandleMessage(IMessageHandler* r) const = 0;
|
||||
};
|
||||
|
||||
struct InboundMessageParser
|
||||
{
|
||||
InboundMessageParser();
|
||||
bool
|
||||
ParseMessageBuffer(llarp_buffer_t buf, IMessageHandler* handler);
|
||||
|
||||
private:
|
||||
static bool
|
||||
OnKey(dict_reader* r, llarp_buffer_t* key);
|
||||
bool firstKey;
|
||||
dict_reader reader;
|
||||
IMessage* msg;
|
||||
};
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -1,30 +0,0 @@
|
||||
#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,69 @@
|
||||
#include <llarp/messages/path_confirm.hpp>
|
||||
#include <llarp/routing/message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
InboundMessageParser::InboundMessageParser()
|
||||
{
|
||||
reader.user = this;
|
||||
reader.on_key = &OnKey;
|
||||
firstKey = false;
|
||||
}
|
||||
|
||||
bool
|
||||
InboundMessageParser::OnKey(dict_reader* r, llarp_buffer_t* key)
|
||||
{
|
||||
InboundMessageParser* self =
|
||||
static_cast< InboundMessageParser* >(r->user);
|
||||
|
||||
if(key == nullptr && self->firstKey)
|
||||
{
|
||||
// empty dict
|
||||
return false;
|
||||
}
|
||||
if(!key)
|
||||
return true;
|
||||
if(self->firstKey)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
if(!llarp_buffer_eq(*key, "A"))
|
||||
return false;
|
||||
if(!bencode_read_string(r->buffer, &strbuf))
|
||||
return false;
|
||||
if(strbuf.sz != 1)
|
||||
return false;
|
||||
switch(*strbuf.cur)
|
||||
{
|
||||
case 'P':
|
||||
self->msg = new PathConfirmMessage;
|
||||
break;
|
||||
default:
|
||||
llarp::Error("invalid routing message id: ", *strbuf.cur);
|
||||
}
|
||||
self->firstKey = false;
|
||||
return self->msg != nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return self->msg->DecodeKey(*key, r->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
InboundMessageParser::ParseMessageBuffer(llarp_buffer_t buf,
|
||||
IMessageHandler* h)
|
||||
{
|
||||
bool result = false;
|
||||
msg = nullptr;
|
||||
firstKey = true;
|
||||
if(bencode_read_dict(&buf, &reader))
|
||||
{
|
||||
result = msg->HandleMessage(h);
|
||||
delete msg;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
Loading…
Reference in New Issue