@ -727,14 +727,18 @@ void chat_core_connect_auto(uint64_t node_id,
void ( * cb ) ( int result , uint64_t node_id , void * arg ) ,
void * arg ,
void * * out_state ) {
if ( ! g_cc . initialized | | ! g_cc . inst | | ! cb ) return ;
if ( ! g_cc . initialized | | ! g_cc . inst | | ! cb ) {
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (not initialized) node=0x%016llx init=%d inst=%p cb=%p " ,
CC_ID , ( unsigned long long ) node_id , g_cc . initialized , ( void * ) g_cc . inst , ( void * ) cb ) ;
return ;
}
if ( out_state ) * out_state = NULL ;
struct ETCP_SOCKET * best_socket = g_cc . inst - > etcp_sockets ;
while ( best_socket & & best_socket - > local_addr . ss_family ! = AF_INET ) best_socket = best_socket - > next ;
if ( ! best_socket ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: auto_connect no AF_INET socket for node 0x%016llx " ,
CC_ID , ( unsigned long long ) node_id ) ;
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (no AF_INET socket) node=0x%016llx sockets=%p " ,
CC_ID , ( unsigned long long ) node_id , ( void * ) g_cc . inst - > etcp_sockets ) ;
cb ( CC_ERR_INTERNAL , node_id , arg ) ;
return ;
}
@ -753,8 +757,8 @@ void chat_core_connect_auto(uint64_t node_id,
sqlite3_finalize ( st ) ;
}
if ( pubkey [ 0 ] = = 0 & & pubkey [ 1 ] = = 0 ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: auto_connect no pubkey for node 0x%016llx " ,
CC_ID , ( unsigned long long ) node_id ) ;
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (no pubkey in DB) node= 0x%016llx " ,
CC_ID , ( unsigned long long ) node_id ) ;
cb ( CC_ERR_NOT_FOUND , node_id , arg ) ;
return ;
}
@ -787,13 +791,14 @@ void chat_core_connect_auto(uint64_t node_id,
}
addr_count = uniq ; }
if ( addr_count = = 0 ) {
DEBUG_DEBUG ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect no IPv4 addrs yet for node 0x%016llx (BGP not synced?) " , CC_ID , ( unsigned long long ) node_id ) ;
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (no IPv4 addrs in DB) node=0x%016llx (BGP not synced?) " ,
CC_ID , ( unsigned long long ) node_id ) ;
cb ( CC_ERR_NO_ADDRESSES , node_id , arg ) ;
return ;
}
struct ca_state * pst = u_calloc ( 1 , sizeof ( struct ca_state ) ) ;
if ( ! pst ) { cb ( CC_ERR_INTERNAL , node_id , arg ) ; return ; }
if ( ! pst ) { DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (alloc ca_state) node=0x%016llx " , CC_ID , ( unsigned long long ) node_id ) ; cb ( CC_ERR_INTERNAL , node_id , arg ) ; return ; }
pst - > inst = g_cc . inst ;
pst - > addr_count = addr_count ;
pst - > pending_count = addr_count ;
@ -804,7 +809,7 @@ void chat_core_connect_auto(uint64_t node_id,
pst - > conns = u_calloc ( addr_count , sizeof ( struct ETCP_CONN * ) ) ;
pst - > timers = u_calloc ( addr_count , sizeof ( void * ) ) ;
pst - > ctxs = u_calloc ( addr_count , sizeof ( struct ca_ctx * ) ) ;
if ( ! pst - > conns | | ! pst - > timers | | ! pst - > ctxs ) { ca_cleanup ( pst ) ; cb ( CC_ERR_INTERNAL , node_id , arg ) ; return ; }
if ( ! pst - > conns | | ! pst - > timers | | ! pst - > ctxs ) { DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (alloc arrays) node=0x%016llx " , CC_ID , ( unsigned long long ) node_id ) ; ca_cleanup ( pst ) ; cb ( CC_ERR_INTERNAL , node_id , arg ) ; return ; }
for ( int i = 0 ; i < addr_count ; i + + ) {
struct sockaddr_in sin ;
@ -847,7 +852,8 @@ void chat_core_connect_auto(uint64_t node_id,
if ( out_state ) * out_state = pst ;
if ( pst - > pending_count < = 0 & & ! pst - > delivered ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: auto_connect all %d attempts failed to start " , CC_ID , addr_count ) ;
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: auto_connect FAIL (all %d attempts failed to start) node=0x%016llx " ,
CC_ID , addr_count , ( unsigned long long ) node_id ) ;
if ( out_state ) * out_state = NULL ;
cb ( CC_ERR_UNREACHABLE , node_id , arg ) ;
ca_cleanup ( pst ) ;