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

Commit 6031b38

Browse files
committed
Small style tweaks
1 parent c3f6e0e commit 6031b38

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/kotlin/crawler.kt

+13-13
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
8484
override fun onPreMessageReceived(peer: Peer, m: Message): Message {
8585
if (m is AddressMessage) {
8686
Threading.USER_THREAD execute {
87-
val fresh = m.getAddresses().filterNot { addrMap.containsKey(it.getSocketAddress()) }
87+
val fresh = m.getAddresses() filterNot { addrMap containsKey it.getSocketAddress() }
8888
if (fresh.isNotEmpty()) {
89-
log.info("Got ${fresh.size()} new address(es) from ${peer}")
89+
log.info("Got ${fresh.size()} new address(es) from ${peer}: ${fresh}")
9090
queueAddrs(m)
9191
crawl()
9292
}
@@ -104,7 +104,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
104104
log.info("Kicking off crawl with some peers from previous run")
105105
console.numOKPeers = okPeers.size()
106106
Threading.USER_THREAD.execute() {
107-
okPeers.take(20).forEach { attemptConnect(it) }
107+
okPeers.take(20) forEach { attemptConnect(it) }
108108
}
109109
}
110110
}
@@ -121,7 +121,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
121121
val data = addrMap[p]
122122
var doConnect = if (data == null) {
123123
// Not seen this address before and not already probing it
124-
addrMap.put(p, PeerData(PeerStatus.UNTESTED, 0, Instant.now()))
124+
addrMap[p] = PeerData(PeerStatus.UNTESTED, 0, Instant.now())
125125
console.numKnownAddresses = addrMap.size()
126126
db.commit()
127127
true
@@ -135,9 +135,9 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
135135
}
136136

137137
private fun markAs(addr: InetSocketAddress, status: PeerStatus): PeerStatus {
138-
val cur = addrMap.get(addr)!!
138+
val cur = addrMap[addr]!!
139139
val newData = cur.copy(status = status, lastCrawlTime = Instant.now())
140-
addrMap.put(addr, newData)
140+
addrMap[addr] = newData
141141
console.numKnownAddresses = addrMap.size()
142142
db.commit()
143143
synchronized(this) {
@@ -148,7 +148,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
148148
}
149149

150150
private fun markAsOK(addr: InetSocketAddress, peer: Peer) {
151-
val peerData = addrMap.get(addr)
151+
val peerData: PeerData? = addrMap[addr]
152152
val oldStatus = peerData?.status
153153
if (oldStatus == PeerStatus.UNREACHABLE && peerData!!.lastSuccessTime != null)
154154
log.info("Peer ${addr} came back from the dead")
@@ -158,7 +158,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
158158
serviceBits = peer.getPeerVersionMessage().localServices,
159159
lastSuccessTime = Instant.now()
160160
)
161-
addrMap.put(addr, newData)
161+
addrMap[addr] = newData
162162
console.numKnownAddresses = addrMap.size()
163163
db.commit()
164164

@@ -196,7 +196,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
196196
}
197197

198198
private fun queueAddrs(addr: AddressMessage) {
199-
addressQueue.addAll(addr.getAddresses().map {
199+
addressQueue.addAll(addr.getAddresses() map {
200200
val sockaddr = it.toSocketAddress()
201201
// If we found a peer on the same machine as the cartographer, look up our own hostname to find the public IP
202202
// instead of publishing localhost.
@@ -262,7 +262,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
262262
log.warn("Got ${answer}")
263263
} else {
264264
log.info("Peer ${sockaddr} is flagged as supporting GETUTXO and passed the test query")
265-
addrMap.put(sockaddr, addrMap.get(sockaddr)!!.copy(supportsGetUTXO = true))
265+
addrMap[sockaddr] = addrMap[sockaddr]!!.copy(supportsGetUTXO = true)
266266
db.commit()
267267
}
268268
} catch (e: TimeoutException) {
@@ -282,12 +282,12 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
282282
val addrs: List<InetSocketAddress> = if (serviceMask == -1L) {
283283
size.gatherTimes { okPeers.poll() }.filterNotNull()
284284
} else {
285-
val matches = okPeers.filter { addrMap.get(it)!!.serviceBits and serviceMask == serviceMask }.take(size)
285+
val matches = okPeers.filter { addrMap[it]!!.serviceBits and serviceMask == serviceMask }.take(size)
286286
okPeers.removeAll(matches)
287287
matches
288288
}
289289
okPeers.addAll(addrs)
290-
return addrs.map { it to addrMap.get(it)!! }
290+
return addrs.map { it to addrMap[it]!! }
291291
}
292292

293293
synchronized private fun populateOKPeers() {
@@ -315,6 +315,6 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
315315

316316
private fun scheduleRecrawlsFromDB() {
317317
// Recrawl peers in the db that are either considered OK, or have disappeared recently
318-
addrMap.filter { it.getValue().shouldRecrawl() }.map { it.getKey() }.forEach { scheduleRecrawl(it) }
318+
addrMap filter { it.getValue().shouldRecrawl() } map { it.getKey() } forEach { scheduleRecrawl(it) }
319319
}
320320
}

0 commit comments

Comments
 (0)