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

perf: use NodeContact instead of Enr for sending talk_req() #279

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
10 changes: 6 additions & 4 deletions src/discv5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ impl<P: ProtocolIdentity> Discv5<P> {
nodes_to_send
}

pub fn ip_mode(&self) -> IpMode {
self.ip_mode
}

/// Mark a node in the routing table as `Disconnected`.
///
/// A `Disconnected` node will be present in the routing table and will be only
Expand Down Expand Up @@ -568,21 +572,19 @@ impl<P: ProtocolIdentity> Discv5<P> {
}
}

/// Request a TALK message from a node, identified via the ENR.
/// Request a TALK message from a node, identified via the NodeContact.
pub fn talk_req(
&self,
enr: Enr,
node_contact: NodeContact,
protocol: Vec<u8>,
request: Vec<u8>,
) -> impl Future<Output = Result<Vec<u8>, RequestError>> + 'static {
// convert the ENR to a node_contact.

let (callback_send, callback_recv) = oneshot::channel();
let channel = self.clone_channel();
let ip_mode = self.ip_mode;

async move {
let node_contact = NodeContact::try_from_enr(enr, ip_mode)?;
let channel = channel.map_err(|_| RequestError::ServiceNotStarted)?;

let event = ServiceRequest::Talk(node_contact, protocol, request, callback_send);
Expand Down