differentiate between inbound and outbound convos

pull/686/head
Jeff Becker 5 years ago
parent 227f561ffc
commit a323003824
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -34,7 +34,7 @@ namespace llarp
// put values
self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey);
self->handler->PutIntroFor(self->msg.tag, self->remoteIntro);
self->handler->PutSenderFor(self->msg.tag, self->remote);
self->handler->PutSenderFor(self->msg.tag, self->remote, false);
self->handler->PutReplyIntroFor(self->msg.tag, self->msg.introReply);
self->hook(self->frame);
delete self;

@ -389,8 +389,20 @@ namespace llarp
return true;
}
bool
Endpoint::HasInboundConvo(const Address& addr) const
{
for(const auto& item : m_Sessions)
{
if(item.second.remote.Addr() == addr && item.second.inbound)
return true;
}
return false;
}
void
Endpoint::PutSenderFor(const ConvoTag& tag, const ServiceInfo& info)
Endpoint::PutSenderFor(const ConvoTag& tag, const ServiceInfo& info,
bool inbound)
{
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
@ -398,6 +410,7 @@ namespace llarp
itr = m_Sessions.emplace(tag, Session{}).first;
}
itr->second.remote = info;
itr->second.inbound = inbound;
itr->second.lastUsed = Now();
}
@ -417,7 +430,7 @@ namespace llarp
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
{
itr = m_Sessions.emplace(tag, Session{}).first;
return;
}
itr->second.intro = intro;
itr->second.lastUsed = Now();
@ -439,7 +452,7 @@ namespace llarp
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
{
itr = m_Sessions.emplace(tag, Session{}).first;
return;
}
itr->second.replyIntro = intro;
itr->second.lastUsed = Now();
@ -456,10 +469,10 @@ namespace llarp
}
bool
Endpoint::GetConvoTagsForService(const ServiceInfo& info,
Endpoint::GetConvoTagsForService(const Address& addr,
std::set< ConvoTag >& tags) const
{
return EndpointUtil::GetConvoTagsForService(m_Sessions, info, tags);
return EndpointUtil::GetConvoTagsForService(m_Sessions, addr, tags);
}
bool
@ -829,11 +842,11 @@ namespace llarp
{
msg->sender.UpdateAddr();
auto path = GetPathByID(src);
if(path)
PutReplyIntroFor(msg->tag, path->intro);
PutSenderFor(msg->tag, msg->sender);
if(path == nullptr)
return false;
PutReplyIntroFor(msg->tag, path->intro);
PutSenderFor(msg->tag, msg->sender, true);
PutIntroFor(msg->tag, msg->introReply);
EnsureReplyPath(msg->sender);
return ProcessDataMessage(msg);
}
@ -1083,66 +1096,64 @@ namespace llarp
// inbound converstation
auto now = Now();
if(HasInboundConvo(remote))
{
auto itr = m_AddressToService.find(remote);
if(itr != m_AddressToService.end())
auto transfer = std::make_shared< routing::PathTransferMessage >();
ProtocolFrame& f = transfer->T;
std::shared_ptr< path::Path > p;
std::set< ConvoTag > tags;
if(GetConvoTagsForService(remote, tags))
{
auto transfer = std::make_shared< routing::PathTransferMessage >();
ProtocolFrame& f = transfer->T;
std::shared_ptr< path::Path > p;
std::set< ConvoTag > tags;
if(GetConvoTagsForService(itr->second, tags))
Introduction remoteIntro;
SharedSecret K;
// pick tag
for(const auto& tag : tags)
{
Introduction remoteIntro;
SharedSecret K;
// pick tag
for(const auto& tag : tags)
if(tag.IsZero())
continue;
if(!GetCachedSessionKeyFor(tag, K))
continue;
if(GetIntroFor(tag, remoteIntro))
{
if(tag.IsZero())
continue;
if(!GetCachedSessionKeyFor(tag, K))
continue;
if(GetIntroFor(tag, remoteIntro))
if(!remoteIntro.ExpiresSoon(now))
p = GetNewestPathByRouter(remoteIntro.router);
if(p)
{
if(!remoteIntro.ExpiresSoon(now))
p = GetNewestPathByRouter(remoteIntro.router);
if(p)
{
f.T = tag;
}
f.T = tag;
}
}
if(p)
}
if(p)
{
// TODO: check expiration of our end
ProtocolMessage m(f.T);
m.PutBuffer(data);
f.N.Randomize();
f.C.Zero();
transfer->Y.Randomize();
m.proto = t;
m.introReply = p->intro;
PutReplyIntroFor(f.T, m.introReply);
m.sender = m_Identity.pub;
m.seqno = GetSeqNoForConvo(f.T);
f.S = 1;
f.F = m.introReply.pathID;
transfer->P = remoteIntro.pathID;
if(!f.EncryptAndSign(m, K, m_Identity))
{
// TODO: check expiration of our end
ProtocolMessage m(f.T);
m.PutBuffer(data);
f.N.Randomize();
f.C.Zero();
transfer->Y.Randomize();
m.proto = t;
m.introReply = p->intro;
PutReplyIntroFor(f.T, m.introReply);
m.sender = m_Identity.pub;
m.seqno = GetSeqNoForConvo(f.T);
f.S = 1;
f.F = m.introReply.pathID;
transfer->P = remoteIntro.pathID;
if(!f.EncryptAndSign(m, K, m_Identity))
{
LogError("failed to encrypt and sign");
return false;
}
LogDebug(Name(), " send ", data.sz, " via ", remoteIntro.router);
{
util::Lock lock(&m_SendQueueMutex);
m_SendQueue.emplace_back(transfer, p);
}
return true;
LogError("failed to encrypt and sign");
return false;
}
LogDebug(Name(), " send ", data.sz, " via ", remoteIntro.router);
{
util::Lock lock(&m_SendQueueMutex);
m_SendQueue.emplace_back(transfer, p);
}
return true;
}
}
}
// outbound converstation
if(EndpointUtil::HasPathToService(remote, m_RemoteSessions))
{
@ -1174,12 +1185,6 @@ namespace llarp
5000, true);
}
void
Endpoint::EnsureReplyPath(const ServiceInfo& ident)
{
m_AddressToService[ident.Addr()] = ident;
}
bool
Endpoint::HasConvoTag(const ConvoTag& t) const
{

@ -130,9 +130,6 @@ namespace llarp
void
HandlePathDied(path::Path_ptr p) override;
void
EnsureReplyPath(const ServiceInfo& addr);
bool
PublishIntroSet(AbstractRouter* r) override;
@ -258,7 +255,11 @@ namespace llarp
HasPathToSNode(const RouterID& remote) const;
void
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info) override;
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info,
bool inbound) override;
bool
HasInboundConvo(const Address& addr) const override;
bool
GetCachedSessionKeyFor(const ConvoTag& remote,
@ -288,7 +289,7 @@ namespace llarp
Introduction& intro) const override;
bool
GetConvoTagsForService(const ServiceInfo& si,
GetConvoTagsForService(const Address& si,
std::set< ConvoTag >& tag) const override;
void
@ -457,10 +458,9 @@ namespace llarp
Sessions m_RemoteSessions;
Sessions m_DeadSessions;
SNodeSessions m_SNodeSessions;
std::set< ConvoTag > m_InboundConvos;
std::unordered_map< Address, ServiceInfo, Address::Hash >
m_AddressToService;
SNodeSessions m_SNodeSessions;
std::unordered_multimap< Address, PathEnsureHook, Address::Hash >
m_PendingServiceLookups;

@ -117,7 +117,9 @@ namespace llarp
while(itr != sessions.end())
{
if(itr->second.IsExpired(now))
{
itr = sessions.erase(itr);
}
else
++itr;
}
@ -158,14 +160,14 @@ namespace llarp
bool
EndpointUtil::GetConvoTagsForService(const Endpoint::ConvoMap& sessions,
const ServiceInfo& info,
const Address& info,
std::set< ConvoTag >& tags)
{
bool inserted = false;
auto itr = sessions.begin();
while(itr != sessions.end())
{
if(itr->second.remote == info)
if(itr->second.remote.Addr() == info)
{
if(tags.insert(itr->first).second)
{

@ -41,8 +41,7 @@ namespace llarp
static bool
GetConvoTagsForService(const Endpoint::ConvoMap& sessions,
const ServiceInfo& info,
std::set< ConvoTag >& tags);
const Address& addr, std::set< ConvoTag >& tags);
};
} // namespace service

@ -34,7 +34,8 @@ namespace llarp
HasConvoTag(const ConvoTag& remote) const = 0;
virtual void
PutSenderFor(const ConvoTag& remote, const ServiceInfo& si) = 0;
PutSenderFor(const ConvoTag& remote, const ServiceInfo& si,
bool inbound) = 0;
virtual bool
GetSenderFor(const ConvoTag& remote, ServiceInfo& si) const = 0;
@ -52,8 +53,11 @@ namespace llarp
GetReplyIntroFor(const ConvoTag& remote, Introduction& intro) const = 0;
virtual bool
GetConvoTagsForService(const ServiceInfo& si,
GetConvoTagsForService(const Address& si,
std::set< ConvoTag >& tag) const = 0;
virtual bool
HasInboundConvo(const Address& addr) const = 0;
};
} // namespace service
} // namespace llarp

