示例#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);
        }
示例#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();
        }
示例#3
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;
            }
        }