/* Main loop. */ void do_net_crypto(Net_Crypto *c) { unix_time_update(); do_lossless_udp(c->lossless_udp); kill_timedout(c); receive_crypto(c); }
/* Main loop. */ void do_net_crypto(Net_Crypto *c) { do_lossless_udp(c->lossless_udp); handle_incomings(c); receive_crypto(c); kill_timedout(c); }
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); if (argc < argvoffset + 4) { printf("Usage: %s [--ipv4|--ipv6] ip port filename\n", argv[0]); exit(0); } uint8_t buffer[512]; int read; FILE *file = fopen(argv[argvoffset + 3], "rb"); if (file == NULL) { printf("Failed to open file \"%s\".\n", argv[argvoffset + 3]); return 1; } /* initialize networking */ /* bind to ip 0.0.0.0:PORT */ IP ip; ip_init(&ip, ipv6enabled); Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); perror("Initialization"); 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); int connection = new_connection(ludp, serverip); uint64_t timer = current_time(); while (1) { /* printconnection(connection); */ networking_poll(ludp->net); do_lossless_udp(ludp); if (is_connected(ludp, connection) == 3) { printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); break; } if (is_connected(ludp, connection) == 0) { printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); return 1; } c_sleep(1); } timer = current_time(); /*read first part of file */ read = fread(buffer, 1, 512, file); while (1) { /* printconnection(connection); */ networking_poll(ludp->net); do_lossless_udp(ludp); if (is_connected(ludp, connection) == 3) { if (write_packet(ludp, connection, buffer, read)) { /* printf("Wrote data.\n"); */ read = fread(buffer, 1, 512, file); } /* printf("%u\n", sendqueue(connection)); */ if (sendqueue(ludp, connection) == 0) { if (read == 0) { printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); break; } } } else { printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); return 0; } /* c_sleep(1); */ } return 0; }
int main(int argc, char *argv[]) { if (argc < 4) { printf("usage: %s ip port filename\n", argv[0]); exit(0); } uint8_t buffer[512]; int read; FILE *file = fopen(argv[3], "rb"); if (file == NULL) return 1; /* initialize networking */ /* bind to ip 0.0.0.0:PORT */ IP ip; ip.uint32 = 0; Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); perror("Initialization"); IP_Port serverip; serverip.ip.uint32 = inet_addr(argv[1]); serverip.port = htons(atoi(argv[2])); printip(serverip); int connection = new_connection(ludp, serverip); uint64_t timer = current_time(); while (1) { /* printconnection(connection); */ networking_poll(ludp->net); do_lossless_udp(ludp); if (is_connected(ludp, connection) == 3) { printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); break; } if (is_connected(ludp, connection) == 0) { printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); return 1; } c_sleep(1); } timer = current_time(); /*read first part of file */ read = fread(buffer, 1, 512, file); while (1) { /* printconnection(connection); */ networking_poll(ludp->net); do_lossless_udp(ludp); if (is_connected(ludp, connection) == 3) { if (write_packet(ludp, connection, buffer, read)) { /* printf("Wrote data.\n"); */ read = fread(buffer, 1, 512, file); } /* printf("%u\n", sendqueue(connection)); */ if (sendqueue(ludp, connection) == 0) { if (read == 0) { printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); break; } } } else { printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); return 0; } /* c_sleep(1); */ } return 0; }