+
Skip to content

jacklowrie/chordnet

Repository files navigation

ChordNet

GitHub Actions Workflow Status GitHub Actions Workflow Status

GitHub License PyPI - Types PyPI - Version PyPI - Downloads PyPI - Python Version PyPI - Implementation

Python implementation of the chord protocol, introduced by Stoica et al. This library began as a group project for cs536 at Purdue University in Fall 2024.

Installation

pip install chordnet

uv add chordnet

Usage

To stay consistent with the language from the original paper, we recommend naming your chordnet attribute ring:

from chordnet import ChordNet

ring = new ChordNet(...)
ring.create() # or ring.join(...)
#...application logic...
ring.leave()
# end program

This fits with the concept of "joining" an existing ring network, or creating a new one. Examples follow this practice.

At present, this package only supports IP lookup. All application-dependent logic (state transfer, etc) must be handled by the application. The easiest way to do this is to initialize ChordNet as an attribute on an application class:

class App:
    """An example/template application that uses ChordNet."""
    def __init__(self, ip: str, chordnet_port: int) -> None:
        """Creates a new insance of the app."""
        self._ring = ChordNet(ip, chordnet_port)

    def start(
        self, ip = None: str | None, port = None: int | None
    ) -> None:
        """Starts the app by joining an existing ring or creating a new one."""
        if ip and port:
            self._ring.join(ip, port)
            # ...any state transfer logic, if part of this app...
        elif not ip and not port:
            self._ring.create()
        else:
            print("need both or neither")
            return

    #...application logic (probably using self._ring.lookup()...

    def stop(self) -> None:
        """Gracefully leaves the ring."""
        # ...any state transfer logic (if using)...
        self._ring.leave()

Not all distributed applications that ChordNet is suitable for will require state transfer logic (for example, search problems), and the nature of that logic will likely vary by app. In future versions, we hope to support in-library state transfer.

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载