|
|
@ -79,6 +79,7 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
fmt.Println("received a identity message") |
|
|
|
fmt.Println("received a identity message") |
|
|
|
// TODO(ak): fix it.
|
|
|
|
// TODO(ak): fix it.
|
|
|
|
// node.processPOWMessage(msgPayload)
|
|
|
|
// node.processPOWMessage(msgPayload)
|
|
|
|
|
|
|
|
node.log.Info("NET: received message: IDENTITY/REGISTER") |
|
|
|
case proto_identity.Announce: |
|
|
|
case proto_identity.Announce: |
|
|
|
node.log.Error("Announce message should be sent to IdentityChain") |
|
|
|
node.log.Error("Announce message should be sent to IdentityChain") |
|
|
|
} |
|
|
|
} |
|
|
@ -88,8 +89,10 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
switch actionType { |
|
|
|
switch actionType { |
|
|
|
case consensus.Consensus: |
|
|
|
case consensus.Consensus: |
|
|
|
if consensusObj.IsLeader { |
|
|
|
if consensusObj.IsLeader { |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Consensus/Leader") |
|
|
|
consensusObj.ProcessMessageLeader(msgPayload) |
|
|
|
consensusObj.ProcessMessageLeader(msgPayload) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Consensus/Validator") |
|
|
|
consensusObj.ProcessMessageValidator(msgPayload) |
|
|
|
consensusObj.ProcessMessageValidator(msgPayload) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -97,8 +100,10 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
actionType := proto_node.NodeMessageType(msgType) |
|
|
|
actionType := proto_node.NodeMessageType(msgType) |
|
|
|
switch actionType { |
|
|
|
switch actionType { |
|
|
|
case proto_node.Transaction: |
|
|
|
case proto_node.Transaction: |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Node/Transaction") |
|
|
|
node.transactionMessageHandler(msgPayload) |
|
|
|
node.transactionMessageHandler(msgPayload) |
|
|
|
case proto_node.BLOCK: |
|
|
|
case proto_node.BLOCK: |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Node/BLOCK") |
|
|
|
blockMsgType := proto_node.BlockMessageType(msgPayload[0]) |
|
|
|
blockMsgType := proto_node.BlockMessageType(msgPayload[0]) |
|
|
|
switch blockMsgType { |
|
|
|
switch blockMsgType { |
|
|
|
case proto_node.Sync: |
|
|
|
case proto_node.Sync: |
|
|
@ -110,8 +115,10 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
case proto_node.BlockchainSync: |
|
|
|
case proto_node.BlockchainSync: |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Node/BlockchainSync") |
|
|
|
node.handleBlockchainSync(msgPayload, conn) |
|
|
|
node.handleBlockchainSync(msgPayload, conn) |
|
|
|
case proto_node.CLIENT: |
|
|
|
case proto_node.CLIENT: |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Node/CLIENT") |
|
|
|
clientMsgType := proto_node.ClientMessageType(msgPayload[0]) |
|
|
|
clientMsgType := proto_node.ClientMessageType(msgPayload[0]) |
|
|
|
switch clientMsgType { |
|
|
|
switch clientMsgType { |
|
|
|
case proto_node.LookupUtxo: |
|
|
|
case proto_node.LookupUtxo: |
|
|
@ -125,6 +132,7 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
p2p.SendMessage(fetchUtxoMessage.Sender, client.ConstructFetchUtxoResponseMessage(&utxoMap, node.UtxoPool.ShardID)) |
|
|
|
p2p.SendMessage(fetchUtxoMessage.Sender, client.ConstructFetchUtxoResponseMessage(&utxoMap, node.UtxoPool.ShardID)) |
|
|
|
} |
|
|
|
} |
|
|
|
case proto_node.CONTROL: |
|
|
|
case proto_node.CONTROL: |
|
|
|
|
|
|
|
node.log.Info("NET: received message: Node/CONTROL") |
|
|
|
controlType := msgPayload[0] |
|
|
|
controlType := msgPayload[0] |
|
|
|
if proto_node.ControlMessageType(controlType) == proto_node.STOP { |
|
|
|
if proto_node.ControlMessageType(controlType) == proto_node.STOP { |
|
|
|
node.log.Debug("Stopping Node", "node", node, "numBlocks", len(node.blockchain.Blocks), "numTxsProcessed", node.countNumTransactionsInBlockchain()) |
|
|
|
node.log.Debug("Stopping Node", "node", node, "numBlocks", len(node.blockchain.Blocks), "numTxsProcessed", node.countNumTransactionsInBlockchain()) |
|
|
@ -172,6 +180,7 @@ func (node *Node) NodeHandler(conn net.Conn) { |
|
|
|
} |
|
|
|
} |
|
|
|
case proto.CLIENT: |
|
|
|
case proto.CLIENT: |
|
|
|
actionType := client.ClientMessageType(msgType) |
|
|
|
actionType := client.ClientMessageType(msgType) |
|
|
|
|
|
|
|
node.log.Info("NET: received message: CLIENT/Transaction") |
|
|
|
switch actionType { |
|
|
|
switch actionType { |
|
|
|
case client.Transaction: |
|
|
|
case client.Transaction: |
|
|
|
if node.Client != nil { |
|
|
|
if node.Client != nil { |
|
|
@ -357,7 +366,7 @@ func (node *Node) SendBackProofOfAcceptOrReject() { |
|
|
|
// NOTE: For now, just send to the client (basically not broadcasting)
|
|
|
|
// NOTE: For now, just send to the client (basically not broadcasting)
|
|
|
|
func (node *Node) BroadcastNewBlock(newBlock *blockchain.Block) { |
|
|
|
func (node *Node) BroadcastNewBlock(newBlock *blockchain.Block) { |
|
|
|
if node.ClientPeer != nil { |
|
|
|
if node.ClientPeer != nil { |
|
|
|
node.log.Debug("SENDING NEW BLOCK TO CLIENT") |
|
|
|
node.log.Debug("NET: SENDING NEW BLOCK TO CLIENT") |
|
|
|
p2p.SendMessage(*node.ClientPeer, proto_node.ConstructBlocksSyncMessage([]blockchain.Block{*newBlock})) |
|
|
|
p2p.SendMessage(*node.ClientPeer, proto_node.ConstructBlocksSyncMessage([]blockchain.Block{*newBlock})) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|