remove NodeMessageType EXPERIMENT

pull/37/head
Minh Doan 6 years ago
parent 0c1756298c
commit bf0e4fd1b3
  1. 20
      node/message.go
  2. 15
      node/node_handler.go

@ -15,7 +15,6 @@ const (
BLOCK
CONTROL
EXPERIMENT // Exist only for experiment setup
// TODO: add more types
)
@ -42,14 +41,6 @@ const (
STOP ControlMessageType = iota
)
// The types of messages used for NODE/EXPERIMENT
type ExperimentMessageType int
const (
UTXO_REQUEST ExperimentMessageType = iota
UTXO_RESPONSE
)
// Constructs serialized transactions
func ConstructTransactionListMessage(transactions []*blockchain.Transaction) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)})
@ -84,17 +75,6 @@ func ConstructStopMessage() []byte {
return byteBuffer.Bytes()
}
// Constructs utxo response message with serialized utxoPool to return
func ConstructUtxoResponseMessage(pool blockchain.UTXOPool) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)})
byteBuffer.WriteByte(byte(EXPERIMENT))
byteBuffer.WriteByte(byte(UTXO_RESPONSE))
encoder := gob.NewEncoder(byteBuffer)
encoder.Encode(pool)
return byteBuffer.Bytes()
}
// Constructs blocks sync message to send blocks to other nodes
func ConstructBlocksSyncMessage(blocks []blockchain.Block) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)})

@ -101,21 +101,6 @@ func (node *Node) NodeHandler(conn net.Conn) {
os.Exit(0)
}
case EXPERIMENT:
expType := msgPayload[0]
switch ExperimentMessageType(expType) {
case UTXO_REQUEST:
node.log.Debug("Received UTXO request")
p2p.SendMessage(*node.ClientPeer, ConstructUtxoResponseMessage(node.UtxoPool.GetSnapshot()))
case UTXO_RESPONSE:
node.log.Debug("Received UTXO response")
decoder := gob.NewDecoder(bytes.NewReader(msgPayload[1:])) // skip the UTXO_RESPONSE messge type
utxoPool := new(blockchain.UTXOPool)
decoder.Decode(utxoPool)
if node.Client != nil && utxoPool != nil {
//node.Client.UpdateUtxoPool(*utxoPool)
}
}
}
case common.CLIENT:
actionType := client.ClientMessageType(msgType)

Loading…
Cancel
Save