|
|
|
|
@ -25,7 +25,7 @@ static void etcp_router_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry)
|
|
|
|
|
uint8_t svc_id = entry->dgram[1]; |
|
|
|
|
uint64_t dst_node_id = 0; memcpy(&dst_node_id, entry->dgram + 2, 8); |
|
|
|
|
if (dst_node_id == inst->node_id) { |
|
|
|
|
if (svc_id >= SVC_ROUTE_MAX_BINDINGS || !inst->router_bindings.callbacks[svc_id]) { |
|
|
|
|
if (!inst->router_bindings.callbacks[svc_id]) { |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router: no handler for svc_id=%u dst=%016llx self=%016llx", |
|
|
|
|
svc_id, (unsigned long long)dst_node_id, (unsigned long long)inst->node_id); |
|
|
|
|
queue_entry_free(entry); queue_dgram_free(entry); |
|
|
|
|
@ -80,7 +80,6 @@ void etcp_router_destroy(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
|
|
|
|
|
int etcp_router_bind(struct UTUN_INSTANCE* inst, uint8_t svc_id, etcp_recv_fn callback) { |
|
|
|
|
if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: NULL instance"); return -1; } |
|
|
|
|
if (svc_id >= SVC_ROUTE_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: invalid svc_id %u", svc_id); return -1; } |
|
|
|
|
if (!callback) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: NULL callback for svc_id=%u", svc_id); return -1; } |
|
|
|
|
if (inst->router_bindings.callbacks[svc_id]) DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router_bind: overwriting svc_id=%u", svc_id); |
|
|
|
|
inst->router_bindings.callbacks[svc_id] = callback; |
|
|
|
|
@ -90,7 +89,6 @@ int etcp_router_bind(struct UTUN_INSTANCE* inst, uint8_t svc_id, etcp_recv_fn ca
|
|
|
|
|
|
|
|
|
|
int etcp_router_unbind(struct UTUN_INSTANCE* inst, uint8_t svc_id) { |
|
|
|
|
if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: NULL instance"); return -1; } |
|
|
|
|
if (svc_id >= SVC_ROUTE_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: invalid svc_id %u", svc_id); return -1; } |
|
|
|
|
if (!inst->router_bindings.callbacks[svc_id]) { DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: svc_id=%u not bound", svc_id); return -1; } |
|
|
|
|
inst->router_bindings.callbacks[svc_id] = NULL; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: svc_id=%u", svc_id); |
|
|
|
|
@ -114,7 +112,7 @@ int etcp_route_send(struct UTUN_INSTANCE* inst, uint64_t dst_node_id, struct ll_
|
|
|
|
|
// Loopback — dispatch прямо локально
|
|
|
|
|
if (dst_node_id == inst->node_id) { |
|
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "etcp_route_send: loopback svc_id=%u len=%zu", svc_id, payload_len); |
|
|
|
|
if (svc_id < SVC_ROUTE_MAX_BINDINGS && inst->router_bindings.callbacks[svc_id]) |
|
|
|
|
if (inst->router_bindings.callbacks[svc_id]) |
|
|
|
|
inst->router_bindings.callbacks[svc_id](NULL, entry); |
|
|
|
|
else { queue_entry_free(entry); queue_dgram_free(entry); } |
|
|
|
|
return 0; |
|
|
|
|
|