Example #1
0
// Serve the "fast lane" incoming control msg from inCtlMsgQueue
func serveCtlMsgRequest(msg wire.FtmInternalMsg) error {

	switch msg.Command() {
	case wire.CmdCommitChain:

	default:
		return errors.New("1 Message type unsupported:" + spew.Sdump(msg))
	}
	return nil

}
Example #2
0
// Serve incoming msg from inMsgQueue
func serveMsgRequest(msg wire.FtmInternalMsg) error {

	switch msg.Command() {
	case wire.CmdCommitChain:
		msgCommitChain, ok := msg.(*wire.MsgCommitChain)
		if ok && msgCommitChain.IsValid() {

			h := msgCommitChain.CommitChain.GetSigHash().Bytes()
			t := msgCommitChain.CommitChain.GetMilliTime() / 1000

			if !IsTSValid(h, t) {
				return fmt.Errorf("Timestamp invalid on Commit Chain")
			}

			err := processCommitChain(msgCommitChain)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + spew.Sdump(msg))
		}
		// Broadcast the msg to the network if no errors
		outMsgQueue <- msg

	case wire.CmdCommitEntry:
		msgCommitEntry, ok := msg.(*wire.MsgCommitEntry)
		if ok && msgCommitEntry.IsValid() {

			h := msgCommitEntry.CommitEntry.GetSigHash().Bytes()
			t := msgCommitEntry.CommitEntry.GetMilliTime() / 1000

			if !IsTSValid(h, t) {
				return fmt.Errorf("Timestamp invalid on Commit Entry")
			}

			err := processCommitEntry(msgCommitEntry)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + spew.Sdump(msg))
		}
		// Broadcast the msg to the network if no errors
		outMsgQueue <- msg

	case wire.CmdRevealEntry:
		msgRevealEntry, ok := msg.(*wire.MsgRevealEntry)
		if ok && msgRevealEntry.IsValid() {
			err := processRevealEntry(msgRevealEntry)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + spew.Sdump(msg))
		}
		// Broadcast the msg to the network if no errors
		outMsgQueue <- msg

	case wire.CmdInt_EOM:

		if nodeMode == common.SERVER_NODE {
			msgEom, ok := msg.(*wire.MsgInt_EOM)
			if !ok {
				return errors.New("Error in build blocks:" + spew.Sdump(msg))
			}
			procLog.Infof("PROCESSOR: End of minute msg - wire.CmdInt_EOM:%+v\n", msg)

			common.FactoidState.EndOfPeriod(int(msgEom.EOM_Type))

			if msgEom.EOM_Type == wire.END_MINUTE_10 {

				// Process from Orphan pool before the end of process list
				processFromOrphanPool()

				// Pass the Entry Credit Exchange Rate into the Factoid component
				msgEom.EC_Exchange_Rate = FactoshisPerCredit
				plMgr.AddMyProcessListItem(msgEom, nil, wire.END_MINUTE_10)
				// Set exchange rate in the Factoid State
				common.FactoidState.SetFactoshisPerEC(FactoshisPerCredit)

				err := buildBlocks()
				if err != nil {
					return err
				}

			} else if wire.END_MINUTE_1 <= msgEom.EOM_Type && msgEom.EOM_Type < wire.END_MINUTE_10 {
				ack, err := plMgr.AddMyProcessListItem(msgEom, nil, msgEom.EOM_Type)
				if err != nil {
					return err
				}
				if ack.ChainID == nil {
					ack.ChainID = dchain.ChainID
				}
				// Broadcast the ack to the network if no errors
				//outMsgQueue <- ack
			}

			cp.CP.AddUpdate(
				"MinMark",  // tag
				"status",   // Category
				"Progress", // Title
				fmt.Sprintf("End of Minute %v\n", msgEom.EOM_Type)+ // Message
					fmt.Sprintf("Directory Block Height %v", dchain.NextDBHeight),
				0)
		}

	case wire.CmdDirBlock:
		if nodeMode == common.SERVER_NODE {
			break
		}

		dirBlock, ok := msg.(*wire.MsgDirBlock)
		if ok {
			err := processDirBlock(dirBlock)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	case wire.CmdFBlock:

		if nodeMode == common.SERVER_NODE {
			break
		}

		fblock, ok := msg.(*wire.MsgFBlock)
		if ok {
			err := processFBlock(fblock)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	case wire.CmdFactoidTX:

		// First check that the message is good, and is valid.  If not,
		// continue processing commands.
		msgFactoidTX, ok := msg.(*wire.MsgFactoidTX)
		if !ok || !msgFactoidTX.IsValid() {
			break
		}
		// prevent replay attacks
		{
			h := msgFactoidTX.Transaction.GetSigHash().Bytes()
			t := int64(msgFactoidTX.Transaction.GetMilliTimestamp() / 1000)

			if !IsTSValid(h, t) {
				return fmt.Errorf("Timestamp invalid on Factoid Transaction")
			}
		}

		// Handle the server case
		if nodeMode == common.SERVER_NODE {
			t := msgFactoidTX.Transaction
			txnum := len(common.FactoidState.GetCurrentBlock().GetTransactions())
			if common.FactoidState.AddTransaction(txnum, t) == nil {
				if err := processBuyEntryCredit(msgFactoidTX); err != nil {
					return err
				}
			}
		} else {
			// Handle the client case
			outMsgQueue <- msg
		}

	case wire.CmdABlock:
		if nodeMode == common.SERVER_NODE {
			break
		}

		ablock, ok := msg.(*wire.MsgABlock)
		if ok {
			err := processABlock(ablock)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	case wire.CmdECBlock:
		if nodeMode == common.SERVER_NODE {
			break
		}

		cblock, ok := msg.(*wire.MsgECBlock)
		if ok {
			err := procesECBlock(cblock)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	case wire.CmdEBlock:
		if nodeMode == common.SERVER_NODE {
			break
		}

		eblock, ok := msg.(*wire.MsgEBlock)
		if ok {
			err := processEBlock(eblock)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	case wire.CmdEntry:
		if nodeMode == common.SERVER_NODE {
			break
		}

		entry, ok := msg.(*wire.MsgEntry)
		if ok {
			err := processEntry(entry)
			if err != nil {
				return err
			}
		} else {
			return errors.New("Error in processing msg:" + fmt.Sprintf("%+v", msg))
		}

	default:
		return errors.New("Message type unsupported:" + fmt.Sprintf("%+v", msg))
	}

	return nil
}