summaryrefslogtreecommitdiff
path: root/listener.go
diff options
context:
space:
mode:
Diffstat (limited to 'listener.go')
-rw-r--r--listener.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/listener.go b/listener.go
index 30ad401..70b4503 100644
--- a/listener.go
+++ b/listener.go
@@ -10,11 +10,16 @@ import (
"net"
pt "git.torproject.org/pluggable-transports/goptlib.git"
+ "github.com/xtaci/kcp-go"
"gitlab.com/yawning/obfs4.git/common/ntor"
"gitlab.com/yawning/obfs4.git/transports/base"
"gitlab.com/yawning/obfs4.git/transports/obfs4"
)
+const (
+ netKCP = "kcp"
+)
+
// ListenConfig contains options for listening to an address.
// If Seed is not set it defaults to a randomized value.
// If StateDir is not set the current working directory is used.
@@ -79,7 +84,7 @@ func NewListenConfigCert(cert string) (*ListenConfig, error) {
}
// Wrap takes an existing net.Listener and wraps it in a listener that is
-// configured to perform the ntor handshake.
+// configured to perform the ntor handshake and copy data through the obfuscated conn.
// Values from the inner net.ListenConfig are ignored.
func (lc *ListenConfig) Wrap(ctx context.Context, ln net.Listener) (*Listener, error) {
args := make(pt.Args)
@@ -105,13 +110,22 @@ func (lc *ListenConfig) Wrap(ctx context.Context, ln net.Listener) (*Listener, e
return &Listener{sf: sf, ln: ln}, nil
}
-// Listen announces on the local network address.
-//
+// Listen listens on the local network address.
// See func net.Dial for a description of the network and address parameters.
func (lc *ListenConfig) Listen(ctx context.Context, network, address string) (*Listener, error) {
- ln, err := lc.ListenConfig.Listen(ctx, network, address)
- if err != nil {
- return nil, err
+ var ln net.Listener
+ var err error
+ switch network {
+ case netKCP:
+ ln, err = kcp.Listen(address)
+ if err != nil {
+ return nil, err
+ }
+ default:
+ ln, err = lc.ListenConfig.Listen(ctx, network, address)
+ if err != nil {
+ return nil, err
+ }
}
return lc.Wrap(ctx, ln)
}