Add AWG module

This commit is contained in:
albexk 2023-11-26 13:07:31 +03:00
parent 91f44fb394
commit 9297f877c4
11 changed files with 295 additions and 43 deletions

View file

@ -18,17 +18,17 @@ private const val TAG = "Protocol"
const val VPN_SESSION_NAME = "AmneziaVPN"
abstract class Protocol(protected val context: Context) {
open lateinit var config: ProtocolConfig
abstract class Protocol {
abstract val statistics: Statistics
abstract fun initialize()
abstract fun initialize(context: Context)
abstract fun parseConfig(config: JSONObject)
abstract fun startVpn(config: JSONObject, vpnBuilder: Builder, protect: (Int) -> Boolean)
protected open fun buildVpnInterface(vpnBuilder: Builder) {
abstract fun stopVpn()
protected open fun buildVpnInterface(config: ProtocolConfig, vpnBuilder: Builder) {
vpnBuilder.setSession(VPN_SESSION_NAME)
vpnBuilder.allowFamily(OsConstants.AF_INET)
vpnBuilder.allowFamily(OsConstants.AF_INET6)
@ -49,10 +49,6 @@ abstract class Protocol(protected val context: Context) {
vpnBuilder.setMetered(false)
}
abstract fun startVpn(vpnBuilder: Builder, protect: (Int) -> Boolean)
abstract fun stopVpn()
companion object {
private fun extractLibrary(context: Context, libraryName: String, destination: File): Boolean {
Log.d(TAG, "Extracting library: $libraryName")

View file

@ -5,7 +5,7 @@ import android.os.Build
import androidx.annotation.RequiresApi
import java.net.InetAddress
data class ProtocolConfig(
open class ProtocolConfig protected constructor(
val addresses: Set<InetNetwork>,
val dnsServers: Set<InetAddress>,
val routes: Set<InetNetwork>,
@ -15,7 +15,7 @@ data class ProtocolConfig(
val mtu: Int
) {
private constructor(builder: Builder) : this(
protected constructor(builder: Builder) : this(
builder.addresses,
builder.dnsServers,
builder.routes,
@ -49,6 +49,7 @@ data class ProtocolConfig(
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
fun excludeRoute(route: InetNetwork) = apply { this.excludedRoutes += route }
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
fun excludeRoutes(routes: List<InetNetwork>) = apply { this.excludedRoutes += routes }