Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Jul 23, 2022
1 parent 4cad918 commit 761574c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/core/packetgen/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package packetgen

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand All @@ -42,7 +41,7 @@ type ConnectionConfig struct {
Proxy *utils.ProxyParams
}

func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error) {
func OpenConnection(c ConnectionConfig) (Connection, error) {
switch c.Type {
case "raw":
var cfg rawConnConfig
Expand All @@ -57,7 +56,7 @@ func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error)
return nil, fmt.Errorf("error decoding connection config: %w", err)
}

return openNetConn(ctx, cfg, c.Proxy)
return openNetConn(cfg, c.Proxy)
default:
return nil, fmt.Errorf("unknown connection type: %v", c.Type)
}
Expand Down Expand Up @@ -129,7 +128,7 @@ type netConn struct {
target string
}

func openNetConn(ctx context.Context, c netConnConfig, proxyParams *utils.ProxyParams) (*netConn, error) {
func openNetConn(c netConnConfig, proxyParams *utils.ProxyParams) (*netConn, error) {
conn, err := utils.GetProxyFunc(utils.NonNilOrDefault(proxyParams, utils.ProxyParams{}), c.Protocol)(c.Protocol, c.Address)

switch {
Expand Down
12 changes: 6 additions & 6 deletions src/job/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func packetgenJob(ctx context.Context, args config.Args, globalConfig *GlobalCon
ctx, cancel := context.WithCancel(ctx)
defer cancel()

jobConfig, err := parsePacketgenArgs(ctx, args, globalConfig, a, logger)
jobConfig, err := parsePacketgenArgs(ctx, args, globalConfig, logger)
if err != nil {
return nil, fmt.Errorf("error parsing job config: %w", err)
}
Expand All @@ -72,7 +72,7 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob
ctx, cancel := context.WithCancel(ctx)
defer cancel()

conn, err := packetgen.OpenConnection(ctx, jobConfig.Connection)
conn, err := packetgen.OpenConnection(jobConfig.Connection)
if err != nil {
return err
}
Expand Down Expand Up @@ -131,8 +131,8 @@ func makePacketSource(ctx context.Context, logger *zap.Logger, packetTpls []*tem

packetsChan := utils.InfiniteRange(ctx, packets)

return func(ctx context.Context, logger *zap.Logger) (packetgen.Packet, error) {
return getNextStaticPacket(ctx, logger, packetsChan)
return func(ctx context.Context, _ *zap.Logger) (packetgen.Packet, error) {
return getNextStaticPacket(ctx, packetsChan)
}, nil
}

Expand All @@ -158,7 +158,7 @@ func staticPackets(ctx context.Context, logger *zap.Logger, packetTpls []*templa
return packets, nil
}

func getNextStaticPacket(ctx context.Context, logger *zap.Logger, packetsChan chan packetgen.Packet) (packetgen.Packet, error) {
func getNextStaticPacket(ctx context.Context, packetsChan chan packetgen.Packet) (packetgen.Packet, error) {
select {
case <-ctx.Done():
return packetgen.Packet{}, ctx.Err()
Expand Down Expand Up @@ -251,7 +251,7 @@ func parsePackets(packets []packetDescriptor, dflt map[string]any) ([]*templates
return packetTpls, nil
}

func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *GlobalConfig, a *metrics.Accumulator, logger *zap.Logger) (
func parsePacketgenArgs(ctx context.Context, args config.Args, globalConfig *GlobalConfig, logger *zap.Logger) (
tpl *packetgenJobConfig, err error,
) {
var jobConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions src/job/rawnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func udpJob(ctx context.Context, args config.Args, globalConfig *GlobalConfig, a
func rawnetJob(ctx context.Context, protocol string, args config.Args, globalConfig *GlobalConfig, a *metrics.Accumulator, logger *zap.Logger) (
data any, err error,
) {
packetgenArgs, err := parseRawNetJobArgs(logger, globalConfig, args, protocol)
packetgenArgs, err := parseRawNetJobArgs(globalConfig, args, protocol)
if err != nil {
return nil, err
}

return packetgenJob(ctx, packetgenArgs, globalConfig, a, logger)
}

func parseRawNetJobArgs(logger *zap.Logger, globalConfig *GlobalConfig, args config.Args, protocol string) (
func parseRawNetJobArgs(globalConfig *GlobalConfig, args config.Args, protocol string) (
result map[string]any, err error,
) {
var jobConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/countrychecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func getCountry(logger *zap.Logger, proxyParams ProxyParams, maxFetchRetries int
for counter.Next() {
logger.Info("checking IP address,", zap.Int("iter", counter.iter))

if country, ip, err = fetchLocationInfo(logger, proxyParams); err != nil {
if country, ip, err = fetchLocationInfo(proxyParams); err != nil {
logger.Warn("error fetching location info", zap.Error(err))
Sleep(context.Background(), backoffController.Increment().GetTimeout())
} else {
Expand All @@ -98,7 +98,7 @@ func getCountry(logger *zap.Logger, proxyParams ProxyParams, maxFetchRetries int
return "", "", fmt.Errorf("couldn't get location info in %d tries", maxFetchRetries)
}

func fetchLocationInfo(logger *zap.Logger, proxyParams ProxyParams) (country, ip string, err error) {
func fetchLocationInfo(proxyParams ProxyParams) (country, ip string, err error) {
const (
ipCheckerURI = "https://api.myip.com/"
requestTimeout = 3 * time.Second
Expand Down
6 changes: 4 additions & 2 deletions src/utils/metrics/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func serveMetrics(ctx context.Context, logger *zap.Logger, listen string) {
))

server := &http.Server{
Addr: listen,
Handler: mux,
Addr: listen,
Handler: mux,
ReadTimeout: time.Second,
ReadHeaderTimeout: time.Second,
}
go func(ctx context.Context, server *http.Server) {
<-ctx.Done()
Expand Down

0 comments on commit 761574c

Please sign in to comment.