Skip to content

Commit a8e2566

Browse files
authored
Daemon (#24)
* missed a log statement * add daemon code (back) in, simplify * start isn't user facing, update bools to reflect * update manual scripts to make sure daemon is disabled * init timer to None * switch from bpython to IPython to avoid greenlet exception * update notification logic for first joiner edge case * fix 2 node ring edge case * bump version to 1.1
1 parent 233b059 commit a8e2566

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "chordnet"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
license = "MIT"
55
license-files = ["LICENSE"]
66
description = "Implementation of the chord peer-to-peer networking protocol, introduced by Stoica et al."

src/chordnet/node.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ def stabilize(self) -> None:
290290
# set successor to x
291291
# notify successor about this node
292292
curr_successor = self.successor()
293-
if curr_successor is None:
293+
if curr_successor is None or curr_successor == self.address:
294+
# if we have a predecessor, then its a 2 node ring
295+
# complete the circle
296+
if self.predecessor and self.predecessor != self.address:
297+
self.finger_table[0] = self.predecessor
294298
return
295299

300+
301+
296302
x = None
297303

298304
try:
@@ -441,9 +447,11 @@ def _be_notified(self, notifying_node: Address) -> bool:
441447
True if the node was accepted as a predecessor, False otherwise.
442448
"""
443449
# Update predecessor if necessary
444-
if not self.predecessor or self._is_between(
445-
self.predecessor.key, self.address.key, notifying_node.key
446-
):
450+
my_key = self.address.key
451+
their_key = notifying_node.key
452+
if not self.predecessor \
453+
or self.predecessor == self.address \
454+
or self._is_between(self.predecessor.key, my_key, their_key):
447455
self.predecessor = notifying_node
448456
return True
449457
else:
@@ -546,7 +554,8 @@ def _process_request(
546554
[args[0], args[1], args[2]])
547555
)
548556
assert notifier is not None
549-
return "OK" if self._be_notified(notifier) else "IGNORED"
557+
new_predecessor = self._be_notified(notifier)
558+
return "OK" if new_predecessor else "IGNORED"
550559

551560
except (ValueError, AssertionError):
552561
return "INVALID_NODE"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)