|
|
|
|
@ -1166,9 +1166,11 @@ static void tcp_link_reconnect_cb(void *arg) {
|
|
|
|
|
if (link->tcp_reconnect_delay_ms == 0) link->tcp_reconnect_delay_ms = 1000; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] TCP link %d reconnect attempt (delay=%ums)", link->etcp->log_name, link->local_link_id, link->tcp_reconnect_delay_ms); |
|
|
|
|
uint16_t port = ntohs(((struct sockaddr_in *)&link->remote_addr)->sin_port); |
|
|
|
|
struct stcp_link_config tcp_cfg = {.ua = link->etcp->instance->ua, .my_keys = &link->etcp->instance->my_keys, .inst = link->etcp->instance, .peer_pubkey = link->etcp->crypto_ctx.peer_public_key, .peer_pubkey_mode = 0, .remote_addr = &link->remote_addr, .remote_port = port, .got_initial_pkt = link->etcp->got_initial_pkt, .session_id = link->etcp->session_id}; |
|
|
|
|
struct stcp_link_config tcp_cfg = {.ua = link->etcp->instance->ua, .my_keys = &link->etcp->instance->my_keys, .inst = link->etcp->instance, .peer_pubkey = link->etcp->crypto_ctx.peer_public_key, |
|
|
|
|
.peer_pubkey_mode = 0, .remote_addr = &link->remote_addr, .remote_port = port, .got_initial_pkt = link->etcp->got_initial_pkt, .session_id = link->etcp->session_id}; |
|
|
|
|
struct stcp_link *sl = stcp_link_connect(&tcp_cfg); |
|
|
|
|
if (!sl) { link->tcp_reconnect_delay_ms *= 2; if (link->tcp_reconnect_delay_ms > 30000) link->tcp_reconnect_delay_ms = 30000; link->tcp_reconnect_timer = uasync_set_timeout(link->etcp->instance->ua, (int)(link->tcp_reconnect_delay_ms * 10), link, tcp_link_reconnect_cb, "tcp_rct"); return; } |
|
|
|
|
if (!sl) { link->tcp_reconnect_delay_ms *= 2; if (link->tcp_reconnect_delay_ms > 30000) link->tcp_reconnect_delay_ms = 30000; |
|
|
|
|
link->tcp_reconnect_timer = uasync_set_timeout(link->etcp->instance->ua, (int)(link->tcp_reconnect_delay_ms * 10), link, tcp_link_reconnect_cb, "tcp_rct"); return; } |
|
|
|
|
link->tcp_link = sl; stcp_link_set_etcp_conn(sl, link->etcp); stcp_link_set_etcp_link(sl, link); |
|
|
|
|
stcp_link_set_on_close(sl, tcp_link_close_cb, link); |
|
|
|
|
} |
|
|
|
|
@ -1176,7 +1178,14 @@ static void tcp_link_reconnect_cb(void *arg) {
|
|
|
|
|
void etcp_tcp_link_start_connect(struct ETCP_LINK *link, struct sockaddr_storage *addr, uint16_t port) { |
|
|
|
|
if (!link || !link->etcp || !addr) return; |
|
|
|
|
memcpy(&link->remote_addr, addr, sizeof(*addr)); |
|
|
|
|
struct stcp_link_config tcp_cfg = {.ua = link->etcp->instance->ua, .my_keys = &link->etcp->instance->my_keys, .inst = link->etcp->instance, .peer_pubkey = link->etcp->crypto_ctx.peer_public_key, .peer_pubkey_mode = 0, .remote_addr = addr, .remote_port = port, .got_initial_pkt = link->etcp->got_initial_pkt, .session_id = link->etcp->session_id}; |
|
|
|
|
struct stcp_link_config tcp_cfg = { |
|
|
|
|
.ua = link->etcp->instance->ua, |
|
|
|
|
.my_keys = &link->etcp->instance->my_keys, |
|
|
|
|
.inst = link->etcp->instance, |
|
|
|
|
.peer_pubkey = link->etcp->crypto_ctx.peer_public_key, |
|
|
|
|
.peer_pubkey_mode = 0, .remote_addr = &link->remote_addr, .remote_port = port, |
|
|
|
|
.got_initial_pkt = link->etcp->got_initial_pkt, |
|
|
|
|
.session_id = link->etcp->session_id}; |
|
|
|
|
struct stcp_link *sl = stcp_link_connect(&tcp_cfg); |
|
|
|
|
if (!sl) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_tcp_link_start_connect: stcp_link_connect failed"); return; } |
|
|
|
|
link->tcp_link = sl; stcp_link_set_etcp_conn(sl, link->etcp); stcp_link_set_etcp_link(sl, link); |
|
|
|
|
@ -1199,10 +1208,18 @@ static void tcp_link_close_cb(struct stcp_link *sl, int err, void *arg) {
|
|
|
|
|
struct ETCP_LINK *link = (struct ETCP_LINK *)arg; |
|
|
|
|
if (!link || !link->etcp) return; |
|
|
|
|
if (link->etcp->state == 2) return; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] TCP link %d down err=%d, scheduling reconnect", link->etcp->log_name, link->local_link_id, err); |
|
|
|
|
stcp_link_close(sl); |
|
|
|
|
link->tcp_link = NULL; |
|
|
|
|
|
|
|
|
|
if (link->is_server) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] TCP server link %d down err=%d, closing", link->etcp->log_name, link->local_link_id, err); |
|
|
|
|
etcp_on_link_down(link->etcp, link); |
|
|
|
|
etcp_link_close(link); |
|
|
|
|
} else { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[%s] TCP link %d down err=%d, scheduling reconnect", link->etcp->log_name, link->local_link_id, err); |
|
|
|
|
etcp_on_link_down(link->etcp, link); |
|
|
|
|
etcp_tcp_link_start_reconnect(link); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int etcp_tcp_send(struct ETCP_DGRAM* dgram) { |
|
|
|
|
|