Skip to content

Commit

Permalink
p2p/*: golint updates for this or self warning, have updated pr
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbarry committed Apr 27, 2018
1 parent 86be91b commit 3660688
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 309 deletions.
24 changes: 12 additions & 12 deletions p2p/discover/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,15 @@ type preminedTestnet struct {
dists [hashBits + 1][]NodeID
}

func (tn *preminedTestnet) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node, error) {
func (net *preminedTestnet) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node, error) {
// current log distance is encoded in port number
// fmt.Println("findnode query at dist", toaddr.Port)
if toaddr.Port == 0 {
panic("query to node at distance 0")
}
next := uint16(toaddr.Port) - 1
var result []*Node
for i, id := range tn.dists[toaddr.Port] {
for i, id := range net.dists[toaddr.Port] {
result = append(result, NewNode(id, net.ParseIP("127.0.0.1"), next, uint16(i)))
}
return result, nil
Expand All @@ -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 (net *preminedTestnet) mine(target NodeID) {
net.target = target
net.targetSha = crypto.Keccak256Hash(net.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(net.targetSha, sha)
if len(net.dists[ld]) < bucketSize {
net.dists[ld] = append(net.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", net.target)
fmt.Printf(" targetSha: %#v,\n", net.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(net.dists))
for ld, ns := range net.dists {
if len(ns) == 0 {
continue
}
Expand Down
50 changes: 25 additions & 25 deletions p2p/discv5/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,33 +265,33 @@ type preminedTestnet struct {
net *Network
}

func (tn *preminedTestnet) sendFindnode(to *Node, target NodeID) {
func (net *preminedTestnet) sendFindnode(to *Node, target NodeID) {
panic("sendFindnode called")
}

func (tn *preminedTestnet) sendFindnodeHash(to *Node, target common.Hash) {
func (net *preminedTestnet) sendFindnodeHash(to *Node, target common.Hash) {
// current log distance is encoded in port number
// fmt.Println("findnode query at dist", toaddr.Port)
if to.UDP <= lowPort {
panic("query to node at or below distance 0")
}
next := to.UDP - 1
var result []rpcNode
for i, id := range tn.dists[to.UDP-lowPort] {
for i, id := range net.dists[to.UDP-lowPort] {
result = append(result, nodeToRPC(NewNode(id, net.ParseIP("10.0.2.99"), next, uint16(i)+1+lowPort)))
}
injectResponse(tn.net, to, neighborsPacket, &neighbors{Nodes: result})
injectResponse(net.net, to, neighborsPacket, &neighbors{Nodes: result})
}

func (tn *preminedTestnet) sendPing(to *Node, addr *net.UDPAddr, topics []Topic) []byte {
injectResponse(tn.net, to, pongPacket, &pong{ReplyTok: []byte{1}})
func (net *preminedTestnet) sendPing(to *Node, addr *net.UDPAddr, topics []Topic) []byte {
injectResponse(net.net, to, pongPacket, &pong{ReplyTok: []byte{1}})
return []byte{1}
}

func (tn *preminedTestnet) send(to *Node, ptype nodeEvent, data interface{}) (hash []byte) {
func (net *preminedTestnet) send(to *Node, ptype nodeEvent, data interface{}) (hash []byte) {
switch ptype {
case pingPacket:
injectResponse(tn.net, to, pongPacket, &pong{ReplyTok: []byte{1}})
injectResponse(net.net, to, pongPacket, &pong{ReplyTok: []byte{1}})
case pongPacket:
// ignored
case findnodeHashPacket:
Expand All @@ -302,29 +302,29 @@ func (tn *preminedTestnet) send(to *Node, ptype nodeEvent, data interface{}) (ha
}
next := to.UDP - 1
var result []rpcNode
for i, id := range tn.dists[to.UDP-lowPort] {
for i, id := range net.dists[to.UDP-lowPort] {
result = append(result, nodeToRPC(NewNode(id, net.ParseIP("10.0.2.99"), next, uint16(i)+1+lowPort)))
}
injectResponse(tn.net, to, neighborsPacket, &neighbors{Nodes: result})
injectResponse(net.net, to, neighborsPacket, &neighbors{Nodes: result})
default:
panic("send(" + ptype.String() + ")")
}
return []byte{2}
}

func (tn *preminedTestnet) sendNeighbours(to *Node, nodes []*Node) {
func (net *preminedTestnet) sendNeighbours(to *Node, nodes []*Node) {
panic("sendNeighbours called")
}

func (tn *preminedTestnet) sendTopicQuery(to *Node, topic Topic) {
func (net *preminedTestnet) sendTopicQuery(to *Node, topic Topic) {
panic("sendTopicQuery called")
}

func (tn *preminedTestnet) sendTopicNodes(to *Node, queryHash common.Hash, nodes []*Node) {
func (net *preminedTestnet) sendTopicNodes(to *Node, queryHash common.Hash, nodes []*Node) {
panic("sendTopicNodes called")
}

func (tn *preminedTestnet) sendTopicRegister(to *Node, topics []Topic, idx int, pong []byte) {
func (net *preminedTestnet) sendTopicRegister(to *Node, topics []Topic, idx int, pong []byte) {
panic("sendTopicRegister called")
}

Expand All @@ -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 (net *preminedTestnet) mine(target NodeID) {
net.target = target
net.targetSha = crypto.Keccak256Hash(net.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(net.targetSha, sha)
if len(net.dists[ld]) < bucketSize {
net.dists[ld] = append(net.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.Println("&preminedTesnetet{")
fmt.Printf(" target: %#v,\n", net.target)
fmt.Printf(" targetSha: %#v,\n", net.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(net.dists))
for ld, ns := range net.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 @@ -271,15 +271,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 @@ -288,15 +288,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 @@ -305,8 +305,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 3660688

Please sign in to comment.