flwr-nightly 1.15.0.dev20250104__py3-none-any.whl → 1.15.0.dev20250123__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flwr/cli/cli_user_auth_interceptor.py +6 -2
- flwr/cli/config_utils.py +23 -146
- flwr/cli/constant.py +27 -0
- flwr/cli/install.py +1 -1
- flwr/cli/log.py +17 -2
- flwr/cli/login/login.py +20 -5
- flwr/cli/ls.py +10 -2
- flwr/cli/run/run.py +20 -10
- flwr/cli/stop.py +9 -1
- flwr/cli/utils.py +4 -4
- flwr/client/app.py +36 -48
- flwr/client/clientapp/app.py +4 -6
- flwr/client/clientapp/utils.py +1 -1
- flwr/client/grpc_client/connection.py +0 -6
- flwr/client/grpc_rere_client/client_interceptor.py +19 -119
- flwr/client/grpc_rere_client/connection.py +34 -24
- flwr/client/grpc_rere_client/grpc_adapter.py +16 -0
- flwr/client/rest_client/connection.py +34 -26
- flwr/client/supernode/app.py +14 -20
- flwr/common/auth_plugin/auth_plugin.py +34 -23
- flwr/common/config.py +152 -15
- flwr/common/constant.py +11 -8
- flwr/common/exit/__init__.py +24 -0
- flwr/common/exit/exit.py +99 -0
- flwr/common/exit/exit_code.py +93 -0
- flwr/common/exit_handlers.py +24 -10
- flwr/common/grpc.py +161 -3
- flwr/common/logger.py +1 -1
- flwr/common/secure_aggregation/crypto/symmetric_encryption.py +45 -0
- flwr/common/serde.py +6 -4
- flwr/common/typing.py +20 -0
- flwr/proto/clientappio_pb2.py +13 -3
- flwr/proto/clientappio_pb2_grpc.py +63 -12
- flwr/proto/error_pb2.py +13 -3
- flwr/proto/error_pb2_grpc.py +20 -0
- flwr/proto/exec_pb2.py +27 -29
- flwr/proto/exec_pb2.pyi +27 -54
- flwr/proto/exec_pb2_grpc.py +105 -24
- flwr/proto/fab_pb2.py +13 -3
- flwr/proto/fab_pb2_grpc.py +20 -0
- flwr/proto/fleet_pb2.py +54 -31
- flwr/proto/fleet_pb2.pyi +84 -0
- flwr/proto/fleet_pb2_grpc.py +207 -28
- flwr/proto/fleet_pb2_grpc.pyi +26 -0
- flwr/proto/grpcadapter_pb2.py +14 -4
- flwr/proto/grpcadapter_pb2_grpc.py +35 -4
- flwr/proto/log_pb2.py +13 -3
- flwr/proto/log_pb2_grpc.py +20 -0
- flwr/proto/message_pb2.py +15 -5
- flwr/proto/message_pb2_grpc.py +20 -0
- flwr/proto/node_pb2.py +15 -5
- flwr/proto/node_pb2.pyi +1 -4
- flwr/proto/node_pb2_grpc.py +20 -0
- flwr/proto/recordset_pb2.py +18 -8
- flwr/proto/recordset_pb2_grpc.py +20 -0
- flwr/proto/run_pb2.py +16 -6
- flwr/proto/run_pb2_grpc.py +20 -0
- flwr/proto/serverappio_pb2.py +32 -14
- flwr/proto/serverappio_pb2.pyi +56 -0
- flwr/proto/serverappio_pb2_grpc.py +261 -44
- flwr/proto/serverappio_pb2_grpc.pyi +20 -0
- flwr/proto/simulationio_pb2.py +13 -3
- flwr/proto/simulationio_pb2_grpc.py +105 -24
- flwr/proto/task_pb2.py +13 -3
- flwr/proto/task_pb2_grpc.py +20 -0
- flwr/proto/transport_pb2.py +20 -10
- flwr/proto/transport_pb2_grpc.py +35 -4
- flwr/server/app.py +87 -38
- flwr/server/compat/app_utils.py +0 -1
- flwr/server/compat/driver_client_proxy.py +1 -2
- flwr/server/driver/grpc_driver.py +5 -2
- flwr/server/driver/inmemory_driver.py +2 -1
- flwr/server/serverapp/app.py +5 -6
- flwr/server/superlink/driver/serverappio_grpc.py +1 -1
- flwr/server/superlink/driver/serverappio_servicer.py +132 -14
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +20 -88
- flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +2 -165
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +38 -0
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +95 -168
- flwr/server/superlink/fleet/message_handler/message_handler.py +66 -5
- flwr/server/superlink/fleet/rest_rere/rest_api.py +28 -3
- flwr/server/superlink/fleet/vce/vce_api.py +2 -2
- flwr/server/superlink/linkstate/in_memory_linkstate.py +40 -48
- flwr/server/superlink/linkstate/linkstate.py +15 -22
- flwr/server/superlink/linkstate/sqlite_linkstate.py +80 -99
- flwr/server/superlink/linkstate/utils.py +18 -8
- flwr/server/superlink/simulation/simulationio_grpc.py +1 -1
- flwr/server/utils/validator.py +9 -34
- flwr/simulation/app.py +4 -6
- flwr/simulation/legacy_app.py +4 -2
- flwr/simulation/run_simulation.py +1 -1
- flwr/superexec/exec_grpc.py +1 -1
- flwr/superexec/exec_servicer.py +23 -2
- {flwr_nightly-1.15.0.dev20250104.dist-info → flwr_nightly-1.15.0.dev20250123.dist-info}/METADATA +7 -7
- {flwr_nightly-1.15.0.dev20250104.dist-info → flwr_nightly-1.15.0.dev20250123.dist-info}/RECORD +98 -94
- {flwr_nightly-1.15.0.dev20250104.dist-info → flwr_nightly-1.15.0.dev20250123.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.15.0.dev20250104.dist-info → flwr_nightly-1.15.0.dev20250123.dist-info}/WHEEL +0 -0
- {flwr_nightly-1.15.0.dev20250104.dist-info → flwr_nightly-1.15.0.dev20250123.dist-info}/entry_points.txt +0 -0
flwr/common/exit/exit.py
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright 2025 Flower Labs GmbH. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
"""Unified exit function."""
|
16
|
+
|
17
|
+
|
18
|
+
from __future__ import annotations
|
19
|
+
|
20
|
+
import sys
|
21
|
+
from logging import ERROR, INFO
|
22
|
+
from typing import Any, NoReturn
|
23
|
+
|
24
|
+
from flwr.common import EventType, event
|
25
|
+
|
26
|
+
from ..logger import log
|
27
|
+
from .exit_code import EXIT_CODE_HELP
|
28
|
+
|
29
|
+
HELP_PAGE_URL = "https://flower.ai/docs/framework/ref-exit-codes/"
|
30
|
+
|
31
|
+
|
32
|
+
def flwr_exit(
|
33
|
+
code: int,
|
34
|
+
message: str | None = None,
|
35
|
+
event_type: EventType | None = None,
|
36
|
+
event_details: dict[str, Any] | None = None,
|
37
|
+
) -> NoReturn:
|
38
|
+
"""Handle application exit with an optional message.
|
39
|
+
|
40
|
+
The exit message logged and displayed will follow this structure:
|
41
|
+
|
42
|
+
>>> Exit Code: <code>
|
43
|
+
>>> <message>
|
44
|
+
>>> <short-help-message>
|
45
|
+
>>>
|
46
|
+
>>> For more information, visit: <help-page-url>
|
47
|
+
|
48
|
+
- `<code>`: The unique exit code representing the termination reason.
|
49
|
+
- `<message>`: Optional context or additional information about the exit.
|
50
|
+
- `<short-help-message>`: A brief explanation for the given exit code.
|
51
|
+
- `<help-page-url>`: A URL providing detailed documentation and resolution steps.
|
52
|
+
"""
|
53
|
+
is_error = not 0 <= code < 100 # 0-99 are success exit codes
|
54
|
+
|
55
|
+
# Construct exit message
|
56
|
+
exit_message = f"Exit Code: {code}\n" if is_error else ""
|
57
|
+
exit_message += message or ""
|
58
|
+
if short_help_message := EXIT_CODE_HELP.get(code, ""):
|
59
|
+
exit_message += f"\n{short_help_message}"
|
60
|
+
|
61
|
+
# Set log level and system exit code
|
62
|
+
log_level = ERROR if is_error else INFO
|
63
|
+
sys_exit_code = 1 if is_error else 0
|
64
|
+
|
65
|
+
# Add help URL for non-successful/graceful exits
|
66
|
+
if is_error:
|
67
|
+
help_url = f"{HELP_PAGE_URL}{code}.html"
|
68
|
+
exit_message += f"\n\nFor more information, visit: <{help_url}>"
|
69
|
+
|
70
|
+
# Telemetry event
|
71
|
+
event_type = event_type or _try_obtain_telemetry_event()
|
72
|
+
if event_type:
|
73
|
+
event_details = event_details or {}
|
74
|
+
event_details["exit_code"] = code
|
75
|
+
event(event_type, event_details).result()
|
76
|
+
|
77
|
+
# Log the exit message
|
78
|
+
log(log_level, exit_message)
|
79
|
+
|
80
|
+
# Exit
|
81
|
+
sys.exit(sys_exit_code)
|
82
|
+
|
83
|
+
|
84
|
+
# pylint: disable-next=too-many-return-statements
|
85
|
+
def _try_obtain_telemetry_event() -> EventType | None:
|
86
|
+
"""Try to obtain a telemetry event."""
|
87
|
+
if sys.argv[0].endswith("flower-superlink"):
|
88
|
+
return EventType.RUN_SUPERLINK_LEAVE
|
89
|
+
if sys.argv[0].endswith("flower-supernode"):
|
90
|
+
return EventType.RUN_SUPERNODE_LEAVE
|
91
|
+
if sys.argv[0].endswith("flwr-serverapp"):
|
92
|
+
return EventType.FLWR_SERVERAPP_RUN_LEAVE
|
93
|
+
if sys.argv[0].endswith("flwr-clientapp"):
|
94
|
+
return None # Not yet implemented
|
95
|
+
if sys.argv[0].endswith("flwr-simulation"):
|
96
|
+
return EventType.FLWR_SIMULATION_RUN_LEAVE
|
97
|
+
if sys.argv[0].endswith("flower-simulation"):
|
98
|
+
return EventType.CLI_FLOWER_SIMULATION_LEAVE
|
99
|
+
return None
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# Copyright 2025 Flower Labs GmbH. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
"""Exit codes."""
|
16
|
+
|
17
|
+
|
18
|
+
from __future__ import annotations
|
19
|
+
|
20
|
+
|
21
|
+
class ExitCode:
|
22
|
+
"""Exit codes for Flower components."""
|
23
|
+
|
24
|
+
# Success exit codes (0-99)
|
25
|
+
SUCCESS = 0 # Successful exit without any errors or signals
|
26
|
+
GRACEFUL_EXIT_SIGINT = 1 # Graceful exit triggered by SIGINT
|
27
|
+
GRACEFUL_EXIT_SIGQUIT = 2 # Graceful exit triggered by SIGQUIT
|
28
|
+
GRACEFUL_EXIT_SIGTERM = 3 # Graceful exit triggered by SIGTERM
|
29
|
+
|
30
|
+
# SuperLink-specific exit codes (100-199)
|
31
|
+
SUPERLINK_THREAD_CRASH = 100
|
32
|
+
|
33
|
+
# ServerApp-specific exit codes (200-299)
|
34
|
+
|
35
|
+
# SuperNode-specific exit codes (300-399)
|
36
|
+
SUPERNODE_REST_ADDRESS_INVALID = 300
|
37
|
+
SUPERNODE_NODE_AUTH_KEYS_REQUIRED = 301
|
38
|
+
SUPERNODE_NODE_AUTH_KEYS_INVALID = 302
|
39
|
+
|
40
|
+
# ClientApp-specific exit codes (400-499)
|
41
|
+
|
42
|
+
# Simulation-specific exit codes (500-599)
|
43
|
+
|
44
|
+
# Common exit codes (600-)
|
45
|
+
COMMON_ADDRESS_INVALID = 600
|
46
|
+
COMMON_MISSING_EXTRA_REST = 601
|
47
|
+
COMMON_TLS_NOT_SUPPORTED = 602
|
48
|
+
|
49
|
+
def __new__(cls) -> ExitCode:
|
50
|
+
"""Prevent instantiation."""
|
51
|
+
raise TypeError(f"{cls.__name__} cannot be instantiated.")
|
52
|
+
|
53
|
+
|
54
|
+
# All short help messages for exit codes
|
55
|
+
EXIT_CODE_HELP = {
|
56
|
+
# Success exit codes (0-99)
|
57
|
+
ExitCode.SUCCESS: "",
|
58
|
+
ExitCode.GRACEFUL_EXIT_SIGINT: "",
|
59
|
+
ExitCode.GRACEFUL_EXIT_SIGQUIT: "",
|
60
|
+
ExitCode.GRACEFUL_EXIT_SIGTERM: "",
|
61
|
+
# SuperLink-specific exit codes (100-199)
|
62
|
+
ExitCode.SUPERLINK_THREAD_CRASH: "An important background thread has crashed.",
|
63
|
+
# ServerApp-specific exit codes (200-299)
|
64
|
+
# SuperNode-specific exit codes (300-399)
|
65
|
+
ExitCode.SUPERNODE_REST_ADDRESS_INVALID: (
|
66
|
+
"When using the REST API, please provide `https://` or "
|
67
|
+
"`http://` before the server address (e.g. `http://127.0.0.1:8080`)"
|
68
|
+
),
|
69
|
+
ExitCode.SUPERNODE_NODE_AUTH_KEYS_REQUIRED: (
|
70
|
+
"Node authentication requires file paths to both "
|
71
|
+
"'--auth-supernode-private-key' and '--auth-supernode-public-key' "
|
72
|
+
"to be provided (providing only one of them is not sufficient)."
|
73
|
+
),
|
74
|
+
ExitCode.SUPERNODE_NODE_AUTH_KEYS_INVALID: (
|
75
|
+
"Node uthentication requires elliptic curve private and public key pair. "
|
76
|
+
"Please ensure that the file path points to a valid private/public key "
|
77
|
+
"file and try again."
|
78
|
+
),
|
79
|
+
# ClientApp-specific exit codes (400-499)
|
80
|
+
# Simulation-specific exit codes (500-599)
|
81
|
+
# Common exit codes (600-)
|
82
|
+
ExitCode.COMMON_ADDRESS_INVALID: (
|
83
|
+
"Please provide a valid URL, IPv4 or IPv6 address."
|
84
|
+
),
|
85
|
+
ExitCode.COMMON_MISSING_EXTRA_REST: """
|
86
|
+
Extra dependencies required for using the REST-based Fleet API are missing.
|
87
|
+
|
88
|
+
To use the REST API, install `flwr` with the `rest` extra:
|
89
|
+
|
90
|
+
`pip install "flwr[rest]"`.
|
91
|
+
""",
|
92
|
+
ExitCode.COMMON_TLS_NOT_SUPPORTED: "Please use the '--insecure' flag.",
|
93
|
+
}
|
flwr/common/exit_handlers.py
CHANGED
@@ -15,28 +15,38 @@
|
|
15
15
|
"""Common function to register exit handlers for server and client."""
|
16
16
|
|
17
17
|
|
18
|
-
import
|
19
|
-
from signal import SIGINT, SIGTERM, signal
|
18
|
+
from signal import SIGINT, SIGQUIT, SIGTERM, signal
|
20
19
|
from threading import Thread
|
21
20
|
from types import FrameType
|
22
21
|
from typing import Optional
|
23
22
|
|
24
23
|
from grpc import Server
|
25
24
|
|
26
|
-
from flwr.common.telemetry import EventType
|
25
|
+
from flwr.common.telemetry import EventType
|
26
|
+
|
27
|
+
from .exit import ExitCode, flwr_exit
|
28
|
+
|
29
|
+
SIGNAL_TO_EXIT_CODE = {
|
30
|
+
SIGINT: ExitCode.GRACEFUL_EXIT_SIGINT,
|
31
|
+
SIGQUIT: ExitCode.GRACEFUL_EXIT_SIGQUIT,
|
32
|
+
SIGTERM: ExitCode.GRACEFUL_EXIT_SIGTERM,
|
33
|
+
}
|
27
34
|
|
28
35
|
|
29
36
|
def register_exit_handlers(
|
30
37
|
event_type: EventType,
|
38
|
+
exit_message: Optional[str] = None,
|
31
39
|
grpc_servers: Optional[list[Server]] = None,
|
32
40
|
bckg_threads: Optional[list[Thread]] = None,
|
33
41
|
) -> None:
|
34
|
-
"""Register exit handlers for `SIGINT` and `
|
42
|
+
"""Register exit handlers for `SIGINT`, `SIGTERM` and `SIGQUIT` signals.
|
35
43
|
|
36
44
|
Parameters
|
37
45
|
----------
|
38
46
|
event_type : EventType
|
39
47
|
The telemetry event that should be logged before exit.
|
48
|
+
exit_message : Optional[str] (default: None)
|
49
|
+
The message to be logged before exiting.
|
40
50
|
grpc_servers: Optional[List[Server]] (default: None)
|
41
51
|
An otpional list of gRPC servers that need to be gracefully
|
42
52
|
terminated before exiting.
|
@@ -46,6 +56,7 @@ def register_exit_handlers(
|
|
46
56
|
"""
|
47
57
|
default_handlers = {
|
48
58
|
SIGINT: None,
|
59
|
+
SIGQUIT: None,
|
49
60
|
SIGTERM: None,
|
50
61
|
}
|
51
62
|
|
@@ -61,8 +72,6 @@ def register_exit_handlers(
|
|
61
72
|
# Reset to default handler
|
62
73
|
signal(signalnum, default_handlers[signalnum])
|
63
74
|
|
64
|
-
event_res = event(event_type=event_type)
|
65
|
-
|
66
75
|
if grpc_servers is not None:
|
67
76
|
for grpc_server in grpc_servers:
|
68
77
|
grpc_server.stop(grace=1)
|
@@ -71,16 +80,21 @@ def register_exit_handlers(
|
|
71
80
|
for bckg_thread in bckg_threads:
|
72
81
|
bckg_thread.join()
|
73
82
|
|
74
|
-
# Ensure event has happend
|
75
|
-
event_res.result()
|
76
|
-
|
77
83
|
# Setup things for graceful exit
|
78
|
-
|
84
|
+
flwr_exit(
|
85
|
+
code=SIGNAL_TO_EXIT_CODE[signalnum],
|
86
|
+
message=exit_message,
|
87
|
+
event_type=event_type,
|
88
|
+
)
|
79
89
|
|
80
90
|
default_handlers[SIGINT] = signal( # type: ignore
|
81
91
|
SIGINT,
|
82
92
|
graceful_exit_handler, # type: ignore
|
83
93
|
)
|
94
|
+
default_handlers[SIGQUIT] = signal( # type: ignore
|
95
|
+
SIGQUIT,
|
96
|
+
graceful_exit_handler, # type: ignore
|
97
|
+
)
|
84
98
|
default_handlers[SIGTERM] = signal( # type: ignore
|
85
99
|
SIGTERM,
|
86
100
|
graceful_exit_handler, # type: ignore
|
flwr/common/grpc.py
CHANGED
@@ -15,16 +15,33 @@
|
|
15
15
|
"""Utility functions for gRPC."""
|
16
16
|
|
17
17
|
|
18
|
+
import concurrent.futures
|
19
|
+
import os
|
20
|
+
import sys
|
18
21
|
from collections.abc import Sequence
|
19
|
-
from logging import DEBUG
|
20
|
-
from typing import Optional
|
22
|
+
from logging import DEBUG, ERROR
|
23
|
+
from typing import Any, Callable, Optional
|
21
24
|
|
22
25
|
import grpc
|
23
26
|
|
24
|
-
from
|
27
|
+
from .address import is_port_in_use
|
28
|
+
from .logger import log
|
25
29
|
|
26
30
|
GRPC_MAX_MESSAGE_LENGTH: int = 536_870_912 # == 512 * 1024 * 1024
|
27
31
|
|
32
|
+
INVALID_CERTIFICATES_ERR_MSG = """
|
33
|
+
When setting any of root_certificate, certificate, or private_key,
|
34
|
+
all of them need to be set.
|
35
|
+
"""
|
36
|
+
|
37
|
+
AddServicerToServerFn = Callable[..., Any]
|
38
|
+
|
39
|
+
if "GRPC_VERBOSITY" not in os.environ:
|
40
|
+
os.environ["GRPC_VERBOSITY"] = "error"
|
41
|
+
# The following flags can be uncommented for debugging. Other possible values:
|
42
|
+
# https://github.com/grpc/grpc/blob/master/doc/environment_variables.md
|
43
|
+
# os.environ["GRPC_TRACE"] = "tcp,http"
|
44
|
+
|
28
45
|
|
29
46
|
def create_channel(
|
30
47
|
server_address: str,
|
@@ -66,3 +83,144 @@ def create_channel(
|
|
66
83
|
channel = grpc.intercept_channel(channel, interceptors)
|
67
84
|
|
68
85
|
return channel
|
86
|
+
|
87
|
+
|
88
|
+
def valid_certificates(certificates: tuple[bytes, bytes, bytes]) -> bool:
|
89
|
+
"""Validate certificates tuple."""
|
90
|
+
is_valid = (
|
91
|
+
all(isinstance(certificate, bytes) for certificate in certificates)
|
92
|
+
and len(certificates) == 3
|
93
|
+
)
|
94
|
+
|
95
|
+
if not is_valid:
|
96
|
+
log(ERROR, INVALID_CERTIFICATES_ERR_MSG)
|
97
|
+
|
98
|
+
return is_valid
|
99
|
+
|
100
|
+
|
101
|
+
def generic_create_grpc_server( # pylint: disable=too-many-arguments,R0917
|
102
|
+
servicer_and_add_fn: tuple[Any, AddServicerToServerFn],
|
103
|
+
server_address: str,
|
104
|
+
max_concurrent_workers: int = 1000,
|
105
|
+
max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
|
106
|
+
keepalive_time_ms: int = 210000,
|
107
|
+
certificates: Optional[tuple[bytes, bytes, bytes]] = None,
|
108
|
+
interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None,
|
109
|
+
) -> grpc.Server:
|
110
|
+
"""Create a gRPC server with a single servicer.
|
111
|
+
|
112
|
+
Parameters
|
113
|
+
----------
|
114
|
+
servicer_and_add_fn : tuple
|
115
|
+
A tuple holding a servicer implementation and a matching
|
116
|
+
add_Servicer_to_server function.
|
117
|
+
server_address : str
|
118
|
+
Server address in the form of HOST:PORT e.g. "[::]:8080"
|
119
|
+
max_concurrent_workers : int
|
120
|
+
Maximum number of clients the server can process before returning
|
121
|
+
RESOURCE_EXHAUSTED status (default: 1000)
|
122
|
+
max_message_length : int
|
123
|
+
Maximum message length that the server can send or receive.
|
124
|
+
Int valued in bytes. -1 means unlimited. (default: GRPC_MAX_MESSAGE_LENGTH)
|
125
|
+
keepalive_time_ms : int
|
126
|
+
Flower uses a default gRPC keepalive time of 210000ms (3 minutes 30 seconds)
|
127
|
+
because some cloud providers (for example, Azure) agressively clean up idle
|
128
|
+
TCP connections by terminating them after some time (4 minutes in the case
|
129
|
+
of Azure). Flower does not use application-level keepalive signals and relies
|
130
|
+
on the assumption that the transport layer will fail in cases where the
|
131
|
+
connection is no longer active. `keepalive_time_ms` can be used to customize
|
132
|
+
the keepalive interval for specific environments. The default Flower gRPC
|
133
|
+
keepalive of 210000 ms (3 minutes 30 seconds) ensures that Flower can keep
|
134
|
+
the long running streaming connection alive in most environments. The actual
|
135
|
+
gRPC default of this setting is 7200000 (2 hours), which results in dropped
|
136
|
+
connections in some cloud environments.
|
137
|
+
|
138
|
+
These settings are related to the issue described here:
|
139
|
+
- https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md
|
140
|
+
- https://github.com/grpc/grpc/blob/master/doc/keepalive.md
|
141
|
+
- https://grpc.io/docs/guides/performance/
|
142
|
+
|
143
|
+
Mobile Flower clients may choose to increase this value if their server
|
144
|
+
environment allows long-running idle TCP connections.
|
145
|
+
(default: 210000)
|
146
|
+
certificates : Tuple[bytes, bytes, bytes] (default: None)
|
147
|
+
Tuple containing root certificate, server certificate, and private key to
|
148
|
+
start a secure SSL-enabled server. The tuple is expected to have three bytes
|
149
|
+
elements in the following order:
|
150
|
+
|
151
|
+
* CA certificate.
|
152
|
+
* server certificate.
|
153
|
+
* server private key.
|
154
|
+
interceptors : Optional[Sequence[grpc.ServerInterceptor]] (default: None)
|
155
|
+
A list of gRPC interceptors.
|
156
|
+
|
157
|
+
Returns
|
158
|
+
-------
|
159
|
+
server : grpc.Server
|
160
|
+
A non-running instance of a gRPC server.
|
161
|
+
"""
|
162
|
+
# Check if port is in use
|
163
|
+
if is_port_in_use(server_address):
|
164
|
+
sys.exit(f"Port in server address {server_address} is already in use.")
|
165
|
+
|
166
|
+
# Deconstruct tuple into servicer and function
|
167
|
+
servicer, add_servicer_to_server_fn = servicer_and_add_fn
|
168
|
+
|
169
|
+
# Possible options:
|
170
|
+
# https://github.com/grpc/grpc/blob/v1.43.x/include/grpc/impl/codegen/grpc_types.h
|
171
|
+
options = [
|
172
|
+
# Maximum number of concurrent incoming streams to allow on a http2
|
173
|
+
# connection. Int valued.
|
174
|
+
("grpc.max_concurrent_streams", max(100, max_concurrent_workers)),
|
175
|
+
# Maximum message length that the channel can send.
|
176
|
+
# Int valued, bytes. -1 means unlimited.
|
177
|
+
("grpc.max_send_message_length", max_message_length),
|
178
|
+
# Maximum message length that the channel can receive.
|
179
|
+
# Int valued, bytes. -1 means unlimited.
|
180
|
+
("grpc.max_receive_message_length", max_message_length),
|
181
|
+
# The gRPC default for this setting is 7200000 (2 hours). Flower uses a
|
182
|
+
# customized default of 210000 (3 minutes and 30 seconds) to improve
|
183
|
+
# compatibility with popular cloud providers. Mobile Flower clients may
|
184
|
+
# choose to increase this value if their server environment allows
|
185
|
+
# long-running idle TCP connections.
|
186
|
+
("grpc.keepalive_time_ms", keepalive_time_ms),
|
187
|
+
# Setting this to zero will allow sending unlimited keepalive pings in between
|
188
|
+
# sending actual data frames.
|
189
|
+
("grpc.http2.max_pings_without_data", 0),
|
190
|
+
# Is it permissible to send keepalive pings from the client without
|
191
|
+
# any outstanding streams. More explanation here:
|
192
|
+
# https://github.com/adap/flower/pull/2197
|
193
|
+
("grpc.keepalive_permit_without_calls", 0),
|
194
|
+
]
|
195
|
+
|
196
|
+
server = grpc.server(
|
197
|
+
concurrent.futures.ThreadPoolExecutor(max_workers=max_concurrent_workers),
|
198
|
+
# Set the maximum number of concurrent RPCs this server will service before
|
199
|
+
# returning RESOURCE_EXHAUSTED status, or None to indicate no limit.
|
200
|
+
maximum_concurrent_rpcs=max_concurrent_workers,
|
201
|
+
options=options,
|
202
|
+
interceptors=interceptors,
|
203
|
+
)
|
204
|
+
add_servicer_to_server_fn(servicer, server)
|
205
|
+
|
206
|
+
if certificates is not None:
|
207
|
+
if not valid_certificates(certificates):
|
208
|
+
sys.exit(1)
|
209
|
+
|
210
|
+
root_certificate_b, certificate_b, private_key_b = certificates
|
211
|
+
|
212
|
+
server_credentials = grpc.ssl_server_credentials(
|
213
|
+
((private_key_b, certificate_b),),
|
214
|
+
root_certificates=root_certificate_b,
|
215
|
+
# A boolean indicating whether or not to require clients to be
|
216
|
+
# authenticated. May only be True if root_certificates is not None.
|
217
|
+
# We are explicitly setting the current gRPC default to document
|
218
|
+
# the option. For further reference see:
|
219
|
+
# https://grpc.github.io/grpc/python/grpc.html#create-server-credentials
|
220
|
+
require_client_auth=False,
|
221
|
+
)
|
222
|
+
server.add_secure_port(server_address, server_credentials)
|
223
|
+
else:
|
224
|
+
server.add_insecure_port(server_address)
|
225
|
+
|
226
|
+
return server
|
flwr/common/logger.py
CHANGED
@@ -320,7 +320,7 @@ def _log_uploader(
|
|
320
320
|
) -> None:
|
321
321
|
"""Upload logs to the SuperLink."""
|
322
322
|
exit_flag = False
|
323
|
-
node = Node(node_id=node_id
|
323
|
+
node = Node(node_id=node_id)
|
324
324
|
msgs: list[str] = []
|
325
325
|
while True:
|
326
326
|
# Fetch all messages from the queue
|
@@ -117,3 +117,48 @@ def verify_hmac(key: bytes, message: bytes, hmac_value: bytes) -> bool:
|
|
117
117
|
return True
|
118
118
|
except InvalidSignature:
|
119
119
|
return False
|
120
|
+
|
121
|
+
|
122
|
+
def sign_message(private_key: ec.EllipticCurvePrivateKey, message: bytes) -> bytes:
|
123
|
+
"""Sign a message using the provided EC private key.
|
124
|
+
|
125
|
+
Parameters
|
126
|
+
----------
|
127
|
+
private_key : ec.EllipticCurvePrivateKey
|
128
|
+
The EC private key to sign the message with.
|
129
|
+
message : bytes
|
130
|
+
The message to be signed.
|
131
|
+
|
132
|
+
Returns
|
133
|
+
-------
|
134
|
+
bytes
|
135
|
+
The signature of the message.
|
136
|
+
"""
|
137
|
+
signature = private_key.sign(message, ec.ECDSA(hashes.SHA256()))
|
138
|
+
return signature
|
139
|
+
|
140
|
+
|
141
|
+
def verify_signature(
|
142
|
+
public_key: ec.EllipticCurvePublicKey, message: bytes, signature: bytes
|
143
|
+
) -> bool:
|
144
|
+
"""Verify a signature against a message using the provided EC public key.
|
145
|
+
|
146
|
+
Parameters
|
147
|
+
----------
|
148
|
+
public_key : ec.EllipticCurvePublicKey
|
149
|
+
The EC public key to verify the signature.
|
150
|
+
message : bytes
|
151
|
+
The original message.
|
152
|
+
signature : bytes
|
153
|
+
The signature to verify.
|
154
|
+
|
155
|
+
Returns
|
156
|
+
-------
|
157
|
+
bool
|
158
|
+
True if the signature is valid, False otherwise.
|
159
|
+
"""
|
160
|
+
try:
|
161
|
+
public_key.verify(signature, message, ec.ECDSA(hashes.SHA256()))
|
162
|
+
return True
|
163
|
+
except InvalidSignature:
|
164
|
+
return False
|
flwr/common/serde.py
CHANGED
@@ -21,6 +21,8 @@ from typing import Any, TypeVar, cast
|
|
21
21
|
|
22
22
|
from google.protobuf.message import Message as GrpcMessage
|
23
23
|
|
24
|
+
from flwr.common.constant import SUPERLINK_NODE_ID
|
25
|
+
|
24
26
|
# pylint: disable=E0611
|
25
27
|
from flwr.proto.clientappio_pb2 import ClientAppOutputCode, ClientAppOutputStatus
|
26
28
|
from flwr.proto.error_pb2 import Error as ProtoError
|
@@ -605,8 +607,8 @@ def message_to_taskins(message: Message) -> TaskIns:
|
|
605
607
|
group_id=md.group_id,
|
606
608
|
run_id=md.run_id,
|
607
609
|
task=Task(
|
608
|
-
producer=Node(node_id=
|
609
|
-
consumer=Node(node_id=md.dst_node_id
|
610
|
+
producer=Node(node_id=SUPERLINK_NODE_ID), # Assume driver node
|
611
|
+
consumer=Node(node_id=md.dst_node_id),
|
610
612
|
created_at=md.created_at,
|
611
613
|
ttl=md.ttl,
|
612
614
|
ancestry=[md.reply_to_message] if md.reply_to_message != "" else [],
|
@@ -659,8 +661,8 @@ def message_to_taskres(message: Message) -> TaskRes:
|
|
659
661
|
group_id=md.group_id,
|
660
662
|
run_id=md.run_id,
|
661
663
|
task=Task(
|
662
|
-
producer=Node(node_id=md.src_node_id
|
663
|
-
consumer=Node(node_id=
|
664
|
+
producer=Node(node_id=md.src_node_id),
|
665
|
+
consumer=Node(node_id=SUPERLINK_NODE_ID), # Assume driver node
|
664
666
|
created_at=md.created_at,
|
665
667
|
ttl=md.ttl,
|
666
668
|
ancestry=[md.reply_to_message] if md.reply_to_message != "" else [],
|
flwr/common/typing.py
CHANGED
@@ -266,3 +266,23 @@ class InvalidRunStatusException(BaseException):
|
|
266
266
|
def __init__(self, message: str) -> None:
|
267
267
|
super().__init__(message)
|
268
268
|
self.message = message
|
269
|
+
|
270
|
+
|
271
|
+
# OIDC user authentication types
|
272
|
+
@dataclass
|
273
|
+
class UserAuthLoginDetails:
|
274
|
+
"""User authentication login details."""
|
275
|
+
|
276
|
+
auth_type: str
|
277
|
+
device_code: str
|
278
|
+
verification_uri_complete: str
|
279
|
+
expires_in: int
|
280
|
+
interval: int
|
281
|
+
|
282
|
+
|
283
|
+
@dataclass
|
284
|
+
class UserAuthCredentials:
|
285
|
+
"""User authentication tokens."""
|
286
|
+
|
287
|
+
access_token: str
|
288
|
+
refresh_token: str
|
flwr/proto/clientappio_pb2.py
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
3
4
|
# source: flwr/proto/clientappio.proto
|
4
|
-
# Protobuf Python Version:
|
5
|
+
# Protobuf Python Version: 5.29.0
|
5
6
|
"""Generated protocol buffer code."""
|
6
7
|
from google.protobuf import descriptor as _descriptor
|
7
8
|
from google.protobuf import descriptor_pool as _descriptor_pool
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
8
10
|
from google.protobuf import symbol_database as _symbol_database
|
9
11
|
from google.protobuf.internal import builder as _builder
|
12
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
13
|
+
_runtime_version.Domain.PUBLIC,
|
14
|
+
5,
|
15
|
+
29,
|
16
|
+
0,
|
17
|
+
'',
|
18
|
+
'flwr/proto/clientappio.proto'
|
19
|
+
)
|
10
20
|
# @@protoc_insertion_point(imports)
|
11
21
|
|
12
22
|
_sym_db = _symbol_database.Default()
|
@@ -22,8 +32,8 @@ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66lwr/proto/
|
|
22
32
|
_globals = globals()
|
23
33
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
24
34
|
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'flwr.proto.clientappio_pb2', _globals)
|
25
|
-
if _descriptor._USE_C_DESCRIPTORS
|
26
|
-
DESCRIPTOR.
|
35
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
36
|
+
DESCRIPTOR._loaded_options = None
|
27
37
|
_globals['_CLIENTAPPOUTPUTCODE']._serialized_start=675
|
28
38
|
_globals['_CLIENTAPPOUTPUTCODE']._serialized_end=751
|
29
39
|
_globals['_CLIENTAPPOUTPUTSTATUS']._serialized_start=114
|