fix golangci-lint errors

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2023-05-22 10:14:51 +02:00
parent e7961b0026
commit 9d9619b39c
44 changed files with 122 additions and 136 deletions

View File

@@ -63,7 +63,7 @@ lint:
install-deps:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/onsi/ginkgo/v2/ginkgo@v2.8.4
go install github.com/onsi/ginkgo/v2/ginkgo@v2.9.5
go install github.com/amobe/gocov-merger@latest
go install github.com/jandelgado/gcov2lcov@latest
go install github.com/goreleaser/goreleaser@latest

View File

@@ -23,7 +23,7 @@ func addClientCommand(rcmd, cmd *cobra.Command) {
rcmd.AddCommand(cmd)
}
func rpcConnect(cmd *cobra.Command, args []string) error {
func rpcConnect(_ *cobra.Command, _ []string) error {
var err error
if rpcClient, err = rpc.Connect(rpcSockPath); err != nil {
@@ -33,6 +33,6 @@ func rpcConnect(cmd *cobra.Command, args []string) error {
return nil
}
func rpcDisconnect(cmd *cobra.Command, args []string) error {
func rpcDisconnect(_ *cobra.Command, _ []string) error {
return rpcClient.Close()
}

View File

@@ -11,7 +11,7 @@ import (
//nolint:gochecknoglobals
var BooleanCompletions = cobra.FixedCompletions([]string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp)
func interfaceValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func interfaceValidArgs(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
// Establish RPC connection
if err := rpcConnect(cmd, args); err != nil {
return nil, cobra.ShellCompDirectiveError

View File

@@ -92,7 +92,7 @@ func getCompletions(typ reflect.Type, haveCompleted, toComplete string) ([]strin
return comps, flags
}
func validConfigSettings(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func validConfigSettings(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
@@ -102,7 +102,7 @@ func validConfigSettings(cmd *cobra.Command, args []string, toComplete string) (
return getCompletions(t, "", toComplete)
}
func set(cmd *cobra.Command, args []string) {
func set(_ *cobra.Command, args []string) {
settings := map[string]string{
args[0]: args[1],
}
@@ -114,7 +114,7 @@ func set(cmd *cobra.Command, args []string) {
}
}
func get(cmd *cobra.Command, args []string) {
func get(_ *cobra.Command, args []string) {
params := &rpcproto.GetConfigParams{}
if len(args) > 0 {
@@ -134,7 +134,7 @@ func get(cmd *cobra.Command, args []string) {
}
}
func reload(cmd *cobra.Command, args []string) error {
func reload(_ *cobra.Command, _ []string) error {
if _, err := rpcClient.ReloadConfig(context.Background(), &proto.Empty{}); err != nil {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -19,7 +19,7 @@ func init() { //nolint:gochecknoinits
addClientCommand(rootCmd, cmd)
}
func restart(cmd *cobra.Command, args []string) error {
func restart(_ *cobra.Command, _ []string) error {
if _, err := rpcClient.DaemonClient.Restart(context.Background(), &proto.Empty{}); err != nil {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -19,7 +19,7 @@ func init() { //nolint:gochecknoinits
addClientCommand(rootCmd, cmd)
}
func stop(cmd *cobra.Command, args []string) error {
func stop(_ *cobra.Command, _ []string) error {
if _, err := rpcClient.Stop(context.Background(), &proto.Empty{}); err != nil {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -20,7 +20,7 @@ func init() { //nolint:gochecknoinits
addClientCommand(rootCmd, cmd)
}
func sync(cmd *cobra.Command, args []string) error {
func sync(_ *cobra.Command, _ []string) error {
_, err := rpcClient.Sync(context.Background(), &proto.Empty{})
if err != nil {
return fmt.Errorf("failed RPC request: %w", err)

View File

@@ -25,7 +25,7 @@ func init() { //nolint:gochecknoinits
addClientCommand(wgCmd, cmd)
}
func wgShowConf(cmd *cobra.Command, args []string) error {
func wgShowConf(_ *cobra.Command, args []string) error {
intfName := args[0]
sts, err := rpcClient.GetStatus(context.Background(), &rpcproto.GetStatusParams{

View File

@@ -40,7 +40,7 @@ $ wg genkey | tee private.key | wg pubkey > public.key`,
wgCmd.AddCommand(pubKeyCmd)
}
func wgGenKey(cmd *cobra.Command, args []string) error {
func wgGenKey(_ *cobra.Command, _ []string) error {
key, err := wgtypes.GeneratePrivateKey()
if err != nil {
os.Exit(1)
@@ -51,7 +51,7 @@ func wgGenKey(cmd *cobra.Command, args []string) error {
return nil
}
func wgPubKey(cmd *cobra.Command, args []string) error {
func wgPubKey(_ *cobra.Command, _ []string) error {
privKeyStrBytes, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("failed to read from stdin: %w", err)

View File

@@ -42,7 +42,7 @@ Subsequent lines are printed for each peer and contain in order separated by tab
addClientCommand(wgCmd, cmd)
}
func wgShowValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func wgShowValidArgs(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
comps := []string{}
if len(args) == 0 {
@@ -68,7 +68,7 @@ func wgShowValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]st
return comps, cobra.ShellCompDirectiveNoFileComp
}
func wgShow(cmd *cobra.Command, args []string) error {
func wgShow(_ *cobra.Command, args []string) error {
intf, mode, field, err := parseWgShowArgs(args)
if err != nil {
return fmt.Errorf("failed to parse arguments: %w", err)

View File

@@ -7,6 +7,7 @@ import (
"path/filepath"
"github.com/pion/ice/v2"
"github.com/pion/stun"
"github.com/stv0g/cunicu/pkg/crypto"
icex "github.com/stv0g/cunicu/pkg/ice"
signalingproto "github.com/stv0g/cunicu/pkg/proto/signaling"
@@ -18,8 +19,8 @@ import (
var errInvalidURLScheme = errors.New("invalid ICE URL scheme")
func (c *InterfaceSettings) AgentURLs(ctx context.Context, pk *crypto.Key) ([]*ice.URL, error) { //nolint:gocognit
iceURLs := []*ice.URL{}
func (c *InterfaceSettings) AgentURLs(ctx context.Context, pk *crypto.Key) ([]*stun.URI, error) { //nolint:gocognit
iceURLs := []*stun.URI{}
g := errgroup.Group{}
@@ -68,7 +69,7 @@ func (c *InterfaceSettings) AgentURLs(ctx context.Context, pk *crypto.Key) ([]*i
}
for _, svr := range resp.Relays {
u, err := ice.ParseURL(svr.Url)
u, err := stun.ParseURI(svr.Url)
if err != nil {
return fmt.Errorf("failed to parse STUN/TURN URL '%s': %w", u, err)
}
@@ -120,13 +121,13 @@ func (c *InterfaceSettings) AgentConfig(ctx context.Context, peer *crypto.Key) (
}
// Filter URLs
cfg.Urls = slices.Filter(cfg.Urls, func(u *ice.URL) bool {
if isRelay := u.Scheme == ice.SchemeTypeTURN || u.Scheme == ice.SchemeTypeTURNS; isRelay {
if c.ICE.RelayTCP != nil && *c.ICE.RelayTCP && u.Proto == ice.ProtoTypeUDP {
cfg.Urls = slices.Filter(cfg.Urls, func(u *stun.URI) bool {
if isRelay := u.Scheme == stun.SchemeTypeTURN || u.Scheme == stun.SchemeTypeTURNS; isRelay {
if c.ICE.RelayTCP != nil && *c.ICE.RelayTCP && u.Proto == stun.ProtoTypeUDP {
return false
}
if c.ICE.RelayTLS != nil && *c.ICE.RelayTLS && u.Scheme == ice.SchemeTypeTURN {
if c.ICE.RelayTLS != nil && *c.ICE.RelayTLS && u.Scheme == stun.SchemeTypeTURN {
return false
}
}

View File

@@ -10,6 +10,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pion/ice/v2"
"github.com/pion/stun"
"github.com/stv0g/cunicu/pkg/config"
"github.com/stv0g/cunicu/pkg/crypto"
grpcx "github.com/stv0g/cunicu/pkg/signaling/grpc"
@@ -38,33 +39,33 @@ var _ = Describe("Agent config", func() {
switch exp := exp.(type) {
case string:
Expect(err).To(MatchError(exp))
case *ice.URL:
case *stun.URI:
Expect(err).To(Succeed())
Expect(aCfg.Urls).To(HaveLen(1))
Expect(aCfg.Urls).To(ContainElements(exp))
}
},
Entry("url1", []string{"--ice-url", "stun:server1", "--ice-username", "user1", "--ice-password", "pass1"}, &ice.URL{
Scheme: ice.SchemeTypeSTUN,
Entry("url1", []string{"--ice-url", "stun:server1", "--ice-username", "user1", "--ice-password", "pass1"}, &stun.URI{
Scheme: stun.SchemeTypeSTUN,
Host: "server1",
Port: 3478,
Proto: ice.ProtoTypeUDP,
Proto: stun.ProtoTypeUDP,
Username: "user1",
Password: "pass1",
}),
Entry("url2", []string{"--ice-url", "turn:server2:1234?transport=tcp", "--ice-username", "user1", "--ice-password", "pass1"}, &ice.URL{
Scheme: ice.SchemeTypeTURN,
Entry("url2", []string{"--ice-url", "turn:server2:1234?transport=tcp", "--ice-username", "user1", "--ice-password", "pass1"}, &stun.URI{
Scheme: stun.SchemeTypeTURN,
Host: "server2",
Port: 1234,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
Username: "user1",
Password: "pass1",
}),
Entry("url3", []string{"--ice-url", "turn:user3:pass3@server3:1234?transport=tcp", "--ice-password", "pass3"}, &ice.URL{
Scheme: ice.SchemeTypeTURN,
Entry("url3", []string{"--ice-url", "turn:user3:pass3@server3:1234?transport=tcp", "--ice-password", "pass3"}, &stun.URI{
Scheme: stun.SchemeTypeTURN,
Host: "server3",
Port: 1234,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
Username: "user3",
Password: "pass3",
}),
@@ -132,12 +133,12 @@ var _ = Describe("Agent config", func() {
Expect(urls).To(HaveLen(2))
for _, u := range urls {
switch u.Scheme {
case ice.SchemeTypeSTUN:
case stun.SchemeTypeSTUN:
Expect(u.String()).To(Equal(stunRelay.URL))
Expect(u.Username).To(BeEmpty())
Expect(u.Password).To(BeEmpty())
case ice.SchemeTypeTURN:
case stun.SchemeTypeTURN:
Expect(u.String()).To(Equal(turnRelay.URL))
user, pass, exp := turnRelay.GetCredentials(pk.String())
@@ -148,7 +149,7 @@ var _ = Describe("Agent config", func() {
}))
Expect(u.Password).To(Equal(pass))
case ice.SchemeTypeSTUNS, ice.SchemeTypeTURNS:
case stun.SchemeTypeSTUNS, stun.SchemeTypeTURNS, stun.SchemeTypeUnknown:
}
}
})

View File

@@ -132,7 +132,7 @@ func (p *RemoteFileProvider) hasChanged() (bool, error) {
resp, err := client.Do(req)
if err != nil {
return false, fmt.Errorf("%s %s: %w", errFailedToFetch, p.url, err)
return false, fmt.Errorf("%w %s: %w", errFailedToFetch, p.url, err)
} else if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("%w: %s: %s", errFailedToFetch, p.url, resp.Status)
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/knadh/koanf"
"github.com/knadh/koanf/maps"
"github.com/miekg/dns"
"github.com/pion/ice/v2"
"github.com/pion/stun"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)
@@ -276,11 +276,11 @@ func lookupICEUrlSRV(name, svc, proto string) ([]string, error) {
urls := []string{}
for _, addr := range addrs {
url := ice.URL{
Scheme: ice.NewSchemeType(svc),
url := stun.URI{
Scheme: stun.NewSchemeType(svc),
Host: addr.Target,
Port: int(addr.Port),
Proto: ice.NewProtoType(proto),
Proto: stun.NewProtoType(proto),
}
urls = append(urls, url.String())
}

View File

@@ -53,4 +53,4 @@ func (i *Interface) OnPeerAdded(p *daemon.Peer) {
}
}
func (i *Interface) OnPeerRemoved(p *daemon.Peer) {}
func (i *Interface) OnPeerRemoved(_ *daemon.Peer) {}

View File

@@ -32,7 +32,7 @@ func (i *Interface) OnPeerRemoved(cp *daemon.Peer) {
delete(i.Peers, cp)
}
func (i *Interface) OnPeerModified(cp *daemon.Peer, old *wgtypes.Peer, m daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
func (i *Interface) OnPeerModified(cp *daemon.Peer, _ *wgtypes.Peer, m daemon.PeerModifier, _, _ []net.IPNet) {
p := i.Peers[cp]
if m.Is(daemon.PeerModifiedEndpoint) {
@@ -46,7 +46,7 @@ func (i *Interface) OnPeerModified(cp *daemon.Peer, old *wgtypes.Peer, m daemon.
}
}
func (i *Interface) OnBindOpen(b *wg.Bind, port uint16) {
func (i *Interface) OnBindOpen(b *wg.Bind, _ uint16) {
logger := i.logger.Named("bind_conn")
for _, muxConn := range i.muxConns {

View File

@@ -32,9 +32,9 @@ func NftablesUserDataGet(udata []byte, styp NftablesUserDataType) []byte {
if len(udata) < 2+length {
break
} else {
udata = udata[2+length:]
}
udata = udata[2+length:]
}
return nil

View File

@@ -16,7 +16,7 @@ import (
// whenever the state of the ICE connection has changed
// It is started as goroutine from pion/ice.Agent.
func (p *Peer) onConnectionStateChange(ics ice.ConnectionState) {
cs := ConnectionState(epdiscproto.NewConnectionState(ics))
cs := epdiscproto.NewConnectionState(ics)
switch cs {
case ConnectionStateFailed, ConnectionStateDisconnected:
@@ -55,6 +55,8 @@ func (p *Peer) onConnectionStateChange(ics ice.ConnectionState) {
if _, ok := p.SetStateIf(daemon.PeerStateConnected, daemon.PeerStateConnecting); !ok {
p.logger.Error("Failed to change peer state to connected", zap.String("prev_state", strings.ToLower(p.State().String())))
}
default:
}
}
@@ -149,11 +151,11 @@ func (p *Peer) onSignalingMessage(msg *signaling.Message) {
}
// OnSignalingMessage is invoked for every message received via the signaling backend
func (p *Peer) OnSignalingMessage(kp *crypto.PublicKeyPair, msg *signaling.Message) {
func (p *Peer) OnSignalingMessage(_ *crypto.PublicKeyPair, msg *signaling.Message) {
p.signalingMessages <- msg
}
func (p *Peer) OnBindOpen(b *wg.Bind, port uint16) {
func (p *Peer) OnBindOpen(b *wg.Bind, _ uint16) {
if conn, ok := p.proxy.(wg.BindConn); ok {
b.Conns = append(b.Conns, conn)
}

View File

@@ -95,6 +95,6 @@ func (p *BindProxy) ListenPort() (uint16, bool) {
return 0, false
}
func (p *BindProxy) SetMark(mark uint32) error {
func (p *BindProxy) SetMark(_ uint32) error {
return errNotSupported
}

View File

@@ -91,7 +91,7 @@ func (h *WebHook) OnInterfaceRemoved(i *daemon.Interface) {
})
}
func (h *WebHook) OnInterfaceModified(i *daemon.Interface, old *wg.Interface, m daemon.InterfaceModifier) {
func (h *WebHook) OnInterfaceModified(i *daemon.Interface, _ *wg.Interface, m daemon.InterfaceModifier) {
go h.run(&hooksproto.WebHookBody{
Type: rpcproto.EventType_INTERFACE_MODIFIED,
Interface: marshalRedactedInterface(i),
@@ -113,7 +113,7 @@ func (h *WebHook) OnPeerRemoved(p *daemon.Peer) {
})
}
func (h *WebHook) OnPeerModified(p *daemon.Peer, oldPeer *wgtypes.Peer, m daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
func (h *WebHook) OnPeerModified(p *daemon.Peer, _ *wgtypes.Peer, m daemon.PeerModifier, _, _ []net.IPNet) {
go h.run(&hooksproto.WebHookBody{
Type: rpcproto.EventType_PEER_MODIFIED,
Peer: p.Marshal().Redact(),
@@ -121,7 +121,7 @@ func (h *WebHook) OnPeerModified(p *daemon.Peer, oldPeer *wgtypes.Peer, m daemon
})
}
func (h *WebHook) OnPeerStateChanged(p *daemon.Peer, newState, prevState daemon.PeerState) {
func (h *WebHook) OnPeerStateChanged(p *daemon.Peer, _, _ daemon.PeerState) {
pm := p.Marshal().Redact()
if epi := epdisc.Get(p.Interface); epi != nil {

View File

@@ -16,13 +16,13 @@ func (i *Interface) OnPeerAdded(p *daemon.Peer) {
p.AddModifiedHandler(i)
}
func (i *Interface) OnPeerRemoved(p *daemon.Peer) {
func (i *Interface) OnPeerRemoved(_ *daemon.Peer) {
if err := i.Sync(); err != nil {
i.logger.Error("Failed to update hosts file", zap.Error(err))
}
}
func (i *Interface) OnPeerModified(p *daemon.Peer, old *wgtypes.Peer, m daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
func (i *Interface) OnPeerModified(_ *daemon.Peer, _ *wgtypes.Peer, m daemon.PeerModifier, _, _ []net.IPNet) {
// Only update if the name has changed
if m.Is(daemon.PeerModifiedName) {
if err := i.Sync(); err != nil {

View File

@@ -152,4 +152,4 @@ func (i *Interface) OnPeerAdded(p *daemon.Peer) {
i.ApplyDescription(p)
}
func (i *Interface) OnPeerRemoved(p *daemon.Peer) {}
func (i *Interface) OnPeerRemoved(_ *daemon.Peer) {}

View File

@@ -54,7 +54,7 @@ func (i *Interface) OnPeerRemoved(p *daemon.Peer) {
}
}
func (i *Interface) OnPeerModified(p *daemon.Peer, old *wgtypes.Peer, m daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
func (i *Interface) OnPeerModified(p *daemon.Peer, _ *wgtypes.Peer, _ daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
pk := p.PublicKey()
// Determine peer gateway address by using the first IPv4 and IPv6 prefix

View File

@@ -46,4 +46,4 @@ func (h *peerHandler) OnInterfaceAdded(i *Interface) {
i.AddPeerHandler(h)
}
func (h *peerHandler) OnInterfaceRemoved(i *Interface) {}
func (h *peerHandler) OnInterfaceRemoved(_ *Interface) {}

View File

@@ -369,7 +369,7 @@ func (i *Interface) ForEachFeature(cb func(fi FeatureInterface) error) error {
return nil
}
func (i *Interface) OnInterfaceModified(_ *Interface, old *wg.Interface, mod InterfaceModifier) {
func (i *Interface) OnInterfaceModified(_ *Interface, _ *wg.Interface, mod InterfaceModifier) {
if mod&InterfaceModifiedListenPort == 0 {
return
}

View File

@@ -103,11 +103,7 @@ func FindUserDevice(name string) (Device, error) {
func (d *UserDevice) Close() error {
d.Device.Close()
if err := d.apiListener.Close(); err != nil {
return err
}
return nil
return d.apiListener.Close()
}
func (d *UserDevice) Bind() *wg.Bind {

View File

@@ -6,10 +6,10 @@ import (
"net/url"
"strings"
"github.com/pion/ice/v2"
"github.com/pion/stun"
)
func ParseURL(urlStr string) (*ice.URL, string, string, url.Values, error) {
func ParseURL(urlStr string) (*stun.URI, string, string, url.Values, error) {
u, err := url.Parse(urlStr)
if err != nil {
return nil, "", "", nil, err
@@ -37,7 +37,7 @@ func ParseURL(urlStr string) (*ice.URL, string, string, url.Values, error) {
u.RawQuery = ""
}
iu, err := ice.ParseURL(u.String())
iu, err := stun.ParseURI(u.String())
if err != nil {
return nil, "", "", nil, err
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/pion/ice/v2"
"github.com/pion/stun"
)
var (
@@ -17,7 +18,7 @@ type URL struct {
}
func (u *URL) UnmarshalText(text []byte) error {
up, err := ice.ParseURL(string(text))
up, err := stun.ParseURI(string(text))
if err != nil {
return err
}

View File

@@ -4,6 +4,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pion/ice/v2"
"github.com/pion/stun"
icex "github.com/stv0g/cunicu/pkg/ice"
)
@@ -54,45 +55,45 @@ var _ = Describe("Marshaling of ICE types", func() {
Context("URL", func() {
t := []TableEntry{
Entry("stun", "stun:cunicu.0l.de:1234", ice.URL{
Scheme: ice.SchemeTypeSTUN,
Entry("stun", "stun:cunicu.0l.de:1234", stun.URI{
Scheme: stun.SchemeTypeSTUN,
Host: "cunicu.0l.de",
Port: 1234,
Proto: ice.ProtoTypeUDP,
Proto: stun.ProtoTypeUDP,
}),
Entry("stuns", "stuns:cunicu.0l.de:1234", ice.URL{
Scheme: ice.SchemeTypeSTUNS,
Entry("stuns", "stuns:cunicu.0l.de:1234", stun.URI{
Scheme: stun.SchemeTypeSTUNS,
Host: "cunicu.0l.de",
Port: 1234,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
}),
Entry("turn-udp", "turn:cunicu.0l.de:1234?transport=udp", ice.URL{
Scheme: ice.SchemeTypeTURN,
Entry("turn-udp", "turn:cunicu.0l.de:1234?transport=udp", stun.URI{
Scheme: stun.SchemeTypeTURN,
Host: "cunicu.0l.de",
Port: 1234,
Proto: ice.ProtoTypeUDP,
Proto: stun.ProtoTypeUDP,
}),
Entry("turn-tcp", "turn:cunicu.0l.de:1234?transport=tcp", ice.URL{
Scheme: ice.SchemeTypeTURN,
Entry("turn-tcp", "turn:cunicu.0l.de:1234?transport=tcp", stun.URI{
Scheme: stun.SchemeTypeTURN,
Host: "cunicu.0l.de",
Port: 1234,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
}),
Entry("turns", "turns:cunicu.0l.de:1234?transport=tcp", ice.URL{
Scheme: ice.SchemeTypeTURNS,
Entry("turns", "turns:cunicu.0l.de:1234?transport=tcp", stun.URI{
Scheme: stun.SchemeTypeTURNS,
Host: "cunicu.0l.de",
Port: 1234,
Proto: ice.ProtoTypeTCP,
Proto: stun.ProtoTypeTCP,
}),
}
DescribeTable("Unmarshal", func(urlStr string, url ice.URL) {
DescribeTable("Unmarshal", func(urlStr string, url stun.URI) {
var u icex.URL
Expect(u.UnmarshalText([]byte(urlStr))).To(Succeed())
Expect(u.URL).To(Equal(url))
}, t)
DescribeTable("Marshal", func(urlStr string, url ice.URL) {
DescribeTable("Marshal", func(urlStr string, url stun.URI) {
u := icex.URL{url}
m, err := u.MarshalText()
Expect(err).To(Succeed())

View File

@@ -187,7 +187,7 @@ func (d *LinuxLink) DeleteRoute(dst net.IPNet, table int) error {
return netlink.RouteDel(route)
}
func DetectMTU(ip net.IP, fwmark int) (int, error) {
func DetectMTU(ip net.IP, _ int) (int, error) {
// TODO: How do we use the correct fwmark here?
rts, err := netlink.RouteGet(ip)
if err != nil {
@@ -197,7 +197,7 @@ func DetectMTU(ip net.IP, fwmark int) (int, error) {
return mtuFromRoutes(rts)
}
func DetectDefaultMTU(fwmark int) (int, error) {
func DetectDefaultMTU(_ int) (int, error) {
// TODO: How do we use the correct fwmark here?
flt := &netlink.Route{
Dst: nil,

View File

@@ -31,7 +31,7 @@ func (c *PacketPipeConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
return c.rx.ReadFrom(p)
}
func (c *PacketPipeConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
func (c *PacketPipeConn) WriteTo(p []byte, _ net.Addr) (n int, err error) {
return c.tx.WriteFrom(p, c.rx.LocalAddr())
}
@@ -40,11 +40,7 @@ func (c *PacketPipeConn) Close() error {
return err
}
if err := c.tx.Close(); err != nil {
return err
}
return nil
return c.tx.Close()
}
func (c *PacketPipeConn) LocalAddr() net.Addr {
@@ -56,11 +52,7 @@ func (c *PacketPipeConn) SetDeadline(t time.Time) error {
return err
}
if err := c.tx.SetWriteDeadline(t); err != nil {
return err
}
return nil
return c.tx.SetWriteDeadline(t)
}
func (c *PacketPipeConn) SetReadDeadline(t time.Time) error {

View File

@@ -46,11 +46,7 @@ func (c *SplitConn) Close() error {
return err
}
if err := c.send.Close(); err != nil {
return err
}
return nil
return c.send.Close()
}
func (c *SplitConn) LocalAddr() net.Addr {
@@ -62,11 +58,7 @@ func (c *SplitConn) SetDeadline(t time.Time) error {
return err
}
if err := c.send.SetWriteDeadline(t); err != nil {
return err
}
return nil
return c.send.SetWriteDeadline(t)
}
func (c *SplitConn) SetReadDeadline(t time.Time) error {

View File

@@ -25,7 +25,7 @@ func (s *Server) OnInterfaceRemoved(i *daemon.Interface) {
})
}
func (s *Server) OnInterfaceModified(i *daemon.Interface, old *wg.Interface, mod daemon.InterfaceModifier) {
func (s *Server) OnInterfaceModified(i *daemon.Interface, _ *wg.Interface, mod daemon.InterfaceModifier) {
s.events.Send(&rpcproto.Event{
Type: rpcproto.EventType_INTERFACE_MODIFIED,
Interface: i.Name(),
@@ -53,7 +53,7 @@ func (s *Server) OnPeerRemoved(p *daemon.Peer) {
})
}
func (s *Server) OnPeerModified(p *daemon.Peer, old *wgtypes.Peer, mod daemon.PeerModifier, ipsAdded, ipsRemoved []net.IPNet) {
func (s *Server) OnPeerModified(p *daemon.Peer, _ *wgtypes.Peer, mod daemon.PeerModifier, _, _ []net.IPNet) {
s.events.Send(&rpcproto.Event{
Type: rpcproto.EventType_PEER_MODIFIED,
Interface: p.Interface.Name(),
@@ -79,5 +79,5 @@ func (s *Server) OnSignalingBackendReady(b signaling.Backend) {
})
}
func (s *Server) OnSignalingMessage(kp *crypto.PublicKeyPair, msg *signaling.Message) {
func (s *Server) OnSignalingMessage(_ *crypto.PublicKeyPair, _ *signaling.Message) {
}

View File

@@ -54,7 +54,7 @@ func NewDaemonServer(s *Server, d *daemon.Daemon) *DaemonServer {
return ds
}
func (s *DaemonServer) StreamEvents(params *proto.Empty, stream rpcproto.Daemon_StreamEventsServer) error {
func (s *DaemonServer) StreamEvents(_ *proto.Empty, stream rpcproto.Daemon_StreamEventsServer) error {
// Send initial connection state of all peers
s.SendPeerStates(stream)
@@ -87,7 +87,7 @@ func (s *DaemonServer) GetBuildInfo(context.Context, *proto.Empty) (*proto.Build
return buildinfo.BuildInfo(), nil
}
func (s *DaemonServer) UnWait(ctx context.Context, params *proto.Empty) (*proto.Empty, error) {
func (s *DaemonServer) UnWait(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
err := status.Error(codes.AlreadyExists, "RPC socket has already been unwaited")
s.waitOnce.Do(func() {
@@ -98,13 +98,13 @@ func (s *DaemonServer) UnWait(ctx context.Context, params *proto.Empty) (*proto.
return &proto.Empty{}, err
}
func (s *DaemonServer) Stop(ctx context.Context, params *proto.Empty) (*proto.Empty, error) {
func (s *DaemonServer) Stop(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
s.Daemon.Stop()
return &proto.Empty{}, nil
}
func (s *DaemonServer) Restart(ctx context.Context, params *proto.Empty) (*proto.Empty, error) {
func (s *DaemonServer) Restart(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
if osx.ReexecSelfSupported {
s.Daemon.Restart()
} else {
@@ -114,7 +114,7 @@ func (s *DaemonServer) Restart(ctx context.Context, params *proto.Empty) (*proto
return &proto.Empty{}, nil
}
func (s *DaemonServer) Sync(ctx context.Context, params *proto.Empty) (*proto.Empty, error) {
func (s *DaemonServer) Sync(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
if err := s.Daemon.Sync(); err != nil {
return nil, status.Errorf(codes.Unknown, "failed to sync: %s", err)
}
@@ -122,7 +122,7 @@ func (s *DaemonServer) Sync(ctx context.Context, params *proto.Empty) (*proto.Em
return &proto.Empty{}, nil
}
func (s *DaemonServer) GetStatus(ctx context.Context, p *rpcproto.GetStatusParams) (*rpcproto.GetStatusResp, error) { //nolint:gocognit
func (s *DaemonServer) GetStatus(_ context.Context, p *rpcproto.GetStatusParams) (*rpcproto.GetStatusResp, error) { //nolint:gocognit
var err error
var pk crypto.Key
@@ -178,7 +178,7 @@ func (s *DaemonServer) GetStatus(ctx context.Context, p *rpcproto.GetStatusParam
}, nil
}
func (s *DaemonServer) SetConfig(ctx context.Context, p *rpcproto.SetConfigParams) (*proto.Empty, error) {
func (s *DaemonServer) SetConfig(_ context.Context, p *rpcproto.SetConfigParams) (*proto.Empty, error) {
errs := []error{}
settings := map[string]any{}
@@ -240,7 +240,7 @@ func (s *DaemonServer) SetConfig(ctx context.Context, p *rpcproto.SetConfigParam
return &proto.Empty{}, nil
}
func (s *DaemonServer) GetConfig(ctx context.Context, p *rpcproto.GetConfigParams) (*rpcproto.GetConfigResp, error) {
func (s *DaemonServer) GetConfig(_ context.Context, p *rpcproto.GetConfigParams) (*rpcproto.GetConfigResp, error) {
settings := map[string]string{}
match := func(key string) bool {
@@ -271,7 +271,7 @@ func (s *DaemonServer) GetConfig(ctx context.Context, p *rpcproto.GetConfigParam
}, nil
}
func (s *DaemonServer) ReloadConfig(ctx context.Context, params *proto.Empty) (*proto.Empty, error) {
func (s *DaemonServer) ReloadConfig(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
if _, err := s.Config.Reload(); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to reload configuration: %s", err)
}
@@ -279,7 +279,7 @@ func (s *DaemonServer) ReloadConfig(ctx context.Context, params *proto.Empty) (*
return &proto.Empty{}, nil
}
func (s *DaemonServer) AddPeer(ctx context.Context, params *rpcproto.AddPeerParams) (*rpcproto.AddPeerResp, error) {
func (s *DaemonServer) AddPeer(_ context.Context, params *rpcproto.AddPeerParams) (*rpcproto.AddPeerResp, error) {
i := s.InterfaceByName(params.Interface)
if i == nil {
return nil, status.Errorf(codes.NotFound, "Interface %s does not exist", params.Interface)
@@ -335,7 +335,7 @@ func (s *DaemonServer) OnInterfaceAdded(i *daemon.Interface) {
i.AddPeerStateChangeHandler(s)
}
func (s *DaemonServer) OnInterfaceRemoved(i *daemon.Interface) {
func (s *DaemonServer) OnInterfaceRemoved(_ *daemon.Interface) {
}
func (s *DaemonServer) SendPeerStates(stream rpcproto.Daemon_StreamEventsServer) {

View File

@@ -27,7 +27,7 @@ func NewEndpointDiscoveryServer(s *Server) *EndpointDiscoveryServer {
return eps
}
func (s *EndpointDiscoveryServer) RestartPeer(ctx context.Context, params *rpcproto.RestartPeerParams) (*proto.Empty, error) {
func (s *EndpointDiscoveryServer) RestartPeer(_ context.Context, params *rpcproto.RestartPeerParams) (*proto.Empty, error) {
di := s.daemon.InterfaceByName(params.Intf)
if di == nil {
return nil, status.Errorf(codes.NotFound, "unknown interface %s", params.Intf)

View File

@@ -35,10 +35,10 @@ func NewSignalingServer(s *Server, b *signaling.MultiBackend) *SignalingServer {
return ss
}
func (s *SignalingServer) GetSignalingMessage(ctx context.Context, params *rpcproto.GetSignalingMessageParams) (*rpcproto.GetSignalingMessageResp, error) {
func (s *SignalingServer) GetSignalingMessage(_ context.Context, _ *rpcproto.GetSignalingMessageParams) (*rpcproto.GetSignalingMessageResp, error) {
return nil, status.Error(codes.Unimplemented, "not implemented yet")
}
func (s *SignalingServer) PutSignalingMessage(ctx context.Context, params *rpcproto.PutSignalingMessageParams) (*proto.Empty, error) {
func (s *SignalingServer) PutSignalingMessage(_ context.Context, _ *rpcproto.PutSignalingMessageParams) (*proto.Empty, error) {
return &proto.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}

View File

@@ -13,7 +13,7 @@ type readyHandler struct {
ready chan any
}
func (h *readyHandler) OnSignalingBackendReady(b signaling.Backend) {
func (h *readyHandler) OnSignalingBackendReady(_ signaling.Backend) {
close(h.ready)
}

View File

@@ -162,7 +162,7 @@ func (b *Backend) subscribeFromServer(ctx context.Context, pk *crypto.Key) error
return nil
}
func (b *Backend) unsubscribeFromServer(ctx context.Context, pk *crypto.Key) error {
func (b *Backend) unsubscribeFromServer(_ context.Context, _ *crypto.Key) error {
// TODO: Cancel subscription stream
return nil

View File

@@ -121,7 +121,7 @@ out:
return nil
}
func (s *Server) Publish(ctx context.Context, env *signaling.Envelope) (*proto.Empty, error) {
func (s *Server) Publish(_ context.Context, env *signaling.Envelope) (*proto.Empty, error) {
var err error
var pkRecipient, pkSender crypto.Key

View File

@@ -118,7 +118,7 @@ func NewRelayAPIServer(relays []RelayInfo, opts ...grpc.ServerOption) (*RelayAPI
return s, nil
}
func (s *RelayAPIServer) GetRelays(ctx context.Context, params *signalingproto.GetRelaysParams) (*signalingproto.GetRelaysResp, error) {
func (s *RelayAPIServer) GetRelays(_ context.Context, params *signalingproto.GetRelaysParams) (*signalingproto.GetRelaysResp, error) {
resp := &signalingproto.GetRelaysResp{}
pk, err := crypto.ParseKeyBytes(params.PublicKey)

View File

@@ -39,15 +39,15 @@ func (b *Backend) Type() signalingproto.BackendType {
return signalingproto.BackendType_INPROCESS
}
func (b *Backend) Subscribe(ctx context.Context, kp *crypto.KeyPair, h signaling.MessageHandler) (bool, error) {
func (b *Backend) Subscribe(_ context.Context, kp *crypto.KeyPair, h signaling.MessageHandler) (bool, error) {
return subs.Subscribe(kp, h)
}
func (b *Backend) Unsubscribe(ctx context.Context, kp *crypto.KeyPair, h signaling.MessageHandler) (bool, error) {
func (b *Backend) Unsubscribe(_ context.Context, kp *crypto.KeyPair, h signaling.MessageHandler) (bool, error) {
return subs.Unsubscribe(kp, h)
}
func (b *Backend) Publish(ctx context.Context, kp *crypto.KeyPair, msg *signaling.Message) error {
func (b *Backend) Publish(_ context.Context, kp *crypto.KeyPair, msg *signaling.Message) error {
env, err := msg.Encrypt(kp)
if err != nil {
return err

View File

@@ -69,7 +69,7 @@ func PrettyBytes(b int64) string {
var f float32
var i int
for i, f = 0, float32(b); i < len(suffices) && f >= 1024; i, f = i+1, f/1024 {
for i, f = 0, float32(b); i < len(suffices) && f >= 1024; i, f = i+1, f/1024 { //nolint:revive
}
if i == 0 {

View File

@@ -18,7 +18,7 @@ type readyHandler struct {
Count atomic.Uint32
}
func (r *readyHandler) OnSignalingBackendReady(b signaling.Backend) {
func (r *readyHandler) OnSignalingBackendReady(_ signaling.Backend) {
r.Count.Add(1)
}

View File

@@ -69,10 +69,10 @@ func (matcher *eventMatcher[E]) Match(actual any) (success bool, err error) {
}
}
func (matcher *eventMatcher[E]) FailureMessage(actual any) (message string) {
func (matcher *eventMatcher[E]) FailureMessage(_ any) (message string) {
return "Did not receive expected event"
}
func (matcher *eventMatcher[E]) NegatedFailureMessage(actual any) (message string) {
func (matcher *eventMatcher[E]) NegatedFailureMessage(_ any) (message string) {
return "Received event unexpectedly"
}