@ -337,7 +337,7 @@ namespace llarp
self->handler->PutIntroFor(self->msg->tag, self->msg->introReply);
self->handler->PutReplyIntroFor(self->msg->tag, self->fromIntro);
self->handler->PutSenderFor(self->msg->tag, self->msg->sender);
self->handler->PutSenderFor(self->msg->tag, self->msg->sender, true);
self->handler->PutCachedSessionKeyFor(self->msg->tag, sharedKey);
self->msg->handler = self->handler;

@ -14,5 +14,15 @@ namespace llarp
{"intro", intro.ExtractStatus()}};
return obj;
}
bool
Session::IsExpired(llarp_time_t now, llarp_time_t lifetime) const
{
if(now <= lastUsed)
return false;
return now - lastUsed > lifetime || intro.IsExpired(now)
|| replyIntro.IsExpired(now);
}
} // namespace service
} // namespace llarp

@ -20,18 +20,14 @@ namespace llarp
Introduction intro;
llarp_time_t lastUsed = 0;
uint64_t seqno = 0;
bool inbound = false;
util::StatusObject
ExtractStatus() const;
bool
IsExpired(llarp_time_t now,
llarp_time_t lifetime = (path::default_lifetime * 2)) const
{
if(now <= lastUsed)
return false;
return now - lastUsed > lifetime;
}
llarp_time_t lifetime = (path::default_lifetime * 2)) const;
};
} // namespace service

Loading…
Cancel
Save