diff --git a/src/routing_layer/topo_group_connect.c b/src/routing_layer/topo_group_connect.c index 7230a1c0..0373ef41 100644 --- a/src/routing_layer/topo_group_connect.c +++ b/src/routing_layer/topo_group_connect.c @@ -189,13 +189,17 @@ int topo_group_connect_init(struct TOPO_GROUP* group) { return 0; } - gc->phase = TGC_PHASE_ONE; gc->pending = count; + gc->phase = TGC_PHASE_ONE; + int launched = 0; DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: Phase 1 launching %d connects ch=%s grp=%016llx", TGC_ID, count, group->channel_id, (unsigned long long)group->group_id); for (int i = 0; i < count && gc->handle_count < TGC_MAX_HANDLES; i++) { + if (ids[i] == group->instance->node_id) { DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "%s: Phase1 skip self 0x%016llx", TGC_ID, (unsigned long long)ids[i]); continue; } DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "%s: Phase1 connect to 0x%016llx (%d/%d)", TGC_ID, (unsigned long long)ids[i], i + 1, count); node_conn_direct_open(group->instance, ids[i], tgc_callback, gc, &gc->handles[gc->handle_count++], NULL); + launched++; } + gc->pending = launched; tgc_notify_connecting(gc, ids, gc->handle_count); u_free(ids); @@ -259,6 +263,7 @@ int topo_group_connect_active_count(struct TOPO_GROUP* group) { void topo_group_connect_on_up(struct TOPO_GROUP* group, struct ETCP_CONN* conn) { if (!group || group->group_type != TOPO_GROUP_TYPE_CHAT || !group->channel_id[0] || !conn) return; uint64_t peer = conn->peer_node_id; + if (peer == group->instance->node_id) return; struct TOPO_GROUP_CONNECT* gc = group->connect; if (!gc) return; @@ -288,6 +293,7 @@ void topo_group_connect_on_up(struct TOPO_GROUP* group, struct ETCP_CONN* conn) void topo_group_connect_on_down(struct TOPO_GROUP* group, struct ETCP_CONN* conn) { if (!group || group->group_type != TOPO_GROUP_TYPE_CHAT || !group->channel_id[0] || !conn) return; uint64_t peer = conn->peer_node_id; + if (peer == group->instance->node_id) return; struct TOPO_GROUP_CONNECT* gc = group->connect; if (!gc) return; @@ -519,6 +525,7 @@ static void tgc_phase2_try_next(struct TOPO_GROUP_CONNECT* gc) { } if (gc->cursor < gc->candidate_count) { uint64_t nid = gc->candidate_ids[gc->cursor++]; + if (nid == gc->group->instance->node_id) continue; DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: Phase2 trying 0x%016llx (%d/%d) super_round=%d", TGC_ID, (unsigned long long)nid, gc->cursor, gc->candidate_count, gc->tried_super); if (node_conn_direct_open(gc->group->instance, nid, tgc_callback, gc, &gc->cur_handle, NULL) < 0) continue; @@ -553,6 +560,7 @@ static void tgc_phase3_try_next(struct TOPO_GROUP_CONNECT* gc) { } while (gc->cursor < gc->candidate_count) { uint64_t nid = gc->candidate_ids[gc->cursor++]; + if (nid == gc->group->instance->node_id) continue; DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: Phase3 trying 0x%016llx (%d/%d)", TGC_ID, (unsigned long long)nid, gc->cursor, gc->candidate_count); if (node_conn_direct_open(gc->group->instance, nid, tgc_callback, gc, &gc->cur_handle, NULL) < 0) continue; @@ -594,14 +602,18 @@ static void tgc_cycle_restart(struct TOPO_GROUP_CONNECT* gc) { return; } - gc->phase = TGC_PHASE_ONE; gc->pending = count; + gc->phase = TGC_PHASE_ONE; + int launched = 0; DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: cycle_restart Phase 1 launching %d connects ch=%s", TGC_ID, count, gc->group->channel_id); for (int i = 0; i < count && gc->handle_count < TGC_MAX_HANDLES; i++) { + if (ids[i] == gc->group->instance->node_id) { DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "%s: Phase1 skip self 0x%016llx", TGC_ID, (unsigned long long)ids[i]); continue; } DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "%s: Phase1 connect to 0x%016llx (%d/%d)", TGC_ID, (unsigned long long)ids[i], i + 1, count); node_conn_direct_open(gc->group->instance, ids[i], tgc_callback, gc, &gc->handles[gc->handle_count++], NULL); + launched++; } + gc->pending = launched; tgc_notify_connecting(gc, ids, gc->handle_count); u_free(ids);