summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorJoseph Henry <josephjah@gmail.com>2017-05-04 15:26:44 -0700
committerJoseph Henry <josephjah@gmail.com>2017-05-04 15:26:44 -0700
commit1f26cb98de307cd7838fa14c61bcf958a5a7bb1c (patch)
tree59fca5d55c5cd37cd67cc4647848da0c929a171b /service
parentceeb8ee0bcd591d79dc61a684ede2c9cae91323c (diff)
downloadinfinitytier-1f26cb98de307cd7838fa14c61bcf958a5a7bb1c.tar.gz
infinitytier-1f26cb98de307cd7838fa14c61bcf958a5a7bb1c.zip
updated OneService convenience functions for SDK
Diffstat (limited to 'service')
-rw-r--r--service/OneService.cpp73
-rw-r--r--service/OneService.hpp44
2 files changed, 111 insertions, 6 deletions
diff --git a/service/OneService.cpp b/service/OneService.cpp
index 9f9cec0a..9bfb310b 100644
--- a/service/OneService.cpp
+++ b/service/OneService.cpp
@@ -104,11 +104,12 @@ namespace ZeroTier { typedef TestEthernetTap EthernetTap; }
#else
-#ifdef ZT_SERVICE_NETCON
-
-#include "../netcon/NetconEthernetTap.hpp"
-namespace ZeroTier { typedef NetconEthernetTap EthernetTap; }
-
+#ifdef ZT_SDK
+ #include "../controller/EmbeddedNetworkController.hpp"
+ #include "../node/Node.hpp"
+ // Use the virtual netcon endpoint instead of a tun/tap port driver
+ #include "../src/SocketTap.hpp"
+ namespace ZeroTier { typedef SocketTap EthernetTap; }
#else
#ifdef __APPLE__
@@ -989,6 +990,62 @@ public:
else return std::string();
}
+#ifdef ZT_SDK
+ virtual void leave(const char *hp)
+ {
+ _node->leave(Utils::hexStrToU64(hp),NULL,NULL);
+ }
+
+ virtual void join(const char *hp)
+ {
+ _node->join(Utils::hexStrToU64(hp),NULL,NULL);
+ }
+
+ virtual std::string givenHomePath()
+ {
+ return _homePath;
+ }
+
+ virtual EthernetTap * getTap(uint64_t nwid)
+ {
+ Mutex::Lock _l(_nets_m);
+ std::map<uint64_t,NetworkState>::const_iterator n(_nets.find(nwid));
+ if (n == _nets.end())
+ return NULL;
+ return n->second.tap;
+ }
+
+ virtual EthernetTap *getTap(InetAddress &addr)
+ {
+ Mutex::Lock _l(_nets_m);
+ std::map<uint64_t,NetworkState>::iterator it;
+ for(it = _nets.begin(); it != _nets.end(); it++) {
+ if(it->second.tap) {
+ for(int j=0; j<it->second.tap->_ips.size(); j++) {
+ if(it->second.tap->_ips[j].isEqualPrefix(addr) || it->second.tap->_ips[j].ipsEqual(addr)) {
+ return it->second.tap;
+ }
+ }
+ }
+ }
+ return NULL;
+ }
+
+ virtual Node * getNode()
+ {
+ return _node;
+ }
+
+ virtual void removeNets()
+ {
+ Mutex::Lock _l(_nets_m);
+ std::map<uint64_t,NetworkState>::iterator i;
+ for(i = _nets.begin(); i != _nets.end(); i++) {
+ delete i->second.tap;
+ }
+ }
+#endif // ZT_SDK
+
virtual void terminate()
{
_run_m.lock();
@@ -1158,9 +1215,11 @@ public:
#else
settings["portMappingEnabled"] = false; // not supported in build
#endif
+#ifndef ZT_SDK
+
settings["softwareUpdate"] = OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT);
settings["softwareUpdateChannel"] = OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL);
-
+#endif
const World planet(_node->planet());
res["planetWorldId"] = planet.id();
res["planetWorldTimestamp"] = planet.timestamp();
@@ -1508,6 +1567,7 @@ public:
_primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff;
_portMappingEnabled = OSUtils::jsonBool(settings["portMappingEnabled"],true);
+#ifndef ZT_SDK
const std::string up(OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT));
const bool udist = OSUtils::jsonBool(settings["softwareUpdateDist"],false);
if (((up == "apply")||(up == "download"))||(udist)) {
@@ -1521,6 +1581,7 @@ public:
_updater = (SoftwareUpdater *)0;
_updateAutoApply = false;
}
+#endif
json &ignoreIfs = settings["interfacePrefixBlacklist"];
if (ignoreIfs.is_array()) {
diff --git a/service/OneService.hpp b/service/OneService.hpp
index f52cd40e..b770a3c0 100644
--- a/service/OneService.hpp
+++ b/service/OneService.hpp
@@ -32,6 +32,13 @@
#include "../node/InetAddress.hpp"
+#ifdef ZT_SDK
+ #include "../node/Node.hpp"
+ // Use the virtual netcon endpoint instead of a tun/tap port driver
+ #include "../src/SocketTap.hpp"
+ namespace ZeroTier { typedef SocketTap EthernetTap; }
+#endif
+
namespace ZeroTier {
/**
@@ -139,6 +146,43 @@ public:
*/
virtual std::string portDeviceName(uint64_t nwid) const = 0;
+#ifdef ZT_SDK
+ /**
+ * Leaves a network
+ */
+ virtual void leave(const char *hp) = 0;
+
+ /**
+ * Joins a network
+ */
+ virtual void join(const char *hp) = 0;
+
+ /**
+ * Returns the homePath given by the client application
+ */
+ virtual std::string givenHomePath() = 0;
+
+ /*
+ * Returns a SocketTap that is associated with the given nwid
+ */
+ virtual EthernetTap * getTap(uint64_t nwid) = 0;
+
+ /*
+ * Returns a SocketTap that cant function as a route to the specified host
+ */
+ virtual EthernetTap * getTap(InetAddress &addr) = 0;
+
+ /*
+ * Returns a pointer to the Node
+ */
+ virtual Node * getNode() = 0;
+
+ /*
+ * Delete all SocketTap interfaces
+ */
+ virtual void removeNets() = 0;
+#endif
+
/**
* Terminate background service (can be called from other threads)
*/