Applied styling rules from .clang-format
This commit is contained in:
@@ -5,15 +5,16 @@
|
||||
* local storage. In this mode you are responsible for saving keys.
|
||||
*/
|
||||
|
||||
#include "ZeroTierSockets.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ZeroTierSockets.h"
|
||||
|
||||
struct Node
|
||||
{
|
||||
Node() : online(false), joinedAtLeastOneNetwork(false), id(0) {}
|
||||
struct Node {
|
||||
Node() : online(false), joinedAtLeastOneNetwork(false), id(0)
|
||||
{
|
||||
}
|
||||
bool online;
|
||||
bool joinedAtLeastOneNetwork;
|
||||
uint64_t id;
|
||||
@@ -24,9 +25,9 @@ struct Node
|
||||
to ensure timely receipt of future events. You should not call libzt API functions from
|
||||
this function unless it's something trivial like zts_inet_ntop() or similar that has
|
||||
no state-change implications. */
|
||||
void on_zts_event(void *msgPtr)
|
||||
void on_zts_event(void* msgPtr)
|
||||
{
|
||||
struct zts_callback_msg *msg = (struct zts_callback_msg *)msgPtr;
|
||||
struct zts_callback_msg* msg = (struct zts_callback_msg*)msgPtr;
|
||||
|
||||
if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) {
|
||||
printf("ZTS_EVENT_NODE_ONLINE --- This node's ID is %llx\n", msg->node->address);
|
||||
@@ -34,36 +35,39 @@ void on_zts_event(void *msgPtr)
|
||||
myNode.online = true;
|
||||
}
|
||||
if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) {
|
||||
printf("ZTS_EVENT_NODE_OFFLINE --- Check your physical Internet connection, router, firewall, etc. What ports are you blocking?\n");
|
||||
printf("ZTS_EVENT_NODE_OFFLINE --- Check your physical Internet connection, router, "
|
||||
"firewall, etc. What ports are you blocking?\n");
|
||||
myNode.online = false;
|
||||
}
|
||||
if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP6) {
|
||||
printf("ZTS_EVENT_NETWORK_READY_IP6 --- Network config received. IPv6 traffic can now be sent over network %llx\n",
|
||||
msg->network->nwid);
|
||||
printf(
|
||||
"ZTS_EVENT_NETWORK_READY_IP6 --- Network config received. IPv6 traffic can now be sent "
|
||||
"over network %llx\n",
|
||||
msg->network->nwid);
|
||||
myNode.joinedAtLeastOneNetwork = true;
|
||||
}
|
||||
}
|
||||
|
||||
#define KEY_BUF_LEN 2048
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
printf("\nlibzt example\n");
|
||||
printf("earthtest <config_file_path> <ztServicePort>\n");
|
||||
exit(0);
|
||||
}
|
||||
int ztServicePort = atoi(argv[2]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||
int ztServicePort = atoi(
|
||||
argv[2]); // Port ZT uses to send encrypted UDP packets to peers (try something like 9994)
|
||||
int err = ZTS_ERR_OK;
|
||||
|
||||
|
||||
// BEGIN key handling
|
||||
|
||||
|
||||
// Do not allow ZT to write anything to disk
|
||||
zts_disable_local_storage(1);
|
||||
|
||||
// Buffer used to store identity keypair (if someone can read this, they can impersonate your node!)
|
||||
// Buffer used to store identity keypair (if someone can read this, they can impersonate your
|
||||
// node!)
|
||||
char keypair[KEY_BUF_LEN];
|
||||
memset(keypair, 0, KEY_BUF_LEN);
|
||||
|
||||
@@ -77,15 +81,18 @@ int main(int argc, char **argv)
|
||||
printf("\n\nVerifying ident...\n");
|
||||
if (zts_verify_identity(keypair)) {
|
||||
printf("\tIdentity is valid\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("\tIdentity is invalid\n");
|
||||
}
|
||||
|
||||
printf("\n\nStarting node with generated identity...\n");
|
||||
zts_start_with_identity(keypair, keypair_len, &on_zts_event, ztServicePort);
|
||||
|
||||
|
||||
printf("\n\nWaiting for node to come online...\n");
|
||||
while (!myNode.online) { zts_delay_ms(50); }
|
||||
while (! myNode.online) {
|
||||
zts_delay_ms(50);
|
||||
}
|
||||
|
||||
printf("\n\nAs a test, copy node's identity keypair back into buffer...\n");
|
||||
memset(keypair, 0, KEY_BUF_LEN);
|
||||
@@ -93,23 +100,25 @@ int main(int argc, char **argv)
|
||||
zts_get_node_identity(keypair, &keypair_len);
|
||||
printf("keypair(len=%d) = [%s]\n", keypair_len, keypair);
|
||||
|
||||
|
||||
// END key handling
|
||||
|
||||
|
||||
uint64_t nwid = 0x8056c2e21c000001;
|
||||
|
||||
if((err = zts_join(nwid)) != ZTS_ERR_OK) {
|
||||
if ((err = zts_join(nwid)) != ZTS_ERR_OK) {
|
||||
printf("Unable to join network, error = %d. Exiting.\n", err);
|
||||
exit(1);
|
||||
}
|
||||
printf("Joining network %llx\n", nwid);
|
||||
while (!myNode.joinedAtLeastOneNetwork) { zts_delay_ms(50); }
|
||||
while (! myNode.joinedAtLeastOneNetwork) {
|
||||
zts_delay_ms(50);
|
||||
}
|
||||
|
||||
// Idle and just show callback events, stack statistics, etc
|
||||
|
||||
printf("Node will now idle...\n");
|
||||
while (true) { zts_delay_ms(1000); }
|
||||
while (true) {
|
||||
zts_delay_ms(1000);
|
||||
}
|
||||
|
||||
// Shut down service and stack threads
|
||||
|
||||
|
||||
Reference in New Issue
Block a user