mosaik 0.3.13

A Rust runtime for building self-organizing, leaderless distributed systems.
Documentation
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
use {
	super::{Catalog, Config, Error, PeerEntryVersion, SignedPeerEntry},
	crate::{
		NetworkId,
		PeerId,
		Signature,
		discovery::PeerEntry,
		network::{LocalNode, link::Protocol},
		primitives::{
			IntoIterOrSingle,
			Pretty,
			Short,
			UnboundedChannel,
			deserialize,
			serialize,
		},
	},
	chrono::Utc,
	core::{
		sync::atomic::{AtomicUsize, Ordering},
		time::Duration,
	},
	futures::StreamExt,
	iroh::{
		EndpointAddr,
		address_lookup::AddressLookup,
		protocol::ProtocolHandler,
	},
	iroh_gossip::{
		Gossip,
		api::{
			ApiError as GossipError,
			Event as GossipEvent,
			GossipReceiver,
			GossipSender,
			GossipTopic,
		},
	},
	serde::{Deserialize, Serialize},
	std::sync::Arc,
	tokio::sync::{
		mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
		oneshot,
		watch,
	},
	tokio_util::sync::CancellationToken,
	tracing::error,
};

#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum Event {
	/// A valid and signed peer entry has been updated.
	PeerEntryReceived(SignedPeerEntry),

	/// A peer has gracefully departed the network.
	PeerDeparted(PeerId, PeerEntryVersion),
}

/// The announcement protocol for broadcasting peer presence and metadata.
///
/// This protocol forms a gossip topic that is named after the network ID,
/// allowing peers to announce their presence and metadata changes in real time.
///
/// Notes:
///
/// - All announcements are signed by the peer's private key to ensure
///   authenticity.
///
/// - Announcements are broadcasted over the gossip topic to all subscribed
///   peers.
///
/// - The first announcement from a peer is broadcasted when they join the
///   gossip topic.
///
/// - Subsequent announcements are broadcasted whenever:
///   - the local peer entry is updated.
///   - a new direct gossip neighbor is detected.
///   - Periodically, to reaffirm presence at regular intervals with random
///     jitter.
///
/// - Peers listen for announcements from other peers and update their local
///   catalogs accordingly.
///
/// - Each announcement carries a version number to help peers determine the
///   most recent information, only updating their catalogs if the received
///   version is newer than the existing one.
///
/// - The catalog is the source of truth for the local peer entry; announcements
///   are generated based on the changes to the current state of the catalog.
pub(super) struct Announce {
	gossip: Gossip,
	local: LocalNode,
	network_id: NetworkId,
	events: UnboundedReceiver<Event>,
	dials: UnboundedSender<(Vec<EndpointAddr>, oneshot::Sender<()>)>,
	neighbors_count: Arc<AtomicUsize>,
}

impl Protocol for Announce {
	/// ALPN identifier for the announcement protocol.
	///
	/// This overrides the default `iroh_gossip` ALPN to use a Mosaik-specific
	/// namespace.
	const ALPN: &'static [u8] = b"/mosaik/discovery/announce/1.0";
}

/// Public API for the announcement protocol
impl Announce {
	/// Initializes the announcement protocol with the given local node and
	/// configuration.
	///
	/// This sets up the gossip topic and prepares the protocol for operation.
	/// We need the catalog watch receiver to monitor local peer entry updates.
	pub(super) fn new(
		local: LocalNode,
		config: &Config,
		catalog: watch::Receiver<Catalog>,
	) -> Self {
		let network_id = *local.network_id();
		let gossip = Gossip::builder()
			.alpn(Self::ALPN)
			.spawn(local.endpoint().clone());

		let events = unbounded_channel();
		let dials = unbounded_channel();
		let cancel = local.termination().clone();
		let last_own_version = catalog.borrow().local().update_version();
		let neighbors_count = Arc::new(AtomicUsize::new(0));

		let driver = WorkerLoop {
			config: config.clone(),
			gossip: gossip.clone(),
			local: local.clone(),
			cancel: cancel.clone(),
			catalog,
			events: events.0,
			dials: dials.1,
			last_own_version,
			neighbors_count: Arc::clone(&neighbors_count),
			messages_in: UnboundedChannel::default(),
			messages_out: UnboundedChannel::default(),
		};

		// Spawn the worker loop task
		tokio::spawn(async move {
			if let Err(e) = driver.spawn().await {
				error!(
					error = %e,
					network_id = %network_id,
					"Unrecoverable error in discovery protocol, terminating network"
				);

				// Trigger network termination
				cancel.cancel();
			}
		});

		Self {
			gossip,
			local,
			network_id,
			events: events.1,
			dials: dials.0,
			neighbors_count,
		}
	}

