@ -21,7 +21,7 @@ struct DB_SYNC;
struct DB_SYNC_INSTANCE ;
static void db_sync_recv_cb ( struct ETCP_CONN * conn , struct ll_entry * entry ) ;
static void db_sync_on_new_ conn ( struct ETCP_CONN * conn , void * arg ) ;
static void db_sync_on_conn_status ( struct ETCP_CONN * conn , int status , void * arg ) ;
static void db_sync_on_conn_up ( struct ETCP_CONN * conn , void * arg ) ;
static void db_sync_on_conn_down ( struct ETCP_CONN * conn , void * arg ) ;
static void db_sync_peer_check_cb ( void * arg ) ;
@ -1094,6 +1094,15 @@ static void db_sync_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry)
// Connection callbacks
// ============================================================
static void db_sync_on_conn_status ( struct ETCP_CONN * conn , int status , void * arg ) {
switch ( status ) {
case ETCP_CONN_STATUS_UP : db_sync_on_conn_up ( conn , arg ) ; break ;
case ETCP_CONN_STATUS_DOWN : db_sync_on_conn_down ( conn , arg ) ; break ;
default : break ;
}
}
#if 0 /* replaced by db_sync_on_conn_status */
static void db_sync_on_new_conn ( struct ETCP_CONN * conn , void * arg )
{
( void ) arg ;
@ -1102,6 +1111,7 @@ static void db_sync_on_new_conn(struct ETCP_CONN* conn, void* arg)
etcp_conn_add_up_cbk ( conn , db_sync_on_conn_up , NULL ) ;
etcp_conn_add_down_cbk ( conn , db_sync_on_conn_down , NULL ) ;
}
# endif
static void db_sync_on_conn_up ( struct ETCP_CONN * conn , void * arg )
{
@ -1355,19 +1365,7 @@ int db_sync_init(struct UTUN_INSTANCE* inst)
}
etcp_bind ( inst , ETCP_RT_ID_DB_SYNC , db_sync_recv_cb ) ;
etcp_set_new_conn_cbk ( inst , db_sync_on_new_conn , NULL ) ;
{
struct ll_entry * entry = inst - > connections - > head ;
while ( entry ) {
struct conn_queue_entry * ce = ( struct conn_queue_entry * ) entry - > data ;
if ( ce & & ce - > conn ) {
etcp_conn_add_up_cbk ( ce - > conn , db_sync_on_conn_up , NULL ) ;
etcp_conn_add_down_cbk ( ce - > conn , db_sync_on_conn_down , NULL ) ;
}
entry = entry - > next ;
}
}
etcp_add_conn_status_cbk ( inst , db_sync_on_conn_status , NULL ) ;
if ( db - > enabled )
db - > peer_check_timer = uasync_set_timeout ( inst - > ua , DB_SYNC_PEER_CHECK_INTERVAL * 10000u ,
@ -1394,17 +1392,7 @@ void db_sync_destroy(struct UTUN_INSTANCE* inst)
if ( si - > peers ) u_free ( si - > peers ) ;
}
{
struct ll_entry * entry = inst - > connections - > head ;
while ( entry ) {
struct conn_queue_entry * ce = ( struct conn_queue_entry * ) entry - > data ;
if ( ce & & ce - > conn ) {
etcp_conn_remove_up_cbk ( ce - > conn , db_sync_on_conn_up , NULL ) ;
etcp_conn_remove_down_cbk ( ce - > conn , db_sync_on_conn_down , NULL ) ;
}
entry = entry - > next ;
}
}
etcp_remove_conn_status_cbk ( inst , db_sync_on_conn_status , NULL ) ;
db_sqlite_close ( db ) ;
if ( db - > instances ) u_free ( db - > instances ) ;