add idc struct

pull/76/head
ak 6 years ago
parent d4f9a82215
commit b7807f5ec0
  1. 50
      identitychain/identitychain.go

@ -20,61 +20,13 @@ type IdentityChain struct {
//Identities []*IdentityBlock //No need to have the identity block as of now
Identities []*node.Node
log log.Logger
Peer p2p.Peer
SelectedIdentitites []*node.Node
EpochNum int
PeerToShardMap map[*node.Node]int
ShardLeaderMap map[int]*node.Node
PubKey string
CurrentEpochStartTime int64
NumberOfShards int
NumberOfNodesInShard int
NumberOfLeadersAdded int
}
func seekRandomNumber(EpochNum int, SelectedIdentitites []*node.Node) int {
// Broadcast message to all nodes and collect back their numbers, do consensus and get a leader.
// Use leader to generate a random number.
//all here mocked
// interact with "node" and "wait_node"
return rand.Intn(1000)
}
//GlobalBlockchainConfig stores global level blockchain configurations.
type GlobalBlockchainConfig struct {
NumberOfShards int
EpochTimeSecs int16
MaxNodesInShard int
}
//Shard
func (IDC *IdentityChain) Shard() {
IDC.SelectIds()
IDC.CreateShardAssignment()
IDC.ElectLeaders()
IDC.BroadCastNewConfiguration()
}
//ElectLeaders
func (IDC *IdentityChain) ElectLeaders() {
}
//BroadCastNewConfiguration
func (IDC *IdentityChain) BroadCastNewConfiguration() {
fmt.Println("Broadcasting leader and shard info to everyone!")
// allPeers := make([]p2p.Peer, len(IDC.SelectedIdentitites))
// msgToSend := proto.
// p2p.BroadCastMessage(allPeers, msgToSend)
}
//BroadCast Peer Infor to Node
// func (IDC *IdentityChain) SendPeerInfo(Node node) {
// return
// }
//CreateShardAssignment
func (IDC *IdentityChain) CreateShardAssignment() {
num := seekRandomNumber(IDC.EpochNum, IDC.SelectedIdentitites)
IDC.NumberOfShards = IDC.NumberOfShards + needNewShards()

Loading…
Cancel
Save