-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace old waitForTunnelUp function
After invoking VpnService.establish() we will get a tunnel file descriptor that corresponds to the interface that was created. However, this has no guarantee of the routing table beeing up to date, and we might thus send traffic outside the tunnel. Previously this was done through looking at the tunFd to see that traffic is sent to verify that the routing table has changed. If no traffic is seen some traffic is induced to a random IP address to ensure traffic can be seen. This new implementation is slower but won't risk sending UDP traffic to a random public address at the internet.
- Loading branch information
Showing
6 changed files
with
150 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package net.mullvad.talpid.util | ||
|
||
import android.net.ConnectivityManager | ||
import android.net.ConnectivityManager.NetworkCallback | ||
import android.net.LinkProperties | ||
import android.net.Network | ||
import android.net.NetworkCapabilities | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.channels.trySendBlocking | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
|
||
sealed interface NetworkEvent { | ||
data class OnAvailable(val network: Network) : NetworkEvent | ||
|
||
data object OnUnavailable : NetworkEvent | ||
|
||
data class OnLinkPropertiesChanged(val network: Network, val linkProperties: LinkProperties) : | ||
NetworkEvent | ||
|
||
data class OnCapabilitiesChanged( | ||
val network: Network, | ||
val networkCapabilities: NetworkCapabilities, | ||
) : NetworkEvent | ||
|
||
data class OnBlockedStatusChanged(val network: Network, val blocked: Boolean) : NetworkEvent | ||
|
||
data class OnLosing(val network: Network, val maxMsToLive: Int) : NetworkEvent | ||
|
||
data class OnLost(val network: Network) : NetworkEvent | ||
} | ||
|
||
fun ConnectivityManager.defaultCallbackFlow(): Flow<NetworkEvent> = | ||
callbackFlow<NetworkEvent> { | ||
val callback = | ||
object : NetworkCallback() { | ||
override fun onLinkPropertiesChanged( | ||
network: Network, | ||
linkProperties: LinkProperties, | ||
) { | ||
super.onLinkPropertiesChanged(network, linkProperties) | ||
trySendBlocking(NetworkEvent.OnLinkPropertiesChanged(network, linkProperties)) | ||
} | ||
|
||
override fun onAvailable(network: Network) { | ||
super.onAvailable(network) | ||
trySendBlocking(NetworkEvent.OnAvailable(network)) | ||
} | ||
|
||
override fun onCapabilitiesChanged( | ||
network: Network, | ||
networkCapabilities: NetworkCapabilities, | ||
) { | ||
super.onCapabilitiesChanged(network, networkCapabilities) | ||
trySendBlocking( | ||
NetworkEvent.OnCapabilitiesChanged(network, networkCapabilities) | ||
) | ||
} | ||
|
||
override fun onBlockedStatusChanged(network: Network, blocked: Boolean) { | ||
super.onBlockedStatusChanged(network, blocked) | ||
trySendBlocking(NetworkEvent.OnBlockedStatusChanged(network, blocked)) | ||
} | ||
|
||
override fun onLosing(network: Network, maxMsToLive: Int) { | ||
super.onLosing(network, maxMsToLive) | ||
trySendBlocking(NetworkEvent.OnLosing(network, maxMsToLive)) | ||
} | ||
|
||
override fun onLost(network: Network) { | ||
super.onLost(network) | ||
trySendBlocking(NetworkEvent.OnLost(network)) | ||
} | ||
|
||
override fun onUnavailable() { | ||
super.onUnavailable() | ||
trySendBlocking(NetworkEvent.OnUnavailable) | ||
} | ||
} | ||
registerDefaultNetworkCallback(callback) | ||
|
||
awaitClose { unregisterNetworkCallback(callback) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
mod api; | ||
mod classes; | ||
mod problem_report; | ||
mod talpid_vpn_service; | ||
|
||
use jnix::{ | ||
jni::{ | ||
|
Oops, something went wrong.