Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(framework:skip) Set default client and server gRPC addresses #4491

Merged
merged 24 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
from flwr.common import GRPC_MAX_MESSAGE_LENGTH, Context, EventType, Message, event
from flwr.common.address import parse_address
from flwr.common.constant import (
CLIENTAPPIO_API_DEFAULT_ADDRESS,
CLIENT_OCTET,
CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
ISOLATION_MODE_PROCESS,
ISOLATION_MODE_SUBPROCESS,
MISSING_EXTRA_REST,
RUN_ID_NUM_BYTES,
SERVER_OCTET,
TRANSPORT_TYPE_GRPC_ADAPTER,
TRANSPORT_TYPE_GRPC_BIDI,
TRANSPORT_TYPE_GRPC_RERE,
Expand Down Expand Up @@ -216,7 +218,7 @@ def start_client_internal(
max_wait_time: Optional[float] = None,
flwr_path: Optional[Path] = None,
isolation: Optional[str] = None,
clientappio_api_address: Optional[str] = CLIENTAPPIO_API_DEFAULT_ADDRESS,
clientappio_api_address: Optional[str] = CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
certificates: Optional[tuple[bytes, bytes, bytes]] = None,
ssl_ca_certfile: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -279,7 +281,8 @@ class `flwr.client.Client` (default: None)
`clientappio_api_address`. If `process`, the `ClientApp` runs in a separate
isolated process and communicates using gRPC at the address
`clientappio_api_address`.
clientappio_api_address : Optional[str] (default: `CLIENTAPPIO_API_DEFAULT_ADDRESS`)
clientappio_api_address : Optional[str]
(default: `CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS`)
The SuperNode gRPC server address.
certificates : Optional[Tuple[bytes, bytes, bytes]] (default: None)
Tuple containing the CA certificate, server certificate, and server private key.
Expand Down Expand Up @@ -516,11 +519,19 @@ def _on_backoff(retry_state: RetryState) -> None:
)

if start_subprocess:
_octet, _colon, _port = (
clientappio_api_address.rpartition(":")
)
io_address = (
f"{CLIENT_OCTET}:{_port}"
if _octet == SERVER_OCTET
else clientappio_api_address
)
# Start ClientApp subprocess
command = [
"flwr-clientapp",
"--clientappio-api-address",
clientappio_api_address,
io_address,
"--token",
str(token),
]
Expand Down
6 changes: 4 additions & 2 deletions src/py/flwr/client/clientapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from flwr.common import Context, Message
from flwr.common.args import add_args_flwr_app_common, try_obtain_root_certificates
from flwr.common.config import get_flwr_dir
from flwr.common.constant import ErrorCode
from flwr.common.constant import CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS, ErrorCode
from flwr.common.grpc import create_channel
from flwr.common.logger import log
from flwr.common.message import Error
Expand Down Expand Up @@ -61,8 +61,10 @@ def flwr_clientapp() -> None:
)
parser.add_argument(
"--clientappio-api-address",
default=CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS,
type=str,
help="Address of SuperNode's ClientAppIo API",
help="Address of SuperNode's ClientAppIo API (IPv4, IPv6, or a domain name)."
f"By default, it is set to {CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS}.",
)
parser.add_argument(
"--token",
Expand Down
6 changes: 4 additions & 2 deletions src/py/flwr/client/supernode/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)
from flwr.common.config import parse_config_args
from flwr.common.constant import (
CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
FLEET_API_GRPC_RERE_DEFAULT_ADDRESS,
ISOLATION_MODE_PROCESS,
ISOLATION_MODE_SUBPROCESS,
Expand Down Expand Up @@ -179,8 +180,9 @@ def _parse_args_run_supernode() -> argparse.ArgumentParser:
)
parser.add_argument(
"--clientappio-api-address",
default="0.0.0.0:9094",
help="Set the SuperNode gRPC server address. Defaults to `0.0.0.0:9094`.",
default=CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS,
help="ClientAppIo API (gRPC) server address (IPv4, IPv6, or a domain name). "
f"By default, it is set to {CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS}.",
)

return parser
Expand Down
25 changes: 19 additions & 6 deletions src/py/flwr/common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,30 @@
]

