X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsptps_test.c;h=06d8deab97432c09459eece0e46016d58e69fdaf;hb=84570275acd84628586a6ca591a283d074ca10f0;hp=7b33eef1837d733f9b157cd861582137bbedb894;hpb=3d75dbc0880484ff6d2f689a9b981def3cd75b5e;p=meshlink diff --git a/src/sptps_test.c b/src/sptps_test.c index 7b33eef1..06d8deab 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -25,6 +25,7 @@ #include "sptps.h" #include "utils.h" +char *logfilename; ecdsa_t mykey, hiskey; static bool send_data(void *handle, const char *data, size_t len) { @@ -117,11 +118,11 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Keys loaded\n"); sptps_t s; - if(!start_sptps(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record)) + if(!sptps_start(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record)) return 1; while(true) { - char buf[4095]; + char buf[65535] = ""; struct pollfd fds[2]; fds[0].fd = 0; @@ -139,7 +140,12 @@ int main(int argc, char *argv[]) { } if(len == 0) break; - if(!send_record(&s, 0, buf, len)) + if(buf[0] == '^') + sptps_send_record(&s, SPTPS_HANDSHAKE, NULL, 0); + else if(buf[0] == '$') + sptps_force_kex(&s); + else + if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len)) return 1; } @@ -156,10 +162,13 @@ int main(int argc, char *argv[]) { char hex[len * 2 + 1]; bin2hex(buf, hex, len); fprintf(stderr, "Received %zd bytes of data:\n%s\n", len, hex); - if(!receive_data(&s, buf, len)) + if(!sptps_receive_data(&s, buf, len)) return 1; } } + if(!sptps_stop(&s)) + return 1; + return 0; }