Skip to content

Commit

Permalink
Merge pull request #1885 from mrpalide/fix/solve-golangci-lint-issues…
Browse files Browse the repository at this point in the history
…-on-codebase

Fix codebase issues
  • Loading branch information
mrpalide authored Oct 18, 2024
2 parents 8ab4b9d + c0296d5 commit 59a24a4
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 62 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- uses: actions/checkout@v3
- name: deploy to docker
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.21.x
go-version: 1.23.x
- uses: actions/checkout@v4
- name: Install Requirements
run: |
Expand All @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.21.x
go-version: 1.23.x
- uses: actions/checkout@v4
- name: Install Requirements
run: |
Expand All @@ -48,7 +48,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.21.x
go-version: 1.23.x
- uses: actions/checkout@v4
- name: Install Requirements
shell: pwsh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install Requirements
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
make dep
chmod +x ./ci_scripts/create-ip-aliases.sh
./ci_scripts/create-ip-aliases.sh
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install Requirements
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
make dep
chmod +x ./ci_scripts/create-ip-aliases.sh
./ci_scripts/create-ip-aliases.sh
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Install Requirements
run: |
choco install make
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
make dep
- name: Testing
run: |
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ linters:
- ineffassign
- typecheck
- gosec
- gosimple
- staticcheck
- unused
- misspell
- nakedret
enable-all: false
Expand Down
2 changes: 0 additions & 2 deletions cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/skycoin/dmsg/pkg/disc"
"github.com/spf13/cobra"

"github.com/skycoin/skywire"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
Expand All @@ -24,7 +23,6 @@ var (
Test: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}},
Prod: visorconfig.DmsgHTTPServersData{DMSGServers: []*disc.Entry{}},
}
emdeddedSvcConf = skywire.Prod
path string
noFetch bool
noDefaults bool
Expand Down
6 changes: 3 additions & 3 deletions cmd/skywire-cli/commands/rewards/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func server() {
case <-dmsgclient.Ready():
}

