From f5e28992750a2d3497e8c761a3c4cf6d4ef1cd00 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 22 Aug 2016 13:04:36 -0400 Subject: [PATCH] post work to io service --- ClientContext.cpp | 10 ++++++---- I2PTunnel.cpp | 19 ++++++++++++------- I2PTunnel.h | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index 0b9b1f60..6b7e58bc 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -87,9 +87,6 @@ namespace client LogPrint(eLogError, "Clients: Exception in SOCKS Proxy: ", e.what()); } } - - // I2P tunnels - ReadTunnels (); if ( m_ServiceThread == nullptr ) { m_ServiceThread = new std::thread([&] () { @@ -99,7 +96,11 @@ namespace client }); ScheduleCleanupUDP(); } - + + + // I2P tunnels + ReadTunnels (); + // SAM bool sam; i2p::config::GetOption("sam.enabled", sam); @@ -468,6 +469,7 @@ namespace client std::make_pair( localDestination->GetIdentHash(), port), std::unique_ptr(serverTunnel))).second) { + serverTunnel->Start(); 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"); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index ac64186c..ea0f6122 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -569,13 +569,13 @@ namespace client LogPrint(eLogDebug, "UDPSesssion: HandleRecveived"); if(!ecode) { LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint); - auto dgram = m_Destination->GetDatagramDestination(); - if(dgram) { - LastActivity = i2p::util::GetMillisecondsSinceEpoch(); - dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0); - } else { - LogPrint(eLogWarning, "UDPSession: no datagram destination"); - } + LastActivity = i2p::util::GetMillisecondsSinceEpoch(); + m_Destination->GetService().post([&, len] () { + auto dgram = m_Destination->GetDatagramDestination(); + if (dgram) { + dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0); + } + }); Receive(); } else { LogPrint(eLogError, "UDPSession: ", ecode.message()); @@ -602,6 +602,10 @@ namespace client LogPrint(eLogInfo, "UDPServer: done"); } + void I2PUDPServerTunnel::Start() { + m_LocalDest->Start(); + } + I2PUDPClientTunnel::I2PUDPClientTunnel(const std::string & name, const std::string &remoteDest, boost::asio::ip::udp::endpoint localEndpoint, std::shared_ptr localDestination, uint16_t remotePort, boost::asio::io_service & service) : m_Session(nullptr), m_RemoteDest(remoteDest), @@ -624,6 +628,7 @@ namespace client void I2PUDPClientTunnel::Start() { + m_LocalDest->Start(); if (m_ResolveThread == nullptr) m_ResolveThread = new std::thread(std::bind(&I2PUDPClientTunnel::TryResolving, this)); } diff --git a/I2PTunnel.h b/I2PTunnel.h index ca5c8cc9..64e68640 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -167,7 +167,7 @@ namespace client ~I2PUDPServerTunnel(); /** expire stale udp conversations */ void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT); - + void Start(); private: void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len); UDPSession & ObtainUDPSession(const i2p::data::IdentityEx& from, uint16_t localPort, uint16_t remotePort);