mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed build errors.
This commit is contained in:
parent
790867d984
commit
25563ac070
|
@ -84,7 +84,7 @@ int main(int argc, char *argv[])
|
||||||
/* Initialize networking -
|
/* Initialize networking -
|
||||||
Bind to ip 0.0.0.0:PORT */
|
Bind to ip 0.0.0.0:PORT */
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
||||||
manage_keys(dht);
|
manage_keys(dht);
|
||||||
printf("Public key: ");
|
printf("Public key: ");
|
||||||
|
@ -111,7 +111,7 @@ int main(int argc, char *argv[])
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
printf("Trying to bootstrap into the network...\n");
|
printf("Trying to bootstrap into the network...\n");
|
||||||
IP_Port bootstrap_info;
|
IP_Port bootstrap_info;
|
||||||
bootstrap_info.ip.i = inet_addr(argv[1]);
|
bootstrap_info.ip.uint32 = inet_addr(argv[1]);
|
||||||
bootstrap_info.port = htons(atoi(argv[2]));
|
bootstrap_info.port = htons(atoi(argv[2]));
|
||||||
uint8_t *bootstrap_key = hex_string_to_bin(argv[3]);
|
uint8_t *bootstrap_key = hex_string_to_bin(argv[3]);
|
||||||
DHT_bootstrap(dht, bootstrap_info, bootstrap_key);
|
DHT_bootstrap(dht, bootstrap_info, bootstrap_key);
|
||||||
|
|
|
@ -301,7 +301,7 @@ struct server_conf_s configure_server(char *cfg_file)
|
||||||
printf("bootstrap_server %d: Invalid port.\n", i);
|
printf("bootstrap_server %d: Invalid port.\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
server_conf.info[i].conn.ip.i = resolve_addr(strcpy(tmp_ip, bs_ip));
|
server_conf.info[i].conn.ip.uint32 = resolve_addr(strcpy(tmp_ip, bs_ip));
|
||||||
server_conf.info[i].conn.port = htons(bs_port);
|
server_conf.info[i].conn.port = htons(bs_port);
|
||||||
b16_to_key(strcpy(tmp_pk, bs_pk), bs_pk_p);
|
b16_to_key(strcpy(tmp_pk, bs_pk), bs_pk_p);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ int main(int argc, char *argv[])
|
||||||
/* Initialize networking
|
/* Initialize networking
|
||||||
bind to ip 0.0.0.0:PORT */
|
bind to ip 0.0.0.0:PORT */
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, server_conf.port)));
|
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, server_conf.port)));
|
||||||
/* Read the config file */
|
/* Read the config file */
|
||||||
printf("PID file: %s\n", server_conf.pid_file);
|
printf("PID file: %s\n", server_conf.pid_file);
|
||||||
|
|
|
@ -62,11 +62,11 @@ void print_clientlist(DHT *dht)
|
||||||
}
|
}
|
||||||
|
|
||||||
p_ip = dht->close_clientlist[i].ip_port;
|
p_ip = dht->close_clientlist[i].ip_port;
|
||||||
printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
|
printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], ntohs(p_ip.port));
|
||||||
printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp);
|
printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp);
|
||||||
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged);
|
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged);
|
||||||
p_ip = dht->close_clientlist[i].ret_ip_port;
|
p_ip = dht->close_clientlist[i].ret_ip_port;
|
||||||
printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
|
printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], ntohs(p_ip.port));
|
||||||
printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp);
|
printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ void print_friendlist(DHT *dht)
|
||||||
}
|
}
|
||||||
|
|
||||||
p_ip = DHT_getfriendip(dht, dht->friends_list[k].client_id);
|
p_ip = DHT_getfriendip(dht, dht->friends_list[k].client_id);
|
||||||
printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
|
printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], ntohs(p_ip.port));
|
||||||
|
|
||||||
printf("\nCLIENTS IN LIST:\n\n");
|
printf("\nCLIENTS IN LIST:\n\n");
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ void print_friendlist(DHT *dht)
|
||||||
}
|
}
|
||||||
|
|
||||||
p_ip = dht->friends_list[k].client_list[i].ip_port;
|
p_ip = dht->friends_list[k].client_list[i].ip_port;
|
||||||
printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
|
printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], ntohs(p_ip.port));
|
||||||
printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp);
|
printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp);
|
||||||
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged);
|
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged);
|
||||||
p_ip = dht->friends_list[k].client_list[i].ret_ip_port;
|
p_ip = dht->friends_list[k].client_list[i].ret_ip_port;
|
||||||
printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port));
|
printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], ntohs(p_ip.port));
|
||||||
printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp);
|
printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||||
/* initialize networking */
|
/* initialize networking */
|
||||||
/* bind to ip 0.0.0.0:PORT */
|
/* bind to ip 0.0.0.0:PORT */
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
|
|
||||||
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ int main(int argc, char *argv[])
|
||||||
* bootstrap_ip_port.ip.c[1] = 0;
|
* bootstrap_ip_port.ip.c[1] = 0;
|
||||||
* bootstrap_ip_port.ip.c[2] = 0;
|
* bootstrap_ip_port.ip.c[2] = 0;
|
||||||
* bootstrap_ip_port.ip.c[3] = 1; */
|
* bootstrap_ip_port.ip.c[3] = 1; */
|
||||||
bootstrap_ip_port.ip.i = inet_addr(argv[1]);
|
bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]);
|
||||||
DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -62,7 +62,7 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
|
||||||
|
|
||||||
void printip(IP_Port ip_port)
|
void printip(IP_Port ip_port)
|
||||||
{
|
{
|
||||||
printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.c[0], ip_port.ip.c[1], ip_port.ip.c[2], ip_port.ip.c[3],
|
printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.uint8[0], ip_port.ip.uint8[1], ip_port.ip.uint8[2], ip_port.ip.uint8[3],
|
||||||
ntohs(ip_port.port));
|
ntohs(ip_port.port));
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -165,11 +165,11 @@ int main(int argc, char *argv[])
|
||||||
/* initialize networking */
|
/* initialize networking */
|
||||||
/* bind to ip 0.0.0.0:PORT */
|
/* bind to ip 0.0.0.0:PORT */
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
|
Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
|
||||||
perror("Initialization");
|
perror("Initialization");
|
||||||
IP_Port serverip;
|
IP_Port serverip;
|
||||||
serverip.ip.i = inet_addr(argv[1]);
|
serverip.ip.uint32 = inet_addr(argv[1]);
|
||||||
serverip.port = htons(atoi(argv[2]));
|
serverip.port = htons(atoi(argv[2]));
|
||||||
printip(serverip);
|
printip(serverip);
|
||||||
int connection = new_connection(ludp, serverip);
|
int connection = new_connection(ludp, serverip);
|
||||||
|
|
|
@ -160,7 +160,7 @@ int main(int argc, char *argv[])
|
||||||
//initialize networking
|
//initialize networking
|
||||||
//bind to ip 0.0.0.0:PORT
|
//bind to ip 0.0.0.0:PORT
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
|
Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
|
||||||
perror("Initialization");
|
perror("Initialization");
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
IP_Port bootstrap_ip_port;
|
IP_Port bootstrap_ip_port;
|
||||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||||
bootstrap_ip_port.ip.i = inet_addr(argv[1]);
|
bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]);
|
||||||
DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
||||||
} else {
|
} else {
|
||||||
FILE *file = fopen(argv[1], "rb");
|
FILE *file = fopen(argv[1], "rb");
|
||||||
|
|
|
@ -88,7 +88,7 @@ static int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2)
|
||||||
|
|
||||||
static int ipport_equal(IP_Port a, IP_Port b)
|
static int ipport_equal(IP_Port a, IP_Port b)
|
||||||
{
|
{
|
||||||
return (a.ip.i == b.ip.i) && (a.port == b.port);
|
return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int id_equal(uint8_t *a, uint8_t *b)
|
static int id_equal(uint8_t *a, uint8_t *b)
|
||||||
|
@ -122,7 +122,7 @@ static int client_in_list(Client_data *list, uint32_t length, uint8_t *client_id
|
||||||
if (id_equal(list[i].client_id, client_id)) {
|
if (id_equal(list[i].client_id, client_id)) {
|
||||||
/* Refresh the client timestamp. */
|
/* Refresh the client timestamp. */
|
||||||
list[i].timestamp = temp_time;
|
list[i].timestamp = temp_time;
|
||||||
list[i].ip_port.ip.i = ip_port.ip.i;
|
list[i].ip_port.ip.uint32 = ip_port.ip.uint32;
|
||||||
list[i].ip_port.port = ip_port.port;
|
list[i].ip_port.port = ip_port.port;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ static int replace_bad( Client_data *list,
|
||||||
memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
|
memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||||
list[i].ip_port = ip_port;
|
list[i].ip_port = ip_port;
|
||||||
list[i].timestamp = temp_time;
|
list[i].timestamp = temp_time;
|
||||||
list[i].ret_ip_port.ip.i = 0;
|
list[i].ret_ip_port.ip.uint32 = 0;
|
||||||
list[i].ret_ip_port.port = 0;
|
list[i].ret_ip_port.port = 0;
|
||||||
list[i].ret_timestamp = 0;
|
list[i].ret_timestamp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -320,7 +320,7 @@ static int replace_good( Client_data *list,
|
||||||
memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
|
memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||||
list[i].ip_port = ip_port;
|
list[i].ip_port = ip_port;
|
||||||
list[i].timestamp = temp_time;
|
list[i].timestamp = temp_time;
|
||||||
list[i].ret_ip_port.ip.i = 0;
|
list[i].ret_ip_port.ip.uint32 = 0;
|
||||||
list[i].ret_ip_port.port = 0;
|
list[i].ret_ip_port.port = 0;
|
||||||
list[i].ret_timestamp = 0;
|
list[i].ret_timestamp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -418,13 +418,13 @@ static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id)
|
||||||
if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) {
|
if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) {
|
||||||
pinging = 0;
|
pinging = 0;
|
||||||
|
|
||||||
if (ip_port.ip.i != 0 && ipport_equal(dht->send_nodes[i].ip_port, ip_port))
|
if (ip_port.ip.uint32 != 0 && ipport_equal(dht->send_nodes[i].ip_port, ip_port))
|
||||||
++pinging;
|
++pinging;
|
||||||
|
|
||||||
if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id)
|
if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id)
|
||||||
++pinging;
|
++pinging;
|
||||||
|
|
||||||
if (pinging == (ping_id != 0) + (ip_port.ip.i != 0))
|
if (pinging == (ping_id != 0) + (ip_port.ip.uint32 != 0))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -690,7 +690,7 @@ IP_Port DHT_getfriendip(DHT *dht, uint8_t *client_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
empty.ip.i = 1;
|
empty.ip.uint32 = 1;
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,7 +814,7 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
|
||||||
client = &friend->client_list[i];
|
client = &friend->client_list[i];
|
||||||
|
|
||||||
/* If ip is not zero and node is good */
|
/* If ip is not zero and node is good */
|
||||||
if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
||||||
|
|
||||||
if (id_equal(client->client_id, friend->client_id))
|
if (id_equal(client->client_id, friend->client_id))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -856,7 +856,7 @@ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t lengt
|
||||||
client = &friend->client_list[i];
|
client = &friend->client_list[i];
|
||||||
|
|
||||||
/* If ip is not zero and node is good */
|
/* If ip is not zero and node is good */
|
||||||
if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
||||||
if (sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length) == length)
|
if (sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length) == length)
|
||||||
++sent;
|
++sent;
|
||||||
}
|
}
|
||||||
|
@ -887,7 +887,7 @@ static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint
|
||||||
client = &friend->client_list[i];
|
client = &friend->client_list[i];
|
||||||
|
|
||||||
/* If ip is not zero and node is good. */
|
/* If ip is not zero and node is good. */
|
||||||
if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
||||||
ip_list[n] = client->ip_port;
|
ip_list[n] = client->ip_port;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
@ -998,7 +998,7 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
for (j = 0; j < len; ++j) {
|
for (j = 0; j < len; ++j) {
|
||||||
if (ip_portlist[i].ip.i == ip_portlist[j].ip.i)
|
if (ip_portlist[i].ip.uint32 == ip_portlist[j].ip.uint32)
|
||||||
++numbers[i];
|
++numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,7 +1020,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t
|
||||||
uint16_t num = 0;
|
uint16_t num = 0;
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (ip_portlist[i].ip.i == ip.i) {
|
if (ip_portlist[i].ip.uint32 == ip.uint32) {
|
||||||
portlist[num] = ntohs(ip_portlist[i].port);
|
portlist[num] = ntohs(ip_portlist[i].port);
|
||||||
++num;
|
++num;
|
||||||
}
|
}
|
||||||
|
@ -1071,7 +1071,7 @@ static void do_NAT(DHT *dht)
|
||||||
|
|
||||||
IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2);
|
IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2);
|
||||||
|
|
||||||
if (ip.i == 0)
|
if (ip.uint32 == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint16_t port_list[MAX_FRIEND_CLIENTS];
|
uint16_t port_list[MAX_FRIEND_CLIENTS];
|
||||||
|
@ -1099,15 +1099,15 @@ static void do_NAT(DHT *dht)
|
||||||
*/
|
*/
|
||||||
int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
|
int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
|
||||||
{
|
{
|
||||||
if (ip_port.ip.i == 0)
|
if (ip_port.ip.uint32 == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_TOPING; ++i) {
|
for (i = 0; i < MAX_TOPING; ++i) {
|
||||||
if (dht->toping[i].ip_port.ip.i == 0) {
|
if (dht->toping[i].ip_port.ip.uint32 == 0) {
|
||||||
memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
|
memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||||
dht->toping[i].ip_port.ip.i = ip_port.ip.i;
|
dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32;
|
||||||
dht->toping[i].ip_port.port = ip_port.port;
|
dht->toping[i].ip_port.port = ip_port.port;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1116,7 @@ int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
|
||||||
for (i = 0; i < MAX_TOPING; ++i) {
|
for (i = 0; i < MAX_TOPING; ++i) {
|
||||||
if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) {
|
if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) {
|
||||||
memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
|
memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||||
dht->toping[i].ip_port.ip.i = ip_port.ip.i;
|
dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32;
|
||||||
dht->toping[i].ip_port.port = ip_port.port;
|
dht->toping[i].ip_port.port = ip_port.port;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1139,11 +1139,11 @@ static void do_toping(DHT *dht)
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_TOPING; ++i) {
|
for (i = 0; i < MAX_TOPING; ++i) {
|
||||||
if (dht->toping[i].ip_port.ip.i == 0)
|
if (dht->toping[i].ip_port.ip.uint32 == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id);
|
send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id);
|
||||||
dht->toping[i].ip_port.ip.i = 0;
|
dht->toping[i].ip_port.ip.uint32 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,11 +89,10 @@ static IP broadcast_ip(void)
|
||||||
{
|
{
|
||||||
IP ip;
|
IP ip;
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
ip.i = get_broadcast();
|
ip.uint32 = get_broadcast();
|
||||||
|
|
||||||
if (ip.i == 0)
|
if (ip.uint32 == 0)
|
||||||
/* Error occured, but try anyway? */
|
ip.uint32 = ~0; /* Error occured, but try anyway? */
|
||||||
ip.i = ~0;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
ip.i = ~0;
|
ip.i = ~0;
|
||||||
|
@ -106,19 +105,19 @@ static IP broadcast_ip(void)
|
||||||
*/
|
*/
|
||||||
static int LAN_ip(IP ip)
|
static int LAN_ip(IP ip)
|
||||||
{
|
{
|
||||||
if (ip.c[0] == 127) /* Loopback. */
|
if (ip.uint8[0] == 127) /* Loopback. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ip.c[0] == 10) /* 10.0.0.0 to 10.255.255.255 range. */
|
if (ip.uint8[0] == 10) /* 10.0.0.0 to 10.255.255.255 range. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ip.c[0] == 172 && ip.c[1] >= 16 && ip.c[1] <= 31) /* 172.16.0.0 to 172.31.255.255 range. */
|
if (ip.uint8[0] == 172 && ip.uint8[1] >= 16 && ip.uint8[1] <= 31) /* 172.16.0.0 to 172.31.255.255 range. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ip.c[0] == 192 && ip.c[1] == 168) /* 192.168.0.0 to 192.168.255.255 range. */
|
if (ip.uint8[0] == 192 && ip.uint8[1] == 168) /* 192.168.0.0 to 192.168.255.255 range. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ip.c[0] == 169 && ip.c[1] == 254 && ip.c[2] != 0 && ip.c[2] != 255)/* 169.254.1.0 to 169.254.254.255 range. */
|
if (ip.uint8[0] == 169 && ip.uint8[1] == 254 && ip.uint8[2] != 0 && ip.uint8[2] != 255)/* 169.254.1.0 to 169.254.254.255 range. */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -41,7 +41,7 @@ int getconnection_id(Lossless_UDP *ludp, IP_Port ip_port)
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < ludp->connections_length; ++i) {
|
for (i = 0; i < ludp->connections_length; ++i) {
|
||||||
if (ludp->connections[i].ip_port.ip.i == ip_port.ip.i &&
|
if (ludp->connections[i].ip_port.ip.uint32 == ip_port.ip.uint32 &&
|
||||||
ludp->connections[i].ip_port.port == ip_port.port &&
|
ludp->connections[i].ip_port.port == ip_port.port &&
|
||||||
ludp->connections[i].status > 0)
|
ludp->connections[i].status > 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
|
@ -643,7 +643,7 @@ Messenger *initMessenger(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
IP ip;
|
IP ip;
|
||||||
ip.i = 0;
|
ip.uint32 = 0;
|
||||||
m->net = new_networking(ip, PORT);
|
m->net = new_networking(ip, PORT);
|
||||||
|
|
||||||
if (m->net == NULL) {
|
if (m->net == NULL) {
|
||||||
|
@ -731,7 +731,7 @@ void doFriends(Messenger *m)
|
||||||
|
|
||||||
switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) {
|
switch (is_cryptoconnected(m->net_crypto, m->friendlist[i].crypt_connection_id)) {
|
||||||
case 0:
|
case 0:
|
||||||
if (friendip.ip.i > 1)
|
if (friendip.ip.uint32 > 1)
|
||||||
m->friendlist[i].crypt_connection_id = crypto_connect(m->net_crypto, m->friendlist[i].client_id, friendip);
|
m->friendlist[i].crypt_connection_id = crypto_connect(m->net_crypto, m->friendlist[i].client_id, friendip);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,10 +47,10 @@ int send_friendrequest(DHT *dht, uint8_t *public_key, uint32_t nospam_num, uint8
|
||||||
|
|
||||||
IP_Port ip_port = DHT_getfriendip(dht, public_key);
|
IP_Port ip_port = DHT_getfriendip(dht, public_key);
|
||||||
|
|
||||||
if (ip_port.ip.i == 1)
|
if (ip_port.ip.uint32 == 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (ip_port.ip.i != 0) {
|
if (ip_port.ip.uint32 != 0) {
|
||||||
if (sendpacket(dht->c->lossless_udp->net->sock, ip_port, packet, len) != -1)
|
if (sendpacket(dht->c->lossless_udp->net->sock, ip_port, packet, len) != -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
IP_Port c_ip = connection_ip(c->lossless_udp, c->crypto_connections[id].number);
|
IP_Port c_ip = connection_ip(c->lossless_udp, c->crypto_connections[id].number);
|
||||||
|
|
||||||
if (c_ip.ip.i == ip_port.ip.i && c_ip.port == ip_port.port)
|
if (c_ip.ip.uint32 == ip_port.ip.uint32 && c_ip.port == ip_port.port)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ bool is_pinging(void *ping, IP_Port ipp, uint64_t ping_id) // O(n) TODO: Repl
|
||||||
{
|
{
|
||||||
PING *png = ping;
|
PING *png = ping;
|
||||||
|
|
||||||
if (ipp.ip.i == 0 && ping_id == 0)
|
if (ipp.ip.uint32 == 0 && ping_id == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t i, id;
|
size_t i, id;
|
||||||
|
@ -107,7 +107,7 @@ bool is_pinging(void *ping, IP_Port ipp, uint64_t ping_id) // O(n) TODO: Repl
|
||||||
id = (png->pos_pings + i) % PING_NUM_MAX;
|
id = (png->pos_pings + i) % PING_NUM_MAX;
|
||||||
|
|
||||||
/* ping_id = 0 means match any id. */
|
/* ping_id = 0 means match any id. */
|
||||||
if ((ipp_eq(png->pings[id].ipp, ipp) || ipp.ip.i == 0) && (png->pings[id].id == ping_id || ping_id == 0)) {
|
if ((ipp_eq(png->pings[id].ipp, ipp) || ipp.ip.uint32 == 0) && (png->pings[id].id == ping_id || ping_id == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ uint64_t random_64b()
|
||||||
|
|
||||||
bool ipp_eq(IP_Port a, IP_Port b)
|
bool ipp_eq(IP_Port a, IP_Port b)
|
||||||
{
|
{
|
||||||
return (a.ip.i == b.ip.i) && (a.port == b.port);
|
return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool id_eq(uint8_t *dest, uint8_t *src)
|
bool id_eq(uint8_t *dest, uint8_t *src)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user