From 998cc99ad15839b14c59935872b1df5b7c6f8526 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Thu, 14 Dec 2017 16:28:49 -0800 Subject: [PATCH] Updated tests/examples --- src/libzt.cpp | 11 +++++------ test/dummy.cpp | 2 +- test/layer2.cpp | 7 +++---- test/sample.cpp | 37 ------------------------------------- test/selftest.cpp | 6 +++--- 5 files changed, 12 insertions(+), 51 deletions(-) delete mode 100644 test/sample.cpp diff --git a/src/libzt.cpp b/src/libzt.cpp index 2170c97..fa6d95e 100644 --- a/src/libzt.cpp +++ b/src/libzt.cpp @@ -291,7 +291,6 @@ int zts_sethostname(const char *name, size_t len) #endif } -/* struct hostent *zts_gethostbyname(const char *name) { if (zts_ready() == false) { @@ -303,7 +302,7 @@ struct hostent *zts_gethostbyname(const char *name) #endif #if defined(ZT_LWIP_SEQ_SOCKET) // TODO: Test thread safety - + /* char buf[256]; int buflen = 256; int h_err = 0; @@ -319,6 +318,8 @@ struct hostent *zts_gethostbyname(const char *name) return *result; return lwip_gethostbyname(name); + */ + return NULL; #endif #if defined(ZT_PICO_BSD_SOCKET) #endif @@ -326,7 +327,6 @@ struct hostent *zts_gethostbyname(const char *name) #endif return NULL; } -*/ int zts_close(int fd) { @@ -608,7 +608,7 @@ int zts_shutdown(int fd, int how) #endif } -/* + int zts_add_dns_nameserver(struct sockaddr *addr) { DEBUG_EXTRA(); @@ -624,7 +624,7 @@ int zts_add_dns_nameserver(struct sockaddr *addr) static ip4_addr_t ipaddr; ipaddr.addr = in4->sin_addr.s_addr; // TODO: manage DNS server indices - dns_setserver(0, (const ip_addr_t*)&ipaddr); + //dns_setserver(0, (const ip_addr_t*)&ipaddr); return 0; #endif #if defined(ZT_PICO_BSD_SOCKET) @@ -649,7 +649,6 @@ int zts_del_dns_nameserver(struct sockaddr *addr) return -1; #endif } -*/ /* The rationale for the following correctional methods is as follows: diff --git a/test/dummy.cpp b/test/dummy.cpp index 4dbb53f..450da11 100644 --- a/test/dummy.cpp +++ b/test/dummy.cpp @@ -6,7 +6,7 @@ int main() { printf("Starting ZT service"); - zts_startjoin("ztp","17d709436c2c5367"); + zts_startjoin("my_config_path",0x0000000000000000); printf("Dummy. Going into infinite loop. Ping me or something\n"); while(1) { diff --git a/test/layer2.cpp b/test/layer2.cpp index 1450ca6..50b82ce 100644 --- a/test/layer2.cpp +++ b/test/layer2.cpp @@ -44,10 +44,9 @@ int main(int argc , char *argv[]) // initialize library printf("Starting libzt...\n"); - zts_startjoin(argv[1], argv[2]); - char device_id[11]; - zts_get_id(device_id); - fprintf(stderr, "Complete. I am %s\n", device_id); + zts_startjoin(argv[1], strtoull(argv[2], NULL, 16)); + uint64_t device_id = zts_get_node_id(); + fprintf(stderr, "Complete. I am %llx\n", device_id); // create socket int fd; diff --git a/test/sample.cpp b/test/sample.cpp deleted file mode 100644 index 5aebc34..0000000 --- a/test/sample.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include - -#include "libzt.h" - -int main() -{ - char *str = "welcome to the machine"; - char *nwid = "c7cd7c9e1b0f52a2"; // network - char *path = "config_path"; // where this instance's keys and configs are stored - char *ip = "10.8.8.42"; // remote address - int port = 8080; // remote port - - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr(ip); - addr.sin_port = htons(port); - - zts_startjoin(path, nwid); - - int fd, err = 0; - if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) { - printf("error creating socket\n"); - } - if ((err = zts_connect(fd, (const struct sockaddr *)&addr, sizeof(addr))) < 0) { - printf("error connecting to remote host\n"); - } - if ((err = zts_write(fd, str, strlen(str))) < 0) { - printf("error writing to socket\n"); - } - if ((err = zts_close(fd)) < 0) { - printf("error closing socket\n"); - } - zts_stop(); - return 0; -} \ No newline at end of file diff --git a/test/selftest.cpp b/test/selftest.cpp index 4b87d40..d7d4adb 100644 --- a/test/selftest.cpp +++ b/test/selftest.cpp @@ -2694,12 +2694,12 @@ int main(int argc , char *argv[]) DEBUG_ERROR("invalid pathname was given"); exit(-1); } - //uint64_t nwid = strtoull(argv[2],NULL,16); + uint64_t nwid = strtoull(argv[2],NULL,16); uint64_t nodeId = zts_get_node_id(); zts_start(argv[3], true); - //zts_join(nwid); - //sleep(5); + zts_join(nwid); + sleep(2); DEBUG_TEST("generated id: %llx", nodeId); exit(0); }