Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try Generics #19

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ go 1.20
require (
github.com/shadowsocks/go-shadowsocks2 v0.1.5
github.com/stretchr/testify v1.8.2
golang.org/x/crypto v0.7.0
golang.org/x/crypto v0.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
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/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
Expand All @@ -21,13 +23,13 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
38 changes: 9 additions & 29 deletions transport/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import (
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if I should define

type PacketConn interface {
  net.Conn
}

That would be a parallel to StreamConn and allow us to expand in the future, if needed.

It would, however, be confusing with net.PacketConn. Perhaps it makes sense to call it DatagramConn or DgramConn, to mirror posix sockets.

// PacketEndpoint represents an endpoint that can be used to established packet connections (like UDP) to a fixed destination.
type PacketEndpoint interface {
// Connect creates a connection bound to an endpoint, returning the connection.
Connect(ctx context.Context) (net.Conn, error)
}
type PacketEndpoint = Endpoint[net.Conn]

// UDPEndpoint is a [PacketEndpoint] that connects to the given address via UDP
type UDPEndpoint struct {
Expand All @@ -42,39 +39,22 @@ func (e UDPEndpoint) Connect(ctx context.Context) (net.Conn, error) {
return e.Dialer.DialContext(ctx, "udp", e.Address)
}

// PacketDialerEndpoint is a [PacketEndpoint] that connects to the given address using the given [PacketDialer].
type PacketDialerEndpoint struct {
Dialer PacketDialer
Address string
}

var _ PacketEndpoint = (*PacketDialerEndpoint)(nil)

// Connect implements [PacketEndpoint].Connect.
func (e *PacketDialerEndpoint) Connect(ctx context.Context) (net.Conn, error) {
return e.Dialer.Dial(ctx, e.Address)
}

// PacketDialer provides a way to dial a destination and establish datagram connections.
type PacketDialer interface {
// Dial connects to `raddr`.
// `raddr` has the form `host:port`, where `host` can be a domain name or IP address.
Dial(ctx context.Context, addr string) (net.Conn, error)
}

// UDPPacketDialer is a [PacketDialer] that uses the standard [net.Dialer] to dial.
// UDPDialer is a [PacketDialer] that uses the standard [net.Dialer] to dial.
// It provides a convenient way to use a [net.Dialer] when you need a [PacketDialer].
type UDPPacketDialer struct {
type UDPDialer struct {
Dialer net.Dialer
}

var _ PacketDialer = (*UDPPacketDialer)(nil)
var _ PacketDialer = (*UDPDialer)(nil)

// Dial implements [PacketDialer].Dial.
func (d *UDPPacketDialer) Dial(ctx context.Context, addr string) (net.Conn, error) {
// Dial implements [Dialer].Dial.
func (d *UDPDialer) Dial(ctx context.Context, addr string) (net.Conn, error) {
return d.Dialer.DialContext(ctx, "udp", addr)
}

// PacketDialer provides a way to dial a destination and establish datagram connections.
type PacketDialer = Dialer[net.Conn]

// PacketListenerDialer is a [PacketDialer] that connects to the destination using the given [PacketListener].
type PacketListenerDialer struct {
// The PacketListener that is used to create the net.PacketConn to bind on Dial. Must be non nil.
Expand Down
2 changes: 1 addition & 1 deletion transport/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestUDPPacketDialer(t *testing.T) {
require.Nil(t, err)
require.Equal(t, "udp", server.LocalAddr().Network())

dialer := &UDPPacketDialer{}
dialer := &UDPDialer{}
conn, err := dialer.Dial(context.Background(), server.LocalAddr().String())
require.Nil(t, err)

Expand Down
35 changes: 8 additions & 27 deletions transport/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net"
)

// StreamConn is a net.Conn that allows for closing only the reader or writer end of
// StreamConn is a [net.Conn] that allows for closing only the reader or writer end of
// it, supporting half-open state.
type StreamConn interface {
net.Conn
Expand Down Expand Up @@ -71,10 +71,7 @@ func WrapConn(c StreamConn, r io.Reader, w io.Writer) StreamConn {
}

// StreamEndpoint represents an endpoint that can be used to established stream connections (like TCP) to a fixed destination.
type StreamEndpoint interface {
// Connect establishes a connection with the endpoint, returning the connection.
Connect(ctx context.Context) (StreamConn, error)
}
type StreamEndpoint = Endpoint[StreamConn]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is better:

Suggested change
type StreamEndpoint = Endpoint[StreamConn]
type StreamEndpoint interface {
Endpoint[StreamConn]
}


// TCPEndpoint is a [StreamEndpoint] that connects to the given address using the given [StreamDialer].
type TCPEndpoint struct {
Expand All @@ -96,35 +93,19 @@ func (e *TCPEndpoint) Connect(ctx context.Context) (StreamConn, error) {
return conn.(*net.TCPConn), nil
}

// StreamDialerEndpoint is a [StreamEndpoint] that connects to the given address using the given [StreamDialer].
type StreamDialerEndpoint struct {
Dialer StreamDialer
Address string
}

var _ StreamEndpoint = (*StreamDialerEndpoint)(nil)

// Connect implements [StreamEndpoint].Connect.
func (e *StreamDialerEndpoint) Connect(ctx context.Context) (StreamConn, error) {
return e.Dialer.Dial(ctx, e.Address)
}

// StreamDialer provides a way to dial a destination and establish stream connections.
type StreamDialer interface {
// Dial connects to `raddr`.
// `raddr` has the form `host:port`, where `host` can be a domain name or IP address.
Dial(ctx context.Context, raddr string) (StreamConn, error)
}
type StreamDialer = Dialer[StreamConn]

// TCPStreamDialer is a [StreamDialer] that uses the standard [net.Dialer] to dial.
// TCPDialer is a [StreamDialer] that uses the standard [net.Dialer] to dial.
// It provides a convenient way to use a [net.Dialer] when you need a [StreamDialer].
type TCPStreamDialer struct {
type TCPDialer struct {
Dialer net.Dialer
}

var _ StreamDialer = (*TCPStreamDialer)(nil)
var _ StreamDialer = (*TCPDialer)(nil)

func (d *TCPStreamDialer) Dial(ctx context.Context, addr string) (StreamConn, error) {
// Dial implements [Dialer].Dial.
func (d *TCPDialer) Dial(ctx context.Context, addr string) (StreamConn, error) {
conn, err := d.Dialer.DialContext(ctx, "tcp", addr)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions transport/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestNewTCPStreamDialerIPv4(t *testing.T) {
// Client
go func() {
defer running.Done()
dialer := &TCPStreamDialer{}
dialer := &TCPDialer{}
dialer.Dialer.Control = func(network, address string, c syscall.RawConn) error {
require.Equal(t, "tcp4", network)
require.Equal(t, listener.Addr().String(), address)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestNewTCPStreamDialerIPv4(t *testing.T) {

func TestNewTCPStreamDialerAddress(t *testing.T) {
errCancel := errors.New("cancelled")
dialer := &TCPStreamDialer{}
dialer := &TCPDialer{}

dialer.Dialer.Control = func(network, address string, c syscall.RawConn) error {
require.Equal(t, "tcp4", network)
Expand Down
51 changes: 51 additions & 0 deletions transport/transport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019 Jigsaw Operations LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package transport

import (
"context"
)

// Endpoint represents an endpoint that can be used to established connections to a fixed destination.
type Endpoint[Conn any] interface {
// Connect creates a connection bound to an endpoint, returning the connection.
Connect(ctx context.Context) (Conn, error)
}

// DialerEndpoint is an [Endpoint] that connects to the given address using the given [Dialer].
// Useful if you talk repeatedly to an endpoint, such as a proxy or DNS resolver, or
// if you find yourself passing a (dialer, address) pair around.
func NewDialerEndpoint[C any](dialer Dialer[C], address string) Endpoint[C] {
return &dialerEndpoint[C]{dialer, address}
}

type dialerEndpoint[Conn any] struct {
Dialer Dialer[Conn]
Address string
}

var _ Endpoint[any] = (*dialerEndpoint[any])(nil)

// Connect implements [Endpoint].Connect.
func (e *dialerEndpoint[Conn]) Connect(ctx context.Context) (Conn, error) {
return e.Dialer.Dial(ctx, e.Address)
}

// Dialer provides a way to dial a destination and establish connections.
type Dialer[Conn any] interface {
// Dial connects to `raddr`.
// `raddr` has the form `host:port`, where `host` can be a domain name or IP address.
Dial(ctx context.Context, raddr string) (Conn, error)
}
12 changes: 8 additions & 4 deletions x/connectivity/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (err *TestError) Unwrap() error {
// TestResolverStreamConnectivity uses the given [transport.StreamEndpoint] to connect to a DNS resolver and resolve the test domain.
// The context can be used to set a timeout or deadline, or to pass values to the dialer.
func TestResolverStreamConnectivity(ctx context.Context, resolver transport.StreamEndpoint, testDomain string) (time.Duration, error) {
return testResolver(ctx, resolver.Connect, testDomain)
return testResolverConnectivity(ctx, resolver, testDomain)
}

// TestResolverPacketConnectivity uses the given [transport.PacketEndpoint] to connect to a DNS resolver and resolve the test domain.
// The context can be used to set a timeout or deadline, or to pass values to the listener.
func TestResolverPacketConnectivity(ctx context.Context, resolver transport.PacketEndpoint, testDomain string) (time.Duration, error) {
return testResolver(ctx, resolver.Connect, testDomain)
return testResolverConnectivity(ctx, resolver, testDomain)
}

func isTimeout(err error) bool {
Expand All @@ -74,7 +74,11 @@ func makeTestError(op string, err error) error {
return &TestError{Op: op, PosixError: code, Err: err}
}

func testResolver[C net.Conn](ctx context.Context, connect func(context.Context) (C, error), testDomain string) (time.Duration, error) {
// testResolverConnectivity uses the given [transport.Endpoint] to connect to a DNS resolver and resolve the test domain.
// If the connection returned by the endpoint is a [net.PacketConn], it sends the request as a DNS-over-UDP datagram,
// otherwise it sends the request as a DNS-over-TCP record.
// The [context.Context] can be used to set a timeout or deadline, or to pass values to the listener.
func testResolverConnectivity[Conn net.Conn](ctx context.Context, endpoint transport.Endpoint[Conn], testDomain string) (time.Duration, error) {
deadline, ok := ctx.Deadline()
if !ok {
// Default deadline is 5 seconds.
Expand All @@ -86,7 +90,7 @@ func testResolver[C net.Conn](ctx context.Context, connect func(context.Context)
}
testTime := time.Now()
testErr := func() error {
conn, dialErr := connect(ctx)
conn, dialErr := endpoint.Connect(ctx)
if dialErr != nil {
return makeTestError("dial", dialErr)
}
Expand Down
3 changes: 1 addition & 2 deletions x/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ module github.com/Jigsaw-Code/outline-internal-sdk/x
go 1.20

require (
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230522161920-4652a0839de2
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230523053248-546e6ee75a08
github.com/miekg/dns v1.1.54
github.com/stretchr/testify v1.8.2
golang.org/x/sys v0.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shadowsocks/go-shadowsocks2 v0.1.5 // indirect
golang.org/x/crypto v0.9.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions x/go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230516135045-d8f077429783 h1:eQLfyDy1HS4RnoSGfYWzwIyjdbo0kEPicl13G43KDro=
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230516135045-d8f077429783/go.mod h1:vxtE3esaFy5UG6TnipLyWx0esUQBy9LBXHLQx+SoER8=
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230522161920-4652a0839de2 h1:Yo0b9lNvwQqr17RRB4YmeasNt9N4O+qJwZsDIx7pN0M=
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230522161920-4652a0839de2/go.mod h1:vxtE3esaFy5UG6TnipLyWx0esUQBy9LBXHLQx+SoER8=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230523053248-546e6ee75a08 h1:8WsJ5ZUk6GtfkLcNS6SHEzZzUEjVRxH19XXhwl5itbs=
github.com/Jigsaw-Code/outline-internal-sdk v0.0.0-20230523053248-546e6ee75a08/go.mod h1:R4RofyAAbIc8yzJgwxFDG4YE0pUku5p3iNfTc2BKGhQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI=
github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
25 changes: 14 additions & 11 deletions x/outline-connectivity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ var debugLog log.Logger = *log.New(io.Discard, "", 0)

// var errorLog log.Logger = *log.New(os.Stderr, "[ERROR] ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)

func makeStreamDialer(proxyAddress string, cryptoKey *shadowsocks.EncryptionKey, prefix []byte) (transport.StreamDialer, error) {
proxyDialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: proxyAddress}, cryptoKey)
func newStreamDialer(proxyAddress string, cryptoKey *shadowsocks.EncryptionKey, prefix []byte) (transport.StreamDialer, error) {
dialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: proxyAddress}, cryptoKey)
if err != nil {
return nil, err
}
if len(prefix) > 0 {
proxyDialer.SaltGenerator = shadowsocks.NewPrefixSaltGenerator(prefix)
dialer.SaltGenerator = shadowsocks.NewPrefixSaltGenerator(prefix)
}
return proxyDialer, nil
return dialer, nil
}

func makePacketListener(proxyAddress string, cryptoKey *shadowsocks.EncryptionKey) (transport.PacketListener, error) {
return shadowsocks.NewPacketListener(&transport.UDPEndpoint{Address: proxyAddress}, cryptoKey)
func newPacketDialer(proxyAddress string, cryptoKey *shadowsocks.EncryptionKey) (transport.PacketDialer, error) {
listener, err := shadowsocks.NewPacketListener(&transport.UDPEndpoint{Address: proxyAddress}, cryptoKey)
if err != nil {
return nil, err
}
return &transport.PacketListenerDialer{Listener: listener}, nil
}

type jsonRecord struct {
Expand Down Expand Up @@ -149,19 +153,18 @@ func main() {
var testDuration time.Duration
switch proto {
case "tcp":
dialer, err := makeStreamDialer(proxyAddress, config.CryptoKey, config.Prefix)
dialer, err := newStreamDialer(proxyAddress, config.CryptoKey, config.Prefix)
if err != nil {
log.Fatalf("Failed to create StreamDialer: %v", err)
}
resolver := &transport.StreamDialerEndpoint{Dialer: dialer, Address: resolverAddress}
var resolver = transport.NewDialerEndpoint(dialer, resolverAddress)
testDuration, testErr = connectivity.TestResolverStreamConnectivity(context.Background(), resolver, *domainFlag)
case "udp":
listener, err := makePacketListener(proxyAddress, config.CryptoKey)
dialer, err := newPacketDialer(proxyAddress, config.CryptoKey)
if err != nil {
log.Fatalf("Failed to create PacketListener: %v", err)
}
dialer := transport.PacketListenerDialer{Listener: listener}
resolver := &transport.PacketDialerEndpoint{Dialer: dialer, Address: resolverAddress}
resolver := transport.NewDialerEndpoint(dialer, resolverAddress)
testDuration, testErr = connectivity.TestResolverPacketConnectivity(context.Background(), resolver, *domainFlag)
default:
log.Fatalf(`Invalid proto %v. Must be "tcp" or "udp"`, proto)
Expand Down