跳转至

base_client

BaseClient(addr, cert_path=None)

Provides methods that implement functionality of base client.

Source code in iflearner/communication/base/base_client.py
def __init__(self, addr: str, cert_path: str = None) -> None:
    options = [
        ("grpc.max_message_length", constant.MAX_MSG_LENGTH),
        ("grpc.max_send_message_length", constant.MAX_MSG_LENGTH),
        ("grpc.max_receive_message_length", constant.MAX_MSG_LENGTH),
    ]

    if cert_path is None:
        channel = grpc.insecure_channel(addr, options=options)
    else:
        with open(cert_path, "rb") as f:
            cert_bytes = f.read()

        channel = grpc.secure_channel(
            addr, grpc.ssl_channel_credentials(cert_bytes), options=options
        )

    self._stub: base_pb2_grpc.BaseStub = base_pb2_grpc.BaseStub(channel)