|
@@ -1036,7 +1036,94 @@ int Network::setConfiguration(void *tPtr,const NetworkConfig &nconf,bool saveToD
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void Network::requestConfiguration(void *tPtr)
|
|
|
+bool Network::gate(void *tPtr,const SharedPtr<Peer> &peer)
|
|
|
+{
|
|
|
+ const int64_t now = RR->node->now();
|
|
|
+ Mutex::Lock l(_memberships_l);
|
|
|
+ try {
|
|
|
+ if (_config) {
|
|
|
+ Membership *m = _memberships.get(peer->address());
|
|
|
+ if ( (_config.isPublic()) || ((m)&&(m->isAllowedOnNetwork(_config))) ) {
|
|
|
+ if (!m)
|
|
|
+ m = &(_memberships[peer->address()]);
|
|
|
+ if (m->multicastLikeGate(now)) {
|
|
|
+ Mutex::Lock l2(_myMulticastGroups_l);
|
|
|
+ _announceMulticastGroupsTo(tPtr,peer->address(),_allMulticastGroups());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch ( ... ) {}
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+void Network::doPeriodicTasks(void *tPtr,const int64_t now)
|
|
|
+{
|
|
|
+ if (_destroyed)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if ((now - _lastConfigUpdate) >= ZT_NETWORK_AUTOCONF_DELAY)
|
|
|
+ _requestConfiguration(tPtr);
|
|
|
+
|
|
|
+ {
|
|
|
+ Mutex::Lock l1(_memberships_l);
|
|
|
+
|
|
|
+ {
|
|
|
+ Address *a = (Address *)0;
|
|
|
+ Membership *m = (Membership *)0;
|
|
|
+ Hashtable<Address,Membership>::Iterator i(_memberships);
|
|
|
+ while (i.next(a,m))
|
|
|
+ m->clean(now,_config);
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ Mutex::Lock l2(_myMulticastGroups_l);
|
|
|
+
|
|
|
+ Hashtable< MulticastGroup,uint64_t >::Iterator i(_multicastGroupsBehindMe);
|
|
|
+ MulticastGroup *mg = (MulticastGroup *)0;
|
|
|
+ uint64_t *ts = (uint64_t *)0;
|
|
|
+ while (i.next(mg,ts)) {
|
|
|
+ if ((now - *ts) > (ZT_MULTICAST_LIKE_EXPIRE * 2))
|
|
|
+ _multicastGroupsBehindMe.erase(*mg);
|
|
|
+ }
|
|
|
+
|
|
|
+ _announceMulticastGroups(tPtr,false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+Membership::AddCredentialResult Network::addCredential(void *tPtr,const Address &sentFrom,const Revocation &rev)
|
|
|
+{
|
|
|
+ if (rev.networkId() != _id)
|
|
|
+ return Membership::ADD_REJECTED;
|
|
|
+
|
|
|
+ Mutex::Lock l1(_memberships_l);
|
|
|
+ Membership &m = _memberships[rev.target()];
|
|
|
+
|
|
|
+ const Membership::AddCredentialResult result = m.addCredential(RR,tPtr,_config,rev);
|
|
|
+
|
|
|
+ if ((result == Membership::ADD_ACCEPTED_NEW)&&(rev.fastPropagate())) {
|
|
|
+ Address *a = (Address *)0;
|
|
|
+ Membership *m = (Membership *)0;
|
|
|
+ Hashtable<Address,Membership>::Iterator i(_memberships);
|
|
|
+ while (i.next(a,m)) {
|
|
|
+ if ((*a != sentFrom)&&(*a != rev.signer())) {
|
|
|
+ Packet outp(*a,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
|
|
|
+ outp.append((uint8_t)0x00); // no COM
|
|
|
+ outp.append((uint16_t)0); // no capabilities
|
|
|
+ outp.append((uint16_t)0); // no tags
|
|
|
+ outp.append((uint16_t)1); // one revocation!
|
|
|
+ rev.serialize(outp);
|
|
|
+ outp.append((uint16_t)0); // no certificates of ownership
|
|
|
+ RR->sw->send(tPtr,outp,true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void Network::_requestConfiguration(void *tPtr)
|
|
|
{
|
|
|
if (_destroyed)
|
|
|
return;
|
|
@@ -1215,90 +1302,6 @@ void Network::requestConfiguration(void *tPtr)
|
|
|
RR->sw->send(tPtr,outp,true);
|
|
|
}
|
|
|
|
|
|
-bool Network::gate(void *tPtr,const SharedPtr<Peer> &peer)
|
|
|
-{
|
|
|
- const int64_t now = RR->node->now();
|
|
|
- Mutex::Lock l(_memberships_l);
|
|
|
- try {
|
|
|
- if (_config) {
|
|
|
- Membership *m = _memberships.get(peer->address());
|
|
|
- if ( (_config.isPublic()) || ((m)&&(m->isAllowedOnNetwork(_config))) ) {
|
|
|
- if (!m)
|
|
|
- m = &(_memberships[peer->address()]);
|
|
|
- if (m->multicastLikeGate(now)) {
|
|
|
- Mutex::Lock l2(_myMulticastGroups_l);
|
|
|
- _announceMulticastGroupsTo(tPtr,peer->address(),_allMulticastGroups());
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch ( ... ) {}
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
-void Network::doPeriodicTasks(void *tPtr)
|
|
|
-{
|
|
|
- const int64_t now = RR->node->now();
|
|
|
- Mutex::Lock l1(_memberships_l);
|
|
|
-
|
|
|
- if (_destroyed)
|
|
|
- return;
|
|
|
-
|
|
|
- {
|
|
|
- Address *a = (Address *)0;
|
|
|
- Membership *m = (Membership *)0;
|
|
|
- Hashtable<Address,Membership>::Iterator i(_memberships);
|
|
|
- while (i.next(a,m)) {
|
|
|
- m->clean(now,_config);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- Mutex::Lock l2(_myMulticastGroups_l);
|
|
|
-
|
|
|
- Hashtable< MulticastGroup,uint64_t >::Iterator i(_multicastGroupsBehindMe);
|
|
|
- MulticastGroup *mg = (MulticastGroup *)0;
|
|
|
- uint64_t *ts = (uint64_t *)0;
|
|
|
- while (i.next(mg,ts)) {
|
|
|
- if ((now - *ts) > (ZT_MULTICAST_LIKE_EXPIRE * 2))
|
|
|
- _multicastGroupsBehindMe.erase(*mg);
|
|
|
- }
|
|
|
-
|
|
|
- _announceMulticastGroups(tPtr,false);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-Membership::AddCredentialResult Network::addCredential(void *tPtr,const Address &sentFrom,const Revocation &rev)
|
|
|
-{
|
|
|
- if (rev.networkId() != _id)
|
|
|
- return Membership::ADD_REJECTED;
|
|
|
-
|
|
|
- Mutex::Lock l1(_memberships_l);
|
|
|
- Membership &m = _memberships[rev.target()];
|
|
|
-
|
|
|
- const Membership::AddCredentialResult result = m.addCredential(RR,tPtr,_config,rev);
|
|
|
-
|
|
|
- if ((result == Membership::ADD_ACCEPTED_NEW)&&(rev.fastPropagate())) {
|
|
|
- Address *a = (Address *)0;
|
|
|
- Membership *m = (Membership *)0;
|
|
|
- Hashtable<Address,Membership>::Iterator i(_memberships);
|
|
|
- while (i.next(a,m)) {
|
|
|
- if ((*a != sentFrom)&&(*a != rev.signer())) {
|
|
|
- Packet outp(*a,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
|
|
|
- outp.append((uint8_t)0x00); // no COM
|
|
|
- outp.append((uint16_t)0); // no capabilities
|
|
|
- outp.append((uint16_t)0); // no tags
|
|
|
- outp.append((uint16_t)1); // one revocation!
|
|
|
- rev.serialize(outp);
|
|
|
- outp.append((uint16_t)0); // no certificates of ownership
|
|
|
- RR->sw->send(tPtr,outp,true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
ZT_VirtualNetworkStatus Network::_status() const
|
|
|
{
|
|
|
if (_portError)
|