Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ convention = "google"
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
files = ["src", "tests"]
files = ["src", "tests", "scripts"]
exclude = [
'(^|.*/)__pycache__/', # matches __pycache__ at any depth
'(^|.*/).ruff_cache/',
'(^|.*/).mypy_cache/',
]

[[tool.mypy.overrides]]
module = ["bpython"]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions scripts/auto/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""__init__.py: nothing to see here..."""
1 change: 1 addition & 0 deletions scripts/auto/anchor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""anchor.py: creates and starts an anchor node for testing."""
1 change: 1 addition & 0 deletions scripts/auto/joiner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""joiner.py: creates a joining node for debugging."""
1 change: 1 addition & 0 deletions scripts/manual/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""__init__.py: nothing to see here..."""
33 changes: 33 additions & 0 deletions scripts/manual/anchor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""anchor.py: creates and starts an anchor node for testing."""
import sys

import bpython
from step import step #type: ignore

from chordnet import Node as ChordNode


def main() -> None:
"""Creates a new ring with this computer as the only node."""
if len(sys.argv) != 3:
print("usage: [uv run] python anchor.py ip_addr port_no")
exit(1)

ip = sys.argv[1]
port = int(sys.argv[2])

node = ChordNode(ip, port)
# create (start) the ring
node.create()
print(f"Node created as \"node\": {node.address}", file=sys.stderr)
repl_locals = {
'node': node,
'step': step,
}
print("starting repl. access `node`, advance with `step(node)`")
bpython.embed(locals_=repl_locals)
node.stop()


if __name__ == '__main__':
main()
36 changes: 36 additions & 0 deletions scripts/manual/joiner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""joiner.py: creates a joining node for debugging."""
import sys

import bpython
from step import step #type: ignore

from chordnet import Node as ChordNode


def main() -> None:
"""Creates a new ring with this computer as the only node."""
if len(sys.argv) != 5:
print("usage: [uv run] python " \
"joiner.py this_ip this_port target_ip target_port")
exit(1)

# Get IP and port from command line arguments
ip = sys.argv[1]
port = int(sys.argv[2])
target_ip = sys.argv[3]
target_port = int(sys.argv[4])

# Create and join node
node = ChordNode(ip, port)
node.join(target_ip, target_port)
repl_locals = {
'node': node,
'step': step,
}
print("starting repl. access `node`, advance with `step(node)`")
bpython.embed(locals_=repl_locals)
node.stop()


if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions scripts/manual/step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""step.py: helper for manual scripts."""

from chordnet import Node as ChordNode


def step(node: ChordNode) -> None:
"""Runs the periodic tasks for the node once."""
node.stabilize()
node.fix_fingers()

print(f"pred: {node.predecessor} succ: {node.successor()}")
print(node.finger_table)
1 change: 1 addition & 0 deletions src/chordnet/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __eq__(self, other: object) -> bool:
"""
if not isinstance(other, Address):
return NotImplemented

return (self.ip == other.ip and
self.port == other.port and
self.key == other.key)
Expand Down