hyperactor_mesh/transport.rs
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Default transport configuration for hyperactor_mesh.
10
11use hyperactor::channel::BindSpec;
12use hyperactor::channel::ChannelTransport;
13use hyperactor_config::CONFIG;
14use hyperactor_config::ConfigAttr;
15use hyperactor_config::attrs::declare_attrs;
16use hyperactor_config::global;
17
18declare_attrs! {
19 /// Default transport type to use across the application.
20 @meta(CONFIG = ConfigAttr::new(
21 Some("HYPERACTOR_MESH_DEFAULT_TRANSPORT".to_string()),
22 Some("default_transport".to_string()),
23 ))
24 pub attr DEFAULT_TRANSPORT: BindSpec = BindSpec::Any(ChannelTransport::Unix);
25}
26
27/// Temporary: used to support the legacy allocator-based V1 bootstrap. Should
28/// be removed once we fully migrate to simple bootstrap.
29///
30/// Get the default transport to use across the application. Panic if BindSpec::Addr
31/// is set as default transport. Since we expect BindSpec::Addr to be used only
32/// with simple bootstrap, we should not see this panic in production.
33pub fn default_transport() -> ChannelTransport {
34 match default_bind_spec() {
35 BindSpec::Any(transport) => transport,
36 BindSpec::Addr(addr) => panic!("default_bind_spec() returned BindSpec::Addr({addr})"),
37 }
38}
39
40/// Get the default bind spec to use across the application.
41pub fn default_bind_spec() -> BindSpec {
42 global::get_cloned(DEFAULT_TRANSPORT)
43}