summaryrefslogtreecommitdiff
path: root/node/Node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/Node.cpp')
-rw-r--r--node/Node.cpp227
1 files changed, 225 insertions, 2 deletions
diff --git a/node/Node.cpp b/node/Node.cpp
index 0808062f..3a73b461 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -25,6 +25,9 @@
* LLC. Start here: http://www.zerotier.com/
*/
+#include "../version.h"
+
+#include "Constants.hpp"
#include "Node.hpp"
#include "RuntimeEnvironment.hpp"
#include "NetworkConfigMaster.hpp"
@@ -46,14 +49,14 @@ Node::Node(
ZT1_DataStorePutFunction *dataStorePutFunction,
ZT1_WirePacketSendFunction *wirePacketSendFunction,
ZT1_VirtualNetworkFrameFunction *virtualNetworkFrameFunction,
- ZT1_VirtualNetworkConfigCallback *networkConfigCallback,
+ ZT1_VirtualNetworkConfigCallback *virtualNetworkConfigCallback,
ZT1_StatusCallback *statusCallback) :
RR(new RuntimeEnvironment(this)),
_dataStoreGetFunction(dataStoreGetFunction),
_dataStorePutFunction(dataStorePutFunction),
_wirePacketSendFunction(wirePacketSendFunction),
_virtualNetworkFrameFunction(virtualNetworkFrameFunction),
- _networkConfigCallback(networkConfigCallback),
+ _virtualNetworkConfigCallback(virtualNetworkConfigCallback),
_statusCallback(statusCallback),
_networks(),
_networks_m(),
@@ -91,12 +94,49 @@ Node::~Node()
delete RR;
}
+ZT1_ResultCode Node::processWirePacket(
+ uint64_t now,
+ const struct sockaddr_storage *remoteAddress,
+ int linkDesperation,
+ const void *packetData,
+ unsigned int packetLength,
+ uint64_t *nextCallDeadline)
+{
+ _now = now;
+}
+
+ZT1_ResultCode Node::processVirtualNetworkFrame(
+ uint64_t now,
+ uint64_t nwid,
+ uint64_t sourceMac,
+ uint64_t destMac,
+ unsigned int etherType,
+ unsigned int vlanId,
+ const void *frameData,
+ unsigned int frameLength,
+ uint64_t *nextCallDeadline)
+{
+ _now = now;
+}
+
+ZT1_Resultcode Node::processNothing(uint64_t now,uint64_t *nextCallDeadline)
+{
+ _now = now;
+}
+
ZT1_ResultCode Node::join(uint64_t nwid)
{
+ Mutex::Lock _l(_networks_m);
+ SharedPtr<Network> &nw = _networks[nwid];
+ if (!nw)
+ nw = new Network();
+ return ZT1_RESULT_OK;
}
ZT1_ResultCode Node::leave(uint64_t nwid)
{
+ Mutex::Lock _l(_networks_m);
+ _networks.erase(nwid);
}
ZT1_ResultCode Node::multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
@@ -135,3 +175,186 @@ void Node::setNetconfMaster(void *networkConfigMasterInstance)
}
} // namespace ZeroTier
+
+extern "C" {
+
+enum ZT1_ResultCode ZT1_Node_new(
+ ZT1_Node **node,
+ ZT1_DataStoreGetFunction *dataStoreGetFunction,
+ ZT1_DataStorePutFunction *dataStorePutFunction,
+ ZT1_WirePacketSendFunction *wirePacketSendFunction,
+ ZT1_VirtualNetworkFrameFunction *virtualNetworkFrameFunction,
+ ZT1_VirtualNetworkConfigCallback *virtualNetworkConfigCallback,
+ ZT1_StatusCallback *statusCallback)
+{
+ *node = (ZT1_Node *)0;
+ try {
+ *node = reinterpret_cast<ZT1_Node *>(new ZeroTier::Node(dataStoreGetFunction,dataStorePutFunction,wirePacketSendFunction,virtualNetworkFrameFunction,virtualNetworkConfigCallback,statusCallback));
+ return ZT1_RESULT_OK;
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch (std::runtime_error &exc) {
+ return ZT1_RESULT_ERROR_DATA_STORE_FAILED;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_processWirePacket(
+ ZT1_Node *node,
+ uint64_t now,
+ const struct sockaddr_storage *remoteAddress,
+ int linkDesperation,
+ const void *packetData,
+ unsigned int packetLength,
+ uint64_t *nextCallDeadline)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,remoteAddress,linkDesperation,packetData,packetLength,nextCallDeadline);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_PACKET_INVALID;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
+ ZT1_Node *node,
+ uint64_t now,
+ uint64_t nwid,
+ uint64_t sourceMac,
+ uint64_t destMac,
+ unsigned int etherType,
+ unsigned int vlanId,
+ const void *frameData,
+ unsigned int frameLength,
+ uint64_t *nextCallDeadline)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(now,nwid,sourceMac,destMac,etherType,vlanId,frameData,frameLength,nextCallDeadline);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_Resultcode ZT1_Node_processNothing(ZT1_Node *node,uint64_t now,uint64_t *nextCallDeadline)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->processNothing(now,nextCallDeadline);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_join(ZT1_Node *node,uint64_t nwid)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_leave(ZT1_Node *node,uint64_t nwid)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(nwid,multicastGroup,multicastAdi);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+enum ZT1_ResultCode ZT1_Node_multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
+ } catch (std::bad_alloc &exc) {
+ return ZT1_RESULT_ERROR_OUT_OF_MEMORY;
+ } catch ( ... ) {
+ return ZT1_RESULT_ERROR_INTERNAL;
+ }
+}
+
+void ZT1_Node_status(ZT1_Node *node,ZT1_NodeStatus *status)
+{
+ try {
+ reinterpret_cast<ZeroTier::Node *>(node)->status(status);
+ } catch ( ... ) {}
+}
+
+ZT1_PeerList *ZT1_Node_peers(ZT1_Node *node)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->peers();
+ } catch ( ... ) {
+ return (ZT1_PeerList *)0;
+ }
+}
+
+ZT1_VirtualNetworkConfig *ZT1_Node_networkConfig(ZT1_Node *node,uint64_t nwid)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
+ } catch ( ... ) {
+ return (ZT1_VirtualNetworkConfig *)0;
+ }
+}
+
+ZT1_VirtualNetworkList *ZT1_Node_listNetworks(ZT1_Node *node)
+{
+ try {
+ return reinterpret_cast<ZeroTier::Node *>(node)->listNetworks();
+ } catch ( ... ) {
+ return (ZT1_VirtualNetworkList *)0;
+ }
+}
+
+void ZT1_Node_freeQueryResult(ZT1_Node *node,void *qr)
+{
+ try {
+ reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
+ } catch ( ... ) {}
+}
+
+void ZT1_Node_setNetconfMaster(ZT1_Node *node,void *networkConfigMasterInstance)
+{
+ try {
+ reinterpret_cast<ZeroTier::Node *>(node)->setNetconfMaster(networkConfigMasterInstance);
+ } catch ( ... ) {}
+}
+
+void ZT1_version(int *major,int *minor,int *revision,unsigned long *featureFlags)
+{
+ if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
+ if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
+ if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
+ if (featureFlags) {
+ *featureFlags =
+ ZT1_FEATURE_FLAG_THREAD_SAFE |
+#ifdef ZT_OFFICIAL_BUILD
+ ZT1_FEATURE_FLAG_OFFICIAL
+#endif
+ ;
+ }
+}
+
+} // extern "C"