squash commits and make convotags more "reliable" (probably)

pull/333/head
Jeff Becker 5 years ago
parent 5dde4e6351
commit eecc00211f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -639,7 +639,7 @@ sent inside a HSFM encrypted with a shared secret.
n: uint_message_sequence_number, n: uint_message_sequence_number,
o: N seconds until this converstation plans terminate, o: N seconds until this converstation plans terminate,
s: SI of sender, s: SI of sender,
t: "<16 bytes converstation tag present only when n is 0>", t: "<16 bytes converstation_tag>,
v: 0 v: 0
} }

@ -32,6 +32,7 @@ set(LIB_UTIL_SRC
add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC}) add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC})
target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
# cut back on fluff # cut back on fluff
if (NOT WIN32) if (NOT WIN32)

@ -491,6 +491,28 @@ namespace llarp
return true; return true;
} }
void
Endpoint::PutReplyIntroFor(const ConvoTag& tag, const Introduction& intro)
{
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
{
itr = m_Sessions.emplace(tag, Session{}).first;
}
itr->second.replyIntro = intro;
itr->second.lastUsed = Now();
}
bool
Endpoint::GetReplyIntroFor(const ConvoTag& tag, Introduction& intro) const
{
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
return false;
intro = itr->second.replyIntro;
return true;
}
bool bool
Endpoint::GetConvoTagsForService(const ServiceInfo& info, Endpoint::GetConvoTagsForService(const ServiceInfo& info,
std::set< ConvoTag >& tags) const std::set< ConvoTag >& tags) const
@ -898,11 +920,10 @@ namespace llarp
Endpoint::HandleDataMessage(const PathID_t& src, ProtocolMessage* msg) Endpoint::HandleDataMessage(const PathID_t& src, ProtocolMessage* msg)
{ {
auto path = GetPathByID(src); auto path = GetPathByID(src);
if(path == nullptr) if(path)
return false; PutReplyIntroFor(msg->tag, path->intro);
msg->sender.UpdateAddr(); msg->sender.UpdateAddr();
PutIntroFor(msg->tag, msg->introReply); PutIntroFor(msg->tag, msg->introReply);
PutSenderFor(msg->tag, path->intro);
EnsureReplyPath(msg->sender); EnsureReplyPath(msg->sender);
return ProcessDataMessage(msg); return ProcessDataMessage(msg);
} }
@ -1277,7 +1298,8 @@ namespace llarp
ProtocolMessage m(f.T); ProtocolMessage m(f.T);
m.proto = t; m.proto = t;
m.introReply = p->intro; m.introReply = p->intro;
m.sender = m_Identity.pub; PutReplyIntroFor(f.T, m.introReply);
m.sender = m_Identity.pub;
m.PutBuffer(data); m.PutBuffer(data);
f.N.Randomize(); f.N.Randomize();
f.S = GetSeqNoForConvo(f.T); f.S = GetSeqNoForConvo(f.T);
@ -1611,11 +1633,12 @@ namespace llarp
ex->msg.PutBuffer(payload); ex->msg.PutBuffer(payload);
ex->msg.introReply = path->intro; ex->msg.introReply = path->intro;
m_DataHandler->PutReplyIntroFor(currentConvoTag, path->intro);
llarp_threadpool_queue_job(m_Endpoint->Worker(), llarp_threadpool_queue_job(m_Endpoint->Worker(),
{ex, &AsyncKeyExchange::Encrypt}); {ex, &AsyncKeyExchange::Encrypt});
} }
void bool
Endpoint::SendContext::Send(ProtocolFrame& msg) Endpoint::SendContext::Send(ProtocolFrame& msg)
{ {
auto path = m_PathSet->GetPathByRouter(remoteIntro.router); auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
@ -1630,6 +1653,7 @@ namespace llarp
remoteIntro.router); remoteIntro.router);
lastGoodSend = m_Endpoint->Now(); lastGoodSend = m_Endpoint->Now();
++sequenceNo; ++sequenceNo;
return true;
} }
else else
llarp::LogError("Failed to send frame on path"); llarp::LogError("Failed to send frame on path");
@ -1637,6 +1661,7 @@ namespace llarp
else else
llarp::LogError("cannot send because we have no path to ", llarp::LogError("cannot send because we have no path to ",
remoteIntro.router); remoteIntro.router);
return false;
} }
std::string std::string
@ -1843,8 +1868,12 @@ namespace llarp
if(m_DataHandler->GetCachedSessionKeyFor(f.T, shared)) if(m_DataHandler->GetCachedSessionKeyFor(f.T, shared))
{ {
ProtocolMessage m; ProtocolMessage m;
m.proto = t; m.proto = t;
m.introReply = path->intro; if(!m_DataHandler->GetReplyIntroFor(f.T, m.introReply))
{
m_DataHandler->PutReplyIntroFor(f.T, path->intro);
m.introReply = path->intro;
}
m_DataHandler->PutIntroFor(f.T, remoteIntro); m_DataHandler->PutIntroFor(f.T, remoteIntro);
m.sender = m_Endpoint->m_Identity.pub; m.sender = m_Endpoint->m_Identity.pub;
m.PutBuffer(payload); m.PutBuffer(payload);
@ -1864,11 +1893,11 @@ namespace llarp
msg.P = remoteIntro.pathID; msg.P = remoteIntro.pathID;
msg.Y.Randomize(); msg.Y.Randomize();
++sequenceNo;
if(path->SendRoutingMessage(&msg, m_Endpoint->Router())) if(path->SendRoutingMessage(&msg, m_Endpoint->Router()))
{ {
llarp::LogDebug("sent message via ", remoteIntro.pathID, " on ", llarp::LogDebug("sent message via ", remoteIntro.pathID, " on ",
remoteIntro.router); remoteIntro.router);
++sequenceNo;
lastGoodSend = now; lastGoodSend = now;
} }
else else

@ -221,7 +221,7 @@ namespace llarp
/// send a fully encrypted hidden service frame /// send a fully encrypted hidden service frame
/// via a path on our pathset with path id p /// via a path on our pathset with path id p
void bool
Send(ProtocolFrame& f); Send(ProtocolFrame& f);
llarp::SharedSecret sharedKey; llarp::SharedSecret sharedKey;
@ -390,6 +390,14 @@ namespace llarp
bool bool
GetIntroFor(const ConvoTag& remote, Introduction& intro) const override; GetIntroFor(const ConvoTag& remote, Introduction& intro) const override;
void
PutReplyIntroFor(const ConvoTag& remote,
const Introduction& intro) override;
bool
GetReplyIntroFor(const ConvoTag& remote,
Introduction& intro) const override;
bool bool
GetConvoTagsForService(const ServiceInfo& si, GetConvoTagsForService(const ServiceInfo& si,
std::set< ConvoTag >& tag) const override; std::set< ConvoTag >& tag) const override;
@ -540,6 +548,7 @@ namespace llarp
struct Session : public util::IStateful struct Session : public util::IStateful
{ {
Introduction replyIntro;
SharedSecret sharedKey; SharedSecret sharedKey;
ServiceInfo remote; ServiceInfo remote;
Introduction intro; Introduction intro;
@ -550,9 +559,10 @@ namespace llarp
ExtractStatus() const override ExtractStatus() const override
{ {
util::StatusObject obj{{"lastUsed", lastUsed}, util::StatusObject obj{{"lastUsed", lastUsed},
{"replyIntro", replyIntro.ExtractStatus()},
{"remote", remote.Addr().ToString()}, {"remote", remote.Addr().ToString()},
{"seqno", seqno}}; {"seqno", seqno},
obj.Put("intro", intro.ExtractStatus()); {"intro", intro.ExtractStatus()}};
return obj; return obj;
}; };

@ -37,6 +37,12 @@ namespace llarp
virtual bool virtual bool
GetIntroFor(const ConvoTag& remote, Introduction& intro) const = 0; GetIntroFor(const ConvoTag& remote, Introduction& intro) const = 0;
virtual void
PutReplyIntroFor(const ConvoTag& remote, const Introduction& intro) = 0;
virtual bool
GetReplyIntroFor(const ConvoTag& remote, Introduction& intro) const = 0;
virtual bool virtual bool
GetConvoTagsForService(const ServiceInfo& si, GetConvoTagsForService(const ServiceInfo& si,
std::set< ConvoTag >& tag) const = 0; std::set< ConvoTag >& tag) const = 0;

Loading…
Cancel
Save