format and logging

ignore outbound session auth messages
pull/1669/head
Jeff Becker 3 years ago
parent 5c3b4090d2
commit 71d17dc2c9
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -155,7 +155,7 @@ class Monitor:
def time_to(timestamp): def time_to(timestamp):
""" return time until timestamp in seconds formatted""" """ return time until timestamp in seconds formatted"""
if timestamp: if timestamp:
val = int((timestamp - now()) / 1000) val = (timestamp - now()) / 1000.0
if val < 0: if val < 0:
return "{} seconds ago".format(0-val) return "{} seconds ago".format(0-val)
else: else:

@ -397,10 +397,11 @@ namespace llarp
service::Address addr, auto msg, bool isV6) -> bool { service::Address addr, auto msg, bool isV6) -> bool {
using service::Address; using service::Address;
using service::OutboundContext; using service::OutboundContext;
if(HasInboundConvo(addr)) if (HasInboundConvo(addr))
{ {
// if we have an inbound convo to this address don't mark as outbound so we don't have a state race // if we have an inbound convo to this address don't mark as outbound so we don't have a
// this codepath is hit when an application verifies that reverse and forward dns records match for an inbound session // state race this codepath is hit when an application verifies that reverse and forward
// dns records match for an inbound session
SendDNSReply(addr, this, msg, reply, isV6); SendDNSReply(addr, this, msg, reply, isV6);
return true; return true;
} }

@ -420,9 +420,24 @@ namespace llarp
void void
Endpoint::PutSenderFor(const ConvoTag& tag, const ServiceInfo& info, bool inbound) Endpoint::PutSenderFor(const ConvoTag& tag, const ServiceInfo& info, bool inbound)
{ {
if (info.Addr().IsZero())
{
LogError(Name(), " cannot put invalid service info ", info, " T=", tag);
return;
}
auto itr = Sessions().find(tag); auto itr = Sessions().find(tag);
if (itr == Sessions().end() and not(WantsOutboundSession(info.Addr()) and inbound)) if (itr == Sessions().end())
{ {
if (WantsOutboundSession(info.Addr()) and inbound)
{
LogWarn(
Name(),
" not adding sender for ",
info.Addr(),
" session is inbound and we want outbound T=",
tag);
return;
}
itr = Sessions().emplace(tag, Session{}).first; itr = Sessions().emplace(tag, Session{}).first;
itr->second.inbound = inbound; itr->second.inbound = inbound;
itr->second.remote = info; itr->second.remote = info;
@ -1077,9 +1092,13 @@ namespace llarp
Endpoint::HandleDataMessage( Endpoint::HandleDataMessage(
path::Path_ptr path, const PathID_t from, std::shared_ptr<ProtocolMessage> msg) path::Path_ptr path, const PathID_t from, std::shared_ptr<ProtocolMessage> msg)
{ {
msg->sender.UpdateAddr();
PutSenderFor(msg->tag, msg->sender, true); PutSenderFor(msg->tag, msg->sender, true);
PutReplyIntroFor(msg->tag, msg->introReply); Introduction intro = msg->introReply;
if (HasInboundConvo(msg->sender.Addr()))
{
intro.pathID = from;
}
PutReplyIntroFor(msg->tag, intro);
ConvoTagRX(msg->tag); ConvoTagRX(msg->tag);
return ProcessDataMessage(msg); return ProcessDataMessage(msg);
} }
@ -1798,7 +1817,7 @@ namespace llarp
if (const auto maybe = GetBestConvoTagFor(remote)) if (const auto maybe = GetBestConvoTagFor(remote))
{ {
// the remote guy's intro // the remote guy's intro
Introduction remoteIntro; Introduction replyIntro;
SharedSecret K; SharedSecret K;
const auto tag = *maybe; const auto tag = *maybe;
@ -1807,20 +1826,20 @@ namespace llarp
LogError(Name(), " no cached key for inbound session from ", remote, " T=", tag); LogError(Name(), " no cached key for inbound session from ", remote, " T=", tag);
return false; return false;
} }
if (not GetReplyIntroFor(tag, remoteIntro)) if (not GetReplyIntroFor(tag, replyIntro))
{ {
LogError(Name(), "no reply intro for inbound session from ", remote, " T=", tag); LogError(Name(), "no reply intro for inbound session from ", remote, " T=", tag);
return false; return false;
} }
// get path for intro // get path for intro
auto p = GetPathByRouter(remoteIntro.router); auto p = GetPathByRouter(replyIntro.router);
if (not p) if (not p)
{ {
LogWarn( LogWarn(
Name(), Name(),
" has no path for intro router ", " has no path for intro router ",
RouterID{remoteIntro.router}, RouterID{replyIntro.router},
" for inbound convo T=", " for inbound convo T=",
tag); tag);
return false; return false;
@ -1847,8 +1866,8 @@ namespace llarp
return false; return false;
} }
f.S = m->seqno; f.S = m->seqno;
f.F = m->introReply.pathID; f.F = p->intro.pathID;
transfer->P = remoteIntro.pathID; transfer->P = replyIntro.pathID;
auto self = this; auto self = this;
Router()->QueueWork([transfer, p, m, K, self]() { Router()->QueueWork([transfer, p, m, K, self]() {
if (not transfer->T.EncryptAndSign(*m, K, self->m_Identity)) if (not transfer->T.EncryptAndSign(*m, K, self->m_Identity))

@ -367,9 +367,15 @@ namespace llarp
AuthResult result) { AuthResult result) {
if (result.code == AuthResultCode::eAuthAccepted) if (result.code == AuthResultCode::eAuthAccepted)
{ {
handler->PutSenderFor(msg->tag, msg->sender, true); if (handler->WantsOutboundSession(msg->sender.Addr()))
handler->PutIntroFor(msg->tag, msg->introReply); {
handler->PutReplyIntroFor(msg->tag, fromIntro); handler->PutSenderFor(msg->tag, msg->sender, false);
}
else
{
handler->PutSenderFor(msg->tag, msg->sender, true);
}
handler->PutReplyIntroFor(msg->tag, msg->introReply);
handler->PutCachedSessionKeyFor(msg->tag, sharedKey); handler->PutCachedSessionKeyFor(msg->tag, sharedKey);
handler->SendAuthResult(path, from, msg->tag, result); handler->SendAuthResult(path, from, msg->tag, result);
LogInfo("auth okay for T=", msg->tag, " from ", msg->sender.Addr()); LogInfo("auth okay for T=", msg->tag, " from ", msg->sender.Addr());

Loading…
Cancel
Save