Removed reference to DEBUG_* macros in examples and libzt proper

This commit is contained in:
Joseph Henry
2018-07-27 15:52:15 -07:00
parent f835869117
commit e7a37ee391
13 changed files with 144 additions and 307 deletions

View File

@@ -5,7 +5,7 @@
int main()
{
printf("Starting ZT service");
printf("Starting ZT service\n");
zts_startjoin("my_config_path",0x0000000000000000);
printf("Dummy. Going into infinite loop. Ping me or something\n");

View File

@@ -66,29 +66,29 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_connect(sockfd, (const struct sockaddr *)&in4, sizeof(in4))) < 0) {
DEBUG_ERROR("error connecting to remote host (%d)", err);
printf("error connecting to remote host (%d)\n", err);
}
DEBUG_TEST("sending to server...");
printf("sending to server...\n");
w = zts_write(sockfd, msg, strlen(msg));
DEBUG_TEST("reading from server...");
printf("reading from server...\n");
r = zts_read(sockfd, rbuf, strlen(msg));
DEBUG_TEST("Sent : %s", msg);
DEBUG_TEST("Received : %s", rbuf);
printf("Sent : %s\n", msg);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);

View File

@@ -72,19 +72,19 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
int flags = 0;
int len = strlen(msg);
@@ -92,16 +92,16 @@ int main(int argc, char **argv)
while(true) {
sleep(1);
if ((err = zts_sendto(sockfd, msg, len, flags, (const struct sockaddr *)&remote4, sizeof(remote4))) < 0) {
DEBUG_ERROR("error sending message to remote host (%d)", err);
printf("error sending message to remote host (%d)\n", err);
}
DEBUG_TEST("sent=%d", err);
printf("sent=%d\n", err);
}
/*
DEBUG_TEST("reading from server...");
printf("reading from server...\n");
r = zts_read(sockfd, rbuf, strlen(msg));
DEBUG_TEST("Sent : %s", msg);
DEBUG_TEST("Received : %s", rbuf);
printf("Sent : %s\n", msg);
printf("Received : %s\n", rbuf);
*/
err = zts_close(sockfd);

View File

@@ -62,41 +62,41 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
if ((err = zts_listen(sockfd, 100)) < 0) {
DEBUG_ERROR("error placing socket in LISTENING state (%d)", err);
printf("error placing socket in LISTENING state (%d)\n", err);
}
socklen_t client_addrlen = sizeof(sockaddr_in);
if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in4, &client_addrlen)) < 0) {
DEBUG_ERROR("error accepting connection (%d)", err);
printf("error accepting connection (%d)\n", err);
}
socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
zts_getpeername(accfd, (struct sockaddr*)&acc_in4, &peer_addrlen);
DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
printf("accepted connection from %s : %d\n", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
DEBUG_TEST("reading from client...");
printf("reading from client...\n");
r = zts_read(accfd, rbuf, sizeof rbuf);
DEBUG_TEST("sending to client...");
printf("sending to client...\n");
w = zts_write(accfd, rbuf, strlen(rbuf));
DEBUG_TEST("Received : %s", rbuf);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);
err = zts_close(accfd);

View File

@@ -62,18 +62,18 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
/*
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
*/
DEBUG_TEST("reading from client...");
printf("reading from client...\n");
socklen_t addrlen = sizeof(acc_in4);
memset(&acc_in4, 0, sizeof acc_in4);
@@ -91,12 +91,12 @@ int main(int argc, char **argv)
r = zts_recvfrom(accfd, rbuf, sizeof(rbuf), flags, (struct sockaddr *)&acc_in4, &addrlen);
if (r >= 0) {
char *ip = inet_ntoa(acc_in4.sin_addr);
DEBUG_TEST("Received : r=%d, %s -- from: %s : %d", r, rbuf, ip, ntohs(acc_in4.sin_port));
printf("Received : r=%d, %s -- from: %s : %d\n", r, rbuf, ip, ntohs(acc_in4.sin_port));
}
}
/*
DEBUG_TEST("sending to client...");
printf("sending to client...\n");
w = zts_write(accfd, rbuf, strlen(rbuf));
*/

View File

@@ -84,29 +84,29 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = generate_adhoc_nwid_from_port(remote_port);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0) {
DEBUG_ERROR("error connecting to remote host (%d)", err);
printf("error connecting to remote host (%d)\n", err);
}
DEBUG_TEST("sending to server...");
printf("sending to server...\n");
w = zts_write(sockfd, msg, strlen(msg));
DEBUG_TEST("reading from server...");
printf("reading from server...\n");
r = zts_read(sockfd, rbuf, strlen(msg));
DEBUG_TEST("Sent : %s", msg);
DEBUG_TEST("Received : %s", rbuf);
printf("Sent : %s\n", msg);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);

View File

@@ -84,41 +84,41 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
nwid = generate_adhoc_nwid_from_port(bind_port);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
if ((err = zts_listen(sockfd, 100)) < 0) {
DEBUG_ERROR("error placing socket in LISTENING state (%d)", err);
printf("error placing socket in LISTENING state (%d)\n", err);
}
socklen_t client_addrlen = sizeof(sockaddr_in6);
if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0) {
DEBUG_ERROR("error accepting connection (%d)", err);
printf("error accepting connection (%d)\n", err);
}
socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
zts_getpeername(accfd, (struct sockaddr*)&acc_in6, &peer_addrlen);
//DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in6.sin6_addr), ntohs(acc_in6.sin6_port));
//printf("accepted connection from %s : %d", inet_ntoa(acc_in6.sin6_addr), ntohs(acc_in6.sin6_port));
DEBUG_TEST("reading from client...");
printf("reading from client...\n");
r = zts_read(accfd, rbuf, sizeof rbuf);
DEBUG_TEST("sending to client...");
printf("sending to client...\n");
w = zts_write(accfd, rbuf, strlen(rbuf));
DEBUG_TEST("Received : %s", rbuf);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);
err = zts_close(accfd);

