summaryrefslogtreecommitdiff
path: root/dialer.go
diff options
context:
space:
mode:
Diffstat (limited to 'dialer.go')
-rw-r--r--dialer.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/dialer.go b/dialer.go
index db5d7b4..a269c4f 100644
--- a/dialer.go
+++ b/dialer.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
+ "log"
"net"
"strconv"
@@ -43,9 +44,10 @@ type Dialer struct {
NodeID *ntor.NodeID
PublicKey *ntor.PublicKey
IATMode IATMode
+ DialFunc func(string, string) (net.Conn, error)
- ptArgs pt.Args
- cf base.ClientFactory
+ ptArgs pt.Args
+ clientFactory base.ClientFactory
}
func packCert(node *ntor.NodeID, public *ntor.PublicKey) string {
@@ -92,7 +94,7 @@ func NewDialerFromCert(cert string) (*Dialer, error) {
// NewDialerFromArgs creates a dialer from existing pluggable transport arguments.
func NewDialerFromArgs(args pt.Args) (*Dialer, error) {
- cf, err := (&obfs4.Transport{}).ClientFactory("")
+ clientFactory, err := (&obfs4.Transport{}).ClientFactory("")
if err != nil {
return nil, err
}
@@ -116,11 +118,12 @@ func NewDialerFromArgs(args pt.Args) (*Dialer, error) {
PublicKey: pub,
IATMode: IATMode(iatMode),
- ptArgs: args,
- cf: cf,
+ ptArgs: args,
+ clientFactory: clientFactory,
}, nil
}
+/* what is this for? ----
// Wrap performs the ntor handshake over an existing conection.
// Wrap ignores the underlying Dialer config.
func (d *Dialer) Wrap(ctx context.Context, conn net.Conn) (net.Conn, error) {
@@ -128,6 +131,7 @@ func (d *Dialer) Wrap(ctx context.Context, conn net.Conn) (net.Conn, error) {
return conn, nil
})
}
+*/
// Dial creates an outbound net.Conn and performs the ntor handshake.
func (d *Dialer) Dial(ctx context.Context, network, address string) (net.Conn, error) {
@@ -137,19 +141,26 @@ func (d *Dialer) Dial(ctx context.Context, network, address string) (net.Conn, e
}
func (d *Dialer) dial(ctx context.Context, network, address string, f func(network, address string) (net.Conn, error)) (net.Conn, error) {
- if d.cf == nil {
- cf, err := (&obfs4.Transport{}).ClientFactory("")
+ if d.clientFactory == nil {
+ clientFactory, err := (&obfs4.Transport{}).ClientFactory("")
if err != nil {
return nil, err
}
- d.cf = cf
+ d.clientFactory = clientFactory
}
ptArgs := d.Args()
- args, err := d.cf.ParseArgs(&ptArgs)
+ args, err := d.clientFactory.ParseArgs(&ptArgs)
if err != nil {
return nil, err
}
- return d.cf.Dial(network, address, f, args)
+
+ if d.DialFunc != nil {
+ log.Println("REPLACING DIALFUNC")
+ f = d.DialFunc
+ }
+ log.Printf(">>> client factory dial. f=%v", f)
+
+ return d.clientFactory.Dial(network, address, f, args)
}
// Args returns the dialers options as pluggable transport arguments.