Linter update & fixes

This commit is contained in:
Neil Alexander
2026-01-18 14:51:52 +00:00
parent 24482b7dbe
commit fd46eab3b9
11 changed files with 36 additions and 29 deletions

View File

@@ -1,11 +1,18 @@
version: "2"
run: run:
build-tags: build-tags:
- lint - lint
issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds issues-exit-code: 1
issues:
exclude-dirs:
- contrib/
- misc/
linters: linters:
disable: disable:
- gocyclo - gocyclo
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- contrib/
- misc/

View File

@@ -314,26 +314,26 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
req.Arguments = []byte("{}") req.Arguments = []byte("{}")
if err := func() error { if err := func() error {
if err = decoder.Decode(&buf); err != nil { if err = decoder.Decode(&buf); err != nil {
return fmt.Errorf("Failed to find request") return fmt.Errorf("failed to find request")
} }
if err = json.Unmarshal(buf, &req); err != nil { if err = json.Unmarshal(buf, &req); err != nil {
return fmt.Errorf("Failed to unmarshal request") return fmt.Errorf("failed to unmarshal request")
} }
resp.Request = req resp.Request = req
if req.Name == "" { if req.Name == "" {
return fmt.Errorf("No request specified") return fmt.Errorf("no request specified")
} }
reqname := strings.ToLower(req.Name) reqname := strings.ToLower(req.Name)
handler, ok := a.handlers[reqname] handler, ok := a.handlers[reqname]
if !ok { if !ok {
return fmt.Errorf("Unknown action '%s', try 'list' for help", reqname) return fmt.Errorf("unknown action '%s', try 'list' for help", reqname)
} }
res, err := handler.handler(req.Arguments) res, err := handler.handler(req.Arguments)
if err != nil { if err != nil {
return err return err
} }
if resp.Response, err = json.Marshal(res); err != nil { if resp.Response, err = json.Marshal(res); err != nil {
return fmt.Errorf("Failed to marshal response: %w", err) return fmt.Errorf("failed to marshal response: %w", err)
} }
resp.Status = "success" resp.Status = "success"
return nil return nil

View File

@@ -138,7 +138,7 @@ func (c *Core) GetPaths() []PathEntryInfo {
func (c *Core) GetSessions() []SessionInfo { func (c *Core) GetSessions() []SessionInfo {
var sessions []SessionInfo var sessions []SessionInfo
ss := c.PacketConn.Debug.GetSessions() ss := c.Debug.GetSessions()
for _, s := range ss { for _, s := range ss {
var info SessionInfo var info SessionInfo
info.Key = s.Key info.Key = s.Key

View File

@@ -157,7 +157,7 @@ func (c *Core) Stop() {
func (c *Core) _close() error { func (c *Core) _close() error {
c.cancel() c.cancel()
c.links.shutdown() c.links.shutdown()
err := c.PacketConn.Close() err := c.Close()
return err return err
} }

View File

@@ -52,7 +52,7 @@ func (l *links) newLinkQUIC() *linkQUIC {
func (l *linkQUIC) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { func (l *linkQUIC) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.tlsconfig.Clone() tlsconfig := l.tlsconfig.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12 tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13 tlsconfig.MaxVersion = tls.VersionTLS13

View File

@@ -31,7 +31,7 @@ func (l *linkSOCKS) dial(_ context.Context, url *url.URL, info linkInfo, options
proxyAuth.Password, _ = url.User.Password() proxyAuth.Password, _ = url.User.Password()
} }
tlsconfig := l.tls.config.Clone() tlsconfig := l.tls.config.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
hostport := net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port)) hostport := net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
dialer, err := l.tcp.dialerFor(&net.TCPAddr{ dialer, err := l.tcp.dialerFor(&net.TCPAddr{
IP: ip, IP: ip,

View File

@@ -28,7 +28,7 @@ func (l *links) newLinkTCP() *linkTCP {
} }
func (l *linkTCP) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { func (l *linkTCP) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
addr := &net.TCPAddr{ addr := &net.TCPAddr{
IP: ip, IP: ip,
Port: port, Port: port,

View File

@@ -33,7 +33,7 @@ func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS {
func (l *linkTLS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { func (l *linkTLS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.config.Clone() tlsconfig := l.config.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12 tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13 tlsconfig.MaxVersion = tls.VersionTLS13

View File

@@ -88,7 +88,7 @@ func (l *links) newLinkWS() *linkWS {
} }
func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
u := *url u := *url
u.Host = net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port)) u.Host = net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
addr := &net.TCPAddr{ addr := &net.TCPAddr{

View File

@@ -32,7 +32,7 @@ func (l *links) newLinkWSS() *linkWSS {
func (l *linkWSS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { func (l *linkWSS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.tlsconfig.Clone() tlsconfig := l.tlsconfig.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) { return l.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12 tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13 tlsconfig.MaxVersion = tls.VersionTLS13

View File

@@ -143,13 +143,13 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error)
return nil, err return nil, err
} }
if req.Key == "" { if req.Key == "" {
return nil, fmt.Errorf("No remote public key supplied") return nil, fmt.Errorf("no remote public key supplied")
} }
var key keyArray var key keyArray
var kbs []byte var kbs []byte
var err error var err error
if kbs, err = hex.DecodeString(req.Key); err != nil { if kbs, err = hex.DecodeString(req.Key); err != nil {
return nil, fmt.Errorf("Failed to decode public key: %w", err) return nil, fmt.Errorf("failed to decode public key: %w", err)
} }
copy(key[:], kbs) copy(key[:], kbs)
ch := make(chan []byte, 1) ch := make(chan []byte, 1)
@@ -160,7 +160,7 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error)
defer timer.Stop() defer timer.Stop()
select { select {
case <-timer.C: case <-timer.C:
return nil, errors.New("Timed out waiting for response") return nil, errors.New("timed out waiting for response")
case info := <-ch: case info := <-ch:
var msg json.RawMessage var msg json.RawMessage
if err := msg.UnmarshalJSON(info); err != nil { if err := msg.UnmarshalJSON(info); err != nil {