fix golangci-lint errors

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2023-05-22 23:03:59 +02:00
parent 1fef5e094f
commit a206ac3eec
11 changed files with 30 additions and 25 deletions

2
go.mod
View File

@@ -92,3 +92,5 @@ require (
kernel.org/pub/linux/libs/security/libcap/psx v1.2.69 // indirect
rsc.io/qr v0.2.0 // indirect
)
// replace github.com/stv0g/gont/v2 => ../gont

View File

@@ -27,10 +27,11 @@ import (
)
var (
errCreateNonClosedAgent = errors.New("failed to create new agent if previous one is not closed")
errSwitchToIdle = errors.New("failed to switch to idle state")
errStillIdle = errors.New("not connected yet")
errClosing = errors.New("already closing")
errCreateNonClosedAgent = errors.New("failed to create new agent if previous one is not closed")
errSwitchToIdle = errors.New("failed to switch to idle state")
errStillIdle = errors.New("not connected yet")
errClosing = errors.New("already closing")
errInvalidConnectionStateForRestart = errors.New("can not restart agent while in state")
)
type Peer struct {
@@ -235,7 +236,7 @@ func (p *Peer) Restart() error {
invalidRestartStates := []ConnectionState{ConnectionStateClosed, ConnectionStateClosing, ConnectionStateRestarting}
if prev, ok := p.connectionState.SetIfNot(ConnectionStateRestarting, invalidRestartStates...); !ok {
return fmt.Errorf("can not restart agent while in state: %s", strings.ToLower(prev.String()))
return fmt.Errorf("%w: %s", errInvalidConnectionStateForRestart, strings.ToLower(prev.String()))
}
p.logger.Debug("Restarting ICE session")

View File

@@ -12,6 +12,8 @@ import (
wgdevice "golang.zx2c4.com/wireguard/device"
)
var errNotWireGuardLink = errors.New("link is not a WireGuard link")
type KernelDevice struct {
link.Link
@@ -52,7 +54,7 @@ func FindKernelDevice(name string) (*KernelDevice, error) {
// TODO: Is this portable?
if lnk.Type() != link.TypeWireGuard {
return nil, fmt.Errorf("link '%s' is not a WireGuard link", lnk.Name())
return nil, fmt.Errorf("%w: %s", errNotWireGuardLink, lnk.Name())
}
return &KernelDevice{

View File

@@ -94,7 +94,7 @@ func Connect(path string) (*Client, error) {
}
func (c *Client) Close() error {
if err := c.conn.Close(); err != nil && !errors.Is(err, grpc.ErrClientConnClosing) {
if err := c.conn.Close(); err != nil && status.Code(err) != codes.Canceled {
return fmt.Errorf("failed to close gRPC client connection: %w", err)
}

View File

@@ -2,7 +2,6 @@ package grpc
import (
"context"
"errors"
"fmt"
"github.com/stv0g/cunicu/pkg/crypto"
@@ -11,6 +10,8 @@ import (
"github.com/stv0g/cunicu/pkg/signaling"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func init() { //nolint:gochecknoinits
@@ -146,7 +147,7 @@ func (b *Backend) subscribeFromServer(ctx context.Context, pk *crypto.Key) error
if err != nil {
b.logger.Error("Subscription stream closed. Re-subscribing..", zap.Error(err))
if err := b.subscribeFromServer(ctx, pk); err != nil && !errors.Is(err, grpc.ErrClientConnClosing) {
if err := b.subscribeFromServer(ctx, pk); err != nil && status.Code(err) != codes.Canceled {
b.logger.Error("Failed to resubscribe", zap.Error(err))
}

View File

@@ -62,7 +62,6 @@ func buildBinary(packagePath string) (string, []string, error) {
}
runArgs := []string{}
cmdArgs := []string{}
profileArgs := profileArgs()
buildArgs := []string{
"-buildvcs=false", // avoid build cache invalidation
@@ -94,6 +93,7 @@ func buildBinary(packagePath string) (string, []string, error) {
logger := zap.L().Named("builder")
var cmdArgs []string
var test bool
// Build a test binary if profiling is requested
@@ -126,7 +126,7 @@ func buildBinary(packagePath string) (string, []string, error) {
zap.Bool("test", test))
if output, err := exec.Command("go", cmdArgs...).CombinedOutput(); err != nil {
return "", nil, fmt.Errorf("Failed to build %s:\n\nError:\n%s\n\nOutput:\n%s", packagePath, path, string(output))
return "", nil, fmt.Errorf("ailed to build %s:\n\nError:\n%s\n\nOutput:\n%s", packagePath, path, string(output))
}
logger.Debug("Finished building",

View File

@@ -1,7 +1,7 @@
package nodes
import (
"github.com/pion/ice/v2"
"github.com/pion/stun"
g "github.com/stv0g/gont/v2/pkg"
)
@@ -9,7 +9,7 @@ type RelayNode interface {
Node
WaitReady() error
URLs() []*ice.URL
URLs() []*stun.URI
Username() string
Password() string

View File

@@ -9,7 +9,6 @@ import (
"strconv"
"time"
"github.com/pion/ice/v2"
"github.com/pion/stun"
g "github.com/stv0g/gont/v2/pkg"
copt "github.com/stv0g/gont/v2/pkg/options/cmd"
@@ -145,27 +144,27 @@ func (c *CoturnNode) WaitReady() error {
return nil
}
func (c *CoturnNode) URLs() []*ice.URL {
func (c *CoturnNode) URLs() []*stun.URI {
host := c.Name()
return []*ice.URL{
return []*stun.URI{
{
Scheme: ice.SchemeTypeSTUN,
Scheme: stun.SchemeTypeSTUN,
Host: host,
Port: stun.DefaultPort,
Proto: ice.ProtoTypeUDP,
Proto: stun.ProtoTypeUDP,
},
{
Scheme: ice.SchemeTypeTURN,
Scheme: stun.SchemeTypeTURN,
Host: host,
Port: stun.DefaultPort,
Proto: ice.ProtoTypeUDP,
Proto: stun.ProtoTypeUDP,
},
{
Scheme: ice.SchemeTypeTURN,
Scheme: stun.SchemeTypeTURN,
Host: host,
Port: stun.DefaultPort,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
},
}
}

View File

@@ -9,7 +9,7 @@ import (
type RelayList []RelayNode
func AddRelayNodes(n *g.Network, numNodes int, opts ...g.Option) (RelayList, error) {
func AddRelayNodes(n *g.Network, numNodes int, _ ...g.Option) (RelayList, error) {
ns := RelayList{}
for i := 1; i <= numNodes; i++ {

View File

@@ -9,7 +9,7 @@ import (
type SignalingList []SignalingNode
func AddSignalingNodes(n *g.Network, numNodes int, opts ...g.Option) (SignalingList, error) {
func AddSignalingNodes(n *g.Network, numNodes int, _ ...g.Option) (SignalingList, error) {
ns := SignalingList{}
for i := 1; i <= numNodes; i++ {

View File

@@ -147,7 +147,7 @@ var _ = Context("simple: Simple local-area switched topology with variable numbe
Context("host: Allow only host candidates", func() {
Context("ipv4: Allow IPv4 network only", func() {
ConnectivityTestsWithExtraArgs("--ice-candidate-type", "host", "--ice-network-type", "udp4") //, "--port-forwarding=false")
ConnectivityTestsWithExtraArgs("--ice-candidate-type", "host", "--ice-network-type", "udp4") // , "--port-forwarding=false")
})
Context("ipv6: Allow IPv6 network only", func() {