Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit d636d86

Browse files
roveneliahgbalint
authored andcommitted
whisper: Golint fixes in whisper packages (#16637)
1 parent a9d8b74 commit d636d86

File tree

8 files changed

+74
-78
lines changed

8 files changed

+74
-78
lines changed

whisper/shhclient/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (sc *Client) SetMaxMessageSize(ctx context.Context, size uint32) error {
6767
}
6868

6969
// SetMinimumPoW (experimental) sets the minimal PoW required by this node.
70-
7170
// This experimental function was introduced for the future dynamic adjustment of
7271
// PoW requirement. If the node is overwhelmed with messages, it should raise the
7372
// PoW requirement and notify the peers. The new value should be set relative to
@@ -77,7 +76,7 @@ func (sc *Client) SetMinimumPoW(ctx context.Context, pow float64) error {
7776
return sc.c.CallContext(ctx, &ignored, "shh_setMinPoW", pow)
7877
}
7978

80-
// Marks specific peer trusted, which will allow it to send historic (expired) messages.
79+
// MarkTrustedPeer marks specific peer trusted, which will allow it to send historic (expired) messages.
8180
// Note This function is not adding new nodes, the node needs to exists as a peer.
8281
func (sc *Client) MarkTrustedPeer(ctx context.Context, enode string) error {
8382
var ignored bool

whisper/whisperv5/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32)
8989
return true, api.w.SetMaxMessageSize(size)
9090
}
9191

92-
// SetMinPow sets the minimum PoW for a message before it is accepted.
92+
// SetMinPoW sets the minimum PoW for a message before it is accepted.
9393
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
9494
return true, api.w.SetMinimumPoW(pow)
9595
}
@@ -142,7 +142,7 @@ func (api *PublicWhisperAPI) GetPublicKey(ctx context.Context, id string) (hexut
142142
return crypto.FromECDSAPub(&key.PublicKey), nil
143143
}
144144

