Skip to content

Commit

Permalink
p2p: fix some golint warnings (#16577)
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbarry authored and fjl committed May 8, 2018
1 parent a42be3b commit 864e80a
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 291 deletions.
20 changes: 10 additions & 10 deletions p2p/discover/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,26 +582,26 @@ func (*preminedTestnet) ping(toid NodeID, toaddr *net.UDPAddr) error { return ni

// mine generates a testnet struct literal with nodes at
// various distances to the given target.
func (n *preminedTestnet) mine(target NodeID) {
n.target = target
n.targetSha = crypto.Keccak256Hash(n.target[:])
func (tn *preminedTestnet) mine(target NodeID) {
tn.target = target
tn.targetSha = crypto.Keccak256Hash(tn.target[:])
found := 0
for found < bucketSize*10 {
k := newkey()
id := PubkeyID(&k.PublicKey)
sha := crypto.Keccak256Hash(id[:])
ld := logdist(n.targetSha, sha)
if len(n.dists[ld]) < bucketSize {
n.dists[ld] = append(n.dists[ld], id)
ld := logdist(tn.targetSha, sha)
if len(tn.dists[ld]) < bucketSize {
tn.dists[ld] = append(tn.dists[ld], id)
fmt.Println("found ID with ld", ld)
found++
}
}
fmt.Println("&preminedTestnet{")
fmt.Printf(" target: %#v,\n", n.target)
fmt.Printf(" targetSha: %#v,\n", n.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(n.dists))
for ld, ns := range n.dists {
fmt.Printf(" target: %#v,\n", tn.target)
fmt.Printf(" targetSha: %#v,\n", tn.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(tn.dists))
for ld, ns := range tn.dists {
if len(ns) == 0 {
continue
}
Expand Down
20 changes: 10 additions & 10 deletions p2p/discv5/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,26 @@ func (*preminedTestnet) localAddr() *net.UDPAddr {

// mine generates a testnet struct literal with nodes at
// various distances to the given target.
func (n *preminedTestnet) mine(target NodeID) {
n.target = target
n.targetSha = crypto.Keccak256Hash(n.target[:])
func (tn *preminedTestnet) mine(target NodeID) {
tn.target = target
tn.targetSha = crypto.Keccak256Hash(tn.target[:])
found := 0
for found < bucketSize*10 {
k := newkey()
id := PubkeyID(&k.PublicKey)
sha := crypto.Keccak256Hash(id[:])
ld := logdist(n.targetSha, sha)
if len(n.dists[ld]) < bucketSize {
n.dists[ld] = append(n.dists[ld], id)
ld := logdist(tn.targetSha, sha)
if len(tn.dists[ld]) < bucketSize {
tn.dists[ld] = append(tn.dists[ld], id)
fmt.Println("found ID with ld", ld)
found++
}
}
fmt.Println("&preminedTestnet{")
fmt.Printf(" target: %#v,\n", n.target)
fmt.Printf(" targetSha: %#v,\n", n.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(n.dists))
for ld, ns := range n.dists {
fmt.Printf(" target: %#v,\n", tn.target)
fmt.Printf(" targetSha: %#v,\n", tn.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(tn.dists))
for ld, ns := range tn.dists {
if len(ns) == 0 {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/discv5/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ func PubkeyID(pub *ecdsa.PublicKey) NodeID {

// Pubkey returns the public key represented by the node ID.
// It returns an error if the ID is not a point on the curve.
func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) {
func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
p := &ecdsa.PublicKey{Curve: crypto.S256(), X: new(big.Int), Y: new(big.Int)}
half := len(id) / 2
p.X.SetBytes(id[:half])
p.Y.SetBytes(id[half:])
half := len(n) / 2
p.X.SetBytes(n[:half])
p.Y.SetBytes(n[half:])
if !p.Curve.IsOnCurve(p.X, p.Y) {
return nil, errors.New("id is invalid secp256k1 curve point")
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/discv5/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ func (s ticketRefByWaitTime) Len() int {
return len(s)
}

func (r ticketRef) waitTime() mclock.AbsTime {
return r.t.regTime[r.idx] - r.t.issueTime
func (ref ticketRef) waitTime() mclock.AbsTime {
return ref.t.regTime[ref.idx] - ref.t.issueTime
}

// Less reports whether the element with
Expand Down
16 changes: 8 additions & 8 deletions p2p/discv5/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,31 @@ func (t *topicTable) useTicket(node *Node, serialNo uint32, topics []Topic, idx
return false
}

func (topictab *topicTable) getTicket(node *Node, topics []Topic) *ticket {
topictab.collectGarbage()
func (t *topicTable) getTicket(node *Node, topics []Topic) *ticket {
t.collectGarbage()

now := mclock.Now()
n := topictab.getOrNewNode(node)
n := t.getOrNewNode(node)
n.lastIssuedTicket++
topictab.storeTicketCounters(node)
t.storeTicketCounters(node)

t := &ticket{
tic := &ticket{
issueTime: now,
topics: topics,
serial: n.lastIssuedTicket,
regTime: make([]mclock.AbsTime, len(topics)),
}
for i, topic := range topics {
var waitPeriod time.Duration
if topic := topictab.topics[topic]; topic != nil {
if topic := t.topics[topic]; topic != nil {
waitPeriod = topic.wcl.waitPeriod
} else {
waitPeriod = minWaitPeriod
}

t.regTime[i] = now + mclock.AbsTime(waitPeriod)
tic.regTime[i] = now + mclock.AbsTime(waitPeriod)
}
return t
return tic
}

const gcInterval = time.Minute
Expand Down
24 changes: 12 additions & 12 deletions p2p/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ func newMsgEventer(rw MsgReadWriter, feed *event.Feed, peerID discover.NodeID, p

// ReadMsg reads a message from the underlying MsgReadWriter and emits a
// "message received" event
func (self *msgEventer) ReadMsg() (Msg, error) {
msg, err := self.MsgReadWriter.ReadMsg()
func (ev *msgEventer) ReadMsg() (Msg, error) {
msg, err := ev.MsgReadWriter.ReadMsg()
if err != nil {
return msg, err
}
self.feed.Send(&PeerEvent{
ev.feed.Send(&PeerEvent{
Type: PeerEventTypeMsgRecv,
Peer: self.peerID,
Protocol: self.Protocol,
Peer: ev.peerID,
Protocol: ev.Protocol,
MsgCode: &msg.Code,
MsgSize: &msg.Size,
})
Expand All @@ -287,15 +287,15 @@ func (self *msgEventer) ReadMsg() (Msg, error) {

// WriteMsg writes a message to the underlying MsgReadWriter and emits a
// "message sent" event
func (self *msgEventer) WriteMsg(msg Msg) error {
err := self.MsgReadWriter.WriteMsg(msg)
func (ev *msgEventer) WriteMsg(msg Msg) error {
err := ev.MsgReadWriter.WriteMsg(msg)
if err != nil {
return err
}
self.feed.Send(&PeerEvent{
ev.feed.Send(&PeerEvent{
Type: PeerEventTypeMsgSend,
Peer: self.peerID,
Protocol: self.Protocol,
Peer: ev.peerID,
Protocol: ev.Protocol,
MsgCode: &msg.Code,
MsgSize: &msg.Size,
})
Expand All @@ -304,8 +304,8 @@ func (self *msgEventer) WriteMsg(msg Msg) error {

// Close closes the underlying MsgReadWriter if it implements the io.Closer
// interface
func (self *msgEventer) Close() error {
if v, ok := self.MsgReadWriter.(io.Closer); ok {
func (ev *msgEventer) Close() error {
if v, ok := ev.MsgReadWriter.(io.Closer); ok {
return v.Close()
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions p2p/peer_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func newPeerError(code int, format string, v ...interface{}) *peerError {
return err
}

func (self *peerError) Error() string {
return self.message
func (pe *peerError) Error() string {
return pe.message
}

var errProtocolReturned = errors.New("protocol returned")
Expand Down
Loading

0 comments on commit 864e80a

Please sign in to comment.