@ -62,13 +62,16 @@ static int addr_type_from_ip(int family, const uint8_t* addr) {
}
/* Итоговая классификация: конфиг + автоопределение + IP (всё локально). */
static int addr_type_classify ( int config_type , int nat_type , int family , const uint8_t * ip ) {
static int addr_type_classify ( int config_type , int nat_type ) {
if ( config_type = = CFG_SERVER_TYPE_PUBLIC ) return ADDR_TYPE_DIRECT ;
if ( config_type = = CFG_SERVER_TYPE_PRIVATE | | config_type = = CFG_SERVER_TYPE_LOCAL ) return ADDR_TYPE_NETIF ;
if ( nat_type = = NAT_TYPE_EIM ) return ADDR_TYPE_NAT_EIM ;
if ( nat_type = = NAT_TYPE_STRICT ) return ADDR_TYPE_NAT_STRICT ;
if ( nat_type = = NAT_TYPE_DIRECT ) return ADDR_TYPE_DIRECT ;
return addr_type_from_ip ( family , ip ) ;
if ( nat_type = = NAT_VERIFIED_EIM ) return ADDR_TYPE_NAT_EIM ;
if ( nat_type = = NAT_VERIFIED_STRICT ) return ADDR_TYPE_NAT_STRICT ;
if ( nat_type = = NAT_VERIFIED_DIRECT ) return ADDR_TYPE_DIRECT ;
return ADDR_TYPE_NAT ; /* за NAT, тип неизвестен */
}
static void smeta4_lookup ( struct TOPO_SOCKMETA4 * head , uint8_t sid , uint8_t * cfg , uint8_t * nat ) {
@ -115,8 +118,8 @@ int topo_node_sqlite_addrs_put(sqlite3* db, uint64_t node_id, struct TOPO_NODE*
int written = 0 ;
for ( const struct TOPO_ADDR4 * a = ni - > v4_addrs ; a ; a = a - > next ) {
uint8_t cfg , nat ; smeta4_lookup ( ni - > v4_sock_meta , a - > socket_id , & cfg , & nat ) ;
int at = ( a - > type = = TOPO_ADDR_INTERFACE ) ? ADDR_TYPE_NETIF
: addr_type_classify ( cfg , nat , 4 , a - > addr ) ;
int at = ( a - > type = = TOPO_ADDR_INTERFACE ) ? addr_type_from_ip ( 4 , a - > addr )
: addr_type_classify ( cfg , nat ) ;
sqlite3_bind_int64 ( is , 1 , ( sqlite3_int64 ) node_id ) ;
sqlite3_bind_int ( is , 2 , 4 ) ;
sqlite3_bind_int ( is , 3 , ( int ) a - > protocol ) ;
@ -136,7 +139,7 @@ int topo_node_sqlite_addrs_put(sqlite3* db, uint64_t node_id, struct TOPO_NODE*
for ( const struct TOPO_ADDR6 * a = ni - > v6_addrs ; a ; a = a - > next ) {
uint8_t cfg , nat ; smeta6_lookup ( ni - > v6_sock_meta , a - > socket_id , & cfg , & nat ) ;
int at = ( a - > type = = TOPO_ADDR_INTERFACE ) ? ADDR_TYPE_NETIF
: addr_type_classify ( cfg , nat , 6 , a - > addr ) ;
: addr_type_classify ( cfg , nat ) ;
sqlite3_bind_int64 ( is , 1 , ( sqlite3_int64 ) node_id ) ;
sqlite3_bind_int ( is , 2 , 6 ) ;
sqlite3_bind_int ( is , 3 , ( int ) a - > protocol ) ;
@ -747,7 +750,7 @@ int topo_node_sqlite_nodeinfo_updated(sqlite3* db, uint64_t node_id) {
}
}
static const int at2type [ ] = { [ ADDR_TYPE_NETIF ] = 1 , [ ADDR_TYPE_DIRECT ] = 1 , [ ADDR_TYPE_NAT_EIM ] = 2 , [ ADDR_TYPE_NAT_STRICT ] = 1 } ;
static const int at2type [ ] = { [ ADDR_TYPE_NETIF ] = 1 , [ ADDR_TYPE_DIRECT ] = 1 , [ ADDR_TYPE_NAT_EIM ] = 2 , [ ADDR_TYPE_NAT_STRICT ] = 1 , [ ADDR_TYPE_NAT ] = 2 } ;
int base_type = ( best_at < 0 ) ? 0 : at2type [ best_at ] ;
sqlite3_stmt * s = NULL ;