-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Added ZeroTier Parser #106
Closes #106
- Loading branch information
1 parent
1a10207
commit 850fb38
Showing
6 changed files
with
566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from netdiff.parsers.base import BaseParser | ||
|
||
|
||
class ZeroTierParser(BaseParser): | ||
version = '1' | ||
metric = 'static' | ||
protocol = 'ZeroTier Controller Peers' | ||
|
||
def to_python(self, data): | ||
return super().to_python(data) | ||
|
||
def parse(self, data): | ||
graph = self._init_graph() | ||
for peer in data: | ||
# In the ZeroTier architecture, a 'LEAF' refers to a device | ||
# that is a member of a ZeroTier virtual network. | ||
# Therefore, we can skip peers with roles other than 'LEAF' | ||
# or with latency -1 (indicating not reachable) | ||
if peer.get('role') != 'LEAF' or peer.get('latency') == -1: | ||
continue | ||
# Similar to zerotier-cli peers command (PATH) | ||
# We only select path that are active, preferred, and not expired | ||
for path in peer.get('paths'): | ||
if ( | ||
not path.get('expired') | ||
and path.get('active') | ||
and path.get('preferred') | ||
): | ||
peer_address = peer.get('address') | ||
peer_properties = dict( | ||
label=peer_address, | ||
address=peer_address, | ||
ip_address=path.pop('address'), | ||
role=peer.get('role'), | ||
version=peer.get('version'), | ||
tunneled=peer.get('tunneled'), | ||
isBonded=peer.get('isBonded'), | ||
) | ||
graph.add_node('controller', label='controller') | ||
graph.add_node(peer_address, **peer_properties) | ||
graph.add_edge( | ||
'controller', peer_address, weight=peer.get('latency'), **path | ||
) | ||
return graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
[ | ||
{ | ||
"address": "3504e2b2e2", | ||
"isBonded": false, | ||
"latency": 9, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "192.168.56.1/44221", | ||
"expired": false, | ||
"lastReceive": 1691493323678, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869108304, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
}, | ||
{ | ||
"active": true, | ||
"address": "fd60:8d57:65e9::1/9993", | ||
"expired": false, | ||
"lastReceive": 1691493323678, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869123504, | ||
"preferred": false, | ||
"trustedPathId": 0 | ||
}, | ||
{ | ||
"active": true, | ||
"address": "fd60:8d57:65e9::1/9993", | ||
"expired": false, | ||
"lastReceive": 1691493323678, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869095936, | ||
"preferred": false, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "LEAF", | ||
"tunneled": false, | ||
"version": "1.10.3", | ||
"versionMajor": 1, | ||
"versionMinor": 10, | ||
"versionRev": 3 | ||
}, | ||
{ | ||
"address": "9a9e1c9f19", | ||
"isBonded": false, | ||
"latency": 0, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "192.168.56.6/9993", | ||
"expired": false, | ||
"lastReceive": 1691493318673, | ||
"lastSend": 1691493318672, | ||
"localSocket": 94434869092208, | ||
"preferred": false, | ||
"trustedPathId": 0 | ||
}, | ||
{ | ||
"active": true, | ||
"address": "192.168.56.1/9993", | ||
"expired": false, | ||
"lastReceive": 1691493318673, | ||
"lastSend": 1691493318672, | ||
"localSocket": 94434869109504, | ||
"preferred": false, | ||
"trustedPathId": 0 | ||
}, | ||
{ | ||
"active": true, | ||
"address": "172.168.56.9/9993", | ||
"expired": false, | ||
"lastReceive": 1691493323678, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869108304, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "LEAF", | ||
"tunneled": false, | ||
"version": "1.10.3", | ||
"versionMajor": 1, | ||
"versionMinor": 10, | ||
"versionRev": 3 | ||
}, | ||
{ | ||
"address": "62f865ae71", | ||
"isBonded": false, | ||
"latency": 297, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "50.7.252.138/9993", | ||
"expired": false, | ||
"lastReceive": 1691493263920, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869079296, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "PLANET", | ||
"tunneled": false, | ||
"version": "-1.-1.-1", | ||
"versionMajor": -1, | ||
"versionMinor": -1, | ||
"versionRev": -1 | ||
}, | ||
{ | ||
"address": "778cde7190", | ||
"isBonded": false, | ||
"latency": 276, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "103.195.103.66/9993", | ||
"expired": false, | ||
"lastReceive": 1691493263899, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869085344, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "PLANET", | ||
"tunneled": false, | ||
"version": "-1.-1.-1", | ||
"versionMajor": -1, | ||
"versionMinor": -1, | ||
"versionRev": -1 | ||
}, | ||
{ | ||
"address": "cafe04eba9", | ||
"isBonded": false, | ||
"latency": 163, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "84.17.53.155/9993", | ||
"expired": false, | ||
"lastReceive": 1691493263786, | ||
"lastSend": 1691493327124, | ||
"localSocket": 94434869086304, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "PLANET", | ||
"tunneled": false, | ||
"version": "-1.-1.-1", | ||
"versionMajor": -1, | ||
"versionMinor": -1, | ||
"versionRev": -1 | ||
}, | ||
{ | ||
"address": "cafe9efeb9", | ||
"isBonded": false, | ||
"latency": 241, | ||
"paths": [ | ||
{ | ||
"active": true, | ||
"address": "104.194.8.134/9993", | ||
"expired": false, | ||
"lastReceive": 1691493263864, | ||
"lastSend": 1691493323677, | ||
"localSocket": 94434869086304, | ||
"preferred": true, | ||
"trustedPathId": 0 | ||
} | ||
], | ||
"role": "PLANET", | ||
"tunneled": false, | ||
"version": "-1.-1.-1", | ||
"versionMajor": -1, | ||
"versionMinor": -1, | ||
"versionRev": -1 | ||
} | ||
] |
Oops, something went wrong.