post work to io service

This commit is contained in:
Jeff Becker 2016-08-22 13:04:36 -04:00
parent bee34a3222
commit f5e2899275
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
3 changed files with 19 additions and 12 deletions

View File

@ -88,9 +88,6 @@ namespace client
}
}
// I2P tunnels
ReadTunnels ();
if ( m_ServiceThread == nullptr ) {
m_ServiceThread = new std::thread([&] () {
LogPrint(eLogInfo, "ClientContext: starting service");
@ -101,6 +98,10 @@ namespace client
}
// I2P tunnels
ReadTunnels ();
// SAM
bool sam; i2p::config::GetOption("sam.enabled", sam);
if (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");

View File

@ -569,13 +569,13 @@ namespace client
LogPrint(eLogDebug, "UDPSesssion: HandleRecveived");
if(!ecode) {
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
LastActivity = i2p::util::GetMillisecondsSinceEpoch();
m_Destination->GetService().post([&, len] () {
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");
}
});
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));
}

View File

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