Skip to content

Commit

Permalink
start_client insecure by default
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Nov 28, 2023
1 parent c044d4b commit 7f3574e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def start_client(
client: Optional[Client] = None,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
root_certificates: Optional[Union[bytes, str]] = None,
use_grpc_certificates: bool = True,
use_grpc_certificates: bool = False,
transport: Optional[str] = None,
) -> None:
"""Start a Flower client node which connects to a Flower server.
Expand Down Expand Up @@ -176,10 +176,10 @@ class `flwr.client.Client` (default: None)
The PEM-encoded root certificates as a byte string or a path string.
If provided, a secure connection using the certificates will be
established to an SSL-enabled Flower server.
use_grpc_certificates : bool (default: True)
use_grpc_certificates : bool (default: False)
Enables HTTPS connection when True, using system certificates
if `root_certificates` is None. Starts an insecure gRPC connection
when False, ignoring `root_certificates`.
if set to False and `root_certificates` is None.
transport : Optional[str] (default: None)
Configure the transport layer. Allowed values:
- 'grpc-bidi': gRPC, bidirectional streaming
Expand All @@ -188,6 +188,13 @@ class `flwr.client.Client` (default: None)
Examples
--------
Starting a gRPC client with an insecure server connection:
>>> start_client(
>>> server_address=localhost:8080,
>>> client_fn=client_fn,
>>> )
Starting an SSL-enabled gRPC client using system certificates:
>>> def client_fn(cid: str):
Expand All @@ -196,6 +203,7 @@ class `flwr.client.Client` (default: None)
>>> start_client(
>>> server_address=localhost:8080,
>>> client_fn=client_fn,
>>> use_grpc_certificates=True,
>>> )
Starting an SSL-enabled gRPC client using provided certificates:
Expand All @@ -207,14 +215,6 @@ class `flwr.client.Client` (default: None)
>>> client_fn=client_fn,
>>> root_certificates=Path("/crts/root.pem").read_bytes(),
>>> )
Starting a gRPC client with an insecure server connection:
>>> start_client(
>>> server_address=localhost:8080,
>>> client_fn=client_fn,
>>> use_grpc_certificates=False,
>>> )
"""
event(EventType.START_CLIENT_ENTER)

Expand Down Expand Up @@ -311,7 +311,7 @@ def start_numpy_client(
client: NumPyClient,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
root_certificates: Optional[bytes] = None,
use_grpc_certificates: bool = True,
use_grpc_certificates: bool = False,
transport: Optional[str] = None,
) -> None:
"""Start a Flower NumPyClient which connects to a gRPC server.
Expand All @@ -335,10 +335,10 @@ def start_numpy_client(
The PEM-encoded root certificates as a byte string or a path string.
If provided, a secure connection using the certificates will be
established to an SSL-enabled Flower server.
use_grpc_certificates : bool (default: True)
use_grpc_certificates : bool (default: False)
Enables HTTPS connection when True, using system certificates
if `root_certificates` is None. Starts an insecure gRPC connection
when False, ignoring `root_certificates`.
if set to False and `root_certificates` is None.
transport : Optional[str] (default: None)
Configure the transport layer. Allowed values:
- 'grpc-bidi': gRPC, bidirectional streaming
Expand All @@ -347,29 +347,29 @@ def start_numpy_client(
Examples
--------
Starting an SSL-enabled gRPC client using system certificates:
Starting a gRPC client with an insecure server connection:
>>> start_numpy_client(
>>> server_address=localhost:8080,
>>> client=FlowerClient(),
>>> )
Starting an SSL-enabled gRPC client using provided certificates:
Starting an SSL-enabled gRPC client using system certificates:
>>> from pathlib import Path
>>>
>>> start_numpy_client(
>>> server_address=localhost:8080,
>>> client=FlowerClient(),
>>> root_certificates=Path("/crts/root.pem").read_bytes(),
>>> use_grpc_certificates=True,
>>> )
Starting a gRPC client with an insecure server connection:
Starting an SSL-enabled gRPC client using provided certificates:
>>> from pathlib import Path
>>>
>>> start_numpy_client(
>>> server_address=localhost:8080,
>>> client=FlowerClient(),
>>> use_grpc_certificates=False,
>>> root_certificates=Path("/crts/root.pem").read_bytes(),
>>> )
"""
# warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/common/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_channel(
("grpc.max_receive_message_length", max_message_length),
]

if use_grpc_certificates:
if use_grpc_certificates or root_certificates is not None:
ssl_channel_credentials = grpc.ssl_channel_credentials(root_certificates)
channel = grpc.secure_channel(
server_address, ssl_channel_credentials, options=channel_options
Expand Down

0 comments on commit 7f3574e

Please sign in to comment.