public PeerAddressMessage(byte[] encoding)
            : this()
        {
            try
            {
                MemoryStream memoryStream = new MemoryStream(encoding, 0, encoding.Length, false);
                BinaryReader binaryReader = new BinaryReader(new BufferedStream(memoryStream));

                TypeOfMessage = (MessageType)MessagesEncodingUtil.ReadByte(binaryReader);

                IPEndPoint localEndPoint = ParseIpEndPoint(MessagesEncodingUtil.ReadString(binaryReader));
                IPEndPoint publicEndPoint = ParseIpEndPoint(MessagesEncodingUtil.ReadString(binaryReader));

                PeerAddress = new PeerAddress(localEndPoint, publicEndPoint);
            }
            catch (Exception)
            {
                throw new BinaryEncodingException("Encode");
            }
        }
 public PeerAddressMessage(PeerAddress peerAddress, MessageType messageType = MessageType.PeerAddress)
 {
     PeerAddress = peerAddress;
     TypeOfMessage = messageType;
 }
Beispiel #3
0
 public ClientInfo PeerAddress(PeerAddress peerAddress)
 {
     _peerAddress = peerAddress;
     return this;
 }        
        private bool InitClientAddress()
        {
            var requestMessage = _client.Read() as RequestMessage;

            if (requestMessage != null && requestMessage.RequestedMessageType == MessageType.ClientPeerAddress)
            {
                PeerAddress peerAddress = new PeerAddress { PublicEndPoint = _client.RemoteEndPoint };

                _client.Send(new PeerAddressMessage(peerAddress, MessageType.ClientPeerAddress));
                peerAddress.PrivateEndPoint = ((PeerAddressMessage)_client.Read()).PeerAddress.PrivateEndPoint;

                Info.PeerAddress(peerAddress);
                return true;
            }
            else
            {
                _client.Close();
                return false;
            }
        }
Beispiel #5
0
 protected bool Equals(PeerAddress other)
 {
     return Equals(PrivateEndPoint, other.PrivateEndPoint)
         && Equals(PublicEndPoint, other.PublicEndPoint);
 }