# Addresses
# Ports
CLIENTAPPIO_PORT = "9094"
SERVERAPPIO_PORT = "9091"
FLEETAPI_GRPC_RERE_PORT = "9092"
FLEETAPI_PORT = "9095"
EXEC_API_PORT = "9093"
SIMULATIONIO_PORT = "9096"
# Octets
SERVER_OCTET = "0.0.0.0"
CLIENT_OCTET = "127.0.0.1"
# SuperNode
CLIENTAPPIO_API_DEFAULT_ADDRESS = "0.0.0.0:9094"
CLIENTAPPIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{CLIENTAPPIO_PORT}"
CLIENTAPPIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{CLIENTAPPIO_PORT}"
# SuperLink
SERVERAPPIO_API_DEFAULT_ADDRESS = "0.0.0.0:9091"
FLEET_API_GRPC_RERE_DEFAULT_ADDRESS = "0.0.0.0:9092"
SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{SERVERAPPIO_PORT}"
SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{SERVERAPPIO_PORT}"
FLEET_API_GRPC_RERE_DEFAULT_ADDRESS = f"{SERVER_OCTET}:{FLEETAPI_GRPC_RERE_PORT}"
FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS = (
"[::]:8080" # IPv6 to keep start_server compatible
)
FLEET_API_REST_DEFAULT_ADDRESS = "0.0.0.0:9095"
EXEC_API_DEFAULT_ADDRESS = "0.0.0.0:9093"
SIMULATIONIO_API_DEFAULT_ADDRESS = "0.0.0.0:9096"
FLEET_API_REST_DEFAULT_ADDRESS = f"{SERVER_OCTET}:{FLEETAPI_PORT}"
EXEC_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{EXEC_API_PORT}"
SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS = f"{SERVER_OCTET}:{SIMULATIONIO_PORT}"
SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS = f"{CLIENT_OCTET}:{SIMULATIONIO_PORT}"

# Constants for ping
PING_DEFAULT_INTERVAL = 30
Expand Down
29 changes: 19 additions & 10 deletions src/py/flwr/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@
from flwr.common.args import try_obtain_server_certificates
from flwr.common.config import get_flwr_dir, parse_config_args
from flwr.common.constant import (
EXEC_API_DEFAULT_ADDRESS,
CLIENT_OCTET,
EXEC_API_DEFAULT_SERVER_ADDRESS,
FLEET_API_GRPC_BIDI_DEFAULT_ADDRESS,
FLEET_API_GRPC_RERE_DEFAULT_ADDRESS,
FLEET_API_REST_DEFAULT_ADDRESS,
ISOLATION_MODE_PROCESS,
ISOLATION_MODE_SUBPROCESS,
MISSING_EXTRA_REST,
SERVERAPPIO_API_DEFAULT_ADDRESS,
SIMULATIONIO_API_DEFAULT_ADDRESS,
SERVER_OCTET,
SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS,
SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS,
TRANSPORT_TYPE_GRPC_ADAPTER,
TRANSPORT_TYPE_GRPC_RERE,
TRANSPORT_TYPE_REST,
Expand Down Expand Up @@ -367,7 +369,11 @@ def run_superlink() -> None:

if args.isolation == ISOLATION_MODE_SUBPROCESS:

address = simulationio_address if sim_exec else serverappio_address
_octet, _colon, _port = serverappio_address.rpartition(":")
io_address = (
f"{CLIENT_OCTET}:{_port}" if _octet == SERVER_OCTET else serverappio_address
)
address = simulationio_address if sim_exec else io_address
cmd = "flwr-simulation" if sim_exec else "flwr-serverapp"

# Scheduler thread
Expand Down Expand Up @@ -732,8 +738,9 @@ def _add_args_common(parser: argparse.ArgumentParser) -> None:
def _add_args_serverappio_api(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--serverappio-api-address",
help="ServerAppIo API (gRPC) server address (IPv4, IPv6, or a domain name).",
default=SERVERAPPIO_API_DEFAULT_ADDRESS,
default=SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS,
help="ServerAppIo API (gRPC) server address (IPv4, IPv6, or a domain name). "
f"By default, it is set to {SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS}.",
)


Expand Down Expand Up @@ -766,8 +773,9 @@ def _add_args_exec_api(parser: argparse.ArgumentParser) -> None:
"""Add command line arguments for Exec API."""
parser.add_argument(
"--exec-api-address",
help="Exec API server address (IPv4, IPv6, or a domain name)",
default=EXEC_API_DEFAULT_ADDRESS,
help="Exec API server address (IPv4, IPv6, or a domain name) "
f"By default, it is set to {EXEC_API_DEFAULT_SERVER_ADDRESS}.",
default=EXEC_API_DEFAULT_SERVER_ADDRESS,
)
parser.add_argument(
"--executor",
Expand All @@ -791,6 +799,7 @@ def _add_args_exec_api(parser: argparse.ArgumentParser) -> None:
def _add_args_simulationio_api(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--simulationio-api-address",
help="SimulationIo API (gRPC) server address (IPv4, IPv6, or a domain name).",
default=SIMULATIONIO_API_DEFAULT_ADDRESS,
default=SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS,
help="SimulationIo API (gRPC) server address (IPv4, IPv6, or a domain name)."
f"By default, it is set to {SIMULATIONIO_API_DEFAULT_SERVER_ADDRESS}.",
)
4 changes: 2 additions & 2 deletions src/py/flwr/server/driver/grpc_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import grpc

from flwr.common import DEFAULT_TTL, Message, Metadata, RecordSet
from flwr.common.constant import SERVERAPPIO_API_DEFAULT_ADDRESS
from flwr.common.constant import SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS
from flwr.common.grpc import create_channel
from flwr.common.logger import log
from flwr.common.serde import message_from_taskres, message_to_taskins, run_from_proto
Expand Down Expand Up @@ -66,7 +66,7 @@ class GrpcDriver(Driver):

def __init__( # pylint: disable=too-many-arguments
self,
serverappio_service_address: str = SERVERAPPIO_API_DEFAULT_ADDRESS,
serverappio_service_address: str = SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
root_certificates: Optional[bytes] = None,
) -> None:
self._addr = serverappio_service_address
Expand Down
10 changes: 5 additions & 5 deletions src/py/flwr/server/run_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
get_project_config,
get_project_dir,
)
from flwr.common.constant import SERVERAPPIO_API_DEFAULT_ADDRESS
from flwr.common.constant import SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS
from flwr.common.logger import log, update_console_handler, warn_deprecated_feature
from flwr.common.object_ref import load_app
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
Expand Down Expand Up @@ -106,11 +106,11 @@ def run_server_app() -> None:
"app by executing `flwr new` and following the prompt."
)

