|
|
|
@ -692,6 +692,12 @@ static void _recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) { |
|
|
|
struct merkle_sync* ms = inst ? inst->msync : NULL; |
|
|
|
struct merkle_sync* ms = inst ? inst->msync : NULL; |
|
|
|
if (!ms || !ms->initialized) { u_free(entry->dgram); queue_entry_free(entry); return; } |
|
|
|
if (!ms || !ms->initialized) { u_free(entry->dgram); queue_entry_free(entry); return; } |
|
|
|
uint64_t peer = conn ? conn->peer_node_id : 0; |
|
|
|
uint64_t peer = conn ? conn->peer_node_id : 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* пир в спячке — не обрабатываем его синхронизацию (server-side throttling) */ |
|
|
|
|
|
|
|
if (conn && conn->peer_sleeping) { |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_MEMBER_SYNC, "%s: recv DROP — peer=0x%016llx sleeping", MS_ID, (unsigned long long)peer); |
|
|
|
|
|
|
|
u_free(entry->dgram); queue_entry_free(entry); return; |
|
|
|
|
|
|
|
} |
|
|
|
const uint8_t* d = entry->dgram; |
|
|
|
const uint8_t* d = entry->dgram; |
|
|
|
size_t dlen = entry->len; |
|
|
|
size_t dlen = entry->len; |
|
|
|
|
|
|
|
|
|
|
|
@ -882,6 +888,15 @@ int merkle_sync_start(struct UTUN_INSTANCE* inst, uint64_t peer, |
|
|
|
if (!inst || !ns || !ms || !ms->initialized) return -1; |
|
|
|
if (!inst || !ns || !ms || !ms->initialized) return -1; |
|
|
|
_ensure_table(ms); |
|
|
|
_ensure_table(ms); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* пир в спячке — не инициируем синхронизацию (server-side throttling) */ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct ETCP_CONN* pc = ms_find_conn_for_node(inst, peer); |
|
|
|
|
|
|
|
if (pc && pc->peer_sleeping) { |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_MEMBER_SYNC, "%s: start SKIP — peer=0x%016llx sleeping", MS_ID, (unsigned long long)peer); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct ms_session* s = _session_find(ms, peer, ns); |
|
|
|
struct ms_session* s = _session_find(ms, peer, ns); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEMBER_SYNC, "%s: start peer=%016llx ns=%s new=%d", MS_ID, (unsigned long long)peer, ns, s ? 0 : 1); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEMBER_SYNC, "%s: start peer=%016llx ns=%s new=%d", MS_ID, (unsigned long long)peer, ns, s ? 0 : 1); |
|
|
|
if (!s) { |
|
|
|
if (!s) { |
|
|
|
@ -939,3 +954,22 @@ void merkle_sync_cancel_ns(struct UTUN_INSTANCE* inst, const char* ns) { |
|
|
|
} |
|
|
|
} |
|
|
|
if (removed) DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "%s: cancel_ns ns=%s removed=%d", MS_ID, ns, removed); |
|
|
|
if (removed) DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "%s: cancel_ns ns=%s removed=%d", MS_ID, ns, removed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void merkle_sync_cancel_peer(struct UTUN_INSTANCE* inst, uint64_t peer) { |
|
|
|
|
|
|
|
struct merkle_sync* ms = inst ? inst->msync : NULL; |
|
|
|
|
|
|
|
if (!ms) return; |
|
|
|
|
|
|
|
struct ms_session** p = &ms->sessions; |
|
|
|
|
|
|
|
int removed = 0; |
|
|
|
|
|
|
|
while (*p) { |
|
|
|
|
|
|
|
struct ms_session* s = *p; |
|
|
|
|
|
|
|
if (s->peer == peer) { |
|
|
|
|
|
|
|
*p = s->next; |
|
|
|
|
|
|
|
ms_session_outq_free(s); |
|
|
|
|
|
|
|
u_free(s); |
|
|
|
|
|
|
|
removed++; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p = &(*p)->next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (removed) DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "%s: cancel_peer peer=%016llx removed=%d", MS_ID, (unsigned long long)peer, removed); |
|
|
|
|
|
|
|
} |
|
|
|
|