X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsptps_speed.c;h=268e6c9bf0ce388af2cc269b635d6db1f10131fb;hb=0da07280882253b792ddf9c6bd8b6690ba585b7a;hp=99aaef8372cedf8fbe0308889c9bea322f6898bb;hpb=b7b68c3e979994a70f3adb9b40784f65cadf6a75;p=tinc diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 99aaef83..268e6c9b 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -48,7 +48,8 @@ static void receive_data(sptps_t *sptps) { char buf[4096]; int fd = *(int *)sptps->handle; size_t len = recv(fd, buf, sizeof buf, 0); - sptps_receive_data(sptps, buf, len); + if(!sptps_receive_data(sptps, buf, len)) + abort(); } struct timespec start; @@ -62,12 +63,12 @@ static void clock_start() { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); } -static bool clock_countto(int seconds) { +static bool clock_countto(double seconds) { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); elapsed = end.tv_sec + end.tv_nsec * 1e-9 - start.tv_sec - start.tv_nsec * 1e-9; if(elapsed < seconds) return ++count; - + rate = count / elapsed; return false; } @@ -77,41 +78,43 @@ int main(int argc, char *argv[]) { ecdh_t *ecdh1, *ecdh2; sptps_t sptps1, sptps2; char buf1[4096], buf2[4096], buf3[4096]; + double duration = argc > 1 ? atof(argv[1]) : 10; crypto_init(); // Key generation - fprintf(stderr, "Generating keys for 10 seconds: "); - for(clock_start(); clock_countto(10);) - key1 = ecdsa_generate(); - fprintf(stderr, "%13.2lf op/s\n", rate); + fprintf(stderr, "Generating keys for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) + ecdsa_free(ecdsa_generate()); + fprintf(stderr, "%17.2lf op/s\n", rate); + + key1 = ecdsa_generate(); + key2 = ecdsa_generate(); // ECDSA signatures - fprintf(stderr, "ECDSA sign for 10 seconds: "); - for(clock_start(); clock_countto(10);) + fprintf(stderr, "ECDSA sign for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) ecdsa_sign(key1, buf1, 256, buf2); - fprintf(stderr, "%18.2lf op/s\n", rate); - - fprintf(stderr, "ECDSA verify for 10 seconds: "); - for(clock_start(); clock_countto(10);) + fprintf(stderr, "%22.2lf op/s\n", rate); + + fprintf(stderr, "ECDSA verify for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) ecdsa_verify(key1, buf1, 256, buf2); - fprintf(stderr, "%16.2lf op/s\n", rate); + fprintf(stderr, "%20.2lf op/s\n", rate); ecdh1 = ecdh_generate_public(buf1); - fprintf(stderr, "ECDH for 10 seconds: "); - for(clock_start(); clock_countto(10);) { + fprintf(stderr, "ECDH for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { ecdh2 = ecdh_generate_public(buf2); ecdh_compute_shared(ecdh2, buf1, buf3); } - fprintf(stderr, "%24.2lf op/s\n", rate); + fprintf(stderr, "%28.2lf op/s\n", rate); ecdh_free(ecdh1); // SPTPS authentication phase - key2 = ecdsa_generate(); - int fd[2]; if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { fprintf(stderr, "Could not create a UNIX socket pair: %s\n", strerror(errno)); @@ -120,8 +123,8 @@ int main(int argc, char *argv[]) { struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; - fprintf(stderr, "SPTPS authenticate for 10 seconds: "); - for(clock_start(); clock_countto(10);) { + fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); while(poll(pfd, 2, 0)) { @@ -132,8 +135,8 @@ int main(int argc, char *argv[]) { } sptps_stop(&sptps1); sptps_stop(&sptps2); - } - fprintf(stderr, "%10.2lf op/s\n", rate * 2); + } + fprintf(stderr, "%10.2lf op/s\n", rate * 2); // SPTPS data @@ -145,9 +148,61 @@ int main(int argc, char *argv[]) { if(pfd[1].revents) receive_data(&sptps2); } - fprintf(stderr, "SPTPS transmit for 10 seconds: "); - for(clock_start(); clock_countto(10);) { - sptps_send_record(&sptps1, 0, buf1, 1451); + fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) + abort(); + receive_data(&sptps2); + } + rate *= 2 * 1451 * 8; + if(rate > 1e9) + fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); + else if(rate > 1e6) + fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); + else if(rate > 1e3) + fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); + sptps_stop(&sptps1); + sptps_stop(&sptps2); + + // SPTPS datagram authentication phase + + close(fd[0]); + close(fd[1]); + + if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", strerror(errno)); + return 1; + } + + fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { + sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); + sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) + receive_data(&sptps1); + if(pfd[1].revents) + receive_data(&sptps2); + } + sptps_stop(&sptps1); + sptps_stop(&sptps2); + } + fprintf(stderr, "%10.2lf op/s\n", rate * 2); + + // SPTPS datagram data + + sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); + sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); + while(poll(pfd, 2, 0)) { + if(pfd[0].revents) + receive_data(&sptps1); + if(pfd[1].revents) + receive_data(&sptps2); + } + fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) + abort(); receive_data(&sptps2); } rate *= 2 * 1451 * 8;