don't use netDb subcriptions anymore

This commit is contained in:
orignal 2014-10-15 12:07:06 -04:00
parent c92d99718b
commit a046af1806
6 changed files with 45 additions and 56 deletions

View file

@ -147,7 +147,8 @@ namespace stream
int port, StreamingDestination * localDestination):
I2PTunnel (service, localDestination ? localDestination : GetSharedLocalDestination ()),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Destination (destination), m_DestinationIdentHash (nullptr), m_RemoteLeaseSet (nullptr)
m_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr),
m_RemoteLeaseSet (nullptr)
{
}
@ -161,12 +162,7 @@ namespace stream
i2p::data::IdentHash identHash;
if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash))
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
if (m_DestinationIdentHash)
{
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetLocalDestination ()->GetTunnelPool ());
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*m_DestinationIdentHash);
}
else
if (!m_DestinationIdentHash)
LogPrint ("I2PTunnel unknown destination ", m_Destination);
m_Acceptor.listen ();
Accept ();
@ -175,6 +171,7 @@ namespace stream
void I2PClientTunnel::Stop ()
{
m_Acceptor.close();
m_Timer.cancel ();
ClearConnections ();
m_DestinationIdentHash = nullptr;
}
@ -201,28 +198,50 @@ namespace stream
if (i2p::data::netdb.GetAddressBook ().GetIdentHash (m_Destination, identHash))
{
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
i2p::data::netdb.Subscribe (*m_DestinationIdentHash, GetLocalDestination ()->GetTunnelPool ());
i2p::data::netdb.RequestDestination (*m_DestinationIdentHash, GetLocalDestination ()->GetTunnelPool ());
m_Timer.expires_from_now (boost::posix_time::seconds (I2P_TUNNEL_DESTINATION_REQUEST_TIMEOUT));
m_Timer.async_wait (boost::bind (&I2PClientTunnel::HandleDestinationRequestTimer,
this, boost::asio::placeholders::error, socket));
}
}
}
if (m_RemoteLeaseSet) // leaseSet found
{
LogPrint ("New I2PTunnel connection");
auto connection = new I2PTunnelConnection (this, socket, m_RemoteLeaseSet);
AddConnection (connection);
}
else
{
LogPrint ("LeaseSet for I2PTunnel destination not found");
delete socket;
}
CreateConnection (socket);
Accept ();
}
else
delete socket;
}
void I2PClientTunnel::HandleDestinationRequestTimer (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket)
{
if (ecode != boost::asio::error::operation_aborted)
{
if (m_DestinationIdentHash)
{
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*m_DestinationIdentHash);
CreateConnection (socket);
return;
}
}
delete socket;
}
void I2PClientTunnel::CreateConnection (boost::asio::ip::tcp::socket * socket)
{
if (m_RemoteLeaseSet) // leaseSet found
{
LogPrint ("New I2PTunnel connection");
auto connection = new I2PTunnelConnection (this, socket, m_RemoteLeaseSet);
AddConnection (connection);
}
else
{
LogPrint ("LeaseSet for I2PTunnel destination not found");
delete socket;
}
}
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
StreamingDestination * localDestination): I2PTunnel (service, localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port)