mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
astyled everything.
This commit is contained in:
parent
64d000cdfa
commit
12d1c5199b
@ -94,6 +94,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ int main(int argc, char *argv[])
|
|||||||
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
||||||
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
|
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
|
||||||
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1],
|
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1],
|
||||||
ipv6enabled, port, bootstrap_key);
|
ipv6enabled, port, bootstrap_key);
|
||||||
free(bootstrap_key);
|
free(bootstrap_key);
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@ -151,6 +152,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
do_DHT(dht);
|
do_DHT(dht);
|
||||||
|
|
||||||
if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) {
|
if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) {
|
||||||
send_LANdiscovery(htons(PORT), dht->c);
|
send_LANdiscovery(htons(PORT), dht->c);
|
||||||
last_LANdiscovery = unix_time();
|
last_LANdiscovery = unix_time();
|
||||||
|
@ -141,6 +141,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -177,6 +178,7 @@ int main(int argc, char *argv[])
|
|||||||
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
||||||
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
|
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
|
||||||
free(binary_string);
|
free(binary_string);
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -155,6 +155,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -184,10 +185,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
IP_Port serverip;
|
IP_Port serverip;
|
||||||
ip_init(&serverip.ip, ipv6enabled);
|
ip_init(&serverip.ip, ipv6enabled);
|
||||||
|
|
||||||
if (!addr_resolve(argv[argvoffset + 1], &serverip.ip, NULL)) {
|
if (!addr_resolve(argv[argvoffset + 1], &serverip.ip, NULL)) {
|
||||||
printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
|
printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverip.port = htons(atoi(argv[argvoffset + 2]));
|
serverip.port = htons(atoi(argv[argvoffset + 2]));
|
||||||
printip(serverip);
|
printip(serverip);
|
||||||
|
|
||||||
|
@ -151,6 +151,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -120,14 +121,16 @@ int main(int argc, char *argv[])
|
|||||||
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
||||||
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
|
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
|
||||||
int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
|
int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
|
||||||
ipv6enabled, port, bootstrap_key);
|
ipv6enabled, port, bootstrap_key);
|
||||||
free(bootstrap_key);
|
free(bootstrap_key);
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FILE *file = fopen(argv[argvoffset + 1], "rb");
|
FILE *file = fopen(argv[argvoffset + 1], "rb");
|
||||||
|
|
||||||
if ( file == NULL ) {
|
if ( file == NULL ) {
|
||||||
printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
|
printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -51,10 +51,12 @@ unsigned char *hex_string_to_bin(char hex_string[])
|
|||||||
int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
|
int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
|
||||||
{
|
{
|
||||||
int argvoffset = 0, argi;
|
int argvoffset = 0, argi;
|
||||||
for(argi = 1; argi < argc; argi++)
|
|
||||||
|
for (argi = 1; argi < argc; argi++)
|
||||||
if (!strncasecmp(argv[argi], "--ipv", 5)) {
|
if (!strncasecmp(argv[argi], "--ipv", 5)) {
|
||||||
if (argv[argi][5] && !argv[argi][6]) {
|
if (argv[argi][5] && !argv[argi][6]) {
|
||||||
char c = argv[argi][5];
|
char c = argv[argi][5];
|
||||||
|
|
||||||
if (c == '4')
|
if (c == '4')
|
||||||
*ipv6enabled = 0;
|
*ipv6enabled = 0;
|
||||||
else if (c == '6')
|
else if (c == '6')
|
||||||
@ -63,8 +65,7 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
|
|||||||
printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
|
printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
|
printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -582,6 +582,7 @@ int main(int argc, char *argv[])
|
|||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0)
|
if (argvoffset < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -641,6 +642,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (on == 0 && tox_isconnected(m)) {
|
if (on == 0 && tox_isconnected(m)) {
|
||||||
new_lines("[i] connected to DHT\n[i] define username with /n");
|
new_lines("[i] connected to DHT\n[i] define username with /n");
|
||||||
|
@ -169,12 +169,12 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key);
|
|||||||
* if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
|
* if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
|
||||||
* if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
|
* if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
|
||||||
* then IPv4 addresses.
|
* then IPv4 addresses.
|
||||||
*
|
*
|
||||||
* returns 1 if the address could be converted into an IP address
|
* returns 1 if the address could be converted into an IP address
|
||||||
* returns 0 otherwise
|
* returns 0 otherwise
|
||||||
*/
|
*/
|
||||||
int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
|
int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
|
||||||
uint16_t port, uint8_t *public_key);
|
uint16_t port, uint8_t *public_key);
|
||||||
|
|
||||||
/* Add nodes to the toping list.
|
/* Add nodes to the toping list.
|
||||||
* All nodes in this list are pinged every TIME_TOPING seconds
|
* All nodes in this list are pinged every TIME_TOPING seconds
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
* return higher than 0 on success.
|
* return higher than 0 on success.
|
||||||
* return 0 on error.
|
* return 0 on error.
|
||||||
*/
|
*/
|
||||||
static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t * data, uint16_t length)
|
static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
/* Not sure how many platforms this will run on,
|
/* Not sure how many platforms this will run on,
|
||||||
* so it's wrapped in __linux for now.
|
* so it's wrapped in __linux for now.
|
||||||
@ -63,16 +63,17 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t * d
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
|
if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Just to clarify where we're getting the values from. */
|
/* Just to clarify where we're getting the values from. */
|
||||||
sock_holder = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
|
sock_holder = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
|
||||||
if (sock_holder != NULL) {
|
|
||||||
IP_Port ip_port = {{{{sock_holder->sin_addr.s_addr}}, port, 0}};
|
if (sock_holder != NULL) {
|
||||||
sendpacket(net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES);
|
IP_Port ip_port = {{{{sock_holder->sin_addr.s_addr}}, port, 0}};
|
||||||
}
|
sendpacket(net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sock);
|
close(sock);
|
||||||
@ -87,6 +88,7 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
|
|||||||
ip_reset(&ip);
|
ip_reset(&ip);
|
||||||
|
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
|
|
||||||
if (family_socket == AF_INET6) {
|
if (family_socket == AF_INET6) {
|
||||||
if (family_broadcast == AF_INET6) {
|
if (family_broadcast == AF_INET6) {
|
||||||
ip.family = AF_INET6;
|
ip.family = AF_INET6;
|
||||||
@ -96,25 +98,26 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
|
|||||||
ip.ip6.s6_addr[ 0] = 0xFF;
|
ip.ip6.s6_addr[ 0] = 0xFF;
|
||||||
ip.ip6.s6_addr[ 1] = 0x02;
|
ip.ip6.s6_addr[ 1] = 0x02;
|
||||||
ip.ip6.s6_addr[15] = 0x01;
|
ip.ip6.s6_addr[15] = 0x01;
|
||||||
}
|
} else if (family_broadcast == AF_INET) {
|
||||||
else if (family_broadcast == AF_INET) {
|
|
||||||
ip.family = AF_INET6;
|
ip.family = AF_INET6;
|
||||||
ip.ip6.s6_addr32[0] = 0;
|
ip.ip6.s6_addr32[0] = 0;
|
||||||
ip.ip6.s6_addr32[1] = 0;
|
ip.ip6.s6_addr32[1] = 0;
|
||||||
ip.ip6.s6_addr32[2] = htonl(0xFFFF);
|
ip.ip6.s6_addr32[2] = htonl(0xFFFF);
|
||||||
ip.ip6.s6_addr32[3] = INADDR_BROADCAST;
|
ip.ip6.s6_addr32[3] = INADDR_BROADCAST;
|
||||||
}
|
}
|
||||||
}
|
} else if (family_socket == AF_INET) {
|
||||||
else if (family_socket == AF_INET) {
|
|
||||||
if (family_broadcast == AF_INET) {
|
if (family_broadcast == AF_INET) {
|
||||||
ip.family = AF_INET;
|
ip.family = AF_INET;
|
||||||
ip.ip4.uint32 = INADDR_BROADCAST;
|
ip.ip4.uint32 = INADDR_BROADCAST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (family_socket == AF_INET)
|
if (family_socket == AF_INET)
|
||||||
if (family_broadcast == AF_INET)
|
if (family_broadcast == AF_INET)
|
||||||
ip.uint32 = INADDR_BROADCAST;
|
ip.uint32 = INADDR_BROADCAST;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
@ -126,11 +129,13 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
|
|||||||
static int LAN_ip(IP ip)
|
static int LAN_ip(IP ip)
|
||||||
{
|
{
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
|
|
||||||
if (ip.family == AF_INET) {
|
if (ip.family == AF_INET) {
|
||||||
IP4 ip4 = ip.ip4;
|
IP4 ip4 = ip.ip4;
|
||||||
#else
|
#else
|
||||||
IP4 ip4 = ip;
|
IP4 ip4 = ip;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Loopback. */
|
/* Loopback. */
|
||||||
if (ip4.uint8[0] == 127)
|
if (ip4.uint8[0] == 127)
|
||||||
return 0;
|
return 0;
|
||||||
@ -151,13 +156,14 @@ static int LAN_ip(IP ip)
|
|||||||
if (ip4.uint8[0] == 169 && ip4.uint8[1] == 254 && ip4.uint8[2] != 0
|
if (ip4.uint8[0] == 169 && ip4.uint8[1] == 254 && ip4.uint8[2] != 0
|
||||||
&& ip4.uint8[2] != 255)
|
&& ip4.uint8[2] != 255)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
}
|
} else if (ip.family == AF_INET6)
|
||||||
else if (ip.family == AF_INET6) {
|
{
|
||||||
/* autogenerated for each interface: FE80::* (up to FEBF::*)
|
/* autogenerated for each interface: FE80::* (up to FEBF::*)
|
||||||
/* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */
|
/* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */
|
||||||
if (((ip.ip6.s6_addr[0] == 0xFF) && (ip.ip6.s6_addr[1] < 3) && (ip.ip6.s6_addr[15] == 1)) ||
|
if (((ip.ip6.s6_addr[0] == 0xFF) && (ip.ip6.s6_addr[1] < 3) && (ip.ip6.s6_addr[15] == 1)) ||
|
||||||
((ip.ip6.s6_addr[0] == 0xFE) && ((ip.ip6.s6_addr[1] & 0xC0) == 0x80)))
|
((ip.ip6.s6_addr[0] == 0xFE) && ((ip.ip6.s6_addr[1] & 0xC0) == 0x80)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* embedded IPv4-in-IPv6 */
|
/* embedded IPv4-in-IPv6 */
|
||||||
@ -168,6 +174,7 @@ static int LAN_ip(IP ip)
|
|||||||
return LAN_ip(ip4);
|
return LAN_ip(ip4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -203,9 +210,11 @@ int send_LANdiscovery(uint16_t port, Net_Crypto *c)
|
|||||||
ip_port.port = port;
|
ip_port.port = port;
|
||||||
|
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
|
|
||||||
/* IPv6 multicast */
|
/* IPv6 multicast */
|
||||||
if (c->lossless_udp->net->family == AF_INET6) {
|
if (c->lossless_udp->net->family == AF_INET6) {
|
||||||
ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);
|
ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);
|
||||||
|
|
||||||
if (ip_isset(&ip_port.ip))
|
if (ip_isset(&ip_port.ip))
|
||||||
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
|
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
|
||||||
res = 1;
|
res = 1;
|
||||||
@ -216,6 +225,7 @@ int send_LANdiscovery(uint16_t port, Net_Crypto *c)
|
|||||||
#else
|
#else
|
||||||
ip_port.ip = broadcast_ip(AF_INET, AF_INET);
|
ip_port.ip = broadcast_ip(AF_INET, AF_INET);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ip_isset(&ip_port.ip))
|
if (ip_isset(&ip_port.ip))
|
||||||
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
|
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
|
||||||
res = 1;
|
res = 1;
|
||||||
|
@ -1225,11 +1225,13 @@ static time_t lastdump = 0;
|
|||||||
static char IDString[CLIENT_ID_SIZE * 2 + 1];
|
static char IDString[CLIENT_ID_SIZE * 2 + 1];
|
||||||
static char *ID2String(uint8_t *client_id)
|
static char *ID2String(uint8_t *client_id)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for(i = 0; i < CLIENT_ID_SIZE; i++)
|
|
||||||
sprintf(&IDString[i], "%02X", client_id[i]);
|
for (i = 0; i < CLIENT_ID_SIZE; i++)
|
||||||
IDString[CLIENT_ID_SIZE * 2] = 0;
|
sprintf(&IDString[i], "%02X", client_id[i]);
|
||||||
return IDString;
|
|
||||||
|
IDString[CLIENT_ID_SIZE * 2] = 0;
|
||||||
|
return IDString;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1246,73 +1248,85 @@ void doMessenger(Messenger *m)
|
|||||||
LANdiscovery(m);
|
LANdiscovery(m);
|
||||||
|
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
|
|
||||||
loglog(" = = = = = = = = \n");
|
|
||||||
|
|
||||||
lastdump = now();
|
if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
|
||||||
uint32_t client, last_pinged;
|
loglog(" = = = = = = = = \n");
|
||||||
for(client = 0; client < LCLIENT_LIST; client++) {
|
|
||||||
Client_data *cptr = &m->dht->close_clientlist[client];
|
|
||||||
if (ip_isset(&cptr->ip_port.ip)) {
|
|
||||||
last_pinged = lastdump - cptr->last_pinged;
|
|
||||||
if (last_pinged > 999)
|
|
||||||
last_pinged = 999;
|
|
||||||
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
|
|
||||||
client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port),
|
|
||||||
last_pinged, ID2String(cptr->client_id));
|
|
||||||
loglog(logbuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loglog(" = = = = = = = = \n");
|
lastdump = now();
|
||||||
|
uint32_t client, last_pinged;
|
||||||
|
|
||||||
uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends);
|
for (client = 0; client < LCLIENT_LIST; client++) {
|
||||||
if (m->numfriends != m->dht->num_friends) {
|
Client_data *cptr = &m->dht->close_clientlist[client];
|
||||||
sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n",
|
|
||||||
m->dht->num_friends, m->numfriends);
|
|
||||||
loglog(logbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t friend, ping_lastrecv;
|
if (ip_isset(&cptr->ip_port.ip)) {
|
||||||
for(friend = 0; friend < num_friends; friend++) {
|
last_pinged = lastdump - cptr->last_pinged;
|
||||||
Friend *msgfptr = &m->friendlist[friend];
|
|
||||||
DHT_Friend *dhtfptr = &m->dht->friends_list[friend];
|
|
||||||
if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) {
|
|
||||||
if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) {
|
|
||||||
sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend,
|
|
||||||
ID2String(msgfptr->client_id));
|
|
||||||
strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id));
|
|
||||||
strcat(logbuffer + strlen(logbuffer), "\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend);
|
|
||||||
|
|
||||||
loglog(logbuffer);
|
if (last_pinged > 999)
|
||||||
}
|
last_pinged = 999;
|
||||||
|
|
||||||
ping_lastrecv = lastdump - msgfptr->ping_lastrecv;
|
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
|
||||||
if (ping_lastrecv > 999)
|
client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port),
|
||||||
ping_lastrecv = 999;
|
last_pinged, ID2String(cptr->client_id));
|
||||||
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n",
|
loglog(logbuffer);
|
||||||
friend, msgfptr->name, msgfptr->crypt_connection_id,
|
}
|
||||||
ping_lastrecv, ID2String(msgfptr->client_id));
|
}
|
||||||
loglog(logbuffer);
|
|
||||||
|
|
||||||
for(client = 0; client < MAX_FRIEND_CLIENTS; client++) {
|
loglog(" = = = = = = = = \n");
|
||||||
Client_data *cptr = &dhtfptr->client_list[client];
|
|
||||||
last_pinged = lastdump - cptr->last_pinged;
|
uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends);
|
||||||
if (last_pinged > 999)
|
|
||||||
last_pinged = 999;
|
if (m->numfriends != m->dht->num_friends) {
|
||||||
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
|
sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n",
|
||||||
friend, client, ip_ntoa(&cptr->ip_port.ip),
|
m->dht->num_friends, m->numfriends);
|
||||||
ntohs(cptr->ip_port.port), last_pinged,
|
loglog(logbuffer);
|
||||||
ID2String(cptr->client_id));
|
}
|
||||||
loglog(logbuffer);
|
|
||||||
}
|
uint32_t friend, ping_lastrecv;
|
||||||
}
|
|
||||||
|
for (friend = 0; friend < num_friends; friend++) {
|
||||||
|
Friend *msgfptr = &m->friendlist[friend];
|
||||||
|
DHT_Friend *dhtfptr = &m->dht->friends_list[friend];
|
||||||
|
|
||||||
|
if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) {
|
||||||
|
if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) {
|
||||||
|
sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend,
|
||||||
|
ID2String(msgfptr->client_id));
|
||||||
|
strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id));
|
||||||
|
strcat(logbuffer + strlen(logbuffer), "\n");
|
||||||
|
} else
|
||||||
|
sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend);
|
||||||
|
|
||||||
|
loglog(logbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ping_lastrecv = lastdump - msgfptr->ping_lastrecv;
|
||||||
|
|
||||||
|
if (ping_lastrecv > 999)
|
||||||
|
ping_lastrecv = 999;
|
||||||
|
|
||||||
|
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n",
|
||||||
|
friend, msgfptr->name, msgfptr->crypt_connection_id,
|
||||||
|
ping_lastrecv, ID2String(msgfptr->client_id));
|
||||||
|
loglog(logbuffer);
|
||||||
|
|
||||||
|
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
|
||||||
|
Client_data *cptr = &dhtfptr->client_list[client];
|
||||||
|
last_pinged = lastdump - cptr->last_pinged;
|
||||||
|
|
||||||
|
if (last_pinged > 999)
|
||||||
|
last_pinged = 999;
|
||||||
|
|
||||||
|
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
|
||||||
|
friend, client, ip_ntoa(&cptr->ip_port.ip),
|
||||||
|
ntohs(cptr->ip_port.port), last_pinged,
|
||||||
|
ID2String(cptr->client_id));
|
||||||
|
loglog(logbuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loglog(" = = = = = = = = \n");
|
||||||
|
}
|
||||||
|
|
||||||
loglog(" = = = = = = = = \n");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1410,6 +1424,7 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
|
|||||||
memcpy(temp, data, size);
|
memcpy(temp, data, size);
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < num; ++i) {
|
for (i = 0; i < num; ++i) {
|
||||||
if (temp[i].status >= 3) {
|
if (temp[i].status >= 3) {
|
||||||
int fnum = m_addfriend_norequest(m, temp[i].client_id);
|
int fnum = m_addfriend_norequest(m, temp[i].client_id);
|
||||||
|
@ -113,7 +113,7 @@ bool is_pinging(void *ping, IP_Port ipp, uint64_t ping_id) // O(n) TODO: Repl
|
|||||||
|
|
||||||
/* ping_id = 0 means match any id. */
|
/* ping_id = 0 means match any id. */
|
||||||
if ((!ip_isset(&ipp.ip) || ipport_equal(&png->pings[id].ipp, &ipp)) &&
|
if ((!ip_isset(&ipp.ip) || ipport_equal(&png->pings[id].ipp, &ipp)) &&
|
||||||
(png->pings[id].id == ping_id || ping_id == 0)) {
|
(png->pings[id].id == ping_id || ping_id == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ void tox_bootstrap_from_ip(void *tox, IP_Port ip_port, uint8_t *public_key)
|
|||||||
DHT_bootstrap(m->dht, ip_port, public_key);
|
DHT_bootstrap(m->dht, ip_port, public_key);
|
||||||
}
|
}
|
||||||
int tox_bootstrap_from_address(void *tox, const char *address,
|
int tox_bootstrap_from_address(void *tox, const char *address,
|
||||||
uint8_t ipv6enabled, uint16_t port, uint8_t *public_key)
|
uint8_t ipv6enabled, uint16_t port, uint8_t *public_key)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return DHT_bootstrap_from_address(m->dht, address, ipv6enabled, port, public_key);
|
return DHT_bootstrap_from_address(m->dht, address, ipv6enabled, port, public_key);
|
||||||
|
@ -409,12 +409,12 @@ void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key);
|
|||||||
* if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
|
* if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
|
||||||
* if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
|
* if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
|
||||||
* then IPv4 addresses.
|
* then IPv4 addresses.
|
||||||
*
|
*
|
||||||
* returns 1 if the address could be converted into an IP address
|
* returns 1 if the address could be converted into an IP address
|
||||||
* returns 0 otherwise
|
* returns 0 otherwise
|
||||||
*/
|
*/
|
||||||
int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled,
|
int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled,
|
||||||
uint16_t port, uint8_t *public_key);
|
uint16_t port, uint8_t *public_key);
|
||||||
|
|
||||||
/* return 0 if we are not connected to the DHT.
|
/* return 0 if we are not connected to the DHT.
|
||||||
* return 1 if we are.
|
* return 1 if we are.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user