Publish pubsub messages over Iroh
This commit is contained in:
parent
f85039367c
commit
e294965833
8 changed files with 357 additions and 28 deletions
|
|
@ -216,6 +216,7 @@ pub enum ControlRequest {
|
|||
PubsubPub {
|
||||
topic: String,
|
||||
message: String,
|
||||
node: Option<String>,
|
||||
},
|
||||
PubsubSub {
|
||||
topic: String,
|
||||
|
|
@ -451,6 +452,15 @@ pub enum ControlResponse {
|
|||
PubsubPublished {
|
||||
message: PubsubMessage,
|
||||
},
|
||||
PubsubRemotePublished {
|
||||
peer_node_id: String,
|
||||
peer_agent_id: String,
|
||||
endpoint_id: String,
|
||||
message: PubsubMessage,
|
||||
allowed: bool,
|
||||
reason: String,
|
||||
note: String,
|
||||
},
|
||||
PubsubMessages {
|
||||
topic: String,
|
||||
messages: Vec<PubsubMessage>,
|
||||
|
|
@ -541,6 +551,12 @@ pub enum PeerControlRequest {
|
|||
since_ms: i64,
|
||||
nonce: String,
|
||||
},
|
||||
PubsubPublish {
|
||||
peer_card: PeerCard,
|
||||
topic: String,
|
||||
message: String,
|
||||
nonce: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
|
@ -623,6 +639,18 @@ pub enum PeerControlResponse {
|
|||
nonce: String,
|
||||
note: String,
|
||||
},
|
||||
PubsubPublished {
|
||||
node_id: String,
|
||||
agent_id: String,
|
||||
endpoint_id: String,
|
||||
remote_endpoint_id: String,
|
||||
message: Option<PubsubMessage>,
|
||||
allowed: bool,
|
||||
reason: String,
|
||||
evaluated_ops: usize,
|
||||
nonce: String,
|
||||
note: String,
|
||||
},
|
||||
Error {
|
||||
message: String,
|
||||
},
|
||||
|
|
@ -822,6 +850,34 @@ mod tests {
|
|||
request
|
||||
);
|
||||
|
||||
let request = ControlRequest::PubsubPub {
|
||||
topic: "presence/test".to_owned(),
|
||||
message: "online".to_owned(),
|
||||
node: Some("node:peer".to_owned()),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_request(&encode_request(&request).expect("encode")).expect("decode"),
|
||||
request
|
||||
);
|
||||
|
||||
let response = ControlResponse::PubsubRemotePublished {
|
||||
peer_node_id: "node:peer".to_owned(),
|
||||
peer_agent_id: "agent:peer".to_owned(),
|
||||
endpoint_id: "endpoint:peer".to_owned(),
|
||||
message: PubsubMessage {
|
||||
topic: "presence/test".into(),
|
||||
message: "online".to_owned(),
|
||||
published_at: geth_types::UnixMillis(1),
|
||||
},
|
||||
allowed: true,
|
||||
reason: "direct grant".to_owned(),
|
||||
note: "lossy".to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_response(&encode_response(&response).expect("encode")).expect("decode"),
|
||||
response
|
||||
);
|
||||
|
||||
let request = ControlRequest::DbChanges {
|
||||
name: "notes".to_owned(),
|
||||
after_db_version: Some(7),
|
||||
|
|
@ -990,5 +1046,27 @@ mod tests {
|
|||
.expect("decode"),
|
||||
response
|
||||
);
|
||||
|
||||
let response = PeerControlResponse::PubsubPublished {
|
||||
node_id: "node:peer".to_owned(),
|
||||
agent_id: "agent:peer".to_owned(),
|
||||
endpoint_id: "endpoint:peer".to_owned(),
|
||||
remote_endpoint_id: "endpoint:caller".to_owned(),
|
||||
message: Some(PubsubMessage {
|
||||
topic: "presence/test".into(),
|
||||
message: "online".to_owned(),
|
||||
published_at: geth_types::UnixMillis(1),
|
||||
}),
|
||||
allowed: true,
|
||||
reason: "direct grant".to_owned(),
|
||||
evaluated_ops: 1,
|
||||
nonce: "nonce".to_owned(),
|
||||
note: "lossy".to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_peer_response(&encode_peer_response(&response).expect("encode"))
|
||||
.expect("decode"),
|
||||
response
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue