-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathoption.go
80 lines (65 loc) · 3.14 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"encoding/base64"
"encoding/hex"
"net"
"net/netip"
"strconv"
"time"
)
type ipT netip.Addr
func (o *ipT) UnmarshalFlag(value string) error {
ip, err := netip.ParseAddr(value)
*o = ipT(ip)
return err
}
func (o ipT) String() string {
return netip.Addr(o).String()
}
type hostPortT struct {
host string
port uint16
}
func (o *hostPortT) UnmarshalFlag(value string) error {
host, port, err := net.SplitHostPort(value)
if err != nil {
return err
}
port16, err := strconv.ParseUint(port, 10, 16)
*o = hostPortT{host, uint16(port16)}
return err
}
type keyT string
func (o *keyT) UnmarshalFlag(value string) error {
key, err := base64.StdEncoding.DecodeString(value)
*o = keyT(hex.EncodeToString(key))
return err
}
type timeT int64
func (o *timeT) UnmarshalFlag(value string) error {
i, err := strconv.ParseInt(value, 10, 32)
if err == nil {
*o = timeT(i)
return nil
}
d, err := time.ParseDuration(value)
*o = timeT(d.Seconds())
return err
}
type options struct {
ClientIPs []ipT `long:"client-ip" env:"CLIENT_IP" env-delim:"," required:"true" description:"[Interface].Address\tfor WireGuard client (can be set multiple times)"`
ClientPort int `long:"client-port" env:"CLIENT_PORT" description:"[Interface].ListenPort\tfor WireGuard client (optional)"`
PrivateKey keyT `long:"private-key" env:"PRIVATE_KEY" required:"true" description:"[Interface].PrivateKey\tfor WireGuard client (format: base64)"`
DNS string `long:"dns" env:"DNS" description:"[Interface].DNS\tfor WireGuard network (format: protocol://ip:port)\nProtocol includes udp(default), tcp, tls(DNS over TLS) and https(DNS over HTTPS)"`
MTU int `long:"mtu" env:"MTU" default:"1280" description:"[Interface].MTU\tfor WireGuard network"`
PeerEndpoint hostPortT `long:"peer-endpoint" env:"PEER_ENDPOINT" required:"true" description:"[Peer].Endpoint\tfor WireGuard server (format: host:port)"`
PeerKey keyT `long:"peer-key" env:"PEER_KEY" required:"true" description:"[Peer].PublicKey\tfor WireGuard server (format: base64)"`
PresharedKey keyT `long:"preshared-key" env:"PRESHARED_KEY" description:"[Peer].PresharedKey\tfor WireGuard network (optional, format: base64)"`
KeepaliveInterval timeT `long:"keepalive-interval" env:"KEEPALIVE_INTERVAL" description:"[Peer].PersistentKeepalive\tfor WireGuard network (optional)"`
ResolveDNS string `long:"resolve-dns" env:"RESOLVE_DNS" description:"DNS for resolving WireGuard server address (optional, format: protocol://ip:port)\nProtocol includes udp(default), tcp, tls(DNS over TLS) and https(DNS over HTTPS)"`
ResolveInterval timeT `long:"resolve-interval" env:"RESOLVE_INTERVAL" default:"1m" description:"Interval for resolving WireGuard server address (set 0 to disable)"`
Listen string `long:"listen" env:"LISTEN" default:"localhost:8080" description:"HTTP & SOCKS5 server address"`
ExitMode string `long:"exit-mode" env:"EXIT_MODE" choice:"remote" choice:"local" default:"remote" description:"Exit mode"`
Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
ClientID string `long:"client-id" env:"CLIENT_ID" hidden:"true"`
}