Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Unclear logic in NetworkController initialisation #225

Open
mike-aksarin opened this issue Apr 11, 2018 · 2 comments
Open

Unclear logic in NetworkController initialisation #225

mike-aksarin opened this issue Apr 11, 2018 · 2 comments

Comments

@mike-aksarin
Copy link
Contributor

We have the following logics in a NetworkController class initialisation section. Here we validate declaredAddress setting and warn about the validation exceptions, but we don't use the boolean result of the validation that looks weird.

This is line 62, https://github.com/ScorexFoundation/Scorex/blob/master/src/main/scala/scorex/core/network/NetworkController.scala#L62

   //check own declared address for validity
  if (!settings.localOnly) {
    settings.declaredAddress.foreach { myAddress =>
      Try {
        val uri = new URI("http://" + myAddress)
        val myHost = uri.getHost
        val myAddrs = InetAddress.getAllByName(myHost)

        NetworkInterface.getNetworkInterfaces.asScala.exists { intf =>
          intf.getInterfaceAddresses.asScala.exists { intfAddr =>
            val extAddr = intfAddr.getAddress
            myAddrs.contains(extAddr)
          }
        } || (settings.upnpEnabled && myAddrs.exists(_ == upnp.externalAddress))
      } recover { case t: Throwable =>
        log.error("Declared address validation failed: ", t)
      }
    }
  }
@ceilican
Copy link
Contributor

Maybe the goal here is just to emit a warning that declaredAddress is badly configured. If this is the case, then maybe we should use log.warn instead of log.error.

@mike-aksarin
Copy link
Contributor Author

Then we don't need (settings.upnpEnabled && myAddrs.exists(_ == upnp.externalAddress)) check and NetworkInterface.getNetworkInterfaces.asScala.exists should be NetworkInterface.getNetworkInterfaces.asScala.foreach

By the way myAddrs.exists(_ == upnp.externalAddress) is never true as upnp.externalAddress is Option and it could not ever equal to InetAddress

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants