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