post work to io service

pull/628/head
Jeff Becker 8 years ago
parent bee34a3222
commit f5e2899275
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B

@ -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<I2PUDPServerTunnel>(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");

@ -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<i2p::client::ClientDestination> 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));
}

@ -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);

Loading…
Cancel
Save