@@ -84,9 +84,9 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
84
84
override fun onPreMessageReceived (peer : Peer , m : Message ): Message {
85
85
if (m is AddressMessage ) {
86
86
Threading .USER_THREAD execute {
87
- val fresh = m.getAddresses(). filterNot { addrMap. containsKey( it.getSocketAddress() ) }
87
+ val fresh = m.getAddresses() filterNot { addrMap containsKey it.getSocketAddress() }
88
88
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} " )
90
90
queueAddrs(m)
91
91
crawl()
92
92
}
@@ -104,7 +104,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
104
104
log.info(" Kicking off crawl with some peers from previous run" )
105
105
console.numOKPeers = okPeers.size()
106
106
Threading .USER_THREAD .execute() {
107
- okPeers.take(20 ). forEach { attemptConnect(it) }
107
+ okPeers.take(20 ) forEach { attemptConnect(it) }
108
108
}
109
109
}
110
110
}
@@ -121,7 +121,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
121
121
val data = addrMap[p]
122
122
var doConnect = if (data == null ) {
123
123
// 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())
125
125
console.numKnownAddresses = addrMap.size()
126
126
db.commit()
127
127
true
@@ -135,9 +135,9 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
135
135
}
136
136
137
137
private fun markAs (addr : InetSocketAddress , status : PeerStatus ): PeerStatus {
138
- val cur = addrMap.get( addr) !!
138
+ val cur = addrMap[ addr] !!
139
139
val newData = cur.copy(status = status, lastCrawlTime = Instant .now())
140
- addrMap.put( addr, newData)
140
+ addrMap[ addr] = newData
141
141
console.numKnownAddresses = addrMap.size()
142
142
db.commit()
143
143
synchronized(this ) {
@@ -148,7 +148,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
148
148
}
149
149
150
150
private fun markAsOK (addr : InetSocketAddress , peer : Peer ) {
151
- val peerData = addrMap.get( addr)
151
+ val peerData: PeerData ? = addrMap[ addr]
152
152
val oldStatus = peerData?.status
153
153
if (oldStatus == PeerStatus .UNREACHABLE && peerData!! .lastSuccessTime != null )
154
154
log.info(" Peer ${addr} came back from the dead" )
@@ -158,7 +158,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
158
158
serviceBits = peer.getPeerVersionMessage().localServices,
159
159
lastSuccessTime = Instant .now()
160
160
)
161
- addrMap.put( addr, newData)
161
+ addrMap[ addr] = newData
162
162
console.numKnownAddresses = addrMap.size()
163
163
db.commit()
164
164
@@ -196,7 +196,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
196
196
}
197
197
198
198
private fun queueAddrs (addr : AddressMessage ) {
199
- addressQueue.addAll(addr.getAddresses(). map {
199
+ addressQueue.addAll(addr.getAddresses() map {
200
200
val sockaddr = it.toSocketAddress()
201
201
// If we found a peer on the same machine as the cartographer, look up our own hostname to find the public IP
202
202
// instead of publishing localhost.
@@ -262,7 +262,7 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
262
262
log.warn(" Got ${answer} " )
263
263
} else {
264
264
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 )
266
266
db.commit()
267
267
}
268
268
} catch (e: TimeoutException ) {
@@ -282,12 +282,12 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
282
282
val addrs: List <InetSocketAddress > = if (serviceMask == - 1L ) {
283
283
size.gatherTimes { okPeers.poll() }.filterNotNull()
284
284
} 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)
286
286
okPeers.removeAll(matches)
287
287
matches
288
288
}
289
289
okPeers.addAll(addrs)
290
- return addrs.map { it to addrMap.get(it) !! }
290
+ return addrs.map { it to addrMap[it] !! }
291
291
}
292
292
293
293
synchronized private fun populateOKPeers () {
@@ -315,6 +315,6 @@ class Crawler(private val console: Console, private val workingDir: Path, privat
315
315
316
316
private fun scheduleRecrawlsFromDB () {
317
317
// 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) }
319
319
}
320
320
}
0 commit comments