Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot committed Sep 11, 2024
1 parent 4bd23b7 commit 4d1a58f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion node/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ waves {

# How long the information about peer stays in database after the last communication with it.
# This value should be big eno
peers-data-residence-time = 15m
peers-data-residence-time = 1h

# How long peer stays in blacklist after getting in it
black-list-residence-time = 15m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.net.{InetAddress, InetSocketAddress}
import java.util.concurrent.TimeUnit
import scala.annotation.tailrec
import scala.collection.*
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration.{DurationInt, FiniteDuration}
import scala.jdk.CollectionConverters.*
import scala.util.Random
import scala.util.control.NonFatal
Expand Down Expand Up @@ -123,7 +123,7 @@ class PeerDatabaseImpl(settings: NetworkSettings) extends PeerDatabase with Scor
}
}

val knownPeersFromConfig = settings.knownPeers.flatMap(p => inetSocketAddress(p, 6868))
val knownPeersFromConfig = settings.knownPeers.flatMap(p => inetSocketAddress(p, 6868))
val nextCandidateFromConfig = knownPeersFromConfig.filterNot(knownPeers.keySet).headOption

nextCandidateFromConfig
Expand All @@ -138,12 +138,15 @@ class PeerDatabaseImpl(settings: NetworkSettings) extends PeerDatabase with Scor
}

override def close(): Unit = settings.file.foreach { f =>
log.info(s"Saving ${knownPeers.size} known peer(s) to ${f.getName}")
val tsThreshold = System.currentTimeMillis() - 3.minutes.toMillis
val rawPeers = for {
inetAddress <- knownPeers.keySet
address <- Option(inetAddress.getAddress)
(inetAddress, timestamp) <- knownPeers
if timestamp >= tsThreshold
address <- Option(inetAddress.getAddress)
} yield s"${address.getHostAddress}:${inetAddress.getPort}"

log.info(s"Saving ${rawPeers.size} known peer(s) to ${f.getName}")

JsonFileStorage.save[PeersPersistenceType](rawPeers, f.getCanonicalPath)
}

Expand Down

0 comments on commit 4d1a58f

Please sign in to comment.