Browse Source

Remove time-dependent profile matching from connection setup

master
evgeny 1 week ago
parent
commit
e47ae480f5
  1. 9
      src/routing_layer/conn_mgr_core.c
  2. 12
      src/transport_layer/node_conn_direct.c

9
src/routing_layer/conn_mgr_core.c

@ -102,14 +102,12 @@ uint8_t cm_classify_v6_addr(const uint8_t addr[16]) {
int cm_has_direct_ip(struct CONN_MGR* mgr, struct TOPO_GROUP_NODE* nq) {
struct TOPO_NODE* ni = nq ? topo_node_registry_find(mgr->instance->topo_groups, nq->node_id) : NULL;
if (!ni) return 0;
int64_t current = ntp_time_get_us(mgr->instance);
uint64_t now_us = current > 0 ? (uint64_t)current : 0;
for (const struct TOPO_ADDR4* a = ni->v4_addrs; a; a = a->next) {
if (!(a->protocol & (TOPO_PROTO_UDP | TOPO_PROTO_TCP))) continue;
uint32_t ip; memcpy(&ip, a->addr, 4);
for (const struct TOPO_SOCKMETA4* m = ni->v4_sock_meta; m; m = m->next) {
if (m->id != a->socket_id) continue;
uint8_t cls = sock_target_class(a->type, m->config_type, &m->address_profile, ip_is_public(ip), now_us);
uint8_t cls = sock_target_class(a->type, m->config_type, &m->address_profile, ip_is_public(ip));
if (cls != SOCK_TC_PRIV && cls != SOCK_TC_UNREACH) return 1;
if (a->type == TOPO_ADDR_INTERFACE && m->config_type == CFG_SERVER_TYPE_PUBLIC) return 1;
}
@ -119,7 +117,7 @@ int cm_has_direct_ip(struct CONN_MGR* mgr, struct TOPO_GROUP_NODE* nq) {
for (const struct TOPO_SOCKMETA6 *meta = ni->v6_sock_meta; meta; meta = meta->next) {
if (meta->id != a->socket_id) continue;
uint8_t cls = sock_target_class(a->type, meta->config_type, &meta->address_profile,
cm_classify_v6_addr(a->addr) == CM_V6_DIR, now_us);
cm_classify_v6_addr(a->addr) == CM_V6_DIR);
if (cls != SOCK_TC_PRIV && cls != SOCK_TC_UNREACH) return 1;
if (a->type == TOPO_ADDR_INTERFACE && meta->config_type == CFG_SERVER_TYPE_PUBLIC) return 1;
}
@ -625,13 +623,12 @@ void cm_start_local_scan(struct CONN_MGR_ENTRY* entry) {
(unsigned long long)entry->node_id); return;
}
int addresses = 0;
int64_t current = ntp_time_get_us(entry->mgr->instance);
for (const struct TOPO_ADDR4* a = ni->v4_addrs; a; a = a->next) {
if (!(a->protocol & (TOPO_PROTO_UDP | TOPO_PROTO_TCP))) continue;
uint32_t ip; memcpy(&ip, a->addr, 4);
for (const struct TOPO_SOCKMETA4* m = ni->v4_sock_meta; m; m = m->next)
if (m->id == a->socket_id && sock_target_class(a->type, m->config_type, &m->address_profile,
ip_is_public(ip), current > 0 ? (uint64_t)current : 0) == SOCK_TC_PRIV) {
ip_is_public(ip)) == SOCK_TC_PRIV) {
addresses++; break;
}
}

12
src/transport_layer/node_conn_direct.c

@ -270,8 +270,7 @@ static int ncd_create_links(struct ncd_entry* entry, struct TOPO_NODE* ni,
if (mm->id == a->socket_id) { m = mm; break; }
uint8_t tcfg = m ? m->config_type : CFG_SERVER_TYPE_UNKNOWN;
const struct address_profile *profile = m ? &m->address_profile : NULL;
uint8_t target_class = sock_target_class(a->type, tcfg, profile, ip_is_public(tip),
nviews ? views[0].now_us : (uint64_t)ntp_time_get_us(inst));
uint8_t target_class = sock_target_class(a->type, tcfg, profile, ip_is_public(tip));
if (target_class == SOCK_TC_UNREACH) { v4_skip++; continue; }
if (a->protocol & TOPO_PROTO_TCP) {
@ -321,9 +320,8 @@ static int ncd_create_links(struct ncd_entry* entry, struct TOPO_NODE* ni,
const struct TOPO_SOCKMETA6 *metadata = ni->v6_sock_meta;
while (metadata && metadata->id != a->socket_id) metadata = metadata->next;
int global = (a->addr[0] & 0xe0) == 0x20;
int64_t current = ntp_time_get_us(inst);
uint8_t target_class = sock_target_class(a->type, metadata ? metadata->config_type : CFG_SERVER_TYPE_UNKNOWN,
metadata ? &metadata->address_profile : NULL, global, current > 0 ? (uint64_t)current : 0);
metadata ? &metadata->address_profile : NULL, global);
if (target_class == SOCK_TC_UNREACH) { v6_skip++; continue; }
struct sockaddr_in6 sin6; memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6;
memcpy(&sin6.sin6_addr, a->addr, 16); sin6.sin6_port = htons(a->port);
@ -390,8 +388,6 @@ int node_conn_direct_compatible(struct UTUN_INSTANCE* inst, uint64_t node_id) {
* Это возможность попытки, не подтверждение маршрута/работоспособности скрытых сокетов пира. */
const struct TOPO_NODE* self = topo_node_registry_find(inst->topo_groups, inst->node_id);
if (!self) return 0;
int64_t current = ntp_time_get_us(inst);
uint64_t now_us = current > 0 ? (uint64_t)current : 0;
for (const struct TOPO_ADDR4* a = self->v4_addrs; a; a = a->next) {
uint32_t ip; memcpy(&ip, a->addr, 4);
if (!ip || !a->port) continue;
@ -399,7 +395,7 @@ int node_conn_direct_compatible(struct UTUN_INSTANCE* inst, uint64_t node_id) {
while (meta && meta->id != a->socket_id) meta = meta->next;
uint8_t cfg = meta ? meta->config_type : CFG_SERVER_TYPE_UNKNOWN;
const struct address_profile *profile = meta ? &meta->address_profile : NULL;
uint8_t target_class = sock_target_class(a->type, cfg, profile, ip_is_public(ip), now_us);
uint8_t target_class = sock_target_class(a->type, cfg, profile, ip_is_public(ip));
if (target_class == SOCK_TC_PRIV || target_class == SOCK_TC_UNREACH) continue;
if ((a->protocol & TOPO_PROTO_REALITY) && !topo_node_find_reality_sock(self, a->socket_id)) continue;
if (a->protocol & TOPO_PROTO_TCP) return 1;
@ -408,7 +404,7 @@ int node_conn_direct_compatible(struct UTUN_INSTANCE* inst, uint64_t node_id) {
if (!(remote->protocol & TOPO_PROTO_UDP)) continue;
const struct TOPO_SOCKMETA4* rm = node->v4_sock_meta;
while (rm && rm->id != remote->socket_id) rm = rm->next;
struct sock_view view = {.has_inet = 1, .now_us = now_us};
struct sock_view view = {.has_inet = 1};
if (rm) view.address_profile = rm->address_profile;
for (const struct TOPO_ADDR4* ra = node->v4_addrs; ra; ra = ra->next)
if (ra->socket_id == remote->socket_id && ra->type == TOPO_ADDR_NAT) memcpy(&view.public_ip4, ra->addr, 4);

Loading…
Cancel
Save