本文整理汇总了Python中node.Node.id方法的典型用法代码示例。如果您正苦于以下问题:Python Node.id方法的具体用法?Python Node.id怎么用?Python Node.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node.Node
的用法示例。
在下文中一共展示了Node.id方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def __init__(self, layers_nodes_count):
self.layers = []
self.nodeCount = 0
# create layers
for i in range(0, len(layers_nodes_count)):
layer = []
# create nodes in each layer
for j in range(0, layers_nodes_count[i]):
node = Node()
node.id = "n%i" % self.nodeCount
# connect node to all previous layer nodes, add dummy node
if i > 0:
prevLayer = self.layers[i - 1]
for k in range(0, len(prevLayer)):
node.addIndegree(prevLayer[k],random.random())
dummy = Node()
dummy.id = "d"
dummy.output = 1.0
node.addIndegree(dummy,random.random())
layer.append(node)
self.nodeCount += 1
self.layers.append(layer)
示例2: test_node_without_id
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def test_node_without_id(self):
n1 = Node(tc.CLIENT_ADDR)
n2 = Node(tc.CLIENT_ADDR)
eq_(n1, n2)
n1.id = tc.CLIENT_ID
ok_(n1 != n2)
n2.id = tc.CLIENT_ID
eq_(n1, n2)
示例3: import_aliases
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def import_aliases(self, aliases):
for mac, alias in aliases.items():
try:
node = self.maybe_node_by_mac([mac])
except:
try:
node = self.maybe_node_by_fuzzy_mac(mac)
except:
# create an offline node
node = Node()
node.add_mac(mac)
self._nodes.append(node)
if 'name' in alias:
node.name = alias['name']
if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
node.interfaces[mac].vpn = True
if 'gps' in alias:
node.gps = alias['gps']
if 'firmware' in alias:
node.firmware = alias['firmware']
if 'id' in alias:
node.id = alias['id']
示例4: test_node
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def test_node(self):
node1 = Node(addr1, id1, 'version')
node2 = Node(addr2, id2)
node1b = Node(addr1, None)
node1ip = Node(('127.0.0.2', 1111), id1)
node1port = Node(addr2, id1)
node1id = Node(addr1, id2)
eq_(str(node1), '<node: %r %r (version)>' % (addr1, id1))
#<node: ('127.0.0.1', 1111) 0x1313131313131313131313131313131313131313>
eq_(node1.id, id1)
assert node1.id != id2
assert node1.addr == addr1
eq_(node1.ip, addr1[0])
assert node1.addr != addr2
assert node1 == node1
assert node1 != node1b
node1b.id = id1
assert node1 == node1b
assert node1 != node2
assert node1 != node1ip
assert node1 != node1port
assert node1 != node1id
示例5: test_node
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def test_node(self):
node1 = Node(addr1, id1)
node2 = Node(addr2, id2)
node1b = Node(addr1, None)
node1ip = Node(('127.0.0.2', 1111), id1)
node1port = Node(addr2, id1)
node1id = Node(addr1, id2)
assert str(node1) == '<node: %r %r>' % (addr1, id1)
#<node: ('127.0.0.1', 1111) 0x1313131313131313131313131313131313131313>
assert node1.id == id1
assert node1.id != id2
assert node1.addr == addr1
assert node1.addr != addr2
assert node1 == node1
assert node1 != node1b
node1b.id = id1
assert node1 == node1b
assert node1 != node2
assert node1 != node1ip
assert node1 != node1port
assert node1 != node1id
示例6: reducer
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def reducer(self, key, values):
edges = []
distance = 9999
status = UNVISITED
for value in values:
node = Node()
node.fromLine(value)
#if it's not itself
if(len(node.connections)>0):
filtered_connections = filter(None, node.connections)
edges.extend(filtered_connections)
if(node.distance < distance):
distance = node.distance
if(node.status == VISITED):
status = VISITED
if(node.status == PROCESS and status == UNVISITED):
status = PROCESS
node = Node()
node.id = key
node.distance = distance
node.status = status
node.connections = edges
yield key, node.getLine()
示例7: load_state
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def load_state(self, filename):
try:
with open(filename, "r") as f:
obj = json.load(f)
for n in obj:
try:
node = self.maybe_node_by_id(n['id'])
except:
node = Node()
node.id = n['id']
node.name = n['name']
node.lastseen = n['lastseen']
node.gps = n['geo']
node.firmware = n['firmware']
node.firmware_release = n['firmware_release']
node.hardware = n['hardware']
node.autoupdate = n['autoupdate']
node.branch = n['branch']
self._nodes.append(node)
if 'firstseen' in n:
node.firstseen = n['firstseen']
except:
pass
示例8: import_aliases
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def import_aliases(self, aliases):
for mac, alias in aliases.items():
try:
node = self.maybe_node_by_mac([mac])
except:
try:
node = self.maybe_node_by_fuzzy_mac(mac)
except:
# create an offline node
node = Node()
node.add_mac(mac)
self._nodes.append(node)
if 'name' in alias:
node.name = alias['name']
if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
try:
node.interfaces[mac].vpn = True
except:
print("error with ", mac)
if 'gps' in alias:
node.gps = alias['gps']
if 'firmware' in alias:
node.firmware = alias['firmware']
if 'model' in alias:
node.model = alias['model']
if 'uptime' in alias:
node.uptime = alias['uptime']
if 'id' in alias:
node.id = alias['id']
if 'addresses' in alias:
node.addresses = alias['addresses']
if 'autoupdater_enabled' in alias:
node.autoupdater['enabled'] = alias['autoupdater_enabled']
if 'autoupdater_branch' in alias:
node.autoupdater['branch'] = alias['autoupdater_branch']
if 'contact' in alias:
node.contact = alias['contact']
示例9: import_aliases
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def import_aliases(self, aliases):
for mac, alias in aliases.items():
try:
node = self.maybe_node_by_mac([mac])
except:
try:
node = self.maybe_node_by_fuzzy_mac(mac)
except:
# create an offline node
node = Node()
node.add_mac(mac)
self._nodes.append(node)
if 'name' in alias:
node.name = alias['name']
if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
node.interfaces[mac].vpn = True
if 'gps' in alias:
node.gps = alias['gps']
if 'firmware' in alias:
node.firmware = alias['firmware']
if 'id' in alias:
node.id = alias['id']
if 'uptime' in alias:
node.uptime = alias['uptime']
if 'tx_bytes' in alias:
node.tx_bytes = alias['tx_bytes']
if 'rx_bytes' in alias:
node.rx_bytes = alias['rx_bytes']
if 'loadavg' in alias:
node.loadavg = alias['loadavg']
if 'autoupdater' in alias:
node.autoupdater = alias['autoupdater']
if 'branch' in alias:
node.branch = alias['branch']
if 'hardware' in alias:
node.hardware = alias['hardware']
示例10: load_state
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def load_state(self, filename):
try:
with open(filename, "r") as f:
obj = json.load(f)
for n in obj:
try:
node = self.maybe_node_by_id(n['id'])
except:
node = Node()
node.id = n['id']
node.name = n['name']
node.lastseen = n['lastseen']
node.gps = n['geo']
self._nodes.append(node)
except:
pass
示例11: mapper
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def mapper(self, _, line):
node = Node()
node.fromLine(line)
#Processing the starting point
if(node.status == PROCESS):
for connection in node.connections:
adjNode = Node()
adjNode.id = connection
adjNode.distance = int(node.distance) + 1
#put the node into the stack
adjNode.status = PROCESS
if(self.options.target== connection):
counterName = ("Target ID " + connection + " is connected " + str(adjNode.distance))
self.increment_counter('Degrees of Separation', counterName, 1)
if not os.path.exists(result_dir.resultDir+'/report'):
os.makedirs(result_dir.resultDir+'/report')
result = open(result_dir.resultDir+'/report/result.txt','w')
result.write(counterName)
result.close()
yield connection, adjNode.getLine()
node.status = VISITED
yield node.id, node.getLine()
示例12: parse_vis_data
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def parse_vis_data(self,vis_data):
for x in vis_data:
if 'of' in x:
try:
node = self.maybe_node_by_mac((x['of'], x['secondary']))
except:
node = Node()
node.flags['online'] = True
if 'legacy' in x:
node.flags['legacy'] = True
self._nodes.append(node)
node.add_mac(x['of'])
node.add_mac(x['secondary'])
for x in vis_data:
if 'router' in x:
try:
node = self.maybe_node_by_mac((x['router'], ))
except:
node = Node()
node.flags['online'] = True
if 'legacy' in x:
node.flags['legacy'] = True
node.add_mac(x['router'])
self._nodes.append(node)
# If it's a TT link and the MAC is very similar
# consider this MAC as one of the routers
# MACs
if 'gateway' in x and x['label'] == "TT":
if is_similar(x['router'], x['gateway']):
node.add_mac(x['gateway'])
# skip processing as regular link
continue
try:
if 'neighbor' in x:
try:
node = self.maybe_node_by_mac((x['neighbor']))
except:
continue
if 'gateway' in x:
x['neighbor'] = x['gateway']
node = self.maybe_node_by_mac((x['neighbor'], ))
except:
node = Node()
node.flags['online'] = True
if x['label'] == 'TT':
node.flags['client'] = True
node.add_mac(x['neighbor'])
self._nodes.append(node)
for x in vis_data:
if 'router' in x:
try:
if 'gateway' in x:
x['neighbor'] = x['gateway']
router = self.maybe_node_by_mac((x['router'], ))
neighbor = self.maybe_node_by_mac((x['neighbor'], ))
except:
continue
# filter TT links merged in previous step
if router == neighbor:
continue
link = Link()
link.source = LinkConnector()
link.source.interface = x['router']
link.source.id = self._nodes.index(router)
link.target = LinkConnector()
link.target.interface = x['neighbor']
link.target.id = self._nodes.index(neighbor)
link.quality = x['label']
link.id = "-".join(sorted((link.source.interface, link.target.interface)))
if x['label'] == "TT":
link.type = "client"
self._links.append(link)
for x in vis_data:
if 'primary' in x:
try:
node = self.maybe_node_by_mac((x['primary'], ))
except:
continue
node.id = x['primary']
示例13: parse_vis_data
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def parse_vis_data(self,vis_data):
for x in vis_data:
if 'of' in x:
try:
node = self.maybe_node_by_mac((x['of'], x['secondary']))
except KeyError:
node = Node()
node.lastseen = self.time
node.firstseen = self.time
node.flags['online'] = True
self._nodes.append(node)
node.add_mac(x['of'])
node.add_mac(x['secondary'])
for x in vis_data:
if 'router' in x:
# TTs will be processed later
if x['label'] == "TT":
continue
try:
node = self.maybe_node_by_mac((x['router'], ))
except KeyError:
node = Node()
node.lastseen = self.time
node.firstseen = self.time
node.flags['online'] = True
node.add_mac(x['router'])
self._nodes.append(node)
try:
if 'neighbor' in x:
try:
node = self.maybe_node_by_mac((x['neighbor'], ))
except KeyError:
continue
if 'gateway' in x:
x['neighbor'] = x['gateway']
node = self.maybe_node_by_mac((x['neighbor'], ))
except KeyError:
node = Node()
node.lastseen = self.time
node.firstseen = self.time
node.flags['online'] = True
node.add_mac(x['neighbor'])
self._nodes.append(node)
for x in vis_data:
if 'router' in x:
# TTs will be processed later
if x['label'] == "TT":
continue
try:
if 'gateway' in x:
x['neighbor'] = x['gateway']
router = self.maybe_node_by_mac((x['router'], ))
neighbor = self.maybe_node_by_mac((x['neighbor'], ))
except KeyError:
continue
# filter TT links merged in previous step
if router == neighbor:
continue
link = Link()
link.source = LinkConnector()
link.source.interface = x['router']
link.source.id = self._nodes.index(router)
link.target = LinkConnector()
link.target.interface = x['neighbor']
link.target.id = self._nodes.index(neighbor)
link.quality = x['label']
link.id = "-".join(sorted((link.source.interface, link.target.interface)))
self._links.append(link)
for x in vis_data:
if 'primary' in x:
try:
node = self.maybe_node_by_mac((x['primary'], ))
except KeyError:
continue
node.id = x['primary']
for x in vis_data:
if 'router' in x and x['label'] == 'TT':
try:
node = self.maybe_node_by_mac((x['router'], ))
node.add_mac(x['gateway'])
node.clientcount += 1
except KeyError:
pass
#.........这里部分代码省略.........
示例14: import_batman
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import id [as 别名]
def import_batman(self, lines):
for line in lines:
x = json.loads(line)
if 'of' in x:
try:
node = self.maybe_node_by_mac((x['of'], x['secondary']))
except:
node = Node()
node.flags['online'] = True
self._nodes.append(node)
node.add_mac(x['of'])
node.add_mac(x['secondary'])
for line in lines:
x = json.loads(line)
if 'router' in x:
try:
node = self.maybe_node_by_mac((x['router'], ))
except:
node = Node()
node.flags['online'] = True
node.add_mac(x['router'])
self._nodes.append(node)
# If it's a TT link and the MAC is very similar
# consider this MAC as one of the routers
# MACs
if 'gateway' in x and x['label'] == "TT":
router = list(int(i, 16) for i in x['router'].split(":"))
gateway = list(int(i, 16) for i in x['gateway'].split(":"))
# first byte must only differ in bit 2
if router[0] == gateway[0] | 2:
# count different bytes
a = [x for x in zip(router[1:], gateway[1:]) if x[0] != x[1]]
# no more than two additional bytes must differ
if len(a) <= 2:
delta = 0
if len(a) > 0:
delta = sum(abs(i[0] -i[1]) for i in a)
if delta < 8:
# This TT link looks like a mac of the router!
node.add_mac(x['gateway'])
# skip processing as regular link
continue
try:
if 'neighbor' in x:
try:
node = self.maybe_node_by_mac((x['neighbor']))
except:
continue
if 'gateway' in x:
x['neighbor'] = x['gateway']
node = self.maybe_node_by_mac((x['neighbor'], ))
except:
node = Node()
node.flags['online'] = True
if x['label'] == 'TT':
node.flags['client'] = True
node.add_mac(x['neighbor'])
self._nodes.append(node)
for line in lines:
x = json.loads(line)
if 'router' in x:
try:
if 'gateway' in x:
x['neighbor'] = x['gateway']
router = self.maybe_node_by_mac((x['router'], ))
neighbor = self.maybe_node_by_mac((x['neighbor'], ))
except:
continue
# filter TT links merged in previous step
if router == neighbor:
continue
link = Link()
link.source = LinkConnector()
link.source.interface = x['router']
link.source.id = self._nodes.index(router)
link.target = LinkConnector()
link.target.interface = x['neighbor']
link.target.id = self._nodes.index(neighbor)
link.quality = x['label']
link.id = "-".join(sorted((link.source.interface, link.target.interface)))
#.........这里部分代码省略.........