aranya_runtime/sync/dispatcher.rs
1use core::time::Duration;
2
3use heapless::Vec;
4use serde::{Deserialize, Serialize};
5
6use super::{COMMAND_SAMPLE_MAX, SyncResponseMessage, requester::SyncRequestMessage};
7use crate::{Address, GraphId};
8
9/// The sync hello message types for subscription-based notifications.
10#[derive(Serialize, Deserialize, Debug)]
11pub enum SyncHelloType {
12 /// Subscribe to receive hello notifications from this peer
13 Subscribe {
14 /// Specifies the graph.
15 graph_id: GraphId,
16 /// Delay between notifications when graph changes (rate limiting)
17 graph_change_delay: Duration,
18 /// How long the subscription should last
19 duration: Duration,
20 /// Schedule-based hello sending delay.
21 /// Send hello every `schedule_delay` duration regardless of graph changes.
22 schedule_delay: Duration,
23 },
24 /// Unsubscribe from hello notifications
25 Unsubscribe {
26 /// Specifies the graph.
27 graph_id: GraphId,
28 },
29 /// Notification message sent to subscribers
30 Hello {
31 /// Specifies the graph.
32 graph_id: GraphId,
33 /// The current head of the sender's graph
34 head: Address,
35 },
36}
37
38/// The sync type to dispatch.
39#[derive(Serialize, Deserialize, Debug)]
40#[allow(clippy::large_enum_variant)]
41pub enum SyncType {
42 /// This will include a sync request and be
43 /// immediately responded to with a sync response.
44 Poll {
45 /// The sync request message.
46 request: SyncRequestMessage,
47 },
48 /// Subscribes the peer to receive push syncs from this peer. Calling this
49 /// again will update remain_open and max_bytes for this peer.
50 Subscribe {
51 /// The number of seconds the sync request will remain open.
52 remain_open: u64,
53 /// The maximum number of bytes that should be sent.
54 max_bytes: u64,
55 /// A sample of the peer's graph. This will be used to update the
56 /// known heads for the peer.
57 commands: Vec<Address, COMMAND_SAMPLE_MAX>,
58 /// The graph this request is for.
59 graph_id: GraphId,
60 },
61 /// Removes any open subsciptions for the peer. If there is no subscription
62 /// this will be a noop.
63 Unsubscribe {
64 /// Specifies the graph.
65 graph_id: GraphId,
66 },
67 /// This will only be sent to peers who have an open subscription.
68 /// Contains any new commands that come after the peer's known heads.
69 Push {
70 /// A message containing commands that the pusher believes the peer
71 /// does not have.
72 message: SyncResponseMessage,
73 /// The graph this push is for.
74 graph_id: GraphId,
75 },
76 /// Sync hello message for subscription-based notifications.
77 Hello(SyncHelloType),
78}
79
80/// The result of attempting to subscribe.
81#[derive(Serialize, Deserialize, Debug)]
82pub enum SubscribeResult {
83 Success,
84 TooManySubscriptions,
85}