void rendezvous_time_event(nabto_connect* con) { nabto_rendezvous_connect_state* rcs = &con->rendezvousConnectState; if (rcs->state == RS_CONNECTING) { if (nabtoIsStampPassed(&rcs->timestamp)) { send_rendezvous_to_all(con); } #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS if (rcs->openManySockets && nabtoIsStampPassed(&rcs->openManySocketsStamp)) { if (rcs->socketsOpened < NABTO_EXTENDED_RENDEZVOUS_MAX_SOCKETS) { nabto_socket_t* candidate = &rcs->sockets[rcs->socketsOpened]; uint16_t localport = 0; if(nabto_init_socket(0,&localport, candidate)) { rcs->socketsOpened++; send_rendezvous_socket(*candidate, con, 0, &con->cp.globalEndpoint, 0); } else { NABTO_LOG_ERROR(("Could not open socket.")); } nabtoSetFutureStamp(&con->rendezvousConnectState.openManySocketsStamp, 20); } else { rcs->openManySockets = false; } } #endif if (rcs->openManyPorts && nabtoIsStampPassed(&rcs->openManyPortsStamp)) { int i; for (i = 0; i < 10; i++) { nabto_endpoint newEp; uint16_t newPort; nabto_random((uint8_t*)&newPort, sizeof(uint16_t)); newEp.addr = con->cp.globalEndpoint.addr; newEp.port = 1024+(newPort%64500); send_rendezvous(con, 0, &newEp, 0); rcs->portsOpened++; } nabtoSetFutureStamp(&rcs->openManyPortsStamp, 50); } if(nabtoIsStampPassed(&rcs->timeout)) { #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS NABTO_LOG_INFO(("Rendezvous timeout. Sockets opened %i", rcs->socketsOpened)); #endif nabto_rendezvous_stop(con); } } }
void rendezvous_time_event(nabto_connect* con) { nabto_rendezvous_connect_state* rcs = &con->rendezvousConnectState; if (rcs->state == RS_CONNECTING) { if (nabtoIsStampPassed(&rcs->timestamp)) { send_rendezvous_to_all(con); } #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS if (rcs->openManySockets && nabtoIsStampPassed(&rcs->openManySocketsStamp)) { if (rcs->socketsOpened < NABTO_EXTENDED_RENDEZVOUS_MAX_SOCKETS) { nabto_socket_t* candidate = &extended_rendezvous_sockets[rcs->socketsOpened]; send_rendezvous_socket(*candidate, con, 0, &con->cp.globalEndpoint, 0); rcs->socketsOpened++; unabto_connection_set_future_stamp(&con->rendezvousConnectState.openManySocketsStamp, 20); } else { rcs->openManySockets = false; } } #endif if (rcs->openManyPorts && nabtoIsStampPassed(&rcs->openManyPortsStamp)) { int i; for (i = 0; i < 10; i++) { nabto_endpoint newEp; uint16_t newPort = unabto_extended_rendezvous_next_port(&rcs->portSequence, rcs->portsOpened); newEp.addr = con->cp.globalEndpoint.addr; newEp.port = newPort; send_rendezvous(con, 0, &newEp, 0); rcs->portsOpened++; } unabto_connection_set_future_stamp(&rcs->openManyPortsStamp, 50); } if(nabtoIsStampPassed(&rcs->timeout)) { #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS NABTO_LOG_INFO(("Rendezvous timeout. Sockets opened %i", rcs->socketsOpened)); #endif nabto_rendezvous_stop(con); } } }
void nabto_rendezvous_start(nabto_connect* con) { nabto_rendezvous_connect_state* rcs = &con->rendezvousConnectState; rcs->state = RS_CONNECTING; nabtoSetFutureStamp(&rcs->timeout, 5000); nabtoSetFutureStamp(&rcs->timestamp, 0); #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS if (nmc.context.natType == NP_PAYLOAD_IPX_NAT_SYMMETRIC) { con->rendezvousConnectState.openManySockets = true; nabtoSetFutureStamp(&con->rendezvousConnectState.openManySocketsStamp, 20); } #endif if (con->clientNatType == NP_PAYLOAD_IPX_NAT_SYMMETRIC) { con->rendezvousConnectState.openManyPorts = true; nabtoSetFutureStamp(&con->rendezvousConnectState.openManyPortsStamp, 0); } send_rendezvous_to_all(con); }
void nabto_rendezvous_start(nabto_connect* con) { nabto_rendezvous_connect_state* rcs = &con->rendezvousConnectState; rcs->state = RS_CONNECTING; unabto_connection_set_future_stamp(&rcs->timeout, 5000); unabto_connection_set_future_stamp(&rcs->timestamp, 0); #if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS if (nmc.context.natType == NP_PAYLOAD_IPX_NAT_SYMMETRIC && nmc.nabtoMainSetup.enableExtendedRendezvousMultipleSockets) { con->rendezvousConnectState.openManySockets = true; unabto_connection_set_future_stamp(&con->rendezvousConnectState.openManySocketsStamp, 20); } #endif if (con->clientNatType == NP_PAYLOAD_IPX_NAT_SYMMETRIC) { unabto_extended_rendezvous_init_port_sequence(&con->rendezvousConnectState.portSequence, con->cp.globalEndpoint.port); con->rendezvousConnectState.openManyPorts = true; unabto_connection_set_future_stamp(&con->rendezvousConnectState.openManyPortsStamp, 0); } send_rendezvous_to_all(con); }