145-
// GetPublicKey returns the private key associated with the given key. The key is the hex
145+
// GetPrivateKey returns the private key associated with the given key. The key is the hex
146146
// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
147147
func (api *PublicWhisperAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error) {
148148
key, err := api.w.GetPrivateKey(id)

whisper/whisperv5/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

1717
/*
18-
Package whisper implements the Whisper protocol (version 5).
18+
Package whisperv5 implements the Whisper protocol (version 5).
1919
2020
Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
2121
As such it may be likened and compared to both, not dissimilar to the

whisper/whisperv5/message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/ethereum/go-ethereum/log"
3434
)
3535

36-
// Options specifies the exact way a message should be wrapped into an Envelope.
36+
// MessageParams specifies the exact way a message should be wrapped into an Envelope.
3737
type MessageParams struct {
3838
TTL uint32
3939
Src *ecdsa.PrivateKey
@@ -86,7 +86,7 @@ func (msg *ReceivedMessage) isAsymmetricEncryption() bool {
8686
return msg.Dst != nil
8787
}
8888

89-
// NewMessage creates and initializes a non-signed, non-encrypted Whisper message.
89+
// NewSentMessage creates and initializes a non-signed, non-encrypted Whisper message.
9090
func NewSentMessage(params *MessageParams) (*sentMessage, error) {
9191
msg := sentMessage{}
9292
msg.Raw = make([]byte, 1, len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
@@ -330,7 +330,7 @@ func (msg *ReceivedMessage) extractPadding(end int) (int, bool) {
330330
return paddingSize, true
331331
}
332332

333-
// Recover retrieves the public key of the message signer.
333+
// SigToPubKey retrieves the public key of the message signer.
334334
func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey {
335335
defer func() { recover() }() // in case of invalid signature
336336

whisper/whisperv5/peer.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
set "gopkg.in/fatih/set.v0"
2828
)
2929

30-
// peer represents a whisper protocol peer connection.
30+
// Peer represents a whisper protocol peer connection.
3131
type Peer struct {
3232
host *Whisper
3333
peer *p2p.Peer
@@ -53,51 +53,51 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
5353

5454
// start initiates the peer updater, periodically broadcasting the whisper packets
5555
// into the network.
56-
func (p *Peer) start() {
57-
go p.update()
58-
log.Trace("start", "peer", p.ID())
56+
func (peer *Peer) start() {
57+
go peer.update()
58+
log.Trace("start", "peer", peer.ID())
5959
}
6060

6161
// stop terminates the peer updater, stopping message forwarding to it.
62-
func (p *Peer) stop() {
63-
close(p.quit)
64-
log.Trace("stop", "peer", p.ID())
62+
func (peer *Peer) stop() {
63+
close(peer.quit)
64+
log.Trace("stop", "peer", peer.ID())
6565
}
6666

6767
// handshake sends the protocol initiation status message to the remote peer and
6868
// verifies the remote status too.
69-
func (p *Peer) handshake() error {
69+
func (peer *Peer) handshake() error {
7070
// Send the handshake status message asynchronously
7171
errc := make(chan error, 1)
7272
go func() {
73-
errc <- p2p.Send(p.ws, statusCode, ProtocolVersion)
73+
errc <- p2p.Send(peer.ws, statusCode, ProtocolVersion)
7474
}()
7575
// Fetch the remote status packet and verify protocol match
76-
packet, err := p.ws.ReadMsg()
76+
packet, err := peer.ws.ReadMsg()
7777
if err != nil {
7878
return err
7979
}
8080
if packet.Code != statusCode {
81-
return fmt.Errorf("peer [%x] sent packet %x before status packet", p.ID(), packet.Code)
81+
return fmt.Errorf("peer [%x] sent packet %x before status packet", peer.ID(), packet.Code)
8282
}
8383
s := rlp.NewStream(packet.Payload, uint64(packet.Size))
8484
peerVersion, err := s.Uint()
8585
if err != nil {
86-
return fmt.Errorf("peer [%x] sent bad status message: %v", p.ID(), err)
86+
return fmt.Errorf("peer [%x] sent bad status message: %v", peer.ID(), err)
8787
}
8888
if peerVersion != ProtocolVersion {
89-
return fmt.Errorf("peer [%x]: protocol version mismatch %d != %d", p.ID(), peerVersion, ProtocolVersion)
89+
return fmt.Errorf("peer [%x]: protocol version mismatch %d != %d", peer.ID(), peerVersion, ProtocolVersion)
9090
}
9191
// Wait until out own status is consumed too
9292
if err := <-errc; err != nil {
93-
return fmt.Errorf("peer [%x] failed to send status packet: %v", p.ID(), err)
93+
return fmt.Errorf("peer [%x] failed to send status packet: %v", peer.ID(), err)
9494
}
9595
return nil
9696
}
9797

9898
// update executes periodic operations on the peer, including message transmission
9999
// and expiration.
100-
func (p *Peer) update() {
100+
func (peer *Peer) update() {
101101
// Start the tickers for the updates
102102
expire := time.NewTicker(expirationCycle)
103103
transmit := time.NewTicker(transmissionCycle)
@@ -106,15 +106,15 @@ func (p *Peer) update() {
106106
for {
107107
select {
108108
case <-expire.C:
109-
p.expire()
109+
peer.expire()
110110

111111
case <-transmit.C:
112-
if err := p.broadcast(); err != nil {
113-
log.Trace("broadcast failed", "reason", err, "peer", p.ID())
112+
if err := peer.broadcast(); err != nil {
113+
log.Trace("broadcast failed", "reason", err, "peer", peer.ID())
114114
return
115115
}
116116

117-
case <-p.quit:
117+
case <-peer.quit:
118118
return
119119
}
120120
}
@@ -148,16 +148,16 @@ func (peer *Peer) expire() {
148148

149149
// broadcast iterates over the collection of envelopes and transmits yet unknown
150150
// ones over the network.
151-
func (p *Peer) broadcast() error {
151+
func (peer *Peer) broadcast() error {
152152
var cnt int
153-
envelopes := p.host.Envelopes()
153+
envelopes := peer.host.Envelopes()
154154
for _, envelope := range envelopes {
155-
if !p.marked(envelope) {
156-
err := p2p.Send(p.ws, messagesCode, envelope)
155+
if !peer.marked(envelope) {
156+
err := p2p.Send(peer.ws, messagesCode, envelope)
157157
if err != nil {
158158
return err
159159
} else {
160-
p.mark(envelope)
160+
peer.mark(envelope)
161161
cnt++
162162
}
163163
}
@@ -168,7 +168,7 @@ func (p *Peer) broadcast() error {
168168
return nil
169169
}
170170

171-
func (p *Peer) ID() []byte {
172-
id := p.peer.ID()
171+
func (peer *Peer) ID() []byte {
172+
id := peer.peer.ID()
173173
return id[:]
174174
}

whisper/whisperv5/peer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/p2p/nat"
3333
)
3434

35-
var keys []string = []string{
35+
var keys = []string{
3636
"d49dcf37238dc8a7aac57dc61b9fee68f0a97f062968978b9fafa7d1033d03a9",
3737
"73fd6143c48e80ed3c56ea159fe7494a0b6b393a392227b422f4c3e8f1b54f98",
3838
"119dd32adb1daa7a4c7bf77f847fb28730785aa92947edf42fdd997b54de40dc",
@@ -84,9 +84,9 @@ type TestNode struct {
8484

8585
var result TestData
8686
var nodes [NumNodes]*TestNode
87-
var sharedKey []byte = []byte("some arbitrary data here")
87+
var sharedKey = []byte("some arbitrary data here")
8888
var sharedTopic TopicType = TopicType{0xF, 0x1, 0x2, 0}
89-
var expectedMessage []byte = []byte("per rectum ad astra")
89+
var expectedMessage = []byte("per rectum ad astra")
9090

9191
// This test does the following:
9292
// 1. creates a chain of whisper nodes,

whisper/whisperv5/topic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/ethereum/go-ethereum/common/hexutil"
2424
)
2525

26-
// Topic represents a cryptographically secure, probabilistic partial
26+
// TopicType represents a cryptographically secure, probabilistic partial
2727
// classifications of a message, determined as the first (left) 4 bytes of the
2828
// SHA3 hash of some arbitrary data given by the original author of the message.
2929
type TopicType [TopicLength]byte

0 commit comments

Comments
 (0)