mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
support boost 1.87
This commit is contained in:
parent
3474538697
commit
ffd18baf30
|
@ -1486,8 +1486,8 @@ namespace http {
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPServer::HTTPServer (const std::string& address, int port):
|
HTTPServer::HTTPServer (const std::string& address, int port):
|
||||||
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service),
|
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service.get_executor ()),
|
||||||
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string(address), port)),
|
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::make_address(address), port)),
|
||||||
m_Hostname(address)
|
m_Hostname(address)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,8 @@ namespace http
|
||||||
|
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
std::unique_ptr<std::thread> m_Thread;
|
std::unique_ptr<std::thread> m_Thread;
|
||||||
boost::asio::io_service m_Service;
|
boost::asio::io_context m_Service;
|
||||||
boost::asio::io_service::work m_Work;
|
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_Work;
|
||||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||||
std::string m_Hostname;
|
std::string m_Hostname;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace client
|
||||||
{
|
{
|
||||||
I2PControlService::I2PControlService (const std::string& address, int port):
|
I2PControlService::I2PControlService (const std::string& address, int port):
|
||||||
m_IsRunning (false), m_Thread (nullptr),
|
m_IsRunning (false), m_Thread (nullptr),
|
||||||
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)),
|
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(address), port)),
|
||||||
m_SSLContext (boost::asio::ssl::context::sslv23),
|
m_SSLContext (boost::asio::ssl::context::sslv23),
|
||||||
m_ShutdownTimer (m_Service)
|
m_ShutdownTimer (m_Service)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2022, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -88,7 +88,7 @@ namespace client
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
std::thread * m_Thread;
|
std::thread * m_Thread;
|
||||||
|
|
||||||
boost::asio::io_service m_Service;
|
boost::asio::io_context m_Service;
|
||||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||||
boost::asio::ssl::context m_SSLContext;
|
boost::asio::ssl::context m_SSLContext;
|
||||||
boost::asio::deadline_timer m_ShutdownTimer;
|
boost::asio::deadline_timer m_ShutdownTimer;
|
||||||
|
|
|
@ -294,7 +294,7 @@ namespace client
|
||||||
if (m_IsPublic)
|
if (m_IsPublic)
|
||||||
{
|
{
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([s](void)
|
boost::asio::post (m_Service, [s](void)
|
||||||
{
|
{
|
||||||
s->m_PublishVerificationTimer.cancel ();
|
s->m_PublishVerificationTimer.cancel ();
|
||||||
s->Publish ();
|
s->Publish ();
|
||||||
|
@ -322,7 +322,7 @@ namespace client
|
||||||
memcpy (data.k, key, 32);
|
memcpy (data.k, key, 32);
|
||||||
memcpy (data.t, tag, 32);
|
memcpy (data.t, tag, 32);
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([s,data](void)
|
boost::asio::post (m_Service, [s,data](void)
|
||||||
{
|
{
|
||||||
s->AddSessionKey (data.k, data.t);
|
s->AddSessionKey (data.k, data.t);
|
||||||
});
|
});
|
||||||
|
@ -339,7 +339,7 @@ namespace client
|
||||||
memcpy (data.k, key, 32);
|
memcpy (data.k, key, 32);
|
||||||
data.t = tag;
|
data.t = tag;
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([s,data](void)
|
boost::asio::post (m_Service, [s,data](void)
|
||||||
{
|
{
|
||||||
s->AddECIESx25519Key (data.k, data.t);
|
s->AddECIESx25519Key (data.k, data.t);
|
||||||
});
|
});
|
||||||
|
@ -355,7 +355,7 @@ namespace client
|
||||||
m_IncomingMsgsQueue.push_back (msg);
|
m_IncomingMsgsQueue.push_back (msg);
|
||||||
}
|
}
|
||||||
if (empty)
|
if (empty)
|
||||||
m_Service.post([s = shared_from_this ()]()
|
boost::asio::post (m_Service, [s = shared_from_this ()]()
|
||||||
{
|
{
|
||||||
std::list<std::shared_ptr<I2NPMessage> > receivedMsgs;
|
std::list<std::shared_ptr<I2NPMessage> > receivedMsgs;
|
||||||
{
|
{
|
||||||
|
@ -370,7 +370,7 @@ namespace client
|
||||||
void LeaseSetDestination::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
void LeaseSetDestination::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
uint32_t msgID = bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET);
|
uint32_t msgID = bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET);
|
||||||
m_Service.post (std::bind (&LeaseSetDestination::HandleDeliveryStatusMessage, shared_from_this (), msgID));
|
boost::asio::post (m_Service, std::bind (&LeaseSetDestination::HandleDeliveryStatusMessage, shared_from_this (), msgID));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len)
|
void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len)
|
||||||
|
@ -608,7 +608,7 @@ namespace client
|
||||||
void LeaseSetDestination::SetLeaseSetUpdated (bool post)
|
void LeaseSetDestination::SetLeaseSetUpdated (bool post)
|
||||||
{
|
{
|
||||||
if (post)
|
if (post)
|
||||||
m_Service.post([s = shared_from_this ()]() { s->UpdateLeaseSet (); });
|
boost::asio::post (m_Service, [s = shared_from_this ()]() { s->UpdateLeaseSet (); });
|
||||||
else
|
else
|
||||||
UpdateLeaseSet ();
|
UpdateLeaseSet ();
|
||||||
}
|
}
|
||||||
|
@ -690,7 +690,7 @@ namespace client
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
msg->onDrop = [s]()
|
msg->onDrop = [s]()
|
||||||
{
|
{
|
||||||
s->GetService ().post([s]()
|
boost::asio::post (s->GetService (), [s]()
|
||||||
{
|
{
|
||||||
s->m_PublishConfirmationTimer.cancel ();
|
s->m_PublishConfirmationTimer.cancel ();
|
||||||
s->HandlePublishConfirmationTimer (boost::system::error_code());
|
s->HandlePublishConfirmationTimer (boost::system::error_code());
|
||||||
|
@ -775,10 +775,10 @@ namespace client
|
||||||
if (!m_Pool || !IsReady ())
|
if (!m_Pool || !IsReady ())
|
||||||
{
|
{
|
||||||
if (requestComplete)
|
if (requestComplete)
|
||||||
m_Service.post ([requestComplete](void){requestComplete (nullptr);});
|
boost::asio::post (m_Service, [requestComplete](void){requestComplete (nullptr);});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_Service.post (std::bind (&LeaseSetDestination::RequestLeaseSet, shared_from_this (), dest, requestComplete, nullptr));
|
boost::asio::post (m_Service, std::bind (&LeaseSetDestination::RequestLeaseSet, shared_from_this (), dest, requestComplete, nullptr));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ namespace client
|
||||||
if (!dest || !m_Pool || !IsReady ())
|
if (!dest || !m_Pool || !IsReady ())
|
||||||
{
|
{
|
||||||
if (requestComplete)
|
if (requestComplete)
|
||||||
m_Service.post ([requestComplete](void){requestComplete (nullptr);});
|
boost::asio::post (m_Service, [requestComplete](void){requestComplete (nullptr);});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto storeHash = dest->GetStoreHash ();
|
auto storeHash = dest->GetStoreHash ();
|
||||||
|
@ -795,17 +795,17 @@ namespace client
|
||||||
if (leaseSet)
|
if (leaseSet)
|
||||||
{
|
{
|
||||||
if (requestComplete)
|
if (requestComplete)
|
||||||
m_Service.post ([requestComplete, leaseSet](void){requestComplete (leaseSet);});
|
boost::asio::post (m_Service, [requestComplete, leaseSet](void){requestComplete (leaseSet);});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_Service.post (std::bind (&LeaseSetDestination::RequestLeaseSet, shared_from_this (), storeHash, requestComplete, dest));
|
boost::asio::post (m_Service, std::bind (&LeaseSetDestination::RequestLeaseSet, shared_from_this (), storeHash, requestComplete, dest));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeaseSetDestination::CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify)
|
void LeaseSetDestination::CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify)
|
||||||
{
|
{
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([dest, notify, s](void)
|
boost::asio::post (m_Service, [dest, notify, s](void)
|
||||||
{
|
{
|
||||||
auto it = s->m_LeaseSetRequests.find (dest);
|
auto it = s->m_LeaseSetRequests.find (dest);
|
||||||
if (it != s->m_LeaseSetRequests.end ())
|
if (it != s->m_LeaseSetRequests.end ())
|
||||||
|
@ -903,7 +903,7 @@ namespace client
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
msg->onDrop = [s, dest, request]()
|
msg->onDrop = [s, dest, request]()
|
||||||
{
|
{
|
||||||
s->GetService ().post([s, dest, request]()
|
boost::asio::post (s->GetService (), [s, dest, request]()
|
||||||
{
|
{
|
||||||
s->SendNextLeaseSetRequest (dest, request);
|
s->SendNextLeaseSetRequest (dest, request);
|
||||||
});
|
});
|
||||||
|
@ -1215,7 +1215,7 @@ namespace client
|
||||||
if (leaseSet)
|
if (leaseSet)
|
||||||
{
|
{
|
||||||
auto stream = CreateStream (leaseSet, port);
|
auto stream = CreateStream (leaseSet, port);
|
||||||
GetService ().post ([streamRequestComplete, stream]()
|
boost::asio::post (GetService (), [streamRequestComplete, stream]()
|
||||||
{
|
{
|
||||||
streamRequestComplete(stream);
|
streamRequestComplete(stream);
|
||||||
});
|
});
|
||||||
|
|
|
@ -406,7 +406,7 @@ namespace transport
|
||||||
|
|
||||||
void NTCP2Session::Done ()
|
void NTCP2Session::Done ()
|
||||||
{
|
{
|
||||||
m_Server.GetService ().post (std::bind (&NTCP2Session::Terminate, shared_from_this ()));
|
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::Terminate, shared_from_this ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCP2Session::Established ()
|
void NTCP2Session::Established ()
|
||||||
|
@ -508,7 +508,7 @@ namespace transport
|
||||||
{
|
{
|
||||||
// we don't care about padding, send SessionCreated and close session
|
// we don't care about padding, send SessionCreated and close session
|
||||||
SendSessionCreated ();
|
SendSessionCreated ();
|
||||||
m_Server.GetService ().post (std::bind (&NTCP2Session::Terminate, shared_from_this ()));
|
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::Terminate, shared_from_this ()));
|
||||||
}
|
}
|
||||||
else if (paddingLen > 0)
|
else if (paddingLen > 0)
|
||||||
{
|
{
|
||||||
|
@ -1296,7 +1296,7 @@ namespace transport
|
||||||
void NTCP2Session::SendTerminationAndTerminate (NTCP2TerminationReason reason)
|
void NTCP2Session::SendTerminationAndTerminate (NTCP2TerminationReason reason)
|
||||||
{
|
{
|
||||||
SendTermination (reason);
|
SendTermination (reason);
|
||||||
m_Server.GetService ().post (std::bind (&NTCP2Session::Terminate, shared_from_this ())); // let termination message go
|
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::Terminate, shared_from_this ())); // let termination message go
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCP2Session::SendI2NPMessages (std::list<std::shared_ptr<I2NPMessage> >& msgs)
|
void NTCP2Session::SendI2NPMessages (std::list<std::shared_ptr<I2NPMessage> >& msgs)
|
||||||
|
@ -1313,7 +1313,7 @@ namespace transport
|
||||||
m_IntermediateQueue.splice (m_IntermediateQueue.end (), msgs);
|
m_IntermediateQueue.splice (m_IntermediateQueue.end (), msgs);
|
||||||
}
|
}
|
||||||
if (empty)
|
if (empty)
|
||||||
m_Server.GetService ().post (std::bind (&NTCP2Session::PostI2NPMessages, shared_from_this ()));
|
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::PostI2NPMessages, shared_from_this ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCP2Session::PostI2NPMessages ()
|
void NTCP2Session::PostI2NPMessages ()
|
||||||
|
@ -1350,7 +1350,7 @@ namespace transport
|
||||||
void NTCP2Session::SendLocalRouterInfo (bool update)
|
void NTCP2Session::SendLocalRouterInfo (bool update)
|
||||||
{
|
{
|
||||||
if (update || !IsOutgoing ()) // we send it in SessionConfirmed for outgoing session
|
if (update || !IsOutgoing ()) // we send it in SessionConfirmed for outgoing session
|
||||||
m_Server.GetService ().post (std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ()));
|
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NTCP2Server::NTCP2Server ():
|
NTCP2Server::NTCP2Server ():
|
||||||
|
@ -1374,14 +1374,13 @@ namespace transport
|
||||||
{
|
{
|
||||||
LogPrint(eLogInfo, "NTCP2: Using proxy to connect to peers");
|
LogPrint(eLogInfo, "NTCP2: Using proxy to connect to peers");
|
||||||
// TODO: resolve proxy until it is resolved
|
// TODO: resolve proxy until it is resolved
|
||||||
boost::asio::ip::tcp::resolver::query q(m_ProxyAddress, std::to_string(m_ProxyPort));
|
|
||||||
boost::system::error_code e;
|
boost::system::error_code e;
|
||||||
auto itr = m_Resolver.resolve(q, e);
|
auto itr = m_Resolver.resolve(m_ProxyAddress, std::to_string(m_ProxyPort), e);
|
||||||
if(e)
|
if(e)
|
||||||
LogPrint(eLogCritical, "NTCP2: Failed to resolve proxy ", e.message());
|
LogPrint(eLogCritical, "NTCP2: Failed to resolve proxy ", e.message());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_ProxyEndpoint.reset (new boost::asio::ip::tcp::endpoint(*itr));
|
m_ProxyEndpoint.reset (new boost::asio::ip::tcp::endpoint(*itr.begin ()));
|
||||||
if (m_ProxyEndpoint)
|
if (m_ProxyEndpoint)
|
||||||
LogPrint(eLogDebug, "NTCP2: m_ProxyEndpoint ", *m_ProxyEndpoint);
|
LogPrint(eLogDebug, "NTCP2: m_ProxyEndpoint ", *m_ProxyEndpoint);
|
||||||
}
|
}
|
||||||
|
@ -1541,7 +1540,7 @@ namespace transport
|
||||||
}
|
}
|
||||||
LogPrint (eLogDebug, "NTCP2: Connecting to ", conn->GetRemoteEndpoint (),
|
LogPrint (eLogDebug, "NTCP2: Connecting to ", conn->GetRemoteEndpoint (),
|
||||||
" (", i2p::data::GetIdentHashAbbreviation (conn->GetRemoteIdentity ()->GetIdentHash ()), ")");
|
" (", i2p::data::GetIdentHashAbbreviation (conn->GetRemoteIdentity ()->GetIdentHash ()), ")");
|
||||||
GetService ().post([this, conn]()
|
boost::asio::post (GetService (), [this, conn]()
|
||||||
{
|
{
|
||||||
if (this->AddNTCP2Session (conn))
|
if (this->AddNTCP2Session (conn))
|
||||||
{
|
{
|
||||||
|
@ -1762,7 +1761,7 @@ namespace transport
|
||||||
LogPrint (eLogError, "NTCP2: Can't connect to unspecified address");
|
LogPrint (eLogError, "NTCP2: Can't connect to unspecified address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GetService().post([this, conn]()
|
boost::asio::post (GetService(), [this, conn]()
|
||||||
{
|
{
|
||||||
if (this->AddNTCP2Session (conn))
|
if (this->AddNTCP2Session (conn))
|
||||||
{
|
{
|
||||||
|
@ -1860,7 +1859,7 @@ namespace transport
|
||||||
{
|
{
|
||||||
readbuff->commit(transferred);
|
readbuff->commit(transferred);
|
||||||
i2p::http::HTTPRes res;
|
i2p::http::HTTPRes res;
|
||||||
if(res.parse(boost::asio::buffer_cast<const char*>(readbuff->data()), readbuff->size()) > 0)
|
if(res.parse(std::string {boost::asio::buffers_begin(readbuff->data ()), boost::asio::buffers_begin(readbuff->data ()) + readbuff->size ()}) > 0)
|
||||||
{
|
{
|
||||||
if(res.code == 200)
|
if(res.code == 200)
|
||||||
{
|
{
|
||||||
|
|
|
@ -179,7 +179,7 @@ namespace data
|
||||||
|
|
||||||
void NetDbRequests::RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r)
|
void NetDbRequests::RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r)
|
||||||
{
|
{
|
||||||
GetIOService ().post ([this, ident, r]()
|
boost::asio::post (GetIOService (), [this, ident, r]()
|
||||||
{
|
{
|
||||||
std::shared_ptr<RequestedDestination> request;
|
std::shared_ptr<RequestedDestination> request;
|
||||||
auto it = m_RequestedDestinations.find (ident);
|
auto it = m_RequestedDestinations.find (ident);
|
||||||
|
@ -267,7 +267,7 @@ namespace data
|
||||||
{
|
{
|
||||||
if (dest->IsActive ())
|
if (dest->IsActive ())
|
||||||
{
|
{
|
||||||
s->GetIOService ().post ([s, dest]()
|
boost::asio::post (s->GetIOService (), [s, dest]()
|
||||||
{
|
{
|
||||||
if (dest->IsActive ()) s->SendNextRequest (dest);
|
if (dest->IsActive ()) s->SendNextRequest (dest);
|
||||||
});
|
});
|
||||||
|
@ -345,7 +345,7 @@ namespace data
|
||||||
|
|
||||||
void NetDbRequests::PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg)
|
void NetDbRequests::PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
GetIOService ().post ([this, msg]()
|
boost::asio::post (GetIOService (), [this, msg]()
|
||||||
{
|
{
|
||||||
HandleDatabaseSearchReplyMsg (msg);
|
HandleDatabaseSearchReplyMsg (msg);
|
||||||
});
|
});
|
||||||
|
@ -431,7 +431,7 @@ namespace data
|
||||||
void NetDbRequests::PostRequestDestination (const IdentHash& destination,
|
void NetDbRequests::PostRequestDestination (const IdentHash& destination,
|
||||||
const RequestedDestination::RequestComplete& requestComplete, bool direct)
|
const RequestedDestination::RequestComplete& requestComplete, bool direct)
|
||||||
{
|
{
|
||||||
GetIOService ().post ([this, destination, requestComplete, direct]()
|
boost::asio::post (GetIOService (), [this, destination, requestComplete, direct]()
|
||||||
{
|
{
|
||||||
RequestDestination (destination, requestComplete, direct);
|
RequestDestination (destination, requestComplete, direct);
|
||||||
});
|
});
|
||||||
|
|
|
@ -562,11 +562,10 @@ namespace data
|
||||||
if(proxyUrl.schema.size())
|
if(proxyUrl.schema.size())
|
||||||
{
|
{
|
||||||
// proxy connection
|
// proxy connection
|
||||||
auto it = boost::asio::ip::tcp::resolver(service).resolve (
|
auto it = boost::asio::ip::tcp::resolver(service).resolve (proxyUrl.host, std::to_string(proxyUrl.port), ecode);
|
||||||
boost::asio::ip::tcp::resolver::query (proxyUrl.host, std::to_string(proxyUrl.port)), ecode);
|
|
||||||
if(!ecode)
|
if(!ecode)
|
||||||
{
|
{
|
||||||
s.lowest_layer().connect(*it, ecode);
|
s.lowest_layer().connect(*it.begin (), ecode);
|
||||||
if(!ecode)
|
if(!ecode)
|
||||||
{
|
{
|
||||||
auto & sock = s.next_layer();
|
auto & sock = s.next_layer();
|
||||||
|
@ -599,7 +598,7 @@ namespace data
|
||||||
LogPrint(eLogError, "Reseed: HTTP CONNECT read error: ", ecode.message());
|
LogPrint(eLogError, "Reseed: HTTP CONNECT read error: ", ecode.message());
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if(proxyRes.parse(boost::asio::buffer_cast<const char *>(readbuf.data()), readbuf.size()) <= 0)
|
if(proxyRes.parse(std::string {boost::asio::buffers_begin(readbuf.data ()), boost::asio::buffers_begin(readbuf.data ()) + readbuf.size ()}) <= 0)
|
||||||
{
|
{
|
||||||
sock.close();
|
sock.close();
|
||||||
LogPrint(eLogError, "Reseed: HTTP CONNECT malformed reply");
|
LogPrint(eLogError, "Reseed: HTTP CONNECT malformed reply");
|
||||||
|
@ -638,13 +637,11 @@ namespace data
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// direct connection
|
// direct connection
|
||||||
auto it = boost::asio::ip::tcp::resolver(service).resolve (
|
auto endpoints = boost::asio::ip::tcp::resolver(service).resolve (url.host, std::to_string(url.port), ecode);
|
||||||
boost::asio::ip::tcp::resolver::query (url.host, std::to_string(url.port)), ecode);
|
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
boost::asio::ip::tcp::resolver::iterator end;
|
for (auto it = endpoints.begin (); it != endpoints.end ();)
|
||||||
while (it != end)
|
|
||||||
{
|
{
|
||||||
boost::asio::ip::tcp::endpoint ep = *it;
|
boost::asio::ip::tcp::endpoint ep = *it;
|
||||||
bool supported = false;
|
bool supported = false;
|
||||||
|
@ -749,14 +746,11 @@ namespace data
|
||||||
boost::asio::io_context service;
|
boost::asio::io_context service;
|
||||||
boost::asio::ip::tcp::socket s(service, boost::asio::ip::tcp::v6());
|
boost::asio::ip::tcp::socket s(service, boost::asio::ip::tcp::v6());
|
||||||
|
|
||||||
auto it = boost::asio::ip::tcp::resolver(service).resolve (
|
auto endpoints = boost::asio::ip::tcp::resolver(service).resolve (url.host, std::to_string(url.port), ecode);
|
||||||
boost::asio::ip::tcp::resolver::query (url.host, std::to_string(url.port)), ecode);
|
|
||||||
|
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
boost::asio::ip::tcp::resolver::iterator end;
|
for (auto it = endpoints.begin (); it != endpoints.end ();)
|
||||||
while (it != end)
|
|
||||||
{
|
{
|
||||||
boost::asio::ip::tcp::endpoint ep = *it;
|
boost::asio::ip::tcp::endpoint ep = *it;
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
boost::asio::ip::address addr;
|
boost::asio::ip::address addr;
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
addr = boost::asio::ip::address::from_string (host);
|
addr = boost::asio::ip::make_address (host);
|
||||||
if (!addr.is_v4())
|
if (!addr.is_v4())
|
||||||
addr = boost::asio::ip::address_v4 ();
|
addr = boost::asio::ip::address_v4 ();
|
||||||
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
||||||
|
@ -161,7 +161,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
boost::asio::ip::address addr;
|
boost::asio::ip::address addr;
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
addr = boost::asio::ip::address::from_string (host);
|
addr = boost::asio::ip::make_address (host);
|
||||||
if (!addr.is_v4())
|
if (!addr.is_v4())
|
||||||
addr = boost::asio::ip::address_v4 ();
|
addr = boost::asio::ip::address_v4 ();
|
||||||
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
||||||
|
@ -192,7 +192,7 @@ namespace i2p
|
||||||
ntcp2Host = host;
|
ntcp2Host = host;
|
||||||
boost::asio::ip::address addr;
|
boost::asio::ip::address addr;
|
||||||
if (!ntcp2Host.empty ())
|
if (!ntcp2Host.empty ())
|
||||||
addr = boost::asio::ip::address::from_string (ntcp2Host);
|
addr = boost::asio::ip::make_address (ntcp2Host);
|
||||||
if (!addr.is_v6())
|
if (!addr.is_v6())
|
||||||
addr = boost::asio::ip::address_v6 ();
|
addr = boost::asio::ip::address_v6 ();
|
||||||
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
||||||
|
@ -211,7 +211,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
boost::asio::ip::address addr;
|
boost::asio::ip::address addr;
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
addr = boost::asio::ip::address::from_string (host);
|
addr = boost::asio::ip::make_address (host);
|
||||||
if (!addr.is_v6())
|
if (!addr.is_v6())
|
||||||
addr = boost::asio::ip::address_v6 ();
|
addr = boost::asio::ip::address_v6 ();
|
||||||
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
routerInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
||||||
|
@ -802,7 +802,7 @@ namespace i2p
|
||||||
i2p::config::GetOption("host", ntcp2Host);
|
i2p::config::GetOption("host", ntcp2Host);
|
||||||
if (!ntcp2Host.empty () && ntcp2Port)
|
if (!ntcp2Host.empty () && ntcp2Port)
|
||||||
{
|
{
|
||||||
auto addr = boost::asio::ip::address::from_string (ntcp2Host);
|
auto addr = boost::asio::ip::make_address (ntcp2Host);
|
||||||
if (addr.is_v6 ())
|
if (addr.is_v6 ())
|
||||||
{
|
{
|
||||||
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
||||||
|
@ -831,7 +831,7 @@ namespace i2p
|
||||||
std::string host; i2p::config::GetOption("host", host);
|
std::string host; i2p::config::GetOption("host", host);
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
{
|
{
|
||||||
auto addr = boost::asio::ip::address::from_string (host);
|
auto addr = boost::asio::ip::make_address (host);
|
||||||
if (addr.is_v6 ())
|
if (addr.is_v6 ())
|
||||||
{
|
{
|
||||||
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
||||||
|
@ -900,7 +900,7 @@ namespace i2p
|
||||||
std::string host; i2p::config::GetOption("host", host);
|
std::string host; i2p::config::GetOption("host", host);
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
{
|
{
|
||||||
auto addr = boost::asio::ip::address::from_string (host);
|
auto addr = boost::asio::ip::make_address (host);
|
||||||
if (addr.is_v4 ())
|
if (addr.is_v4 ())
|
||||||
{
|
{
|
||||||
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
m_RouterInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv, addr, ntcp2Port);
|
||||||
|
@ -930,7 +930,7 @@ namespace i2p
|
||||||
std::string host; i2p::config::GetOption("host", host);
|
std::string host; i2p::config::GetOption("host", host);
|
||||||
if (!host.empty ())
|
if (!host.empty ())
|
||||||
{
|
{
|
||||||
auto addr = boost::asio::ip::address::from_string (host);
|
auto addr = boost::asio::ip::make_address (host);
|
||||||
if (addr.is_v4 ())
|
if (addr.is_v4 ())
|
||||||
{
|
{
|
||||||
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
m_RouterInfo.AddSSU2Address (m_SSU2Keys->staticPublicKey, m_SSU2Keys->intro, addr, ssu2Port);
|
||||||
|
@ -1185,7 +1185,7 @@ namespace i2p
|
||||||
void RouterContext::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
if (m_Service)
|
if (m_Service)
|
||||||
m_Service->GetService ().post (std::bind (&RouterContext::PostGarlicMessage, this, msg));
|
boost::asio::post (m_Service->GetService (), std::bind (&RouterContext::PostGarlicMessage, this, msg));
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Router: service is NULL");
|
LogPrint (eLogError, "Router: service is NULL");
|
||||||
}
|
}
|
||||||
|
@ -1213,7 +1213,7 @@ namespace i2p
|
||||||
void RouterContext::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
void RouterContext::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
if (m_Service)
|
if (m_Service)
|
||||||
m_Service->GetService ().post (std::bind (&RouterContext::PostDeliveryStatusMessage, this, msg));
|
boost::asio::post (m_Service->GetService (), std::bind (&RouterContext::PostDeliveryStatusMessage, this, msg));
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Router: service is NULL");
|
LogPrint (eLogError, "Router: service is NULL");
|
||||||
}
|
}
|
||||||
|
@ -1242,7 +1242,7 @@ namespace i2p
|
||||||
} data;
|
} data;
|
||||||
memcpy (data.k, key, 32);
|
memcpy (data.k, key, 32);
|
||||||
data.t = tag;
|
data.t = tag;
|
||||||
m_Service->GetService ().post ([this,data](void)
|
boost::asio::post (m_Service->GetService (), [this,data](void)
|
||||||
{
|
{
|
||||||
AddECIESx25519Key (data.k, data.t);
|
AddECIESx25519Key (data.k, data.t);
|
||||||
});
|
});
|
||||||
|
@ -1408,7 +1408,7 @@ namespace i2p
|
||||||
auto onDrop = [this]()
|
auto onDrop = [this]()
|
||||||
{
|
{
|
||||||
if (m_Service)
|
if (m_Service)
|
||||||
m_Service->GetService ().post ([this]() { HandlePublishResendTimer (boost::system::error_code ()); });
|
boost::asio::post (m_Service->GetService (), [this]() { HandlePublishResendTimer (boost::system::error_code ()); });
|
||||||
};
|
};
|
||||||
if (i2p::transport::transports.IsConnected (floodfill->GetIdentHash ()) || // already connected
|
if (i2p::transport::transports.IsConnected (floodfill->GetIdentHash ()) || // already connected
|
||||||
(floodfill->IsReachableFrom (i2p::context.GetRouterInfo ()) && // are we able to connect
|
(floodfill->IsReachableFrom (i2p::context.GetRouterInfo ()) && // are we able to connect
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace garlic
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RouterService (): RunnableServiceWithWork ("Router") {};
|
RouterService (): RunnableServiceWithWork ("Router") {};
|
||||||
boost::asio::io_service& GetService () { return GetIOService (); };
|
auto& GetService () { return GetIOService (); };
|
||||||
void Start () { StartIOService (); };
|
void Start () { StartIOService (); };
|
||||||
void Stop () { StopIOService (); };
|
void Stop () { StopIOService (); };
|
||||||
};
|
};
|
||||||
|
|
|
@ -257,7 +257,7 @@ namespace data
|
||||||
if (!strcmp (key, "host"))
|
if (!strcmp (key, "host"))
|
||||||
{
|
{
|
||||||
boost::system::error_code ecode;
|
boost::system::error_code ecode;
|
||||||
address->host = boost::asio::ip::address::from_string (value, ecode);
|
address->host = boost::asio::ip::make_address (value, ecode);
|
||||||
if (!ecode && !address->host.is_unspecified ())
|
if (!ecode && !address->host.is_unspecified ())
|
||||||
{
|
{
|
||||||
if (!i2p::transport::transports.IsInReservedRange (address->host) ||
|
if (!i2p::transport::transports.IsInReservedRange (address->host) ||
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace transport
|
||||||
found = true;
|
found = true;
|
||||||
LogPrint (eLogDebug, "SSU2: Opening IPv4 socket at Start");
|
LogPrint (eLogDebug, "SSU2: Opening IPv4 socket at Start");
|
||||||
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV4, port));
|
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV4, port));
|
||||||
m_ReceiveService.GetService ().post(
|
boost::asio::post (m_ReceiveService.GetService (),
|
||||||
[this]()
|
[this]()
|
||||||
{
|
{
|
||||||
Receive (m_SocketV4);
|
Receive (m_SocketV4);
|
||||||
|
@ -93,7 +93,7 @@ namespace transport
|
||||||
found = true;
|
found = true;
|
||||||
LogPrint (eLogDebug, "SSU2: Opening IPv6 socket at Start");
|
LogPrint (eLogDebug, "SSU2: Opening IPv6 socket at Start");
|
||||||
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV6, port));
|
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV6, port));
|
||||||
m_ReceiveService.GetService ().post(
|
boost::asio::post (m_ReceiveService.GetService (),
|
||||||
[this]()
|
[this]()
|
||||||
{
|
{
|
||||||
Receive (m_SocketV6);
|
Receive (m_SocketV6);
|
||||||
|
@ -451,7 +451,7 @@ namespace transport
|
||||||
m_ReceivedPacketsQueue.push_back (packet);
|
m_ReceivedPacketsQueue.push_back (packet);
|
||||||
}
|
}
|
||||||
if (empty)
|
if (empty)
|
||||||
GetService ().post([this]() { HandleReceivedPacketsQueue (); });
|
boost::asio::post (GetService (), [this]() { HandleReceivedPacketsQueue (); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Server::InsertToReceivedPacketsQueue (std::list<Packet *>& packets)
|
void SSU2Server::InsertToReceivedPacketsQueue (std::list<Packet *>& packets)
|
||||||
|
@ -471,7 +471,7 @@ namespace transport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queueSize)
|
if (!queueSize)
|
||||||
GetService ().post([this]() { HandleReceivedPacketsQueue (); });
|
boost::asio::post (GetService (), [this]() { HandleReceivedPacketsQueue (); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Server::HandleReceivedPacketsQueue ()
|
void SSU2Server::HandleReceivedPacketsQueue ()
|
||||||
|
@ -522,7 +522,7 @@ namespace transport
|
||||||
|
|
||||||
void SSU2Server::RequestRemoveSession (uint64_t connID)
|
void SSU2Server::RequestRemoveSession (uint64_t connID)
|
||||||
{
|
{
|
||||||
GetService ().post ([connID, this]() { RemoveSession (connID); });
|
boost::asio::post (GetService (), [connID, this]() { RemoveSession (connID); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session)
|
void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session)
|
||||||
|
@ -550,7 +550,7 @@ namespace transport
|
||||||
// move unsent msgs to new session
|
// move unsent msgs to new session
|
||||||
oldSession->MoveSendQueue (session);
|
oldSession->MoveSendQueue (session);
|
||||||
// terminate existing
|
// terminate existing
|
||||||
GetService ().post (std::bind (&SSU2Session::RequestTermination, oldSession, eSSU2TerminationReasonReplacedByNewSession));
|
boost::asio::post (GetService (), std::bind (&SSU2Session::RequestTermination, oldSession, eSSU2TerminationReasonReplacedByNewSession));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -878,7 +878,7 @@ namespace transport
|
||||||
{
|
{
|
||||||
// session with router found, trying to send peer test if requested
|
// session with router found, trying to send peer test if requested
|
||||||
if (peerTest && existingSession->IsEstablished ())
|
if (peerTest && existingSession->IsEstablished ())
|
||||||
GetService ().post ([existingSession]() { existingSession->SendPeerTest (); });
|
boost::asio::post (GetService (), [existingSession]() { existingSession->SendPeerTest (); });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check is no pending session
|
// check is no pending session
|
||||||
|
@ -905,9 +905,9 @@ namespace transport
|
||||||
session->SetOnEstablished ([session]() {session->SendPeerTest (); });
|
session->SetOnEstablished ([session]() {session->SendPeerTest (); });
|
||||||
|
|
||||||
if (isValidEndpoint) // we know endpoint
|
if (isValidEndpoint) // we know endpoint
|
||||||
GetService ().post ([session]() { session->Connect (); });
|
boost::asio::post (GetService (), [session]() { session->Connect (); });
|
||||||
else if (address->UsesIntroducer ()) // we don't know endpoint yet
|
else if (address->UsesIntroducer ()) // we don't know endpoint yet
|
||||||
GetService ().post (std::bind (&SSU2Server::ConnectThroughIntroducer, this, session));
|
boost::asio::post (GetService (), std::bind (&SSU2Server::ConnectThroughIntroducer, this, session));
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1050,7 +1050,7 @@ namespace transport
|
||||||
if (!remoteAddr || !remoteAddr->IsPeerTesting () ||
|
if (!remoteAddr || !remoteAddr->IsPeerTesting () ||
|
||||||
(v4 && !remoteAddr->IsV4 ()) || (!v4 && !remoteAddr->IsV6 ())) return false;
|
(v4 && !remoteAddr->IsV4 ()) || (!v4 && !remoteAddr->IsV6 ())) return false;
|
||||||
if (session->IsEstablished ())
|
if (session->IsEstablished ())
|
||||||
GetService ().post ([session]() { session->SendPeerTest (); });
|
boost::asio::post (GetService (), [session]() { session->SendPeerTest (); });
|
||||||
else
|
else
|
||||||
session->SetOnEstablished ([session]() { session->SendPeerTest (); });
|
session->SetOnEstablished ([session]() { session->SendPeerTest (); });
|
||||||
return true;
|
return true;
|
||||||
|
@ -1764,7 +1764,7 @@ namespace transport
|
||||||
bool SSU2Server::SetProxy (const std::string& address, uint16_t port)
|
bool SSU2Server::SetProxy (const std::string& address, uint16_t port)
|
||||||
{
|
{
|
||||||
boost::system::error_code ecode;
|
boost::system::error_code ecode;
|
||||||
auto addr = boost::asio::ip::address::from_string (address, ecode);
|
auto addr = boost::asio::ip::make_address (address, ecode);
|
||||||
if (!ecode && !addr.is_unspecified () && port)
|
if (!ecode && !addr.is_unspecified () && port)
|
||||||
{
|
{
|
||||||
m_IsThroughProxy = true;
|
m_IsThroughProxy = true;
|
||||||
|
|
|
@ -667,7 +667,7 @@ namespace stream
|
||||||
{
|
{
|
||||||
// make sure that AsycReceive complete
|
// make sure that AsycReceive complete
|
||||||
auto s = shared_from_this();
|
auto s = shared_from_this();
|
||||||
m_Service.post ([s]()
|
boost::asio::post (m_Service, [s]()
|
||||||
{
|
{
|
||||||
s->m_ReceiveTimer.cancel ();
|
s->m_ReceiveTimer.cancel ();
|
||||||
});
|
});
|
||||||
|
@ -695,7 +695,7 @@ namespace stream
|
||||||
else if (handler)
|
else if (handler)
|
||||||
handler(boost::system::error_code ());
|
handler(boost::system::error_code ());
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([s, buffer]()
|
boost::asio::post (m_Service, [s, buffer]()
|
||||||
{
|
{
|
||||||
if (buffer)
|
if (buffer)
|
||||||
s->m_SendBuffer.Add (buffer);
|
s->m_SendBuffer.Add (buffer);
|
||||||
|
@ -1058,7 +1058,7 @@ namespace stream
|
||||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||||
|
|
||||||
p->len = size;
|
p->len = size;
|
||||||
m_Service.post (std::bind (&Stream::SendPacket, shared_from_this (), p));
|
boost::asio::post (m_Service, std::bind (&Stream::SendPacket, shared_from_this (), p));
|
||||||
LogPrint (eLogDebug, "Streaming: FIN sent, sSID=", m_SendStreamID);
|
LogPrint (eLogDebug, "Streaming: FIN sent, sSID=", m_SendStreamID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1855,7 +1855,7 @@ namespace stream
|
||||||
if (it == m_Streams.end ())
|
if (it == m_Streams.end ())
|
||||||
return false;
|
return false;
|
||||||
auto s = it->second;
|
auto s = it->second;
|
||||||
m_Owner->GetService ().post ([this, s] ()
|
boost::asio::post (m_Owner->GetService (), [this, s] ()
|
||||||
{
|
{
|
||||||
s->Close (); // try to send FIN
|
s->Close (); // try to send FIN
|
||||||
s->Terminate (false);
|
s->Terminate (false);
|
||||||
|
@ -1868,7 +1868,7 @@ namespace stream
|
||||||
{
|
{
|
||||||
m_Acceptor = acceptor; // we must set it immediately for IsAcceptorSet
|
m_Acceptor = acceptor; // we must set it immediately for IsAcceptorSet
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Owner->GetService ().post([s](void)
|
boost::asio::post (m_Owner->GetService (), [s](void)
|
||||||
{
|
{
|
||||||
// take care about incoming queue
|
// take care about incoming queue
|
||||||
for (auto& it: s->m_PendingIncomingStreams)
|
for (auto& it: s->m_PendingIncomingStreams)
|
||||||
|
@ -1887,7 +1887,7 @@ namespace stream
|
||||||
|
|
||||||
void StreamingDestination::AcceptOnce (const Acceptor& acceptor)
|
void StreamingDestination::AcceptOnce (const Acceptor& acceptor)
|
||||||
{
|
{
|
||||||
m_Owner->GetService ().post([acceptor, this](void)
|
boost::asio::post (m_Owner->GetService (), [acceptor, this](void)
|
||||||
{
|
{
|
||||||
if (!m_PendingIncomingStreams.empty ())
|
if (!m_PendingIncomingStreams.empty ())
|
||||||
{
|
{
|
||||||
|
|
|
@ -202,7 +202,7 @@ namespace stream
|
||||||
size_t ReadSome (uint8_t * buf, size_t len) { return ConcatenatePackets (buf, len); };
|
size_t ReadSome (uint8_t * buf, size_t len) { return ConcatenatePackets (buf, len); };
|
||||||
size_t Receive (uint8_t * buf, size_t len, int timeout);
|
size_t Receive (uint8_t * buf, size_t len, int timeout);
|
||||||
|
|
||||||
void AsyncClose() { m_Service.post(std::bind(&Stream::Close, shared_from_this())); };
|
void AsyncClose() { boost::asio::post(m_Service, std::bind(&Stream::Close, shared_from_this())); };
|
||||||
|
|
||||||
/** only call close from destination thread, use Stream::AsyncClose for other threads */
|
/** only call close from destination thread, use Stream::AsyncClose for other threads */
|
||||||
void Close ();
|
void Close ();
|
||||||
|
@ -238,7 +238,7 @@ namespace stream
|
||||||
void UpdateCurrentRemoteLease (bool expired = false);
|
void UpdateCurrentRemoteLease (bool expired = false);
|
||||||
|
|
||||||
template<typename Buffer, typename ReceiveHandler>
|
template<typename Buffer, typename ReceiveHandler>
|
||||||
void HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler, int remainingTimeout);
|
void HandleReceiveTimer (const boost::system::error_code& ecode, Buffer& buffer, ReceiveHandler handler, int remainingTimeout);
|
||||||
|
|
||||||
void ScheduleSend ();
|
void ScheduleSend ();
|
||||||
void HandleSendTimer (const boost::system::error_code& ecode);
|
void HandleSendTimer (const boost::system::error_code& ecode);
|
||||||
|
@ -375,7 +375,7 @@ namespace stream
|
||||||
void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout)
|
void Stream::AsyncReceive (const Buffer& buffer, ReceiveHandler handler, int timeout)
|
||||||
{
|
{
|
||||||
auto s = shared_from_this();
|
auto s = shared_from_this();
|
||||||
m_Service.post ([s, buffer, handler, timeout](void)
|
boost::asio::post (m_Service, [s, buffer, handler, timeout](void)
|
||||||
{
|
{
|
||||||
if (!s->m_ReceiveQueue.empty () || s->m_Status == eStreamStatusReset)
|
if (!s->m_ReceiveQueue.empty () || s->m_Status == eStreamStatusReset)
|
||||||
s->HandleReceiveTimer (boost::asio::error::make_error_code (boost::asio::error::operation_aborted), buffer, handler, 0);
|
s->HandleReceiveTimer (boost::asio::error::make_error_code (boost::asio::error::operation_aborted), buffer, handler, 0);
|
||||||
|
@ -394,9 +394,9 @@ namespace stream
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Buffer, typename ReceiveHandler>
|
template<typename Buffer, typename ReceiveHandler>
|
||||||
void Stream::HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler, int remainingTimeout)
|
void Stream::HandleReceiveTimer (const boost::system::error_code& ecode, Buffer& buffer, ReceiveHandler handler, int remainingTimeout)
|
||||||
{
|
{
|
||||||
size_t received = ConcatenatePackets (boost::asio::buffer_cast<uint8_t *>(buffer), boost::asio::buffer_size(buffer));
|
size_t received = ConcatenatePackets ((uint8_t *)buffer.data (), buffer.size ());
|
||||||
if (received > 0)
|
if (received > 0)
|
||||||
handler (boost::system::error_code (), received);
|
handler (boost::system::error_code (), received);
|
||||||
else if (ecode == boost::asio::error::operation_aborted)
|
else if (ecode == boost::asio::error::operation_aborted)
|
||||||
|
|
|
@ -62,14 +62,12 @@ namespace util
|
||||||
LogPrint (eLogInfo, "Timestamp: NTP request to ", address);
|
LogPrint (eLogInfo, "Timestamp: NTP request to ", address);
|
||||||
boost::asio::io_context service;
|
boost::asio::io_context service;
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto it = boost::asio::ip::udp::resolver (service).resolve (
|
auto endpoints = boost::asio::ip::udp::resolver (service).resolve (address, "ntp", ec);
|
||||||
boost::asio::ip::udp::resolver::query (address, "ntp"), ec);
|
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
boost::asio::ip::udp::resolver::iterator end;
|
|
||||||
boost::asio::ip::udp::endpoint ep;
|
boost::asio::ip::udp::endpoint ep;
|
||||||
while (it != end)
|
for (auto it = endpoints.begin (); it != endpoints.end ();)
|
||||||
{
|
{
|
||||||
ep = *it;
|
ep = *it;
|
||||||
if (!ep.address ().is_unspecified ())
|
if (!ep.address ().is_unspecified ())
|
||||||
|
@ -154,7 +152,7 @@ namespace util
|
||||||
{
|
{
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
LogPrint(eLogInfo, "Timestamp: NTP time sync starting");
|
LogPrint(eLogInfo, "Timestamp: NTP time sync starting");
|
||||||
m_Service.post (std::bind (&NTPTimeSync::Sync, this));
|
boost::asio::post (m_Service, std::bind (&NTPTimeSync::Sync, this));
|
||||||
m_Thread.reset (new std::thread (std::bind (&NTPTimeSync::Run, this)));
|
m_Thread.reset (new std::thread (std::bind (&NTPTimeSync::Run, this)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -175,7 +175,7 @@ namespace transport
|
||||||
if (!m_Service)
|
if (!m_Service)
|
||||||
{
|
{
|
||||||
m_Service = new boost::asio::io_context ();
|
m_Service = new boost::asio::io_context ();
|
||||||
m_Work = new boost::asio::io_context::work (*m_Service);
|
m_Work = new boost::asio::executor_work_guard<boost::asio::io_context::executor_type> (m_Service->get_executor ());
|
||||||
m_PeerCleanupTimer = new boost::asio::deadline_timer (*m_Service);
|
m_PeerCleanupTimer = new boost::asio::deadline_timer (*m_Service);
|
||||||
m_PeerTestTimer = new boost::asio::deadline_timer (*m_Service);
|
m_PeerTestTimer = new boost::asio::deadline_timer (*m_Service);
|
||||||
m_UpdateBandwidthTimer = new boost::asio::deadline_timer (*m_Service);
|
m_UpdateBandwidthTimer = new boost::asio::deadline_timer (*m_Service);
|
||||||
|
@ -249,7 +249,7 @@ namespace transport
|
||||||
if (!address.empty ())
|
if (!address.empty ())
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string (address, ec);
|
auto addr = boost::asio::ip::make_address (address, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
|
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
|
||||||
|
@ -275,7 +275,7 @@ namespace transport
|
||||||
if (!address.empty ())
|
if (!address.empty ())
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string (address, ec);
|
auto addr = boost::asio::ip::make_address (address, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
|
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
|
||||||
|
@ -302,7 +302,7 @@ namespace transport
|
||||||
if (!address.empty ())
|
if (!address.empty ())
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string (address, ec);
|
auto addr = boost::asio::ip::make_address (address, ec);
|
||||||
if (!ec && m_NTCP2Server && i2p::util::net::IsYggdrasilAddress (addr))
|
if (!ec && m_NTCP2Server && i2p::util::net::IsYggdrasilAddress (addr))
|
||||||
m_NTCP2Server->SetLocalAddress (addr);
|
m_NTCP2Server->SetLocalAddress (addr);
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ namespace transport
|
||||||
|
|
||||||
void Transports::SendMessages (const i2p::data::IdentHash& ident, std::list<std::shared_ptr<i2p::I2NPMessage> >&& msgs)
|
void Transports::SendMessages (const i2p::data::IdentHash& ident, std::list<std::shared_ptr<i2p::I2NPMessage> >&& msgs)
|
||||||
{
|
{
|
||||||
m_Service->post ([this, ident, msgs = std::move(msgs)] () mutable
|
boost::asio::post (*m_Service, [this, ident, msgs = std::move(msgs)] () mutable
|
||||||
{
|
{
|
||||||
PostMessages (ident, msgs);
|
PostMessages (ident, msgs);
|
||||||
});
|
});
|
||||||
|
@ -719,7 +719,7 @@ namespace transport
|
||||||
|
|
||||||
void Transports::RequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident)
|
void Transports::RequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident)
|
||||||
{
|
{
|
||||||
m_Service->post (std::bind (&Transports::HandleRequestComplete, this, r, ident));
|
boost::asio::post (*m_Service, std::bind (&Transports::HandleRequestComplete, this, r, ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::HandleRequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, i2p::data::IdentHash ident)
|
void Transports::HandleRequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, i2p::data::IdentHash ident)
|
||||||
|
@ -856,7 +856,7 @@ namespace transport
|
||||||
|
|
||||||
void Transports::PeerConnected (std::shared_ptr<TransportSession> session)
|
void Transports::PeerConnected (std::shared_ptr<TransportSession> session)
|
||||||
{
|
{
|
||||||
m_Service->post([session, this]()
|
boost::asio::post (*m_Service, [session, this]()
|
||||||
{
|
{
|
||||||
auto remoteIdentity = session->GetRemoteIdentity ();
|
auto remoteIdentity = session->GetRemoteIdentity ();
|
||||||
if (!remoteIdentity) return;
|
if (!remoteIdentity) return;
|
||||||
|
@ -928,7 +928,7 @@ namespace transport
|
||||||
|
|
||||||
void Transports::PeerDisconnected (std::shared_ptr<TransportSession> session)
|
void Transports::PeerDisconnected (std::shared_ptr<TransportSession> session)
|
||||||
{
|
{
|
||||||
m_Service->post([session, this]()
|
boost::asio::post (*m_Service, [session, this]()
|
||||||
{
|
{
|
||||||
auto remoteIdentity = session->GetRemoteIdentity ();
|
auto remoteIdentity = session->GetRemoteIdentity ();
|
||||||
if (!remoteIdentity) return;
|
if (!remoteIdentity) return;
|
||||||
|
@ -1276,7 +1276,7 @@ namespace transport
|
||||||
std::string yggaddress; i2p::config::GetOption ("meshnets.yggaddress", yggaddress);
|
std::string yggaddress; i2p::config::GetOption ("meshnets.yggaddress", yggaddress);
|
||||||
if (!yggaddress.empty ())
|
if (!yggaddress.empty ())
|
||||||
{
|
{
|
||||||
yggaddr = boost::asio::ip::address_v6::from_string (yggaddress);
|
yggaddr = boost::asio::ip::make_address (yggaddress).to_v6 ();
|
||||||
if (yggaddr.is_unspecified () || !i2p::util::net::IsYggdrasilAddress (yggaddr) ||
|
if (yggaddr.is_unspecified () || !i2p::util::net::IsYggdrasilAddress (yggaddr) ||
|
||||||
!i2p::util::net::IsLocalAddress (yggaddr))
|
!i2p::util::net::IsLocalAddress (yggaddr))
|
||||||
{
|
{
|
||||||
|
@ -1321,7 +1321,7 @@ namespace transport
|
||||||
if (ipv6)
|
if (ipv6)
|
||||||
{
|
{
|
||||||
std::string ipv6Addr; i2p::config::GetOption("ntcp2.addressv6", ipv6Addr);
|
std::string ipv6Addr; i2p::config::GetOption("ntcp2.addressv6", ipv6Addr);
|
||||||
auto addr = boost::asio::ip::address_v6::from_string (ipv6Addr);
|
auto addr = boost::asio::ip::make_address (ipv6Addr).to_v6 ();
|
||||||
if (!addr.is_unspecified () && addr != boost::asio::ip::address_v6::any ())
|
if (!addr.is_unspecified () && addr != boost::asio::ip::address_v6::any ())
|
||||||
i2p::context.UpdateNTCP2V6Address (addr); // set ipv6 address if configured
|
i2p::context.UpdateNTCP2V6Address (addr); // set ipv6 address if configured
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace transport
|
||||||
bool m_IsRunning, m_IsNAT, m_CheckReserved;
|
bool m_IsRunning, m_IsNAT, m_CheckReserved;
|
||||||
std::thread * m_Thread;
|
std::thread * m_Thread;
|
||||||
boost::asio::io_context * m_Service;
|
boost::asio::io_context * m_Service;
|
||||||
boost::asio::io_context::work * m_Work;
|
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> * m_Work;
|
||||||
boost::asio::deadline_timer * m_PeerCleanupTimer, * m_PeerTestTimer, * m_UpdateBandwidthTimer;
|
boost::asio::deadline_timer * m_PeerCleanupTimer, * m_PeerTestTimer, * m_UpdateBandwidthTimer;
|
||||||
|
|
||||||
SSU2Server * m_SSU2Server;
|
SSU2Server * m_SSU2Server;
|
||||||
|
|
|
@ -123,8 +123,8 @@ const char *inet_ntop_xp(int af, const void *src, char *dst, socklen_t size)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define address_pair_v4(a,b) { boost::asio::ip::address_v4::from_string (a).to_ulong (), boost::asio::ip::address_v4::from_string (b).to_ulong () }
|
#define address_pair_v4(a,b) { boost::asio::ip::make_address (a).to_v4 ().to_uint (), boost::asio::ip::make_address(b).to_v4 ().to_uint () }
|
||||||
#define address_pair_v6(a,b) { boost::asio::ip::address_v6::from_string (a).to_bytes (), boost::asio::ip::address_v6::from_string (b).to_bytes () }
|
#define address_pair_v6(a,b) { boost::asio::ip::make_address (a).to_v6 ().to_bytes (), boost::asio::ip::make_address(b).to_v6 ().to_bytes () }
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -478,7 +478,7 @@ namespace net
|
||||||
inet_ntop(af, &((sockaddr_in6 *)cur->ifa_addr)->sin6_addr, addr, INET6_ADDRSTRLEN);
|
inet_ntop(af, &((sockaddr_in6 *)cur->ifa_addr)->sin6_addr, addr, INET6_ADDRSTRLEN);
|
||||||
freeifaddrs(addrs);
|
freeifaddrs(addrs);
|
||||||
std::string cur_ifaddr(addr);
|
std::string cur_ifaddr(addr);
|
||||||
return boost::asio::ip::address::from_string(cur_ifaddr);
|
return boost::asio::ip::make_address(cur_ifaddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -498,7 +498,7 @@ namespace net
|
||||||
fallback = "127.0.0.1";
|
fallback = "127.0.0.1";
|
||||||
LogPrint(eLogWarning, "NetIface: Cannot find IPv4 address for interface ", ifname);
|
LogPrint(eLogWarning, "NetIface: Cannot find IPv4 address for interface ", ifname);
|
||||||
}
|
}
|
||||||
return boost::asio::ip::address::from_string(fallback);
|
return boost::asio::ip::make_address(fallback);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,7 +664,7 @@ namespace net
|
||||||
address_pair_v4("224.0.0.0", "255.255.255.255")
|
address_pair_v4("224.0.0.0", "255.255.255.255")
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t ipv4_address = host.to_v4 ().to_ulong ();
|
uint32_t ipv4_address = host.to_v4 ().to_uint ();
|
||||||
for (const auto& it : reservedIPv4Ranges) {
|
for (const auto& it : reservedIPv4Ranges) {
|
||||||
if (ipv4_address >= it.first && ipv4_address <= it.second)
|
if (ipv4_address >= it.first && ipv4_address <= it.second)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -202,11 +202,11 @@ namespace util
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
RunnableServiceWithWork (const std::string& name):
|
RunnableServiceWithWork (const std::string& name):
|
||||||
RunnableService (name), m_Work (GetIOService ()) {}
|
RunnableService (name), m_Work (GetIOService ().get_executor ()) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
boost::asio::io_context::work m_Work;
|
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_Work;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetThreadName (const char *name);
|
void SetThreadName (const char *name);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -129,7 +129,7 @@ namespace client
|
||||||
|
|
||||||
BOBI2POutboundTunnel::BOBI2POutboundTunnel (const std::string& outhost, uint16_t port,
|
BOBI2POutboundTunnel::BOBI2POutboundTunnel (const std::string& outhost, uint16_t port,
|
||||||
std::shared_ptr<ClientDestination> localDestination, bool quiet): BOBI2PTunnel (localDestination),
|
std::shared_ptr<ClientDestination> localDestination, bool quiet): BOBI2PTunnel (localDestination),
|
||||||
m_Endpoint (boost::asio::ip::address::from_string (outhost), port), m_IsQuiet (quiet)
|
m_Endpoint (boost::asio::ip::make_address (outhost), port), m_IsQuiet (quiet)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ namespace client
|
||||||
if (!inhost.empty ())
|
if (!inhost.empty ())
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string (inhost, ec);
|
auto addr = boost::asio::ip::make_address (inhost, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
ep.address (addr);
|
ep.address (addr);
|
||||||
else
|
else
|
||||||
|
@ -425,7 +425,7 @@ namespace client
|
||||||
{
|
{
|
||||||
// TODO: FIXME: temporary validation, until hostname support is added
|
// TODO: FIXME: temporary validation, until hostname support is added
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
boost::asio::ip::address::from_string(m_InHost, ec);
|
boost::asio::ip::make_address(m_InHost, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
SendReplyError("inhost must be a valid IPv4 address.");
|
SendReplyError("inhost must be a valid IPv4 address.");
|
||||||
|
@ -436,7 +436,7 @@ namespace client
|
||||||
{
|
{
|
||||||
// TODO: FIXME: temporary validation, until hostname support is added
|
// TODO: FIXME: temporary validation, until hostname support is added
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
boost::asio::ip::address::from_string(m_OutHost, ec);
|
boost::asio::ip::make_address(m_OutHost, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
SendReplyError("outhost must be a IPv4 address.");
|
SendReplyError("outhost must be a IPv4 address.");
|
||||||
|
@ -828,7 +828,7 @@ namespace client
|
||||||
|
|
||||||
BOBCommandChannel::BOBCommandChannel (const std::string& address, uint16_t port):
|
BOBCommandChannel::BOBCommandChannel (const std::string& address, uint16_t port):
|
||||||
RunnableService ("BOB"),
|
RunnableService ("BOB"),
|
||||||
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port))
|
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(address), port))
|
||||||
{
|
{
|
||||||
// command -> handler
|
// command -> handler
|
||||||
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
|
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
|
||||||
|
|
|
@ -631,7 +631,7 @@ namespace client
|
||||||
if (type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) {
|
if (type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) {
|
||||||
// udp client
|
// udp client
|
||||||
// TODO: hostnames
|
// TODO: hostnames
|
||||||
boost::asio::ip::udp::endpoint end (boost::asio::ip::address::from_string(address), port);
|
boost::asio::ip::udp::endpoint end (boost::asio::ip::make_address(address), port);
|
||||||
if (!localDestination)
|
if (!localDestination)
|
||||||
localDestination = m_SharedLocalDestination;
|
localDestination = m_SharedLocalDestination;
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ namespace client
|
||||||
{
|
{
|
||||||
// udp server tunnel
|
// udp server tunnel
|
||||||
// TODO: hostnames
|
// TODO: hostnames
|
||||||
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(host), port);
|
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::make_address(host), port);
|
||||||
if (address.empty ())
|
if (address.empty ())
|
||||||
{
|
{
|
||||||
if (!endpoint.address ().is_unspecified () && endpoint.address ().is_v6 ())
|
if (!endpoint.address ().is_unspecified () && endpoint.address ().is_v6 ())
|
||||||
|
@ -795,7 +795,7 @@ namespace client
|
||||||
else
|
else
|
||||||
address = "127.0.0.1";
|
address = "127.0.0.1";
|
||||||
}
|
}
|
||||||
auto localAddress = boost::asio::ip::address::from_string(address);
|
auto localAddress = boost::asio::ip::make_address(address);
|
||||||
auto serverTunnel = std::make_shared<I2PUDPServerTunnel>(name, localDestination, localAddress, endpoint, inPort, gzip);
|
auto serverTunnel = std::make_shared<I2PUDPServerTunnel>(name, localDestination, localAddress, endpoint, inPort, gzip);
|
||||||
if(!isUniqueLocal)
|
if(!isUniqueLocal)
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,7 +98,7 @@ namespace proxy {
|
||||||
|
|
||||||
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
||||||
|
|
||||||
void HandleUpstreamProxyResolved(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr, ProxyResolvedHandler handler);
|
void HandleUpstreamProxyResolved(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::results_type endpoints, ProxyResolvedHandler handler);
|
||||||
|
|
||||||
void SocksProxySuccess();
|
void SocksProxySuccess();
|
||||||
void HandoverToUpstreamProxy();
|
void HandoverToUpstreamProxy();
|
||||||
|
@ -584,8 +584,9 @@ namespace proxy {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boost::asio::ip::tcp::resolver::query q(m_ProxyURL.host, std::to_string(m_ProxyURL.port));
|
m_proxy_resolver.async_resolve(m_ProxyURL.host, std::to_string(m_ProxyURL.port), std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this,
|
||||||
m_proxy_resolver.async_resolve(q, std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this, std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep) {
|
std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep)
|
||||||
|
{
|
||||||
m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamHTTPProxyConnect, this, std::placeholders::_1));
|
m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamHTTPProxyConnect, this, std::placeholders::_1));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -594,8 +595,9 @@ namespace proxy {
|
||||||
{
|
{
|
||||||
/* handle upstream socks proxy */
|
/* handle upstream socks proxy */
|
||||||
if (!m_ProxyURL.port) m_ProxyURL.port = 9050; // default to tor default if not specified
|
if (!m_ProxyURL.port) m_ProxyURL.port = 9050; // default to tor default if not specified
|
||||||
boost::asio::ip::tcp::resolver::query q(m_ProxyURL.host, std::to_string(m_ProxyURL.port));
|
m_proxy_resolver.async_resolve(m_ProxyURL.host, std::to_string(m_ProxyURL.port), std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this,
|
||||||
m_proxy_resolver.async_resolve(q, std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this, std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep) {
|
std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep)
|
||||||
|
{
|
||||||
m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamSocksProxyConnect, this, std::placeholders::_1));
|
m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamSocksProxyConnect, this, std::placeholders::_1));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -606,10 +608,10 @@ namespace proxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::HandleUpstreamProxyResolved(const boost::system::error_code & ec, boost::asio::ip::tcp::resolver::iterator it, ProxyResolvedHandler handler)
|
void HTTPReqHandler::HandleUpstreamProxyResolved(const boost::system::error_code & ec, boost::asio::ip::tcp::resolver::results_type endpoints, ProxyResolvedHandler handler)
|
||||||
{
|
{
|
||||||
if(ec) GenericProxyError(tr("Cannot resolve upstream proxy"), ec.message());
|
if(ec) GenericProxyError(tr("Cannot resolve upstream proxy"), ec.message());
|
||||||
else handler(*it);
|
else handler(*endpoints.begin ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec)
|
void HTTPReqHandler::HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec)
|
||||||
|
|
|
@ -88,7 +88,7 @@ namespace client
|
||||||
|
|
||||||
void I2CPDestination::CreateNewLeaseSet (const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels)
|
void I2CPDestination::CreateNewLeaseSet (const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels)
|
||||||
{
|
{
|
||||||
GetService ().post (std::bind (&I2CPDestination::PostCreateNewLeaseSet, this, tunnels));
|
boost::asio::post (GetService (), std::bind (&I2CPDestination::PostCreateNewLeaseSet, this, tunnels));
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2CPDestination::PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
|
void I2CPDestination::PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
|
||||||
|
@ -170,7 +170,7 @@ namespace client
|
||||||
{
|
{
|
||||||
// send in destination's thread
|
// send in destination's thread
|
||||||
auto s = GetSharedFromThis ();
|
auto s = GetSharedFromThis ();
|
||||||
GetService ().post (
|
boost::asio::post (GetService (),
|
||||||
[s, msg, remote, nonce]()
|
[s, msg, remote, nonce]()
|
||||||
{
|
{
|
||||||
bool sent = s->SendMsg (msg, remote);
|
bool sent = s->SendMsg (msg, remote);
|
||||||
|
@ -1079,7 +1079,7 @@ namespace client
|
||||||
I2CPServer::I2CPServer (const std::string& interface, uint16_t port, bool isSingleThread):
|
I2CPServer::I2CPServer (const std::string& interface, uint16_t port, bool isSingleThread):
|
||||||
RunnableService ("I2CP"), m_IsSingleThread (isSingleThread),
|
RunnableService ("I2CP"), m_IsSingleThread (isSingleThread),
|
||||||
m_Acceptor (GetIOService (),
|
m_Acceptor (GetIOService (),
|
||||||
boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(interface), port))
|
boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(interface), port))
|
||||||
{
|
{
|
||||||
memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers));
|
memset (m_MessagesHandlers, 0, sizeof (m_MessagesHandlers));
|
||||||
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
|
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
|
||||||
|
|
|
@ -283,7 +283,7 @@ namespace client
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TCPIPAcceptor (const std::string& address, uint16_t port, std::shared_ptr<ClientDestination> localDestination = nullptr) :
|
TCPIPAcceptor (const std::string& address, uint16_t port, std::shared_ptr<ClientDestination> localDestination = nullptr) :
|
||||||
ServiceAcceptor (boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string(address), port), localDestination) {}
|
ServiceAcceptor (boost::asio::ip::tcp::endpoint (boost::asio::ip::make_address(address), port), localDestination) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -717,7 +717,7 @@ namespace client
|
||||||
{
|
{
|
||||||
m_Endpoint.port (m_Port);
|
m_Endpoint.port (m_Port);
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string (m_Address, ec);
|
auto addr = boost::asio::ip::make_address (m_Address, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
m_Endpoint.address (addr);
|
m_Endpoint.address (addr);
|
||||||
|
@ -726,7 +726,7 @@ namespace client
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(GetService ());
|
auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(GetService ());
|
||||||
resolver->async_resolve (boost::asio::ip::tcp::resolver::query (m_Address, ""),
|
resolver->async_resolve (m_Address, "",
|
||||||
std::bind (&I2PServerTunnel::HandleResolve, this,
|
std::bind (&I2PServerTunnel::HandleResolve, this,
|
||||||
std::placeholders::_1, std::placeholders::_2, resolver));
|
std::placeholders::_1, std::placeholders::_2, resolver));
|
||||||
}
|
}
|
||||||
|
@ -743,7 +743,7 @@ namespace client
|
||||||
ClearHandlers ();
|
ClearHandlers ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
|
void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
||||||
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver)
|
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver)
|
||||||
{
|
{
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
|
@ -752,8 +752,7 @@ namespace client
|
||||||
boost::asio::ip::tcp::endpoint ep;
|
boost::asio::ip::tcp::endpoint ep;
|
||||||
if (m_LocalAddress)
|
if (m_LocalAddress)
|
||||||
{
|
{
|
||||||
boost::asio::ip::tcp::resolver::iterator end;
|
for (auto it = endpoints.begin (); it != endpoints.end ();)
|
||||||
while (it != end)
|
|
||||||
{
|
{
|
||||||
ep = *it;
|
ep = *it;
|
||||||
if (!ep.address ().is_unspecified ())
|
if (!ep.address ().is_unspecified ())
|
||||||
|
@ -780,7 +779,7 @@ namespace client
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
ep = *it; // first available
|
ep = *endpoints.begin (); // first available
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
|
@ -789,7 +788,7 @@ namespace client
|
||||||
}
|
}
|
||||||
|
|
||||||
auto addr = ep.address ();
|
auto addr = ep.address ();
|
||||||
LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*it).host_name (), " has been resolved to ", addr);
|
LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*endpoints.begin ()).host_name (), " has been resolved to ", addr);
|
||||||
m_Endpoint.address (addr);
|
m_Endpoint.address (addr);
|
||||||
Accept ();
|
Accept ();
|
||||||
}
|
}
|
||||||
|
@ -806,7 +805,7 @@ namespace client
|
||||||
void I2PServerTunnel::SetLocalAddress (const std::string& localAddress)
|
void I2PServerTunnel::SetLocalAddress (const std::string& localAddress)
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::address::from_string(localAddress, ec);
|
auto addr = boost::asio::ip::make_address(localAddress, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
m_LocalAddress.reset (new boost::asio::ip::address (addr));
|
m_LocalAddress.reset (new boost::asio::ip::address (addr));
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -208,7 +208,7 @@ namespace client
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
|
void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
||||||
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
|
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
|
||||||
|
|
||||||
void Accept ();
|
void Accept ();
|
||||||
|
|
|
@ -371,7 +371,7 @@ namespace client
|
||||||
// udp forward selected
|
// udp forward selected
|
||||||
boost::system::error_code e;
|
boost::system::error_code e;
|
||||||
// TODO: support hostnames in udp forward
|
// TODO: support hostnames in udp forward
|
||||||
auto addr = boost::asio::ip::address::from_string(params[SAM_PARAM_HOST], e);
|
auto addr = boost::asio::ip::make_address(params[SAM_PARAM_HOST], e);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
// not an ip address
|
// not an ip address
|
||||||
|
@ -624,7 +624,7 @@ namespace client
|
||||||
auto socket = session->acceptQueue.front ().first;
|
auto socket = session->acceptQueue.front ().first;
|
||||||
session->acceptQueue.pop_front ();
|
session->acceptQueue.pop_front ();
|
||||||
if (socket)
|
if (socket)
|
||||||
m_Owner.GetService ().post (std::bind(&SAMSocket::TerminateClose, socket));
|
boost::asio::post (m_Owner.GetService (), std::bind(&SAMSocket::TerminateClose, socket));
|
||||||
}
|
}
|
||||||
if (session->acceptQueue.size () < SAM_SESSION_MAX_ACCEPT_QUEUE_SIZE)
|
if (session->acceptQueue.size () < SAM_SESSION_MAX_ACCEPT_QUEUE_SIZE)
|
||||||
{
|
{
|
||||||
|
@ -1046,13 +1046,13 @@ namespace client
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Owner.GetService ().post ([s] { s->Terminate ("stream read error"); });
|
boost::asio::post (m_Owner.GetService (), [s] { s->Terminate ("stream read error"); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Owner.GetService ().post ([s] { s->Terminate ("stream read error (op aborted)"); });
|
boost::asio::post (m_Owner.GetService (), [s] { s->Terminate ("stream read error (op aborted)"); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1102,7 +1102,7 @@ namespace client
|
||||||
auto socket = session->acceptQueue.front ().first;
|
auto socket = session->acceptQueue.front ().first;
|
||||||
session->acceptQueue.pop_front ();
|
session->acceptQueue.pop_front ();
|
||||||
if (socket)
|
if (socket)
|
||||||
m_Owner.GetService ().post (std::bind(&SAMSocket::TerminateClose, socket));
|
boost::asio::post (m_Owner.GetService (), std::bind(&SAMSocket::TerminateClose, socket));
|
||||||
}
|
}
|
||||||
if (!session->acceptQueue.empty ())
|
if (!session->acceptQueue.empty ())
|
||||||
{
|
{
|
||||||
|
@ -1236,7 +1236,7 @@ namespace client
|
||||||
|
|
||||||
void SAMSocket::HandleStreamSend(const boost::system::error_code & ec)
|
void SAMSocket::HandleStreamSend(const boost::system::error_code & ec)
|
||||||
{
|
{
|
||||||
m_Owner.GetService ().post (std::bind( !ec ? &SAMSocket::Receive : &SAMSocket::TerminateClose, shared_from_this()));
|
boost::asio::post (m_Owner.GetService (), std::bind( !ec ? &SAMSocket::Receive : &SAMSocket::TerminateClose, shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMSession::SAMSession (SAMBridge & parent, const std::string & id, SAMSessionType type):
|
SAMSession::SAMSession (SAMBridge & parent, const std::string & id, SAMSessionType type):
|
||||||
|
@ -1310,8 +1310,8 @@ namespace client
|
||||||
|
|
||||||
SAMBridge::SAMBridge (const std::string& address, uint16_t portTCP, uint16_t portUDP, bool singleThread):
|
SAMBridge::SAMBridge (const std::string& address, uint16_t portTCP, uint16_t portUDP, bool singleThread):
|
||||||
RunnableService ("SAM"), m_IsSingleThread (singleThread),
|
RunnableService ("SAM"), m_IsSingleThread (singleThread),
|
||||||
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), portTCP)),
|
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(address), portTCP)),
|
||||||
m_DatagramEndpoint (boost::asio::ip::address::from_string(address), (!portUDP) ? portTCP-1 : portUDP), m_DatagramSocket (GetIOService (), m_DatagramEndpoint),
|
m_DatagramEndpoint (boost::asio::ip::make_address(address), (!portUDP) ? portTCP-1 : portUDP), m_DatagramSocket (GetIOService (), m_DatagramEndpoint),
|
||||||
m_SignatureTypes
|
m_SignatureTypes
|
||||||
{
|
{
|
||||||
{"DSA_SHA1", i2p::data::SIGNING_KEY_TYPE_DSA_SHA1},
|
{"DSA_SHA1", i2p::data::SIGNING_KEY_TYPE_DSA_SHA1},
|
||||||
|
|
|
@ -126,9 +126,8 @@ namespace proxy
|
||||||
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered);
|
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered);
|
||||||
void Terminate();
|
void Terminate();
|
||||||
void AsyncSockRead();
|
void AsyncSockRead();
|
||||||
boost::asio::const_buffers_1 GenerateSOCKS5SelectAuth(authMethods method);
|
boost::asio::const_buffer GenerateSOCKS4Response(errTypes error, uint32_t ip, uint16_t port);
|
||||||
boost::asio::const_buffers_1 GenerateSOCKS4Response(errTypes error, uint32_t ip, uint16_t port);
|
boost::asio::const_buffer GenerateSOCKS5Response(errTypes error, addrTypes type, const address &addr, uint16_t port);
|
||||||
boost::asio::const_buffers_1 GenerateSOCKS5Response(errTypes error, addrTypes type, const address &addr, uint16_t port);
|
|
||||||
bool Socks5ChooseAuth();
|
bool Socks5ChooseAuth();
|
||||||
void Socks5UserPasswdResponse ();
|
void Socks5UserPasswdResponse ();
|
||||||
void SocksRequestFailed(errTypes error);
|
void SocksRequestFailed(errTypes error);
|
||||||
|
@ -145,9 +144,9 @@ namespace proxy
|
||||||
template<typename Socket>
|
template<typename Socket>
|
||||||
void SendUpstreamRequest(std::shared_ptr<Socket>& upstreamSock);
|
void SendUpstreamRequest(std::shared_ptr<Socket>& upstreamSock);
|
||||||
void HandleUpstreamConnected(const boost::system::error_code & ecode,
|
void HandleUpstreamConnected(const boost::system::error_code & ecode,
|
||||||
boost::asio::ip::tcp::resolver::iterator itr);
|
const boost::asio::ip::tcp::endpoint& ep);
|
||||||
void HandleUpstreamResolved(const boost::system::error_code & ecode,
|
void HandleUpstreamResolved(const boost::system::error_code & ecode,
|
||||||
boost::asio::ip::tcp::resolver::iterator itr);
|
boost::asio::ip::tcp::resolver::results_type endpoints);
|
||||||
|
|
||||||
boost::asio::ip::tcp::resolver m_proxy_resolver;
|
boost::asio::ip::tcp::resolver m_proxy_resolver;
|
||||||
uint8_t m_sock_buff[socks_buffer_size];
|
uint8_t m_sock_buff[socks_buffer_size];
|
||||||
|
@ -233,17 +232,17 @@ namespace proxy
|
||||||
Done(shared_from_this());
|
Done(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::const_buffers_1 SOCKSHandler::GenerateSOCKS4Response(SOCKSHandler::errTypes error, uint32_t ip, uint16_t port)
|
boost::asio::const_buffer SOCKSHandler::GenerateSOCKS4Response(SOCKSHandler::errTypes error, uint32_t ip, uint16_t port)
|
||||||
{
|
{
|
||||||
assert(error >= SOCKS4_OK);
|
assert(error >= SOCKS4_OK);
|
||||||
m_response[0] = '\x00'; // version
|
m_response[0] = '\x00'; // version
|
||||||
m_response[1] = error; // response code
|
m_response[1] = error; // response code
|
||||||
htobe16buf(m_response + 2, port); // port
|
htobe16buf(m_response + 2, port); // port
|
||||||
htobe32buf(m_response + 4, ip); // IP
|
htobe32buf(m_response + 4, ip); // IP
|
||||||
return boost::asio::const_buffers_1(m_response,8);
|
return boost::asio::const_buffer (m_response,8);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::const_buffers_1 SOCKSHandler::GenerateSOCKS5Response(SOCKSHandler::errTypes error, SOCKSHandler::addrTypes type, const SOCKSHandler::address &addr, uint16_t port)
|
boost::asio::const_buffer SOCKSHandler::GenerateSOCKS5Response(SOCKSHandler::errTypes error, SOCKSHandler::addrTypes type, const SOCKSHandler::address &addr, uint16_t port)
|
||||||
{
|
{
|
||||||
size_t size = 6; // header + port
|
size_t size = 6; // header + port
|
||||||
assert(error <= SOCKS5_ADDR_UNSUP);
|
assert(error <= SOCKS5_ADDR_UNSUP);
|
||||||
|
@ -280,14 +279,14 @@ namespace proxy
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return boost::asio::const_buffers_1(m_response, size);
|
return boost::asio::const_buffer (m_response, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SOCKSHandler::Socks5ChooseAuth()
|
bool SOCKSHandler::Socks5ChooseAuth()
|
||||||
{
|
{
|
||||||
m_response[0] = '\x05'; // Version
|
m_response[0] = '\x05'; // Version
|
||||||
m_response[1] = m_authchosen; // Response code
|
m_response[1] = m_authchosen; // Response code
|
||||||
boost::asio::const_buffers_1 response(m_response, 2);
|
boost::asio::const_buffer response(m_response, 2);
|
||||||
if (m_authchosen == AUTH_UNACCEPTABLE)
|
if (m_authchosen == AUTH_UNACCEPTABLE)
|
||||||
{
|
{
|
||||||
LogPrint(eLogWarning, "SOCKS: v5 authentication negotiation failed");
|
LogPrint(eLogWarning, "SOCKS: v5 authentication negotiation failed");
|
||||||
|
@ -307,14 +306,14 @@ namespace proxy
|
||||||
m_response[0] = 1; // Version of the subnegotiation
|
m_response[0] = 1; // Version of the subnegotiation
|
||||||
m_response[1] = 0; // Response code
|
m_response[1] = 0; // Response code
|
||||||
LogPrint(eLogDebug, "SOCKS: v5 user/password response");
|
LogPrint(eLogDebug, "SOCKS: v5 user/password response");
|
||||||
boost::asio::async_write(*m_sock, boost::asio::const_buffers_1(m_response, 2),
|
boost::asio::async_write(*m_sock, boost::asio::const_buffer(m_response, 2),
|
||||||
std::bind(&SOCKSHandler::SentSocksResponse, shared_from_this(), std::placeholders::_1));
|
std::bind(&SOCKSHandler::SentSocksResponse, shared_from_this(), std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* All hope is lost beyond this point */
|
/* All hope is lost beyond this point */
|
||||||
void SOCKSHandler::SocksRequestFailed(SOCKSHandler::errTypes error)
|
void SOCKSHandler::SocksRequestFailed(SOCKSHandler::errTypes error)
|
||||||
{
|
{
|
||||||
boost::asio::const_buffers_1 response(nullptr,0);
|
boost::asio::const_buffer response(nullptr,0);
|
||||||
assert(error != SOCKS4_OK && error != SOCKS5_OK);
|
assert(error != SOCKS4_OK && error != SOCKS5_OK);
|
||||||
switch (m_socksv)
|
switch (m_socksv)
|
||||||
{
|
{
|
||||||
|
@ -334,7 +333,7 @@ namespace proxy
|
||||||
|
|
||||||
void SOCKSHandler::SocksRequestSuccess()
|
void SOCKSHandler::SocksRequestSuccess()
|
||||||
{
|
{
|
||||||
boost::asio::const_buffers_1 response(nullptr,0);
|
boost::asio::const_buffer response(nullptr,0);
|
||||||
// TODO: this should depend on things like the command type and callbacks may change
|
// TODO: this should depend on things like the command type and callbacks may change
|
||||||
switch (m_socksv)
|
switch (m_socksv)
|
||||||
{
|
{
|
||||||
|
@ -691,9 +690,8 @@ namespace proxy
|
||||||
if (m_UpstreamProxyPort) // TCP
|
if (m_UpstreamProxyPort) // TCP
|
||||||
{
|
{
|
||||||
EnterState(UPSTREAM_RESOLVE);
|
EnterState(UPSTREAM_RESOLVE);
|
||||||
boost::asio::ip::tcp::resolver::query q(m_UpstreamProxyAddress, std::to_string(m_UpstreamProxyPort));
|
m_proxy_resolver.async_resolve(m_UpstreamProxyAddress, std::to_string(m_UpstreamProxyPort),
|
||||||
m_proxy_resolver.async_resolve(q, std::bind(&SOCKSHandler::HandleUpstreamResolved, shared_from_this(),
|
std::bind(&SOCKSHandler::HandleUpstreamResolved, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
||||||
std::placeholders::_1, std::placeholders::_2));
|
|
||||||
}
|
}
|
||||||
else if (!m_UpstreamProxyAddress.empty ())// local
|
else if (!m_UpstreamProxyAddress.empty ())// local
|
||||||
{
|
{
|
||||||
|
@ -729,7 +727,7 @@ namespace proxy
|
||||||
void SOCKSHandler::SocksUpstreamSuccess(std::shared_ptr<Socket>& upstreamSock)
|
void SOCKSHandler::SocksUpstreamSuccess(std::shared_ptr<Socket>& upstreamSock)
|
||||||
{
|
{
|
||||||
LogPrint(eLogInfo, "SOCKS: Upstream success");
|
LogPrint(eLogInfo, "SOCKS: Upstream success");
|
||||||
boost::asio::const_buffers_1 response(nullptr, 0);
|
boost::asio::const_buffer response(nullptr, 0);
|
||||||
switch (m_socksv)
|
switch (m_socksv)
|
||||||
{
|
{
|
||||||
case SOCKS4:
|
case SOCKS4:
|
||||||
|
@ -775,7 +773,8 @@ namespace proxy
|
||||||
LogPrint(eLogError, "SOCKS: No upstream socket to send handshake to");
|
LogPrint(eLogError, "SOCKS: No upstream socket to send handshake to");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr)
|
void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode,
|
||||||
|
const boost::asio::ip::tcp::endpoint& ep)
|
||||||
{
|
{
|
||||||
if (ecode) {
|
if (ecode) {
|
||||||
LogPrint(eLogWarning, "SOCKS: Could not connect to upstream proxy: ", ecode.message());
|
LogPrint(eLogWarning, "SOCKS: Could not connect to upstream proxy: ", ecode.message());
|
||||||
|
@ -786,7 +785,8 @@ namespace proxy
|
||||||
SendUpstreamRequest(m_upstreamSock);
|
SendUpstreamRequest(m_upstreamSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SOCKSHandler::HandleUpstreamResolved(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr)
|
void SOCKSHandler::HandleUpstreamResolved(const boost::system::error_code & ecode,
|
||||||
|
boost::asio::ip::tcp::resolver::results_type endpoints)
|
||||||
{
|
{
|
||||||
if (ecode) {
|
if (ecode) {
|
||||||
// error resolving
|
// error resolving
|
||||||
|
@ -798,7 +798,7 @@ namespace proxy
|
||||||
EnterState(UPSTREAM_CONNECT);
|
EnterState(UPSTREAM_CONNECT);
|
||||||
auto & service = GetOwner()->GetService();
|
auto & service = GetOwner()->GetService();
|
||||||
m_upstreamSock = std::make_shared<boost::asio::ip::tcp::socket>(service);
|
m_upstreamSock = std::make_shared<boost::asio::ip::tcp::socket>(service);
|
||||||
boost::asio::async_connect(*m_upstreamSock, itr,
|
boost::asio::async_connect(*m_upstreamSock, endpoints,
|
||||||
std::bind(&SOCKSHandler::HandleUpstreamConnected,
|
std::bind(&SOCKSHandler::HandleUpstreamConnected,
|
||||||
shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue