# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings

from . import p2p_pb2 as p2p__pb2

GRPC_GENERATED_VERSION = '1.66.2'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

try:
    from grpc._utilities import first_version_is_lower
    _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
except ImportError:
    _version_not_supported = True

if _version_not_supported:
    raise RuntimeError(
        f'The grpc package installed is at version {GRPC_VERSION},'
        + f' but the generated code in p2p_pb2_grpc.py depends on'
        + f' grpcio>={GRPC_GENERATED_VERSION}.'
        + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
        + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
    )


class P2pServiceStub(object):
    """P2P Metadata Service for coordinating NIXL/RDMA transfers between vLLM instances.
    The server stores model metadata keyed by mx_source_id (a hash of SourceIdentity).
    Clients query for existing sources and publish their own metadata.
    """

    def __init__(self, channel):
        """Constructor.

        Args:
            channel: A grpc.Channel.
        """
        self.PublishMetadata = channel.unary_unary(
                '/model_express.p2p.P2pService/PublishMetadata',
                request_serializer=p2p__pb2.PublishMetadataRequest.SerializeToString,
                response_deserializer=p2p__pb2.PublishMetadataResponse.FromString,
                _registered_method=True)
        self.ListSources = channel.unary_unary(
                '/model_express.p2p.P2pService/ListSources',
                request_serializer=p2p__pb2.ListSourcesRequest.SerializeToString,
                response_deserializer=p2p__pb2.ListSourcesResponse.FromString,
                _registered_method=True)
        self.GetMetadata = channel.unary_unary(
                '/model_express.p2p.P2pService/GetMetadata',
                request_serializer=p2p__pb2.GetMetadataRequest.SerializeToString,
                response_deserializer=p2p__pb2.GetMetadataResponse.FromString,
                _registered_method=True)
        self.UpdateStatus = channel.unary_unary(
                '/model_express.p2p.P2pService/UpdateStatus',
                request_serializer=p2p__pb2.UpdateStatusRequest.SerializeToString,
                response_deserializer=p2p__pb2.UpdateStatusResponse.FromString,
                _registered_method=True)


class P2pServiceServicer(object):
    """P2P Metadata Service for coordinating NIXL/RDMA transfers between vLLM instances.
    The server stores model metadata keyed by mx_source_id (a hash of SourceIdentity).
    Clients query for existing sources and publish their own metadata.
    """

    def PublishMetadata(self, request, context):
        """Publish model metadata - called by client after loading model weights
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

    def ListSources(self, request, context):
        """List available source workers - lightweight, no tensor metadata.
        Returns one SourceInstanceRef per worker; clients filter by worker_rank
        to find matching peers and then call GetMetadata for the chosen one.
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

    def GetMetadata(self, request, context):
        """Fetch full tensor metadata for one specific worker (MB-scale).
        Call this after filtering ListSources results by worker_rank.
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

    def UpdateStatus(self, request, context):
        """Update source status - called by source after NIXL registration and warmup
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')


def add_P2pServiceServicer_to_server(servicer, server):
    rpc_method_handlers = {
            'PublishMetadata': grpc.unary_unary_rpc_method_handler(
                    servicer.PublishMetadata,
                    request_deserializer=p2p__pb2.PublishMetadataRequest.FromString,
                    response_serializer=p2p__pb2.PublishMetadataResponse.SerializeToString,
            ),
            'ListSources': grpc.unary_unary_rpc_method_handler(
                    servicer.ListSources,
                    request_deserializer=p2p__pb2.ListSourcesRequest.FromString,
                    response_serializer=p2p__pb2.ListSourcesResponse.SerializeToString,
            ),
            'GetMetadata': grpc.unary_unary_rpc_method_handler(
                    servicer.GetMetadata,
                    request_deserializer=p2p__pb2.GetMetadataRequest.FromString,
                    response_serializer=p2p__pb2.GetMetadataResponse.SerializeToString,
            ),
            'UpdateStatus': grpc.unary_unary_rpc_method_handler(
                    servicer.UpdateStatus,
                    request_deserializer=p2p__pb2.UpdateStatusRequest.FromString,
                    response_serializer=p2p__pb2.UpdateStatusResponse.SerializeToString,
            ),
    }
    generic_handler = grpc.method_handlers_generic_handler(
            'model_express.p2p.P2pService', rpc_method_handlers)
    server.add_generic_rpc_handlers((generic_handler,))
    server.add_registered_method_handlers('model_express.p2p.P2pService', rpc_method_handlers)


 # This class is part of an EXPERIMENTAL API.
class P2pService(object):
    """P2P Metadata Service for coordinating NIXL/RDMA transfers between vLLM instances.
    The server stores model metadata keyed by mx_source_id (a hash of SourceIdentity).
    Clients query for existing sources and publish their own metadata.
    """

    @staticmethod
    def PublishMetadata(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/model_express.p2p.P2pService/PublishMetadata',
            p2p__pb2.PublishMetadataRequest.SerializeToString,
            p2p__pb2.PublishMetadataResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)

    @staticmethod
    def ListSources(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/model_express.p2p.P2pService/ListSources',
            p2p__pb2.ListSourcesRequest.SerializeToString,
            p2p__pb2.ListSourcesResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)

    @staticmethod
    def GetMetadata(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/model_express.p2p.P2pService/GetMetadata',
            p2p__pb2.GetMetadataRequest.SerializeToString,
            p2p__pb2.GetMetadataResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)

    @staticmethod
    def UpdateStatus(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/model_express.p2p.P2pService/UpdateStatus',
            p2p__pb2.UpdateStatusRequest.SerializeToString,
            p2p__pb2.UpdateStatusResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)


class WorkerServiceStub(object):
    """============================================================================
    Worker Service (P2P tensor manifest exchange)
    ============================================================================

    Per-worker gRPC service for direct tensor manifest retrieval.
    Sources start this service when MX_P2P_METADATA=1. Targets call
    GetTensorManifest to fetch tensor descriptors directly from the
    source worker instead of from the central metadata server.
    """

    def __init__(self, channel):
        """Constructor.

        Args:
            channel: A grpc.Channel.
        """
        self.GetTensorManifest = channel.unary_unary(
                '/model_express.p2p.WorkerService/GetTensorManifest',
                request_serializer=p2p__pb2.GetTensorManifestRequest.SerializeToString,
                response_deserializer=p2p__pb2.GetTensorManifestResponse.FromString,
                _registered_method=True)


class WorkerServiceServicer(object):
    """============================================================================
    Worker Service (P2P tensor manifest exchange)
    ============================================================================

    Per-worker gRPC service for direct tensor manifest retrieval.
    Sources start this service when MX_P2P_METADATA=1. Targets call
    GetTensorManifest to fetch tensor descriptors directly from the
    source worker instead of from the central metadata server.
    """

    def GetTensorManifest(self, request, context):
        """Missing associated documentation comment in .proto file."""
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')


def add_WorkerServiceServicer_to_server(servicer, server):
    rpc_method_handlers = {
            'GetTensorManifest': grpc.unary_unary_rpc_method_handler(
                    servicer.GetTensorManifest,
                    request_deserializer=p2p__pb2.GetTensorManifestRequest.FromString,
                    response_serializer=p2p__pb2.GetTensorManifestResponse.SerializeToString,
            ),
    }
    generic_handler = grpc.method_handlers_generic_handler(
            'model_express.p2p.WorkerService', rpc_method_handlers)
    server.add_generic_rpc_handlers((generic_handler,))
    server.add_registered_method_handlers('model_express.p2p.WorkerService', rpc_method_handlers)


 # This class is part of an EXPERIMENTAL API.
class WorkerService(object):
    """============================================================================
    Worker Service (P2P tensor manifest exchange)
    ============================================================================

    Per-worker gRPC service for direct tensor manifest retrieval.
    Sources start this service when MX_P2P_METADATA=1. Targets call
    GetTensorManifest to fetch tensor descriptors directly from the
    source worker instead of from the central metadata server.
    """

    @staticmethod
    def GetTensorManifest(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/model_express.p2p.WorkerService/GetTensorManifest',
            p2p__pb2.GetTensorManifestRequest.SerializeToString,
            p2p__pb2.GetTensorManifestResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)
