Skip to content

Commit

Permalink
feat: add node queries request
Browse files Browse the repository at this point in the history
  • Loading branch information
iduartgomez committed Oct 26, 2024
1 parent aa5c7b7 commit b708c49
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rust/src/client_api/client_events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use flatbuffers::WIPOffset;
use std::borrow::Cow;
use std::fmt::Display;
use std::net::SocketAddr;

use serde::{de::DeserializeOwned, Deserialize, Serialize};

Expand Down Expand Up @@ -245,8 +246,12 @@ pub enum ClientRequest<'a> {
ContractOp(#[serde(borrow)] ContractRequest<'a>),
Disconnect { cause: Option<Cow<'static, str>> },
Authenticate { token: String },
NodeQueries(ConnectedPeers),
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ConnectedPeers {}

impl ClientRequest<'_> {
pub fn into_owned(self) -> ClientRequest<'static> {
match self {
Expand Down Expand Up @@ -288,6 +293,7 @@ impl ClientRequest<'_> {
}
ClientRequest::Disconnect { cause } => ClientRequest::Disconnect { cause },
ClientRequest::Authenticate { token } => ClientRequest::Authenticate { token },
ClientRequest::NodeQueries(query) => ClientRequest::NodeQueries(query),
}
}

Expand Down Expand Up @@ -590,6 +596,7 @@ impl Display for ClientRequest<'_> {
},
ClientRequest::Disconnect { .. } => write!(f, "client disconnected"),
ClientRequest::Authenticate { .. } => write!(f, "authenticate"),
ClientRequest::NodeQueries(query) => write!(f, "node queries: {:?}", query),
}
}
}
Expand Down Expand Up @@ -669,10 +676,18 @@ pub enum HostResponse<T = WrappedState> {
key: DelegateKey,
values: Vec<OutboundDelegateMsg>,
},
QueryResponse(QueryResponse),
/// A requested action which doesn't require an answer was performed successfully.
Ok,
}

type Peer = String;

#[derive(Serialize, Deserialize, Debug)]
pub enum QueryResponse {
ConnectedPeers { peers: Vec<(Peer, SocketAddr)> },
}

impl HostResponse {
pub fn unwrap_put(self) -> ContractKey {
if let Self::ContractResponse(ContractResponse::PutResponse { key }) = self {
Expand Down Expand Up @@ -1310,6 +1325,7 @@ impl HostResponse {
finish_host_response_buffer(&mut builder, host_response_offset);
Ok(builder.finished_data().to_vec())
}
HostResponse::QueryResponse(_) => unimplemented!(),
}
}
}
Expand All @@ -1333,6 +1349,7 @@ impl std::fmt::Display for HostResponse {
},
HostResponse::DelegateResponse { .. } => write!(f, "delegate responses"),
HostResponse::Ok => write!(f, "ok response"),
HostResponse::QueryResponse(_) => write!(f, "query response"),
}
}
}
Expand Down

0 comments on commit b708c49

Please sign in to comment.