mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(disc): add set_lookup_interval function (#696)
This commit is contained in:
@ -207,6 +207,11 @@ impl Discv4 {
|
||||
self.local_addr
|
||||
}
|
||||
|
||||
/// Sets the [Interval] used for periodically looking up targets over the network
|
||||
pub fn set_lookup_interval(&self, duration: Duration) {
|
||||
self.safe_send_to_service(Discv4Command::SetLookupInterval(duration))
|
||||
}
|
||||
|
||||
/// Starts a `FindNode` recursive lookup that locates the closest nodes to the given node id. See also: <https://github.com/ethereum/devp2p/blob/master/discv4.md#recursive-lookup>
|
||||
///
|
||||
/// The lookup initiator starts by picking α closest nodes to the target it knows of. The
|
||||
@ -482,6 +487,11 @@ impl Discv4Service {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the [Interval] used for periodically looking up targets over the network
|
||||
pub fn set_lookup_interval(&mut self, duration: Duration) {
|
||||
self.lookup_interval = tokio::time::interval(duration);
|
||||
}
|
||||
|
||||
/// Sets the given ip address as the node's external IP in the node record announced in
|
||||
/// discovery
|
||||
pub fn set_external_ip_addr(&mut self, external_ip: IpAddr) {
|
||||
@ -1296,6 +1306,9 @@ impl Discv4Service {
|
||||
let node_id = node_id.unwrap_or(self.local_node_record.id);
|
||||
self.lookup_with(node_id, tx);
|
||||
}
|
||||
Discv4Command::SetLookupInterval(duration) => {
|
||||
self.set_lookup_interval(duration);
|
||||
}
|
||||
Discv4Command::Updates(tx) => {
|
||||
let rx = self.update_stream();
|
||||
let _ = tx.send(rx);
|
||||
@ -1476,6 +1489,7 @@ enum Discv4Command {
|
||||
BanIp(IpAddr),
|
||||
Remove(PeerId),
|
||||
Lookup { node_id: Option<PeerId>, tx: Option<NodeRecordSender> },
|
||||
SetLookupInterval(Duration),
|
||||
Updates(OneshotSender<ReceiverStream<DiscoveryUpdate>>),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user