Skip to content

Commit

Permalink
support boost 1.87
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 25, 2024
1 parent 3474538 commit ffd18ba
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 172 deletions.
4 changes: 2 additions & 2 deletions daemon/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,8 +1486,8 @@ namespace http {
}

HTTPServer::HTTPServer (const std::string& address, int port):
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string(address), port)),
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service.get_executor ()),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::make_address(address), port)),
m_Hostname(address)
{
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ namespace http

bool m_IsRunning;
std::unique_ptr<std::thread> m_Thread;
boost::asio::io_service m_Service;
boost::asio::io_service::work m_Work;
boost::asio::io_context m_Service;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_Work;
boost::asio::ip::tcp::acceptor m_Acceptor;
std::string m_Hostname;
};
Expand Down
2 changes: 1 addition & 1 deletion daemon/I2PControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace client
{
I2PControlService::I2PControlService (const std::string& address, int port):
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_ShutdownTimer (m_Service)
{
Expand Down
4 changes: 2 additions & 2 deletions daemon/I2PControl.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace client
bool m_IsRunning;
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::ssl::context m_SSLContext;
boost::asio::deadline_timer m_ShutdownTimer;
Expand Down
30 changes: 15 additions & 15 deletions libi2pd/Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ namespace client
if (m_IsPublic)
{
auto s = shared_from_this ();
m_Service.post ([s](void)
boost::asio::post (m_Service, [s](void)
{
s->m_PublishVerificationTimer.cancel ();
s->Publish ();
Expand Down Expand Up @@ -322,7 +322,7 @@ namespace client
memcpy (data.k, key, 32);
memcpy (data.t, tag, 32);
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);
});
Expand All @@ -339,7 +339,7 @@ namespace client
memcpy (data.k, key, 32);
data.t = tag;
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);
});
Expand All @@ -355,7 +355,7 @@ namespace client
m_IncomingMsgsQueue.push_back (msg);
}
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;
{
Expand All @@ -370,7 +370,7 @@ namespace client
void LeaseSetDestination::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{
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)
Expand Down Expand Up @@ -608,7 +608,7 @@ namespace client
void LeaseSetDestination::SetLeaseSetUpdated (bool post)
{
if (post)
m_Service.post([s = shared_from_this ()]() { s->UpdateLeaseSet (); });
boost::asio::post (m_Service, [s = shared_from_this ()]() { s->UpdateLeaseSet (); });
else
UpdateLeaseSet ();
}
Expand Down Expand Up @@ -690,7 +690,7 @@ namespace client
auto s = shared_from_this ();
msg->onDrop = [s]()
{
s->GetService ().post([s]()
boost::asio::post (s->GetService (), [s]()
{
s->m_PublishConfirmationTimer.cancel ();
s->HandlePublishConfirmationTimer (boost::system::error_code());
Expand Down Expand Up @@ -775,10 +775,10 @@ namespace client
if (!m_Pool || !IsReady ())
{
if (requestComplete)
m_Service.post ([requestComplete](void){requestComplete (nullptr);});
boost::asio::post (m_Service, [requestComplete](void){requestComplete (nullptr);});
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;
}

Expand All @@ -787,25 +787,25 @@ namespace client
if (!dest || !m_Pool || !IsReady ())
{
if (requestComplete)
m_Service.post ([requestComplete](void){requestComplete (nullptr);});
boost::asio::post (m_Service, [requestComplete](void){requestComplete (nullptr);});
return false;
}
auto storeHash = dest->GetStoreHash ();
auto leaseSet = FindLeaseSet (storeHash);
if (leaseSet)
{
if (requestComplete)
m_Service.post ([requestComplete, leaseSet](void){requestComplete (leaseSet);});
boost::asio::post (m_Service, [requestComplete, leaseSet](void){requestComplete (leaseSet);});
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;
}

void LeaseSetDestination::CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify)
{
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);
if (it != s->m_LeaseSetRequests.end ())
Expand Down Expand Up @@ -903,7 +903,7 @@ namespace client
auto s = shared_from_this ();
msg->onDrop = [s, dest, request]()
{
s->GetService ().post([s, dest, request]()
boost::asio::post (s->GetService (), [s, dest, request]()
{
s->SendNextLeaseSetRequest (dest, request);
});
Expand Down Expand Up @@ -1215,7 +1215,7 @@ namespace client
if (leaseSet)
{
auto stream = CreateStream (leaseSet, port);
GetService ().post ([streamRequestComplete, stream]()
boost::asio::post (GetService (), [streamRequestComplete, stream]()
{
streamRequestComplete(stream);
});
Expand Down
21 changes: 10 additions & 11 deletions libi2pd/NTCP2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace transport

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 ()
Expand Down Expand Up @@ -508,7 +508,7 @@ namespace transport
{
// we don't care about padding, send SessionCreated and close session
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)
{
Expand Down Expand Up @@ -1296,7 +1296,7 @@ namespace transport
void NTCP2Session::SendTerminationAndTerminate (NTCP2TerminationReason 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)
Expand All @@ -1313,7 +1313,7 @@ namespace transport
m_IntermediateQueue.splice (m_IntermediateQueue.end (), msgs);
}
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 ()
Expand Down Expand Up @@ -1350,7 +1350,7 @@ namespace transport
void NTCP2Session::SendLocalRouterInfo (bool update)
{
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 ():
Expand All @@ -1374,14 +1374,13 @@ namespace transport
{
LogPrint(eLogInfo, "NTCP2: Using proxy to connect to peers");
// 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;
auto itr = m_Resolver.resolve(q, e);
auto itr = m_Resolver.resolve(m_ProxyAddress, std::to_string(m_ProxyPort), e);
if(e)
LogPrint(eLogCritical, "NTCP2: Failed to resolve proxy ", e.message());
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)
LogPrint(eLogDebug, "NTCP2: m_ProxyEndpoint ", *m_ProxyEndpoint);
}
Expand Down Expand Up @@ -1541,7 +1540,7 @@ namespace transport
}
LogPrint (eLogDebug, "NTCP2: Connecting to ", conn->GetRemoteEndpoint (),
" (", i2p::data::GetIdentHashAbbreviation (conn->GetRemoteIdentity ()->GetIdentHash ()), ")");
GetService ().post([this, conn]()
boost::asio::post (GetService (), [this, conn]()
{
if (this->AddNTCP2Session (conn))
{
Expand Down Expand Up @@ -1762,7 +1761,7 @@ namespace transport
LogPrint (eLogError, "NTCP2: Can't connect to unspecified address");
return;
}
GetService().post([this, conn]()
boost::asio::post (GetService(), [this, conn]()
{
if (this->AddNTCP2Session (conn))
{
Expand Down Expand Up @@ -1860,7 +1859,7 @@ namespace transport
{
readbuff->commit(transferred);
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)
{
Expand Down
8 changes: 4 additions & 4 deletions libi2pd/NetDbRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace data

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;
auto it = m_RequestedDestinations.find (ident);
Expand Down Expand Up @@ -267,7 +267,7 @@ namespace data
{
if (dest->IsActive ())
{
s->GetIOService ().post ([s, dest]()
boost::asio::post (s->GetIOService (), [s, dest]()
{
if (dest->IsActive ()) s->SendNextRequest (dest);
});
Expand Down Expand Up @@ -345,7 +345,7 @@ namespace data

void NetDbRequests::PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg)
{
GetIOService ().post ([this, msg]()
boost::asio::post (GetIOService (), [this, msg]()
{
HandleDatabaseSearchReplyMsg (msg);
});
Expand Down Expand Up @@ -431,7 +431,7 @@ namespace data
void NetDbRequests::PostRequestDestination (const IdentHash& destination,
const RequestedDestination::RequestComplete& requestComplete, bool direct)
{
GetIOService ().post ([this, destination, requestComplete, direct]()
boost::asio::post (GetIOService (), [this, destination, requestComplete, direct]()
{
RequestDestination (destination, requestComplete, direct);
});
Expand Down
20 changes: 7 additions & 13 deletions libi2pd/Reseed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,10 @@ namespace data
if(proxyUrl.schema.size())
{
// proxy connection
auto it = boost::asio::ip::tcp::resolver(service).resolve (
boost::asio::ip::tcp::resolver::query (proxyUrl.host, std::to_string(proxyUrl.port)), ecode);
auto it = boost::asio::ip::tcp::resolver(service).resolve (proxyUrl.host, std::to_string(proxyUrl.port), ecode);
if(!ecode)
{
s.lowest_layer().connect(*it, ecode);
s.lowest_layer().connect(*it.begin (), ecode);
if(!ecode)
{
auto & sock = s.next_layer();
Expand Down Expand Up @@ -599,7 +598,7 @@ namespace data
LogPrint(eLogError, "Reseed: HTTP CONNECT read error: ", ecode.message());
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();
LogPrint(eLogError, "Reseed: HTTP CONNECT malformed reply");
Expand Down Expand Up @@ -638,13 +637,11 @@ namespace data
else
{
// direct connection
auto it = boost::asio::ip::tcp::resolver(service).resolve (
boost::asio::ip::tcp::resolver::query (url.host, std::to_string(url.port)), ecode);
auto endpoints = boost::asio::ip::tcp::resolver(service).resolve (url.host, std::to_string(url.port), ecode);
if (!ecode)
{
bool connected = false;
boost::asio::ip::tcp::resolver::iterator end;
while (it != end)
for (auto it = endpoints.begin (); it != endpoints.end ();)
{
boost::asio::ip::tcp::endpoint ep = *it;
bool supported = false;
Expand Down Expand Up @@ -749,14 +746,11 @@ namespace data
boost::asio::io_context service;
boost::asio::ip::tcp::socket s(service, boost::asio::ip::tcp::v6());

auto it = boost::asio::ip::tcp::resolver(service).resolve (
boost::asio::ip::tcp::resolver::query (url.host, std::to_string(url.port)), ecode);

auto endpoints = boost::asio::ip::tcp::resolver(service).resolve (url.host, std::to_string(url.port), ecode);
if (!ecode)
{
bool connected = false;
boost::asio::ip::tcp::resolver::iterator end;
while (it != end)
for (auto it = endpoints.begin (); it != endpoints.end ();)
{
boost::asio::ip::tcp::endpoint ep = *it;
if (
Expand Down
Loading

0 comments on commit ffd18ba

Please sign in to comment.