implement the GetBeaconSyncingPeer function

Signed-off-by: Leo Chen <leo@harmony.one>
pull/513/head
Leo Chen 6 years ago
parent 634ada791c
commit 42fe29bbf4
  1. 29
      node/node_syncing.go

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -32,21 +33,11 @@ func getPeerFromIPandPort(ip, port string) p2p.Peer {
return p2p.Peer{IP: ip, Port: port, PeerID: peerID} return p2p.Peer{IP: ip, Port: port, PeerID: peerID}
} }
// GetBeaconSyncingPeers returns a list of peers for beaconchain syncing // getNeighborPeers is a helper function to return list of peers
// TODO: currently hard coded // based on different neightbor map
func (node *Node) GetBeaconSyncingPeers() []p2p.Peer { func (node *Node) getNeighborPeers(neighbor sync.Map) []p2p.Peer {
p1 := getPeerFromIPandPort("127.0.0.1", "6001")
p2 := getPeerFromIPandPort("127.0.0.1", "6002")
p3 := getPeerFromIPandPort("127.0.0.1", "6003")
p4 := getPeerFromIPandPort("127.0.0.1", "6004")
p5 := getPeerFromIPandPort("127.0.0.1", "6005")
return []p2p.Peer{p1, p2, p3, p4, p5}
}
// GetSyncingPeers returns list of peers.
func (node *Node) GetSyncingPeers() []p2p.Peer {
res := []p2p.Peer{} res := []p2p.Peer{}
node.Neighbors.Range(func(k, v interface{}) bool { neighbor.Range(func(k, v interface{}) bool {
res = append(res, v.(p2p.Peer)) res = append(res, v.(p2p.Peer))
return true return true
}) })
@ -65,6 +56,16 @@ func (node *Node) GetSyncingPeers() []p2p.Peer {
return res return res
} }
// GetBeaconSyncingPeers returns a list of peers for beaconchain syncing
func (node *Node) GetBeaconSyncingPeers() []p2p.Peer {
return node.getNeighborPeers(node.BeaconNeighbors)
}
// GetSyncingPeers returns list of peers for regular shard syncing.
func (node *Node) GetSyncingPeers() []p2p.Peer {
return node.getNeighborPeers(node.Neighbors)
}
// DoBeaconSyncing update received beaconchain blocks and downloads missing beacon chain blocks // DoBeaconSyncing update received beaconchain blocks and downloads missing beacon chain blocks
func (node *Node) DoBeaconSyncing() { func (node *Node) DoBeaconSyncing() {
for { for {

Loading…
Cancel
Save