if args.server != SERVERAPPIO_API_DEFAULT_ADDRESS:
if args.server != SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS:
warn = "Passing flag --server is deprecated. Use --superlink instead."
warn_deprecated_feature(warn)

if args.superlink != SERVERAPPIO_API_DEFAULT_ADDRESS:
if args.superlink != SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS:
# if `--superlink` also passed, then
# warn user that this argument overrides what was passed with `--server`
log(
Expand Down Expand Up @@ -277,12 +277,12 @@ def _parse_args_run_server_app() -> argparse.ArgumentParser:
)
parser.add_argument(
"--server",
default=SERVERAPPIO_API_DEFAULT_ADDRESS,
default=SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS,
help="Server address",
chongshenng marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument(
"--superlink",
chongshenng marked this conversation as resolved.
Show resolved Hide resolved
default=SERVERAPPIO_API_DEFAULT_ADDRESS,
default=SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS,
help="SuperLink ServerAppIo API (gRPC-rere) address "
"(IPv4, IPv6, or a domain name)",
)
Expand Down
10 changes: 8 additions & 2 deletions src/py/flwr/server/serverapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
get_project_config,
get_project_dir,
)
from flwr.common.constant import Status, SubStatus
from flwr.common.constant import (
SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
Status,
SubStatus,
)
from flwr.common.logger import (
log,
mirror_output_to_queue,
Expand Down Expand Up @@ -67,8 +71,10 @@ def flwr_serverapp() -> None:
)
parser.add_argument(
"--serverappio-api-address",
default=SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
type=str,
help="Address of SuperLink's ServerAppIo API",
help="Address of SuperLink's ServerAppIo API (IPv4, IPv6, or a domain name)."
f"By default, it is set to {SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS}.",
)
parser.add_argument(
"--run-once",
Expand Down
4 changes: 2 additions & 2 deletions src/py/flwr/simulation/simulationio_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import grpc

from flwr.common.constant import SIMULATIONIO_API_DEFAULT_ADDRESS
from flwr.common.constant import SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS
from flwr.common.grpc import create_channel
from flwr.common.logger import log
from flwr.proto.simulationio_pb2_grpc import SimulationIoStub # pylint: disable=E0611
Expand All @@ -41,7 +41,7 @@ class SimulationIoConnection:

def __init__( # pylint: disable=too-many-arguments
self,
simulationio_service_address: str = SIMULATIONIO_API_DEFAULT_ADDRESS,
simulationio_service_address: str = SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS,
root_certificates: Optional[bytes] = None,
) -> None:
self._addr = simulationio_service_address
Expand Down
10 changes: 7 additions & 3 deletions src/py/flwr/superexec/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

from flwr.cli.config_utils import get_fab_metadata
from flwr.common import ConfigsRecord, Context, RecordSet
from flwr.common.constant import SERVERAPPIO_API_DEFAULT_ADDRESS, Status, SubStatus
from flwr.common.constant import (
SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
Status,
SubStatus,
)
from flwr.common.logger import log
from flwr.common.typing import Fab, RunStatus, UserConfig
from flwr.server.superlink.ffs import Ffs
Expand All @@ -38,7 +42,7 @@ class DeploymentEngine(Executor):

Parameters
----------
serverappio_api_address: str (default: "0.0.0.0:9091")
serverappio_api_address: str (default: "127.0.0.1:9091")
Address of the SuperLink to connect to.
root_certificates: Optional[str] (default: None)
Specifies the path to the PEM-encoded root certificate file for
Expand All @@ -49,7 +53,7 @@ class DeploymentEngine(Executor):

def __init__(
self,
serverappio_api_address: str = SERVERAPPIO_API_DEFAULT_ADDRESS,
serverappio_api_address: str = SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
root_certificates: Optional[str] = None,
flwr_dir: Optional[str] = None,
) -> None:
Expand Down