Skip to content

Commit

Permalink
feat(admin-ws): enable custom websocket config (#112)
Browse files Browse the repository at this point in the history
* feat: pass a custom WebsocketConfig to connect for overriding default timeout

* fix: await future

* feat: expose HolochainWebsocket to consumer crates

* fix: actually use websocket config for connection

---------

Co-authored-by: Jost Schulte <[email protected]>
  • Loading branch information
mattyg and jost-s authored Sep 10, 2024
1 parent a6c8b20 commit 5456c7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/admin_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ impl AdminWebsocket {
/// As string `"localhost:30000"`
/// As tuple `([127.0.0.1], 30000)`
pub async fn connect(socket_addr: impl ToSocketAddrs) -> Result<Self> {
Self::connect_with_config(socket_addr, Arc::new(WebsocketConfig::CLIENT_DEFAULT)).await
}

/// Connect to a Conductor API AdminWebsocket with a custom WebsocketConfig.
pub async fn connect_with_config(
socket_addr: impl ToSocketAddrs,
websocket_config: Arc<WebsocketConfig>,
) -> Result<Self> {
let addr = socket_addr
.to_socket_addrs()?
.next()
.expect("invalid websocket address");
let websocket_config = Arc::new(WebsocketConfig::CLIENT_DEFAULT);

let (tx, mut rx) = again::retry(|| {
let websocket_config = Arc::clone(&websocket_config);
connect(websocket_config, addr)
})
.await?;
let (tx, mut rx) = again::retry(|| connect(websocket_config.clone(), addr)).await?;

// WebsocketReceiver needs to be polled in order to receive responses
// from remote to sender requests.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub use holochain_types::{
app::{InstallAppPayload, InstalledAppId},
dna::AgentPubKey,
};
pub use holochain_websocket::WebsocketConfig;
pub use signing::client_signing::{ClientAgentSigner, SigningCredentials};
#[cfg(feature = "lair_signing")]
pub use signing::lair_signing::LairAgentSigner;
Expand Down

0 comments on commit 5456c7d

Please sign in to comment.