Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 6 additions & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ default-features = true
[dependencies.smg-auth]
workspace = true

[dependencies.smg-mesh]
workspace = true

[dependencies.rand]
workspace = true

[dependencies.tool-parser]
workspace = true

Expand Down
44 changes: 43 additions & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ struct Router {
otlp_traces_endpoint: String,
control_plane_auth: Option<PyControlPlaneAuthConfig>,
schema_config: Option<String>,
// Mesh server
enable_mesh: bool,
mesh_server_name: Option<String>,
mesh_host: String,
mesh_port: u16,
mesh_peer_urls: Vec<String>,
}

impl Router {
Expand Down Expand Up @@ -814,6 +820,11 @@ impl Router {
control_plane_auth = None,
schema_config = None,
disable_tokenizer_autoload = false,
enable_mesh = false,
mesh_server_name = None,
mesh_host = String::from("0.0.0.0"),
mesh_port = 39527u16,
mesh_peer_urls = vec![],
))]
#[expect(clippy::too_many_arguments)]
#[expect(
Expand Down Expand Up @@ -913,6 +924,11 @@ impl Router {
control_plane_auth: Option<PyControlPlaneAuthConfig>,
schema_config: Option<String>,
disable_tokenizer_autoload: bool,
enable_mesh: bool,
mesh_server_name: Option<String>,
mesh_host: String,
mesh_port: u16,
mesh_peer_urls: Vec<String>,
) -> PyResult<Self> {
let mut all_urls = worker_urls.clone();

Expand Down Expand Up @@ -1022,6 +1038,11 @@ impl Router {
otlp_traces_endpoint,
control_plane_auth,
schema_config,
enable_mesh,
mesh_server_name,
mesh_host,
mesh_port,
mesh_peer_urls,
})
}

Expand Down Expand Up @@ -1097,7 +1118,28 @@ impl Router {
.control_plane_auth
.as_ref()
.map(|c| c.to_auth_control_plane_config()),
mesh_server_config: None,
mesh_server_config: if self.enable_mesh {
let self_name = self.mesh_server_name.clone().unwrap_or_else(|| {
use rand::{Rng, distr::Alphanumeric};
let random_string: String = (0..4)
.map(|_| rand::rng().sample(Alphanumeric) as char)
.collect();
format!("Mesh_{random_string}")
});
let peer = self.mesh_peer_urls.first()
.and_then(|url| url.parse::<std::net::SocketAddr>().ok());
format!("{}:{}", self.mesh_host, self.mesh_port)
.parse::<std::net::SocketAddr>()
.ok()
Comment thread
slin1237 marked this conversation as resolved.
Resolved
.map(|addr| smg_mesh::MeshServerConfig {
self_name,
self_addr: addr,
init_peer: peer,
mtls_config: None,
})
} else {
None
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
webrtc_bind_addr: None,
webrtc_stun_server: None,
})
Expand Down
40 changes: 40 additions & 0 deletions bindings/python/src/smg/router_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ class RouterArgs:
jwt_audience: str | None = None
jwt_jwks_uri: str | None = None
jwt_role_mapping: dict[str, str] = dataclasses.field(default_factory=dict)
# Mesh server configuration
enable_mesh: bool = False
mesh_server_name: str | None = None
mesh_host: str = "0.0.0.0"
mesh_port: int = 39527
mesh_peer_urls: list[str] = dataclasses.field(default_factory=list)

@staticmethod
def add_cli_args(
Expand Down Expand Up @@ -1025,6 +1031,40 @@ def add_cli_args(
),
)

# Mesh server configuration
mesh_group = parser.add_argument_group("Mesh Server")
mesh_group.add_argument(
f"--{prefix}enable-mesh",
action="store_true",
default=False,
help="Enable mesh server for HA multi-router coordination",
)
mesh_group.add_argument(
f"--{prefix}mesh-server-name",
type=str,
default=None,
help="Mesh server name (default: auto-generated random name)",
)
mesh_group.add_argument(
f"--{prefix}mesh-host",
type=str,
default="0.0.0.0",
help="Mesh server bind address (default: 0.0.0.0)",
)
mesh_group.add_argument(
f"--{prefix}mesh-port",
type=int,
default=39527,
help="Mesh server port (default: 39527)",
)
mesh_group.add_argument(
f"--{prefix}mesh-peer-urls",
type=str,
nargs="*",
default=[],
help="Peer mesh server addresses to join (format: host:port)",
)

@classmethod
def from_cli_args(cls, args: argparse.Namespace, use_router_prefix: bool = False) -> RouterArgs:
"""
Expand Down
Loading