Server & Application
Create Application
Example
class MyApplication(ApplicationBase):
def __init__(
self,
*,
role: "trainer" | "validator",
key_pair: KeyPair,
db: RocksDB,
subnet_id: int,
subnet_node_id: int,
is_bootstrap: bool,
telemetry: Telemetry | None = None,
) -> None:
super().__init__()
self.role= role
self.key_pair = key_pair
self.db = db
self.subnet_id = subnet_id
self.subnet_node_id = subnet_node_id
self.is_bootstrap = is_bootstrap
self.telemetry = telemetry
async def setup(self, context: P2PNetworkContext) -> None:
"""
Called once after the host, DHT, and optional pubsub are ready.
The custom P2P logic should deploy from here, such as the custom P2P
protocols, the API protocol. As well as non-application-based logic,
such as the Network API.
"""
async def start_application(self, context: P2PNetworkContext) -> None:
"""
Called after the bootstrap and optional connection maintenance startup.
Deploy all of the application logic for the peer
"""
async def cleanup(self, context: P2PNetworkContext) -> None:
"""
Called once while the network context is still available.
Cleanup any processes created.
"""Create Server
Example
Last updated