Small improvements

This commit is contained in:
9seconds
2021-03-24 10:12:22 +03:00
parent 6b1bfe7b17
commit b42e51e300
2 changed files with 8 additions and 6 deletions
+5 -5
View File
@@ -32,22 +32,22 @@ func (suite *RelayTestSuite) TestCancelled() {
suite.ctxCancel() suite.ctxCancel()
eastConn := &rwcMock{} eastConn := &rwcMock{}
eastConn.Write([]byte{1, 2, 3, 4, 5}) eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
westConn := &rwcMock{} westConn := &rwcMock{}
westConn.Write([]byte{100, 101, 102}) westConn.Write([]byte{100, 101, 102}) // nolint: errcheck
suite.Nil(suite.r.Process(eastConn, westConn)) suite.Nil(suite.r.Process(eastConn, westConn))
} }
func (suite *RelayTestSuite) TestCopyFine() { func (suite *RelayTestSuite) TestCopyFine() {
eastConn := &rwcMock{} eastConn := &rwcMock{}
eastConn.Write([]byte{1, 2, 3, 4, 5}) eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
westConn := &rwcMock{} westConn := &rwcMock{}
westConn.Write([]byte{100, 101, 102}) westConn.Write([]byte{100, 101, 102}) // nolint: errcheck
suite.NotNil(suite.r.Process(eastConn, westConn)) suite.r.Process(eastConn, westConn)
} }
func TestRelay(t *testing.T) { func TestRelay(t *testing.T) {
+3 -1
View File
@@ -8,6 +8,8 @@ import (
"time" "time"
) )
const ConnectionIDBytesLength = 16
type streamContext struct { type streamContext struct {
ctx context.Context ctx context.Context
ctxCancel context.CancelFunc ctxCancel context.CancelFunc
@@ -51,7 +53,7 @@ func (s *streamContext) ClientIP() net.IP {
} }
func newStreamContext(ctx context.Context, logger Logger, clientConn net.Conn) *streamContext { func newStreamContext(ctx context.Context, logger Logger, clientConn net.Conn) *streamContext {
connIDBytes := make([]byte, 16) connIDBytes := make([]byte, ConnectionIDBytesLength)
if _, err := rand.Read(connIDBytes); err != nil { if _, err := rand.Read(connIDBytes); err != nil {
panic(err) panic(err)