summaryrefslogtreecommitdiff
path: root/listener.go
diff options
context:
space:
mode:
authoratanarjuat <atanarjuat@example.com>2022-05-23 01:48:14 +0200
committeratanarjuat <atanarjuat@example.com>2022-05-23 10:15:59 +0200
commit0da16a351753eb1bd9b807a01d1b419711226b70 (patch)
tree8e94e7ecf9b98d27f0dd19b2c3050525183c9a4d /listener.go
parente72ad4b857b09a788c553283ecb8cda7d2b580fd (diff)
wip: use kcp in the serverfeat/kcp
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)
}