Refine processLines
This commit is contained in:
@@ -4,6 +4,7 @@ import be.mygod.vpnhotspot.net.IpDev
|
||||
import be.mygod.vpnhotspot.net.IpNeighbour
|
||||
import kotlinx.collections.immutable.PersistentMap
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
import kotlinx.collections.immutable.toPersistentMap
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.channels.*
|
||||
|
||||
@@ -71,11 +72,11 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
}
|
||||
|
||||
override suspend fun processLines(lines: Sequence<String>) {
|
||||
neighbours = lines
|
||||
.flatMap { IpNeighbour.parse(it, fullMode).asSequence() }
|
||||
.filter { it.state != IpNeighbour.State.DELETING } // skip entries without lladdr
|
||||
.associateByTo(persistentMapOf<IpDev, IpNeighbour>().builder()) { IpDev(it) }
|
||||
.build()
|
||||
neighbours = mutableMapOf<IpDev, IpNeighbour>().apply {
|
||||
for (line in lines) for (neigh in IpNeighbour.parse(line, fullMode)) {
|
||||
if (neigh.state != IpNeighbour.State.DELETING) this[IpDev(neigh)] = neigh
|
||||
}
|
||||
}.toPersistentMap()
|
||||
aggregator.trySendBlocking(neighbours).onFailure { throw it!! }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user