	/// Returns a mutable reference to the events receiver.
	///
	/// This is polled by the discovery worker to process incoming events from the
	/// announcement protocol.
	pub const fn events(&mut self) -> &mut UnboundedReceiver<Event> {
		&mut self.events
	}

	/// Returns a reference to the neighbors count atomic tracker.
	pub const fn neighbors_count(&self) -> &Arc<AtomicUsize> {
		&self.neighbors_count
	}

	/// Dials the given peer address to initiate a discovery exchange.
	pub async fn dial<V>(&self, peers: impl IntoIterOrSingle<EndpointAddr, V>) {
		let (tx, rx) = oneshot::channel::<()>();

		let Ok(addr_lookup) = self.local.endpoint().address_lookup() else {
			return; // endpoint closed
		};

		let peers = peers.iterator().into_iter().collect::<Vec<_>>();
		for peer in &peers {
			addr_lookup.publish(&peer.clone().into());
		}

		self.dials.send((peers, tx)).ok();
		let _ = rx.await;
	}

	/// A hint to observe a peer.
	///
	/// This is useful when a peer does not have any connected gossip neighbors
	/// but it does a full catalog sync with another peer or learns in any other
	/// way about another peer and there are new potential peers to connect to.
	pub fn observe(&self, peer: &PeerEntry) {
		// Ignore peers from different networks
		if peer.network_id() != self.network_id {
			return;
		}

		self.local.observe(peer.address());

		if self.neighbors_count.load(Ordering::SeqCst) == 0 {
			let (tx, _) = oneshot::channel::<()>();
			self.dials.send((vec![peer.address().clone()], tx)).ok();
		}
	}

	/// Returns the protocol listener instance responsible for accepting incoming
	/// connections for the announcement protocol.
	pub const fn protocol(&self) -> &impl ProtocolHandler {
		&self.gossip
	}
}

struct WorkerLoop {
	config: Config,
	gossip: Gossip,
	local: LocalNode,
	cancel: CancellationToken,
	events: UnboundedSender<Event>,
	catalog: watch::Receiver<Catalog>,
	last_own_version: PeerEntryVersion,
	messages_in: UnboundedChannel<AnnouncementMessage>,
	messages_out: UnboundedChannel<AnnouncementMessage>,
	neighbors_count: Arc<AtomicUsize>,
	dials: UnboundedReceiver<(Vec<EndpointAddr>, oneshot::Sender<()>)>,
}

impl WorkerLoop {
	async fn spawn(mut self) -> Result<(), Error> {
		// Ensure that the local node is online and has all protocols installed
		// and addresses resolved.
		self.local.endpoint().online().await;

		// add bootstrap peers to the addressing system
		self.local.observe(self.config.bootstrap_peers.iter());
		let peer_ids = self.config.bootstrap_peers_ids();
		let topic_id = self.local.network_id().into();
		let (mut topic_tx, mut topic_rx) =
			self.gossip.subscribe(topic_id, peer_ids).await?.split();

		loop {
			tokio::select! {
				// Network is terminating, exit the loop
				() = self.cancel.cancelled() => {
					self.shutdown(&topic_tx, &topic_rx).await;
					return Ok(());
				}

				// There is an outbound message to broadcast and we have neighbors
				Some(outbound) = self.messages_out.recv(), if topic_rx.is_joined() => {
					self.broadcast_message(
						&mut topic_tx,
						&mut topic_rx,
						outbound
					).await?;
				}

				// There is an inbound message received from gossip broadcast
				Some(inbound) = self.messages_in.recv() => {
					self.on_message_received(inbound);
				}

				// The gossip topic has an event
				gossip_event = topic_rx.next() => {
					self.on_topic_rx(gossip_event, &mut topic_rx, &mut topic_tx).await?;
				}

				// The local catalog has been updated
				Ok(()) = self.catalog.changed() => {
					self.on_catalog_update();
				}

				// Manual dial request
				Some((peers, tx)) = self.dials.recv() => {
					self.dial_peers(peers, &topic_tx, tx).await;
				}
			}
		}
	}

