bool conclude_connection(nabto_connect* con, nabto_endpoint* peer, uint32_t interval) {
    NABTO_LOG_TRACE(("conclude connection, %i", interval));
    if (con->rendezvousConnectState.state != RS_DONE) {
        con->timeOut = 7*interval/2;
        nabtoSetFutureStamp(&con->stamp, con->timeOut); // Give extra time in the connect phase.
    }
    nabto_rendezvous_stop(con);
    return true;
}
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);
        }
    }
} 
Пример #3
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 nabto_rendezvous_end(nabto_connect* con) {
    nabto_rendezvous_stop(con);

#if NABTO_ENABLE_EXTENDED_RENDEZVOUS_MULTIPLE_SOCKETS
    {
        nabto_rendezvous_connect_state* rcs = &con->rendezvousConnectState;

        if (!rcs->socketsHasBeenClosed) {
            int i;
            for (i = 0; i < rcs->socketsOpened; i++) {
                if (con->socket == rcs->sockets[i]) {
                    // do not close this socket!
                } else {
                    NABTO_LOG_TRACE(("Rendezvous end, closing socket %i", rcs->sockets[i]));
                    nabto_close_socket(&rcs->sockets[i]);
                }
            }
            rcs->socketsHasBeenClosed = true;
        }
    }
#endif
}
Пример #5
0
void nabto_rendezvous_end(nabto_connect* con) {
    nabto_rendezvous_stop(con);
}