referrerpolicy=no-referrer-when-downgrade

polkadot_node_network_protocol/
authority_discovery.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Authority discovery service interfacing.
18
19use std::{collections::HashSet, fmt::Debug};
20
21use async_trait::async_trait;
22
23use sc_authority_discovery::Service as AuthorityDiscoveryService;
24
25use polkadot_primitives::AuthorityDiscoveryId;
26use sc_network::Multiaddr;
27use sc_network_types::PeerId;
28
29/// An abstraction over the authority discovery service.
30///
31/// Needed for mocking in tests mostly.
32#[async_trait]
33pub trait AuthorityDiscovery: Send + Debug + 'static {
34	/// Get the addresses for the given [`AuthorityDiscoveryId`] from the local address cache.
35	async fn get_addresses_by_authority_id(
36		&mut self,
37		authority: AuthorityDiscoveryId,
38	) -> Option<HashSet<Multiaddr>>;
39	/// Get the [`AuthorityDiscoveryId`] for the given [`PeerId`] from the local address cache.
40	async fn get_authority_ids_by_peer_id(
41		&mut self,
42		peer_id: PeerId,
43	) -> Option<HashSet<AuthorityDiscoveryId>>;
44}
45
46#[async_trait]
47impl AuthorityDiscovery for AuthorityDiscoveryService {
48	async fn get_addresses_by_authority_id(
49		&mut self,
50		authority: AuthorityDiscoveryId,
51	) -> Option<HashSet<Multiaddr>> {
52		AuthorityDiscoveryService::get_addresses_by_authority_id(self, authority).await
53	}
54
55	async fn get_authority_ids_by_peer_id(
56		&mut self,
57		peer_id: PeerId,
58	) -> Option<HashSet<AuthorityDiscoveryId>> {
59		AuthorityDiscoveryService::get_authority_ids_by_peer_id(self, peer_id).await
60	}
61}