@ -967,7 +967,7 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
struct sockaddr_in * sin = ( struct sockaddr_in * ) & lk - > remote_addr ;
uint8_t ip [ 4 ] ; memcpy ( ip , & sin - > sin_addr , 4 ) ; uint16_t port = ntohs ( sin - > sin_port ) ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) ,
" INSERT OR REPLACE INTO node_addresses(node_id,family,address,port,addr_type,socket_id) VALUES(?,4,?,?,0,?) " ) ;
" INSERT OR REPLACE INTO node_addresses(node_id,family,protocol, address,port,addr_type,socket_id) VALUES(?,4,1 ,?,?,0,?) " ) ;
sqlite3_stmt * as = NULL ;
if ( sqlite3_prepare_v2 ( vdb , sql , - 1 , & as , NULL ) = = SQLITE_OK ) {
sqlite3_bind_int64 ( as , 1 , ( sqlite3_int64 ) peer ) ;
@ -1108,14 +1108,15 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
for ( uint8_t i = 0 ; i < addr_cnt & & p + 2 < = pl + len ; i + + ) {
uint8_t fm = * p + + ;
uint8_t sid = * p + + ;
uint8_t proto = * p + + ;
int ip_len = ( fm = = 4 ) ? 4 : 16 ;
if ( p + ip_len + 2 > pl + len ) break ;
const uint8_t * ip = p ; p + = ip_len ;
uint16_t port = ( ( uint16_t ) p [ 0 ] < < 8 ) | p [ 1 ] ; p + = 2 ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) ,
" INSERT OR REPLACE INTO node_addresses(node_id,family,address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,0,?) " ) ;
" INSERT OR REPLACE INTO node_addresses(node_id,family,protocol, address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,?, 0,?) " ) ;
sqlite3_stmt * stmt = NULL ;
if ( sqlite3_prepare_v2 ( db , sql , - 1 , & stmt , NULL ) = = SQLITE_OK ) {
sqlite3_bind_int64 ( stmt , 1 , ( sqlite3_int64 ) node_id ) ;
@ -1268,23 +1269,25 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer,
if ( p + 2 > pl + len ) break ;
uint8_t fm = * p + + ;
uint8_t sid = * p + + ;
uint8_t proto = * p + + ;
int ip_len = ( fm = = 4 ) ? 4 : 16 ;
if ( p + ip_len + 2 > pl + len ) break ;
const uint8_t * ip = p ; p + = ip_len ;
uint16_t port = ( ( uint16_t ) p [ 0 ] < < 8 ) | p [ 1 ] ; p + = 2 ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) ,
" INSERT OR REPLACE INTO node_addresses(node_id,family,address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,0,?) " ) ;
sqlite3_stmt * stmt = NULL ;
if ( sqlite3_prepare_v2 ( db , sql , - 1 , & stmt , NULL ) = = SQLITE_OK ) {
sqlite3_bind_int64 ( stmt , 1 , ( sqlite3_int64 ) node_id ) ;
sqlite3_bind_int ( stmt , 2 , fm ) ;
sqlite3_bind_blob ( stmt , 3 , ip , ip_len , SQLITE_STATIC ) ;
sqlite3_bind_int ( stmt , 4 , ( int ) port ) ;
sqlite3_bind_int ( stmt , 5 , ( int ) sid ) ;
sqlite3_step ( stmt ) ; sqlite3_finalize ( stmt ) ;
}
" INSERT OR REPLACE INTO node_addresses(node_id,family,protocol,address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,?,0,?) " ) ;
sqlite3_stmt * stmt = NULL ;
if ( sqlite3_prepare_v2 ( db , sql , - 1 , & stmt , NULL ) = = SQLITE_OK ) {
sqlite3_bind_int64 ( stmt , 1 , ( sqlite3_int64 ) node_id ) ;
sqlite3_bind_int ( stmt , 2 , fm ) ;
sqlite3_bind_int ( stmt , 3 , ( int ) proto ) ;
sqlite3_bind_blob ( stmt , 4 , ip , ip_len , SQLITE_STATIC ) ;
sqlite3_bind_int ( stmt , 5 , ( int ) port ) ;
sqlite3_bind_int ( stmt , 6 , ( int ) sid ) ;
sqlite3_step ( stmt ) ; sqlite3_finalize ( stmt ) ;
}
if ( fm = = 4 )
DEBUG_INFO ( DEBUG_CATEGORY_DEBUG , " %s: [ADDR_SYNC] WELCOME INSERT node=0x%016llx sock=%d %d.%d.%d.%d:%d " ,
CS_ID , ( unsigned long long ) node_id , sid , ip [ 0 ] , ip [ 1 ] , ip [ 2 ] , ip [ 3 ] , port ) ;
@ -1380,21 +1383,23 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer,
if ( p + 2 > pl + len ) break ;
uint8_t fm = * p + + ;
uint8_t sid = * p + + ;
uint8_t proto = * p + + ;
int ip_len = ( fm = = 4 ) ? 4 : 16 ;
if ( p + ip_len + 2 > pl + len ) break ;
const uint8_t * ip = p ; p + = ip_len ;
uint16_t port = ( ( uint16_t ) p [ 0 ] < < 8 ) | p [ 1 ] ; p + = 2 ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) ,
" INSERT OR REPLACE INTO node_addresses(node_id,family,address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,0,?) " ) ;
" INSERT OR REPLACE INTO node_addresses(node_id,family,protocol, address,port,addr_type,socket_id) "
" VALUES(?,?,?,?,?, 0,?) " ) ;
sqlite3_stmt * stmt = NULL ;
if ( sqlite3_prepare_v2 ( db , sql , - 1 , & stmt , NULL ) = = SQLITE_OK ) {
sqlite3_bind_int64 ( stmt , 1 , ( sqlite3_int64 ) node_id ) ;
sqlite3_bind_int ( stmt , 2 , fm ) ;
sqlite3_bind_blob ( stmt , 3 , ip , ip_len , SQLITE_STATIC ) ;
sqlite3_bind_int ( stmt , 4 , ( int ) port ) ;
sqlite3_bind_int ( stmt , 5 , ( int ) sid ) ;
sqlite3_bind_int ( stmt , 3 , ( int ) proto ) ;
sqlite3_bind_blob ( stmt , 4 , ip , ip_len , SQLITE_STATIC ) ;
sqlite3_bind_int ( stmt , 5 , ( int ) port ) ;
sqlite3_bind_int ( stmt , 6 , ( int ) sid ) ;
sqlite3_step ( stmt ) ; sqlite3_finalize ( stmt ) ;
}
if ( fm = = 4 )