X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsptps_speed.c;h=cc05b8656352e8bcc0000c9abfc29c597e959533;hb=28b7a53b693f6b4e70218a926e68a36ece54cda1;hp=953d7f5ec8e260b4f4276351402a66579bed7649;hpb=f0e7e6b03e34e69cac5b01a2d943ad3b9b59d36c;p=tinc diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 953d7f5e..cc05b865 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -1,6 +1,6 @@ /* sptps_speed.c -- SPTPS benchmark - Copyright (C) 2013 Guus Sliepen , + Copyright (C) 2013-2022 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ */ #include "system.h" +#include "utils.h" #include @@ -25,31 +26,59 @@ #include "ecdh.h" #include "ecdsa.h" #include "ecdsagen.h" +#include "meta.h" +#include "protocol.h" #include "sptps.h" // Symbols necessary to link with logger.o -bool send_request(void *c, const char *msg, ...) { return false; } -struct list_t *connection_list = NULL; -bool send_meta(void *c, const char *msg , int len) { return false; } +bool send_request(struct connection_t *c, const char *msg, ...) { + (void)c; + (void)msg; + return false; +} + +list_t connection_list; + +bool send_meta(struct connection_t *c, const void *msg, size_t len) { + (void)c; + (void)msg; + (void)len; + return false; +} char *logfilename = NULL; +bool do_detach = false; struct timeval now; -static bool send_data(void *handle, uint8_t type, const char *data, size_t len) { +static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; int fd = *(int *)handle; send(fd, data, len, 0); return true; } -static bool receive_record(void *handle, uint8_t type, const char *data, uint16_t len) { +static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) { + (void)handle; + (void)type; + (void)data; + (void)len; return true; } static void receive_data(sptps_t *sptps) { - char buf[4096]; + uint8_t buf[4096], *bufp = buf; int fd = *(int *)sptps->handle; - size_t len = recv(fd, buf, sizeof buf, 0); - if(!sptps_receive_data(sptps, buf, len)) - abort(); + size_t len = recv(fd, buf, sizeof(buf), 0); + + while(len) { + size_t done = sptps_receive_data(sptps, bufp, len); + + if(!done) { + abort(); + } + + bufp += done; + len -= done; + } } struct timespec start; @@ -58,16 +87,19 @@ double elapsed; double rate; unsigned int count; -static void clock_start() { +static void clock_start(void) { count = 0; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); } 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) + elapsed = (double) end.tv_sec + (double) end.tv_nsec * 1e-9 + - (double) start.tv_sec - (double) start.tv_nsec * 1e-9; + + if(elapsed < seconds) { return ++count; + } rate = count / elapsed; return false; @@ -77,20 +109,23 @@ int main(int argc, char *argv[]) { ecdsa_t *key1, *key2; ecdh_t *ecdh1, *ecdh2; sptps_t sptps1, sptps2; - char buf1[4096], buf2[4096], buf3[4096]; + uint8_t buf1[4096], buf2[4096], buf3[4096]; double duration = argc > 1 ? atof(argv[1]) : 10; crypto_init(); - randomize(buf1, sizeof buf1); - randomize(buf2, sizeof buf2); - randomize(buf3, sizeof buf3); + randomize(buf1, sizeof(buf1)); + randomize(buf2, sizeof(buf2)); + randomize(buf3, sizeof(buf3)); // Key generation fprintf(stderr, "Generating keys for %lg seconds: ", duration); - for(clock_start(); clock_countto(duration);) + + for(clock_start(); clock_countto(duration);) { ecdsa_free(ecdsa_generate()); + } + fprintf(stderr, "%17.2lf op/s\n", rate); key1 = ecdsa_generate(); @@ -99,72 +134,110 @@ int main(int argc, char *argv[]) { // Ed25519 signatures fprintf(stderr, "Ed25519 sign for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) - ecdsa_sign(key1, buf1, 256, buf2); - fprintf(stderr, "%22.2lf op/s\n", rate); + if(!ecdsa_sign(key1, buf1, 256, buf2)) { + return 1; + } + + fprintf(stderr, "%20.2lf op/s\n", rate); fprintf(stderr, "Ed25519 verify for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) - ecdsa_verify(key1, buf1, 256, buf2); - fprintf(stderr, "%20.2lf op/s\n", rate); + if(!ecdsa_verify(key1, buf1, 256, buf2)) { + fprintf(stderr, "Signature verification failed\n"); + return 1; + } + + fprintf(stderr, "%18.2lf op/s\n", rate); ecdh1 = ecdh_generate_public(buf1); fprintf(stderr, "ECDH for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { ecdh2 = ecdh_generate_public(buf2); - ecdh_compute_shared(ecdh2, buf1, buf3); + + if(!ecdh2) { + return 1; + } + + if(!ecdh_compute_shared(ecdh2, buf1, buf3)) { + return 1; + } } + fprintf(stderr, "%28.2lf op/s\n", rate); ecdh_free(ecdh1); // SPTPS authentication phase int fd[2]; + if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", strerror(errno)); + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); return 1; } - struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; + struct pollfd pfd[2] = {{fd[0], POLLIN, 0}, {fd[1], POLLIN, 0}}; 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)) { - if(pfd[0].revents) + if(pfd[0].revents) { receive_data(&sptps1); - if(pfd[1].revents) + } + + if(pfd[1].revents) { receive_data(&sptps2); + } } + sptps_stop(&sptps1); sptps_stop(&sptps2); } + fprintf(stderr, "%10.2lf op/s\n", rate * 2); // SPTPS data 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)) { - if(pfd[0].revents) + if(pfd[0].revents) { receive_data(&sptps1); - if(pfd[1].revents) + } + + if(pfd[1].revents) { receive_data(&sptps2); + } } + fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); + for(clock_start(); clock_countto(duration);) { - if(!sptps_send_record(&sptps1, 0, buf1, 1451)) + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { abort(); + } + receive_data(&sptps2); } + rate *= 2 * 1451 * 8; - if(rate > 1e9) + + if(rate > 1e9) { fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - else if(rate > 1e6) + } else if(rate > 1e6) { fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - else if(rate > 1e3) + } else if(rate > 1e3) { fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); + } + sptps_stop(&sptps1); sptps_stop(&sptps2); @@ -174,48 +247,67 @@ int main(int argc, char *argv[]) { close(fd[1]); if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { - fprintf(stderr, "Could not create a UNIX socket pair: %s\n", strerror(errno)); + fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); 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) + if(pfd[0].revents) { receive_data(&sptps1); - if(pfd[1].revents) + } + + 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) + if(pfd[0].revents) { receive_data(&sptps1); - if(pfd[1].revents) + } + + 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)) + if(!sptps_send_record(&sptps1, 0, buf1, 1451)) { abort(); + } + receive_data(&sptps2); } + rate *= 2 * 1451 * 8; - if(rate > 1e9) + + if(rate > 1e9) { fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); - else if(rate > 1e6) + } else if(rate > 1e6) { fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); - else if(rate > 1e3) + } else if(rate > 1e3) { fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); + } + sptps_stop(&sptps1); sptps_stop(&sptps2);