1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! # Network
//!
//! The primary entry point to mosaik. A [`Network`] wraps an
//! [iroh](https://docs.rs/iroh) QUIC endpoint, bootstraps the transport
//! layer, and composes the four subsystems —
//! [`discovery`](crate::discovery), [`streams`](crate::streams),
//! [`groups`](crate::groups), and [`collections`](crate::collections)
//! — behind a single handle.
//!
//! # Node Identity
//!
//! Every node has a globally unique [`PeerId`] derived from its secret
//! key. If no key is provided at construction time a random one is
//! generated. Peers are addressed by their public key; the discovery
//! subsystem resolves the corresponding transport addresses.
//!
//! # Network Identity
//!
//! Nodes are partitioned into logical networks identified by a
//! [`NetworkId`] (a blake3 hash of a human-readable name). Only nodes
//! sharing the same `NetworkId` discover and connect to each other.
//!
//! # Quick start
//!
//! ```rust
//! // Minimal — random key, default discovery
//! let net = Network::new(NetworkId::random()).await?;
//!
//! // Customized
//! let net = Network::builder("my-app")
//! .with_secret_key(key)
//! .with_discovery(
//! discovery::Config::builder()
//! .with_tags(vec![tag!("api")])
//! .with_bootstrap(vec![seed_peer]),
//! )
//! .build()
//! .await?;
//! ```
use ;
pub
pub use ;
/// The entrypoint to the Mosaic network SDK.
///
/// Notes:
///
/// - This type represents a Mosaik network connection and provides methods to
/// access different facilities such as peer discovery and stream management.
///
/// - In most cases one network instance will represent one running
/// process/node.
///
/// - Each network instance has a globally unique identity that is the public
/// key of the secret key used to construct it. If no secret key is provided a
/// new random key will be generated. This is an important property because
/// node identities are globally unique across all Mosaik networks and nodes
/// can be addressed by their public keys alone. The discovery mechanism is
/// responsible for resolving the corresponding network addresses for a given
/// public key. Knowing the physical transport addresses of a peer is not
/// sufficient to identify a node and connect to it.
///
/// - By default a random local port will be chosen for the network instance.
/// This can be overridden by providing a specific port in the builder.
///
/// - Mosaik networks are identified by a [`NetworkId`] which is a unique
/// identifier (a blake3 hash of the network string name). Nodes can only
/// connect to other nodes that are part of the same network (i.e. have the
/// same [`NetworkId`]).
/// This type uniquely identifies a network by its name.
///
/// On the protocol level this is represented by a gossip `TopicId` that is a
/// 32-byte blake3 hash of the network string name.
pub type NetworkId = Digest;
/// This type uniquely identifies a peer globally across all Mosaik networks.
/// It is the public key derived from the node's secret key.
pub type PeerId = EndpointId;
/// Public construction API
/// Public API
/// Internal trait for network components that need to install new ALPNs during
/// network initialization.
pub