astyled everything.

This commit is contained in:
irungentoo 2013-09-14 12:42:17 -04:00
parent 64d000cdfa
commit 12d1c5199b
13 changed files with 132 additions and 93 deletions

View File

@ -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);
@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);
@ -122,12 +123,14 @@ int main(int argc, char *argv[])
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;

View File

@ -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;
} }

View File

@ -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");

View File

@ -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.
@ -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. */ /* 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) { if (sock_holder != NULL) {
IP_Port ip_port = {{{{sock_holder->sin_addr.s_addr}}, port, 0}}; IP_Port ip_port = {{{{sock_holder->sin_addr.s_addr}}, port, 0}};
sendpacket(net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES); 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); 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,9 +156,10 @@ 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)) ||
@ -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;

View File

@ -1226,8 +1226,10 @@ 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++)
for (i = 0; i < CLIENT_ID_SIZE; i++)
sprintf(&IDString[i], "%02X", client_id[i]); sprintf(&IDString[i], "%02X", client_id[i]);
IDString[CLIENT_ID_SIZE * 2] = 0; IDString[CLIENT_ID_SIZE * 2] = 0;
return IDString; return IDString;
} }
@ -1246,17 +1248,22 @@ void doMessenger(Messenger *m)
LANdiscovery(m); LANdiscovery(m);
#ifdef LOGGING #ifdef LOGGING
if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
loglog(" = = = = = = = = \n"); loglog(" = = = = = = = = \n");
lastdump = now(); lastdump = now();
uint32_t client, last_pinged; uint32_t client, last_pinged;
for(client = 0; client < LCLIENT_LIST; client++) {
for (client = 0; client < LCLIENT_LIST; client++) {
Client_data *cptr = &m->dht->close_clientlist[client]; Client_data *cptr = &m->dht->close_clientlist[client];
if (ip_isset(&cptr->ip_port.ip)) { if (ip_isset(&cptr->ip_port.ip)) {
last_pinged = lastdump - cptr->last_pinged; last_pinged = lastdump - cptr->last_pinged;
if (last_pinged > 999) if (last_pinged > 999)
last_pinged = 999; last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n", snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port), client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port),
last_pinged, ID2String(cptr->client_id)); last_pinged, ID2String(cptr->client_id));
@ -1267,6 +1274,7 @@ void doMessenger(Messenger *m)
loglog(" = = = = = = = = \n"); loglog(" = = = = = = = = \n");
uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends); uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends);
if (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", sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n",
m->dht->num_friends, m->numfriends); m->dht->num_friends, m->numfriends);
@ -1274,35 +1282,40 @@ void doMessenger(Messenger *m)
} }
uint32_t friend, ping_lastrecv; uint32_t friend, ping_lastrecv;
for(friend = 0; friend < num_friends; friend++) {
for (friend = 0; friend < num_friends; friend++) {
Friend *msgfptr = &m->friendlist[friend]; Friend *msgfptr = &m->friendlist[friend];
DHT_Friend *dhtfptr = &m->dht->friends_list[friend]; DHT_Friend *dhtfptr = &m->dht->friends_list[friend];
if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) { if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) {
if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) { if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) {
sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend, sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend,
ID2String(msgfptr->client_id)); ID2String(msgfptr->client_id));
strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id)); strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id));
strcat(logbuffer + strlen(logbuffer), "\n"); strcat(logbuffer + strlen(logbuffer), "\n");
} } else
else
sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend); sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend);
loglog(logbuffer); loglog(logbuffer);
} }
ping_lastrecv = lastdump - msgfptr->ping_lastrecv; ping_lastrecv = lastdump - msgfptr->ping_lastrecv;
if (ping_lastrecv > 999) if (ping_lastrecv > 999)
ping_lastrecv = 999; ping_lastrecv = 999;
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n", snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n",
friend, msgfptr->name, msgfptr->crypt_connection_id, friend, msgfptr->name, msgfptr->crypt_connection_id,
ping_lastrecv, ID2String(msgfptr->client_id)); ping_lastrecv, ID2String(msgfptr->client_id));
loglog(logbuffer); loglog(logbuffer);
for(client = 0; client < MAX_FRIEND_CLIENTS; client++) { for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
Client_data *cptr = &dhtfptr->client_list[client]; Client_data *cptr = &dhtfptr->client_list[client];
last_pinged = lastdump - cptr->last_pinged; last_pinged = lastdump - cptr->last_pinged;
if (last_pinged > 999) if (last_pinged > 999)
last_pinged = 999; last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n", snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
friend, client, ip_ntoa(&cptr->ip_port.ip), friend, client, ip_ntoa(&cptr->ip_port.ip),
ntohs(cptr->ip_port.port), last_pinged, ntohs(cptr->ip_port.port), last_pinged,
@ -1313,6 +1326,7 @@ void doMessenger(Messenger *m)
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);