Skip to content
Snippets Groups Projects
Commit 747f1733 authored by Jarrod Pas's avatar Jarrod Pas
Browse files

Renames links to neighbours

parent 80884444
No related branches found
No related tags found
1 merge request!3Version 0.2
......@@ -143,15 +143,13 @@ class Node(TickProcess):
return self.network[self][other]['state']
@property
def links(self):
def neighbours(self):
'''
Returns a list of connected links.
Returns the set of nodes that are within transmission range.
'''
return {
met: data
for met, data in self.network[self].items()
if self.connected_to(met)
}
return frozenset([
met for met in self.network[self] if self.connected_to(met)
])
def __repr__(self):
return 'Node(id={})'.format(self.id)
......
......@@ -2,7 +2,7 @@ from .community import CommunityRouter
class BubbleRouter(CommunityRouter):
def __call__(self, packet):
if packet.destination in self.node.links:
if packet.destination in self.node.neighbours:
return packet.destination, 'direct', True
if self.local_community:
......
......@@ -8,15 +8,15 @@ class CommunityRouter(Router):
@property
def local_community(self):
links = self.node.links
neighbours = self.node.neighbours
community = self.node.community
return [met for met in links if met in community]
return [met for met in neighbours if met in community]
@property
def not_local_community(self):
links = self.node.links
neighbours = self.node.neighbours
community = self.node.community
return [met for met in links if met not in community]
return [met for met in neighbours if met not in community]
@staticmethod
def best(nodes, key):
......
......@@ -2,7 +2,7 @@ from .base import Router
class DirectRouter(Router):
def __call__(self, packet):
if packet.destination in self.node.links:
if packet.destination in self.node.neighbours:
return packet.destination, 'direct', True
return None, None, False
......
......@@ -13,7 +13,7 @@ class EpidemicRouter(Router):
# get list of currently encountered nodes that do not have the packet
targets = [
met
for met in self.node.links
for met in self.node.neighbours
if met not in self.sent[packet]
]
......
......@@ -2,5 +2,5 @@ from .base import Router
class FloodingRouter(Router):
def __call__(self, packet):
return self.node.links, 'flood', False
return self.node.neighbours, 'flood', False
......@@ -5,7 +5,7 @@ class HCBFRouter(CommunityRouter):
me = self.node
dest = packet.destination
if dest in me.links:
if dest in me.neighbours:
return dest, 'direct', True
if me.community is not dest.community and self.not_local_community:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment