Node status and network list.

This commit is contained in:
Adam Ierymenko 2015-04-08 18:25:40 -07:00
parent e34bc961db
commit d9e9b60a98
3 changed files with 27 additions and 16 deletions

View file

@ -96,22 +96,17 @@ extern "C" {
/** /**
* Maximum number of multicast group subscriptions per network * Maximum number of multicast group subscriptions per network
*/ */
#define ZT1_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS 8194 #define ZT1_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS 4096
/**
* Feature flag: this is an official ZeroTier, Inc. binary build (built with ZT_OFFICIAL_RELEASE)
*/
#define ZT1_FEATURE_FLAG_OFFICIAL 0x00000001
/** /**
* Feature flag: ZeroTier One was built to be thread-safe -- concurrent processXXX() calls are okay * Feature flag: ZeroTier One was built to be thread-safe -- concurrent processXXX() calls are okay
*/ */
#define ZT1_FEATURE_FLAG_THREAD_SAFE 0x00000002 #define ZT1_FEATURE_FLAG_THREAD_SAFE 0x00000001
/** /**
* Feature flag: FIPS compliant build (not available yet, but reserved for future use if we ever do this) * Feature flag: FIPS compliant build (not available yet, but reserved for future use if we ever do this)
*/ */
#define ZT1_FEATURE_FLAG_FIPS 0x00000004 #define ZT1_FEATURE_FLAG_FIPS 0x00000002
/****************************************************************************/ /****************************************************************************/
/* Structures and other types */ /* Structures and other types */
@ -298,11 +293,6 @@ typedef struct
* True if some kind of connectivity appears available * True if some kind of connectivity appears available
*/ */
int online; int online;
/**
* Current maximum link desperation metric
*/
unsigned int desperation;
} ZT1_NodeStatus; } ZT1_NodeStatus;
/** /**

View file

@ -92,6 +92,8 @@ Node::Node(
throw std::runtime_error("unable to write identity.public"); throw std::runtime_error("unable to write identity.public");
} }
} }
RR->publicIdentityStr = RR->identity.toString(false);
RR->secretIdentityStr = RR->identity.toString(true);
try { try {
RR->prng = new CMWC4096(); RR->prng = new CMWC4096();
@ -291,6 +293,7 @@ ZT1_ResultCode Node::leave(uint64_t nwid)
nw->second->destroy(); nw->second->destroy();
_networks.erase(nw); _networks.erase(nw);
} }
return ZT1_RESULT_OK;
} }
ZT1_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi) ZT1_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
@ -299,6 +302,7 @@ ZT1_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,un
std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid)); std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
if (nw != _networks.end()) if (nw != _networks.end())
nw->second->multicastSubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff))); nw->second->multicastSubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
return ZT1_RESULT_OK;
} }
ZT1_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi) ZT1_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
@ -307,10 +311,15 @@ ZT1_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,
std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid)); std::map< uint64_t,SharedPtr<Network> >::iterator nw(_networks.find(nwid));
if (nw != _networks.end()) if (nw != _networks.end())
nw->second->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff))); nw->second->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
return ZT1_RESULT_OK;
} }
void Node::status(ZT1_NodeStatus *status) void Node::status(ZT1_NodeStatus *status)
{ {
status->address = RR->identity.address().toInt();
status->publicIdentity = RR->publicIdentityStr.c_str();
status->secretIdentity = RR->secretIdentityStr.c_str();
status->online = _online ? 1 : 0;
} }
ZT1_PeerList *Node::peers() ZT1_PeerList *Node::peers()
@ -331,6 +340,19 @@ ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid)
ZT1_VirtualNetworkList *Node::networks() ZT1_VirtualNetworkList *Node::networks()
{ {
Mutex::Lock _l(_networks_m);
char *buf = (char *)::malloc(sizeof(ZT1_VirtualNetworkList) + (sizeof(ZT1_VirtualNetworkConfig) * _networks.size()));
if (!buf)
return (ZT1_VirtualNetworkList *)0;
ZT1_VirtualNetworkList *nl = (ZT1_VirtualNetworkList *)buf;
nl->networks = (ZT1_VirtualNetworkConfig *)(buf + sizeof(ZT1_VirtualNetworkList));
nl->networkCount = 0;
for(std::map< uint64_t,SharedPtr<Network> >::const_iterator n(_networks.begin());n!=_networks.end();++n)
n->second->externalConfig(&(nl->networks[nl->networkCount++]));
return nl;
} }
void Node::freeQueryResult(void *qr) void Node::freeQueryResult(void *qr)
@ -589,9 +611,6 @@ void ZT1_version(int *major,int *minor,int *revision,unsigned long *featureFlags
if (featureFlags) { if (featureFlags) {
*featureFlags = ( *featureFlags = (
ZT1_FEATURE_FLAG_THREAD_SAFE ZT1_FEATURE_FLAG_THREAD_SAFE
#ifdef ZT_OFFICIAL_BUILD
| ZT1_FEATURE_FLAG_OFFICIAL
#endif
); );
} }
} }

View file

@ -69,6 +69,8 @@ public:
// This node's identity // This node's identity
Identity identity; Identity identity;
std::string publicIdentityStr;
std::string secretIdentityStr;
// This is set externally to an instance of this base class if netconf functionality is enabled // This is set externally to an instance of this base class if netconf functionality is enabled
NetworkConfigMaster *netconfMaster; NetworkConfigMaster *netconfMaster;