|
|
|
|
@ -171,11 +171,16 @@ static void router_send_resume_cb(void* arg) {
|
|
|
|
|
router_drain_send_q(rconn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void router_enqueue_send(struct ETCP_ROUTER_CONN* rconn, const uint8_t* payload, size_t pl_len) { |
|
|
|
|
static int router_enqueue_send(struct ETCP_ROUTER_CONN* rconn, const uint8_t* payload, size_t pl_len) { |
|
|
|
|
if (queue_entry_count(rconn->send_q) >= ROUTER_MAX_SEND_Q_PACKETS) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCPROUTE, "router_send_q: FULL svc_id=%u count=%d — backpressure", |
|
|
|
|
rconn->svc_id, queue_entry_count(rconn->send_q)); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
struct ll_entry* qe = queue_entry_new(0); |
|
|
|
|
if (!qe) { DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "router_enqueue_send: queue_entry_new failed"); return; } |
|
|
|
|
if (!qe) { DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "router_enqueue_send: queue_entry_new failed"); return -1; } |
|
|
|
|
qe->dgram = u_malloc(pl_len); |
|
|
|
|
if (!qe->dgram) { queue_entry_free(qe); return; } |
|
|
|
|
if (!qe->dgram) { queue_entry_free(qe); return -1; } |
|
|
|
|
qe->len = pl_len; |
|
|
|
|
if (pl_len > 0) memcpy(qe->dgram, payload, pl_len); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCPROUTE, "router_send_q: queued svc_id=%u inflight=%d send_q=%d", |
|
|
|
|
@ -185,6 +190,7 @@ static void router_enqueue_send(struct ETCP_ROUTER_CONN* rconn, const uint8_t* p
|
|
|
|
|
if (!rconn->send_resume_timer) |
|
|
|
|
rconn->send_resume_timer = uasync_set_timeout(rconn->inst->ua, |
|
|
|
|
ROUTER_SEND_RESUME_TB, rconn, router_send_resume_cb, "router_send_resume"); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ====================================================================
|
|
|
|
|
@ -513,9 +519,9 @@ int etcp_route_send(struct UTUN_INSTANCE* inst, uint64_t dst_node_id, struct ll_
|
|
|
|
|
if (!rconn) { queue_dgram_free(entry); queue_entry_free(entry); return -1; } |
|
|
|
|
|
|
|
|
|
if ((int32_t)(rconn->tx_seq - rconn->tx_acked) >= ROUTER_MAX_INFLIGHT) { |
|
|
|
|
router_enqueue_send(rconn, entry->dgram + 1, payload_len); |
|
|
|
|
int eq_ret = router_enqueue_send(rconn, entry->dgram + 1, payload_len); |
|
|
|
|
queue_dgram_free(entry); queue_entry_free(entry); |
|
|
|
|
return 0; |
|
|
|
|
return eq_ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ret = router_send_one(rconn, entry->dgram + 1, payload_len); |
|
|
|
|
@ -585,6 +591,7 @@ struct ETCP_ROUTER_CONN* etcp_router_conn_get(struct UTUN_INSTANCE* inst,
|
|
|
|
|
if (!rconn->recv_q) { DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "router_conn_get: queue_new(recv_q) failed"); queue_entry_free(&rconn->ll); return NULL; } |
|
|
|
|
rconn->send_q = queue_new(inst->ua, 0, 0, 0, "router_send_q"); |
|
|
|
|
if (!rconn->send_q) { DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "router_conn_get: queue_new(send_q) failed"); queue_free(rconn->recv_q); queue_entry_free(&rconn->ll); return NULL; } |
|
|
|
|
queue_set_threshold(rconn->send_q, ROUTER_MAX_SEND_Q_PACKETS / 2, 0); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCPROUTE, "router_conn: new conn remote=%016llx svc_id=%u", |
|
|
|
|
(unsigned long long)remote_node_id, svc_id); |
|
|
|
|
queue_data_put_with_index(inst->router_conns, &rconn->ll); |
|
|
|
|
@ -599,8 +606,7 @@ int etcp_router_conn_send(struct ETCP_ROUTER_CONN* rconn,
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if ((int32_t)(rconn->tx_seq - rconn->tx_acked) >= ROUTER_MAX_INFLIGHT) { |
|
|
|
|
router_enqueue_send(rconn, data, len); |
|
|
|
|
return 0; |
|
|
|
|
return router_enqueue_send(rconn, data, len); |
|
|
|
|
} |
|
|
|
|
return router_send_one(rconn, data, len); |
|
|
|
|
} |
|
|
|
|
|