# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401, F403, F405

import builtins
import collections.abc
import os
import pathlib
import typing
__all__ = [
    "LVAggregator",
    "LVPublisher",
    "LVSubscriber",
    "NetworkingHandle",
    "Pidfile",
    "PidfileError",
    "PyFromSwarm",
    "SessionHandle",
    "Storage",
    "StorageGetter",
    "TaskChunkSender",
    "TaskRequest",
    "TaskRequester",
    "TaskResponder",
    "TaskStream",
]

@typing.final
class LVAggregator:
    def dump(self) -> builtins.dict[builtins.str, builtins.str]: ...

@typing.final
class LVPublisher:
    def put(self, data: builtins.str) -> collections.abc.Awaitable[None]: ...

@typing.final
class LVSubscriber:
    def recv(self) -> collections.abc.Awaitable[tuple[str, str] | None]: ...

@typing.final
class NetworkingHandle:
    @staticmethod
    def new(identity: builtins.str, listen_port: builtins.int, discovery_service_port: builtins.int) -> NetworkingHandle: ...
    async def gossipsub_subscribe(self, topic: builtins.str) -> builtins.bool:
        r"""
        Subscribe to a `GossipSub` topic.
        
        Returns `True` if the subscription worked. Returns `False` if we were already subscribed.
        """
    async def gossipsub_unsubscribe(self, topic: builtins.str) -> builtins.bool:
        r"""
        Unsubscribes from a `GossipSub` topic.
        
        Returns `True` if we were subscribed to this topic. Returns `False` if we were not subscribed.
        """
    async def gossipsub_publish(self, topic: builtins.str, data: bytes) -> None:
        r"""
        Publishes a message with multiple topics to the `GossipSub` network.
        
        If no peers are found that subscribe to this topic, throws `NoPeersSubscribedToTopicError` exception.
        """
    async def recv(self) -> PyFromSwarm: ...

@typing.final
class Pidfile:
    r"""
    A PID file protected with a lock.
    
    An instance of `Pidfile` can be used to manage a PID file: create it,
    lock it, detect already running daemons. It is backed by [`pidfile`]
    functions of `libbsd`/`libutil` which use `flopen` to lock the PID
    file.
    
    When a PID file is created, the process ID of the current process is
    *not* written there, making it possible to lock the PID file before
    forking and only write the ID of the forked process when it is ready.
    
    The PID file is deleted automatically when the `Pidfile` comes out of
    the scope. To close the PID file without deleting it, for example, in
    the parent process of a forked daemon, call `close()`.
    
    [`exit`]: https://doc.rust-lang.org/std/process/fn.exit.html
    [`pidfile`]: https://linux.die.net/man/3/pidfile
    [`daemon`(3)]: https://linux.die.net/man/3/daemon
    """
    def __new__(cls, path: builtins.str | os.PathLike | pathlib.Path, mode: builtins.int) -> Pidfile:
        r"""
        Creates a new PID file and locks it.
        Writes the current process ID to the PID file.
        
        If the PID file cannot be locked, returns `PidfileError::AlreadyRunning` with
        a PID of the already running process, or `None` if no PID has been written to
        the PID file yet.
        """
    def write(self) -> None:
        r"""
        Writes the current process ID to the PID file.
        
        The file is truncated before writing.
        """
    def as_raw_fd(self) -> builtins.int:
        r"""
        Extracts the raw file descriptor.
        
        This function is typically used to **borrow** an owned file descriptor.
        When used in this way, this method does **not** pass ownership of the
        raw file descriptor to the caller, and the file descriptor is only
        guaranteed to be valid while the original object has not yet been
        destroyed.
        """
    def close(self) -> None:
        r"""
        Closes the PID file and releases associated resources.
        """

@typing.final
class PidfileError(builtins.Exception):
    def __repr__(self) -> builtins.str: ...
    def __str__(self) -> builtins.str: ...

class PyFromSwarm:
    @typing.final
    class Connection(PyFromSwarm):
        __match_args__ = ("connected",)
        @property
        def connected(self) -> builtins.bool: ...
        def __new__(cls, connected: builtins.bool) -> PyFromSwarm.Connection: ...
    
    @typing.final
    class Message(PyFromSwarm):
        __match_args__ = ("topic", "data",)
        @property
        def topic(self) -> builtins.str: ...
        @property
        def data(self) -> bytes: ...
        def __new__(cls, topic: builtins.str, data: bytes) -> PyFromSwarm.Message: ...
    
    ...

@typing.final
class SessionHandle:
    @staticmethod
    def new(identity: builtins.str, listen_port: builtins.int, discovery_service_port: builtins.int) -> tuple[SessionHandle, NetworkingHandle]: ...
    def last_value_aggregator(self, prefix: builtins.str) -> LVAggregator: ...
    def last_value_subscriber(self, kexpr: builtins.str) -> LVSubscriber: ...
    def last_value_publisher(self, kexpr: builtins.str) -> LVPublisher: ...
    def storage_interface(self) -> Storage: ...
    def task_requester(self) -> TaskRequester: ...
    def task_responder(self, instance_id: builtins.str) -> TaskResponder: ...

@typing.final
class Storage:
    def get(self, key: builtins.str) -> collections.abc.Awaitable[str | None]: ...
    def get_many(self, key: builtins.str) -> StorageGetter: ...
    def put(self, key: builtins.str, data: builtins.str) -> collections.abc.Awaitable[None]: ...
    def delete(self, key: builtins.str) -> collections.abc.Awaitable[None]: ...
    def dump(self, prefix: builtins.str) -> collections.abc.Awaitable[dict[str, str]]: ...

@typing.final
class StorageGetter:
    def recv(self) -> collections.abc.Awaitable[tuple[str, str] | None]: ...

@typing.final
class TaskChunkSender:
    def send(self, chunk: builtins.str) -> collections.abc.Awaitable[None]: ...

@typing.final
class TaskRequest:
    def reply(self, payload: builtins.str) -> None: ...
    def reply_err(self, payload: builtins.str) -> None: ...

@typing.final
class TaskRequester:
    def submit(self, instance_id: builtins.str, command_id: builtins.str, command: builtins.str) -> collections.abc.Awaitable[TaskStream]: ...
    def interrupt(self, instance_id: builtins.str, command_id: builtins.str, command: builtins.str) -> collections.abc.Awaitable[None]: ...

@typing.final
class TaskResponder:
    def assign_task(self, task_id: builtins.str, task: builtins.str) -> collections.abc.Awaitable[None]: ...
    def unassign_task(self, task_id: builtins.str) -> collections.abc.Awaitable[None]: ...
    def recv(self) -> collections.abc.Awaitable[tuple[TaskRequest, TaskChunkSender, str | None] | None]: ...

@typing.final
class TaskStream:
    def recv(self) -> collections.abc.Awaitable[str | None]: ...

