Ejemplo n.º 1
0
        public void SendMessageToPeer(Message message, Peer peer)
        {
            if (Status == TrackerStatus.Connected)
            {
                NetworkComms.Logger.Warn("Sent message: " + message.Type.ToString());

                var shellMessage = new ToPeerMessage(CommonHelpers.GetLocalEndPoint(CommonHelpers.PeerPort, true), peer.Address, message);
                try
                {
                    Connection.SendObject(shellMessage.GetType().Name, shellMessage);
                }
                catch
                {
                    Status = TrackerStatus.Disconnected;
                    Connect();
                }
            }
            else
            {
                Connect();
            }
        }
Ejemplo n.º 2
0
        private void OnToPeerMessage(PacketHeader packetHeader, Connection connection, ToPeerMessage incomingObject)
        {
            NetworkComms.Logger.Warn("Received message: " + incomingObject.Message.Type.ToString());

            if (incomingObject.RecieverAddress.Equals(CommonHelpers.GetLocalEndPoint(CommonHelpers.PeerPort, true)))
            {
                var eventArgs = new MessageEventArgs(incomingObject.Message, null, incomingObject.SenderAddress);

                if (incomingObject.Message is PeerHashMessage)
                {
                    OnPeerHashMessage?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is RequestPeersMessage)
                {
                    OnRequestPeersMessage?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is PeersMessage)
                {
                    OnPeersMessageFromPeer?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is RequestBlocksMessage)
                {
                    OnRequestBlocksMessage?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is RequestTransactionsMessage)
                {
                    OnRequestTransactionsMessage?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is BlocksMessage)
                {
                    OnBlocksMessage?.Invoke(this, eventArgs);
                }
                else if (incomingObject.Message is TransactionsMessage)
                {
                    OnTransactionsMessage?.Invoke(this, eventArgs);
                }
            }
        }