Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed serializing #2048

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/scala/scorex/core/network/ConnectedPeer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import scorex.core.network.peer.PeerInfo
*
* @param connectionId - connection address
* @param handlerRef - reference to PeerConnectionHandler that is responsible for communication with this peer
* @param lastMessage - timestamp of last received message
* @param peerInfo - information about this peer. May be None if peer is connected, but is not handshaked yet
*/
case class ConnectedPeer(connectionId: ConnectionId,
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/scorex/core/network/NetworkController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ class NetworkController(ergoSettings: ErgoSettings,
peerManagerRef ! RemovePeer(peerAddress)
connections -= connectedPeer.connectionId.remoteAddress
} else {
peerManagerRef ! AddOrUpdatePeer(peerInfo)
val newPeerInfo = peerInfo.copy(lastStoredActivityTime = time())
peerManagerRef ! AddOrUpdatePeer(newPeerInfo)

val updatedConnectedPeer = connectedPeer.copy(peerInfo = Some(peerInfo))
val updatedConnectedPeer = connectedPeer.copy(peerInfo = Some(newPeerInfo))
connections += remoteAddress -> updatedConnectedPeer
context.system.eventStream.publish(HandshakedPeer(updatedConnectedPeer))
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/scorex/core/network/peer/PeerInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object PeerInfo {
*/
def fromAddress(address: InetSocketAddress): PeerInfo = {
val peerSpec = PeerSpec("unknown", Version.initial, s"unknown-$address", Some(address), Seq())
PeerInfo(peerSpec, 0L, None)
PeerInfo(peerSpec, 0L, None, 0L)
}

}
Expand All @@ -51,12 +51,14 @@ object PeerInfoSerializer extends ErgoSerializer[PeerInfo] {
w.putLong(obj.lastHandshake)
w.putOption(obj.connectionType)((w,d) => w.putBoolean(d.isIncoming))
PeerSpecSerializer.serialize(obj.peerSpec, w)
w.putLong(obj.lastStoredActivityTime)
}

override def parse(r: Reader): PeerInfo = {
val lastHandshake = r.getLong()
val connectionType = r.getOption(if (r.getUByte() != 0) Incoming else Outgoing)
val peerSpec = PeerSpecSerializer.parse(r)
PeerInfo(peerSpec, lastHandshake, connectionType)
val lastStoredTime = r.getLong()
PeerInfo(peerSpec, lastHandshake, connectionType, lastStoredTime)
}
}