add data discarded message in routing layer to indicate

a path no longer exists.
pull/15/head
Jeff Becker 6 years ago
parent baf2e1fb3c
commit a9b259985e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -456,7 +456,8 @@ always the first message sent
path latency message (PLM)
a latency measurement message, reply with a PLM response if we are the far end of a path.
a latency measurement message, reply with a PLM response if we are the far end
of a path.
variant 1, request, generated by the path creator:
@ -471,7 +472,7 @@ variant 2, response, generated by the endpoint that recieved the request.
{
A: "L",
S: uint64_sequence_number,
T: uint64_timestamp_sent,
T: uint64_timestamp_recieved,
V: 0
}
@ -534,6 +535,18 @@ B is set to a backoff value.
R contains additional metadata text describing why the exit was rejected.
discarded data fragment message (DDFM)
sent in reply to TDFM when we don't have a path locally or are doing network
congestion control. indcates a TDFM was discarded.
{
A: "D",
P: "<16 bytes path id>",
S: uint64_sequence_number_of_fragment_dropped,
V: 0
}
transfer data fragment message (TDFM)
transfer data between paths.
@ -542,13 +555,14 @@ transfer data between paths.
A: "T",
P: "<16 bytes path id>",
S: uint64_sequence_number,
T: message_transfered_between_paths,
T: hidden_service_frame,
V: 0
}
transfer data to another path with id P on the local router place a random 32 byte and T values
into y and z values into a LRDM message (respectively) and send it in the
downstream direction.
transfer data to another path with id P on the local router place a random 32
byte and T values into y and z values into a LRDM message (respectively) and
send it in the downstream direction. if this path does not exist on the router
it is replied to with a DDFM.

@ -1,7 +1,10 @@
#ifndef LLARP_MESSAGES_DISCARD_HPP
#define LLARP_MESSAGES_DISCARD_HPP
#include <llarp/link_message.hpp>
#include <llarp/routing/message.hpp>
#include <llarp/bencode.hpp>
#include <llarp/routing/handler.hpp>
namespace llarp
{
struct DiscardMessage : public ILinkMessage
@ -44,6 +47,64 @@ namespace llarp
return true;
}
};
namespace routing
{
struct DataDiscardMessage : public IMessage
{
PathID_t P;
DataDiscardMessage() : IMessage()
{
}
DataDiscardMessage(const PathID_t& src, const PathID_t& dst, uint64_t s)
: P(dst)
{
from = src;
S = s;
version = LLARP_PROTO_VERSION;
}
bool
HandleMessage(IMessageHandler* h, llarp_router* r) const
{
return h->HandleDataDiscardMessage(this, r);
}
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))
return false;
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
return false;
if(!BEncodeMaybeReadDictInt("V", version, read, k, buf))
return false;
return read;
}
bool
BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "A", "D"))
return false;
if(!BEncodeWriteDictEntry("P", P, buf))
return false;
if(!BEncodeWriteDictInt("S", S, buf))
return false;
if(!BEncodeWriteDictInt("V", version, buf))
return false;
return bencode_end(buf);
}
};
} // namespace routing
} // namespace llarp
#endif

@ -14,7 +14,6 @@ namespace llarp
{
PathID_t P;
service::ProtocolFrame T;
uint64_t V = 0;
TunnelNonce Y;
PathTransferMessage();
@ -38,4 +37,4 @@ namespace llarp
} // namespace routing
} // namespace llarp
#endif
#endif

@ -159,6 +159,10 @@ namespace llarp
HandleRoutingMessage(const llarp::routing::IMessage* msg,
llarp_router* r);
bool
HandleDataDiscardMessage(const llarp::routing::DataDiscardMessage* msg,
llarp_router* r);
bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg,
llarp_router* r);
@ -220,6 +224,8 @@ namespace llarp
struct Path : public IHopHandler, public llarp::routing::IMessageHandler
{
typedef std::function< void(Path*) > BuildResultHookFunc;
typedef std::function< bool(Path*, const PathID_t&, uint64_t) >
DropHandlerFunc;
typedef std::vector< PathHopConfig > HopList;
typedef std::function< bool(const service::ProtocolFrame*) >
DataHandlerFunc;
@ -242,6 +248,12 @@ namespace llarp
m_DataHandler = func;
}
void
SetDropHandler(DropHandlerFunc func)
{
m_DropHandler = func;
}
llarp_time_t
ExpireTime() const
{
@ -257,6 +269,10 @@ namespace llarp
bool
SendRoutingMessage(llarp::routing::IMessage* msg, llarp_router* r);
bool
HandleDataDiscardMessage(const llarp::routing::DataDiscardMessage* msg,
llarp_router* r);
bool
HandlePathConfirmMessage(const llarp::routing::PathConfirmMessage* msg,
llarp_router* r);
@ -312,6 +328,7 @@ namespace llarp
private:
BuildResultHookFunc m_BuiltHook;
DataHandlerFunc m_DataHandler;
DropHandlerFunc m_DropHandler;
llarp_time_t m_LastLatencyTestTime = 0;
uint64_t m_LastLatencyTestID = 0;
};

@ -7,15 +7,22 @@
#include <llarp/messages/path_confirm.hpp>
#include <llarp/messages/path_latency.hpp>
#include <llarp/messages/path_transfer.hpp>
namespace llarp
{
namespace routing
{
struct DataDiscardMessage;
// handles messages on the routing level
struct IMessageHandler
{
virtual bool
HandleDataDiscardMessage(const DataDiscardMessage *msg,
llarp_router *r) = 0;
virtual bool
HandlePathTransferMessage(const PathTransferMessage *msg,
llarp_router *r) = 0;
@ -36,4 +43,4 @@ namespace llarp
} // namespace routing
} // namespace llarp
#endif
#endif

@ -143,6 +143,9 @@ namespace llarp
}
};
bool
HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t s);
typedef std::queue< PendingBuffer > PendingBufferQueue;
/// context needed to initiate an outbound hidden service session
@ -151,6 +154,9 @@ namespace llarp
OutboundContext(const IntroSet& introSet, Endpoint* parent);
~OutboundContext();
bool
HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t s);
/// the remote hidden service's curren intro set
IntroSet currentIntroSet;
/// the current selected intro

@ -3,6 +3,7 @@
#include <llarp/path.hpp>
#include <llarp/pathbuilder.hpp>
#include <llarp/messages/dht.hpp>
#include <llarp/messages/discard.hpp>
#include "buffer.hpp"
#include "router.hpp"
@ -488,6 +489,15 @@ namespace llarp
return false;
}
bool
Path::HandleDataDiscardMessage(
const llarp::routing::DataDiscardMessage* msg, llarp_router* r)
{
if(m_DropHandler)
return m_DropHandler(this, msg->P, msg->S);
return true;
}
bool
Path::HandlePathConfirmMessage(
const llarp::routing::PathConfirmMessage* msg, llarp_router* r)

@ -2,6 +2,7 @@
#include <llarp/messages/path_confirm.hpp>
#include <llarp/messages/path_latency.hpp>
#include <llarp/messages/path_transfer.hpp>
#include <llarp/messages/discard.hpp>
#include <llarp/routing/message.hpp>
#include "mem.hpp"
@ -41,6 +42,9 @@ namespace llarp
self->key = *strbuf.cur;
switch(self->key)
{
case 'D':
self->msg = new DataDiscardMessage();
break;
case 'L':
self->msg = new PathLatencyMessage();
break;
@ -93,4 +97,4 @@ namespace llarp
return result;
}
} // namespace routing
} // namespace llarp
} // namespace llarp

@ -24,7 +24,7 @@ namespace llarp
return false;
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeReadDictInt("V", V, read, key, val))
if(!BEncodeMaybeReadDictInt("V", version, read, key, val))
return false;
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, val))
return false;

@ -11,7 +11,7 @@ namespace llarp
namespace service
{
Endpoint::Endpoint(const std::string& name, llarp_router* r)
: path::Builder(r, r->dht, 2, 4), m_Router(r), m_Name(name)
: path::Builder(r, r->dht, 4, 4), m_Router(r), m_Name(name)
{
m_Tag.Zero();
}
@ -645,9 +645,45 @@ namespace llarp
{
p->SetDataHandler(std::bind(&Endpoint::HandleHiddenServiceFrame, this,
std::placeholders::_1));
p->SetDropHandler(std::bind(&Endpoint::HandleDataDrop, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3));
RegenAndPublishIntroSet(llarp_time_now_ms());
}
bool
Endpoint::HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t seq)
{
llarp::LogWarn(Name(), " message ", seq, " dropped by endpoint ",
p->Endpoint(), " via ", dst);
return true;
}
bool
Endpoint::OutboundContext::HandleDataDrop(path::Path* p,
const PathID_t& dst, uint64_t seq)
{
llarp::LogWarn(Name(), " message ", seq, " dropped by endpoint ",
p->Endpoint(), " via ", dst);
// pick another intro
if(selectedIntro.router == p->Endpoint() && selectedIntro.pathID == dst)
{
auto now = llarp_time_now_ms();
for(const auto& intro : currentIntroSet.I)
{
if(intro.ExpiresSoon(now))
continue;
if(intro.pathID != dst && intro.router != p->Endpoint())
{
selectedIntro = intro;
return true;
}
}
llarp::LogError(Name(), " has no more usable intros");
}
return true;
}
bool
Endpoint::HandleHiddenServiceFrame(const ProtocolFrame* frame)
{
@ -661,6 +697,9 @@ namespace llarp
p->SetDataHandler(
std::bind(&Endpoint::OutboundContext::HandleHiddenServiceFrame, this,
std::placeholders::_1));
p->SetDropHandler(std::bind(
&Endpoint::OutboundContext::HandleDataDrop, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
bool
@ -751,6 +790,7 @@ namespace llarp
if(i && addr == i->A.Addr() && currentIntroSet.OtherIsNewer(*i))
{
currentIntroSet = *i;
ShiftIntroduction();
}
return true;
}
@ -796,15 +836,18 @@ namespace llarp
void
Endpoint::OutboundContext::ShiftIntroduction()
{
bool shifted = false;
for(const auto& intro : currentIntroSet.I)
{
m_Parent->EnsureRouterIsKnown(selectedIntro.router);
if(intro.expiresAt > selectedIntro.expiresAt)
{
selectedIntro = intro;
shifted = true;
}
}
ManualRebuild(1);
if(shifted)
ManualRebuild(1);
}
void

@ -1,5 +1,6 @@
#include <llarp/path.hpp>
#include <llarp/routing/handler.hpp>
#include <llarp/messages/discard.hpp>
#include "buffer.hpp"
#include "router.hpp"
@ -135,6 +136,14 @@ namespace llarp
return false;
}
bool
TransitHop::HandleDataDiscardMessage(
const llarp::routing::DataDiscardMessage* msg, llarp_router* r)
{
llarp::LogWarn("unwarranted path data discard message on ", info);
return false;
}
bool
TransitHop::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, llarp_router* r)

Loading…
Cancel
Save