View File

@@ -66,29 +66,29 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0) {
DEBUG_ERROR("error connecting to remote host (%d)", err);
printf("error connecting to remote host (%d)\n", err);
}
DEBUG_TEST("sending to server...");
printf("sending to server...\n");
w = zts_write(sockfd, msg, strlen(msg));
DEBUG_TEST("reading from server...");
printf("reading from server...\n");
r = zts_read(sockfd, rbuf, strlen(msg));
DEBUG_TEST("Sent : %s", msg);
DEBUG_TEST("Received : %s", rbuf);
printf("Sent : %s\n", msg);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);

View File

@@ -63,41 +63,41 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
if ((err = zts_listen(sockfd, 100)) < 0) {
DEBUG_ERROR("error placing socket in LISTENING state (%d)", err);
printf("error placing socket in LISTENING state (%d)\n", err);
}
socklen_t client_addrlen = sizeof(sockaddr_in6);
if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0) {
DEBUG_ERROR("error accepting connection (%d)", err);
printf("error accepting connection (%d)\n", err);
}
socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
zts_getpeername(accfd, (struct sockaddr*)&acc_in6, &peer_addrlen);
//DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in6.sin6_addr), ntohs(acc_in6.sin6_port));
DEBUG_TEST("reading from client...");
printf("reading from client...\n");
r = zts_read(accfd, rbuf, sizeof rbuf);
DEBUG_TEST("sending to client...");
printf("sending to client...\n");
w = zts_write(accfd, rbuf, strlen(rbuf));
DEBUG_TEST("Received : %s", rbuf);
printf("Received : %s\n", rbuf);
err = zts_close(sockfd);
err = zts_close(accfd);

View File

@@ -24,25 +24,21 @@
* of your own application.
*/
#if !defined(_MSC_VER)
#include <stdio.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <dlfcn.h>
#include "libzt.h"
#include <dlfcn.h>
// function pointers which will have values assigned once the dynamic library is loaded
@@ -179,31 +175,33 @@ int main(int argc, char **argv)
// --- BEGIN EXAMPLE CODE
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
_zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = _zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = _zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = _zts_connect(sockfd, (const struct sockaddr *)&in4, sizeof(in4))) < 0) {
DEBUG_ERROR("error connecting to remote host (%d)", err);
printf("error connecting to remote host (%d)\n", err);
}
DEBUG_TEST("sending to server...");
printf("sending to server...\n");
w = _zts_write(sockfd, msg, strlen(msg));
DEBUG_TEST("reading from server...");
printf("reading from server...\n");
r = _zts_read(sockfd, rbuf, strlen(msg));
DEBUG_TEST("Sent : %s", msg);
DEBUG_TEST("Received : %s", rbuf);
printf("Sent : %s\n", msg);
printf("Received : %s\n", rbuf);
err = _zts_close(sockfd);
return err;
}
}
#endif // _MSC_VER

View File

@@ -24,25 +24,21 @@
* of your own application.
*/
#if !defined(_MSC_VER)
#include <stdio.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include "libzt.h"
#include <dlfcn.h>
#include "libzt.h"
// function pointers which will have values assigned once the dynamic library is loaded
int (*_zts_set_service_port)(int portno);
@@ -179,44 +175,43 @@ int main(int argc, char **argv)
char *library_path = (char*)"bin/lib/libzt.dylib";
load_library_symbols(library_path);
DEBUG_TEST("Waiting for libzt to come online...\n");
printf("Waiting for libzt to come online...\n");
uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
printf("nwid=%llx\n", (unsigned long long)nwid);
_zts_startjoin(path.c_str(), nwid);
uint64_t nodeId = _zts_get_node_id();
DEBUG_TEST("I am %llx", (unsigned long long)nodeId);
printf("I am %llx\n", (unsigned long long)nodeId);
if ((sockfd = _zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
printf("error creating ZeroTier socket\n");
}
if ((err = _zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
printf("error binding to interface (%d)\n", err);
}
if ((err = _zts_listen(sockfd, 100)) < 0) {
DEBUG_ERROR("error placing socket in LISTENING state (%d)", err);
printf("error placing socket in LISTENING state (%d)\n", err);
}
socklen_t client_addrlen = sizeof(sockaddr_in);
if ((accfd = _zts_accept(sockfd, (struct sockaddr *)&acc_in4, &client_addrlen)) < 0) {
DEBUG_ERROR("error accepting connection (%d)", err);
printf("error accepting connection (%d)\n", err);
}
socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
_zts_getpeername(accfd, (struct sockaddr*)&acc_in4, &peer_addrlen);
DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
DEBUG_INFO("accepted connection from %s : %d\n", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
DEBUG_TEST("reading from client...");
printf("reading from client...\n");
r = _zts_read(accfd, rbuf, sizeof rbuf);
DEBUG_TEST("sending to client...");
printf("sending to client...\n");
w = _zts_write(accfd, rbuf, strlen(rbuf));
DEBUG_TEST("Received : %s", rbuf);
printf("Received : %s\n", rbuf);
err = _zts_close(sockfd);
err = _zts_close(accfd);
return err;
}
}
#endif // _MSC_VER