	/// Initializes the gossip topic for discovery.
	///
	/// This joins an iroh-gossip topic based on the network ID.
	async fn join_gossip_topic(&self) -> Result<GossipTopic, Error> {
		let topic_id = self.local.network_id().into();
		let mut peers = self.config.bootstrap_peers_ids();
		for peer in self.catalog.borrow().peers() {
			if *peer.id() != self.local.id() {
				peers.push(*peer.id());
			}
		}
		let topic = self.gossip.subscribe(topic_id, peers).await?;
		Ok(topic)
	}

	/// Handles events from the iroh gossip topic in their raw form.
	///
	/// This method processes low-level gossip events such as connection drops,
	/// errors, and received messages, delegating to specific handlers as needed.
	///
	/// When a topic is closed, it attempts to rejoin the topic.
	async fn on_topic_rx(
		&self,
		gossip_event: Option<Result<GossipEvent, GossipError>>,
		topic_rx: &mut GossipReceiver,
		topic_tx: &mut GossipSender,
	) -> Result<(), Error> {
		match gossip_event {
			None | Some(Err(GossipError::Closed { .. })) => {
				// topic connection dropped, re-join
				tracing::warn!(
					network = %self.local.network_id(),
					"announcement gossip network connection lost, attempting to re-join"
				);
				self.rejoin_topic(topic_tx, topic_rx).await?;
			}
			Some(Err(e)) => {
				tracing::warn!(
					error = %e,
					network = %self.local.network_id(),
					"announcement gossip network down"
				);
				self.rejoin_topic(topic_tx, topic_rx).await?;
			}
			Some(Ok(event)) => {
				self.on_gossip_event(event, topic_tx).await;
			}
		}

		Ok(())
	}

	/// Handle gossip-level events.
	///
	/// This method handles the happy-path gossip events, such as new neighbors
	/// joining and messages being received.
	async fn on_gossip_event(&self, event: GossipEvent, topic_tx: &GossipSender) {
		match event {
			GossipEvent::NeighborUp(id) => {
				self.increment_neighbor_count();
				tracing::trace!(
					network = %self.local.network_id(),
					peer_id = %Short(&id),
					neighbors = self.neighbors_count.load(Ordering::SeqCst),
					"New gossip neighbor connected"
				);

				// Broadcast our own info to the new neighbor
				self.broadcast_self_info();
			}
			GossipEvent::NeighborDown(id) => {
				self.decrement_neighbor_count(topic_tx).await;
				tracing::trace!(
					network = %self.local.network_id(),
					peer_id = %Short(&id),
					neighbors = self.neighbors_count.load(Ordering::SeqCst),
					"Gossip neighbor disconnected"
				);
			}
			GossipEvent::Received(message) => {
				let Ok(decoded) = deserialize(&message.content) else {
					tracing::warn!(
						network = %self.local.network_id(),
						"failed to decode announcement message"
					);
					// todo: Ban peer due to protocol violation
					return;
				};

				self.on_message_received(decoded);
			}
			GossipEvent::Lagged => {
				// we lost track of some updates, put the system in a safe state
				// and re-sync the catalog with the next peer interaction
				self.set_neighbor_count(0, topic_tx).await;
			}
		}
	}

	/// A message has been received from the gossip topic.
	fn on_message_received(&self, message: AnnouncementMessage) {
		match message {
			// a peer is announcing an updated version of its own entry
			AnnouncementMessage::OwnEntryUpdate(entry) => {
				if entry.network_id() != self.local.network_id() {
					tracing::trace!(
						peer_network = %Short(entry.network_id()),
						this_network = %Short(self.local.network_id()),
						"received peer entry from different network, ignoring"
					);
					return;
				}

				// Check if the update timestamp is within allowed drift
				let Ok(time_diff) = (Utc::now() - entry.updated_at()).abs().to_std()
				else {
					tracing::trace!(
						peer_id = %Short(&entry.id()),
						network = %Short(entry.network_id()),
						"ignoring discovery entry with invalid timestamp"
					);
					return;
				};

				if time_diff > self.config.max_time_drift {
					tracing::trace!(
						peer_id = %Short(&entry.id()),
						network = %Short(entry.network_id()),
						time_diff = ?time_diff,
						max_drift = ?self.config.max_time_drift,
						"ignoring discovery entry with stale timestamp"
					);
					return;
				}

				// Update local state or catalog as needed
				let _ = self.events.send(Event::PeerEntryReceived(entry));
			}

			// a peer is gracefully departing the network
			AnnouncementMessage::GracefulDeparture(departure) => {
				if !departure.has_valid_signature() {
					tracing::trace!(
						peer_id = %Short(&departure.peer_id),
						"received graceful departure with invalid signature, ignoring"
					);
					return;
				}

				let time_diff = (Utc::now() - departure.timestamp)
					.abs()
					.to_std()
					.unwrap_or(Duration::MAX);

				if time_diff > self.config.max_time_drift {
					tracing::trace!(
						peer_id = %Short(&departure.peer_id),
						time_diff = ?time_diff,
						max_drift = ?self.config.max_time_drift,
						"received graceful departure with invalid timestamp, ignoring"
					);
					return;
				}

				let _ = self.events.send(Event::PeerDeparted(
					departure.peer_id,
					departure.last_version,
				));
			}
		}
	}

