summaryrefslogtreecommitdiff
path: root/dialer.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 /dialer.go
parentc51fb38aae17da3de9cbd52cc82822daa4329a8b (diff)
Support KCP as a network typekcp
Signed-off-by: Sam Whited <sam@samwhited.com>
Diffstat (limited to 'dialer.go')
-rw-r--r--dialer.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/dialer.go b/dialer.go
index 444e0c2..dc22e02 100644
--- a/dialer.go
+++ b/dialer.go
@@ -7,12 +7,15 @@ import (
"net"
"strconv"
- 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"
)
+const netKCP = "kcp"
+
const (
ptArgNode = "node-id"
ptArgKey = "public-key"
@@ -121,6 +124,12 @@ func NewDialerArgs(args pt.Args) (*Dialer, error) {
}
// Dial creates an outbound net.Conn and performs the ntor handshake.
+//
+// See func net.Dial for a description of the network and address parameters.
+// In addition to the networks supported by net.Dial, Dial supports the network
+// string "kcp" which creates a reliable UDP connection.
+// If the kcp network is used, the underlying net.Dialer is ignored and options
+// set on it do not apply.
func (d *Dialer) Dial(ctx context.Context, network, address string) (net.Conn, error) {
if d.cf == nil {
cf, err := (&obfs4.Transport{}).ClientFactory("")
@@ -135,6 +144,10 @@ func (d *Dialer) Dial(ctx context.Context, network, address string) (net.Conn, e
return nil, err
}
return d.cf.Dial(network, address, func(network, address string) (net.Conn, error) {
+ switch network {
+ case netKCP:
+ return kcp.Dial(address)
+ }
return d.Dialer.DialContext(ctx, network, address)
}, args)
}