Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub(super) async fn chat_room_presence_heartbeat(
})
.into_response();
};
// A person has Community open in front of them, so History asks present
// Homes for earlier posts while somebody reads them.
port.record_community_open(now_ts());
// Not shown is a successful heartbeat that announces nothing, not an
// error: the person asked for this, and Chat has no failure to report.
// Chat presents only a `/while-open` grant; "Always" is the timer's.
Expand Down
69 changes: 69 additions & 0 deletions elastos/crates/elastos-server/src/carrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19509,6 +19509,75 @@ pub(crate) mod tests {
shutdown_test_carrier_node(node).await;
}

/// A consumer cursor number is not a frame identity. `gossip_leave` drops
/// the topic buffer and every cursor on it, and the next join starts a
/// buffer at position 0, so the same consumer peeks position 0 again and
/// finds a frame it never read. The Community driver binds its progress to
/// the frames it ingested because of this.
#[tokio::test]
async fn test_gossip_leave_and_join_give_the_same_cursor_a_new_frame() {
let dir = tempfile::tempdir().unwrap();
let (signing_key, did) = elastos_identity::derive_did(&[66u8; 32]);
let node = start_carrier_node(&signing_key, &did, dir.path().to_path_buf())
.await
.unwrap();
let provider = CarrierGossipProvider::new(node.gossip_state.clone());
let topic = "__test/gossip-cursor-reuse";
let consumer = "community-consumer";
let join = serde_json::json!({"op":"gossip_join_exact", "topic":topic, "peers":[]});
let peek = serde_json::json!({
"op":"gossip_peek", "topic":topic, "consumer_id":consumer, "limit":32
});
let send = |message: &str| serde_json::json!({"op":"gossip_send", "topic":topic, "message":message});
let read_one = |response: &serde_json::Value| {
(
response["data"]["cursor"].as_u64(),
response["data"]["next_cursor"].as_u64(),
response["data"]["messages"][0]["content"]
.as_str()
.map(str::to_string),
)
};

assert_eq!(provider.send_raw(&join).await.unwrap()["status"], "ok");
assert_eq!(
provider.send_raw(&send("first frame")).await.unwrap()["status"],
"ok"
);
assert_eq!(
read_one(&provider.send_raw(&peek).await.unwrap()),
(Some(0), Some(1), Some("first frame".to_string()))
);
assert_eq!(
provider
.send_raw(&serde_json::json!({
"op":"gossip_ack", "topic":topic, "consumer_id":consumer,
"cursor":0, "next_cursor":1
}))
.await
.unwrap()["status"],
"ok"
);
assert_eq!(
provider
.send_raw(&serde_json::json!({"op":"gossip_leave", "topic":topic}))
.await
.unwrap()["status"],
"ok"
);
assert_eq!(provider.send_raw(&join).await.unwrap()["status"], "ok");
assert_eq!(
provider.send_raw(&send("second frame")).await.unwrap()["status"],
"ok"
);
assert_eq!(
read_one(&provider.send_raw(&peek).await.unwrap()),
(Some(0), Some(1), Some("second frame".to_string())),
"the recreated topic hands the same consumer cursor a frame it never read"
);
shutdown_test_carrier_node(node).await;
}

#[tokio::test]
async fn test_gossip_empty_peek_requires_exact_empty_ack() {
let dir = tempfile::tempdir().unwrap();
Expand Down
8 changes: 7 additions & 1 deletion elastos/crates/elastos-server/src/collaboration_carrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::collaboration_protocol::{

const COLLABORATION_TOPIC_DOMAIN: &[u8] = b"elastos.collaboration.carrier.topic.v1";
const COLLABORATION_TOPIC_PREFIX: &str = "__elastos_internal/collaboration-v1/";
const COLLABORATION_RECEIVE_BATCH_SIZE: usize = 32;
pub(crate) const COLLABORATION_RECEIVE_BATCH_SIZE: usize = 32;
const MAX_RECEIVE_RESPONSE_BYTES: usize =
MAX_COLLABORATION_TRANSPORT_FRAME_BYTES * COLLABORATION_RECEIVE_BATCH_SIZE + 64 * 1024;
/// How long a joined Home may have no Community peer before it repairs the
Expand Down Expand Up @@ -152,6 +152,12 @@ impl CollaborationCarrierReceiveBatch {
pub fn rejected_frames(&self) -> usize {
self.rejected_frames
}

/// The buffer position of the first frame in this batch. The Carrier
/// replays the batch from here until the Home acknowledges it.
pub fn cursor(&self) -> u64 {
self.cursor
}
}

#[derive(Deserialize)]
Expand Down
18 changes: 17 additions & 1 deletion elastos/crates/elastos-server/src/collaboration_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) const DEFAULT_CONVERSATION_SEND_METHOD: &str = "message.send";
const MAX_CORE_STATE_BYTES: usize = 24 * 1024 * 1024;
const MAX_UNRESOLVED_OUTGOING: usize = 64;
const MAX_OUTGOING_RECORDS: usize = 4_096;
const MAX_PENDING_INCOMING: usize = 32;
pub(crate) const MAX_PENDING_INCOMING: usize = 32;
pub(crate) const MAX_PENDING_INCOMING_PER_SENDER: usize = 8;
pub(crate) const MAX_ACCEPTANCE_RECEIPTS_PER_OUTGOING: usize = 32;
const MAX_INCOMING_RECORDS_AND_TOMBSTONES: usize = 4_096;
Expand Down Expand Up @@ -200,13 +200,27 @@ impl DurableIncomingAcceptance {
pub(crate) struct CollaborationTransportIncomingAcceptance {
acceptance_receipt_bytes: Vec<u8>,
product_handoff_pending: bool,
message_hash: String,
message_expires_at: u64,
}

impl CollaborationTransportIncomingAcceptance {
pub(crate) fn acceptance_receipt_bytes(&self) -> &[u8] {
&self.acceptance_receipt_bytes
}

/// The accepted post this receipt confirms.
pub(crate) fn message_hash(&self) -> &str {
&self.message_hash
}

/// When the accepted post expires. A receipt for it is worth sending
/// until then and no longer: after that second the sender has dropped the
/// post and nobody waits for the confirmation.
pub(crate) fn message_expires_at(&self) -> u64 {
self.message_expires_at
}

#[cfg_attr(
not(test),
expect(
Expand Down Expand Up @@ -3122,6 +3136,8 @@ fn transport_incoming_acceptance(
accepted: DurableIncomingAcceptance,
) -> CollaborationTransportIncomingAcceptance {
CollaborationTransportIncomingAcceptance {
message_hash: accepted.authorized.message().envelope_sha256().to_string(),
message_expires_at: accepted.authorized.message().envelope().payload.expires_at,
acceptance_receipt_bytes: accepted.acceptance_receipt_bytes,
product_handoff_pending: accepted.product_handoff_pending,
}
Expand Down
Loading
Loading