Browse Source

send ping every keealive interval for client tunnels

pull/1696/head
orignal 3 years ago
parent
commit
2eded7cdd7
  1. 25
      libi2pd/Destination.cpp
  2. 2
      libi2pd/Destination.h
  3. 9
      libi2pd_client/ClientContext.cpp
  4. 3
      libi2pd_client/ClientContext.h
  5. 39
      libi2pd_client/I2PTunnel.cpp
  6. 10
      libi2pd_client/I2PTunnel.h

25
libi2pd/Destination.cpp

@ -1096,6 +1096,31 @@ namespace client @@ -1096,6 +1096,31 @@ namespace client
return nullptr;
}
void ClientDestination::SendPing (const i2p::data::IdentHash& to)
{
if (m_StreamingDestination)
{
auto leaseSet = FindLeaseSet (to);
if (leaseSet)
m_StreamingDestination->SendPing (leaseSet);
else
RequestDestination (to,
[s = m_StreamingDestination](std::shared_ptr<const i2p::data::LeaseSet> ls)
{
if (ls) s->SendPing (ls);
});
}
}
void ClientDestination::SendPing (std::shared_ptr<const i2p::data::BlindedPublicKey> to)
{
RequestDestinationWithEncryptedLeaseSet (to,
[s = m_StreamingDestination](std::shared_ptr<const i2p::data::LeaseSet> ls)
{
if (ls) s->SendPing (ls);
});
}
std::shared_ptr<i2p::stream::StreamingDestination> ClientDestination::GetStreamingDestination (int port) const
{
if (port)

2
libi2pd/Destination.h

@ -243,6 +243,8 @@ namespace client @@ -243,6 +243,8 @@ namespace client
void CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port = 0);
void CreateStream (StreamRequestComplete streamRequestComplete, std::shared_ptr<const i2p::data::BlindedPublicKey> dest, int port = 0);
std::shared_ptr<i2p::stream::Stream> CreateStream (std::shared_ptr<const i2p::data::LeaseSet> remote, int port = 0);
void SendPing (const i2p::data::IdentHash& to);
void SendPing (std::shared_ptr<const i2p::data::BlindedPublicKey> to);
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
void StopAcceptingStreams ();
bool IsAcceptingStreams () const;

9
libi2pd_client/ClientContext.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -652,6 +652,13 @@ namespace client @@ -652,6 +652,13 @@ namespace client
auto tun = std::make_shared<I2PClientTunnel> (name, dest, address, port, localDestination, destinationPort);
clientTunnel = tun;
clientEndpoint = tun->GetLocalEndpoint ();
uint32_t keepAlive = section.second.get<uint32_t>(I2P_CLIENT_TUNNEL_KEEP_ALIVE_INTERVAL, 0);
if (keepAlive)
{
tun->SetKeepAliveInterval (keepAlive);
LogPrint(eLogInfo, "Clients: I2P Client tunnel keep alive interval set to ", keepAlive);
}
}
uint32_t timeout = section.second.get<uint32_t>(I2P_CLIENT_TUNNEL_CONNECT_TIMEOUT, 0);

3
libi2pd_client/ClientContext.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -48,6 +48,7 @@ namespace client @@ -48,6 +48,7 @@ namespace client
const char I2P_CLIENT_TUNNEL_DESTINATION_PORT[] = "destinationport";
const char I2P_CLIENT_TUNNEL_MATCH_TUNNELS[] = "matchtunnels";
const char I2P_CLIENT_TUNNEL_CONNECT_TIMEOUT[] = "connecttimeout";
const char I2P_CLIENT_TUNNEL_KEEP_ALIVE_INTERVAL[] = "keepaliveinterval";
const char I2P_SERVER_TUNNEL_HOST[] = "host";
const char I2P_SERVER_TUNNEL_HOST_OVERRIDE[] = "hostoverride";
const char I2P_SERVER_TUNNEL_PORT[] = "port";

39
libi2pd_client/I2PTunnel.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -532,7 +532,7 @@ namespace client @@ -532,7 +532,7 @@ namespace client
I2PClientTunnel::I2PClientTunnel (const std::string& name, const std::string& destination,
const std::string& address, int port, std::shared_ptr<ClientDestination> localDestination, int destinationPort):
TCPIPAcceptor (address, port, localDestination), m_Name (name), m_Destination (destination),
m_DestinationPort (destinationPort)
m_DestinationPort (destinationPort), m_KeepAliveInterval (0)
{
}
@ -540,14 +540,24 @@ namespace client @@ -540,14 +540,24 @@ namespace client
{
TCPIPAcceptor::Start ();
GetAddress ();
if (m_KeepAliveInterval)
ScheduleKeepAliveTimer ();
}
void I2PClientTunnel::Stop ()
{
TCPIPAcceptor::Stop();
m_Address = nullptr;
if (m_KeepAliveTimer) m_KeepAliveTimer->cancel ();
}
void I2PClientTunnel::SetKeepAliveInterval (uint32_t keepAliveInterval)
{
m_KeepAliveInterval = keepAliveInterval;
if (m_KeepAliveInterval)
m_KeepAliveTimer.reset (new boost::asio::deadline_timer (GetLocalDestination ()->GetService ()));
}
/* HACK: maybe we should create a caching IdentHash provider in AddressBook */
std::shared_ptr<const Address> I2PClientTunnel::GetAddress ()
{
@ -569,6 +579,31 @@ namespace client @@ -569,6 +579,31 @@ namespace client
return nullptr;
}
void I2PClientTunnel::ScheduleKeepAliveTimer ()
{
if (m_KeepAliveTimer)
{
m_KeepAliveTimer->expires_from_now (boost::posix_time::seconds(m_KeepAliveInterval));
m_KeepAliveTimer->async_wait (std::bind (&I2PClientTunnel::HandleKeepAliveTimer,
this, std::placeholders::_1));
}
}
void I2PClientTunnel::HandleKeepAliveTimer (const boost::system::error_code& ecode)
{
if (ecode != boost::asio::error::operation_aborted)
{
if (m_Address && m_Address->IsValid ())
{
if (m_Address->IsIdentHash ())
GetLocalDestination ()->SendPing (m_Address->identHash);
else
GetLocalDestination ()->SendPing (m_Address->blindedPublicKey);
}
ScheduleKeepAliveTimer ();
}
}
I2PServerTunnel::I2PServerTunnel (const std::string& name, const std::string& address,
int port, std::shared_ptr<ClientDestination> localDestination, int inport, bool gzip):
I2PService (localDestination), m_IsUniqueLocal(true), m_Name (name), m_Address (address), m_Port (port), m_IsAccessList (false)

10
libi2pd_client/I2PTunnel.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -153,16 +153,22 @@ namespace client @@ -153,16 +153,22 @@ namespace client
void Stop ();
const char* GetName() { return m_Name.c_str (); }
void SetKeepAliveInterval (uint32_t keepAliveInterval);
private:
std::shared_ptr<const Address> GetAddress ();
void ScheduleKeepAliveTimer ();
void HandleKeepAliveTimer (const boost::system::error_code& ecode);
private:
std::string m_Name, m_Destination;
std::shared_ptr<const Address> m_Address;
int m_DestinationPort;
uint32_t m_KeepAliveInterval;
std::unique_ptr<boost::asio::deadline_timer> m_KeepAliveTimer;
};

Loading…
Cancel
Save