Refine InterfaceNotFoundException

This commit is contained in:
Mygod
2019-02-01 22:07:31 +08:00
parent 43bb8af522
commit 5c1e84703a

View File

@@ -87,12 +87,16 @@ class Routing(val caller: Any, val downstream: String, ownerAddress: InterfaceAd
None, Simple, Netd None, Simple, Netd
} }
class InterfaceNotFoundException : SocketException() { class InterfaceNotFoundException(override val cause: Throwable) : SocketException() {
override val message: String get() = app.getString(R.string.exception_interface_not_found) override val message: String get() = app.getString(R.string.exception_interface_not_found)
} }
val hostAddress = ownerAddress ?: NetworkInterface.getByName(downstream)?.interfaceAddresses?.asSequence() val hostAddress = try {
?.singleOrNull { it.address is Inet4Address } ?: throw InterfaceNotFoundException() ownerAddress ?: NetworkInterface.getByName(downstream)!!.interfaceAddresses!!
.asSequence().single { it.address is Inet4Address }
} catch (e: Exception) {
throw InterfaceNotFoundException(e)
}
val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}" val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}"
private val transaction = RootSession.beginTransaction() private val transaction = RootSession.beginTransaction()