From e731fc1a3ae5295be843ad84d3769c5c28839782 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 26 Apr 2016 08:40:26 -0700 Subject: [PATCH] Replace two bools in NetworkConfig with a flags field. --- node/NetworkConfig.cpp | 12 ++++++------ node/NetworkConfig.hpp | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/node/NetworkConfig.cpp b/node/NetworkConfig.cpp index 5ca432bad..391d83cae 100644 --- a/node/NetworkConfig.cpp +++ b/node/NetworkConfig.cpp @@ -52,9 +52,8 @@ NetworkConfig NetworkConfig::createTestNetworkConfig(const Address &self) nc._revision = 1; nc._issuedTo = self; nc._multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT; - nc._allowPassiveBridging = false; + nc._flags = ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST; nc._type = ZT_NETWORK_TYPE_PUBLIC; - nc._enableBroadcast = true; nc._rules[nc._ruleCount].ruleNo = 1; nc._rules[nc._ruleCount].matches = (uint8_t)ZT_NETWORK_RULE_MATCHES_ALL; @@ -82,11 +81,11 @@ NetworkConfig NetworkConfig::createTestNetworkConfig(const Address &self) void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen) { - Dictionary d(ds,dslen); - static const std::string zero("0"); static const std::string one("1"); + Dictionary d(ds,dslen); + memset(this,0,sizeof(NetworkConfig)); // NOTE: d.get(name) throws if not found, d.get(name,default) returns default @@ -102,8 +101,9 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen) _multicastLimit = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,zero).c_str()); if (_multicastLimit == 0) _multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT; - _allowPassiveBridging = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0); - _enableBroadcast = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0); + _flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING : 0); + _flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST : 0); + _type = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC; std::string nametmp(d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME,"")); diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 4c8a0857a..3d1aa13c0 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -46,6 +46,16 @@ */ #define ZT_NETWORKCONFIG_V2_MARKER_BYTE 0x00 +/** + * Flag: allow passive bridging (experimental) + */ +#define ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING 0x0001 + +/** + * Flag: enable broadcast + */ +#define ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST 0x0002 + namespace ZeroTier { #ifdef ZT_SUPPORT_OLD_STYLE_NETCONF @@ -189,12 +199,12 @@ public: /** * @return True if passive bridging is allowed (experimental) */ - inline bool allowPassiveBridging() const throw() { return _allowPassiveBridging; } + inline bool allowPassiveBridging() const throw() { return ((_flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0); } /** * @return True if broadcast (ff:ff:ff:ff:ff:ff) address should work on this network */ - inline bool enableBroadcast() const throw() { return _enableBroadcast; } + inline bool enableBroadcast() const throw() { return ((_flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); } /** * @return Type of network (currently public or private) @@ -294,7 +304,7 @@ public: */ inline bool permitsBridging(const Address &fromPeer) const { - if (_allowPassiveBridging) + if ((_flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0) return true; for(unsigned int i=0;i<_activeBridgeCount;++i) { if (_activeBridges[i] == fromPeer) @@ -317,8 +327,7 @@ protected: // protected so that a subclass can fill this out in network controll uint64_t _revision; Address _issuedTo; unsigned int _multicastLimit; - bool _allowPassiveBridging; - bool _enableBroadcast; + unsigned int _flags; ZT_VirtualNetworkType _type; char _name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];