Subscribe to peer pubsub snapshots

This commit is contained in:
Eric Wendland 2026-05-19 15:28:48 +02:00
commit df70b81a1d
8 changed files with 332 additions and 20 deletions

View file

@ -229,6 +229,7 @@ pub enum ControlRequest {
},
PubsubSub {
topic: String,
node: Option<String>,
},
PipeListen {
name: String,
@ -498,6 +499,16 @@ pub enum ControlResponse {
messages: Vec<PubsubMessage>,
note: String,
},
PubsubRemoteMessages {
peer_node_id: String,
peer_agent_id: String,
endpoint_id: String,
topic: String,
messages: Vec<PubsubMessage>,
allowed: bool,
reason: String,
note: String,
},
PipeListening {
listener: PipeListener,
},
@ -602,6 +613,11 @@ pub enum PeerControlRequest {
message: String,
nonce: String,
},
PubsubSubscribe {
peer_card: PeerCard,
topic: String,
nonce: String,
},
PipeConnect {
peer_card: PeerCard,
target: String,
@ -723,6 +739,19 @@ pub enum PeerControlResponse {
nonce: String,
note: String,
},
PubsubSubscribed {
node_id: String,
agent_id: String,
endpoint_id: String,
remote_endpoint_id: String,
topic: String,
messages: Vec<PubsubMessage>,
allowed: bool,
reason: String,
evaluated_ops: usize,
nonce: String,
note: String,
},
PipeConnected {
node_id: String,
agent_id: String,
@ -987,6 +1016,15 @@ mod tests {
request
);
let request = ControlRequest::PubsubSub {
topic: "presence/test".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(),
@ -1005,6 +1043,25 @@ mod tests {
response
);
let response = ControlResponse::PubsubRemoteMessages {
peer_node_id: "node:peer".to_owned(),
peer_agent_id: "agent:peer".to_owned(),
endpoint_id: "endpoint:peer".to_owned(),
topic: "presence/test".to_owned(),
messages: vec![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 response = ControlResponse::PipeRemoteConnected {
peer_node_id: "node:peer".to_owned(),
peer_agent_id: "agent:peer".to_owned(),
@ -1303,6 +1360,50 @@ mod tests {
response
);
let request = PeerControlRequest::PubsubSubscribe {
peer_card: PeerCard {
node_id: "node:caller".into(),
agent_id: "agent:caller".into(),
endpoints: Vec::new(),
issued_at: geth_types::UnixMillis(1),
signature: geth_discovery::SignatureMetadata {
namespace: "geth.peer-card.v1@geth.local".to_owned(),
signer: "agent:caller".to_owned(),
public_key: "key".to_owned(),
signature: "sig".to_owned(),
},
},
topic: "presence/test".to_owned(),
nonce: "nonce".to_owned(),
};
assert_eq!(
decode_peer_request(&encode_peer_request(&request).expect("encode")).expect("decode"),
request
);
let response = PeerControlResponse::PubsubSubscribed {
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(),
topic: "presence/test".to_owned(),
messages: vec![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
);
let response = PeerControlResponse::PipeConnected {
node_id: "node:peer".to_owned(),
agent_id: "agent:peer".to_owned(),