| 904 | } |
| 905 | |
| 906 | ACTOR static void doAcceptHandshake(Reference<SSLConnection> self, Promise<Void> connected) { |
| 907 | state Hold<int> holder; |
| 908 | |
| 909 | try { |
| 910 | Future<Void> onHandshook; |
| 911 | ConfigureSSLStream(N2::g_net2->activeTlsPolicy, self->ssl_sock, [this](bool verifyOk) { |
| 912 | self->has_trusted_peer = verifyOk; |
| 913 | }); |
| 914 | |
| 915 | // If the background handshakers are not all busy, use one |
| 916 | if (N2::g_net2->sslPoolHandshakesInProgress < N2::g_net2->sslHandshakerThreadsStarted) { |
| 917 | holder = Hold(&N2::g_net2->sslPoolHandshakesInProgress); |
| 918 | auto handshake = |
| 919 | new SSLHandshakerThread::Handshake(self->ssl_sock, boost::asio::ssl::stream_base::server); |
| 920 | onHandshook = handshake->done.getFuture(); |
| 921 | N2::g_net2->sslHandshakerPool->post(handshake); |
| 922 | } else { |
| 923 | // Otherwise use flow network thread |
| 924 | BindPromise p("N2_AcceptHandshakeError", UID()); |
| 925 | onHandshook = p.getFuture(); |
| 926 | self->ssl_sock.async_handshake(boost::asio::ssl::stream_base::server, std::move(p)); |
| 927 | } |
| 928 | wait(onHandshook); |
| 929 | wait(delay(0, TaskPriority::Handshake)); |
| 930 | connected.send(Void()); |
| 931 | } catch (...) { |
| 932 | self->closeSocket(); |
| 933 | connected.sendError(connection_failed()); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | ACTOR static Future<Void> acceptHandshakeWrapper(Reference<SSLConnection> self) { |
| 938 | state std::pair<IPAddress, uint16_t> peerIP; |