From e8f9ecc7d902ecc05452649c40e1ef030faa9274 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 21 Aug 2016 15:33:19 -0400 Subject: [PATCH] fixes --- ClientContext.cpp | 4 ++++ I2PTunnel.cpp | 12 +++++++----- I2PTunnel.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index 68115402..4440cb44 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -404,6 +404,9 @@ namespace client if(destinationPort == 0) { destinationPort = port; } + if (!localDestination) { + localDestination = m_SharedLocalDestination; + } auto clientTunnel = new I2PUDPClientTunnel(name, dest, end, localDestination, destinationPort, m_Service); if(m_ClientForwards.insert(std::make_pair(end, std::unique_ptr(clientTunnel))).second) { clientTunnel->Start(); @@ -411,6 +414,7 @@ namespace client LogPrint(eLogError, "Clients: I2P Client forward for endpoint ", end, " already exists"); delete clientTunnel; } + } else { // tcp client auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index e639c12a..55d40fad 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -539,19 +539,20 @@ namespace client } } /** create new */ - m_Sessions.push_back(UDPSession(m_Service, m_Destination, m_Endpoint, ih, localPort, remotePort)); + m_Sessions.push_back(UDPSession(m_Service, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0), m_Destination, m_Endpoint, ih, localPort, remotePort)); return m_Sessions.back(); } - UDPSession::UDPSession(boost::asio::io_service & ios, std::shared_ptr localDestination, boost::asio::ip::udp::endpoint endpoint, const i2p::data::IdentHash from, uint16_t ourPort, uint16_t theirPort) : + UDPSession::UDPSession(boost::asio::io_service & ios, boost::asio::ip::udp::endpoint localEndpoint, std::shared_ptr localDestination, boost::asio::ip::udp::endpoint endpoint, const i2p::data::IdentHash from, uint16_t ourPort, uint16_t theirPort) : Destination(localDestination), - IPSocket(ios, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)), + IPSocket(ios, localEndpoint), Identity(from), ExpectedEndpoint(endpoint), LocalPort(ourPort), RemotePort(theirPort) { Receive(); + LogPrint(eLogDebug, "UDPSession: bound to", IPSocket.local_endpoint()); } @@ -624,10 +625,11 @@ namespace client LogPrint(eLogError, "UDP Tunnel: lookup of ", m_RemoteDest, " was cancelled"); return; } + LogPrint(eLogInfo, "UDP Tunnel: resolved ", m_RemoteDest, " to ", m_RemoteIdent->ToBase32()); + auto dgram = m_LocalDest->CreateDatagramDestination(); // delete existing session if(m_Session) delete m_Session; - m_Session = new UDPSession(m_Service, m_LocalDest, m_LocalEndpoint, *m_RemoteIdent, LocalPort, RemotePort); - auto dgram = m_LocalDest->CreateDatagramDestination(); + m_Session = new UDPSession(m_Service, m_LocalEndpoint, m_LocalDest, m_LocalEndpoint, *m_RemoteIdent, LocalPort, RemotePort); dgram->SetReceiver(std::bind(&I2PUDPClientTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, diff --git a/I2PTunnel.h b/I2PTunnel.h index 232ed2ef..d2b895df 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -152,7 +152,7 @@ namespace client uint8_t m_Buffer[I2P_UDP_MAX_MTU]; - UDPSession(boost::asio::io_service & ios, std::shared_ptr localDestination, boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash ident, uint16_t ourPort, uint16_t theirPort); + UDPSession(boost::asio::io_service & ios, boost::asio::ip::udp::endpoint localEndpoint, std::shared_ptr localDestination, boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash ident, uint16_t ourPort, uint16_t theirPort); void HandleReceived(const boost::system::error_code & ecode, std::size_t len); void Receive();