Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport: Implement TransportService::local_peer_id() #224

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/protocol/libp2p/kademlia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ pub(crate) struct Kademlia {
impl Kademlia {
/// Create new [`Kademlia`].
pub(crate) fn new(mut service: TransportService, config: Config) -> Self {
let local_peer_id = service.local_peer_id;
let local_key = Key::from(service.local_peer_id);
let local_peer_id = service.local_peer_id();
let local_key = Key::from(service.local_peer_id());
let mut routing_table = RoutingTable::new(local_key.clone());

for (peer, addresses) in config.known_peers {
Expand Down Expand Up @@ -357,7 +357,7 @@ impl Kademlia {
/// the mode was set to manual.
async fn update_routing_table(&mut self, peers: &[KademliaPeer]) {
let peers: Vec<_> =
peers.iter().filter(|peer| peer.peer != self.service.local_peer_id).collect();
peers.iter().filter(|peer| peer.peer != self.service.local_peer_id()).collect();

// inform user about the routing table update, regardless of what the routing table update
// mode is
Expand Down Expand Up @@ -892,7 +892,7 @@ impl Kademlia {

// Put the record to the specified peers.
let peers = peers.into_iter().filter_map(|peer| {
if peer == self.service.local_peer_id {
if peer == self.service.local_peer_id() {
return None;
}

Expand Down
7 changes: 6 additions & 1 deletion src/protocol/transport_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ConnectionContext {
#[derive(Debug)]
pub struct TransportService {
/// Local peer ID.
pub(crate) local_peer_id: PeerId,
local_peer_id: PeerId,

/// Protocol.
protocol: ProtocolName,
Expand Down Expand Up @@ -362,6 +362,11 @@ impl TransportService {

connection.primary.force_close()
}

/// Get local peer ID.
pub fn local_peer_id(&self) -> PeerId {
self.local_peer_id
}
}

impl Stream for TransportService {
Expand Down