This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into license-update-to-apache
- Loading branch information
Showing
3 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/scala/scorex/core/network/peer/SessionIdPeerFeature.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package scorex.core.network.peer | ||
|
||
import scorex.core.network.PeerFeature | ||
import scorex.core.network.PeerFeature.Id | ||
import scorex.core.network.message.Message | ||
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 networks | ||
* | ||
* @param networkMagic network magic bytes (taken from settings) | ||
* @param sessionId randomly generated 64-bit session identifier | ||
*/ | ||
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) | ||
} | ||
|
||
override def parse(r: Reader): SessionIdPeerFeature = { | ||
val networkMagic = r.getBytes(Message.MagicLength) | ||
val sessionId = r.getLong() | ||
SessionIdPeerFeature(networkMagic, sessionId) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters