Ejemplo n.º 1
0
        public void SimCleanup()
        {
            FileMap.SafeClear();
            InternalFileMap.SafeClear();

            WorkingStorage x = Working[0];

            StorageFolder packet = new StorageFolder();

            packet.Name  = Core.Trust.GetProjectName(0) + " Files";
            x.RootFolder = new LocalFolder(null, packet);

            SaveLocal(0);
        }
Ejemplo n.º 2
0
        private void Cache_FileAquired(OpVersionedFile file)
        {
            if (file.UserID != Network.Local.UserID)
            {
                return;
            }

            // only we can open the buddly list stored on the network
            byte[] key = Core.User.Settings.KeyPair.Decrypt(file.Header.FileKey, false);

            using (TaggedStream tagged = new TaggedStream(Cache.GetFilePath(file.Header), Network.Protocol))
                using (IVCryptoStream crypto = IVCryptoStream.Load(tagged, key))
                {
                    BuddyList.SafeClear();

                    PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                    G2Header root = null;

                    while (stream.ReadPacket(ref root))
                    {
                        if (root.Name == BuddyPacket.Buddy)
                        {
                            OpBuddy buddy = OpBuddy.Decode(root);
                            ulong   id    = Utilities.KeytoID(buddy.Key);

                            Core.IndexKey(id, ref buddy.Key);
                            Core.IndexName(id, buddy.Name);

                            if (buddy.Ignored)
                            {
                                IgnoreList.SafeAdd(id, buddy);
                            }
                            else
                            {
                                BuddyList.SafeAdd(id, buddy);
                            }
                        }
                    }
                }

            Core.RunInGuiThread(GuiUpdate);
        }
Ejemplo n.º 3
0
        public void SecondTimer()
        {
            if (InvokeRequired)
            {
                RunTimer = true;
                ProcessEvent.Set();
                return;
            }

            try
            {
                // networks
                Network.SecondTimer();

                if (SecondTimerEvent != null)
                {
                    SecondTimerEvent.Invoke();
                }

                // service bandwidth
                foreach (BandwidthLog buffer in ServiceBandwidth.Values)
                {
                    buffer.NextSecond();
                }

                // before minute timer give gui 2 secs to tell us of nodes it doesnt want removed
                if (KeepDataCore != null && MinuteCounter == 58)
                {
                    KeepData.SafeClear();

                    KeepDataCore.Invoke();
                    RunInGuiThread(KeepDataGui);
                }


                MinuteCounter++;

                if (MinuteCounter == 60)
                {
                    MinuteCounter = 0;

                    if (MinuteTimerEvent != null)
                    {
                        MinuteTimerEvent.Invoke();
                    }

                    // prune keys from keymap - dont remove focused, remove furthest first
                    if (KeyMap.Count > KeyMax)
                    {
                        foreach (ulong user in (from id in KeyMap.Keys
                                                where !KeepData.SafeContainsKey(id) &&
                                                !Network.RudpControl.SessionMap.Values.Any(socket => socket.UserID == id) &&
                                                !Network.TcpControl.SocketList.Any(socket => socket.UserID == id)
                                                orderby Network.Local.UserID ^ id descending
                                                select id).Take(KeyMap.Count - KeyMax).ToArray())
                        {
                            KeyMap.Remove(user);
                            if (NameMap.SafeContainsKey(user))
                            {
                                NameMap.SafeRemove(user);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleLog("Exception OpCore::SecondTimer_Tick: " + ex.Message);
            }
        }