From ecd614e2909622b67676ee079bdf34317a3e0ac0 Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Tue, 15 Mar 2022 11:18:21 -0400 Subject: Support KCP as a network type Signed-off-by: Sam Whited --- listener.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'listener.go') 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 } -- cgit v1.2.3