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/waitnode/waitNode.go

45 lines
1.1 KiB

package waitnode
import (
"bytes"
"crypto/sha256"
"github.com/simple-rules/harmony-benchmark/log"
"github.com/simple-rules/harmony-benchmark/p2p"
"github.com/simple-rules/harmony-benchmark/proto/identity"
"github.com/simple-rules/harmony-benchmark/utils"
)
//WaitNode is for nodes waiting to join consensus
type WaitNode struct {
Peer p2p.Peer
6 years ago
Log log.Logger
ID []byte
}
// StartServer a server and process the request by a handler.
func (node *WaitNode) StartServer() {
6 years ago
node.Log.Debug("Starting waitnode on server %d", "node", node.Peer.Ip, "port", node.Peer.Port)
}
func (node *WaitNode) connectIdentityChain(peer p2p.Peer) {
// replace by p2p peer
p2p.SendMessage(peer, identity.ConstructIdentityMessage(identity.REGISTER, node.ID))
}
func calculateHash(num string) []byte {
var hashes [][]byte
hashes = append(hashes, utils.ConvertFixedDataIntoByteArray(num))
hash := sha256.Sum256(bytes.Join(hashes, []byte{}))
return hash[:]
}
// New Create a new Node
6 years ago
func New(Peer p2p.Peer) *WaitNode {
node := WaitNode{}
6 years ago
node.Peer = Peer
node.ID = calculateHash(Peer.Ip)
6 years ago
node.Log = log.New()
return &node
}