Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit ea8b369

Browse files
fix staticcheck errors (#191)
* run go mod tidy * omit receiver name if unused * remove unused type testkey in tests * fix duplicate import of go-multiaddr * fix use of deprecated peer.IDB58{Encode,Decode} * use bytes.Equal instead of bytes.Compare * fix unnecessary assigments to blank identifier * use time.Until instead of t.Sub(time.Now()) * fix use of deprecated go-multihash.ID * add missing error check in envelope test * fix error check in tests
1 parent cfab100 commit ea8b369

File tree

12 files changed

+24
-62
lines changed

12 files changed

+24
-62
lines changed

connmgr/null.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ type NullConnMgr struct{}
1212

1313
var _ ConnManager = (*NullConnMgr)(nil)
1414

15-
func (_ NullConnMgr) TagPeer(peer.ID, string, int) {}
16-
func (_ NullConnMgr) UntagPeer(peer.ID, string) {}
17-
func (_ NullConnMgr) UpsertTag(peer.ID, string, func(int) int) {}
18-
func (_ NullConnMgr) GetTagInfo(peer.ID) *TagInfo { return &TagInfo{} }
19-
func (_ NullConnMgr) TrimOpenConns(ctx context.Context) {}
20-
func (_ NullConnMgr) Notifee() network.Notifiee { return network.GlobalNoopNotifiee }
21-
func (_ NullConnMgr) Protect(peer.ID, string) {}
22-
func (_ NullConnMgr) Unprotect(peer.ID, string) bool { return false }
23-
func (_ NullConnMgr) IsProtected(peer.ID, string) bool { return false }
24-
func (_ NullConnMgr) Close() error { return nil }
15+
func (NullConnMgr) TagPeer(peer.ID, string, int) {}
16+
func (NullConnMgr) UntagPeer(peer.ID, string) {}
17+
func (NullConnMgr) UpsertTag(peer.ID, string, func(int) int) {}
18+
func (NullConnMgr) GetTagInfo(peer.ID) *TagInfo { return &TagInfo{} }
19+
func (NullConnMgr) TrimOpenConns(ctx context.Context) {}
20+
func (NullConnMgr) Notifee() network.Notifiee { return network.GlobalNoopNotifiee }
21+
func (NullConnMgr) Protect(peer.ID, string) {}
22+
func (NullConnMgr) Unprotect(peer.ID, string) bool { return false }
23+
func (NullConnMgr) IsProtected(peer.ID, string) bool { return false }
24+
func (NullConnMgr) Close() error { return nil }

connmgr/presets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func DecayLinear(coef float64) DecayFn {
3333
// DecayExpireWhenInactive expires a tag after a certain period of no bumps.
3434
func DecayExpireWhenInactive(after time.Duration) DecayFn {
3535
return func(value DecayingValue) (_ int, rm bool) {
36-
rm = value.LastVisit.Sub(time.Now()) >= after
36+
rm = time.Until(value.LastVisit) >= after
3737
return 0, rm
3838
}
3939
}

crypto/key_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -293,37 +293,6 @@ func testKeyEquals(t *testing.T, k Key) {
293293
}
294294
}
295295

296-
type testkey []byte
297-
298-
func (pk testkey) Bytes() ([]byte, error) {
299-
return pk, nil
300-
}
301-
302-
func (pk testkey) Type() pb.KeyType {
303-
return pb.KeyType_RSA
304-
}
305-
306-
func (pk testkey) Raw() ([]byte, error) {
307-
return pk, nil
308-
}
309-
310-
func (pk testkey) Equals(k Key) bool {
311-
if pk.Type() != k.Type() {
312-
return false
313-
}
314-
a, err := pk.Raw()
315-
if err != nil {
316-
return false
317-
}
318-
319-
b, err := k.Raw()
320-
if err != nil {
321-
return false
322-
}
323-
324-
return bytes.Equal(a, b)
325-
}
326-
327296
func TestUnknownCurveErrors(t *testing.T) {
328297
_, _, err := GenerateEKeyPair("P-256")
329298
if err != nil {

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1
5252
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
5353
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
5454
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
55-
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
5655
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
5756
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
5857
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
@@ -64,25 +63,21 @@ github.com/multiformats/go-multiaddr v0.2.2 h1:XZLDTszBIJe6m0zF6ITBrEcZR73OPUhCB
6463
github.com/multiformats/go-multiaddr v0.2.2/go.mod h1:NtfXiOtHvghW9KojvtySjH5y0u0xW5UouOmQQrn6a3Y=
6564
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
6665
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
67-
github.com/multiformats/go-multihash v0.0.13 h1:06x+mk/zj1FoMsgNejLpy6QTvJqlSt/BhLEy87zidlc=
6866
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
6967
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
7068
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
71-
github.com/multiformats/go-varint v0.0.5 h1:XVZwSo04Cs3j/jS0uAEPpT3JY6DzMcVLLoWOSnCxOjg=
7269
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
7370
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
7471
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
7572
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
7673
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
7774
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
78-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7975
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8076
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU=
8177
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc=
8278
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
8379
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
8480
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
85-
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
8681
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
8782
go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto=
8883
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -118,7 +113,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
118113
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
119114
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
120115
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
121-
golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ=
122116
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
123117
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
124118
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

peer/addrinfo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package peer
33
import (
44
"fmt"
55

6-
"github.com/multiformats/go-multiaddr"
76
ma "github.com/multiformats/go-multiaddr"
87
)
98

@@ -64,7 +63,7 @@ func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
6463

6564
// AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr
6665
func AddrInfoFromString(s string) (*AddrInfo, error) {
67-
a, err := multiaddr.NewMultiaddr(s)
66+
a, err := ma.NewMultiaddr(s)
6867
if err != nil {
6968
return nil, err
7069
}

peer/addrinfo_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) {
8787
if len(infos) != 0 {
8888
t.Fatal("expected no addrs")
8989
}
90-
infos, err = AddrInfosFromP2pAddrs(nil)
91-
if err == nil {
90+
if _, err = AddrInfosFromP2pAddrs(nil); err == nil {
9291
t.Fatal("expected nil multiaddr to fail")
9392
}
9493

peer/peer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func IDFromPublicKey(pk ic.PubKey) (ID, error) {
226226
}
227227
var alg uint64 = mh.SHA2_256
228228
if AdvancedEnableInlining && len(b) <= maxInlineKeyLength {
229-
alg = mh.ID
229+
alg = mh.IDENTITY
230230
}
231231
hash, _ := mh.Sum(b, alg, -1)
232232
return ID(hash), nil

peer/record.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (r *PeerRecord) Equal(other *PeerRecord) bool {
190190
if len(r.Addrs) != len(other.Addrs) {
191191
return false
192192
}
193-
for i, _ := range r.Addrs {
193+
for i := range r.Addrs {
194194
if !r.Addrs[i].Equal(other.Addrs[i]) {
195195
return false
196196
}

peer/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (ps *Set) TryAdd(p ID) bool {
6363
func (ps *Set) Peers() []ID {
6464
ps.lk.Lock()
6565
out := make([]ID, 0, len(ps.ps))
66-
for p, _ := range ps.ps {
66+
for p := range ps.ps {
6767
out = append(out, p)
6868
}
6969
ps.lk.Unlock()

record/envelope.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func (e *Envelope) Equal(other *Envelope) bool {
215215
return e == nil
216216
}
217217
return e.PublicKey.Equals(other.PublicKey) &&
218-
bytes.Compare(e.PayloadType, other.PayloadType) == 0 &&
219-
bytes.Compare(e.signature, other.signature) == 0 &&
220-
bytes.Compare(e.RawPayload, other.RawPayload) == 0
218+
bytes.Equal(e.PayloadType, other.PayloadType) &&
219+
bytes.Equal(e.signature, other.signature) &&
220+
bytes.Equal(e.RawPayload, other.RawPayload)
221221
}
222222

223223
// Record returns the Envelope's payload unmarshalled as a Record.

record/envelope_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestEnvelopeHappyPath(t *testing.T) {
6161
t.Error("envelope has unexpected public key")
6262
}
6363

64-
if bytes.Compare(rec.Codec(), envelope.PayloadType) != 0 {
64+
if !bytes.Equal(rec.Codec(), envelope.PayloadType) {
6565
t.Error("PayloadType does not match record Codec")
6666
}
6767

@@ -72,7 +72,7 @@ func TestEnvelopeHappyPath(t *testing.T) {
7272
deserialized, rec2, err := ConsumeEnvelope(serialized, rec.Domain())
7373
test.AssertNilError(t, err)
7474

75-
if bytes.Compare(deserialized.RawPayload, payload) != 0 {
75+
if !bytes.Equal(deserialized.RawPayload, payload) {
7676
t.Error("payload of envelope does not match input")
7777
}
7878

@@ -242,6 +242,7 @@ func TestEnvelopeValidateFailsForDifferentDomain(t *testing.T) {
242242
test.AssertNilError(t, err)
243243

244244
serialized, err := envelope.Marshal()
245+
test.AssertNilError(t, err)
245246

246247
// try to open our modified envelope
247248
_, _, err = ConsumeEnvelope(serialized, "wrong-domain")

routing/query_serde.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func (qe *QueryEvent) MarshalJSON() ([]byte, error) {
1010
return json.Marshal(map[string]interface{}{
11-
"ID": peer.IDB58Encode(qe.ID),
11+
"ID": peer.Encode(qe.ID),
1212
"Type": int(qe.Type),
1313
"Responses": qe.Responses,
1414
"Extra": qe.Extra,
@@ -27,7 +27,7 @@ func (qe *QueryEvent) UnmarshalJSON(b []byte) error {
2727
return err
2828
}
2929
if len(temp.ID) > 0 {
30-
pid, err := peer.IDB58Decode(temp.ID)
30+
pid, err := peer.Decode(temp.ID)
3131
if err != nil {
3232
return err
3333
}

0 commit comments

Comments
 (0)