Move service::Session to its own componet

pull/536/head
Michael 5 years ago
parent 94ad84363a
commit 33c80b7c16
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -230,6 +230,7 @@ set(LIB_SRC
service/pendingbuffer.cpp service/pendingbuffer.cpp
service/protocol.cpp service/protocol.cpp
service/sendcontext.cpp service/sendcontext.cpp
service/session.cpp
service/tag.cpp service/tag.cpp
service/tag_lookup_job.cpp service/tag_lookup_job.cpp
service/types.cpp service/types.cpp

@ -12,6 +12,7 @@
#include <service/pendingbuffer.hpp> #include <service/pendingbuffer.hpp>
#include <service/protocol.hpp> #include <service/protocol.hpp>
#include <service/sendcontext.hpp> #include <service/sendcontext.hpp>
#include <service/session.hpp>
#include <service/tag_lookup_job.hpp> #include <service/tag_lookup_job.hpp>
// minimum time between introset shifts // minimum time between introset shifts
@ -69,18 +70,18 @@ namespace llarp
} }
/// router's logic /// router's logic
llarp::Logic* Logic*
RouterLogic(); RouterLogic();
/// endpoint's logic /// endpoint's logic
llarp::Logic* Logic*
EndpointLogic(); EndpointLogic();
/// borrow endpoint's net loop for sending data to user /// borrow endpoint's net loop for sending data to user
llarp_ev_loop_ptr llarp_ev_loop_ptr
EndpointNetLoop(); EndpointNetLoop();
llarp::Crypto* Crypto*
Crypto(); Crypto();
llarp_threadpool* llarp_threadpool*
@ -117,14 +118,14 @@ namespace llarp
PublishIntroSetVia(AbstractRouter* r, path::Path* p); PublishIntroSetVia(AbstractRouter* r, path::Path* p);
bool bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg) override; HandleGotIntroMessage(const dht::GotIntroMessage* msg) override;
bool bool
HandleGotRouterMessage(const llarp::dht::GotRouterMessage* msg) override; HandleGotRouterMessage(const dht::GotRouterMessage* msg) override;
bool bool
HandleHiddenServiceFrame(path::Path* p, HandleHiddenServiceFrame(path::Path* p,
const llarp::service::ProtocolFrame* msg); const service::ProtocolFrame* msg);
/// return true if we have an established path to a hidden service /// return true if we have an established path to a hidden service
bool bool
@ -221,7 +222,7 @@ namespace llarp
uint64_t timeoutMS, bool lookupOnRandomPath = false); uint64_t timeoutMS, bool lookupOnRandomPath = false);
using SNodeEnsureHook = using SNodeEnsureHook =
std::function< void(RouterID, llarp::exit::BaseSession*) >; std::function< void(RouterID, exit::BaseSession*) >;
/// ensure a path to a service node by public key /// ensure a path to a service node by public key
void void
@ -328,12 +329,12 @@ namespace llarp
protected: protected:
IDataHandler* m_DataHandler = nullptr; IDataHandler* m_DataHandler = nullptr;
Identity m_Identity; Identity m_Identity;
std::unique_ptr< llarp::exit::BaseSession > m_Exit; std::unique_ptr< exit::BaseSession > m_Exit;
private: private:
AbstractRouter* m_Router; AbstractRouter* m_Router;
llarp_threadpool* m_IsolatedWorker = nullptr; llarp_threadpool* m_IsolatedWorker = nullptr;
llarp::Logic* m_IsolatedLogic = nullptr; Logic* m_IsolatedLogic = nullptr;
llarp_ev_loop_ptr m_IsolatedNetLoop = nullptr; llarp_ev_loop_ptr m_IsolatedNetLoop = nullptr;
std::string m_Keyfile; std::string m_Keyfile;
std::string m_Name; std::string m_Name;
@ -352,10 +353,8 @@ namespace llarp
Sessions m_DeadSessions; Sessions m_DeadSessions;
using SNodeSessions = using SNodeSessions = std::unordered_multimap<
std::unordered_multimap< RouterID, RouterID, std::unique_ptr< exit::BaseSession >, RouterID::Hash >;
std::unique_ptr< llarp::exit::BaseSession >,
RouterID::Hash >;
SNodeSessions m_SNodeSessions; SNodeSessions m_SNodeSessions;
@ -409,36 +408,6 @@ namespace llarp
/// on initialize functions /// on initialize functions
std::list< std::function< bool(void) > > m_OnInit; std::list< std::function< bool(void) > > m_OnInit;
struct Session
{
Introduction replyIntro;
SharedSecret sharedKey;
ServiceInfo remote;
Introduction intro;
llarp_time_t lastUsed = 0;
uint64_t seqno = 0;
util::StatusObject
ExtractStatus() const
{
util::StatusObject obj{{"lastUsed", lastUsed},
{"replyIntro", replyIntro.ExtractStatus()},
{"remote", remote.Addr().ToString()},
{"seqno", seqno},
{"intro", intro.ExtractStatus()}};
return obj;
};
bool
IsExpired(llarp_time_t now,
llarp_time_t lifetime = (path::default_lifetime * 2)) const
{
if(now <= lastUsed)
return false;
return now - lastUsed > lifetime;
}
};
/// conversations /// conversations
using ConvoMap_t = using ConvoMap_t =
std::unordered_map< ConvoTag, Session, ConvoTag::Hash >; std::unordered_map< ConvoTag, Session, ConvoTag::Hash >;

@ -0,0 +1,18 @@
#include <service/session.hpp>
namespace llarp
{
namespace service
{
util::StatusObject
Session::ExtractStatus() const
{
util::StatusObject obj{{"lastUsed", lastUsed},
{"replyIntro", replyIntro.ExtractStatus()},
{"remote", remote.Addr().ToString()},
{"seqno", seqno},
{"intro", intro.ExtractStatus()}};
return obj;
};
} // namespace service
} // namespace llarp

@ -0,0 +1,41 @@
#ifndef LLARP_SERVICE_SESSION_HPP
#define LLARP_SERVICE_SESSION_HPP
#include <crypto/types.hpp>
#include <path/path.hpp>
#include <service/Info.hpp>
#include <service/Intro.hpp>
#include <util/status.hpp>
#include <util/types.hpp>
namespace llarp
{
namespace service
{
struct Session
{
Introduction replyIntro;
SharedSecret sharedKey;
ServiceInfo remote;
Introduction intro;
llarp_time_t lastUsed = 0;
uint64_t seqno = 0;
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;
}
};
} // namespace service
} // namespace llarp
#endif
Loading…
Cancel
Save