コード例 #1
0
ファイル: PeerListing.cs プロジェクト: saluspass/salus-client
        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);
        }
コード例 #2
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);
        }