Skip to content

Commit 367c329

Browse files
gballetkaralabe
authored andcommitted
whisper: remove linter warnings (#15972)
* whisper: fixes warnings from the code linter * whisper: more non-API-breaking changes The remaining lint errors are because of auto-generated files and one is because an exported function has a non- exported return type. Changing this would break the API, and will be part of another commit for easier reversal. * whisper: un-export NewSentMessage to please the linter This is an API change, which is why it's in its own commit. This change was initiated after the linter complained that the returned type wasn't exported. I chose to un-export the function instead of exporting the type, because that type is an implementation detail that I would like to change in the near future to make the code more readable and with an increased coverage. * whisper: update gencodec output after upgrading it to new lint standards
1 parent 2ef3815 commit 367c329

19 files changed

Lines changed: 363 additions & 328 deletions

‎cmd/wnode/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ func requestExpiredMessagesLoop() {
601601
if err != nil {
602602
utils.Fatalf("Failed to save symmetric key for mail request: %s", err)
603603
}
604-
peerID = extractIdFromEnode(*argEnode)
604+
peerID = extractIDFromEnode(*argEnode)
605605
shh.AllowP2PMessagesFromPeer(peerID)
606606

607607
for {
@@ -652,7 +652,7 @@ func requestExpiredMessagesLoop() {
652652
}
653653
}
654654

655-
func extractIdFromEnode(s string) []byte {
655+
func extractIDFromEnode(s string) []byte {
656656
n, err := discover.ParseNode(s)
657657
if err != nil {
658658
utils.Fatalf("Failed to parse enode: %s", err)

‎whisper/whisperv6/api.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
filterTimeout = 300 // filters are considered timeout out after filterTimeout seconds
3737
)
3838

39+
// List of errors
3940
var (
4041
ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key")
4142
ErrInvalidSymmetricKey = errors.New("invalid symmetric key")
@@ -116,7 +117,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32)
116117
return true, api.w.SetMaxMessageSize(size)
117118
}
118119

119-
// SetMinPow sets the minimum PoW, and notifies the peers.
120+
// SetMinPoW sets the minimum PoW, and notifies the peers.
120121
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
121122
return true, api.w.SetMinimumPoW(pow)
122123
}
@@ -174,7 +175,7 @@ func (api *PublicWhisperAPI) GetPublicKey(ctx context.Context, id string) (hexut
174175
return crypto.FromECDSAPub(&key.PublicKey), nil
175176
}
176177

177-
// GetPublicKey returns the private key associated with the given key. The key is the hex
178+
// GetPrivateKey returns the private key associated with the given key. The key is the hex
178179
// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
179180
func (api *PublicWhisperAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error) {
180181
key, err := api.w.GetPrivateKey(id)
@@ -291,7 +292,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
291292
}
292293

293294
// encrypt and sent message
294-
whisperMsg, err := NewSentMessage(params)
295+
whisperMsg, err := newSentMessage(params)
295296
if err != nil {
296297
return false, err
297298
}

‎whisper/whisperv6/benchmarks_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func BenchmarkEncryptionSym(b *testing.B) {
3939
}
4040

4141
for i := 0; i < b.N; i++ {
42-
msg, _ := NewSentMessage(params)
42+
msg, _ := newSentMessage(params)
4343
_, err := msg.Wrap(params)
4444
if err != nil {
4545
b.Errorf("failed Wrap with seed %d: %s.", seed, err)
@@ -64,7 +64,7 @@ func BenchmarkEncryptionAsym(b *testing.B) {
6464
params.Dst = &key.PublicKey
6565

6666
for i := 0; i < b.N; i++ {
67-
msg, _ := NewSentMessage(params)
67+
msg, _ := newSentMessage(params)
6868
_, err := msg.Wrap(params)
6969
if err != nil {
7070
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
@@ -79,7 +79,7 @@ func BenchmarkDecryptionSymValid(b *testing.B) {
7979
if err != nil {
8080
b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
8181
}
82-
msg, _ := NewSentMessage(params)
82+
msg, _ := newSentMessage(params)
8383
env, err := msg.Wrap(params)
8484
if err != nil {
8585
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
@@ -101,7 +101,7 @@ func BenchmarkDecryptionSymInvalid(b *testing.B) {
101101
if err != nil {
102102
b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
103103
}
104-
msg, _ := NewSentMessage(params)
104+
msg, _ := newSentMessage(params)
105105
env, err := msg.Wrap(params)
106106
if err != nil {
107107
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
@@ -130,7 +130,7 @@ func BenchmarkDecryptionAsymValid(b *testing.B) {
130130
f := Filter{KeyAsym: key}
131131
params.KeySym = nil
132132
params.Dst = &key.PublicKey
133-
msg, _ := NewSentMessage(params)
133+
msg, _ := newSentMessage(params)
134134
env, err := msg.Wrap(params)
135135
if err != nil {
136136
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
@@ -157,7 +157,7 @@ func BenchmarkDecryptionAsymInvalid(b *testing.B) {
157157
}
158158
params.KeySym = nil
159159
params.Dst = &key.PublicKey
160-
msg, _ := NewSentMessage(params)
160+
msg, _ := newSentMessage(params)
161161
env, err := msg.Wrap(params)
162162
if err != nil {
163163
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
@@ -199,7 +199,7 @@ func BenchmarkPoW(b *testing.B) {
199199

200200
for i := 0; i < b.N; i++ {
201201
increment(params.Payload)
202-
msg, _ := NewSentMessage(params)
202+
msg, _ := newSentMessage(params)
203203
_, err := msg.Wrap(params)
204204
if err != nil {
205205
b.Fatalf("failed Wrap with seed %d: %s.", seed, err)

‎whisper/whisperv6/config.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package whisperv6
1818

19+
// Config represents the configuration state of a whisper node.
1920
type Config struct {
2021
MaxMessageSize uint32 `toml:",omitempty"`
2122
MinimumAcceptedPOW float64 `toml:",omitempty"`
2223
}
2324

25+
// DefaultConfig represents (shocker!) the default configuration.
2426
var DefaultConfig = Config{
2527
MaxMessageSize: DefaultMaxMessageSize,
2628
MinimumAcceptedPOW: DefaultMinimumPoW,

‎whisper/whisperv6/doc.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@ Whisper is a pure identity-based messaging system. Whisper provides a low-level
2727
or prejudiced by the low-level hardware attributes and characteristics,
2828
particularly the notion of singular endpoints.
2929
*/
30+
31+
// Contains the Whisper protocol constant definitions
32+
3033
package whisperv6
3134

3235
import (
3336
"fmt"
3437
"time"
3538
)
3639

40+
// Whisper protocol parameters
3741
const (
38-
ProtocolVersion = uint64(6)
39-
ProtocolVersionStr = "6.0"
40-
ProtocolName = "shh"
42+
ProtocolVersion = uint64(6) // Protocol version number
43+
ProtocolVersionStr = "6.0" // The same, as a string
44+
ProtocolName = "shh" // Nickname of the protocol in geth
4145

4246
// whisper protocol message codes, according to EIP-627
4347
statusCode = 0 // used by whisper protocol
@@ -55,7 +59,7 @@ const (
5559
signatureLength = 65 // in bytes
5660
aesKeyLength = 32 // in bytes
5761
AESNonceLength = 12 // in bytes
58-
keyIdSize = 32 // in bytes
62+
keyIDSize = 32 // in bytes
5963
bloomFilterSize = 64 // in bytes
6064

6165
EnvelopeHeaderLength = 20

‎whisper/whisperv6/envelope.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func (e *Envelope) Seal(options *MessageParams) error {
115115
return nil
116116
}
117117

118+
// PoW computes (if necessary) and returns the proof of work target
119+
// of the envelope.
118120
func (e *Envelope) PoW() float64 {
119121
if e.pow == 0 {
120122
e.calculatePoW(0)

‎whisper/whisperv6/envelope_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestEnvelopeOpenAcceptsOnlyOneKeyTypeInFilter(t *testing.T) {
4545

4646
mrand.Read(params.Payload)
4747

48-
msg, err := NewSentMessage(&params)
48+
msg, err := newSentMessage(&params)
4949
if err != nil {
5050
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
5151
}

‎whisper/whisperv6/filter.go‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ethereum/go-ethereum/log"
2727
)
2828

29+
// Filter represents a Whisper message filter
2930
type Filter struct {
3031
Src *ecdsa.PublicKey // Sender of the message
3132
KeyAsym *ecdsa.PrivateKey // Private Key of recipient
@@ -39,19 +40,22 @@ type Filter struct {
3940
mutex sync.RWMutex
4041
}
4142

43+
// Filters represents a collection of filters
4244
type Filters struct {
4345
watchers map[string]*Filter
4446
whisper *Whisper
4547
mutex sync.RWMutex
4648
}
4749

50+
// NewFilters returns a newly created filter collection
4851
func NewFilters(w *Whisper) *Filters {
4952
return &Filters{
5053
watchers: make(map[string]*Filter),
5154
whisper: w,
5255
}
5356
}
5457

58+
// Install will add a new filter to the filter collection
5559
func (fs *Filters) Install(watcher *Filter) (string, error) {
5660
if watcher.KeySym != nil && watcher.KeyAsym != nil {
5761
return "", fmt.Errorf("filters must choose between symmetric and asymmetric keys")
@@ -81,6 +85,8 @@ func (fs *Filters) Install(watcher *Filter) (string, error) {
8185
return id, err
8286
}
8387

88+
// Uninstall will remove a filter whose id has been specified from
89+
// the filter collection
8490
func (fs *Filters) Uninstall(id string) bool {
8591
fs.mutex.Lock()
8692
defer fs.mutex.Unlock()
@@ -91,12 +97,15 @@ func (fs *Filters) Uninstall(id string) bool {
9197
return false
9298
}
9399

100+
// Get returns a filter from the collection with a specific ID
94101
func (fs *Filters) Get(id string) *Filter {
95102
fs.mutex.RLock()
96103
defer fs.mutex.RUnlock()
97104
return fs.watchers[id]
98105
}
99106

107+
// NotifyWatchers notifies any filter that has declared interest
108+
// for the envelope's topic.
100109
func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
101110
var msg *ReceivedMessage
102111

@@ -140,9 +149,9 @@ func (f *Filter) processEnvelope(env *Envelope) *ReceivedMessage {
140149
msg := env.Open(f)
141150
if msg != nil {
142151
return msg
143-
} else {
144-
log.Trace("processing envelope: failed to open", "hash", env.Hash().Hex())
145152
}
153+
154+
log.Trace("processing envelope: failed to open", "hash", env.Hash().Hex())
146155
} else {
147156
log.Trace("processing envelope: does not match", "hash", env.Hash().Hex())
148157
}
@@ -157,6 +166,8 @@ func (f *Filter) expectsSymmetricEncryption() bool {
157166
return f.KeySym != nil
158167
}
159168

169+
// Trigger adds a yet-unknown message to the filter's list of
170+
// received messages.
160171
func (f *Filter) Trigger(msg *ReceivedMessage) {
161172
f.mutex.Lock()
162173
defer f.mutex.Unlock()
@@ -166,6 +177,8 @@ func (f *Filter) Trigger(msg *ReceivedMessage) {
166177
}
167178
}
168179

180+
// Retrieve will return the list of all received messages associated
181+
// to a filter.
169182
func (f *Filter) Retrieve() (all []*ReceivedMessage) {
170183
f.mutex.Lock()
171184
defer f.mutex.Unlock()
@@ -195,7 +208,7 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool {
195208
return false
196209
}
197210

198-
// MatchEvelope checks if it's worth decrypting the message. If
211+
// MatchEnvelope checks if it's worth decrypting the message. If
199212
// it returns `true`, client code is expected to attempt decrypting
200213
// the message and subsequently call MatchMessage.
201214
func (f *Filter) MatchEnvelope(envelope *Envelope) bool {
@@ -206,6 +219,7 @@ func (f *Filter) MatchEnvelope(envelope *Envelope) bool {
206219
return f.MatchTopic(envelope.Topic)
207220
}
208221

222+
// MatchTopic checks that the filter captures a given topic.
209223
func (f *Filter) MatchTopic(topic TopicType) bool {
210224
if len(f.Topics) == 0 {
211225
// any topic matches
@@ -237,6 +251,7 @@ func matchSingleTopic(topic TopicType, bt []byte) bool {
237251
return true
238252
}
239253

254+
// IsPubKeyEqual checks that two public keys are equal
240255
func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool {
241256
if !ValidatePublicKey(a) {
242257
return false

‎whisper/whisperv6/filter_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestInstallFilters(t *testing.T) {
109109
t.Fatalf("seed %d: failed to install filter: %s", seed, err)
110110
}
111111
tst[i].id = j
112-
if len(j) != keyIdSize*2 {
112+
if len(j) != keyIDSize*2 {
113113
t.Fatalf("seed %d: wrong filter id size [%d]", seed, len(j))
114114
}
115115
}
@@ -199,7 +199,7 @@ func TestInstallIdenticalFilters(t *testing.T) {
199199
filter1.Src = &params.Src.PublicKey
200200
filter2.Src = &params.Src.PublicKey
201201

202-
sentMessage, err := NewSentMessage(params)
202+
sentMessage, err := newSentMessage(params)
203203
if err != nil {
204204
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
205205
}
@@ -306,7 +306,7 @@ func TestMatchEnvelope(t *testing.T) {
306306
params.Topic[0] = 0xFF // ensure mismatch
307307

308308
// mismatch with pseudo-random data
309-
msg, err := NewSentMessage(params)
309+
msg, err := newSentMessage(params)
310310
if err != nil {
311311
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
312312
}
@@ -327,7 +327,7 @@ func TestMatchEnvelope(t *testing.T) {
327327
i := mrand.Int() % 4
328328
fsym.Topics[i] = params.Topic[:]
329329
fasym.Topics[i] = params.Topic[:]
330-
msg, err = NewSentMessage(params)
330+
msg, err = newSentMessage(params)
331331
if err != nil {
332332
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
333333
}
@@ -372,7 +372,7 @@ func TestMatchEnvelope(t *testing.T) {
372372
}
373373
params.KeySym = nil
374374
params.Dst = &key.PublicKey
375-
msg, err = NewSentMessage(params)
375+
msg, err = newSentMessage(params)
376376
if err != nil {
377377
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
378378
}
@@ -453,7 +453,7 @@ func TestMatchMessageSym(t *testing.T) {
453453
params.KeySym = f.KeySym
454454
params.Topic = BytesToTopic(f.Topics[index])
455455

456-
sentMessage, err := NewSentMessage(params)
456+
sentMessage, err := newSentMessage(params)
457457
if err != nil {
458458
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
459459
}
@@ -546,7 +546,7 @@ func TestMatchMessageAsym(t *testing.T) {
546546
keySymOrig := params.KeySym
547547
params.KeySym = nil
548548

549-
sentMessage, err := NewSentMessage(params)
549+
sentMessage, err := newSentMessage(params)
550550
if err != nil {
551551
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
552552
}
@@ -630,7 +630,7 @@ func generateCompatibeEnvelope(t *testing.T, f *Filter) *Envelope {
630630

631631
params.KeySym = f.KeySym
632632
params.Topic = BytesToTopic(f.Topics[2])
633-
sentMessage, err := NewSentMessage(params)
633+
sentMessage, err := newSentMessage(params)
634634
if err != nil {
635635
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
636636
}
@@ -806,7 +806,7 @@ func TestVariableTopics(t *testing.T) {
806806
if err != nil {
807807
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
808808
}
809-
msg, err := NewSentMessage(params)
809+
msg, err := newSentMessage(params)
810810
if err != nil {
811811
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
812812
}

‎whisper/whisperv6/gen_criteria_json.go‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)