Skip to content

Commit e9c252e

Browse files
authored
Merge pull request #107 from input-output-hk/ETCM-393-expose-lookup
ETCM-393: Expose the lookup methods on DiscoveryService
2 parents 73dc642 + 233174f commit e9c252e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ trait ScalanetModule extends ScalaModule {
6868
trait ScalanetPublishModule extends PublishModule {
6969
def description: String
7070

71-
override def publishVersion = "0.4.2-SNAPSHOT"
71+
override def publishVersion = "0.4.3-SNAPSHOT"
7272

7373
override def pomSettings = PomSettings(
7474
description = description,

scalanet/discovery/src/io/iohk/scalanet/discovery/ethereum/v4/DiscoveryService.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ trait DiscoveryService {
4242

4343
/** The local node representation. */
4444
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]]
4551
}
4652

4753
object DiscoveryService {
@@ -91,7 +97,7 @@ object DiscoveryService {
9197
// Contact the bootstrap nodes.
9298
enroll = service.enroll()
9399
// Periodically discover new nodes.
94-
discover = service.lookupRandom().delayExecution(config.discoveryPeriod).loopForever
100+
discover = service.lookupRandom.delayExecution(config.discoveryPeriod).loopForever
95101
// Enrollment can be run in the background if it takes very long.
96102
discoveryFiber <- if (enrollInBackground) {
97103
(enroll >> discover).start
@@ -695,13 +701,13 @@ object DiscoveryService {
695701
/** Locate the k closest nodes to a node ID.
696702
*
697703
* 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
699705
* arrive from each peer we ask (or if they return k quicker then it returns earlier)
700706
* it could be quite slow if it was used for routing.
701707
*
702708
* https://github.com/ethereum/devp2p/blob/master/discv4.md#recursive-lookup
703709
*/
704-
protected[v4] def lookup(target: Node.Id): Task[SortedSet[Node]] = {
710+
override def lookup(target: Node.Id): Task[SortedSet[Node]] = {
705711
val targetId = Node.kademliaId(target)
706712

707713
implicit val nodeOrdering: Ordering[Node] =
@@ -824,9 +830,9 @@ object DiscoveryService {
824830
}
825831

826832
/** Look up a random node ID to discover new peers. */
827-
protected[v4] def lookupRandom(): Task[Unit] =
833+
override def lookupRandom: Task[Set[Node]] =
828834
Task(logger.info("Looking up a random target...")) >>
829-
lookup(target = sigalg.newKeyPair._1).void
835+
lookup(target = sigalg.newKeyPair._1)
830836

831837
/** Look up self with the bootstrap nodes. First we have to fetch their ENR
832838
* records to verify they are reachable and so that they can participate

scalanet/discovery/ut/src/io/iohk/scalanet/discovery/ethereum/v4/DiscoveryServiceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class DiscoveryServiceSpec extends AsyncFlatSpec with Matchers {
777777

778778
override val test = for {
779779
_ <- addRemotePeer
780-
_ <- service.lookupRandom()
780+
_ <- service.lookupRandom
781781
state <- stateRef.get
782782
} yield {
783783
// We should bond with nodes along the way, so in the end there should

0 commit comments

Comments
 (0)