Skip to content

Commit 2f92ae3

Browse files
committed
add lookup and leave functions to public api
1 parent 053f60d commit 2f92ae3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/chordnet/chordnet.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""chordnet.py: chordnet api."""
2+
from typing import Tuple
3+
24
from ._node import _Node
5+
from .address import Address
36

47

58
class ChordNet:
@@ -43,6 +46,18 @@ def join(self, known_ip: str, known_port: int) -> None:
4346
"""
4447
self._node.join(known_ip, known_port)
4548

49+
def lookup(self, key: int) -> Tuple[str, int]:
50+
"""Finds the ip address of the node responsible for the given key.
51+
52+
Args:
53+
key: the value to look up (the hash)
54+
55+
Returns: the IP address of the node responsible for the given key,
56+
and the port that key is listening for ChordNet traffic on.
57+
"""
58+
result: Address = self._node.find_successor(key)
59+
return result.ip, result.port
60+
4661
def leave(self) -> None:
4762
"""Leave the current network.
4863
@@ -51,4 +66,4 @@ def leave(self) -> None:
5166
program exit (or before a node shuts down in the network), but the
5267
network can still recover if this does not happen.
5368
"""
54-
pass
69+
self._node.stop()

0 commit comments

Comments
 (0)