public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
     HeadersMessage headersMessage = message as HeadersMessage;
     if (headersMessage != null)
     {
         ProcessHeadersMessage(endpoint, headersMessage);
     }
 }
        public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
        {
            EndpointState endpointState;

            lock (lockObject)
            {
                if (!endpoints.TryGetValue(endpoint, out endpointState))
                {
                    //todo: if node still sends us a required block it should probably be saved
                    // endpoint is either disconnected or not not fit for this service
                    return;
                }
            }

            var invMessage = message as InvMessage;
            if (invMessage != null)
            {
                ProcessInvMessage(endpointState, invMessage);
            }

            var blockMessage = message as BlockMessage;
            if (blockMessage != null)
            {
                ProcessBlockMessage(blockMessage);
            }
        }
 public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
     //todo: process AddrMessage
 }
 public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
     //todo: add test and catch maybe catch other exceptions
     try
     {
         foreach (NodeServiceInfo serviceInfo in services)
         {
             serviceInfo.Service.ProcessMessage(endpoint, message);
         }
     }
     catch (BitcoinProtocolViolationException e)
     {
         logger.Error(e, "Remote node violated protecol rules ({0}).", endpoint.PeerInfo.IpEndpoint);
         //todo: is this a correct way to disconnect node?
         //todo: ban node ?
         endpoint.Dispose();
     }
 }
 public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
     //todo: add test for this method
 }
        private bool LoggingMessageHandler(BitcoinEndpoint endpoint, IBitcoinMessage message)
        {
            Console.WriteLine(">>command: {0}", message.Command);

            if (message is InvMessage)
            {
                InvMessage invMessage = (InvMessage) message;
                foreach (InventoryVector vector in invMessage.Inventory)
                {
                    Console.WriteLine("\t{0} {1}", vector.Type.ToString().PadRight(16), BitConverter.ToString(vector.Hash));
                }
            }

            if (message is GetHeadersMessage)
            {
                GetHeadersMessage getHeadersMessage = (GetHeadersMessage) message;

                Console.WriteLine("\tprotocol: {0}", getHeadersMessage.ProtocolVersion);
                foreach (byte[] hash in getHeadersMessage.LocatorHashes)
                {
                    Console.WriteLine("\t{0}", BitConverter.ToString(hash));
                }
                Console.WriteLine("\t{0} (stop)", BitConverter.ToString(getHeadersMessage.HashStop));

                endpoint.WriteMessage(new InvMessage(new InventoryVector[]
                {
                    new InventoryVector(InventoryVectorType.MsgBlock, blockHash1)
                }));
            }

            if (message is GetDataMessage)
            {
                GetDataMessage getDataMessage = (GetDataMessage) message;
                foreach (InventoryVector vector in getDataMessage.Inventory)
                {
                    Console.WriteLine("\t{0} {1}", vector.Type.ToString().PadRight(16), BitConverter.ToString(vector.Hash));
                }
            }

            if (message is BlockMessage)
            {
                BlockMessage blockMessage = (BlockMessage) message;
                foreach (Tx tx in blockMessage.Transactions)
                {
                    Console.WriteLine("\tInputs:");
                    foreach (TxIn input in tx.Inputs)
                    {
                        Console.WriteLine("\t\t{0} seq. {1:X}", BitConverter.ToString(input.PreviousOutput.Hash), input.Sequence);
                    }
                    Console.WriteLine("\tOutputs:");
                    foreach (TxOut output in tx.Outputs)
                    {
                        Console.WriteLine("\t\t{0}, script: {1}", output.Value, BitConverter.ToString(output.PubkeyScript));
                    }
                }
            }
            if (message is MerkleBlockMessage)
            {
                MerkleBlockMessage merkleBlockMessage = (MerkleBlockMessage) message;

                BitArray flagsBitArray = new BitArray(merkleBlockMessage.Flags);
                StringBuilder flagsSb = new StringBuilder();
                foreach (bool flag in flagsBitArray)
                {
                    flagsSb.Append(flag ? "1" : "0");
                }

                Console.WriteLine("\tTotalTransactions: {0}", merkleBlockMessage.TotalTransactions);
                Console.WriteLine("\tFlags:             {0}", flagsSb);

                foreach (byte[] hash in merkleBlockMessage.Hashes)
                {
                    Console.WriteLine("\t\t{0}", BitConverter.ToString(hash));
                }
            }

            if (message is BitcoinMessage)
            {
                BitcoinMessage rawMessage = (BitcoinMessage) message;
                Console.WriteLine(">>payload: {0}", BitConverter.ToString(rawMessage.Payload));
            }

            return true;
        }
 private bool DeadlockTestMessageHandler(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
     Thread.Sleep(100);
     return true;
 }
        private bool HandleMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
        {
            if (message is AddrMessage)
            {
                SaveReceivedAddresses((AddrMessage) message);
                return true;
            }
            //todo: send GetAddr message sometimes
            //todo: see 0.10.1 Change log: Ignore getaddr messages on Outbound connections.
            if (message is GetAddrMessage)
            {
                SendKnownAddresses(endpoint);
                return true;
            }

            services.ProcessMessage(endpoint, message);
            //todo: handle getaddr message
            //todo: implement
            return true;
        }
 public void ProcessMessage(BitcoinEndpoint endpoint, IBitcoinMessage message)
 {
 }
 public void WriteMessage(IBitcoinMessage message)
 {
     BitcoinMessage rawMessage = new BitcoinMessage(message.Command, BitcoinStreamWriter.GetBytes(message.Write));
     conn.WriteMessage(rawMessage);
 }