lis, err := dmsgclient.Listen(uint16(dmsgPort))
lis, err := dmsgclient.Listen(uint16(dmsgPort)) //nolint: gosec
if err != nil {
log.WithError(err).Fatal()
}
Expand Down Expand Up @@ -1487,7 +1487,7 @@ func scriptExecUint(s string) uint {
}
i, err := strconv.Atoi(strings.TrimSpace(strings.TrimRight(out, "\n")))
if err == nil {
return uint(i) //nolint
return uint(i) //nolint: gosec
}
return 0
}
Expand All @@ -1500,7 +1500,7 @@ func scriptExecUint(s string) uint {
}
i, err := strconv.Atoi(z)
if err == nil {
return uint(i) //nolint
return uint(i) //nolint: gosec
}
}
return uint(0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/visor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var shutdownCmd = &cobra.Command{
if err != nil {
os.Exit(1)
}
rpcClient.Shutdown() //nolint
rpcClient.Shutdown() //nolint: errcheck, gosec
internal.PrintOutput(cmd.Flags(), "Visor was shut down", fmt.Sprintln("Visor was shut down"))
},
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/skycoin/skywire

go 1.21

toolchain go1.21.12
go 1.23

require (
github.com/AudriusButkevicius/pfilter v0.0.11
Expand Down
4 changes: 2 additions & 2 deletions internal/httpauth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func checkResp(t *testing.T, headers http.Header, body []byte, pk cipher.PubKey,
require.Equal(t, pk.Hex(), headers.Get("Sw-Public"))
sig := cipher.Sig{}
require.NoError(t, sig.UnmarshalText([]byte(headers.Get("Sw-Sig"))))
require.NoError(t, cipher.VerifyPubKeySignedPayload(pk, sig, PayloadWithNonce(body, Nonce(nonce)))) //nolint
require.NoError(t, cipher.VerifyPubKeySignedPayload(pk, sig, PayloadWithNonce(body, Nonce(nonce)))) //nolint: gosec
}

func newTestServer(t *testing.T, pk cipher.PubKey, headerCh chan<- http.Header) *httptest.Server {
nonce := 1
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.String() == fmt.Sprintf("/security/nonces/%s", pk) {
require.NoError(t, json.NewEncoder(w).Encode(&NextNonceResponse{pk, Nonce(nonce)})) //nolint
require.NoError(t, json.NewEncoder(w).Encode(&NextNonceResponse{pk, Nonce(nonce)})) //nolint: gosec
} else {
body, err := io.ReadAll(r.Body)
if body != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/appcommon/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func WriteHello(w io.Writer, hello Hello) error {

raw := make([]byte, 2+len(helloRaw))
size := len(helloRaw)
binary.BigEndian.PutUint16(raw[:2], uint16(size)) //nolint
binary.BigEndian.PutUint16(raw[:2], uint16(size)) //nolint: gosec
if n := copy(raw[2:], helloRaw); n != size {
panic("hello write does not add up")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/app/appserver/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ func (p *Proc) ConnectionsSummary() []ConnectionSummary {
}

var summaries []ConnectionSummary
// rpcGW.cm.DoRange(func(id uint16, v interface{}) bool {
rpcGW.cm.DoRange(func(_ uint16, v interface{}) bool {
if v == nil {
summaries = append(summaries, ConnectionSummary{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (m *procManager) Start(conf appcommon.ProcConfig) (appcommon.ProcID, error)
return 0, err
}
delete(m.errors, conf.AppName)
return appcommon.ProcID(proc.cmd.Process.Pid), nil //nolint
return appcommon.ProcID(proc.cmd.Process.Pid), nil //nolint: gosec
}

// Register registers a proc for an external app.
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/idmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestManager_DoRange(t *testing.T) {
}

for i, v := range vals {
_, err := m.Add(uint16(i), v) //nolint
_, err := m.Add(uint16(i), v) //nolint: gosec
require.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/router/network_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *networkStats) SetLatency(latency uint32) {
func (s *networkStats) Latency() time.Duration {
latencyMs := atomic.LoadUint32(&s.latency)
// the latency is store in uint32 of millisecond but time.Duration takes nanosecond
return time.Duration(latencyMs * uint32(time.Millisecond.Nanoseconds())) //nolint
return time.Duration(latencyMs * uint32(time.Millisecond.Nanoseconds())) //nolint: gosec
}

func (s *networkStats) SetUploadSpeed(speed uint32) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (rg *RouteGroup) sendPing() error {

throughput := rg.networkStats.RemoteThroughput()
timestamp := time.Now().UTC().UnixNano() / int64(time.Millisecond)
rg.networkStats.SetDownloadSpeed(uint32(throughput)) //nolint
rg.networkStats.SetDownloadSpeed(uint32(throughput)) //nolint: gosec

packet := routing.MakePingPacket(rule.NextRouteID(), timestamp, throughput)

Expand Down Expand Up @@ -697,7 +697,7 @@ func (rg *RouteGroup) handleErrorPacket(packet routing.Packet) error {
return nil
}

rg.SetError(fmt.Errorf("%v", string(packet.Payload())))
rg.SetError(errors.New((string(packet.Payload()))))
return nil
}

Expand All @@ -723,9 +723,9 @@ func (rg *RouteGroup) handlePingPacket(packet routing.Packet) error {

rg.logger.WithField("func", "RouteGroup.handlePingPacket").Tracef("Throughput is around %d", throughput)

rg.networkStats.SetUploadSpeed(uint32(throughput)) //nolint
rg.networkStats.SetUploadSpeed(uint32(throughput)) //nolint: gosec

return rg.sendPong(int64(timestamp)) //nolint
return rg.sendPong(int64(timestamp)) //nolint: gosec
}

func (rg *RouteGroup) handlePongPacket(packet routing.Packet) error {
Expand All @@ -734,13 +734,13 @@ func (rg *RouteGroup) handlePongPacket(packet routing.Packet) error {
sentAtMs := binary.BigEndian.Uint64(payload)

ms := sentAtMs % 1000
sentAt := time.Unix(int64(sentAtMs/1000), int64(ms)*int64(time.Millisecond)).UTC() //nolint
sentAt := time.Unix(int64(sentAtMs/1000), int64(ms)*int64(time.Millisecond)).UTC() //nolint: gosec

latency := time.Now().UTC().Sub(sentAt).Milliseconds()

rg.logger.WithField("func", "RouteGroup.handlePongPacket").Tracef("Latency is around %d ms", latency)

rg.networkStats.SetLatency(uint32(latency)) //nolint
rg.networkStats.SetLatency(uint32(latency)) //nolint: gosec

return nil
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,11 @@ func (r *router) forwardPacket(ctx context.Context, packet routing.Packet, rule
case routing.ClosePacket:
p = routing.MakeClosePacket(rule.NextRouteID(), routing.CloseCode(packet.Payload()[0]))
case routing.PingPacket:
timestamp := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset:])) //nolint
throughput := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset+8:])) //nolint
timestamp := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset:])) //nolint: gosec
throughput := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset+8:])) //nolint: gosec
p = routing.MakePingPacket(rule.NextRouteID(), timestamp, throughput)
case routing.PongPacket:
timestamp := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset:])) //nolint
timestamp := int64(binary.BigEndian.Uint64(packet[routing.PacketPayloadOffset:])) //nolint: gosec
p = routing.MakePongPacket(rule.NextRouteID(), timestamp)
case routing.ErrorPacket:
var err error
Expand Down Expand Up @@ -1328,7 +1328,6 @@ func (r *router) removeRouteGroupOfRule(rule routing.Rule) {
}

