From: Matt Joiner Date: Tue, 4 Aug 2015 16:41:50 +0000 (+1000) Subject: Add an option to disable IPv6 X-Git-Tag: v1.0.0~1077 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=497d185373a76060b972f164ffe3e360e25aae86;p=btrtrc.git Add an option to disable IPv6 --- diff --git a/client.go b/client.go index 198c04b9..17a3d872 100644 --- a/client.go +++ b/client.go @@ -499,7 +499,13 @@ func NewClient(cfg *Config) (cl *Client, err error) { } if !cl.config.DisableTCP { var l net.Listener - l, err = net.Listen("tcp", listenAddr()) + l, err = net.Listen(func() string { + if cl.config.DisableIPv6 { + return "tcp4" + } else { + return "tcp" + } + }(), listenAddr()) if err != nil { return } @@ -507,7 +513,13 @@ func NewClient(cfg *Config) (cl *Client, err error) { go cl.acceptConnections(l, false) } if !cl.config.DisableUTP { - cl.utpSock, err = utp.NewSocket(listenAddr()) + cl.utpSock, err = utp.NewSocket(func() string { + if cl.config.DisableIPv6 { + return "udp4" + } else { + return "udp" + } + }(), listenAddr()) if err != nil { return } diff --git a/config.go b/config.go index e7de8d88..4bc12896 100644 --- a/config.go +++ b/config.go @@ -46,4 +46,5 @@ type Config struct { DisableEncryption bool `long:"disable-encryption"` IPBlocklist *iplist.IPList + DisableIPv6 bool }