diff --git a/.golangci.yml b/.golangci.yml index 836af618..b30f9c4a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,18 @@ +version: "2" run: build-tags: - lint - issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds -issues: - exclude-dirs: - - contrib/ - - misc/ + issues-exit-code: 1 linters: disable: - gocyclo + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - contrib/ + - misc/ diff --git a/src/admin/admin.go b/src/admin/admin.go index 750694f6..305cac30 100644 --- a/src/admin/admin.go +++ b/src/admin/admin.go @@ -314,26 +314,26 @@ func (a *AdminSocket) handleRequest(conn net.Conn) { req.Arguments = []byte("{}") if err := func() error { 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 { - return fmt.Errorf("Failed to unmarshal request") + return fmt.Errorf("failed to unmarshal request") } resp.Request = req if req.Name == "" { - return fmt.Errorf("No request specified") + return fmt.Errorf("no request specified") } reqname := strings.ToLower(req.Name) handler, ok := a.handlers[reqname] 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) if err != nil { return err } 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" return nil diff --git a/src/core/api.go b/src/core/api.go index cc1bde32..582043a5 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -138,7 +138,7 @@ func (c *Core) GetPaths() []PathEntryInfo { func (c *Core) GetSessions() []SessionInfo { var sessions []SessionInfo - ss := c.PacketConn.Debug.GetSessions() + ss := c.Debug.GetSessions() for _, s := range ss { var info SessionInfo info.Key = s.Key diff --git a/src/core/core.go b/src/core/core.go index 71e267fa..26be28a2 100644 --- a/src/core/core.go +++ b/src/core/core.go @@ -27,14 +27,14 @@ type Core struct { // guarantee that it will be covered by the mutex phony.Inbox *iwe.PacketConn - ctx context.Context - cancel context.CancelFunc - secret ed25519.PrivateKey - public ed25519.PublicKey - links links - proto protoHandler - log Logger - config struct { + ctx context.Context + cancel context.CancelFunc + secret ed25519.PrivateKey + public ed25519.PublicKey + links links + proto protoHandler + log Logger + config struct { tls *tls.Config // immutable after startup //_peers map[Peer]*linkInfo // configurable after startup _listeners map[ListenAddress]struct{} // configurable after startup @@ -157,7 +157,7 @@ func (c *Core) Stop() { func (c *Core) _close() error { c.cancel() c.links.shutdown() - err := c.PacketConn.Close() + err := c.Close() return err } diff --git a/src/core/link_quic.go b/src/core/link_quic.go index 1296680d..ffe7a2c8 100644 --- a/src/core/link_quic.go +++ b/src/core/link_quic.go @@ -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) { 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.MinVersion = tls.VersionTLS12 tlsconfig.MaxVersion = tls.VersionTLS13 diff --git a/src/core/link_socks.go b/src/core/link_socks.go index 495c8233..8b7fbcc2 100644 --- a/src/core/link_socks.go +++ b/src/core/link_socks.go @@ -31,7 +31,7 @@ func (l *linkSOCKS) dial(_ context.Context, url *url.URL, info linkInfo, options proxyAuth.Password, _ = url.User.Password() } 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)) dialer, err := l.tcp.dialerFor(&net.TCPAddr{ IP: ip, diff --git a/src/core/link_tcp.go b/src/core/link_tcp.go index e50912d3..484e0164 100644 --- a/src/core/link_tcp.go +++ b/src/core/link_tcp.go @@ -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) { - 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{ IP: ip, Port: port, diff --git a/src/core/link_tls.go b/src/core/link_tls.go index 55da8597..f5438ea8 100644 --- a/src/core/link_tls.go +++ b/src/core/link_tls.go @@ -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) { 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.MinVersion = tls.VersionTLS12 tlsconfig.MaxVersion = tls.VersionTLS13 diff --git a/src/core/link_ws.go b/src/core/link_ws.go index 86f065a6..b4638d5c 100644 --- a/src/core/link_ws.go +++ b/src/core/link_ws.go @@ -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) { - 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.Host = net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port)) addr := &net.TCPAddr{ diff --git a/src/core/link_wss.go b/src/core/link_wss.go index 1d618324..d7ffeace 100644 --- a/src/core/link_wss.go +++ b/src/core/link_wss.go @@ -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) { 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.MinVersion = tls.VersionTLS12 tlsconfig.MaxVersion = tls.VersionTLS13 diff --git a/src/core/nodeinfo.go b/src/core/nodeinfo.go index 6f1f4be8..698aac7f 100644 --- a/src/core/nodeinfo.go +++ b/src/core/nodeinfo.go @@ -143,13 +143,13 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error) return nil, err } 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 kbs []byte var err error 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) ch := make(chan []byte, 1) @@ -160,7 +160,7 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error) defer timer.Stop() select { case <-timer.C: - return nil, errors.New("Timed out waiting for response") + return nil, errors.New("timed out waiting for response") case info := <-ch: var msg json.RawMessage if err := msg.UnmarshalJSON(info); err != nil {