mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-29 02:12:39 +08:00
fix golangci-lint errors
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
2
go.mod
2
go.mod
@@ -92,3 +92,5 @@ require (
|
|||||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.69 // indirect
|
kernel.org/pub/linux/libs/security/libcap/psx v1.2.69 // indirect
|
||||||
rsc.io/qr v0.2.0 // indirect
|
rsc.io/qr v0.2.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// replace github.com/stv0g/gont/v2 => ../gont
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errCreateNonClosedAgent = errors.New("failed to create new agent if previous one is not closed")
|
errCreateNonClosedAgent = errors.New("failed to create new agent if previous one is not closed")
|
||||||
errSwitchToIdle = errors.New("failed to switch to idle state")
|
errSwitchToIdle = errors.New("failed to switch to idle state")
|
||||||
errStillIdle = errors.New("not connected yet")
|
errStillIdle = errors.New("not connected yet")
|
||||||
errClosing = errors.New("already closing")
|
errClosing = errors.New("already closing")
|
||||||
|
errInvalidConnectionStateForRestart = errors.New("can not restart agent while in state")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
@@ -235,7 +236,7 @@ func (p *Peer) Restart() error {
|
|||||||
invalidRestartStates := []ConnectionState{ConnectionStateClosed, ConnectionStateClosing, ConnectionStateRestarting}
|
invalidRestartStates := []ConnectionState{ConnectionStateClosed, ConnectionStateClosing, ConnectionStateRestarting}
|
||||||
|
|
||||||
if prev, ok := p.connectionState.SetIfNot(ConnectionStateRestarting, invalidRestartStates...); !ok {
|
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")
|
p.logger.Debug("Restarting ICE session")
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
wgdevice "golang.zx2c4.com/wireguard/device"
|
wgdevice "golang.zx2c4.com/wireguard/device"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errNotWireGuardLink = errors.New("link is not a WireGuard link")
|
||||||
|
|
||||||
type KernelDevice struct {
|
type KernelDevice struct {
|
||||||
link.Link
|
link.Link
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ func FindKernelDevice(name string) (*KernelDevice, error) {
|
|||||||
|
|
||||||
// TODO: Is this portable?
|
// TODO: Is this portable?
|
||||||
if lnk.Type() != link.TypeWireGuard {
|
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{
|
return &KernelDevice{
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func Connect(path string) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Close() 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)
|
return fmt.Errorf("failed to close gRPC client connection: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/stv0g/cunicu/pkg/crypto"
|
"github.com/stv0g/cunicu/pkg/crypto"
|
||||||
@@ -11,6 +10,8 @@ import (
|
|||||||
"github.com/stv0g/cunicu/pkg/signaling"
|
"github.com/stv0g/cunicu/pkg/signaling"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { //nolint:gochecknoinits
|
func init() { //nolint:gochecknoinits
|
||||||
@@ -146,7 +147,7 @@ func (b *Backend) subscribeFromServer(ctx context.Context, pk *crypto.Key) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
b.logger.Error("Subscription stream closed. Re-subscribing..", zap.Error(err))
|
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))
|
b.logger.Error("Failed to resubscribe", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ func buildBinary(packagePath string) (string, []string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runArgs := []string{}
|
runArgs := []string{}
|
||||||
cmdArgs := []string{}
|
|
||||||
profileArgs := profileArgs()
|
profileArgs := profileArgs()
|
||||||
buildArgs := []string{
|
buildArgs := []string{
|
||||||
"-buildvcs=false", // avoid build cache invalidation
|
"-buildvcs=false", // avoid build cache invalidation
|
||||||
@@ -94,6 +93,7 @@ func buildBinary(packagePath string) (string, []string, error) {
|
|||||||
|
|
||||||
logger := zap.L().Named("builder")
|
logger := zap.L().Named("builder")
|
||||||
|
|
||||||
|
var cmdArgs []string
|
||||||
var test bool
|
var test bool
|
||||||
|
|
||||||
// Build a test binary if profiling is requested
|
// Build a test binary if profiling is requested
|
||||||
@@ -126,7 +126,7 @@ func buildBinary(packagePath string) (string, []string, error) {
|
|||||||
zap.Bool("test", test))
|
zap.Bool("test", test))
|
||||||
|
|
||||||
if output, err := exec.Command("go", cmdArgs...).CombinedOutput(); err != nil {
|
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",
|
logger.Debug("Finished building",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pion/ice/v2"
|
"github.com/pion/stun"
|
||||||
g "github.com/stv0g/gont/v2/pkg"
|
g "github.com/stv0g/gont/v2/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ type RelayNode interface {
|
|||||||
Node
|
Node
|
||||||
|
|
||||||
WaitReady() error
|
WaitReady() error
|
||||||
URLs() []*ice.URL
|
URLs() []*stun.URI
|
||||||
Username() string
|
Username() string
|
||||||
Password() string
|
Password() string
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/ice/v2"
|
|
||||||
"github.com/pion/stun"
|
"github.com/pion/stun"
|
||||||
g "github.com/stv0g/gont/v2/pkg"
|
g "github.com/stv0g/gont/v2/pkg"
|
||||||
copt "github.com/stv0g/gont/v2/pkg/options/cmd"
|
copt "github.com/stv0g/gont/v2/pkg/options/cmd"
|
||||||
@@ -145,27 +144,27 @@ func (c *CoturnNode) WaitReady() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CoturnNode) URLs() []*ice.URL {
|
func (c *CoturnNode) URLs() []*stun.URI {
|
||||||
host := c.Name()
|
host := c.Name()
|
||||||
|
|
||||||
return []*ice.URL{
|
return []*stun.URI{
|
||||||
{
|
{
|
||||||
Scheme: ice.SchemeTypeSTUN,
|
Scheme: stun.SchemeTypeSTUN,
|
||||||
Host: host,
|
Host: host,
|
||||||
Port: stun.DefaultPort,
|
Port: stun.DefaultPort,
|
||||||
Proto: ice.ProtoTypeUDP,
|
Proto: stun.ProtoTypeUDP,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Scheme: ice.SchemeTypeTURN,
|
Scheme: stun.SchemeTypeTURN,
|
||||||
Host: host,
|
Host: host,
|
||||||
Port: stun.DefaultPort,
|
Port: stun.DefaultPort,
|
||||||
Proto: ice.ProtoTypeUDP,
|
Proto: stun.ProtoTypeUDP,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Scheme: ice.SchemeTypeTURN,
|
Scheme: stun.SchemeTypeTURN,
|
||||||
Host: host,
|
Host: host,
|
||||||
Port: stun.DefaultPort,
|
Port: stun.DefaultPort,
|
||||||
Proto: ice.ProtoTypeTCP,
|
Proto: stun.ProtoTypeTCP,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type RelayList []RelayNode
|
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{}
|
ns := RelayList{}
|
||||||
|
|
||||||
for i := 1; i <= numNodes; i++ {
|
for i := 1; i <= numNodes; i++ {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type SignalingList []SignalingNode
|
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{}
|
ns := SignalingList{}
|
||||||
|
|
||||||
for i := 1; i <= numNodes; i++ {
|
for i := 1; i <= numNodes; i++ {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ var _ = Context("simple: Simple local-area switched topology with variable numbe
|
|||||||
|
|
||||||
Context("host: Allow only host candidates", func() {
|
Context("host: Allow only host candidates", func() {
|
||||||
Context("ipv4: Allow IPv4 network only", 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() {
|
Context("ipv6: Allow IPv6 network only", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user