From 75430a234ce383b0d86b0e2e9f5871c3ea3f6095 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 2 Jun 2019 22:19:10 +0100 Subject: [PATCH] Convert to use memFn --- llarp/context.cpp | 4 ++-- llarp/exit/session.cpp | 17 +++++------------ llarp/handlers/tun.cpp | 6 +++--- llarp/iwp/iwp.cpp | 14 +++++++------- llarp/messages/relay_commit.cpp | 5 ++--- llarp/router/router.cpp | 15 +++++++-------- llarp/rpc/rpc.cpp | 7 +++---- llarp/service/async_key_exchange.cpp | 5 ++--- llarp/service/endpoint.cpp | 12 +++++------- llarp/service/outbound_context.cpp | 15 +++++---------- llarp/service/protocol.cpp | 6 +++--- llarp/utp/session.cpp | 11 +++++------ llarp/utp/utp.cpp | 20 +++++++++----------- 13 files changed, 58 insertions(+), 79 deletions(-) diff --git a/llarp/context.cpp b/llarp/context.cpp index b43932190..663c96479 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -50,8 +51,7 @@ namespace llarp llarp::LogError("failed to load config file ", configfile); return false; } - using namespace std::placeholders; - config->visit(std::bind(&Context::iter_config, this, _1, _2, _3)); + config->visit(util::memFn(&Context::iter_config, this)); if(!disableMetrics) { diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 1c21f9729..12a2534f5 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace llarp { @@ -97,19 +98,11 @@ namespace llarp BaseSession::HandlePathBuilt(llarp::path::Path_ptr p) { path::Builder::HandlePathBuilt(p); - p->SetDropHandler(std::bind(&BaseSession::HandleTrafficDrop, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)); - p->SetDeadChecker(std::bind(&BaseSession::CheckPathDead, this, - std::placeholders::_1, - std::placeholders::_2)); - p->SetExitTrafficHandler( - std::bind(&BaseSession::HandleTraffic, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)); + p->SetDropHandler(util::memFn(&BaseSession::HandleTrafficDrop, this)); + p->SetDeadChecker(util::memFn(&BaseSession::CheckPathDead, this)); + p->SetExitTrafficHandler(util::memFn(&BaseSession::HandleTraffic, this)); + p->AddObtainExitHandler(util::memFn(&BaseSession::HandleGotExit, this)); - p->AddObtainExitHandler(std::bind(&BaseSession::HandleGotExit, this, - std::placeholders::_1, - std::placeholders::_2)); routing::ObtainExitMessage obtain; obtain.S = p->NextSeqNo(); obtain.T = llarp::randint(); diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index fc546e62a..2f22be377 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -150,9 +151,8 @@ namespace llarp } m_Exit = std::make_shared< llarp::exit::ExitSession >( exitRouter, - std::bind(&TunEndpoint::QueueInboundPacketForExit, this, - std::placeholders::_1), - router, m_NumPaths, numHops, ShouldBundleRC()); + util::memFn(&TunEndpoint::QueueInboundPacketForExit, this), router, + m_NumPaths, numHops, ShouldBundleRC()); llarp::LogInfo(Name(), " using exit at ", exitRouter); } if(k == "local-dns") diff --git a/llarp/iwp/iwp.cpp b/llarp/iwp/iwp.cpp index 025a665af..1c02b137c 100644 --- a/llarp/iwp/iwp.cpp +++ b/llarp/iwp/iwp.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace llarp { @@ -9,15 +10,14 @@ namespace llarp std::unique_ptr< ILinkLayer > NewServerFromRouter(AbstractRouter* r) { - using namespace std::placeholders; return NewServer( r->encryption(), std::bind(&AbstractRouter::rc, r), - std::bind(&AbstractRouter::HandleRecvLinkMessageBuffer, r, _1, _2), - std::bind(&AbstractRouter::OnSessionEstablished, r, _1), - std::bind(&AbstractRouter::CheckRenegotiateValid, r, _1, _2), - std::bind(&AbstractRouter::Sign, r, _1, _2), - std::bind(&AbstractRouter::OnConnectTimeout, r, _1), - std::bind(&AbstractRouter::SessionClosed, r, _1)); + util::memFn(&AbstractRouter::HandleRecvLinkMessageBuffer, r), + util::memFn(&AbstractRouter::OnSessionEstablished, r), + util::memFn(&AbstractRouter::CheckRenegotiateValid, r), + util::memFn(&AbstractRouter::Sign, r), + util::memFn(&AbstractRouter::OnConnectTimeout, r), + util::memFn(&AbstractRouter::SessionClosed, r)); } std::unique_ptr< ILinkLayer > diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index da4a60610..a33cbee3a 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -161,9 +162,7 @@ namespace llarp bool LR_CommitRecord::BDecode(llarp_buffer_t* buf) { - using namespace std::placeholders; - return bencode_read_dict(std::bind(&LR_CommitRecord::OnKey, this, _1, _2), - buf); + return bencode_read_dict(util::memFn(&LR_CommitRecord::OnKey, this), buf); } bool diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 7795095da..fde272c86 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -462,8 +463,7 @@ namespace llarp bool Router::Configure(Config *conf) { - using namespace std::placeholders; - conf->visit(std::bind(&Router::router_iter_config, this, _1, _2, _3)); + conf->visit(util::memFn(&Router::router_iter_config, this)); if(!InitOutboundLinks()) return false; if(!Ready()) @@ -1147,9 +1147,10 @@ namespace llarp void Router::ServiceNodeLookupRouterWhenExpired(RouterID router) { - dht()->impl->LookupRouter(router, - std::bind(&Router::HandleDHTLookupForExplore, - this, router, std::placeholders::_1)); + using namespace std::placeholders; + dht()->impl->LookupRouter( + router, + std::bind(&Router::HandleDHTLookupForExplore, this, router, _1)); } void @@ -1926,9 +1927,7 @@ namespace llarp bool Validate() { - using namespace std::placeholders; - config->visit( - std::bind(&RouterConfigValidator::ValidateEntry, this, _1, _2, _3)); + config->visit(util::memFn(&RouterConfigValidator::ValidateEntry, this)); return valid; } }; diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 1da08bd91..47d6b1a6b 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace llarp @@ -151,8 +152,7 @@ namespace llarp { LogInfo("Updating service node list"); QueueRPC("get_all_service_nodes_keys", nlohmann::json::object(), - std::bind(&CallerImpl::NewAsyncUpdatePubkeyListConn, this, - std::placeholders::_1)); + util::memFn(&CallerImpl::NewAsyncUpdatePubkeyListConn, this)); } bool @@ -166,8 +166,7 @@ namespace llarp { return new GetServiceNodeListHandler( impl, this, - std::bind(&CallerImpl::HandleServiceNodeListUpdated, this, - std::placeholders::_1, std::placeholders::_2)); + util::memFn(&CallerImpl::HandleServiceNodeListUpdated, this)); } void diff --git a/llarp/service/async_key_exchange.cpp b/llarp/service/async_key_exchange.cpp index 7a3140ec9..559064d27 100644 --- a/llarp/service/async_key_exchange.cpp +++ b/llarp/service/async_key_exchange.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace llarp { @@ -50,9 +51,7 @@ namespace llarp // compure post handshake session key // PKE (A, B, N) SharedSecret sharedSecret; - using namespace std::placeholders; - path_dh_func dh_client = - std::bind(&Crypto::dh_client, crypto, _1, _2, _3, _4); + path_dh_func dh_client = util::memFn(&Crypto::dh_client, crypto); if(!self->m_LocalIdentity.KeyExchange(dh_client, sharedSecret, self->remote, self->frame.N)) { diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index e6a5a961b..ee36641d1 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include namespace llarp @@ -795,11 +796,9 @@ namespace llarp void Endpoint::HandlePathBuilt(path::Path_ptr p) { - using namespace std::placeholders; - p->SetDataHandler( - std::bind(&Endpoint::HandleHiddenServiceFrame, this, _1, _2)); - p->SetDropHandler(std::bind(&Endpoint::HandleDataDrop, this, _1, _2, _3)); - p->SetDeadChecker(std::bind(&Endpoint::CheckPathIsDead, this, _1, _2)); + p->SetDataHandler(util::memFn(&Endpoint::HandleHiddenServiceFrame, this)); + p->SetDropHandler(util::memFn(&Endpoint::HandleDataDrop, this)); + p->SetDeadChecker(util::memFn(&Endpoint::CheckPathIsDead, this)); path::Builder::HandlePathBuilt(p); } @@ -982,8 +981,7 @@ namespace llarp using namespace std::placeholders; HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup( - this, std::bind(&Endpoint::OnLookup, this, _1, _2, _3), remote, - GenTXID()); + this, util::memFn(&Endpoint::OnLookup, this), remote, GenTXID()); LogInfo("doing lookup for ", remote, " via ", path->Endpoint()); if(job->SendRequestViaPath(path, Router())) { diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index a154fc7f3..49d4e2659 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace llarp { @@ -127,12 +128,9 @@ namespace llarp /// don't use it if we are marked bad if(markedBad) return; - p->SetDataHandler(std::bind(&OutboundContext::HandleHiddenServiceFrame, - this, std::placeholders::_1, - std::placeholders::_2)); - p->SetDropHandler(std::bind(&OutboundContext::HandleDataDrop, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)); + p->SetDataHandler( + util::memFn(&OutboundContext::HandleHiddenServiceFrame, this)); + p->SetDropHandler(util::memFn(&OutboundContext::HandleDataDrop, this)); // we now have a path to the next intro, swap intros if(p->Endpoint() == m_NextIntro.router && remoteIntro != m_NextIntro) SwapIntros(); @@ -198,10 +196,7 @@ namespace llarp if(path) { HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup( - m_Endpoint, - std::bind(&OutboundContext::OnIntroSetUpdate, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), + m_Endpoint, util::memFn(&OutboundContext::OnIntroSetUpdate, this), addr, m_Endpoint->GenTXID()); updatingIntroSet = job->SendRequestViaPath(path, m_Endpoint->Router()); diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index d4d9599b7..1912e127d 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace llarp { @@ -315,9 +316,8 @@ namespace llarp // PKE (A, B, N) SharedSecret sharedSecret; - using namespace std::placeholders; - path_dh_func dh_server = std::bind( - &Crypto::dh_server, CryptoManager::instance(), _1, _2, _3, _4); + path_dh_func dh_server = + util::memFn(&Crypto::dh_server, CryptoManager::instance()); if(!self->m_LocalIdentity.KeyExchange(dh_server, sharedSecret, self->msg->sender, self->frame.N)) diff --git a/llarp/utp/session.cpp b/llarp/utp/session.cpp index 5ef039b6f..0dcda28a9 100644 --- a/llarp/utp/session.cpp +++ b/llarp/utp/session.cpp @@ -4,13 +4,12 @@ #include #include #include +#include namespace llarp { namespace utp { - using namespace std::placeholders; - void Session::OnLinkEstablished(ILinkLayer* p) { @@ -613,7 +612,7 @@ namespace llarp ABSL_ATTRIBUTE_UNUSED void* res = utp_set_userdata(sock, this); assert(res == this); assert(s == sock); - GotLIM = std::bind(&InboundSession::InboundLIM, this, _1); + GotLIM = util::memFn(&InboundSession::InboundLIM, this); } bool @@ -678,7 +677,7 @@ namespace llarp gotLIM = true; EnterState(eSessionReady); /// future LIM are used for session renegotiation - GotLIM = std::bind(&Session::GotSessionRenegotiate, this, _1); + GotLIM = util::memFn(&Session::GotSessionRenegotiate, this); } return true; } @@ -702,7 +701,7 @@ namespace llarp assert(res == this); assert(s == sock); - GotLIM = std::bind(&OutboundSession::OutboundLIM, this, _1); + GotLIM = util::memFn(&OutboundSession::OutboundLIM, this); } void @@ -729,7 +728,7 @@ namespace llarp return false; } /// future LIM are used for session renegotiation - GotLIM = std::bind(&Session::GotSessionRenegotiate, this, _1); + GotLIM = util::memFn(&Session::GotSessionRenegotiate, this); EnterState(eSessionReady); return true; } diff --git a/llarp/utp/utp.cpp b/llarp/utp/utp.cpp index da544d9cd..495199bcd 100644 --- a/llarp/utp/utp.cpp +++ b/llarp/utp/utp.cpp @@ -1,14 +1,13 @@ #include -#include #include +#include +#include namespace llarp { namespace utp { - using namespace std::placeholders; - LinkLayer_ptr NewServer(const SecretKey& routerEncSecret, GetRCFunc getrc, LinkMessageHandler h, SessionEstablishedHandler est, @@ -22,15 +21,14 @@ namespace llarp LinkLayer_ptr NewServerFromRouter(AbstractRouter* r) { - using namespace std::placeholders; return NewServer( - r->encryption(), std::bind(&AbstractRouter::rc, r), - std::bind(&AbstractRouter::HandleRecvLinkMessageBuffer, r, _1, _2), - std::bind(&AbstractRouter::OnSessionEstablished, r, _1), - std::bind(&AbstractRouter::CheckRenegotiateValid, r, _1, _2), - std::bind(&AbstractRouter::Sign, r, _1, _2), - std::bind(&AbstractRouter::OnConnectTimeout, r, _1), - std::bind(&AbstractRouter::SessionClosed, r, _1)); + r->encryption(), util::memFn(&AbstractRouter::rc, r), + util::memFn(&AbstractRouter::HandleRecvLinkMessageBuffer, r), + util::memFn(&AbstractRouter::OnSessionEstablished, r), + util::memFn(&AbstractRouter::CheckRenegotiateValid, r), + util::memFn(&AbstractRouter::Sign, r), + util::memFn(&AbstractRouter::OnConnectTimeout, r), + util::memFn(&AbstractRouter::SessionClosed, r)); } } // namespace utp