	/// Handles updates to the local peer entry in the catalog.
	fn on_catalog_update(&mut self) {
		let current_local_version = self.catalog.borrow().local().update_version();
		if current_local_version > self.last_own_version {
			self.broadcast_self_info();
			self.last_own_version = current_local_version;
		}
	}

	/// Broadcasts the latest version of the local peer entry to the gossip topic.
	///
	/// If the local node is not connected to at least one gossip neighbor, this
	/// function returns early without broadcasting.
	///
	/// We distinguish between periodic and immediate broadcasts for logging
	/// purposes.
	fn broadcast_self_info(&self) {
		let entry = self.catalog.borrow().local().clone();

		tracing::trace!(
			peer_info = ?Pretty(&entry),
			network = %self.local.network_id(),
			"broadcasting local"
		);

		self
			.messages_out
			.send(AnnouncementMessage::OwnEntryUpdate(entry));
	}

	/// Broadcasts an announcement message to the gossip topic.
	///
	/// This method checks if there are any connected neighbors before
	/// broadcasting. If there are no neighbors, it defers the broadcast by
	/// re-queuing the message for later sending.
	///
	/// If the topic connection is closed, it attempts to re-join the topic.
	async fn broadcast_message(
		&self,
		topic_tx: &mut GossipSender,
		topic_rx: &mut GossipReceiver,
		message: AnnouncementMessage,
	) -> Result<(), Error> {
		if !topic_rx.is_joined() {
			tracing::debug!(
				network = %self.local.network_id(),
				"not connected to any gossip neighbors, \
				 deferring announcement broadcast"
			);

			// Re-queue the message for later retry
			self.messages_out.send(message);
			return Ok(());
		}

		if let Err(e) = topic_tx.broadcast(serialize(&message)).await {
			tracing::warn!(
				error = %e,
				network = %self.local.network_id(),
				message = ?message,
				"failed to broadcast announcement message"
			);

			if matches!(e, GossipError::Closed { .. }) {
				// topic connection dropped, re-join
				tracing::warn!(
					network = %self.local.network_id(),
					"announcement gossip network connection lost, attempting to re-join"
				);

				self.rejoin_topic(topic_tx, topic_rx).await?;
			}
		} else {
			// successfully broadcasted the message, update neighbors stats
			self
				.set_neighbor_count(topic_rx.neighbors().count(), topic_tx)
				.await;
		}

		Ok(())
	}

	async fn dial_peers(
		&self,
		peers: Vec<EndpointAddr>,
		topic_tx: &GossipSender,
		tx: oneshot::Sender<()>,
	) {
		self.local.observe(peers.iter());
		let peer_ids = peers.into_iter().map(|p| p.id).collect::<Vec<_>>();

		tracing::trace!(
			network = %self.local.network_id(),
			peers = %Short::iter(&peer_ids),
			"Dialing peers"
		);

		if let Err(e) = topic_tx.join_peers(peer_ids).await {
			tracing::warn!(
				error = %e,
				network = %self.local.network_id(),
				"failed to dial peers via announcement gossip network"
			);
		}

		let _ = tx.send(());
	}

	/// This method is invoked when the gossip topic connection is closed.
	/// It attempts to re-join the topic to restore connectivity.
	async fn rejoin_topic(
		&self,
		topic_tx: &mut GossipSender,
		topic_rx: &mut GossipReceiver,
	) -> Result<(), Error> {
		self.neighbors_count.store(0, Ordering::SeqCst);
		let (new_topic_tx, new_topic_rx) = self.join_gossip_topic().await?.split();
		*topic_tx = new_topic_tx;
		*topic_rx = new_topic_rx;
		Ok(())
	}

