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 */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
@ -151,6 +152,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
do_DHT(dht);
|
||||
|
||||
if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) {
|
||||
send_LANdiscovery(htons(PORT), dht->c);
|
||||
last_LANdiscovery = unix_time();
|
||||
|
|
|
@ -141,6 +141,7 @@ int main(int argc, char *argv[])
|
|||
/* let user override default by cmdline */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
@ -177,6 +178,7 @@ int main(int argc, char *argv[])
|
|||
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);
|
||||
free(binary_string);
|
||||
|
||||
if (!res) {
|
||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||
return 1;
|
||||
|
|
|
@ -155,6 +155,7 @@ int main(int argc, char *argv[])
|
|||
/* let user override default by cmdline */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
@ -184,10 +185,12 @@ int main(int argc, char *argv[])
|
|||
|
||||
IP_Port serverip;
|
||||
ip_init(&serverip.ip, ipv6enabled);
|
||||
|
||||
if (!addr_resolve(argv[argvoffset + 1], &serverip.ip, NULL)) {
|
||||
printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
serverip.port = htons(atoi(argv[argvoffset + 2]));
|
||||
printip(serverip);
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ int main(int argc, char *argv[])
|
|||
/* let user override default by cmdline */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ int main(int argc, char *argv[])
|
|||
/* let user override default by cmdline */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
@ -122,12 +123,14 @@ int main(int argc, char *argv[])
|
|||
int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
|
||||
ipv6enabled, port, bootstrap_key);
|
||||
free(bootstrap_key);
|
||||
|
||||
if (!res) {
|
||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
FILE *file = fopen(argv[argvoffset + 1], "rb");
|
||||
|
||||
if ( file == NULL ) {
|
||||
printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 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 argvoffset = 0, argi;
|
||||
|
||||
for (argi = 1; argi < argc; argi++)
|
||||
if (!strncasecmp(argv[argi], "--ipv", 5)) {
|
||||
if (argv[argi][5] && !argv[argi][6]) {
|
||||
char c = argv[argi][5];
|
||||
|
||||
if (c == '4')
|
||||
*ipv6enabled = 0;
|
||||
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]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -582,6 +582,7 @@ int main(int argc, char *argv[])
|
|||
/* let user override default by cmdline */
|
||||
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
|
||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||
|
||||
if (argvoffset < 0)
|
||||
exit(1);
|
||||
|
||||
|
@ -641,6 +642,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
nodelay(stdscr, TRUE);
|
||||
|
||||
while (1) {
|
||||
if (on == 0 && tox_isconnected(m)) {
|
||||
new_lines("[i] connected to DHT\n[i] define username with /n");
|
||||
|
|
|
@ -69,6 +69,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t * d
|
|||
|
||||
/* Just to clarify where we're getting the values from. */
|
||||
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}};
|
||||
sendpacket(net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES);
|
||||
|
@ -87,6 +88,7 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
|
|||
ip_reset(&ip);
|
||||
|
||||
#ifdef TOX_ENABLE_IPV6
|
||||
|
||||
if (family_socket == AF_INET6) {
|
||||
if (family_broadcast == 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[ 1] = 0x02;
|
||||
ip.ip6.s6_addr[15] = 0x01;
|
||||
}
|
||||
else if (family_broadcast == AF_INET) {
|
||||
} else if (family_broadcast == AF_INET) {
|
||||
ip.family = AF_INET6;
|
||||
ip.ip6.s6_addr32[0] = 0;
|
||||
ip.ip6.s6_addr32[1] = 0;
|
||||
ip.ip6.s6_addr32[2] = htonl(0xFFFF);
|
||||
ip.ip6.s6_addr32[3] = INADDR_BROADCAST;
|
||||
}
|
||||
}
|
||||
else if (family_socket == AF_INET) {
|
||||
} else if (family_socket == AF_INET) {
|
||||
if (family_broadcast == AF_INET) {
|
||||
ip.family = AF_INET;
|
||||
ip.ip4.uint32 = INADDR_BROADCAST;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (family_socket == AF_INET)
|
||||
if (family_broadcast == AF_INET)
|
||||
ip.uint32 = INADDR_BROADCAST;
|
||||
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
#ifdef TOX_ENABLE_IPV6
|
||||
|
||||
if (ip.family == AF_INET) {
|
||||
IP4 ip4 = ip.ip4;
|
||||
#else
|
||||
IP4 ip4 = ip;
|
||||
#endif
|
||||
|
||||
/* Loopback. */
|
||||
if (ip4.uint8[0] == 127)
|
||||
return 0;
|
||||
|
@ -151,9 +156,10 @@ static int LAN_ip(IP ip)
|
|||
if (ip4.uint8[0] == 169 && ip4.uint8[1] == 254 && ip4.uint8[2] != 0
|
||||
&& ip4.uint8[2] != 255)
|
||||
return 0;
|
||||
|
||||
#ifdef TOX_ENABLE_IPV6
|
||||
}
|
||||
else if (ip.family == AF_INET6) {
|
||||
} else if (ip.family == AF_INET6)
|
||||
{
|
||||
/* autogenerated for each interface: FE80::* (up to FEBF::*)
|
||||
/* 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)) ||
|
||||
|
@ -168,6 +174,7 @@ static int LAN_ip(IP ip)
|
|||
return LAN_ip(ip4);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
|
@ -203,9 +210,11 @@ int send_LANdiscovery(uint16_t port, Net_Crypto *c)
|
|||
ip_port.port = port;
|
||||
|
||||
#ifdef TOX_ENABLE_IPV6
|
||||
|
||||
/* IPv6 multicast */
|
||||
if (c->lossless_udp->net->family == AF_INET6) {
|
||||
ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);
|
||||
|
||||
if (ip_isset(&ip_port.ip))
|
||||
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
|
||||
res = 1;
|
||||
|
@ -216,6 +225,7 @@ int send_LANdiscovery(uint16_t port, Net_Crypto *c)
|
|||
#else
|
||||
ip_port.ip = broadcast_ip(AF_INET, AF_INET);
|
||||
#endif
|
||||
|
||||
if (ip_isset(&ip_port.ip))
|
||||
if (sendpacket(c->lossless_udp->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
|
||||
res = 1;
|
||||
|
|
|
@ -1226,8 +1226,10 @@ static char IDString[CLIENT_ID_SIZE * 2 + 1];
|
|||
static char *ID2String(uint8_t *client_id)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < CLIENT_ID_SIZE; i++)
|
||||
sprintf(&IDString[i], "%02X", client_id[i]);
|
||||
|
||||
IDString[CLIENT_ID_SIZE * 2] = 0;
|
||||
return IDString;
|
||||
}
|
||||
|
@ -1246,17 +1248,22 @@ void doMessenger(Messenger *m)
|
|||
LANdiscovery(m);
|
||||
|
||||
#ifdef LOGGING
|
||||
|
||||
if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
|
||||
loglog(" = = = = = = = = \n");
|
||||
|
||||
lastdump = now();
|
||||
uint32_t client, last_pinged;
|
||||
|
||||
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));
|
||||
|
@ -1267,6 +1274,7 @@ void doMessenger(Messenger *m)
|
|||
loglog(" = = = = = = = = \n");
|
||||
|
||||
uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends);
|
||||
|
||||
if (m->numfriends != m->dht->num_friends) {
|
||||
sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n",
|
||||
m->dht->num_friends, m->numfriends);
|
||||
|
@ -1274,25 +1282,28 @@ void doMessenger(Messenger *m)
|
|||
}
|
||||
|
||||
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
|
||||
} 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));
|
||||
|
@ -1301,8 +1312,10 @@ void doMessenger(Messenger *m)
|
|||
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,
|
||||
|
@ -1313,6 +1326,7 @@ void doMessenger(Messenger *m)
|
|||
|
||||
loglog(" = = = = = = = = \n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1410,6 +1424,7 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
|
|||
memcpy(temp, data, size);
|
||||
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < num; ++i) {
|
||||
if (temp[i].status >= 3) {
|
||||
int fnum = m_addfriend_norequest(m, temp[i].client_id);
|
||||
|
|
Loading…
Reference in New Issue
Block a user