Refactor Network for new NetworkConfig.

This commit is contained in:
Adam Ierymenko 2016-04-12 12:16:29 -07:00
parent 6f854c8391
commit 51fecc0be9
2 changed files with 13 additions and 11 deletions

View File

@ -354,13 +354,14 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
ec->nwid = _id; ec->nwid = _id;
ec->mac = _mac.toInt(); ec->mac = _mac.toInt();
if (_config) if (_config)
Utils::scopy(ec->name,sizeof(ec->name),_config.name().c_str()); Utils::scopy(ec->name,sizeof(ec->name),_config.name());
else ec->name[0] = (char)0; else ec->name[0] = (char)0;
ec->status = _status(); ec->status = _status();
ec->type = (_config) ? (_config.isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE; ec->type = (_config) ? (_config.isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE;
ec->mtu = ZT_IF_MTU; ec->mtu = ZT_IF_MTU;
ec->dhcp = 0; ec->dhcp = 0;
ec->bridge = (_config) ? (_config.allowPassiveBridging() || (std::find(_config.activeBridges().begin(),_config.activeBridges().end(),RR->identity.address()) != _config.activeBridges().end())) ? 1 : 0) : 0; std::vector<Address> ab(_config.activeBridges());
ec->bridge = ((_config.allowPassiveBridging())||(std::find(ab.begin(),ab.end(),RR->identity.address()) != ab.end())) ? 1 : 0;
ec->broadcastEnabled = (_config) ? (_config.enableBroadcast() ? 1 : 0) : 0; ec->broadcastEnabled = (_config) ? (_config.enableBroadcast() ? 1 : 0) : 0;
ec->portError = _portError; ec->portError = _portError;
ec->enabled = (_enabled) ? 1 : 0; ec->enabled = (_enabled) ? 1 : 0;
@ -372,13 +373,14 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi(); ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi();
} }
if (_config) { std::vector<InetAddress> sips(_config.staticIps());
ec->assignedAddressCount = (unsigned int)_config.staticIps().size(); ec->assignedAddressCount = 0;
for(unsigned long i=0;i<ZT_MAX_ZT_ASSIGNED_ADDRESSES;++i) { for(unsigned long i=0;i<ZT_MAX_ZT_ASSIGNED_ADDRESSES;++i) {
if (i < _config.staticIps().size()) if (i < sips.size()) {
memcpy(&(ec->assignedAddresses[i]),&(_config.staticIps()[i]),sizeof(struct sockaddr_storage)); memcpy(&(ec->assignedAddresses[i]),&(sips[i]),sizeof(struct sockaddr_storage));
} ++ec->assignedAddressCount;
} else ec->assignedAddressCount = 0; } else memset(&(ec->assignedAddresses[i]),0,sizeof(struct sockaddr_storage));
}
} }
bool Network::_isAllowed(const SharedPtr<Peer> &peer) const bool Network::_isAllowed(const SharedPtr<Peer> &peer) const

View File

@ -230,7 +230,7 @@ public:
* *
* @return Network configuration (may be a null config if we don't have one yet) * @return Network configuration (may be a null config if we don't have one yet)
*/ */
inline const NetworkConfig &config() const { return _config }; inline const NetworkConfig &config() const { return _config; }
/** /**
* @return A thread-safe copy of our NetworkConfig instead of a const reference * @return A thread-safe copy of our NetworkConfig instead of a const reference
@ -238,7 +238,7 @@ public:
inline NetworkConfig configCopy() const inline NetworkConfig configCopy() const
{ {
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
return config; return _config;
} }
/** /**