diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-25 21:11:31 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-01 16:55:02 +0100 |
commit | b95b36756ebfcdfaab6a403d93bc6514f3a3b2e2 (patch) | |
tree | e74ac26517b4c1eae2868d5351bee24746666f7b /conf | |
parent | version: adjust x/sys/windows type name (diff) | |
download | wireguard-windows-b95b36756ebfcdfaab6a403d93bc6514f3a3b2e2.tar.xz wireguard-windows-b95b36756ebfcdfaab6a403d93bc6514f3a3b2e2.zip |
manager: pipeline UAPI requests
This avoids the somewhat expensive pipe setup.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf')
-rw-r--r-- | conf/parser.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/conf/parser.go b/conf/parser.go index d26bdea4..dd0ee317 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -6,8 +6,10 @@ package conf import ( + "bufio" "encoding/base64" "encoding/hex" + "io" "net" "strconv" "strings" @@ -367,8 +369,7 @@ func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) { return nil, firstErr } -func FromUAPI(s string, existingConfig *Config) (*Config, error) { - lines := strings.Split(s, "\n") +func FromUAPI(reader io.Reader, existingConfig *Config) (*Config, error) { parserState := inInterfaceSection conf := Config{ Name: existingConfig.Name, @@ -380,9 +381,15 @@ func FromUAPI(s string, existingConfig *Config) (*Config, error) { }, } var peer *Peer - for _, line := range lines { + lineReader := bufio.NewReader(reader) + for { + line, err := lineReader.ReadString('\n') + if err != nil { + return nil, err + } + line = line[:len(line)-1] if len(line) == 0 { - continue + break } equals := strings.IndexByte(line, '=') if equals < 0 { |