From e3dc34ea5d3285b4e575a18132a4be208e5b4247 Mon Sep 17 00:00:00 2001 From: sc0vu Date: Mon, 23 Oct 2023 17:03:01 +0800 Subject: [PATCH] server: update lint --- server/Makefile | 7 +++++-- server/cborplugin/client.go | 1 - server/cmd/meson-server/main.go | 5 ++--- server/config/config.go | 4 ++-- server/internal/incoming/incoming_conn.go | 8 ++++---- server/internal/outgoing/outgoing_conn.go | 8 ++++---- server/internal/packet/packet.go | 2 +- server/internal/pki/pki.go | 4 ++-- server/internal/provider/kaetzchen/kaetzchen_test.go | 3 +-- server/userdb/externuserdb/externuserdb.go | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/server/Makefile b/server/Makefile index 859c3155..38b97fbd 100644 --- a/server/Makefile +++ b/server/Makefile @@ -6,8 +6,11 @@ default: lint test .PHONY: lint lint: - # go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.0 - # $(GOPATH)/bin/golangci-lint run -e gosec ./... --timeout 2m + # cd ../tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint + # $(GOPATH)/bin/golangci-lint run -e gosec ./... --timeout=2m + cd ../ test && go install honnef.co/go/tools/cmd/staticcheck@latest + $(GOPATH)/bin/staticcheck ./... + go vet ./... go fmt ./... go mod tidy diff --git a/server/cborplugin/client.go b/server/cborplugin/client.go index fe37818b..1ee4647c 100644 --- a/server/cborplugin/client.go +++ b/server/cborplugin/client.go @@ -21,7 +21,6 @@ // as described in our Kaetzchen specification document: // // https://github.com/katzenpost/docs/blob/master/specs/kaetzchen.rst -// package cborplugin import ( diff --git a/server/cmd/meson-server/main.go b/server/cmd/meson-server/main.go index 0c44554d..6a96aab8 100644 --- a/server/cmd/meson-server/main.go +++ b/server/cmd/meson-server/main.go @@ -13,7 +13,6 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - package main import ( @@ -61,10 +60,10 @@ func main() { } // Setup the signal handling. - haltCh := make(chan os.Signal) + haltCh := make(chan os.Signal, 1) signal.Notify(haltCh, os.Interrupt, syscall.SIGTERM) // nolint - rotateCh := make(chan os.Signal) + rotateCh := make(chan os.Signal, 1) signal.Notify(rotateCh, syscall.SIGHUP) // nolint // Start up the server. diff --git a/server/config/config.go b/server/config/config.go index 95b37f6c..cb3699c9 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -909,7 +909,7 @@ func Store(cfg *Config, fileName string) error { // returns the Config. func Load(b []byte) (*Config, error) { if b == nil { - return nil, errors.New("No nil buffer as config file") + return nil, errors.New("no nil buffer as config file") } cfg := new(Config) @@ -918,7 +918,7 @@ func Load(b []byte) (*Config, error) { return nil, err } if undecoded := md.Undecoded(); len(undecoded) != 0 { - return nil, fmt.Errorf("config: Undecoded keys in config file: %v", undecoded) + return nil, fmt.Errorf("undecoded keys in config file: %v", undecoded) } if err := cfg.FixupAndValidate(); err != nil { return nil, err diff --git a/server/internal/incoming/incoming_conn.go b/server/internal/incoming/incoming_conn.go index ce98723b..f90f4898 100644 --- a/server/internal/incoming/incoming_conn.go +++ b/server/internal/incoming/incoming_conn.go @@ -197,8 +197,8 @@ func (c *incomingConn) worker() { defer c.w.Close() // Bind the session to the conn, handshake, authenticate. - timeoutMs := time.Duration(c.l.glue.Config().Debug.HandshakeTimeout) * time.Millisecond - _ = c.c.SetDeadline(time.Now().Add(timeoutMs)) + timeoutDu := time.Duration(c.l.glue.Config().Debug.HandshakeTimeout) * time.Millisecond + _ = c.c.SetDeadline(time.Now().Add(timeoutDu)) if err = c.w.Initialize(c.c); err != nil { c.log.Errorf("Handshake failed: %v", err) return @@ -233,8 +233,8 @@ func (c *incomingConn) worker() { } // Start the reauthenticate ticker. - reauthMs := time.Duration(c.l.glue.Config().Debug.ReauthInterval) * time.Millisecond - reauth := time.NewTicker(reauthMs) + reauthDu := time.Duration(c.l.glue.Config().Debug.ReauthInterval) * time.Millisecond + reauth := time.NewTicker(reauthDu) defer reauth.Stop() // Start reading from the peer. diff --git a/server/internal/outgoing/outgoing_conn.go b/server/internal/outgoing/outgoing_conn.go index 29ed2440..21d91581 100644 --- a/server/internal/outgoing/outgoing_conn.go +++ b/server/internal/outgoing/outgoing_conn.go @@ -274,8 +274,8 @@ func (c *outgoingConn) onConnEstablished(conn net.Conn, closeCh <-chan struct{}) defer w.Close() // Bind the session to the conn, handshake, authenticate. - timeoutMs := time.Duration(c.co.glue.Config().Debug.HandshakeTimeout) * time.Millisecond - _ = conn.SetDeadline(time.Now().Add(timeoutMs)) + timeoutDu := time.Duration(c.co.glue.Config().Debug.HandshakeTimeout) * time.Millisecond + _ = conn.SetDeadline(time.Now().Add(timeoutDu)) if err = w.Initialize(conn); err != nil { c.log.Errorf("Handshake failed: %v", err) return @@ -326,8 +326,8 @@ func (c *outgoingConn) onConnEstablished(conn net.Conn, closeCh <-chan struct{}) }() // Start the reauthenticate ticker. - reauthMs := time.Duration(c.co.glue.Config().Debug.ReauthInterval) * time.Millisecond - reauth := time.NewTicker(reauthMs) + reauthDu := time.Duration(c.co.glue.Config().Debug.ReauthInterval) * time.Millisecond + reauth := time.NewTicker(reauthDu) defer reauth.Stop() // Shuffle packets from the send queue out to the peer. diff --git a/server/internal/packet/packet.go b/server/internal/packet/packet.go index 2dd53cf1..3849eef1 100644 --- a/server/internal/packet/packet.go +++ b/server/internal/packet/packet.go @@ -186,7 +186,7 @@ func (pkt *Packet) copyToRaw(b []byte) error { func (pkt *Packet) disposeRaw() { if len(pkt.Raw) == constants.PacketLength { utils.ExplicitBzero(pkt.Raw) - rawPacketPool.Put(pkt.Raw) // nolint: megacheck + rawPacketPool.Put(&pkt.Raw) // nolint: megacheck } pkt.Raw = nil } diff --git a/server/internal/pki/pki.go b/server/internal/pki/pki.go index 6c0182c8..426bd72e 100644 --- a/server/internal/pki/pki.go +++ b/server/internal/pki/pki.go @@ -695,7 +695,7 @@ func (p *pki) GetRawConsensus(epoch uint64) ([]byte, error) { func (p *pki) Now() (epoch uint64, ellapsed time.Duration, till time.Duration, err error) { if p.impl == nil { - return 0, 0, 0, fmt.Errorf("PKI client uninitialized.") + return 0, 0, 0, fmt.Errorf("PKI client uninitialized") } return epochtime.Now(p.impl) } @@ -732,7 +732,7 @@ func New(glue glue.Glue) (glue.PKI, error) { } if len(p.descAddrMap) == 0 { - return nil, errors.New("Descriptor address map is zero size.") + return nil, errors.New("descriptor address map is zero size") } if glue.Config().PKI.Nonvoting != nil { diff --git a/server/internal/provider/kaetzchen/kaetzchen_test.go b/server/internal/provider/kaetzchen/kaetzchen_test.go index d1997b5b..9c3f4ae5 100644 --- a/server/internal/provider/kaetzchen/kaetzchen_test.go +++ b/server/internal/provider/kaetzchen/kaetzchen_test.go @@ -33,7 +33,6 @@ import ( "github.com/katzenpost/core/log" "github.com/katzenpost/core/monotime" "github.com/katzenpost/core/sphinx/commands" - "github.com/katzenpost/core/sphinx/constants" sConstants "github.com/katzenpost/core/sphinx/constants" "github.com/katzenpost/core/thwack" "github.com/katzenpost/core/wire" @@ -70,7 +69,7 @@ type mockSpool struct{} func (s *mockSpool) StoreMessage(u, msg []byte) error { return nil } -func (s *mockSpool) StoreSURBReply(u []byte, id *[constants.SURBIDLength]byte, msg []byte) error { +func (s *mockSpool) StoreSURBReply(u []byte, id *[sConstants.SURBIDLength]byte, msg []byte) error { return nil } diff --git a/server/userdb/externuserdb/externuserdb.go b/server/userdb/externuserdb/externuserdb.go index f83aa914..b0362a9d 100644 --- a/server/userdb/externuserdb/externuserdb.go +++ b/server/userdb/externuserdb/externuserdb.go @@ -31,8 +31,8 @@ import ( ) var ( - errCantModify = errors.New("Not implemented: External authentication is enabled, you can not modify users") - errNotSupported = errors.New("Not implemented: Support not implemented yet") + errCantModify = errors.New("not implemented: External authentication is enabled, you can not modify users") + errNotSupported = errors.New("not implemented: Support not implemented yet") jsonHandle = &codec.JsonHandle{} )