@ -1553,7 +1553,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
goto process_decrypted ;
}
// Normal decryption failed - might be INIT packet, fall through to INIT handling
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION , " Normal decryption failed, trying INIT decryption " ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " Normal decryption failed, trying INIT decryption " ) ;
}
// Try INIT decryption (for incoming connection requests)
@ -1578,6 +1578,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
errorcode = 2 ;
goto ec_fr ;
}
DEBUG_INFO ( DEBUG_CATEGORY_CRYPTO , " INIT X25519 OK from %s " , sockaddr_storage_to_str ( & addr ) . str ) ;
if ( sc_decrypt ( & sc , data , recv_len - SC_PUBKEY_ENC_SIZE , ( uint8_t * ) & pkt - > timestamp , & pkt_len ) ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CRYPTO , " failed to decrypt init packet, from %s " , sockaddr_storage_to_str ( & addr ) . str ) ;
errorcode = 3 ;
@ -1601,11 +1602,15 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
uint8_t code = pkt - > data [ 0 ] ;
uint64_t peer_id = be64toh ( * ( uint64_t * ) ( pkt - > data + 1 ) ) ;
if ( code = = ETCP_PING ) {
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION , " INIT decrypted: PING from peer=0x%016llx src=%s " ,
( unsigned long long ) peer_id , sockaddr_storage_to_str ( & addr ) . str ) ;
int ret = handle_ping ( e_sock , pkt , & addr , decrypted_pubkey , pkt_len ) ;
if ( ret ) { errorcode = ret ; goto ec_fr ; }
return ;
}
if ( code = = ETCP_PONG ) {
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION , " INIT decrypted: PONG from peer=0x%016llx src=%s " ,
( unsigned long long ) peer_id , sockaddr_storage_to_str ( & addr ) . str ) ;
int ret = handle_pong ( e_sock , pkt , & addr , pkt_len ) ;
if ( ret ) { errorcode = ret ; goto ec_fr ; }
return ;
@ -1652,7 +1657,15 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
struct ETCP_INIT_REQUEST_PKT * req = ( struct ETCP_INIT_REQUEST_PKT * ) pkt - > data ;
uint32_t session_id = be32toh ( * ( uint32_t * ) req - > session_id ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " INIT request session_id=%08x " , session_id ) ;
uint16_t mtu = be16toh ( * ( uint16_t * ) req - > mtu ) ;
uint16_t src_port = be16toh ( * ( uint16_t * ) req - > src_port ) ;
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION ,
" INIT accepted: peer=0x%016llx mtu=%u link=%u sock=%u type=%d local=%d "
" src_ip=%d.%d.%d.%d:%u session=%08x src=%s " ,
( unsigned long long ) peer_id , mtu , req - > link_id , req - > socket_id ,
req - > type , req - > only_local ,
req - > src_ipv4 [ 0 ] , req - > src_ipv4 [ 1 ] , req - > src_ipv4 [ 2 ] , req - > src_ipv4 [ 3 ] ,
src_port , session_id , sockaddr_storage_to_str ( & addr ) . str ) ;
struct ETCP_CONN * conn = e_sock - > instance - > connections ;
while ( conn ) { // ищем есть ли подключение к этому пиру