private Message Create(byte type, byte[] packed) { MessageTypes.MsgType received = MessageTypes.FromByte(type); if (received == MessageTypes.MsgType.LAST) { throw new P2pException(P2pException.ErrorType.NO_SUCH_MESSAGE, "type=" + type + ", len=" + packed.Length); } switch (received) { case MessageTypes.MsgType.TX: return(new TransactionMessage(packed)); case MessageTypes.MsgType.BLOCK: return(new BlockMessage(packed)); case MessageTypes.MsgType.TXS: return(new TransactionsMessage(packed)); case MessageTypes.MsgType.BLOCKS: return(new BlocksMessage(packed)); case MessageTypes.MsgType.INVENTORY: return(new InventoryMessage(packed)); case MessageTypes.MsgType.FETCH_INV_DATA: return(new FetchInventoryDataMessage(packed)); case MessageTypes.MsgType.SYNC_BLOCK_CHAIN: return(new SyncBlockChainMessage(packed)); case MessageTypes.MsgType.BLOCK_CHAIN_INVENTORY: return(new ChainInventoryMessage(packed)); case MessageTypes.MsgType.ITEM_NOT_FOUND: return(new ItemNotFoundMessage()); case MessageTypes.MsgType.FETCH_BLOCK_HEADERS: return(new FetchBlockHeadersMessage(packed)); case MessageTypes.MsgType.TX_INVENTORY: return(new TransactionInventoryMessage(packed)); default: throw new P2pException( P2pException.ErrorType.NO_SUCH_MESSAGE, received.ToString() + ", len=" + packed.Length); } }
private P2pMessage Create(byte type, byte[] raw_data) { P2pMessage result = null; MessageTypes.MsgType message_type = MessageTypes.FromByte(type); if (message_type == MessageTypes.MsgType.LAST) { throw new P2pException(P2pException.ErrorType.NO_SUCH_MESSAGE, "type = " + type + ", len = " + raw_data.Length); } switch (message_type) { case MessageTypes.MsgType.P2P_HELLO: { result = new HelloMessage(type, raw_data); } break; case MessageTypes.MsgType.P2P_DISCONNECT: { result = new DisconnectMessage(type, raw_data); } break; case MessageTypes.MsgType.P2P_PING: { result = new PingMessage(type, raw_data); } break; case MessageTypes.MsgType.P2P_PONG: { result = new PongMessage(type, raw_data); } break; default: { throw new P2pException(P2pException.ErrorType.NO_SUCH_MESSAGE, message_type.ToString()); } } return(result); }