This commit is contained in:
Jeff Becker 2016-08-21 21:17:09 -04:00
parent 72974c85c8
commit 7b5e18d94b
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
5 changed files with 25 additions and 36 deletions

View File

@ -466,7 +466,7 @@ namespace client
std::make_pair(
localDestination->GetIdentHash(), port),
std::unique_ptr<I2PUDPServerTunnel>(serverTunnel))).second) {
LogPrint(eLogInfo, "Cleints: I2P Server Forward created for UDP Endpoint ", host, ":", port, " via ",localDestination->GetIdentHash().ToBase32());
LogPrint(eLogInfo, "Clients: I2P Server Forward created for UDP Endpoint ", host, ":", port, " via ",localDestination->GetIdentHash().ToBase32());
} else {
LogPrint(eLogError, "Clients: I2P Server Forward for destination/port ", m_AddressBook.ToAddress(localDestination->GetIdentHash()), "/", port, "already exists");
}

View File

@ -677,8 +677,6 @@ namespace client
ClientDestination::~ClientDestination ()
{
if (m_DatagramDestination)
delete m_DatagramDestination;
}
bool ClientDestination::Start ()
@ -703,13 +701,8 @@ namespace client
m_StreamingDestination = nullptr;
for (auto& it: m_StreamingDestinationsByPorts)
it.second->Stop ();
if (m_DatagramDestination)
{
auto d = m_DatagramDestination;
m_DatagramDestination = nullptr;
delete d;
}
return true;
m_DatagramDestination = nullptr;
return true;
}
else
return false;
@ -819,10 +812,10 @@ namespace client
return dest;
}
i2p::datagram::DatagramDestination * ClientDestination::CreateDatagramDestination ()
std::shared_ptr<i2p::datagram::DatagramDestination> ClientDestination::CreateDatagramDestination ()
{
if (!m_DatagramDestination)
m_DatagramDestination = new i2p::datagram::DatagramDestination (GetSharedFromThis ());
if (m_DatagramDestination == nullptr)
m_DatagramDestination = std::make_shared<i2p::datagram::DatagramDestination> (GetSharedFromThis ());
return m_DatagramDestination;
}

View File

@ -164,8 +164,8 @@ namespace client
bool IsAcceptingStreams () const;
// datagram
i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; };
i2p::datagram::DatagramDestination * CreateDatagramDestination ();
std::shared_ptr<i2p::datagram::DatagramDestination> GetDatagramDestination () const { return m_DatagramDestination; };
std::shared_ptr<i2p::datagram::DatagramDestination> CreateDatagramDestination ();
// implements LocalDestination
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
@ -190,7 +190,7 @@ namespace client
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
i2p::datagram::DatagramDestination * m_DatagramDestination;
std::shared_ptr<i2p::datagram::DatagramDestination> m_DatagramDestination;
public:

View File

@ -539,14 +539,14 @@ namespace client
}
/** create new */
boost::asio::ip::udp::endpoint ep(boost::asio::ip::address::from_string("127.0.0.1"), 0);
m_Sessions.push_back(UDPSession(m_Service, ep, m_Destination, m_Endpoint, ih, localPort, remotePort));
m_Sessions.push_back(UDPSession(m_Service, ep, m_LocalDest, m_Endpoint, ih, localPort, remotePort));
auto & s = m_Sessions.back();
s.SendEndpoint = s.IPSocket.local_endpoint();
return s;
}
UDPSession::UDPSession(boost::asio::io_service & ios, boost::asio::ip::udp::endpoint localEndpoint, std::shared_ptr<i2p::client::ClientDestination> localDestination, boost::asio::ip::udp::endpoint endpoint, const i2p::data::IdentHash to, uint16_t ourPort, uint16_t theirPort) :
Destination(localDestination),
m_Destination(localDestination),
IPSocket(ios, localEndpoint),
Identity(to),
SendEndpoint(endpoint),
@ -569,17 +569,12 @@ namespace client
LogPrint(eLogDebug, "UDPSesssion: HandleRecveived");
if(!ecode) {
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
if (Destination) {
auto dgram = Destination->CreateDatagramDestination();
if(dgram) {
LastActivity = i2p::util::GetMillisecondsSinceEpoch();
dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0);
LogPrint(eLogDebug, "UDPSession: forward ", len, "B to ", Identity.ToBase32(), " from ", Destination->GetIdentHash().ToBase32());
} else {
LogPrint(eLogWarning, "UDPSession: no datagram destination");
}
auto dgram = m_Destination->GetDatagramDestination();
if(dgram) {
LastActivity = i2p::util::GetMillisecondsSinceEpoch();
dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0);
} else {
LogPrint(eLogWarning, "UDPSession: no Local Destination");
LogPrint(eLogWarning, "UDPSession: no datagram destination");
}
Receive();
} else {
@ -590,20 +585,21 @@ namespace client
I2PUDPServerTunnel::I2PUDPServerTunnel(const std::string & name, std::shared_ptr<i2p::client::ClientDestination> localDestination, boost::asio::ip::udp::endpoint forwardTo, uint16_t port, boost::asio::io_service & service) :
LocalPort(port),
m_Endpoint(forwardTo),
m_Service(service),
m_Destination(localDestination)
m_Service(service)
{
i2p::datagram::DatagramDestination * dgram = m_Destination->CreateDatagramDestination();
if(dgram)
dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), 0);
m_LocalDest = localDestination;
m_LocalDest->Start();
auto dgram = m_LocalDest->CreateDatagramDestination();
dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), 0);
}
I2PUDPServerTunnel::~I2PUDPServerTunnel()
{
i2p::datagram::DatagramDestination * dgram = m_Destination->GetDatagramDestination();
auto dgram = m_LocalDest->GetDatagramDestination();
if (dgram) {
dgram->ResetReceiver(0);
}
LogPrint(eLogInfo, "UDPServer: done");
}
I2PUDPClientTunnel::I2PUDPClientTunnel(const std::string & name, const std::string &remoteDest, boost::asio::ip::udp::endpoint localEndpoint, std::shared_ptr<i2p::client::ClientDestination> localDestination, uint16_t remotePort, boost::asio::io_service & service) :

View File

@ -140,7 +140,7 @@ namespace client
struct UDPSession
{
std::shared_ptr<i2p::client::ClientDestination> Destination;
std::shared_ptr<i2p::client::ClientDestination> m_Destination;
boost::asio::ip::udp::socket IPSocket;
i2p::data::IdentHash Identity;
boost::asio::ip::udp::endpoint FromEndpoint;
@ -177,7 +177,7 @@ namespace client
std::mutex m_SessionsMutex;
std::vector<UDPSession> m_Sessions;
boost::asio::io_service & m_Service;
std::shared_ptr<i2p::client::ClientDestination> m_Destination;
std::shared_ptr<i2p::client::ClientDestination> m_LocalDest;
uint8_t m_Buffer[I2P_UDP_MAX_MTU];
};