MCPcopy Create free account
hub / github.com/apple/foundationdb / connect

Method connect

flow/Net2.actor.cpp:857–898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

855
856 // This is not part of the IConnection interface, because it is wrapped by INetwork::connect()
857 ACTOR static Future<Reference<IConnection>> connect(boost::asio::io_service* ios,
858 Reference<ReferencedObject<boost::asio::ssl::context>> context,
859 NetworkAddress addr,
860 tcp::socket* existingSocket = nullptr) {
861 std::pair<IPAddress, uint16_t> peerIP = std::make_pair(addr.ip, addr.port);
862 auto iter(g_network->networkInfo.serverTLSConnectionThrottler.find(peerIP));
863 if (iter != g_network->networkInfo.serverTLSConnectionThrottler.end()) {
864 if (now() < iter->second.second) {
865 if (iter->second.first >= FLOW_KNOBS->TLS_CLIENT_CONNECTION_THROTTLE_ATTEMPTS) {
866 TraceEvent("TLSOutgoingConnectionThrottlingWarning").suppressFor(1.0).detail("PeerIP", addr);
867 wait(delay(FLOW_KNOBS->CONNECTION_MONITOR_TIMEOUT));
868 throw connection_failed();
869 }
870 } else {
871 g_network->networkInfo.serverTLSConnectionThrottler.erase(peerIP);
872 }
873 }
874
875 if (existingSocket != nullptr) {
876 Reference<SSLConnection> self(new SSLConnection(context, existingSocket));
877 self->peer_address = addr;
878 self->init();
879 return self;
880 }
881
882 state Reference<SSLConnection> self(new SSLConnection(*ios, context));
883 self->peer_address = addr;
884 try {
885 auto to = tcpEndpoint(self->peer_address);
886 BindPromise p("N2_ConnectError", self->id);
887 Future<Void> onConnected = p.getFuture();
888 self->socket.async_connect(to, std::move(p));
889
890 wait(onConnected);
891 self->init();
892 return self;
893 } catch (Error&) {
894 // Either the connection failed, or was cancelled by the caller
895 self->closeSocket();
896 throw;
897 }
898 }
899
900 // This is not part of the IConnection interface, because it is wrapped by IListener::accept()
901 void accept(NetworkAddress peerAddr) {

Callers

nothing calls this directly

Calls 12

nowFunction · 0.85
TraceEventClass · 0.85
delayFunction · 0.85
tcpEndpointFunction · 0.85
moveFunction · 0.85
detailMethod · 0.80
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
initMethod · 0.45
getFutureMethod · 0.45
closeSocketMethod · 0.45

Tested by

no test coverage detected