mirror of https://github.com/cbeuw/Cloak
Use cbeuw/connutil for connection testing
This commit is contained in:
parent
e7963b9e24
commit
443aeecf5f
2
go.mod
2
go.mod
|
|
@ -5,11 +5,11 @@ go 1.12
|
|||
require (
|
||||
github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63 // indirect
|
||||
github.com/boltdb/bolt v1.3.1
|
||||
github.com/cbeuw/connutil v0.0.0-20200407140739-52c0cf88d537
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
github.com/juju/ratelimit v1.0.1
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/mitchellh/gox v1.0.1 // indirect
|
||||
github.com/refraction-networking/utls v0.0.0-20190824032329-cc2996c81813
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
|
||||
|
|
|
|||
8
go.sum
8
go.sum
|
|
@ -2,14 +2,14 @@ github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63 h1:I6/SJSN9wJMJ+Z
|
|||
github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63/go.mod h1:nf+Komq6fVP4SwmKEaVGxHTyQGKREVlwjQKpvOV39yE=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/cbeuw/connutil v0.0.0-20200407140739-52c0cf88d537 h1:7SLpz2OuAX3cQQKzxnHQ5+sYy5roT9etJTa7EHxYraQ=
|
||||
github.com/cbeuw/connutil v0.0.0-20200407140739-52c0cf88d537/go.mod h1:6jR2SzckGv8hIIS9zWJ160mzGVVOYp4AXZMDtacL6LE=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
|
||||
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
|
||||
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
|
|
@ -19,10 +19,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
|||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
|
||||
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
|
||||
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/refraction-networking/utls v0.0.0-20190824032329-cc2996c81813 h1:fn33q5R1B4bgTSJXnxc7E6zR2bGMcxLaruMUt9thb5E=
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
package multiplex
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type blackhole struct {
|
||||
hole *bufio.Writer
|
||||
closer chan int
|
||||
}
|
||||
|
||||
func newBlackHole() *blackhole {
|
||||
return &blackhole{
|
||||
hole: bufio.NewWriter(ioutil.Discard),
|
||||
closer: make(chan int),
|
||||
}
|
||||
}
|
||||
func (b *blackhole) Read([]byte) (int, error) {
|
||||
<-b.closer
|
||||
return 0, io.EOF
|
||||
}
|
||||
func (b *blackhole) Write(in []byte) (int, error) { return b.hole.Write(in) }
|
||||
func (b *blackhole) Close() error {
|
||||
b.closer <- 1
|
||||
return nil
|
||||
}
|
||||
func (b *blackhole) LocalAddr() net.Addr {
|
||||
ret, _ := net.ResolveTCPAddr("tcp", "127.0.0.1")
|
||||
return ret
|
||||
}
|
||||
func (b *blackhole) RemoteAddr() net.Addr {
|
||||
ret, _ := net.ResolveTCPAddr("tcp", "127.0.0.1")
|
||||
return ret
|
||||
}
|
||||
func (b *blackhole) SetDeadline(t time.Time) error { return nil }
|
||||
func (b *blackhole) SetReadDeadline(t time.Time) error { return nil }
|
||||
func (b *blackhole) SetWriteDeadline(t time.Time) error { return nil }
|
||||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cbeuw/connutil"
|
||||
)
|
||||
|
||||
func setupSesh(unordered bool) *Session {
|
||||
|
|
@ -25,7 +27,7 @@ func setupSesh(unordered bool) *Session {
|
|||
|
||||
func BenchmarkStream_Write_Ordered(b *testing.B) {
|
||||
const PAYLOAD_LEN = 1000
|
||||
hole := newBlackHole()
|
||||
hole := connutil.Discard()
|
||||
sesh := setupSesh(false)
|
||||
sesh.AddConnection(hole)
|
||||
testData := make([]byte, PAYLOAD_LEN)
|
||||
|
|
@ -100,7 +102,7 @@ func BenchmarkStream_Read_Ordered(b *testing.B) {
|
|||
|
||||
func TestStream_Write(t *testing.T) {
|
||||
const PAYLOAD_LEN = 1000
|
||||
hole := newBlackHole()
|
||||
hole := connutil.Discard()
|
||||
sesh := setupSesh(false)
|
||||
sesh.AddConnection(hole)
|
||||
testData := make([]byte, PAYLOAD_LEN)
|
||||
|
|
@ -128,11 +130,11 @@ func TestStream_Close(t *testing.T) {
|
|||
testPayload,
|
||||
}
|
||||
|
||||
conn, writingEnd := util.GetMockConn()
|
||||
conn, writingEnd := connutil.AsyncPipe()
|
||||
sesh.AddConnection(conn)
|
||||
obfsBuf := make([]byte, 512)
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, err := sesh.Accept()
|
||||
if err != nil {
|
||||
|
|
@ -163,7 +165,7 @@ func TestStream_Read(t *testing.T) {
|
|||
testPayload,
|
||||
}
|
||||
|
||||
conn, writingEnd := util.GetMockConn()
|
||||
conn, writingEnd := connutil.AsyncPipe()
|
||||
sesh.AddConnection(conn)
|
||||
|
||||
var streamID uint32
|
||||
|
|
@ -174,7 +176,7 @@ func TestStream_Read(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, err := sesh.Accept()
|
||||
if err != nil {
|
||||
|
|
@ -200,7 +202,7 @@ func TestStream_Read(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
i, err := stream.Read(nil)
|
||||
|
|
@ -221,7 +223,7 @@ func TestStream_Read(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
stream.Close()
|
||||
|
|
@ -246,7 +248,7 @@ func TestStream_Read(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
sesh.Close()
|
||||
|
|
@ -282,7 +284,7 @@ func TestStream_UnorderedRead(t *testing.T) {
|
|||
testPayload,
|
||||
}
|
||||
|
||||
conn, writingEnd := util.GetMockConn()
|
||||
conn, writingEnd := connutil.AsyncPipe()
|
||||
sesh.AddConnection(conn)
|
||||
|
||||
var streamID uint32
|
||||
|
|
@ -293,7 +295,7 @@ func TestStream_UnorderedRead(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, err := sesh.Accept()
|
||||
if err != nil {
|
||||
|
|
@ -315,7 +317,7 @@ func TestStream_UnorderedRead(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
i, err := stream.Read(nil)
|
||||
|
|
@ -336,7 +338,7 @@ func TestStream_UnorderedRead(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
stream.Close()
|
||||
|
|
@ -361,7 +363,7 @@ func TestStream_UnorderedRead(t *testing.T) {
|
|||
f.StreamID = streamID
|
||||
i, _ := sesh.Obfs(f, obfsBuf)
|
||||
streamID++
|
||||
writingEnd <- obfsBuf[:i]
|
||||
writingEnd.Write(obfsBuf[:i])
|
||||
time.Sleep(100 * time.Microsecond)
|
||||
stream, _ := sesh.Accept()
|
||||
sesh.Close()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package multiplex
|
|||
|
||||
import (
|
||||
"github.com/cbeuw/Cloak/internal/util"
|
||||
"github.com/cbeuw/connutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"testing"
|
||||
|
|
@ -80,7 +81,7 @@ func TestSwitchboard_Send(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkSwitchboard_Send(b *testing.B) {
|
||||
hole := newBlackHole()
|
||||
hole := connutil.Discard()
|
||||
seshConfig := &SessionConfig{
|
||||
Obfuscator: nil,
|
||||
Valve: nil,
|
||||
|
|
@ -113,7 +114,7 @@ func TestSwitchboard_TxCredit(t *testing.T) {
|
|||
UnitRead: util.ReadTLS,
|
||||
}
|
||||
sesh := MakeSession(0, seshConfig)
|
||||
hole := newBlackHole()
|
||||
hole := connutil.Discard()
|
||||
sesh.sb.addConn(hole)
|
||||
connId, _, err := sesh.sb.pickRandConn()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package server
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/cbeuw/Cloak/internal/util"
|
||||
"github.com/cbeuw/connutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFirstBuffedConn_Read(t *testing.T) {
|
||||
mockConn, writingEnd := util.GetMockConn()
|
||||
mockConn, writingEnd := connutil.AsyncPipe()
|
||||
|
||||
expectedFirstPacket := []byte{1, 2, 3}
|
||||
firstBuffedConn := &firstBuffedConn{
|
||||
|
|
@ -28,7 +28,7 @@ func TestFirstBuffedConn_Read(t *testing.T) {
|
|||
}
|
||||
|
||||
expectedSecondPacket := []byte{4, 5, 6, 7}
|
||||
writingEnd <- expectedSecondPacket
|
||||
writingEnd.Write(expectedSecondPacket)
|
||||
n, err = firstBuffedConn.Read(buf)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
|
@ -41,7 +41,7 @@ func TestFirstBuffedConn_Read(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWsAcceptor(t *testing.T) {
|
||||
mockConn, _ := util.GetMockConn()
|
||||
mockConn := connutil.Discard()
|
||||
expectedFirstPacket := []byte{1, 2, 3}
|
||||
|
||||
wsAcceptor := newWsAcceptor(mockConn, expectedFirstPacket)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"strconv"
|
||||
|
|
@ -137,21 +136,3 @@ func Pipe(dst net.Conn, src net.Conn, srcReadTimeout time.Duration) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetMockConn() (net.Conn, chan []byte) {
|
||||
ch := make(chan []byte)
|
||||
l, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
go func() {
|
||||
conn, _ := net.Dial("tcp", l.Addr().String())
|
||||
for {
|
||||
data := <-ch
|
||||
_, err := conn.Write(data)
|
||||
if err != nil {
|
||||
fmt.Println("cannot write to connection", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
conn, _ := l.Accept()
|
||||
|
||||
return conn, ch
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue