mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Some nodeJS work, and apply fix from GitHub issue #166 plus a small optimization to avoid repeated calls to _allMulticastGroups().
This commit is contained in:
parent
d8ad555b9a
commit
5e3c6d9e0d
3 changed files with 50 additions and 20 deletions
|
@ -139,21 +139,6 @@ Network::~Network()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<MulticastGroup> Network::allMulticastGroups() const
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lock);
|
|
||||||
std::vector<MulticastGroup> mgs(_myMulticastGroups);
|
|
||||||
std::vector<MulticastGroup>::iterator oldend(mgs.end());
|
|
||||||
for(std::map< MulticastGroup,uint64_t >::const_iterator i(_multicastGroupsBehindMe.begin());i!=_multicastGroupsBehindMe.end();++i) {
|
|
||||||
if (!std::binary_search(mgs.begin(),oldend,i->first))
|
|
||||||
mgs.push_back(i->first);
|
|
||||||
}
|
|
||||||
if ((_config)&&(_config->enableBroadcast()))
|
|
||||||
mgs.push_back(Network::BROADCAST);
|
|
||||||
std::sort(mgs.begin(),mgs.end());
|
|
||||||
return mgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Network::subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const
|
bool Network::subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
|
@ -510,6 +495,22 @@ bool Network::_isAllowed(const Address &peer) const
|
||||||
return false; // default position on any failure
|
return false; // default position on any failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<MulticastGroup> Network::_allMulticastGroups() const
|
||||||
|
{
|
||||||
|
// Assumes _lock is locked
|
||||||
|
std::vector<MulticastGroup> mgs(_myMulticastGroups);
|
||||||
|
std::vector<MulticastGroup>::iterator oldend(mgs.end());
|
||||||
|
for(std::map< MulticastGroup,uint64_t >::const_iterator i(_multicastGroupsBehindMe.begin());i!=_multicastGroupsBehindMe.end();++i) {
|
||||||
|
if (!std::binary_search(mgs.begin(),oldend,i->first))
|
||||||
|
mgs.push_back(i->first);
|
||||||
|
}
|
||||||
|
if ((_config)&&(_config->enableBroadcast()))
|
||||||
|
mgs.push_back(Network::BROADCAST);
|
||||||
|
std::sort(mgs.begin(),mgs.end());
|
||||||
|
std::unique(mgs.begin(),mgs.end());
|
||||||
|
return mgs;
|
||||||
|
}
|
||||||
|
|
||||||
// Used in Network::_announceMulticastGroups()
|
// Used in Network::_announceMulticastGroups()
|
||||||
class _AnnounceMulticastGroupsToPeersWithActiveDirectPaths
|
class _AnnounceMulticastGroupsToPeersWithActiveDirectPaths
|
||||||
{
|
{
|
||||||
|
@ -518,7 +519,8 @@ public:
|
||||||
RR(renv),
|
RR(renv),
|
||||||
_now(renv->node->now()),
|
_now(renv->node->now()),
|
||||||
_network(nw),
|
_network(nw),
|
||||||
_supernodeAddresses(renv->topology->supernodeAddresses())
|
_supernodeAddresses(renv->topology->supernodeAddresses()),
|
||||||
|
_allMulticastGroups(nw->_allMulticastGroups())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
|
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
|
||||||
|
@ -526,9 +528,8 @@ public:
|
||||||
if ( ( (p->hasActiveDirectPath(_now)) && (_network->_isAllowed(p->address())) ) || (std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),p->address()) != _supernodeAddresses.end()) ) {
|
if ( ( (p->hasActiveDirectPath(_now)) && (_network->_isAllowed(p->address())) ) || (std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),p->address()) != _supernodeAddresses.end()) ) {
|
||||||
Packet outp(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
|
Packet outp(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
|
||||||
|
|
||||||
std::vector<MulticastGroup> mgs(_network->allMulticastGroups());
|
for(std::vector<MulticastGroup>::iterator mg(_allMulticastGroups.begin());mg!=_allMulticastGroups.end();++mg) {
|
||||||
for(std::vector<MulticastGroup>::iterator mg(mgs.begin());mg!=mgs.end();++mg) {
|
if ((outp.size() + 18) >= ZT_UDP_DEFAULT_PAYLOAD_MTU) {
|
||||||
if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) {
|
|
||||||
outp.armor(p->key(),true);
|
outp.armor(p->key(),true);
|
||||||
p->send(RR,outp.data(),outp.size(),_now);
|
p->send(RR,outp.data(),outp.size(),_now);
|
||||||
outp.reset(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
|
outp.reset(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
|
||||||
|
@ -552,6 +553,7 @@ private:
|
||||||
uint64_t _now;
|
uint64_t _now;
|
||||||
Network *_network;
|
Network *_network;
|
||||||
std::vector<Address> _supernodeAddresses;
|
std::vector<Address> _supernodeAddresses;
|
||||||
|
std::vector<MulticastGroup> _allMulticastGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Network::_announceMulticastGroups()
|
void Network::_announceMulticastGroups()
|
||||||
|
|
|
@ -106,7 +106,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return All multicast groups including learned groups that are behind any bridges we're attached to
|
* @return All multicast groups including learned groups that are behind any bridges we're attached to
|
||||||
*/
|
*/
|
||||||
std::vector<MulticastGroup> allMulticastGroups() const;
|
inline std::vector<MulticastGroup> allMulticastGroups() const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lock);
|
||||||
|
return _allMulticastGroups();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mg Multicast group
|
* @param mg Multicast group
|
||||||
|
@ -356,6 +360,7 @@ private:
|
||||||
void _externalConfig(ZT1_VirtualNetworkConfig *ec) const; // assumes _lock is locked
|
void _externalConfig(ZT1_VirtualNetworkConfig *ec) const; // assumes _lock is locked
|
||||||
bool _isAllowed(const Address &peer) const;
|
bool _isAllowed(const Address &peer) const;
|
||||||
void _announceMulticastGroups();
|
void _announceMulticastGroups();
|
||||||
|
std::vector<MulticastGroup> _allMulticastGroups() const;
|
||||||
|
|
||||||
const RuntimeEnvironment *RR;
|
const RuntimeEnvironment *RR;
|
||||||
uint64_t _id;
|
uint64_t _id;
|
||||||
|
|
|
@ -8,6 +8,25 @@ function ZT1Client(url,authToken)
|
||||||
this.authToken = authToken;
|
this.authToken = authToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate new ZeroTier identity -- mostly for testing
|
||||||
|
ZT1Client.prototype.newIdentity = function(callback)
|
||||||
|
{
|
||||||
|
request({
|
||||||
|
url: this.url + 'newIdentity',
|
||||||
|
method: 'GET',
|
||||||
|
json: false,
|
||||||
|
headers: {
|
||||||
|
'X-ZT1-Auth': this.authToken
|
||||||
|
}
|
||||||
|
},function(error,response,body) {
|
||||||
|
if (error)
|
||||||
|
return callback(error,null);
|
||||||
|
if (response.statusCode === 200)
|
||||||
|
return callback(null,body);
|
||||||
|
return callback(new Error('server responded with error: '+response.statusCode),'');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ZT1Client.prototype._jsonGet = function(getPath,callback)
|
ZT1Client.prototype._jsonGet = function(getPath,callback)
|
||||||
{
|
{
|
||||||
request({
|
request({
|
||||||
|
@ -134,4 +153,8 @@ ZT1Client.prototype.saveControllerNetwork = function(network,callback)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ZT1Client.prototype.getControllerNetworkMember = function(nwid,address,callback) {
|
||||||
|
this._jsonGet('controller/network/' + nwid + '/member/' + address,callback);
|
||||||
|
};
|
||||||
|
|
||||||
exports.ZT1Client = ZT1Client;
|
exports.ZT1Client = ZT1Client;
|
||||||
|
|
Loading…
Add table
Reference in a new issue