Skip to content

Commit

Permalink
Merge pull request #2048 from ccellado/unite_time_delta_info
Browse files Browse the repository at this point in the history
Fixed serializing
  • Loading branch information
kushti committed Oct 7, 2023
2 parents 727b606 + 0ebae16 commit edd390a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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)
}
}

0 comments on commit edd390a

Please sign in to comment.