Skip to content

Commit

Permalink
ETCM-168: Take the TCP port from config rather than wait for the status.
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Nov 3, 2020
1 parent cc2d399 commit 820c273
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.iohk.ethereum.network.discovery.codecs.RLPCodecs
import io.iohk.scalanet.peergroup.udp.StaticUDPPeerGroup
import io.iohk.scalanet.peergroup.InetMultiAddress
import io.iohk.ethereum.utils.LazyLogger
import scala.concurrent.duration._
import java.net.InetAddress

class PeerDiscoveryManager(
Expand Down Expand Up @@ -151,19 +150,21 @@ class PeerDiscoveryManager(
object PeerDiscoveryManager extends LazyLogger {
def props(
discoveryConfig: DiscoveryConfig,
tcpPort: Int,
knownNodesStorage: KnownNodesStorage,
nodeStatusHolder: AtomicReference[NodeStatus]
)(implicit scheduler: Scheduler): Props =
Props(
new PeerDiscoveryManager(
discoveryConfig,
knownNodesStorage,
discoveryServiceResource(discoveryConfig, nodeStatusHolder)
discoveryServiceResource(discoveryConfig, tcpPort, nodeStatusHolder)
)
)

def discoveryServiceResource(
discoveryConfig: DiscoveryConfig,
tcpPort: Int,
nodeStatusHolder: AtomicReference[NodeStatus]
)(implicit scheduler: Scheduler): Resource[Task, v4.DiscoveryService] = {

Expand Down Expand Up @@ -200,10 +201,6 @@ object PeerDiscoveryManager extends LazyLogger {
)

val resource = for {
tcpSocketAddress <- Resource.liftF {
getTcpSocketAddress(nodeStatusHolder)
}

host <- Resource.liftF {
if (discoveryConfig.host.nonEmpty)
Task(InetAddress.getByName(discoveryConfig.host))
Expand All @@ -221,7 +218,7 @@ object PeerDiscoveryManager extends LazyLogger {
address = ENode.Address(
ip = host,
udpPort = discoveryConfig.port,
tcpPort = tcpSocketAddress.getPort
tcpPort = tcpPort
)
)

Expand Down Expand Up @@ -277,19 +274,6 @@ object PeerDiscoveryManager extends LazyLogger {
}
}

// Looks like currently the only way to get the external IP address is to let the TCP
// server actor bind and put it in the NodeStatusHolder, as we don't seem to have the
// ExternalAddressResolver here.
def getTcpSocketAddress(nodeStatusHolder: AtomicReference[NodeStatus]): Task[InetSocketAddress] = {
Task(nodeStatusHolder.get.serverStatus).flatMap {
case ServerStatus.Listening(address) =>
Task.pure(address)
case ServerStatus.NotListening =>
Task(log.debug("Waiting for TCP address...")).delayResult(5.seconds) >>
getTcpSocketAddress(nodeStatusHolder)
}
}

case object Start
case object Stop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ trait PeerDiscoveryManagerBuilder {
lazy val peerDiscoveryManager: ActorRef = system.actorOf(
PeerDiscoveryManager.props(
discoveryConfig,
tcpPort = Config.Network.Server.port,
storagesInstance.storages.knownNodesStorage,
nodeStatusHolder
),
Expand Down

0 comments on commit 820c273

Please sign in to comment.