1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jeff Becker 2019-05-07 07:36:23 -04:00
commit 66fbac7f6e
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
6 changed files with 99 additions and 84 deletions

View file

@ -11,7 +11,7 @@ namespace llarp
/// base type for event hook handlers
struct IBackend
{
~IBackend(){};
virtual ~IBackend() = 0;
virtual void
NotifyAsync(std::unordered_map< std::string, std::string > params) = 0;
@ -25,6 +25,10 @@ namespace llarp
};
using Backend_ptr = std::shared_ptr< IBackend >;
inline IBackend::~IBackend()
{
}
} // namespace hooks
} // namespace llarp

View file

@ -200,20 +200,10 @@ namespace llarp
if(!m_Tag.IsZero())
obj.Put("tag", m_Tag.ToString());
auto putContainer = [](util::StatusObject& o, const std::string& keyname,
const auto& container) {
std::vector< util::StatusObject > objs;
std::transform(container.begin(), container.end(),
std::back_inserter(objs),
[](const auto& item) -> util::StatusObject {
return item.second->ExtractStatus();
});
o.Put(keyname, objs);
};
putContainer(obj, "deadSessions", m_DeadSessions);
putContainer(obj, "remoteSessions", m_RemoteSessions);
putContainer(obj, "snodeSessions", m_SNodeSessions);
putContainer(obj, "lookups", m_PendingLookups);
obj.PutContainer("deadSessions", m_DeadSessions);
obj.PutContainer("remoteSessions", m_RemoteSessions);
obj.PutContainer("snodeSessions", m_SNodeSessions);
obj.PutContainer("lookups", m_PendingLookups);
util::StatusObject sessionObj{};
@ -252,7 +242,7 @@ namespace llarp
// prefetch addrs
for(const auto& addr : m_PrefetchAddrs)
{
if(!HasPathToService(addr))
if(!EndpointUtil::HasPathToService(addr, m_RemoteSessions))
{
if(!EnsurePathToService(
addr,
@ -341,12 +331,6 @@ namespace llarp
return m_Name + ":" + m_Identity.pub.Name();
}
bool
Endpoint::HasPathToService(const Address& addr) const
{
return EndpointUtil::HasPathToService(addr, m_RemoteSessions);
}
void
Endpoint::PutLookup(IServiceLookup* lookup, uint64_t txid)
{
@ -465,17 +449,7 @@ namespace llarp
Endpoint::GetConvoTagsForService(const ServiceInfo& info,
std::set< ConvoTag >& tags) const
{
bool inserted = false;
auto itr = m_Sessions.begin();
while(itr != m_Sessions.end())
{
if(itr->second.remote == info)
{
inserted |= tags.insert(itr->first).second;
}
++itr;
}
return inserted;
return EndpointUtil::GetConvoTagsForService(m_Sessions, info, tags);
}
bool
@ -1118,7 +1092,7 @@ namespace llarp
}
}
// outbound converstation
if(HasPathToService(remote))
if(EndpointUtil::HasPathToService(remote, m_RemoteSessions))
{
auto range = m_RemoteSessions.equal_range(remote);
auto itr = range.first;

View file

@ -146,10 +146,6 @@ namespace llarp
HandleHiddenServiceFrame(path::Path_ptr p,
const service::ProtocolFrame& msg);
/// return true if we have an established path to a hidden service
bool
HasPathToService(const Address& remote) const;
virtual huint32_t
ObtainIPForAddr(const AlignedBuffer< 32 >& addr, bool serviceNode) = 0;
@ -358,46 +354,6 @@ namespace llarp
private:
friend struct EndpointUtil;
AbstractRouter* m_Router;
llarp_threadpool* m_IsolatedWorker = nullptr;
Logic* m_IsolatedLogic = nullptr;
llarp_ev_loop_ptr m_IsolatedNetLoop = nullptr;
std::string m_Keyfile;
std::string m_Name;
std::string m_NetNS;
bool m_BundleRC = false;
using Msg_ptr = std::shared_ptr< const routing::PathTransferMessage >;
using SendEvent_t = std::pair< Msg_ptr, path::Path_ptr >;
util::Mutex m_SendQueueMutex;
std::deque< SendEvent_t > m_SendQueue;
using PendingTraffic =
std::unordered_map< Address, PendingBufferQueue, Address::Hash >;
PendingTraffic m_PendingTraffic;
using Sessions =
std::unordered_multimap< Address, std::shared_ptr< OutboundContext >,
Address::Hash >;
Sessions m_RemoteSessions;
Sessions m_DeadSessions;
using SNodeSessions = std::unordered_multimap<
RouterID, std::shared_ptr< exit::BaseSession >, RouterID::Hash >;
util::Mutex m_SNodeSessionsMutex;
SNodeSessions m_SNodeSessions;
std::unordered_map< Address, ServiceInfo, Address::Hash >
m_AddressToService;
std::unordered_multimap< Address, PathEnsureHook, Address::Hash >
m_PendingServiceLookups;
std::unordered_map< RouterID, uint32_t, RouterID::Hash >
m_ServiceLookupFails;
struct RouterLookupJob
{
RouterLookupJob(Endpoint* p, RouterLookupHandler h) : handler(h)
@ -426,8 +382,55 @@ namespace llarp
}
};
using Msg_ptr = std::shared_ptr< const routing::PathTransferMessage >;
using SendEvent_t = std::pair< Msg_ptr, path::Path_ptr >;
using PendingTraffic =
std::unordered_map< Address, PendingBufferQueue, Address::Hash >;
using PendingRouters =
std::unordered_map< RouterID, RouterLookupJob, RouterID::Hash >;
using PendingLookups =
std::unordered_map< uint64_t,
std::unique_ptr< service::IServiceLookup > >;
using Sessions =
std::unordered_multimap< Address, std::shared_ptr< OutboundContext >,
Address::Hash >;
using SNodeSessions = std::unordered_multimap<
RouterID, std::shared_ptr< exit::BaseSession >, RouterID::Hash >;
using ConvoMap = std::unordered_map< ConvoTag, Session, ConvoTag::Hash >;
AbstractRouter* m_Router;
llarp_threadpool* m_IsolatedWorker = nullptr;
Logic* m_IsolatedLogic = nullptr;
llarp_ev_loop_ptr m_IsolatedNetLoop = nullptr;
std::string m_Keyfile;
std::string m_Name;
std::string m_NetNS;
bool m_BundleRC = false;
util::Mutex m_SendQueueMutex;
std::deque< SendEvent_t > m_SendQueue GUARDED_BY(m_SendQueueMutex);
PendingTraffic m_PendingTraffic;
Sessions m_RemoteSessions;
Sessions m_DeadSessions;
SNodeSessions m_SNodeSessions;
std::unordered_map< Address, ServiceInfo, Address::Hash >
m_AddressToService;
std::unordered_multimap< Address, PathEnsureHook, Address::Hash >
m_PendingServiceLookups;
std::unordered_map< RouterID, uint32_t, RouterID::Hash >
m_ServiceLookupFails;
PendingRouters m_PendingRouters;
uint64_t m_CurrentPublishTX = 0;
@ -437,9 +440,6 @@ namespace llarp
/// our introset
service::IntroSet m_IntroSet;
/// pending remote service lookups by id
using PendingLookups =
std::unordered_map< uint64_t,
std::unique_ptr< service::IServiceLookup > >;
PendingLookups m_PendingLookups;
/// prefetch remote address list
std::set< Address > m_PrefetchAddrs;
@ -451,8 +451,6 @@ namespace llarp
std::list< std::function< bool(void) > > m_OnInit;
/// conversations
using ConvoMap = std::unordered_map< ConvoTag, Session, ConvoTag::Hash >;
ConvoMap m_Sessions;
std::unordered_map< Tag, CachedTagResult, Tag::Hash > m_PrefetchedTags;

View file

@ -155,5 +155,26 @@ namespace llarp
}
return false;
}
bool
EndpointUtil::GetConvoTagsForService(const Endpoint::ConvoMap& sessions,
const ServiceInfo& info,
std::set< ConvoTag >& tags)
{
bool inserted = false;
auto itr = sessions.begin();
while(itr != sessions.end())
{
if(itr->second.remote == info)
{
if(tags.insert(itr->first).second)
{
inserted = true;
}
}
++itr;
}
return inserted;
}
} // namespace service
} // namespace llarp

View file

@ -38,6 +38,11 @@ namespace llarp
static bool
HasPathToService(const Address& addr,
const Endpoint::Sessions& remoteSessions);
static bool
GetConvoTagsForService(const Endpoint::ConvoMap& sessions,
const ServiceInfo& info,
std::set< ConvoTag >& tags);
};
} // namespace service

View file

@ -35,6 +35,19 @@ namespace llarp
void
Put(const value_type& value);
template < typename Container >
void
PutContainer(String_t keyname, const Container& container)
{
std::vector< util::StatusObject > objs;
std::transform(container.begin(), container.end(),
std::back_inserter(objs),
[](const auto& item) -> util::StatusObject {
return item.second->ExtractStatus();
});
Put(keyname, objs);
}
nlohmann::json
get() const
{