Exchange DB changes over Iroh
This commit is contained in:
parent
284207eb01
commit
20fd773a42
10 changed files with 563 additions and 15 deletions
|
|
@ -183,6 +183,11 @@ pub enum ControlRequest {
|
|||
after_db_version: Option<i64>,
|
||||
limit: u32,
|
||||
},
|
||||
DbSync {
|
||||
node: String,
|
||||
name: String,
|
||||
limit: u32,
|
||||
},
|
||||
KvCreate {
|
||||
name: String,
|
||||
},
|
||||
|
|
@ -423,6 +428,18 @@ pub enum ControlResponse {
|
|||
db: DbResource,
|
||||
batch: CrSqliteChangeBatch,
|
||||
},
|
||||
DbSynced {
|
||||
peer_node_id: String,
|
||||
peer_agent_id: String,
|
||||
endpoint_id: String,
|
||||
name: String,
|
||||
changes_received: usize,
|
||||
max_db_version: Option<i64>,
|
||||
schema_match: bool,
|
||||
allowed: bool,
|
||||
reason: String,
|
||||
note: String,
|
||||
},
|
||||
KvCreated {
|
||||
kv: KvResource,
|
||||
},
|
||||
|
|
@ -592,6 +609,13 @@ pub enum PeerControlRequest {
|
|||
since_ms: i64,
|
||||
nonce: String,
|
||||
},
|
||||
DbSync {
|
||||
peer_card: PeerCard,
|
||||
name: String,
|
||||
after_db_version: Option<i64>,
|
||||
limit: u32,
|
||||
nonce: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
|
@ -712,6 +736,20 @@ pub enum PeerControlResponse {
|
|||
nonce: String,
|
||||
note: String,
|
||||
},
|
||||
DbSynced {
|
||||
node_id: String,
|
||||
agent_id: String,
|
||||
endpoint_id: String,
|
||||
remote_endpoint_id: String,
|
||||
name: String,
|
||||
batch: Option<CrSqliteChangeBatch>,
|
||||
high_water_db_version: Option<i64>,
|
||||
allowed: bool,
|
||||
reason: String,
|
||||
evaluated_ops: usize,
|
||||
nonce: String,
|
||||
note: String,
|
||||
},
|
||||
Error {
|
||||
message: String,
|
||||
},
|
||||
|
|
@ -977,6 +1015,33 @@ mod tests {
|
|||
request
|
||||
);
|
||||
|
||||
let request = ControlRequest::DbSync {
|
||||
node: "node:peer".to_owned(),
|
||||
name: "notes".to_owned(),
|
||||
limit: 50,
|
||||
};
|
||||
assert_eq!(
|
||||
decode_request(&encode_request(&request).expect("encode")).expect("decode"),
|
||||
request
|
||||
);
|
||||
|
||||
let response = ControlResponse::DbSynced {
|
||||
peer_node_id: "node:peer".to_owned(),
|
||||
peer_agent_id: "agent:peer".to_owned(),
|
||||
endpoint_id: "endpoint:peer".to_owned(),
|
||||
name: "notes".to_owned(),
|
||||
changes_received: 1,
|
||||
max_db_version: Some(7),
|
||||
schema_match: true,
|
||||
allowed: true,
|
||||
reason: "direct grant".to_owned(),
|
||||
note: "exchange only".to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_response(&encode_response(&response).expect("encode")).expect("decode"),
|
||||
response
|
||||
);
|
||||
|
||||
let request = ControlRequest::CasRootScan {
|
||||
name: "notes".to_owned(),
|
||||
};
|
||||
|
|
@ -1073,6 +1138,29 @@ mod tests {
|
|||
response
|
||||
);
|
||||
|
||||
let request = PeerControlRequest::DbSync {
|
||||
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(),
|
||||
},
|
||||
},
|
||||
name: "notes".to_owned(),
|
||||
after_db_version: Some(7),
|
||||
limit: 10,
|
||||
nonce: "nonce".to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_peer_request(&encode_peer_request(&request).expect("encode")).expect("decode"),
|
||||
request
|
||||
);
|
||||
|
||||
let response = PeerControlResponse::SshCertSynced {
|
||||
node_id: "node:peer".to_owned(),
|
||||
agent_id: "agent:peer".to_owned(),
|
||||
|
|
@ -1180,5 +1268,29 @@ mod tests {
|
|||
.expect("decode"),
|
||||
response
|
||||
);
|
||||
|
||||
let response = PeerControlResponse::DbSynced {
|
||||
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(),
|
||||
name: "notes".to_owned(),
|
||||
batch: Some(CrSqliteChangeBatch {
|
||||
schema_metadata: "tables=1 schema_hash=abc".to_owned(),
|
||||
max_db_version: Some(7),
|
||||
changes: Vec::new(),
|
||||
}),
|
||||
high_water_db_version: Some(7),
|
||||
allowed: true,
|
||||
reason: "direct grant".to_owned(),
|
||||
evaluated_ops: 1,
|
||||
nonce: "nonce".to_owned(),
|
||||
note: "db sync".to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
decode_peer_response(&encode_peer_response(&response).expect("encode"))
|
||||
.expect("decode"),
|
||||
response
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue