Fix bugs in awg and wireguard protocols

This commit is contained in:
albexk 2023-11-29 16:55:17 +03:00
parent eaa209bc3a
commit d7ec611ff4
3 changed files with 14 additions and 7 deletions

View file

@ -29,8 +29,8 @@ class AwgConfig private constructor(
builder.h4 builder.h4
) )
override fun toWgUserspaceString(): String = with(StringBuilder()) { override fun appendDeviceLine(sb: StringBuilder) = with(sb) {
append(super.toWgUserspaceString()) super.appendDeviceLine(this)
appendLine("jc=$jc") appendLine("jc=$jc")
appendLine("jmin=$jmin") appendLine("jmin=$jmin")
appendLine("jmax=$jmax") appendLine("jmax=$jmax")
@ -40,7 +40,6 @@ class AwgConfig private constructor(
appendLine("h2=$h2") appendLine("h2=$h2")
appendLine("h3=$h3") appendLine("h3=$h3")
appendLine("h4=$h4") appendLine("h4=$h4")
return this.toString()
} }
class Builder : WireguardConfig.Builder() { class Builder : WireguardConfig.Builder() {

View file

@ -65,7 +65,7 @@ open class Wireguard : Protocol() {
val config = GoBackend.wgGetConfig(tunnelHandle) ?: return Statistics.EMPTY_STATISTICS val config = GoBackend.wgGetConfig(tunnelHandle) ?: return Statistics.EMPTY_STATISTICS
return Statistics.build { return Statistics.build {
var optsCount = 0 var optsCount = 0
config.splitToSequence("\\n").forEach { line -> config.splitToSequence("\n").forEach { line ->
with(line) { with(line) {
when { when {
startsWith("rx_bytes=") -> setRxBytes(substring(9).toLong()).also { ++optsCount } startsWith("rx_bytes=") -> setRxBytes(substring(9).toLong()).also { ++optsCount }

View file

@ -24,9 +24,18 @@ open class WireguardConfig protected constructor(
builder.privateKeyHex builder.privateKeyHex
) )
open fun toWgUserspaceString(): String = with(StringBuilder()) { fun toWgUserspaceString(): String = with(StringBuilder()) {
appendLine("private_key=$privateKeyHex") appendDeviceLine(this)
appendLine("replace_peers=true") appendLine("replace_peers=true")
appendPeerLine(this)
return this.toString()
}
open fun appendDeviceLine(sb: StringBuilder) = with(sb) {
appendLine("private_key=$privateKeyHex")
}
open fun appendPeerLine(sb: StringBuilder) = with(sb) {
appendLine("public_key=$publicKeyHex") appendLine("public_key=$publicKeyHex")
routes.forEach { route -> routes.forEach { route ->
appendLine("allowed_ip=$route") appendLine("allowed_ip=$route")
@ -35,7 +44,6 @@ open class WireguardConfig protected constructor(
if (persistentKeepalive != 0) if (persistentKeepalive != 0)
appendLine("persistent_keepalive_interval=$persistentKeepalive") appendLine("persistent_keepalive_interval=$persistentKeepalive")
appendLine("preshared_key=$preSharedKeyHex") appendLine("preshared_key=$preSharedKeyHex")
return this.toString()
} }
open class Builder : ProtocolConfig.Builder(true) { open class Builder : ProtocolConfig.Builder(true) {