Browse Source

Remove measurement IDs and timestamps from NODEINFO profiles

stream-multiview
evgeny 1 week ago
parent
commit
38eaae8bb6
  1. 13
      src/routing_layer/address_profile.h
  2. 32
      src/routing_layer/topo_node.c
  3. 2
      src/routing_layer/topo_node.h

13
src/routing_layer/address_profile.h

@ -1,5 +1,5 @@
/* Профиль конкретного endpoint: изменение адреса и доступность входа независимы.
* checked_at — время измерения владельца в Unix microseconds, не версия NODEINFO.
* Последнее успешное измерение действует до изменения endpoint или нового результата.
* Профиль помогает выбирать попытки; работоспособность подтверждает транспорт. */
#ifndef ADDRESS_PROFILE_H
#define ADDRESS_PROFILE_H
@ -21,14 +21,10 @@ enum address_inbound {
enum address_profile_source { ADDRESS_SOURCE_NONE, ADDRESS_SOURCE_ETCP, ADDRESS_SOURCE_STUN };
#define ADDRESS_PROFILE_TTL_US UINT64_C(300000000)
struct address_profile {
uint8_t mapping;
uint8_t inbound;
uint8_t source; /* ETCP — этот endpoint; STUN — резервная оценка его IP/netif. */
uint64_t evidence_id;
uint64_t checked_at;
};
static inline const char *address_mapping_name(uint8_t value) {
@ -50,12 +46,7 @@ static inline int address_profile_valid(const struct address_profile *profile) {
return profile && profile->mapping <= ADDRESS_MAP_DEPENDENT && profile->inbound <= ADDRESS_IN_CONTACT &&
profile->source <= ADDRESS_SOURCE_STUN &&
((!profile->mapping && !profile->inbound && profile->source == ADDRESS_SOURCE_NONE) ||
((profile->mapping || profile->inbound) && profile->source && profile->evidence_id && profile->checked_at));
}
static inline int address_profile_fresh(const struct address_profile *profile, uint64_t now_us) {
return profile && profile->evidence_id && profile->checked_at && now_us >= profile->checked_at &&
now_us - profile->checked_at <= ADDRESS_PROFILE_TTL_US;
((profile->mapping || profile->inbound) && profile->source));
}
#endif

32
src/routing_layer/topo_node.c

@ -93,8 +93,7 @@ static int sockmeta4_list_equal(struct TOPO_SOCKMETA4* a, struct TOPO_SOCKMETA4*
while (a && b) {
if (a->id != b->id || a->config_type != b->config_type ||
a->address_profile.source != b->address_profile.source ||
a->address_profile.mapping != b->address_profile.mapping || a->address_profile.inbound != b->address_profile.inbound ||
a->address_profile.evidence_id != b->address_profile.evidence_id || a->address_profile.checked_at != b->address_profile.checked_at)
a->address_profile.mapping != b->address_profile.mapping || a->address_profile.inbound != b->address_profile.inbound)
return 0;
a = a->next; b = b->next;
}
@ -112,8 +111,7 @@ static int sockmeta6_list_equal(struct TOPO_SOCKMETA6* a, struct TOPO_SOCKMETA6*
while (a && b) {
if (a->id != b->id || a->config_type != b->config_type ||
a->address_profile.source != b->address_profile.source ||
a->address_profile.mapping != b->address_profile.mapping || a->address_profile.inbound != b->address_profile.inbound ||
a->address_profile.evidence_id != b->address_profile.evidence_id || a->address_profile.checked_at != b->address_profile.checked_at)
a->address_profile.mapping != b->address_profile.mapping || a->address_profile.inbound != b->address_profile.inbound)
return 0;
a = a->next; b = b->next;
}
@ -350,19 +348,11 @@ void topo_node_registry_unref(struct TOPO_GROUPS* groups, uint64_t node_id) {
static void sockmeta_wire_write(uint8_t *out, uint8_t id, uint8_t config, const struct address_profile *profile) {
out[0] = id; out[1] = config; out[2] = profile->mapping; out[3] = profile->inbound;
out[4] = profile->source;
for (unsigned i = 0; i < 8; i++) {
out[5 + i] = (uint8_t)(profile->evidence_id >> (56 - i * 8));
out[13 + i] = (uint8_t)(profile->checked_at >> (56 - i * 8));
}
}
static int sockmeta_wire_read(const uint8_t *in, struct address_profile *profile) {
memset(profile, 0, sizeof(*profile)); profile->mapping = in[2]; profile->inbound = in[3];
profile->source = in[4];
for (unsigned i = 0; i < 8; i++) {
profile->evidence_id = (profile->evidence_id << 8) | in[5 + i];
profile->checked_at = (profile->checked_at << 8) | in[13 + i];
}
if (!address_profile_valid(profile)) { DEBUG_WARN(DEBUG_CATEGORY_BGP, "invalid address profile in NODEINFO"); return -1; }
return 0;
}
@ -834,10 +824,9 @@ void topo_node_dump_all(struct TOPO_GROUP* group) {
int si = 0;
{ struct TOPO_SOCKMETA4* sm = ni->v4_sock_meta; while (sm) {
DEBUG_INFO(DEBUG_CATEGORY_BGP, " v4sock[%d]: id=%u config=%u mapping=%s inbound=%s evidence=%016llx checked=%llu",
DEBUG_INFO(DEBUG_CATEGORY_BGP, " v4sock[%d]: id=%u config=%u mapping=%s inbound=%s source=%s",
si++, sm->id, sm->config_type, address_mapping_name(sm->address_profile.mapping),
address_inbound_name(sm->address_profile.inbound), (unsigned long long)sm->address_profile.evidence_id,
(unsigned long long)sm->address_profile.checked_at);
address_inbound_name(sm->address_profile.inbound), address_profile_source_name(sm->address_profile.source));
sm = sm->next;
}}
{ const char* atn[] = {"INTERFACE","NAT","REAL"};
@ -848,10 +837,9 @@ void topo_node_dump_all(struct TOPO_GROUP* group) {
a = a->next;
}}
{ int si6 = 0; struct TOPO_SOCKMETA6* sm6 = ni->v6_sock_meta; while (sm6) {
DEBUG_INFO(DEBUG_CATEGORY_BGP, " v6sock[%d]: id=%u config=%u mapping=%s inbound=%s evidence=%016llx checked=%llu",
DEBUG_INFO(DEBUG_CATEGORY_BGP, " v6sock[%d]: id=%u config=%u mapping=%s inbound=%s source=%s",
si6++, sm6->id, sm6->config_type, address_mapping_name(sm6->address_profile.mapping),
address_inbound_name(sm6->address_profile.inbound), (unsigned long long)sm6->address_profile.evidence_id,
(unsigned long long)sm6->address_profile.checked_at);
address_inbound_name(sm6->address_profile.inbound), address_profile_source_name(sm6->address_profile.source));
sm6 = sm6->next;
}}
{ int ai6 = 0; struct TOPO_ADDR6* a6 = ni->v6_addrs; while (a6) {
@ -931,9 +919,9 @@ int topo_node_format_all(struct TOPO_GROUP* group, char* buf, size_t buf_size) {
FMT_ADD(" ed25519: "); for (int k = 0; k < SC_PUBKEY_SIZE; k++) FMT_ADD("%02x", ni->ed25519_public_key[k]); FMT_ADD("\n");
{ struct TOPO_SOCKMETA4* sm = ni->v4_sock_meta; int si = 0; while (sm) {
FMT_ADD(" v4sock[%d]: id=%u config=%u mapping=%s inbound=%s checked=%llu\n", si++, sm->id, sm->config_type,
FMT_ADD(" v4sock[%d]: id=%u config=%u mapping=%s inbound=%s source=%s\n", si++, sm->id, sm->config_type,
address_mapping_name(sm->address_profile.mapping), address_inbound_name(sm->address_profile.inbound),
(unsigned long long)sm->address_profile.checked_at); sm = sm->next;
address_profile_source_name(sm->address_profile.source)); sm = sm->next;
}}
{ const char* atn[] = {"INTERFACE","NAT","REAL"}; struct TOPO_ADDR4* a = ni->v4_addrs; int ai = 0; while (a) {
const char* proto = (a->protocol & TOPO_PROTO_REALITY) ? "tcp+reality" : (a->protocol & TOPO_PROTO_TCP) ? "tcp" : (a->protocol & TOPO_PROTO_UDP) ? "udp" : "?";
@ -942,9 +930,9 @@ int topo_node_format_all(struct TOPO_GROUP* group, char* buf, size_t buf_size) {
a = a->next;
}}
{ struct TOPO_SOCKMETA6* sm6 = ni->v6_sock_meta; int s6i = 0; while (sm6) {
FMT_ADD(" v6sock[%d]: id=%u config=%u mapping=%s inbound=%s checked=%llu\n", s6i++, sm6->id, sm6->config_type,
FMT_ADD(" v6sock[%d]: id=%u config=%u mapping=%s inbound=%s source=%s\n", s6i++, sm6->id, sm6->config_type,
address_mapping_name(sm6->address_profile.mapping), address_inbound_name(sm6->address_profile.inbound),
(unsigned long long)sm6->address_profile.checked_at); sm6 = sm6->next;
address_profile_source_name(sm6->address_profile.source)); sm6 = sm6->next;
}}
{ struct TOPO_ADDR6* a6 = ni->v6_addrs; int a6i = 0; while (a6) {
const char* proto = (a6->protocol & TOPO_PROTO_REALITY) ? "tcp+reality" : (a6->protocol & TOPO_PROTO_TCP) ? "tcp" : (a6->protocol & TOPO_PROTO_UDP) ? "udp" : "?";

2
src/routing_layer/topo_node.h

@ -106,12 +106,10 @@ struct TOPO_CONNECTIVITY {
struct TOPOMSG_SOCKMETA4 {
uint8_t id, config_type, mapping, inbound, source;
uint8_t evidence_id[8], checked_at[8];
} __attribute__((packed));
struct TOPOMSG_ADDR4 { uint8_t addr[4]; uint16_t port; uint8_t type, socket_id, protocol; } __attribute__((packed));
struct TOPOMSG_SOCKMETA6 {
uint8_t id, config_type, mapping, inbound, source;
uint8_t evidence_id[8], checked_at[8];
} __attribute__((packed));
struct TOPOMSG_ADDR6 { uint8_t addr[16]; uint16_t port; uint8_t type, socket_id, protocol; } __attribute__((packed));
struct TOPOMSG_SUBNET4 { uint8_t addr[4]; uint8_t prefix_length; } __attribute__((packed));

Loading…
Cancel
Save