예제 #1
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);
        }
예제 #2
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();
        }