Beispiel #1
0
        public LocalSync(OpCore core)
        {
            Core = core;
            Network = core.Network;
            Store = Network.Store;
            Core.Sync = this;

            GlobalIM = Core.User.Settings.GlobalIM;

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            Core.Locations.GetTag[ServiceID, DataTypeSync] += new GetLocationTagHandler(Locations_GetTag);
            Core.Locations.TagReceived[ServiceID, DataTypeSync] += new LocationTagReceivedHandler(Locations_TagReceived);

            Store.ReplicateEvent[ServiceID, DataTypeSync] += new ReplicateHandler(Store_Replicate);

            Cache = new VersionedCache(Network, ServiceID, DataTypeSync, true);
            Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired);
            Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved);
            Cache.Load();

            // if sync file for ourselves does not exist create
            if (!Cache.FileMap.SafeContainsKey(Core.UserID))
                UpdateLocal();
        }
Beispiel #2
0
        public BoardService(OpCore core )
        {
            Core       = core;
            Network = Core.Network;
            Protocol = Network.Protocol;
            Store    = Network.Store;
            Trust = Core.Trust;

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.MinuteTimerEvent += Core_MinuteTimer;

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            Store.StoreEvent[ServiceID, 0] += new StoreHandler(Store_Local);
            Store.ReplicateEvent[ServiceID, 0] += new ReplicateHandler(Store_Replicate);
            Store.PatchEvent[ServiceID, 0] += new PatchHandler(Store_Patch);

            Network.Searches.SearchEvent[ServiceID, 0] += new SearchRequestHandler(Search_Local);

            Core.Transfers.FileSearch[ServiceID, 0] += new FileSearchHandler(Transfers_FileSearch);
            Core.Transfers.FileRequest[ServiceID, 0] += new FileRequestHandler(Transfers_FileRequest);

            if (Core.Sim != null)
                PruneSize = 16;

            LocalFileKey = Core.User.Settings.FileKey;

            BoardPath = Core.User.RootPath + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar + ServiceID.ToString();

            if (!Directory.Exists(BoardPath))
                Directory.CreateDirectory(BoardPath);

            // get available board header targets
            string[] directories = Directory.GetDirectories(BoardPath);

            SortedDictionary<ulong, ulong> targets = new SortedDictionary<ulong, ulong>(); // key distance to self, value target

            foreach (string path in directories)
            {
                string dir = Path.GetFileName(path); // gets dir name

                ulong id = BitConverter.ToUInt64(Utilities.FromBase64String(dir), 0);

                targets[Core.UserID ^ id] = id;
            }

            // load closest targets
            int loaded = 0;
            foreach (ulong id in targets.Values)
            {
                LoadHeader(id);

                loaded++;
                if (loaded == PruneSize)
                    break;
            }

            Loading = false;
        }
Beispiel #3
0
        public VersionedCache(DhtNetwork network, uint service, uint type, bool localSync)
        {
            Core    = network.Core;
            Network = network;
            Store   = network.Store;

            Service = service;
            DataType = type;

            LocalSync = localSync;
            GlobalIM = Core.User.Settings.GlobalIM;

            CachePath = Core.User.RootPath + Path.DirectorySeparatorChar +
                        "Data" + Path.DirectorySeparatorChar +
                        Service.ToString() + Path.DirectorySeparatorChar +
                        DataType.ToString();

            HeaderPath = CachePath + Path.DirectorySeparatorChar + Utilities.CryptFilename(Core, "VersionedFileHeaders");

            Directory.CreateDirectory(CachePath);

            LocalKey = Core.User.Settings.FileKey;

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.MinuteTimerEvent += Core_MinuteTimer;

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            Store.StoreEvent[Service, DataType] += new StoreHandler(Store_Local);

            // if local sync used then it will handle all replication
            if (LocalSync && !GlobalIM)
            {
                Store.ReplicateEvent[Service, DataType] += new ReplicateHandler(Store_Replicate);
                Store.PatchEvent[Service, DataType] += new PatchHandler(Store_Patch);
            }

            Network.Searches.SearchEvent[Service, DataType] += new SearchRequestHandler(Search_Local);

            Core.Transfers.FileSearch[Service, DataType] += new FileSearchHandler(Transfers_FileSearch);
            Core.Transfers.FileRequest[Service, DataType] += new FileRequestHandler(Transfers_FileRequest);

            if (!LocalSync)
            {
                Core.Sync.GetTag[Service, DataType] += new GetLocalSyncTagHandler(LocalSync_GetTag);
                Core.Sync.TagReceived[Service, DataType] += new LocalSyncTagReceivedHandler(LocalSync_TagReceived);
            }

            if (Core.Sim != null)
                PruneSize = 16;
        }
