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

Commit

Permalink
formatting, unused import
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 27, 2020
1 parent 9166d3f commit c537271
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/scorex/core/network/NetworkController.scala
Expand Up @@ -7,7 +7,6 @@ import akka.io.Tcp._
import akka.io.{IO, Tcp}
import akka.pattern.ask
import akka.util.Timeout
import scorex.core.api.http.PeersApiRoute.PeersStatusResponse
import scorex.core.app.{ScorexContext, Version}
import scorex.core.network.NodeViewSynchronizer.ReceivableMessages.{DisconnectedPeer, HandshakedPeer}
import scorex.core.network.message.Message.MessageCode
Expand Down Expand Up @@ -296,8 +295,13 @@ class NetworkController(settings: NetworkSettings,
val isLocal = connectionId.remoteAddress.getAddress.isSiteLocalAddress ||
connectionId.remoteAddress.getAddress.isLoopbackAddress
val mandatoryFeatures = scorexContext.features :+ mySessionIdFeature
val peerFeatures = if (isLocal) mandatoryFeatures :+ LocalAddressPeerFeature(new InetSocketAddress(connectionId.localAddress.getAddress, settings.bindAddress.getPort))
else mandatoryFeatures
val peerFeatures = if (isLocal) {
val la = new InetSocketAddress(connectionId.localAddress.getAddress, settings.bindAddress.getPort)
val localAddrFeature = LocalAddressPeerFeature(la)
mandatoryFeatures :+ localAddrFeature
} else {
mandatoryFeatures
}
val selfAddressOpt = getNodeAddressForPeer(connectionId.localAddress)

if (selfAddressOpt.isEmpty)
Expand Down
14 changes: 11 additions & 3 deletions src/main/scala/scorex/core/network/peer/SessionIdPeerFeature.scala
Expand Up @@ -7,22 +7,29 @@ import scorex.util.serialization._
import scorex.core.serialization.ScorexSerializer

/**
* This peer feature allows to more reliably detect connections to self node and connections from other network
* This peer feature allows to more reliably detect connections to self node and connections from other networks
*
* @param networkMagic network magic bytes (taken from settings)
* @param sessionId randomly generated 64-bit session identifier
* @param sessionId randomly generated 64-bit session identifier
*/
case class SessionIdPeerFeature(networkMagic:Array[Byte], sessionId:Long = scala.util.Random.nextLong()) extends PeerFeature {
case class SessionIdPeerFeature(networkMagic: Array[Byte],
sessionId: Long = scala.util.Random.nextLong()) extends PeerFeature {

override type M = SessionIdPeerFeature
override val featureId: Id = SessionIdPeerFeature.featureId

override def serializer: SessionIdPeerFeatureSerializer.type = SessionIdPeerFeatureSerializer

}

object SessionIdPeerFeature {

val featureId: Id = 3: Byte

}

object SessionIdPeerFeatureSerializer extends ScorexSerializer[SessionIdPeerFeature] {

override def serialize(obj: SessionIdPeerFeature, w: Writer): Unit = {
w.putBytes(obj.networkMagic)
w.putLong(obj.sessionId)
Expand All @@ -33,4 +40,5 @@ object SessionIdPeerFeatureSerializer extends ScorexSerializer[SessionIdPeerFeat
val sessionId = r.getLong()
SessionIdPeerFeature(networkMagic, sessionId)
}

}

0 comments on commit c537271

Please sign in to comment.