everscale_network/proto/
overlay.rs

1use bytes::Bytes;
2use smallvec::SmallVec;
3use tl_proto::{BoxedConstructor, TlRead, TlWrite};
4
5use super::{rldp, HashRef};
6
7#[derive(TlWrite, TlRead)]
8pub struct Nodes<'tl> {
9    pub nodes: SmallVec<[Node<'tl>; 5]>,
10}
11
12impl BoxedConstructor for Nodes<'_> {
13    const TL_ID: u32 = tl_proto::id!("overlay.nodes", scheme = "scheme.tl");
14}
15
16#[derive(Clone, TlWrite, TlRead)]
17pub struct NodesOwned {
18    pub nodes: SmallVec<[NodeOwned; 5]>,
19}
20
21impl BoxedConstructor for NodesOwned {
22    const TL_ID: u32 = Nodes::TL_ID;
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, TlWrite, TlRead)]
26pub struct Node<'tl> {
27    pub id: everscale_crypto::tl::PublicKey<'tl>,
28    #[tl(size_hint = 32)]
29    pub overlay: HashRef<'tl>,
30    #[tl(size_hint = 4)]
31    pub version: u32,
32    pub signature: &'tl [u8],
33}
34
35impl Node<'_> {
36    pub fn as_equivalent_owned(&self) -> NodeOwned {
37        NodeOwned {
38            id: self.id.as_equivalent_owned(),
39            overlay: *self.overlay,
40            version: self.version,
41            signature: self.signature.to_vec().into(),
42        }
43    }
44}
45
46#[derive(Debug, Clone, TlWrite, TlRead)]
47pub struct NodeOwned {
48    pub id: everscale_crypto::tl::PublicKeyOwned,
49    pub overlay: [u8; 32],
50    pub version: u32,
51    pub signature: Bytes,
52}
53
54impl NodeOwned {
55    pub fn as_equivalent_ref(&self) -> Node {
56        Node {
57            id: self.id.as_equivalent_ref(),
58            overlay: &self.overlay,
59            version: self.version,
60            signature: &self.signature,
61        }
62    }
63}
64
65#[derive(TlWrite)]
66#[tl(boxed, id = "overlay.node.toSign", scheme = "scheme.tl")]
67pub struct NodeToSign<'tl> {
68    pub id: HashRef<'tl>,
69    pub overlay: HashRef<'tl>,
70    pub version: u32,
71}
72
73#[derive(TlWrite)]
74#[tl(boxed, id = "tonNode.shardPublicOverlayId", scheme = "scheme.tl")]
75pub struct ShardPublicOverlayId<'tl> {
76    pub workchain: i32,
77    pub shard: u64,
78    pub zero_state_file_hash: HashRef<'tl>,
79}
80
81pub struct CatchainFirstBlock<'a, 'tl: 'a, I> {
82    pub unique_hash: HashRef<'tl>,
83    pub nodes: tl_proto::IterRef<'a, I>,
84}
85
86impl<'a, 'tl: 'a, I> TlWrite for CatchainFirstBlock<'a, 'tl, I>
87where
88    I: Iterator<Item = HashRef<'tl>> + ExactSizeIterator + Clone,
89{
90    type Repr = tl_proto::Boxed;
91
92    fn max_size_hint(&self) -> usize {
93        4 + self.unique_hash.max_size_hint() + self.nodes.max_size_hint()
94    }
95
96    fn write_to<P>(&self, packet: &mut P)
97    where
98        P: tl_proto::TlPacket,
99    {
100        const ID: u32 = tl_proto::id!(scheme = "scheme.tl", "catchain.firstblock");
101        ID.write_to(packet);
102        self.unique_hash.write_to(packet);
103        self.nodes.write_to(packet);
104    }
105}
106
107#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
108#[tl(boxed, id = "overlay.message", scheme = "scheme.tl", size_hint = 32)]
109pub struct Message<'tl> {
110    pub overlay: HashRef<'tl>,
111}
112
113#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
114#[tl(boxed, scheme = "scheme.tl")]
115pub enum Broadcast<'tl> {
116    #[tl(id = "overlay.broadcast")]
117    Broadcast(OverlayBroadcast<'tl>),
118    #[tl(id = "overlay.broadcastFec")]
119    BroadcastFec(OverlayBroadcastFec<'tl>),
120    #[tl(id = "overlay.broadcastFecShort")]
121    BroadcastFecShort {
122        src: everscale_crypto::tl::PublicKey<'tl>,
123        certificate: Certificate<'tl>,
124        #[tl(size_hint = 32)]
125        broadcast_hash: HashRef<'tl>,
126        #[tl(size_hint = 32)]
127        part_data_hash: HashRef<'tl>,
128        seqno: u32,
129        signature: &'tl [u8],
130    },
131    #[tl(id = "overlay.broadcastNotFound", size_hint = 0)]
132    BroadcastNotFound,
133    #[tl(id = "overlay.fec.completed", size_hint = 32)]
134    FecCompleted { hash: HashRef<'tl> },
135    #[tl(id = "overlay.fec.received", size_hint = 32)]
136    FecReceived { hash: HashRef<'tl> },
137    #[tl(id = "overlay.unicast")]
138    Unicast { data: &'tl [u8] },
139}
140
141#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
142pub struct OverlayBroadcast<'tl> {
143    pub src: everscale_crypto::tl::PublicKey<'tl>,
144    pub certificate: Certificate<'tl>,
145    pub flags: u32,
146    pub data: &'tl [u8],
147    pub date: u32,
148    pub signature: &'tl [u8],
149}
150
151#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
152pub struct OverlayBroadcastFec<'tl> {
153    pub src: everscale_crypto::tl::PublicKey<'tl>,
154    pub certificate: Certificate<'tl>,
155    #[tl(size_hint = 32)]
156    pub data_hash: HashRef<'tl>,
157    pub data_size: u32,
158    pub flags: u32,
159    pub data: &'tl [u8],
160    pub seqno: u32,
161    pub fec: rldp::RaptorQFecType,
162    pub date: u32,
163    pub signature: &'tl [u8],
164}
165
166#[derive(Debug, Copy, Clone, TlWrite, TlRead)]
167#[tl(boxed, scheme = "scheme.tl")]
168pub enum Certificate<'tl> {
169    #[tl(id = "overlay.certificate")]
170    Certificate {
171        issued_by: everscale_crypto::tl::PublicKey<'tl>,
172        expire_at: u32,
173        max_size: u32,
174        signature: &'tl [u8],
175    },
176    #[tl(id = "overlay.emptyCertificate", size_hint = 0)]
177    EmptyCertificate,
178}