Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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));
         }
     });
 }
Ejemplo n.º 3
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);
        }