summaryrefslogtreecommitdiff
path: root/listener.go
diff options
context:
space:
mode:
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
}