@@ -42,6 +42,12 @@ trait DiscoveryService {
42
42
43
43
/** The local node representation. */
44
44
def getLocalNode : Task [Node ]
45
+
46
+ /** Lookup the nodes closest to a given target. */
47
+ def lookup (target : Node .Id ): Task [SortedSet [Node ]]
48
+
49
+ /** Lookup a random target, to discovery new nodes along the way. */
50
+ def lookupRandom : Task [Set [Node ]]
45
51
}
46
52
47
53
object DiscoveryService {
@@ -91,7 +97,7 @@ object DiscoveryService {
91
97
// Contact the bootstrap nodes.
92
98
enroll = service.enroll()
93
99
// Periodically discover new nodes.
94
- discover = service.lookupRandom() .delayExecution(config.discoveryPeriod).loopForever
100
+ discover = service.lookupRandom.delayExecution(config.discoveryPeriod).loopForever
95
101
// Enrollment can be run in the background if it takes very long.
96
102
discoveryFiber <- if (enrollInBackground) {
97
103
(enroll >> discover).start
@@ -695,13 +701,13 @@ object DiscoveryService {
695
701
/** Locate the k closest nodes to a node ID.
696
702
*
697
703
* Note that it keeps going even if we know the target or find it along the way.
698
- * Due to the way it allows by default 7 seconds for the k closest neihbors to
704
+ * Due to the way it allows by default 7 seconds for the k closest neighbors to
699
705
* arrive from each peer we ask (or if they return k quicker then it returns earlier)
700
706
* it could be quite slow if it was used for routing.
701
707
*
702
708
* https://github.com/ethereum/devp2p/blob/master/discv4.md#recursive-lookup
703
709
*/
704
- protected [v4] def lookup (target : Node .Id ): Task [SortedSet [Node ]] = {
710
+ override def lookup (target : Node .Id ): Task [SortedSet [Node ]] = {
705
711
val targetId = Node .kademliaId(target)
706
712
707
713
implicit val nodeOrdering : Ordering [Node ] =
@@ -824,9 +830,9 @@ object DiscoveryService {
824
830
}
825
831
826
832
/** Look up a random node ID to discover new peers. */
827
- protected [v4] def lookupRandom () : Task [Unit ] =
833
+ override def lookupRandom : Task [Set [ Node ] ] =
828
834
Task (logger.info(" Looking up a random target..." )) >>
829
- lookup(target = sigalg.newKeyPair._1).void
835
+ lookup(target = sigalg.newKeyPair._1)
830
836
831
837
/** Look up self with the bootstrap nodes. First we have to fetch their ENR
832
838
* records to verify they are reachable and so that they can participate
0 commit comments