mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
les/*: golint updates for this or self warning
This commit is contained in:
parent
36606883d6
commit
4f6aea31d0
3 changed files with 100 additions and 100 deletions
|
|
@ -89,16 +89,16 @@ func NewClientManager(rcTarget, maxSimReq, maxRcSum uint64) *ClientManager {
|
||||||
return cm
|
return cm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) Stop() {
|
func (m *ClientManager) Stop() {
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
// signal any waiting accept routines to return false
|
// signal any waiting accept routines to return false
|
||||||
self.nodes = make(map[*cmNode]struct{})
|
m.nodes = make(map[*cmNode]struct{})
|
||||||
close(self.resumeQueue)
|
close(m.resumeQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) addNode(cnode *ClientNode) *cmNode {
|
func (m *ClientManager) addNode(cnode *ClientNode) *cmNode {
|
||||||
time := mclock.Now()
|
time := mclock.Now()
|
||||||
node := &cmNode{
|
node := &cmNode{
|
||||||
node: cnode,
|
node: cnode,
|
||||||
|
|
@ -106,28 +106,28 @@ func (self *ClientManager) addNode(cnode *ClientNode) *cmNode {
|
||||||
finishRecharge: time,
|
finishRecharge: time,
|
||||||
rcWeight: 1,
|
rcWeight: 1,
|
||||||
}
|
}
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
self.nodes[node] = struct{}{}
|
m.nodes[node] = struct{}{}
|
||||||
self.update(mclock.Now())
|
m.update(mclock.Now())
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) removeNode(node *cmNode) {
|
func (m *ClientManager) removeNode(node *cmNode) {
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
time := mclock.Now()
|
time := mclock.Now()
|
||||||
self.stop(node, time)
|
m.stop(node, time)
|
||||||
delete(self.nodes, node)
|
delete(m.nodes, node)
|
||||||
self.update(time)
|
m.update(time)
|
||||||
}
|
}
|
||||||
|
|
||||||
// recalc sumWeight
|
// recalc sumWeight
|
||||||
func (self *ClientManager) updateNodes(time mclock.AbsTime) (rce bool) {
|
func (m *ClientManager) updateNodes(time mclock.AbsTime) (rce bool) {
|
||||||
var sumWeight, rcSum uint64
|
var sumWeight, rcSum uint64
|
||||||
for node := range self.nodes {
|
for node := range m.nodes {
|
||||||
rc := node.recharging
|
rc := node.recharging
|
||||||
node.update(time)
|
node.update(time)
|
||||||
if rc && !node.recharging {
|
if rc && !node.recharging {
|
||||||
|
|
@ -138,44 +138,44 @@ func (self *ClientManager) updateNodes(time mclock.AbsTime) (rce bool) {
|
||||||
}
|
}
|
||||||
rcSum += uint64(node.rcValue)
|
rcSum += uint64(node.rcValue)
|
||||||
}
|
}
|
||||||
self.sumWeight = sumWeight
|
m.sumWeight = sumWeight
|
||||||
self.rcSumValue = rcSum
|
m.rcSumValue = rcSum
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) update(time mclock.AbsTime) {
|
func (m *ClientManager) update(time mclock.AbsTime) {
|
||||||
for {
|
for {
|
||||||
firstTime := time
|
firstTime := time
|
||||||
for node := range self.nodes {
|
for node := range m.nodes {
|
||||||
if node.recharging && node.finishRecharge < firstTime {
|
if node.recharging && node.finishRecharge < firstTime {
|
||||||
firstTime = node.finishRecharge
|
firstTime = node.finishRecharge
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.updateNodes(firstTime) {
|
if m.updateNodes(firstTime) {
|
||||||
for node := range self.nodes {
|
for node := range m.nodes {
|
||||||
if node.recharging {
|
if node.recharging {
|
||||||
node.set(node.serving, self.simReqCnt, self.sumWeight)
|
node.set(node.serving, m.simReqCnt, m.sumWeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.time = time
|
m.time = time
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) canStartReq() bool {
|
func (m *ClientManager) canStartReq() bool {
|
||||||
return self.simReqCnt < self.maxSimReq && self.rcSumValue < self.maxRcSum
|
return m.simReqCnt < m.maxSimReq && m.rcSumValue < m.maxRcSum
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) queueProc() {
|
func (m *ClientManager) queueProc() {
|
||||||
for rc := range self.resumeQueue {
|
for rc := range m.resumeQueue {
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
self.update(mclock.Now())
|
m.update(mclock.Now())
|
||||||
cs := self.canStartReq()
|
cs := m.canStartReq()
|
||||||
self.lock.Unlock()
|
m.lock.Unlock()
|
||||||
if cs {
|
if cs {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -184,41 +184,41 @@ func (self *ClientManager) queueProc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) accept(node *cmNode, time mclock.AbsTime) bool {
|
func (m *ClientManager) accept(node *cmNode, time mclock.AbsTime) bool {
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
self.update(time)
|
m.update(time)
|
||||||
if !self.canStartReq() {
|
if !m.canStartReq() {
|
||||||
resume := make(chan bool)
|
resume := make(chan bool)
|
||||||
self.lock.Unlock()
|
m.lock.Unlock()
|
||||||
self.resumeQueue <- resume
|
m.resumeQueue <- resume
|
||||||
<-resume
|
<-resume
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
if _, ok := self.nodes[node]; !ok {
|
if _, ok := m.nodes[node]; !ok {
|
||||||
return false // reject if node has been removed or manager has been stopped
|
return false // reject if node has been removed or manager has been stopped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.simReqCnt++
|
m.simReqCnt++
|
||||||
node.set(true, self.simReqCnt, self.sumWeight)
|
node.set(true, m.simReqCnt, m.sumWeight)
|
||||||
node.startValue = node.rcValue
|
node.startValue = node.rcValue
|
||||||
self.update(self.time)
|
m.update(m.time)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) stop(node *cmNode, time mclock.AbsTime) {
|
func (m *ClientManager) stop(node *cmNode, time mclock.AbsTime) {
|
||||||
if node.serving {
|
if node.serving {
|
||||||
self.update(time)
|
m.update(time)
|
||||||
self.simReqCnt--
|
m.simReqCnt--
|
||||||
node.set(false, self.simReqCnt, self.sumWeight)
|
node.set(false, m.simReqCnt, m.sumWeight)
|
||||||
self.update(time)
|
m.update(time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ClientManager) processed(node *cmNode, time mclock.AbsTime) (rcValue, rcCost uint64) {
|
func (m *ClientManager) processed(node *cmNode, time mclock.AbsTime) (rcValue, rcCost uint64) {
|
||||||
self.lock.Lock()
|
m.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
self.stop(node, time)
|
m.stop(node, time)
|
||||||
return uint64(node.rcValue), uint64(node.rcValue - node.startValue)
|
return uint64(node.rcValue), uint64(node.rcValue - node.startValue)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1162,15 +1162,15 @@ type NodeInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeInfo retrieves some protocol metadata about the running host node.
|
// NodeInfo retrieves some protocol metadata about the running host node.
|
||||||
func (self *ProtocolManager) NodeInfo() *NodeInfo {
|
func (pm *ProtocolManager) NodeInfo() *NodeInfo {
|
||||||
head := self.blockchain.CurrentHeader()
|
head := self.blockchain.CurrentHeader()
|
||||||
hash := head.Hash()
|
hash := head.Hash()
|
||||||
|
|
||||||
return &NodeInfo{
|
return &NodeInfo{
|
||||||
Network: self.networkId,
|
Network: pm.networkId,
|
||||||
Difficulty: self.blockchain.GetTd(hash, head.Number.Uint64()),
|
Difficulty: pm.blockchain.GetTd(hash, head.Number.Uint64()),
|
||||||
Genesis: self.blockchain.Genesis().Hash(),
|
Genesis: pm.blockchain.Genesis().Hash(),
|
||||||
Config: self.blockchain.Config(),
|
Config: pm.blockchain.Config(),
|
||||||
Head: hash,
|
Head: hash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,47 +50,47 @@ func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LesTxRelay) registerPeer(p *peer) {
|
func (r *LesTxRelay) registerPeer(p *peer) {
|
||||||
self.lock.Lock()
|
r.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
self.peerList = self.ps.AllPeers()
|
r.peerList = r.ps.AllPeers()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LesTxRelay) unregisterPeer(p *peer) {
|
func (r *LesTxRelay) unregisterPeer(p *peer) {
|
||||||
self.lock.Lock()
|
r.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
self.peerList = self.ps.AllPeers()
|
r.peerList = r.ps.AllPeers()
|
||||||
}
|
}
|
||||||
|
|
||||||
// send sends a list of transactions to at most a given number of peers at
|
// send sends a list of transactions to at most a given number of peers at
|
||||||
// once, never resending any particular transaction to the same peer twice
|
// once, never resending any particular transaction to the same peer twice
|
||||||
func (self *LesTxRelay) send(txs types.Transactions, count int) {
|
func (r *LesTxRelay) send(txs types.Transactions, count int) {
|
||||||
sendTo := make(map[*peer]types.Transactions)
|
sendTo := make(map[*peer]types.Transactions)
|
||||||
|
|
||||||
self.peerStartPos++ // rotate the starting position of the peer list
|
r.peerStartPos++ // rotate the starting position of the peer list
|
||||||
if self.peerStartPos >= len(self.peerList) {
|
if r.peerStartPos >= len(r.peerList) {
|
||||||
self.peerStartPos = 0
|
r.peerStartPos = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
ltr, ok := self.txSent[hash]
|
ltr, ok := r.txSent[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
ltr = <rInfo{
|
ltr = <rInfo{
|
||||||
tx: tx,
|
tx: tx,
|
||||||
sentTo: make(map[*peer]struct{}),
|
sentTo: make(map[*peer]struct{}),
|
||||||
}
|
}
|
||||||
self.txSent[hash] = ltr
|
r.txSent[hash] = ltr
|
||||||
self.txPending[hash] = struct{}{}
|
r.txPending[hash] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(self.peerList) > 0 {
|
if len(r.peerList) > 0 {
|
||||||
cnt := count
|
cnt := count
|
||||||
pos := self.peerStartPos
|
pos := r.peerStartPos
|
||||||
for {
|
for {
|
||||||
peer := self.peerList[pos]
|
peer := r.peerList[pos]
|
||||||
if _, ok := ltr.sentTo[peer]; !ok {
|
if _, ok := ltr.sentTo[peer]; !ok {
|
||||||
sendTo[peer] = append(sendTo[peer], tx)
|
sendTo[peer] = append(sendTo[peer], tx)
|
||||||
ltr.sentTo[peer] = struct{}{}
|
ltr.sentTo[peer] = struct{}{}
|
||||||
|
|
@ -100,10 +100,10 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) {
|
||||||
break // sent it to the desired number of peers
|
break // sent it to the desired number of peers
|
||||||
}
|
}
|
||||||
pos++
|
pos++
|
||||||
if pos == len(self.peerList) {
|
if pos == len(r.peerList) {
|
||||||
pos = 0
|
pos = 0
|
||||||
}
|
}
|
||||||
if pos == self.peerStartPos {
|
if pos == r.peerStartPos {
|
||||||
break // tried all available peers
|
break // tried all available peers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,46 +130,46 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) {
|
||||||
return func() { peer.SendTxs(reqID, cost, ll) }
|
return func() { peer.SendTxs(reqID, cost, ll) }
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.reqDist.queue(rq)
|
r.reqDist.queue(rq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LesTxRelay) Send(txs types.Transactions) {
|
func (r *LesTxRelay) Send(txs types.Transactions) {
|
||||||
self.lock.Lock()
|
r.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
self.send(txs, 3)
|
r.send(txs, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) {
|
func (r *LesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) {
|
||||||
self.lock.Lock()
|
r.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
for _, hash := range mined {
|
for _, hash := range mined {
|
||||||
delete(self.txPending, hash)
|
delete(r.txPending, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hash := range rollback {
|
for _, hash := range rollback {
|
||||||
self.txPending[hash] = struct{}{}
|
r.txPending[hash] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(self.txPending) > 0 {
|
if len(r.txPending) > 0 {
|
||||||
txs := make(types.Transactions, len(self.txPending))
|
txs := make(types.Transactions, len(r.txPending))
|
||||||
i := 0
|
i := 0
|
||||||
for hash := range self.txPending {
|
for hash := range r.txPending {
|
||||||
txs[i] = self.txSent[hash].tx
|
txs[i] = r.txSent[hash].tx
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
self.send(txs, 1)
|
r.send(txs, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LesTxRelay) Discard(hashes []common.Hash) {
|
func (r *LesTxRelay) Discard(hashes []common.Hash) {
|
||||||
self.lock.Lock()
|
r.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
for _, hash := range hashes {
|
for _, hash := range hashes {
|
||||||
delete(self.txSent, hash)
|
delete(r.txSent, hash)
|
||||||
delete(self.txPending, hash)
|
delete(r.txPending, hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue