Exemplo n.º 1
0
 public async Task Install()
 {
     foreach (Peer peer in _Servers)
     {
         await IpfsApiWrapper.AddPeer(peer);
     }
 }
Exemplo n.º 2
0
        private void OnApplicationStartup()
        {
            IpfsApiWrapper.StartDaemon();
            SetupBootstrapServers();

            RestServer a = new RestServer();

            a.Start();

            AutoUpdater.Launch();

            MainWindow mainWindow = new MainWindow();

            if (!FirstRunViewModel.WasCompleted())
            {
                FirstRunView dialog = new FirstRunView();
                if (dialog.ShowDialog() != true)
                {
                    mainWindow = null;
                    Shutdown();
                }
            }

            mainWindow?.Show();
        }
Exemplo n.º 3
0
        private async void OnNewAccount()
        {
            if (!Directory.Exists(FileSystemConstants.IpfsConfigFolder))
            {
                InitIfps();
            }

            if (!File.Exists(Path.Combine(FileSystemConstants.PswmgrConfigFolder, "private.pem")))
            {
                using (EncryptionKey key = EncryptionKey.Generate())
                {
                    key.Export();
                }
            }

            if (!File.Exists(Path.Combine(FileSystemConstants.IpfsConfigFolder, "keystore", "salus")))
            {
                await IpfsApiWrapper.GenerateKeyPair("salus");
            }

            if (WasCompleted())
            {
                MessageBox.Show("Creation successful!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                OnAccountConfigued();
            }
            else
            {
                MessageBox.Show("There was an error creating the necessary files", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 4
0
        public static async Task <PeerListing> Load()
        {
            PeerListing returnValue = new PeerListing();

            try
            {
                string filenameHashIpnsEntry = await IpfsApiWrapper.GetAdditionalInformation("salus");

                string listingFileHash = await IpfsApiWrapper.ResolveAsync(filenameHashIpnsEntry);

                if (!string.IsNullOrEmpty(listingFileHash) && await IpfsApiWrapper.Get(listingFileHash, Path.Combine(FileSystemConstants.PswmgrConfigFolder, "peers.json")))
                {
                    using (StreamReader reader = new StreamReader(File.OpenRead(ListingFilename)))
                    {
                        string json = reader.ReadToEnd();
                        returnValue = JsonConvert.DeserializeObject <PeerListing>(json);
                    }
                }

                returnValue.Dirty = false;
            }
            catch
            {
            }

            await returnValue.Sync();

            return(returnValue);
        }
Exemplo n.º 5
0
        public static async Task <IpfsFileListing> Load()
        {
            IpfsFileListing returnValue = new IpfsFileListing();

            try
            {
                //Load the file listing if we have one locally
                if (File.Exists(ListingFilename))
                {
                    using (StreamReader reader = new StreamReader(File.OpenRead(ListingFilename)))
                    {
                        string json = reader.ReadToEnd();
                        returnValue = JsonConvert.DeserializeObject <IpfsFileListing>(json);
                    }
                }

                string localPeerId = IpfsApiWrapper.GetPeerId();

                //Validate that the local file matches the remote file

                /*{
                 *  string listingFileHash = await IpfsApiWrapper.ResolveAsync(localPeerId);
                 *  IpfsFileListing remoteFileListing = await FetchListingFile(listingFileHash, false);
                 *  if (remoteFileListing != returnValue)
                 *  {
                 *      returnValue.Dirty = true;
                 *  }
                 * }*/

                PeerListing peerListing = await IpfsApiWrapper.GetPeerListingAsync();

                foreach (string peer in peerListing.Peers)
                {
                    IpfsFileListing peerFileListing = null;
                    if (peer != localPeerId)
                    {
                        string listingFileHash = await IpfsApiWrapper.ResolveAsync(peer);

                        peerFileListing = await FetchListingFile(listingFileHash, false);
                    }
                    else if (File.Exists(ListingFilename))
                    {
                        string listingFileHash = await IpfsApiWrapper.ResolveAsync();

                        peerFileListing = await FetchListingFile(listingFileHash, true);
                    }

                    returnValue.MergeFile(peerFileListing);
                }
            }
            catch
            {
            }

            await returnValue.Sync();

            return(returnValue);
        }
Exemplo n.º 6
0
        private async void SyncIpfsListing()
        {
            Status = "Synching with Network...";
            await IpfsApiWrapper.GetPeerListingAsync();

            await IpfsApiWrapper.GetFileListingAsync();

            Status = "Up to date";
        }
Exemplo n.º 7
0
        private async Task Sync()
        {
            _FilenameHash = await IpfsApiWrapper.GetAdditionalInformation("salus");

            string peerId = IpfsApiWrapper.GetPeerId();

            if (!_Peers.Contains(peerId))
            {
                _Peers.Add(peerId);
                Dirty = true;
            }

            await Save();
        }
Exemplo n.º 8
0
        public async Task Save()
        {
            if (Dirty)
            {
                using (StreamWriter writer = new StreamWriter(ListingFilename))
                {
                    writer.Write(JsonConvert.SerializeObject(this, Formatting.Indented));
                }

                string hashFilename = await IpfsApiWrapper.AddAsync(ListingFilename);

                await IpfsApiWrapper.PublishAsync(hashFilename);

                Dirty = false;
            }
        }
Exemplo n.º 9
0
 private async Task ProcessRemoteFileList()
 {
     await ForEachAsync(_Files, async delegate(IpfsFile file)
     {
         string filename = Path.Combine(FileSystemConstants.PswmgrDataFolder, Path.ChangeExtension(file.LocalFilename, ".json"));
         if (File.Exists(filename))
         {
             ResolveConflict(file.LocalFilename, filename);
         }
         else
         {
             await IpfsApiWrapper.Get(file.RemoteFilename, filename);
             PasswordEntryManager.Instance.AddEntry(PasswordEntry.Load(filename));
         }
     });
 }
Exemplo n.º 10
0
        private async Task AddFileNotAlreadyExisting(string filename, object lockObject)
        {
            string hashFilename = await IpfsApiWrapper.AddAsync(filename);

            IpfsFile file = new IpfsFile
            {
                LocalFilename  = filename,
                RemoteFilename = hashFilename
            };

            file.ComputerAndStoreHash(filename);
            lock (lockObject)
            {
                Dirty = true;
                _Files.Add(file);
            }
        }
Exemplo n.º 11
0
        public async Task Save()
        {
            if (Dirty)
            {
                using (StreamWriter writer = new StreamWriter(ListingFilename))
                {
                    writer.Write(JsonConvert.SerializeObject(this, Formatting.Indented));
                }

                string hashFilename = await IpfsApiWrapper.AddAsync(ListingFilename);

                string filenameHashIpnsEntry = await IpfsApiWrapper.GetAdditionalInformation("salus");

                await IpfsApiWrapper.PublishAsync(hashFilename, filenameHashIpnsEntry);

                Dirty = false;
            }
        }
Exemplo n.º 12
0
        private static async Task <IpfsFileListing> FetchListingFile(string listingFileHash, bool keep = false)
        {
            IpfsFileListing returnValue = null;

            try
            {
                string localListingFilename = keep ? ListingFilename : Path.GetTempFileName();
                if (!string.IsNullOrEmpty(listingFileHash) && await IpfsApiWrapper.Get(listingFileHash, localListingFilename))
                {
                    using (StreamReader reader = new StreamReader(File.OpenRead(localListingFilename)))
                    {
                        string json = reader.ReadToEnd();
                        returnValue = JsonConvert.DeserializeObject <IpfsFileListing>(json);
                    }
                }
            }
            catch
            {
                //In case the peer's file hasn't yet been published to ipns
            }
            returnValue.Dirty = false;
            return(returnValue);
        }
Exemplo n.º 13
0
        protected override void OnExit(ExitEventArgs e)
        {
            IpfsApiWrapper.StopDaemon();

            base.OnExit(e);
        }
Exemplo n.º 14
0
 protected void OnAccountConfigued()
 {
     IpfsApiWrapper.StartDaemon();
     AccountConfigued?.Invoke(this, EventArgs.Empty);
 }