VPN Hotspot 2.0: Client+ (#39)

Fix #13, #38. I don't have a lot of confidence that this would work very well for every device.

Also here's an SQL command that hopefully somebody could make into the app for me: `SELECT TrafficRecord.mac, SUM(TrafficRecord.sentPackets), SUM(TrafficRecord.sentBytes), SUM(TrafficRecord.receivedPackets), SUM(TrafficRecord.receivedBytes) FROM TrafficRecord LEFT JOIN TrafficRecord AS Next ON TrafficRecord.id = Next.previousId WHERE Next.id IS NULL GROUP BY TrafficRecord.mac;`
This commit is contained in:
Mygod
2018-10-02 21:12:19 +08:00
committed by GitHub
parent 16d1eda0d4
commit 38f95a382e
35 changed files with 946 additions and 98 deletions

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot
import android.content.Context
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.Routing
import be.mygod.vpnhotspot.net.UpstreamMonitor
@@ -8,7 +9,7 @@ import com.crashlytics.android.Crashlytics
import java.net.InetAddress
import java.net.InterfaceAddress
class LocalOnlyInterfaceManager(val downstream: String) : UpstreamMonitor.Callback {
class LocalOnlyInterfaceManager(private val owner: Context, val downstream: String) : UpstreamMonitor.Callback {
private var routing: Routing? = null
private var dns = emptyList<InetAddress>()
@@ -32,7 +33,7 @@ class LocalOnlyInterfaceManager(val downstream: String) : UpstreamMonitor.Callba
private fun clean() {
val routing = routing ?: return
routing.started = false
routing.stop()
initRouting(routing.upstream, routing.hostAddress, dns)
}
@@ -40,22 +41,19 @@ class LocalOnlyInterfaceManager(val downstream: String) : UpstreamMonitor.Callba
dns: List<InetAddress> = this.dns) {
this.dns = dns
try {
this.routing = Routing(upstream, downstream, owner).apply {
routing = Routing(this.owner, upstream, downstream, owner, app.strict).apply {
try {
val strict = app.strict
if (strict && upstream == null) return@apply // in this case, nothing to be done
if (app.dhcpWorkaround) dhcpWorkaround()
ipForward() // local only interfaces need to enable ip_forward
rule()
forward(strict)
if (app.masquerade) masquerade(strict)
forward()
if (app.masquerade) masquerade()
dnsRedirect(dns)
commit()
} catch (e: Exception) {
revert()
throw e
} finally {
commit()
}
} // otw nothing needs to be done
}
} catch (e: Exception) {
SmartSnackbar.make(e.localizedMessage).show()