Browse Source

post work to io service

pull/628/head
Jeff Becker 8 years ago
parent
commit
f5e2899275
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 8
      ClientContext.cpp
  2. 19
      I2PTunnel.cpp
  3. 2
      I2PTunnel.h

8
ClientContext.cpp

@ -88,9 +88,6 @@ namespace client
} }
} }
// I2P tunnels
ReadTunnels ();
if ( m_ServiceThread == nullptr ) { if ( m_ServiceThread == nullptr ) {
m_ServiceThread = new std::thread([&] () { m_ServiceThread = new std::thread([&] () {
LogPrint(eLogInfo, "ClientContext: starting service"); LogPrint(eLogInfo, "ClientContext: starting service");
@ -101,6 +98,10 @@ namespace client
} }
// I2P tunnels
ReadTunnels ();
// SAM // SAM
bool sam; i2p::config::GetOption("sam.enabled", sam); bool sam; i2p::config::GetOption("sam.enabled", sam);
if (sam) { if (sam) {
@ -468,6 +469,7 @@ namespace client
std::make_pair( std::make_pair(
localDestination->GetIdentHash(), port), localDestination->GetIdentHash(), port),
std::unique_ptr<I2PUDPServerTunnel>(serverTunnel))).second) { std::unique_ptr<I2PUDPServerTunnel>(serverTunnel))).second) {
serverTunnel->Start();
LogPrint(eLogInfo, "Clients: 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 { } else {
LogPrint(eLogError, "Clients: I2P Server Forward for destination/port ", m_AddressBook.ToAddress(localDestination->GetIdentHash()), "/", port, "already exists"); LogPrint(eLogError, "Clients: I2P Server Forward for destination/port ", m_AddressBook.ToAddress(localDestination->GetIdentHash()), "/", port, "already exists");

19
I2PTunnel.cpp

@ -569,13 +569,13 @@ namespace client
LogPrint(eLogDebug, "UDPSesssion: HandleRecveived"); LogPrint(eLogDebug, "UDPSesssion: HandleRecveived");
if(!ecode) { if(!ecode) {
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint); LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
auto dgram = m_Destination->GetDatagramDestination(); LastActivity = i2p::util::GetMillisecondsSinceEpoch();
if(dgram) { m_Destination->GetService().post([&, len] () {
LastActivity = i2p::util::GetMillisecondsSinceEpoch(); auto dgram = m_Destination->GetDatagramDestination();
dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0); if (dgram) {
} else { dgram->SendDatagramTo(m_Buffer, len, Identity, 0, 0);
LogPrint(eLogWarning, "UDPSession: no datagram destination"); }
} });
Receive(); Receive();
} else { } else {
LogPrint(eLogError, "UDPSession: ", ecode.message()); LogPrint(eLogError, "UDPSession: ", ecode.message());
@ -602,6 +602,10 @@ namespace client
LogPrint(eLogInfo, "UDPServer: done"); 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<i2p::client::ClientDestination> localDestination, uint16_t remotePort, boost::asio::io_service & service) : 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) :
m_Session(nullptr), m_Session(nullptr),
m_RemoteDest(remoteDest), m_RemoteDest(remoteDest),
@ -624,6 +628,7 @@ namespace client
void I2PUDPClientTunnel::Start() { void I2PUDPClientTunnel::Start() {
m_LocalDest->Start();
if (m_ResolveThread == nullptr) if (m_ResolveThread == nullptr)
m_ResolveThread = new std::thread(std::bind(&I2PUDPClientTunnel::TryResolving, this)); m_ResolveThread = new std::thread(std::bind(&I2PUDPClientTunnel::TryResolving, this));
} }

2
I2PTunnel.h

@ -167,7 +167,7 @@ namespace client
~I2PUDPServerTunnel(); ~I2PUDPServerTunnel();
/** expire stale udp conversations */ /** expire stale udp conversations */
void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT); void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT);
void Start();
private: private:
void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len); 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); UDPSession & ObtainUDPSession(const i2p::data::IdentityEx& from, uint16_t localPort, uint16_t remotePort);

Loading…
Cancel
Save