mirror of https://github.com/oxen-io/lokinet
* implement path transfer message
* update dht docs * update other docs * start working on dht for hidden services * fix up unit tests for dht * update makefile and other build filespull/5/head
parent
7d9bffdf9c
commit
18b50f4a74
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef LLARP_MESSAGES_DHT_HPP
|
||||||
|
#define LLARP_MESSAGES_DHT_HPP
|
||||||
|
#include <llarp/dht.hpp>
|
||||||
|
#include <llarp/routing/message.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace routing
|
||||||
|
{
|
||||||
|
struct DHTMessage : public IMessage
|
||||||
|
{
|
||||||
|
std::vector< llarp::dht::IMessage* > M;
|
||||||
|
uint64_t V = 0;
|
||||||
|
|
||||||
|
~DHTMessage();
|
||||||
|
|
||||||
|
bool
|
||||||
|
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val);
|
||||||
|
|
||||||
|
bool
|
||||||
|
BEncode(llarp_buffer_t* buf) const;
|
||||||
|
|
||||||
|
bool
|
||||||
|
HandleMessage(IMessageHandler* h, llarp_router* r) const;
|
||||||
|
};
|
||||||
|
} // namespace routing
|
||||||
|
} // namespace llarp
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,61 @@
|
|||||||
|
#include <llarp/messages/dht.hpp>
|
||||||
|
#include "../router.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace routing
|
||||||
|
{
|
||||||
|
DHTMessage::~DHTMessage()
|
||||||
|
{
|
||||||
|
for(auto& msg : M)
|
||||||
|
delete msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DHTMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
|
||||||
|
{
|
||||||
|
llarp::dht::Key_t from;
|
||||||
|
from.Zero();
|
||||||
|
if(llarp_buffer_eq(key, "M"))
|
||||||
|
{
|
||||||
|
return llarp::dht::DecodeMesssageList(from, val, M);
|
||||||
|
}
|
||||||
|
else if(llarp_buffer_eq(key, "V"))
|
||||||
|
{
|
||||||
|
return bencode_read_integer(val, &V);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DHTMessage::BEncode(llarp_buffer_t* buf) const
|
||||||
|
{
|
||||||
|
if(!bencode_start_dict(buf))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!BEncodeWriteDictMsgType(buf, "A", "M"))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictBEncodeList("M", M, buf))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictInt(buf, "V", LLARP_PROTO_VERSION))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return bencode_end(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DHTMessage::HandleMessage(IMessageHandler* h, llarp_router* r) const
|
||||||
|
{
|
||||||
|
// set source as us
|
||||||
|
llarp::dht::Key_t us = r->pubkey();
|
||||||
|
for(auto& msg : M)
|
||||||
|
{
|
||||||
|
msg->From = us;
|
||||||
|
if(!r->dht->impl.RelayRequestForPath(from, msg))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace routing
|
||||||
|
} // namespace llarp
|
@ -0,0 +1,65 @@
|
|||||||
|
#include <llarp/messages/path_transfer.hpp>
|
||||||
|
#include "../router.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace routing
|
||||||
|
{
|
||||||
|
PathTransferMessage::PathTransferMessage() : IMessage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PathTransferMessage::~PathTransferMessage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PathTransferMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
|
||||||
|
{
|
||||||
|
bool read = false;
|
||||||
|
if(!BEncodeMaybeReadDictEntry("P", P, read, key, val))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeMaybeReadDictInt("V", V, read, key, val))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
|
||||||
|
return false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PathTransferMessage::BEncode(llarp_buffer_t* buf) const
|
||||||
|
{
|
||||||
|
if(!bencode_start_dict(buf))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictMsgType(buf, "A", "T"))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictEntry("P", P, buf))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictEntry("T", T, buf))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictInt(buf, "V", LLARP_PROTO_VERSION))
|
||||||
|
return false;
|
||||||
|
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return bencode_end(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PathTransferMessage::HandleMessage(IMessageHandler* h,
|
||||||
|
llarp_router* r) const
|
||||||
|
{
|
||||||
|
auto path = r->paths.GetByUpstream(r->pubkey(), P);
|
||||||
|
if(path)
|
||||||
|
{
|
||||||
|
return path->HandleDownstream(T.Buffer(), Y, r);
|
||||||
|
}
|
||||||
|
llarp::Warn("No such local path for path transfer src=", from,
|
||||||
|
" dst=", P);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace routing
|
||||||
|
|
||||||
|
} // namespace llarp
|
Loading…
Reference in New Issue