func (r *router) checkIfTransportAvailable() (ok bool) {
// r.tm.WalkTransports(func(tp *transport.ManagedTransport) bool {
r.tm.WalkTransports(func(_ *transport.ManagedTransport) bool {
ok = true
return ok
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/rpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestRPCGateway_ReserveIDs(t *testing.T) {
gateway := NewRPCGateway(r, mlog)

var gotIDs []routing.RouteID
err := gateway.ReserveIDs(uint8(n), &gotIDs) //nolint
err := gateway.ReserveIDs(uint8(n), &gotIDs) //nolint: gosec
require.NoError(t, err)
require.Equal(t, ids, gotIDs)
})
Expand All @@ -141,7 +141,7 @@ func TestRPCGateway_ReserveIDs(t *testing.T) {
}

var gotIDs []routing.RouteID
err := gateway.ReserveIDs(uint8(n), &gotIDs) //nolint
err := gateway.ReserveIDs(uint8(n), &gotIDs) //nolint: gosec
require.Equal(t, wantErr, err)
require.Nil(t, gotIDs)
})
Expand Down
10 changes: 5 additions & 5 deletions pkg/routing/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func MakeDataPacket(id RouteID, payload []byte) (Packet, error) {

packet[PacketTypeOffset] = byte(DataPacket)
binary.BigEndian.PutUint32(packet[PacketRouteIDOffset:], uint32(id))
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(len(payload))) //nolint
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(len(payload))) //nolint: gosec
copy(packet[PacketPayloadOffset:], payload)

return packet, nil
Expand Down Expand Up @@ -141,8 +141,8 @@ func MakePingPacket(id RouteID, timestamp, throughput int64) Packet {
packet[PacketTypeOffset] = byte(PingPacket)
binary.BigEndian.PutUint32(packet[PacketRouteIDOffset:], uint32(id))
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(16))
binary.BigEndian.PutUint64(packet[PacketPayloadOffset:], uint64(timestamp)) //nolint
binary.BigEndian.PutUint64(packet[PacketPayloadOffset+8:], uint64(throughput)) //nolint
binary.BigEndian.PutUint64(packet[PacketPayloadOffset:], uint64(timestamp)) //nolint: gosec
binary.BigEndian.PutUint64(packet[PacketPayloadOffset+8:], uint64(throughput)) //nolint: gosec

return packet
}
Expand All @@ -154,7 +154,7 @@ func MakePongPacket(id RouteID, timestamp int64) Packet {
packet[PacketTypeOffset] = byte(PongPacket)
binary.BigEndian.PutUint32(packet[PacketRouteIDOffset:], uint32(id))
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(16))
binary.BigEndian.PutUint64(packet[PacketPayloadOffset:], uint64(timestamp)) //nolint
binary.BigEndian.PutUint64(packet[PacketPayloadOffset:], uint64(timestamp)) //nolint: gosec

