public NodeConnection(Bitmessage bitmessage, TcpClient tcpClient)
 {
     Bitmessage = bitmessage;
     _tcpClient = tcpClient;
     var ipep = (IPEndPoint) tcpClient.Client.RemoteEndPoint;
     NetworkAddress = new NetworkAddress
                {
                    TimeLastSeen = DateTime.UtcNow,
                    Stream = 1,
                    Services = 0, // ???
                    Host = (ipep.Address.ToString()),
                    Port = (UInt16)ipep.Port,
                };
 }
        internal static NetworkAddress GetFromAddrList(byte[] addrList, ref int pos)
        {
            var result = new NetworkAddress
            {
                TimeLastSeen = addrList.ReadUInt64(ref pos).FromUnix(),
                Stream       = addrList.ReadUInt32(ref pos),
                Services     = addrList.ReadUInt64(ref pos)
            };

            byte[] ip = addrList.ReadBytes(ref pos, 16);
            result.Host = new IPAddress(ip).ToString();
            if (result.Host.StartsWith("::ffff:"))
            {
                byte[] ipv4 = new byte[4];
                Buffer.BlockCopy(ip, 12, ipv4, 0, 4);
                result.Host = new IPAddress(ipv4).ToString();
            }
            result.Port = addrList.ReadUInt16(ref pos);

            return(result);
        }
 public NodeConnection(Bitmessage bitmessage, NetworkAddress networkAddress)
 {
     Bitmessage = bitmessage;
     NetworkAddress = networkAddress;
     _tcpClient = new TcpClient(AddressFamily.InterNetwork);
 }
 internal void DeleteNode(NetworkAddress networkAddress)
 {
     throw new NotImplementedException();
 }
 internal Task<int> AddNode(NetworkAddress networkAddress)
 {
     return DB.InsertOrReplaceAsync(networkAddress);
 }
        internal static NetworkAddress GetFromAddrList(byte[] addrList, ref int pos)
        {
            var result = new NetworkAddress
                             {
                                 TimeLastSeen = addrList.ReadUInt64(ref pos).FromUnix(),
                                 Stream = addrList.ReadUInt32(ref pos),
                                 Services = addrList.ReadUInt64(ref pos)
                             };
            byte[] ip = addrList.ReadBytes(ref pos, 16);
            result.Host = new IPAddress(ip).ToString();
            if (result.Host.StartsWith("::ffff:"))
            {
                byte[] ipv4 = new byte[4];
                Buffer.BlockCopy(ip, 12, ipv4, 0, 4);
                result.Host = new IPAddress(ipv4).ToString();
            }
            result.Port = addrList.ReadUInt16(ref pos);

            return result;
        }