The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/identitychain/identitychain.go

86 lines
2.2 KiB

package identitychain
import (
"fmt"
6 years ago
"net"
"os"
"sync"
6 years ago
"github.com/simple-rules/harmony-benchmark/log"
6 years ago
"github.com/simple-rules/harmony-benchmark/node"
)
var mutex sync.Mutex
6 years ago
var identityPerBlock = 100000
// IdentityChain (Blockchain) keeps Identities per epoch, currently centralized!
type IdentityChain struct {
//Identities []*IdentityBlock //No need to have the identity block as of now
6 years ago
Identities []*node.Node
log log.Logger
PeerToShardMap map[*node.Node]int
ShardLeaderMap map[int]*node.Node
PubKey string
NumberOfShards int
NumberOfLeadersAdded int
6 years ago
}
6 years ago
func (IDC *IdentityChain) CreateShardAssignment() {
}
func (IDC *IdentityChain) generateRandomPermutations(num int) {
6 years ago
}
6 years ago
// SelectIds as
6 years ago
func (IDC *IdentityChain) SelectIds() {
// selectNumber := IDC.NumberOfNodesInShard - len(IDC.Identities)
// Insert the lines below once you have a identity block
// IB := IDC.GetLatestBlock()
// currentIDS := IB.GetIdentities()
// currentIDS := IDC.Identities
// selectNumber = int(math.Min(float64(len(IDC.PendingIdentities)), float64(selectNumber)))
// pending := IDC.PendingIdentities[:selectNumber]
// IDC.SelectedIdentitites = append(currentIDS, pending...)
// IDC.PendingIdentities = []*node.Node{}
6 years ago
}
//AcceptConnections welcomes new connections
func (IDC *IdentityChain) AcceptConnections() {
registerNode()
}
6 years ago
func registerNode() {
return
}
6 years ago
//StartServer a server and process the request by a handler.
func (IDC *IdentityChain) StartServer() {
fmt.Println("Starting server...")
IDC.log.Info("Starting IDC server...") //log.Info does nothing for me! (ak)
IDC.listenOnPort()
}
func (IDC *IdentityChain) listenOnPort() {
6 years ago
addr := net.JoinHostPort("", "8081")
listen, err := net.Listen("tcp4", addr)
6 years ago
if err != nil {
6 years ago
IDC.log.Crit("Socket listen port failed")
6 years ago
os.Exit(1)
6 years ago
} else {
6 years ago
fmt.Println("Starting server...now listening")
IDC.log.Info("Identity chain is now listening ..") //log.Info does nothing for me! (ak) remove this
6 years ago
}
6 years ago
defer listen.Close()
6 years ago
for {
conn, err := listen.Accept()
if err != nil {
6 years ago
IDC.log.Crit("Error listening on port. Exiting", "8081")
6 years ago
continue
6 years ago
} else {
fmt.Println("I am accepting connections now")
6 years ago
}
go IDC.IdentityChainHandler(conn)
}
}