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