return packet
}
Expand Down Expand Up @@ -187,7 +187,7 @@ func MakeErrorPacket(id RouteID, errPayload []byte) (Packet, error) {

packet[PacketTypeOffset] = byte(ErrorPacket)
binary.BigEndian.PutUint32(packet[PacketRouteIDOffset:], uint32(id))
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(len(errPayload))) //nolint
binary.BigEndian.PutUint16(packet[PacketPayloadSizeOffset:], uint16(len(errPayload))) //nolint: gosec
copy(packet[PacketPayloadOffset:], errPayload)

return packet, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/routing/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r Rule) assertLen(l int) {
// KeepAlive returns rule's keep-alive timeout.
func (r Rule) KeepAlive() time.Duration {
r.assertLen(RuleHeaderSize)
return time.Duration(binary.BigEndian.Uint64(r[0:8])) //nolint
return time.Duration(binary.BigEndian.Uint64(r[0:8])) //nolint: gosec
}

// setKeepAlive sets rule's keep-alive timeout.
Expand All @@ -76,7 +76,7 @@ func (r Rule) setKeepAlive(keepAlive time.Duration) {
keepAlive = 0
}

binary.BigEndian.PutUint64(r[0:8], uint64(keepAlive)) //nolint
binary.BigEndian.PutUint64(r[0:8], uint64(keepAlive)) //nolint: gosec
}

// Type returns type of a rule.
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (mt *memTable) reserveKeysImpl(n int) (first, last RouteID, err error) {
}

first = mt.nextID + 1
mt.nextID += RouteID(n) //nolint
mt.nextID += RouteID(n) //nolint: gosec
last = mt.nextID

return first, last, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/transport/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (hs SettlementHS) Do(ctx context.Context, dc DiscoveryClient, transport net
// The handshake logic only REGISTERS the transport, and does not update the status of the transport.
func MakeSettlementHS(init bool, log *logging.Logger) SettlementHS {
// initiating logic.
initHS := func(ctx context.Context, dc DiscoveryClient, transport network.Transport, sk cipher.SecKey) (err error) { //nolint
initHS := func(_ context.Context, _ DiscoveryClient, transport network.Transport, sk cipher.SecKey) (err error) {
entry := makeEntryFromTransport(transport)

// create signed entry and send it to responding visor.
Expand Down
4 changes: 2 additions & 2 deletions pkg/transport/managed_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (mt *ManagedTransport) WritePacket(ctx context.Context, packet routing.Pack
return err
}
if n > routing.PacketHeaderSize {
mt.logSent(uint64(n - routing.PacketHeaderSize)) //nolint
mt.logSent(uint64(n - routing.PacketHeaderSize)) //nolint: gosec
}
return nil
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func (mt *ManagedTransport) readPacket() (packet routing.Packet, err error) {

packet = append(h, p...)
if n := len(packet); n > routing.PacketHeaderSize {
mt.logRecv(uint64(n - routing.PacketHeaderSize)) //nolint
mt.logRecv(uint64(n - routing.PacketHeaderSize)) //nolint: gosec
}

log.WithField("type", packet.Type().String()).
Expand Down
1 change: 0 additions & 1 deletion pkg/transport/network/addrresolver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func authHandler(next http.Handler) http.Handler {
r := chi.NewRouter()

r.Handle("/security/nonces/{pk}", http.HandlerFunc(
// func(w http.ResponseWriter, r *http.Request) {
func(w http.ResponseWriter, _ *http.Request) {
if err := json.NewEncoder(w).Encode(&httpauth.NextNonceResponse{Edge: testPubKey, NextNonce: 1}); err != nil {
log.WithError(err).Error("Failed to encode nonce response")
Expand Down
1 change: 0 additions & 1 deletion pkg/transport/network/handshake/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func MakeF2PortChecker(portChecker func(port uint16) error) CheckF2 {

// ResponderHandshake creates the handshake logic on the responder's side.
func ResponderHandshake(checkF2 CheckF2) Handshake {
// return handshakeMiddleware(func(conn net.Conn, deadline time.Time) (lAddr, rAddr dmsg.Addr, err error) {
return handshakeMiddleware(func(conn net.Conn, _ time.Time) (lAddr, rAddr dmsg.Addr, err error) {
if err = readFrame0(conn); err != nil {
return dmsg.Addr{}, dmsg.Addr{}, err
Expand Down
Loading

0 comments on commit 59a24a4

Please sign in to comment.