Beispiel #4
0
        public DhtNetwork(OpCore core, bool lookup)
        {
            Core     = core;
            IsLookup = lookup;

            Cache = new OpCache(this); // lookup config loads cache entries

            if (IsLookup)
            {
                Core.Context.LookupConfig.Load(this);
                Lookup = Core.Context.LookupConfig;
            }

            Local          = new DhtClient();
            Local.UserID   = IsLookup ? Lookup.Ports.UserID : Utilities.KeytoID(Core.User.Settings.KeyPublic);
            Local.ClientID = (ushort)Core.RndGen.Next(1, ushort.MaxValue);

            OpID = Utilities.KeytoID(IsLookup ? LookupKey : Core.User.Settings.OpKey);

            OpCrypt = new RijndaelManaged();

            // load encryption
            if (IsLookup)
            {
                OpCrypt.Key = LookupKey;
            }
            else
            {
                OpCrypt.Key = Core.User.Settings.OpKey;
            }

            LocalAugmentedKey = GetAugmentedKey(Local.UserID);

            Protocol    = new G2Protocol();
            TcpControl  = new TcpHandler(this);
            UdpControl  = new UdpHandler(this);
            LanControl  = new LanHandler(this);
            RudpControl = new RudpHandler(this);
            LightComm   = new LightCommHandler(this);
            UPnPControl = new UPnPHandler(this);

            Routing  = new DhtRouting(this);
            Store    = new DhtStore(this);
            Searches = new DhtSearchControl(this);
        }
Beispiel #5
0
        public TrustService(OpCore core)
        {
            Core = core;
            Core.Trust = this;

            Store = Core.Network.Store;
            Network = Core.Network;

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.MinuteTimerEvent += Core_MinuteTimer;
            Core.KeepDataCore += new KeepDataHandler(Core_KeepData);

            Cache = new VersionedCache(Network, ServiceID, DataTypeFile, false);

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            // piggyback searching for uplink requests on cache file data
            Store.StoreEvent[ServiceID, DataTypeFile] += new StoreHandler(Store_Local);
            Network.Searches.SearchEvent[ServiceID, DataTypeFile] += new SearchRequestHandler(Search_Local);

            Core.Locations.KnowOnline += new KnowOnlineHandler(Location_KnowOnline);

            Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired);
            Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved);
            Cache.Load();

            ProjectNames.SafeAdd(0, Core.User.Settings.Operation);

            LinkPath = Core.User.RootPath + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar + ServiceID.ToString();
            Directory.CreateDirectory(LinkPath);

            LocalFileKey = Core.User.Settings.FileKey;

            LoadUplinkReqs();

            LocalTrust = GetTrust(Core.UserID);

            if (LocalTrust == null)
            {
                LocalTrust = new OpTrust(new OpVersionedFile(Core.User.Settings.KeyPublic));
                TrustMap.SafeAdd(Core.UserID, LocalTrust);
            }

            if (!LocalTrust.Loaded)
            {
                LocalTrust.Name = Core.User.Settings.UserName;
                LocalTrust.AddProject(0, true); // operation

                SaveLocal();
            }
        }