	/// Triggered when the network is shutting down.
	///
	/// This broadcasts a graceful departure message to inform peers
	/// of the impending disconnection.
	///
	/// It then waits for a configured duration to allow the message
	/// to propagate before completing the shutdown process.
	async fn shutdown(self, topic_tx: &GossipSender, topic_rx: &GossipReceiver) {
		tracing::trace!(
			network = %self.local.network_id(),
			peer_id = %Short(&self.local.id()),
			"Discovery announcement protocol shutting down"
		);

		if topic_rx.is_joined() {
			let goodbye = AnnouncementMessage::GracefulDeparture(
				GracefulDeparture::new(&self.local, self.last_own_version),
			);

			if let Err(e) = topic_tx.broadcast(serialize(&goodbye)).await {
				tracing::warn!(
					error = %e,
					network = %self.local.network_id(),
					"failed to broadcast graceful departure message"
				);
			} else {
				tracing::trace!(
					network = %self.local.network_id(),
					peer_id = %Short(&self.local.id()),
					"broadcasted graceful departure message"
				);

				// give the broadcasted message some time to propagate before
				// disconnecting from the gossip topic
				tokio::time::sleep(self.config.graceful_departure_window).await;
			}
		}
	}

	fn increment_neighbor_count(&self) {
		self.neighbors_count.fetch_add(1, Ordering::SeqCst);
	}

	async fn decrement_neighbor_count(&self, topic_tx: &GossipSender) {
		if self.neighbors_count.fetch_sub(1, Ordering::SeqCst) == 1 {
			// if we are left with no neighbors, attempt connect to all known peers in
			// the catalog to re-establish connectivity
			let mut peers = Vec::with_capacity(self.catalog.borrow().peers_count());
			for peer in self.catalog.borrow().peers() {
				if *peer.id() != self.local.id() {
					self.local.observe(peer.address());
					peers.push(*peer.id());
				}
			}
			topic_tx.join_peers(peers).await.ok();
		}
	}

	async fn set_neighbor_count(&self, count: usize, topic_tx: &GossipSender) {
		self.neighbors_count.store(count, Ordering::SeqCst);

		if count == 0 {
			// if we are left with no neighbors, attempt connect to all known peers in
			// the catalog to re-establish connectivity
			let mut peers = Vec::with_capacity(self.catalog.borrow().peers_count());
			for peer in self.catalog.borrow().peers() {
				if *peer.id() != self.local.id() {
					self.local.observe(peer.address());
					peers.push(*peer.id());
				}
			}
			topic_tx.join_peers(peers).await.ok();
		}
	}
}

/// Wire format for announcement messages.
#[derive(Debug, Clone, Serialize, Deserialize)]
enum AnnouncementMessage {
	/// Broadcasted when a peer updates its own entry.
	OwnEntryUpdate(SignedPeerEntry),

	/// Broadcasted when a peer is gracefully departing the network.
	GracefulDeparture(GracefulDeparture),
}

/// A message indicating a peer is gracefully departing the network.
#[derive(Debug, Clone, Serialize, Deserialize)]
struct GracefulDeparture {
	peer_id: PeerId,
	last_version: PeerEntryVersion,
	timestamp: chrono::DateTime<Utc>,
	signature: Signature,
}

impl GracefulDeparture {
	pub fn new(local: &LocalNode, last_version: PeerEntryVersion) -> Self {
		let timestamp = Utc::now();
		let mut hasher = blake3::Hasher::default();

		hasher.update(local.id().as_bytes());
		hasher.update(&last_version.0.to_be_bytes());
		hasher.update(&last_version.1.to_be_bytes());
		hasher.update(&timestamp.timestamp_millis().to_be_bytes());
		let hash = hasher.finalize();

		let signature = local.secret_key().sign(hash.as_bytes());

		Self {
			peer_id: local.id(),
			last_version,
			timestamp,
			signature,
		}
	}

	pub fn has_valid_signature(&self) -> bool {
		let mut hasher = blake3::Hasher::default();

		hasher.update(self.peer_id.as_bytes());
		hasher.update(&self.last_version.0.to_be_bytes());
		hasher.update(&self.last_version.1.to_be_bytes());
		hasher.update(&self.timestamp.timestamp_millis().to_be_bytes());
		let hash = hasher.finalize();

		self
			.peer_id
			.verify(hash.as_bytes(), &self.signature)
			.is_ok()
	}
}