| 1127 | |
| 1128 | |
| 1129 | void LibeventSSLSocketImpl::accept_SSL_callback(AcceptRequest* request) |
| 1130 | { |
| 1131 | CHECK(__in_event_loop__); |
| 1132 | |
| 1133 | // Set up SSL object. |
| 1134 | SSL* ssl = SSL_new(openssl::context()); |
| 1135 | if (ssl == nullptr) { |
| 1136 | request->promise.fail("Accept failed, SSL_new"); |
| 1137 | delete request; |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | Try<Address> peer_address = network::peer(request->socket); |
| 1142 | if (!peer_address.isSome()) { |
| 1143 | request->promise.fail("Could not determine peer IP for connection."); |
| 1144 | delete request; |
| 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | // NOTE: Right now, the configure callback does not do anything in server |
| 1149 | // mode, but we still pass the correct peer address to enable modules to |
| 1150 | // implement application-level logic in the future. |
| 1151 | Try<Nothing> configured = openssl::configure_socket( |
| 1152 | ssl, openssl::Mode::SERVER, peer_address.get(), None()); |
| 1153 | |
| 1154 | if (configured.isError()) { |
| 1155 | request->promise.fail("Could not configure socket: " + configured.error()); |
| 1156 | delete request; |
| 1157 | return; |
| 1158 | } |
| 1159 | |
| 1160 | // We use 'request->listener' because 'this->listener' may not have |
| 1161 | // been set by the time this function is executed. See comment in |
| 1162 | // the lambda for evconnlistener_new in |
| 1163 | // 'LibeventSSLSocketImpl::listen'. |
| 1164 | event_base* ev_base = evconnlistener_get_base(request->listener); |
| 1165 | |
| 1166 | // Construct the bufferevent in the accepting state. |
| 1167 | bufferevent* bev = bufferevent_openssl_socket_new( |
| 1168 | ev_base, |
| 1169 | request->socket, |
| 1170 | ssl, |
| 1171 | BUFFEREVENT_SSL_ACCEPTING, |
| 1172 | BEV_OPT_THREADSAFE); |
| 1173 | |
| 1174 | if (bev == nullptr) { |
| 1175 | request->promise.fail("Accept failed: bufferevent_openssl_socket_new"); |
| 1176 | SSL_free(ssl); |
| 1177 | delete request; |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | bufferevent_setcb( |
| 1182 | bev, |
| 1183 | nullptr, |
| 1184 | nullptr, |
| 1185 | [](bufferevent* bev, short events, void* arg) { |
| 1186 | // This handles error states or 'BEV_EVENT_CONNECTED' events |
nothing calls this directly
no test coverage detected