Skip to content

Commit

Permalink
Fixed issue with single client (ISSUE #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
makgyver committed Nov 7, 2023
1 parent 5ae94ab commit 9bb203e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gossipy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def __init__(self, num_nodes: int, topology: Optional[Union[np.ndarray, csr_matr
for node in range(num_nodes):
self._topology[node] = list(topology.getrow(node).nonzero()[-1])
else:
#self._topology = {i: None for i in range(num_nodes)}
self._topology = defaultdict(lambda: range(num_nodes))
self._topology = {i: [j for j in range(num_nodes) if j != i] for i in range(num_nodes)}
# self._topology = defaultdict(lambda: range(num_nodes))

# docstr-coverage:inherited
def size(self, node: Optional[int]=None) -> int:
Expand Down
5 changes: 5 additions & 0 deletions gossipy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def get_peer(self) -> int:
"""

peers = self.p2p_net.get_peers(self.idx)
if not peers:
LOG.warning("Node %d has no peers.", self.idx)
return None
return random.choice(peers) if peers else choice_not_n(0, self.p2p_net.size(), self.idx)

def timed_out(self, t: int) -> bool:
Expand Down Expand Up @@ -737,6 +740,8 @@ def timed_out(self, t: int) -> int:
def get_peer(self) -> int:
if self.step == 1 or not self.best_nodes:
peer = super().get_peer()
if peer is None:
return None
if self.step == 1:
self.selected[peer] += 1
return peer
Expand Down
6 changes: 6 additions & 0 deletions gossipy/simul.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ def start(self, n_rounds: int=100) -> None:
if node.timed_out(t):

peer = node.get_peer()
if peer is None:
break
msg = node.send(t, peer, self.protocol)
self.notify_message(False, msg)
if msg:
Expand Down Expand Up @@ -599,6 +601,8 @@ def start(self, n_rounds: int=100) -> Tuple[List[float], List[float]]:
if node.timed_out(t):
if random() < self.accounts[i].proactive():
peer = node.get_peer()
if peer is None:
break
msg = node.send(t, peer, self.protocol)
self.notify_message(False, msg)
if msg:
Expand Down Expand Up @@ -632,6 +636,8 @@ def start(self, n_rounds: int=100) -> Tuple[List[float], List[float]]:
self.accounts[msg.receiver].sub(reaction)
for _ in range(reaction):
peer = node.get_peer()
if peer is None:
break
msg = node.send(t, peer, self.protocol)
self.notify_message(False, msg)
if msg:
Expand Down

0 comments on commit 9bb203e

Please sign in to comment.