summaryrefslogtreecommitdiff
path: root/listener.go
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2022-03-15 11:18:21 -0400
committerSam Whited <sam@samwhited.com>2022-03-15 11:18:21 -0400
commitecd614e2909622b67676ee079bdf34317a3e0ac0 (patch)
treeb62b57a47508aa2d9fb14d7c89cffeb3b3c129fc /listener.go
parentc51fb38aae17da3de9cbd52cc82822daa4329a8b (diff)
Support KCP as a network typekcp
Signed-off-by: Sam Whited <sam@samwhited.com>
Diffstat (limited to 'listener.go')
-rw-r--r--listener.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/listener.go b/listener.go
index 4163cb9..86f1470 100644
--- a/listener.go
+++ b/listener.go
@@ -7,7 +7,8 @@ import (
"encoding/hex"
"net"
- pt "git.torproject.org/pluggable-transports/goptlib.git"
+ "git.torproject.org/pluggable-transports/goptlib.git"
+ "github.com/xtaci/kcp-go/v5"
"gitlab.com/yawning/obfs4.git/common/ntor"
"gitlab.com/yawning/obfs4.git/transports/base"
"gitlab.com/yawning/obfs4.git/transports/obfs4"
@@ -41,8 +42,19 @@ func NewListenConfigCert(cert string) (*ListenConfig, error) {
// Listen announces on the local network address.
//
// See func net.Dial for a description of the network and address parameters.
+// In addition to the networks supported by net.Dial, Listen supports the
+// network string "kcp" which creates a reliable UDP connection.
+// If the kcp network is used, the underlying ListenConfig is ignored and
+// options set on it do not apply.
func (lc *ListenConfig) Listen(ctx context.Context, network, address string) (*Listener, error) {
- ln, err := lc.ListenConfig.Listen(ctx, network, address)
+ var ln net.Listener
+ var err error
+ switch network {
+ case netKCP:
+ ln, err = kcp.Listen(address)
+ default:
+ ln, err = lc.ListenConfig.Listen(ctx, network, address)
+ }
if err != nil {
return nil, err
}