Reconcile BGP paths and advertise selected routes per neighbor
This commit is contained in:
1 parent
546e0c185d
commit
b76e6553bc
9 files changed
+381
-171
No files matched your search
@@ -127,17 +127,24 @@ static int reality_sock_list_equal(struct TOPO_REALITY_SOCK* a, struct TOPO_REAL
|
||||
return a == NULL && b == NULL;
|
||||
}
|
||||
|
||||
/* извлекает hop_list из лучшего живого path в nq->paths (или любого, если живых нет).
|
||||
память принадлежит TOPO_NODEPATH в paths, не освобождать */
|
||||
/* Один выбор для пересылки данных и NODEINFO. Порядок доставки не влияет на равные пути. */
|
||||
struct TOPO_NODEPATH* topo_node_best_path(const struct TOPO_GROUP_NODE* nq) {
|
||||
struct TOPO_NODEPATH* best = NULL;
|
||||
for (struct ll_entry* e = nq && nq->paths ? nq->paths->head : NULL; e; e = e->next) {
|
||||
struct TOPO_NODEPATH* p = (struct TOPO_NODEPATH*)e;
|
||||
if (!p->conn || !p->conn->links_up || p->conn->close_requested) continue;
|
||||
if (!best || p->hop_count < best->hop_count || (p->hop_count == best->hop_count &&
|
||||
p->conn->peer_node_id < best->conn->peer_node_id)) best = p;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/* Цепочка выбранного живого пути; память принадлежит paths, не освобождать. */
|
||||
uint64_t* topo_node_best_hop_list(struct TOPO_GROUP_NODE* nq, uint8_t* out_count, uint16_t* out_rtt) {
|
||||
if (!nq || !nq->paths || !nq->paths->head) { *out_count = 0; if (out_rtt) *out_rtt = 0; return NULL; }
|
||||
struct TOPO_NODEPATH* best = NULL; uint8_t min_hops = 255;
|
||||
struct ll_entry* e = nq->paths->head;
|
||||
while (e) { struct TOPO_NODEPATH* p = (struct TOPO_NODEPATH*)e; if (p->conn && p->conn->links_up && p->hop_count < min_hops) { best = p; min_hops = p->hop_count; } e = e->next; }
|
||||
if (!best) best = (struct TOPO_NODEPATH*)nq->paths->head;
|
||||
*out_count = best->hop_count;
|
||||
if (out_rtt) *out_rtt = best->cumulative_rtt;
|
||||
return (uint64_t*)((uint8_t*)best + sizeof(struct TOPO_NODEPATH));
|
||||
struct TOPO_NODEPATH* best = topo_node_best_path(nq);
|
||||
*out_count = best ? best->hop_count : 0;
|
||||
if (out_rtt) *out_rtt = best ? best->cumulative_rtt : 0;
|
||||
return best ? (uint64_t*)((uint8_t*)best + sizeof(*best)) : NULL;
|
||||
}
|
||||
|
||||
/* Освобождает списки адресов (sock_meta + addrs + reality) узла в глобальном реестре.
|
||||
@@ -708,21 +715,12 @@ void topo_node_ping_update_rtt(struct TOPO_GROUPS* groups, uint64_t node_id, uin
|
||||
}
|
||||
}
|
||||
|
||||
/* Суммарный RTT цепочки до узла: минимальный (rtt_last + cumulative_rtt) среди живых путей. */
|
||||
/* RTT именно выбранного пути, с насыщением вместо переполнения. */
|
||||
uint16_t topo_get_chain_rtt(struct TOPO_GROUP_NODE* nq) {
|
||||
if (!nq || !nq->paths || !nq->paths->head) {
|
||||
return 0xFFFF;
|
||||
}
|
||||
uint16_t best = 0xFFFF;
|
||||
for (struct ll_entry* e = nq->paths->head; e; e = e->next) {
|
||||
struct TOPO_NODEPATH* p = (struct TOPO_NODEPATH*)e;
|
||||
if (!p->conn || !p->conn->links_up || !p->conn->rtt_last) {
|
||||
continue;
|
||||
}
|
||||
uint16_t total = (uint16_t)((uint32_t)p->conn->rtt_last + p->cumulative_rtt);
|
||||
if (total < best) best = total;
|
||||
}
|
||||
return best;
|
||||
struct TOPO_NODEPATH* p = topo_node_best_path(nq);
|
||||
if (!p || !p->conn->rtt_last) return UINT16_MAX;
|
||||
uint32_t total = (uint32_t)p->conn->rtt_last + p->cumulative_rtt;
|
||||
return total > UINT16_MAX ? UINT16_MAX : (uint16_t)total;
|
||||
}
|
||||
|
||||
// ===== dump / format =====
|
||||
|
||||
Reference in new issue
Block a user