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);
        }
    }
} 
Beispiel #2
0
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 send_rendezvous_to_all(nabto_connect* con) {
    send_rendezvous(con, 0, &con->cp.privateEndpoint, 0);
    send_rendezvous(con, 0, &con->cp.globalEndpoint, 0);
    nabtoSetFutureStamp(&con->rendezvousConnectState.timestamp, 1000);
}