Inheritance: DeOps.Implementation.Protocol.G2Packet
コード例 #1
0
ファイル: Connection.cs プロジェクト: RoelofSol/DeOps
        public CacheItem(WebCache cache)
        {
            Original = cache;

            Cache = new WebCache();

            Cache.Address = cache.Address;
            Cache.AccessKey = cache.AccessKey;
        }
コード例 #2
0
ファイル: CacheSetup.cs プロジェクト: RoelofSol/DeOps
        public CacheSetup(OpCore core, WebCache cache)
            : base(core)
        {
            InitializeComponent();

            Core = core;
            Profile = Core.User;

            Cache = cache;

            AddressBox.Text = cache.Address;
            KeyBox.Text = (cache.AccessKey != null) ? Convert.ToBase64String(cache.AccessKey) : "";
            OpBox.Text = core.Network.OpID.ToString();
        }
コード例 #3
0
ファイル: CacheSetup.cs プロジェクト: RoelofSol/DeOps
        private void TestLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                WebCache test = new WebCache();
                test.Address = AddressBox.Text;
                test.AccessKey = Convert.FromBase64String(KeyBox.Text);

                string response = Core.Network.Cache.MakeWebCacheRequest(test, "ping:" + Core.Network.OpID.ToString());

                if (response.StartsWith("pong"))
                    MessageBox.Show("Success");
                else
                    MessageBox.Show(response);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #4
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        public static WebCache Decode(G2Header root)
        {
            WebCache cache = new WebCache();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Address:
                        cache.Address = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_AccessKey:
                        cache.AccessKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_LastSeen:
                        cache.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_LastTried:
                        cache.LastTried = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;
                }
            }

            return cache;
        }
コード例 #5
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        // caches sent in trust / invite packets
        public WebCache(WebCache cache, byte type)
        {
            Address = cache.Address;
            AccessKey = cache.AccessKey;

            PacketType = type;
            SaveTimeInfo = false;
        }
コード例 #6
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        private void WebQueryResponse(WebCache cache, string response)
        {
            double timeout = 0;
            bool low = false;

            foreach (string line in response.Split('\n'))
            {
                // add to node cache
                if (line.StartsWith("node:"))
                {
                    string[] parts = line.Substring(5).Split('/');

                    DhtContact contact = new DhtContact(ulong.Parse(parts[0]), 0, IPAddress.Parse(parts[1]), ushort.Parse(parts[2]), ushort.Parse(parts[3]));
                    contact.LastSeen = Core.TimeNow; // set this so its put at front of list, and is the first to be attempted

                    AddContact(contact);
                }

                // for use with publishing back to cache, dont set our local IP with it in case on
                // network with LAN nodes and web cache active, dont want to reset until we find nodes on external network
                else if (line.StartsWith("remoteip:"))
                    cache.RemoteIP = IPAddress.Parse(line.Substring(9));

                // set next publish time
                else if (line.StartsWith("timeout:"))
                    timeout = double.Parse(line.Substring(8));

                else if (line.StartsWith("load:low"))
                    low = true;
            }

            cache.NextPublish = Core.TimeNow.AddMinutes(Math.Max(timeout, 15)); // dont change to min

            // if cache low auto publish to low cache so that network can be initialized
            if (low)
                new Thread(WebPublish).Start(cache);
                // more caches will be queried by the bootstrap if network not responsive
        }
コード例 #7
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        private void WebPublishResponse(WebCache cache, string response)
        {
            bool low = false;
            double timeout = 0;

            foreach (string line in response.Split('\n'))
            {
                if (line.StartsWith("timeout:"))
                    timeout = double.Parse(line.Substring(8));

                else if (line.StartsWith("load:low"))
                    low = true;
            }

            cache.NextPublish = Core.TimeNow.AddMinutes(Math.Max(timeout, 15)); // dont change to math.min!

            // if this cache is low, immediately try to re-publish at an active cache
            if (low)
                NextPublishAny = Core.TimeNow;
        }
コード例 #8
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        public string MakeWebCacheRequest(WebCache cache, string request)
        {
            try
            {
                RijndaelManaged crypt = new RijndaelManaged();
                crypt.BlockSize = 256;
                crypt.Padding = PaddingMode.Zeros;
                crypt.GenerateIV();
                crypt.Key = cache.AccessKey;

                byte[] data = ASCIIEncoding.ASCII.GetBytes(request);
                byte[] encrypted = crypt.CreateEncryptor().TransformFinalBlock(data, 0, data.Length);

                // php decode requests
                byte[] ivEnc = Utilities.CombineArrays(crypt.IV, encrypted);
                string get = Convert.ToBase64String(ivEnc);

                string response = Utilities.WebDownloadString(cache.Address + "?get=" + Uri.EscapeDataString(get));

                if (response == null || response == "")
                    throw new Exception("Access key not accepted");

                // php encode response
                byte[] decoded = Convert.FromBase64String(response);

                // decode response
                crypt.IV = Utilities.ExtractBytes(decoded, 0, 32);

                data = Utilities.ExtractBytes(decoded, 32, decoded.Length - 32);
                byte[] decrypted = crypt.CreateDecryptor().TransformFinalBlock(data, 0, data.Length);

                response = ASCIIEncoding.ASCII.GetString(decrypted);
                response = response.Trim('\0');

                return response;
            }
            catch (Exception ex)
            {
                return "error: " + ex.Message;
            }
        }
コード例 #9
0
ファイル: OpCache.cs プロジェクト: swax/DeOps
        public void AddWebCache(WebCache add)
        {
            // look for exact match
            foreach (WebCache cache in WebCaches)
                if (cache.Equals(add))
                    return;

            // cache is pinged in minute timer
            add.NextPublish = Core.TimeNow.AddMinutes(60); // default timeout to publish is 1 hour
            add.PacketType = Network.IsLookup ? IdentityPacket.LookupCachedWeb : IdentityPacket.OpCachedWeb;

            WebCaches.Add(add);
        }