|
|
|
@ -64,10 +64,10 @@ type Node struct { |
|
|
|
|
SelfPeer p2p.Peer // TODO(minhdoan): it could be duplicated with Self below whose is Alok work.
|
|
|
|
|
IDCPeer p2p.Peer |
|
|
|
|
|
|
|
|
|
SyncNode bool // TODO(minhdoan): Remove it later.
|
|
|
|
|
chain *core.BlockChain // Account Model
|
|
|
|
|
Neighbors map[string]*p2p.Peer // All the neighbor nodes, key is the sha256 of Peer IP/Port
|
|
|
|
|
State NodeState // State of the Node
|
|
|
|
|
SyncNode bool // TODO(minhdoan): Remove it later.
|
|
|
|
|
chain *core.BlockChain // Account Model
|
|
|
|
|
Neighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer
|
|
|
|
|
State NodeState // State of the Node
|
|
|
|
|
|
|
|
|
|
// Account Model
|
|
|
|
|
Chain *core.BlockChain |
|
|
|
@ -245,7 +245,6 @@ func New(consensus *bft.Consensus, db *hdb.LDBDatabase) *Node { |
|
|
|
|
} |
|
|
|
|
// Logger
|
|
|
|
|
node.log = log.New() |
|
|
|
|
node.Neighbors = make(map[string]*p2p.Peer) |
|
|
|
|
node.State = INIT |
|
|
|
|
|
|
|
|
|
return &node |
|
|
|
@ -256,15 +255,14 @@ func (node *Node) AddPeers(peers []p2p.Peer) int { |
|
|
|
|
count := 0 |
|
|
|
|
for _, p := range peers { |
|
|
|
|
key := fmt.Sprintf("%v", p.PubKey) |
|
|
|
|
_, ok := node.Neighbors[key] |
|
|
|
|
_, ok := node.Neighbors.Load(key) |
|
|
|
|
if !ok { |
|
|
|
|
np := new(p2p.Peer) |
|
|
|
|
copier.Copy(np, &p) |
|
|
|
|
node.Neighbors[key] = np |
|
|
|
|
node.Neighbors.Store(key, *np) |
|
|
|
|
count++ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
node.log.Info("Added", "# of peers", count) |
|
|
|
|
|
|
|
|
|
if count > 0 { |
|
|
|
|
c := node.Consensus.AddPeers(peers) |
|
|
|
@ -275,7 +273,7 @@ func (node *Node) AddPeers(peers []p2p.Peer) int { |
|
|
|
|
|
|
|
|
|
func (node *Node) JoinShard(leader p2p.Peer) { |
|
|
|
|
// try to join the shard, with 10 minutes time-out
|
|
|
|
|
backoff := p2p.NewExpBackoff(500*time.Millisecond, 10*time.Minute, 2) |
|
|
|
|
backoff := p2p.NewExpBackoff(1*time.Second, 10*time.Minute, 2) |
|
|
|
|
|
|
|
|
|
for node.State == WAIT { |
|
|
|
|
backoff.Sleep() |
|
|
|
@ -285,5 +283,4 @@ func (node *Node) JoinShard(leader p2p.Peer) { |
|
|
|
|
p2p.SendMessage(leader, buffer) |
|
|
|
|
node.log.Debug("Sent ping message") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|