static int add_tcp_relay(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk) { if (ip_port.ip.family == TCP_INET) { ip_port.ip.family = AF_INET; } else if (ip_port.ip.family == TCP_INET6) { ip_port.ip.family = AF_INET6; } if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) return -1; int tcp_connections_number = create_tcp_connection(tcp_c); if (tcp_connections_number == -1) return -1; TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key, &tcp_c->proxy_info); if (!tcp_con->connection) return -1; tcp_con->status = TCP_CONN_VALID; return tcp_connections_number; }
static int add_tcp_relay_instance(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk) { if (net_family_is_tcp_ipv4(ip_port.ip.family)) { ip_port.ip.family = net_family_ipv4; } else if (net_family_is_tcp_ipv6(ip_port.ip.family)) { ip_port.ip.family = net_family_ipv6; } if (!net_family_is_ipv4(ip_port.ip.family) && !net_family_is_ipv6(ip_port.ip.family)) { return -1; } int tcp_connections_number = create_tcp_connection(tcp_c); if (tcp_connections_number == -1) { return -1; } TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; tcp_con->connection = new_TCP_connection(tcp_c->mono_time, ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info); if (!tcp_con->connection) { return -1; } tcp_con->status = TCP_CONN_VALID; return tcp_connections_number; }