Beispiel #6
0
        public DhtNetwork(OpCore core, bool lookup)
        {
            Core = core;
            IsLookup = lookup;

            Cache = new OpCache(this); // lookup config loads cache entries

            if (IsLookup)
            {
                Core.Context.LookupConfig.Load(this);
                Lookup = Core.Context.LookupConfig;
            }

            Local = new DhtClient();
            Local.UserID = IsLookup ? Lookup.Ports.UserID : Utilities.KeytoID(Core.User.Settings.KeyPublic);
            Local.ClientID = (ushort)Core.RndGen.Next(1, ushort.MaxValue);

            OpID = Utilities.KeytoID(IsLookup ? LookupKey : Core.User.Settings.OpKey);

            OpCrypt = new RijndaelManaged();

            // load encryption
            if (IsLookup)
                OpCrypt.Key = LookupKey;
            else
                OpCrypt.Key = Core.User.Settings.OpKey;

            LocalAugmentedKey = GetAugmentedKey(Local.UserID);

            Protocol = new G2Protocol();
            TcpControl = new TcpHandler(this);
            UdpControl = new UdpHandler(this);
            LanControl = new LanHandler(this);
            RudpControl = new RudpHandler(this);
            LightComm = new LightCommHandler(this);
            UPnPControl = new UPnPHandler(this);

            Routing = new DhtRouting(this);
            Store = new DhtStore(this);
            Searches = new DhtSearchControl(this);
        }
Beispiel #7
0
        public StorageService(OpCore core)
        {
            Core = core;
            Network = core.Network;
            Protocol = Network.Protocol;
            Store = Network.Store;
            Trust = Core.Trust;

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.MinuteTimerEvent += Core_MinuteTimer;

            Network.CoreStatusChange += new StatusChange(Network_StatusChange);

            Core.Transfers.FileSearch[ServiceID, FileTypeData] += new FileSearchHandler(Transfers_DataFileSearch);
            Core.Transfers.FileRequest[ServiceID, FileTypeData] += new FileRequestHandler(Transfers_DataFileRequest);

            Core.Trust.LinkUpdate += new LinkUpdateHandler(Trust_Update);

            LocalFileKey = Core.User.Settings.FileKey;
            FileCrypt.Key = LocalFileKey;
            FileCrypt.IV = new byte[FileCrypt.IV.Length];

            string rootpath = Core.User.RootPath + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar + ServiceID.ToString() + Path.DirectorySeparatorChar;
            DataPath = rootpath + FileTypeData.ToString();
            WorkingPath = rootpath + FileTypeWorking.ToString();
            ResourcePath = rootpath + FileTypeResource.ToString();

            Directory.CreateDirectory(DataPath);
            Directory.CreateDirectory(WorkingPath);

            // clear resource files so that updates of these files work
            if (Directory.Exists(ResourcePath))
                Directory.Delete(ResourcePath, true);

            Cache = new VersionedCache(Network, ServiceID, FileTypeCache, false);

            Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired);
            Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved);
            Cache.Load();

            // load working headers
            OpStorage local = GetStorage(Core.UserID);

            foreach (uint project in Trust.LocalTrust.Links.Keys)
            {
                if (local != null)
                    LoadHeaderFile(GetWorkingPath(project), local, false, true);

                Working[project] = new WorkingStorage(this, project);

                bool doSave = false;
                foreach (ulong higher in Trust.GetAutoInheritIDs(Core.UserID, project))
                    if (Working[project].RefreshHigherChanges(higher))
                        doSave = true;

                Working[project].AutoIntegrate(doSave);
            }

            foreach (string testPath in Directory.GetFiles(DataPath))
                if (!ReferencedPaths.Contains(testPath))
                    try { File.Delete(testPath); }
                    catch { }

            ReferencedPaths.Clear();
            Loading = false;
        }
Beispiel #8
0
        int SaveInterval = 60*10; // 10 min stagger, prevent cascade up

        #endregion Fields

        #region Constructors

        public PlanService(OpCore core)
        {
            Core = core;
            Network = core.Network;
            Protocol = Network.Protocol;
            Store = Network.Store;
            Trust = Core.Trust;

            if (Core.Sim != null)
                SaveInterval = 30;

            Core.SecondTimerEvent += Core_SecondTimer;

            Cache = new VersionedCache(Network, ServiceID, DataTypeFile, false);

            Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired);
            Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved);
            Cache.Load();

            if (!PlanMap.SafeContainsKey(Core.UserID))
            {
                LocalPlan = new OpPlan(new OpVersionedFile(Core.User.Settings.KeyPublic));
                LocalPlan.Init();
                LocalPlan.Loaded = true;
                PlanMap.SafeAdd(Core.UserID, LocalPlan);
            }
        }