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

Commit a6fe141

Browse files
authored
fixing PeerConnectionHandler (#396)
* fixing PeerConnectionHandler Signed-off-by: pragmaxim <pragmaxim@gmail.com> * adding handy SyncTracker.peersByStatus method Signed-off-by: pragmaxim <pragmaxim@gmail.com>
1 parent 30f3bea commit a6fe141

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/main/scala/scorex/core/network/SyncTracker.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class SyncTracker(nvsRef: ActorRef,
9292
private def outdatedPeers(): Seq[ConnectedPeer] =
9393
lastSyncSentTime.filter(t => (timeProvider.time() - t._2).millis > maxInterval()).keys.toSeq
9494

95+
96+
def peersByStatus: Map[HistoryComparisonResult, Iterable[ConnectedPeer]] =
97+
statuses.groupBy(_._2).mapValues(_.keys).view.force
98+
9599
private def numOfSeniors(): Int = statuses.count(_._2 == Older)
96100

97101
/**

src/main/scala/scorex/core/network/message/MessageSerializer.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,19 @@ class MessageSerializer(specs: Seq[MessageSpec[_]], magicBytes: Array[Byte]) {
4343
val msgCode = it.getByte
4444
val length = it.getInt
4545

46-
//peer is from another network
47-
if (!java.util.Arrays.equals(magic, magicBytes)) {
48-
throw MaliciousBehaviorException(s"Wrong magic bytes, expected ${magicBytes.mkString}, got ${magic.mkString}")
49-
}
50-
5146
//peer is trying to cause buffer overflow or breaking the parsing
5247
if (length < 0) {
5348
throw MaliciousBehaviorException("Data length is negative!")
5449
}
5550

56-
val spec = specsMap.getOrElse(msgCode, throw new Error(s"No message handler found for $msgCode"))
57-
5851
if (length != 0 && byteString.length < length + HeaderLength + ChecksumLength) {
5952
None
6053
} else {
54+
//peer is from another network
55+
if (!java.util.Arrays.equals(magic, magicBytes)) {
56+
throw MaliciousBehaviorException(s"Wrong magic bytes, expected ${magicBytes.mkString}, got ${magic.mkString} in : ${byteString.utf8String}")
57+
}
58+
val spec = specsMap.getOrElse(msgCode, throw new Error(s"No message handler found for $msgCode"))
6159
val msgData = if (length > 0) {
6260
val checksum = it.getBytes(ChecksumLength)
6361
val data = it.getBytes(length)

0 commit comments

Comments
 (0)