serverServer

The server is where you deploy all of the peers' logic from. The subnet template comes with a base class for building the application logic on top of. The base class exposes the application logic to all of the P2P logic if peers need to access it.

The ServerBase is a class that handles all of the peer discovery and connection logic, enabling developers to build the application-level logic, such as the peers or different roles business logic, how peers score one another, and setting up other communication templates.

Server Base

Application

Application Base

To develop the application logic of the peers or roles, you have to inherit the ApplicationBase class and fill out the required functions.

__init__: Initialize the class with all of your required arguments.

setup: Initialize local logic, such as the telemetry.

start_application: Initialize all of the logic required for the peer to run, such as the GossipSub, DAG, or protocols. Everything the peer requires to do their job.

run:

cleanup: This is a hook to clean up any processes if needed.

class ApplicationBase:
    def __init__(self, *args: object, **kwargs: object) -> None:
        self.args = args
        self.kwargs = kwargs

    async def setup(self, context: P2PNetworkContext) -> None:
        """Called once after host, DHT, and optional pubsub are ready."""

    async def start_application(self, context: P2PNetworkContext) -> None:
        """Called after bootstrap and optional connection maintenance startup."""

    async def run(self, context: P2PNetworkContext) -> None:
        """Block until the app or server should stop."""
        await context.termination_event.wait()

    async def cleanup(self, context: P2PNetworkContext) -> None:
        """Called once while the network context is still available."""

Application

The application class inherits the ApplicationBase class and is filled out.

Server

The server deploys the P2P logic and the application logic.

Last updated