mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 11:17:49 +02:00
windows warnings, tabulation workaround
This commit is contained in:
parent
7d7f5ff4e2
commit
057d6ca05b
7 changed files with 229 additions and 302 deletions
|
@ -16,8 +16,9 @@ namespace client
|
|||
class I2PServiceHandler;
|
||||
class I2PService : std::enable_shared_from_this<I2PService>
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(const boost::system::error_code &)> ReadyCallback;
|
||||
public:
|
||||
typedef std::function<void(const boost::system::error_code &)> ReadyCallback;
|
||||
|
||||
public:
|
||||
I2PService (std::shared_ptr<ClientDestination> localDestination = nullptr);
|
||||
I2PService (i2p::data::SigningKeyType kt);
|
||||
|
@ -35,9 +36,9 @@ namespace client
|
|||
}
|
||||
void ClearHandlers ();
|
||||
|
||||
void SetConnectTimeout(uint32_t timeout);
|
||||
void SetConnectTimeout(uint32_t timeout);
|
||||
|
||||
void AddReadyCallback(ReadyCallback cb);
|
||||
void AddReadyCallback(ReadyCallback cb);
|
||||
|
||||
inline std::shared_ptr<ClientDestination> GetLocalDestination () { return m_LocalDestination; }
|
||||
inline std::shared_ptr<const ClientDestination> GetLocalDestination () const { return m_LocalDestination; }
|
||||
|
@ -48,7 +49,7 @@ namespace client
|
|||
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);
|
||||
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;
|
||||
|
@ -56,18 +57,17 @@ namespace client
|
|||
|
||||
virtual const char* GetName() { return "Generic I2P Service"; }
|
||||
|
||||
private:
|
||||
void TriggerReadyCheckTimer();
|
||||
void HandleReadyCheckTimer(const boost::system::error_code & ec);
|
||||
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;
|
||||
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
|
||||
|
@ -93,6 +93,7 @@ namespace client
|
|||
inline void Done (std::shared_ptr<I2PServiceHandler> me) { if(m_Service) m_Service->RemoveHandler(me); }
|
||||
// Call to talk with the owner
|
||||
inline I2PService * GetOwner() { return m_Service; }
|
||||
|
||||
private:
|
||||
I2PService *m_Service;
|
||||
std::atomic<bool> m_Dead; //To avoid cleaning up multiple times
|
||||
|
@ -101,25 +102,28 @@ namespace client
|
|||
const size_t TCP_IP_PIPE_BUFFER_SIZE = 8192 * 8;
|
||||
|
||||
// bidirectional pipe for 2 tcp/ip sockets
|
||||
class TCPIPPipe: public I2PServiceHandler, public std::enable_shared_from_this<TCPIPPipe> {
|
||||
public:
|
||||
TCPIPPipe(I2PService * owner, std::shared_ptr<boost::asio::ip::tcp::socket> upstream, std::shared_ptr<boost::asio::ip::tcp::socket> downstream);
|
||||
~TCPIPPipe();
|
||||
void Start();
|
||||
protected:
|
||||
void Terminate();
|
||||
void AsyncReceiveUpstream();
|
||||
void AsyncReceiveDownstream();
|
||||
void HandleUpstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transferred);
|
||||
void HandleDownstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transferred);
|
||||
void HandleUpstreamWrite(const boost::system::error_code & ecode);
|
||||
void HandleDownstreamWrite(const boost::system::error_code & ecode);
|
||||
void UpstreamWrite(size_t len);
|
||||
void DownstreamWrite(size_t len);
|
||||
private:
|
||||
uint8_t m_upstream_to_down_buf[TCP_IP_PIPE_BUFFER_SIZE], m_downstream_to_up_buf[TCP_IP_PIPE_BUFFER_SIZE];
|
||||
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;
|
||||
class TCPIPPipe: public I2PServiceHandler, public std::enable_shared_from_this<TCPIPPipe>
|
||||
{
|
||||
public:
|
||||
TCPIPPipe(I2PService * owner, std::shared_ptr<boost::asio::ip::tcp::socket> upstream, std::shared_ptr<boost::asio::ip::tcp::socket> downstream);
|
||||
~TCPIPPipe();
|
||||
void Start();
|
||||
|
||||
protected:
|
||||
void Terminate();
|
||||
void AsyncReceiveUpstream();
|
||||
void AsyncReceiveDownstream();
|
||||
void HandleUpstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transferred);
|
||||
void HandleDownstreamReceived(const boost::system::error_code & ecode, std::size_t bytes_transferred);
|
||||
void HandleUpstreamWrite(const boost::system::error_code & ecode);
|
||||
void HandleDownstreamWrite(const boost::system::error_code & ecode);
|
||||
void UpstreamWrite(size_t len);
|
||||
void DownstreamWrite(size_t len);
|
||||
|
||||
private:
|
||||
uint8_t m_upstream_to_down_buf[TCP_IP_PIPE_BUFFER_SIZE], m_downstream_to_up_buf[TCP_IP_PIPE_BUFFER_SIZE];
|
||||
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 */
|
||||
|
@ -143,10 +147,11 @@ namespace client
|
|||
|
||||
const boost::asio::ip::tcp::endpoint& GetLocalEndpoint () const { return m_LocalEndpoint; };
|
||||
|
||||
virtual const char* GetName() { return "Generic TCP/IP accepting daemon"; }
|
||||
virtual const char* GetName() { return "Generic TCP/IP accepting daemon"; }
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<I2PServiceHandler> CreateHandler(std::shared_ptr<boost::asio::ip::tcp::socket> socket) = 0;
|
||||
|
||||
private:
|
||||
void Accept();
|
||||
void HandleAccept(const boost::system::error_code& ecode, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue