mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 11:17:49 +02:00
add initial connection timeout for i2ptunnel
This commit is contained in:
parent
416589cc93
commit
1ea6d2016d
6 changed files with 408 additions and 298 deletions
|
@ -14,8 +14,10 @@ namespace i2p
|
|||
namespace client
|
||||
{
|
||||
class I2PServiceHandler;
|
||||
class I2PService
|
||||
class I2PService : std::enable_shared_from_this<I2PService>
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(const boost::system::error_code &)> ReadyCallback;
|
||||
public:
|
||||
I2PService (std::shared_ptr<ClientDestination> localDestination = nullptr);
|
||||
I2PService (i2p::data::SigningKeyType kt);
|
||||
|
@ -33,25 +35,37 @@ namespace client
|
|||
}
|
||||
void ClearHandlers ();
|
||||
|
||||
void SetConnectTimeout(uint32_t timeout);
|
||||
|
||||
void AddReadyCallback(ReadyCallback cb);
|
||||
|
||||
inline std::shared_ptr<ClientDestination> GetLocalDestination () { return m_LocalDestination; }
|
||||
inline std::shared_ptr<const ClientDestination> GetLocalDestination () const { return m_LocalDestination; }
|
||||
inline void SetLocalDestination (std::shared_ptr<ClientDestination> dest) { m_LocalDestination = dest; }
|
||||
void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port = 0);
|
||||
|
||||
void CreateStream(StreamRequestComplete complete, const i2p::data::IdentHash & ident, int port);
|
||||
inline boost::asio::io_service& GetService () { return m_LocalDestination->GetService (); }
|
||||
|
||||
virtual void Start () = 0;
|
||||
virtual void Stop () = 0;
|
||||
|
||||
virtual const char* GetName() { return "Generic I2P Service"; }
|
||||
|
||||
private:
|
||||
void TriggerReadyCheckTimer();
|
||||
void HandleReadyCheckTimer(const boost::system::error_code & ec);
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<ClientDestination> m_LocalDestination;
|
||||
std::unordered_set<std::shared_ptr<I2PServiceHandler> > m_Handlers;
|
||||
std::mutex m_HandlersMutex;
|
||||
std::vector<std::pair<ReadyCallback, uint32_t> > m_ReadyCallbacks;
|
||||
boost::asio::deadline_timer m_ReadyTimer;
|
||||
uint32_t m_ConnectTimeout;
|
||||
|
||||
public:
|
||||
bool isUpdated; // transient, used during reload only
|
||||
bool isUpdated; // transient, used during reload only
|
||||
};
|
||||
|
||||
/*Simple interface for I2PHandlers, allows detection of finalization amongst other things */
|
||||
|
@ -64,7 +78,7 @@ namespace client
|
|||
virtual void Handle() {}; //Start handling the socket
|
||||
|
||||
void Terminate () { Kill (); };
|
||||
|
||||
|
||||
protected:
|
||||
// Call when terminating or handing over to avoid race conditions
|
||||
inline bool Kill () { return m_Dead.exchange(true); }
|
||||
|
@ -102,7 +116,7 @@ namespace client
|
|||
uint8_t m_upstream_buf[TCP_IP_PIPE_BUFFER_SIZE], m_downstream_buf[TCP_IP_PIPE_BUFFER_SIZE];
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> m_up, m_down;
|
||||
};
|
||||
|
||||
|
||||
/* TODO: support IPv6 too */
|
||||
//This is a service that listens for connections on the IP network and interacts with I2P
|
||||
class TCPIPAcceptor: public I2PService
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue