|
|
|
|
@ -100,6 +100,7 @@ static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) {
|
|
|
|
|
dgram->data[offset++] = link->local_link_id; |
|
|
|
|
dgram->data[offset++] = link->conn ? link->conn->sock_id : 0; |
|
|
|
|
dgram->data[offset++] = link->conn ? link->conn->only_local : 0; |
|
|
|
|
dgram->data[offset++] = link->conn ? link->conn->type : CFG_SERVER_TYPE_UNKNOWN; |
|
|
|
|
|
|
|
|
|
// padding
|
|
|
|
|
int s = rand() % (link->handshake_maxsize - link->handshake_minsize) + link->handshake_minsize; |
|
|
|
|
@ -1214,6 +1215,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
|
|
|
|
uint8_t link_id; |
|
|
|
|
uint8_t remote_socket_id; |
|
|
|
|
uint8_t only_local; |
|
|
|
|
uint8_t type; |
|
|
|
|
uint8_t pubkey[SC_PUBKEY_SIZE]; |
|
|
|
|
} *ack_hdr=(void*)&pkt->data[0]; |
|
|
|
|
uint64_t peer_id = be64toh(*(uint64_t*)ack_hdr->id); |
|
|
|
|
@ -1358,6 +1360,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
|
|
|
|
link->remote_link_id = ack_hdr->link_id; |
|
|
|
|
link->remote_socket_id = ack_hdr->remote_socket_id; |
|
|
|
|
link->remote_only_local = ack_hdr->only_local; |
|
|
|
|
link->remote_type = ack_hdr->type; |
|
|
|
|
|
|
|
|
|
// For CHANNEL_INIT (0x04): if link already initialized - no reset, otherwise reset
|
|
|
|
|
// For INIT_REQUEST (0x02): always reset
|
|
|
|
|
@ -1385,6 +1388,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
|
|
|
|
link->remote_link_id = ack_hdr->link_id; |
|
|
|
|
link->remote_socket_id = ack_hdr->remote_socket_id; |
|
|
|
|
link->remote_only_local = ack_hdr->only_local; |
|
|
|
|
link->remote_type = ack_hdr->type; |
|
|
|
|
|
|
|
|
|
// For new links: check session_id to avoid false reinit
|
|
|
|
|
if (conn->session_id != session_id) { |
|
|
|
|
@ -1410,6 +1414,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
|
|
|
|
uint8_t link_id; |
|
|
|
|
uint8_t remote_socket_id; |
|
|
|
|
uint8_t only_local; |
|
|
|
|
uint8_t type; |
|
|
|
|
uint8_t peer_ipv4[4]; |
|
|
|
|
uint8_t peer_port[2]; |
|
|
|
|
} *ack_repl_hdr=(void*)&pkt->data[0]; |
|
|
|
|
@ -1431,6 +1436,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
|
|
|
|
ack_repl_hdr->link_id = link->local_link_id; |
|
|
|
|
ack_repl_hdr->remote_socket_id = ack_hdr->remote_socket_id; |
|
|
|
|
ack_repl_hdr->only_local = e_sock->only_local; |
|
|
|
|
ack_repl_hdr->type = e_sock->type; |
|
|
|
|
// Add client's IP:port (so client behind NAT can know its external address)
|
|
|
|
|
if (addr.ss_family == AF_INET) { |
|
|
|
|
struct sockaddr_in *sin = (struct sockaddr_in*)&addr; |
|
|
|
|
@ -1537,9 +1543,10 @@ process_decrypted:
|
|
|
|
|
link->remote_link_id = pkt->data[offset++]; |
|
|
|
|
link->remote_socket_id = pkt->data[offset++]; |
|
|
|
|
link->remote_only_local = pkt->data[offset++]; |
|
|
|
|
link->remote_type = pkt->data[offset++]; |
|
|
|
|
|
|
|
|
|
// Parse NAT IP:port from response (new format includes 4+2 bytes)
|
|
|
|
|
if (pkt_len >= 23) { |
|
|
|
|
if (pkt_len >= 24) { |
|
|
|
|
uint32_t new_nat_ip; |
|
|
|
|
memcpy(&new_nat_ip, &pkt->data[offset], 4); |
|
|
|
|
offset += 4; |
|
|
|
|
|