From a35d2786856e76e4763f608902915e42c1789856 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 20 Feb 2024 11:19:08 +0100 Subject: [PATCH] add node level P2PNeighbor class Signed-off-by: Csaba Kiraly --- DAS/node.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/DAS/node.py b/DAS/node.py index 740f04f..b307462 100644 --- a/DAS/node.py +++ b/DAS/node.py @@ -9,6 +9,13 @@ from bitarray.util import zeros from collections import deque from itertools import chain +class P2PNeighbor: + def __init__(self, node, peerNode): + """Implement a p2p neighbor for gossip and monitor sent and received data.""" + self.node = node + def setPeer(self, peer): + self.peer = peer + class Neighbor: """This class implements a node neighbor to monitor sent and received data. @@ -85,6 +92,7 @@ class Node: self.rowIDs = self.rowIDs.union(v.rowIDs) self.columnIDs = self.columnIDs.union(v.columnIDs) + self.neighbors = dict() self.rowNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict) @@ -119,6 +127,18 @@ class Node: self.segmentShuffleScheduler = True # send each segment that's worth sending once in shuffled order, then repeat self.segmentShuffleSchedulerPersist = True # Persist scheduler state between timesteps + def addNeighbor(self, peer, symmetric = True): + n = P2PNeighbor(self, self.shape.blockSizeR) + p = P2PNeighbor(peer, self.shape.blockSizeR) + n.setPeer(p) + p.setPeer(n) + + if peer.ID not in self.neighbors: + self.neighbors[peer.ID] = p + if symmetric: + if self.ID not in peer.neighbors: + peer.neighbors[self.ID] = n + def addRowNeighbor(self, lineID, peer, symmetric = True): n = Neighbor(self, 0, self.shape.blockSizeR) p = Neighbor(peer, 0, self.shape.blockSizeR)