static void ADC_client_on_connected(struct ADC_client* client) { ADC_TRACE; #ifdef SSL_SUPPORT if (client->flags & cflag_ssl) { net_con_update(client->con, NET_EVENT_READ | NET_EVENT_WRITE); client->callback(client, ADC_CLIENT_SSL_HANDSHAKE, 0); ADC_client_set_state(client, ps_conn_ssl); net_con_ssl_handshake(client->con, net_con_ssl_mode_client, g_adc_client->ctx); } else #endif ADC_client_send_handshake(client); }
static void probe_net_event(struct net_connection* con, int events, void *arg) { struct hub_probe* probe = (struct hub_probe*) net_con_get_ptr(con); if (events == NET_EVENT_TIMEOUT) { char buf[512]; ssize_t len = snprintf(buf, sizeof(buf), "This hub runs on ADC protocol only!\n\nThese are the possible reasons why you see this message:\n\n * you used address without protocol specification, e.g. example.com:1234 instead of adc://example.com:1234\n * your client does not support ADC protocol.\n|$ForceMove %s|", probe->hub->config->nmdc_only_redirect_addr); net_con_send(con, buf, (size_t) len); probe_destroy(probe); return; } if (events & NET_EVENT_READ) { int bytes = net_con_peek(con, probe_recvbuf, PROBE_RECV_SIZE); if (bytes < 0) { probe_destroy(probe); return; } if (bytes >= 4) { if (memcmp(probe_recvbuf, "HSUP", 4) == 0) { LOG_TRACE("Probed ADC"); #ifdef SSL_SUPPORT if (probe->hub->config->tls_enable && probe->hub->config->tls_require) { LOG_TRACE("Not TLS connection - closing connection."); if (*probe->hub->config->tls_require_redirect_addr) { char buf[512]; ssize_t len = snprintf(buf, sizeof(buf), "ISUP " ADC_PROTO_SUPPORT "\nISID AAAB\nIINF NIRedirecting...\nIQUI AAAB RD%s\n", probe->hub->config->tls_require_redirect_addr); net_con_send(con, buf, (size_t) len); LOG_TRACE("Not TLS connection - Redirecting to %s.", probe->hub->config->tls_require_redirect_addr); } else { LOG_TRACE("Not TLS connection - closing connection."); } } else #endif if (user_create(probe->hub, probe->connection, &probe->addr)) { probe->connection = 0; } probe_destroy(probe); return; } else if ((memcmp(probe_recvbuf, "GET ", 4) == 0) || (memcmp(probe_recvbuf, "POST", 4) == 0) || (memcmp(probe_recvbuf, "HEAD", 4) == 0)) { /* Looks like HTTP - Not supported, but we log it. */ LOG_TRACE("Probed HTTP connection. Not supported closing connection (%s)", ip_convert_to_string(&probe->addr)); const char* buf = "501 Not implemented\r\n\r\n"; net_con_send(con, buf, strlen(buf)); } #ifdef SSL_SUPPORT else if (bytes >= 11 && probe_recvbuf[0] == 22 && probe_recvbuf[1] == 3 && /* protocol major version */ probe_recvbuf[5] == 1 && /* message type */ probe_recvbuf[9] == probe_recvbuf[1]) { if (probe->hub->config->tls_enable) { LOG_TRACE("Probed TLS %d.%d connection", (int) probe_recvbuf[1], (int) probe_recvbuf[2]); if (user_create(probe->hub, probe->connection, &probe->addr)) { probe->connection = 0; } net_con_ssl_handshake(con, net_con_ssl_mode_server, probe->hub->ctx); } else { LOG_TRACE("Probed TLS %d.%d connection. TLS disabled in hub.", (int) probe_recvbuf[9], (int) probe_recvbuf[10]); } } else { LOG_TRACE("Probed unsupported protocol: %x%x%x%x.", (int) probe_recvbuf[0], (int) probe_recvbuf[1], (int) probe_recvbuf[2], (int) probe_recvbuf[3]); } #endif probe_destroy(probe); return; } } }