Skip to content

Commit

Permalink
More refactoring and more comments/docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed Sep 28, 2023
1 parent 298b354 commit 24be2a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/msak-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func main() {
Emitter: client.HumanReadable{
Debug: *flagDebug,
},
NoVerify: *flagNoVerify,
}

cl := client.New(clientName, clientVersion, config)
Expand Down
28 changes: 18 additions & 10 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ var (
libraryVersion = version.Version
)

// defaultDialer is the default websocket.Dialer used by the client.
// It wraps the net.Conn with a netx.Conn.
var defaultDialer = &websocket.Dialer{
HandshakeTimeout: DefaultWebSocketHandshakeTimeout,
NetDial: func(network, addr string) (net.Conn, error) {
conn, err := net.Dial(network, addr)
if err != nil {
return nil, err
}
return netx.FromTCPConn(conn.(*net.TCPConn))
},
}

// Locator is an interface used to get a list of available servers to test against.
type Locator interface {
Nearest(ctx context.Context, service string) ([]v2.Target, error)
Expand All @@ -67,6 +80,8 @@ type Throughput1Client struct {
targets []v2.Target
tIndex map[string]int

// recvByteCounters is a map of stream IDs to number of bytes, used to compute the goodput.
// A new byte count is appended every time the client sees a receiver-side Measurement.
recvByteCounters map[int][]int64
recvByteCountersMutex sync.Mutex
}
Expand All @@ -92,21 +107,14 @@ func makeUserAgent(clientName, clientVersion string) string {

// New returns a new Throughput1Client with the provided client name, version and config.
func New(clientName, clientVersion string, config Config) *Throughput1Client {
defaultDialer.TLSClientConfig.InsecureSkipVerify = config.NoVerify

return &Throughput1Client{
ClientName: clientName,
ClientVersion: clientVersion,

config: config,
dialer: &websocket.Dialer{
HandshakeTimeout: DefaultWebSocketHandshakeTimeout,
NetDial: func(network, addr string) (net.Conn, error) {
conn, err := net.Dial(network, addr)
if err != nil {
return nil, err
}
return netx.FromTCPConn(conn.(*net.TCPConn))
},
},
dialer: defaultDialer,

locator: locate.NewClient(makeUserAgent(clientName, clientVersion)),

Expand Down
3 changes: 3 additions & 0 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ type Config struct {
// Emitter is the interface used to emit the results of the test. It can be overridden
// to provide a custom output.
Emitter Emitter

// NoVerify disables the TLS certificate verification.
NoVerify bool
}

0 comments on commit 24be2a2

Please sign in to comment.