コード例 #1
0
ファイル: CoreManager.cs プロジェクト: supertanglang/Amoeba
        public void UploadMetadata(UnicastMetadata metadata)
        {
            this.Check();

            lock (_lockObject)
            {
                _networkManager.Upload(metadata);
            }
        }
コード例 #2
0
            public bool SetMetadata(UnicastMetadata unicastMetadata)
            {
                using (_lockManager.WriteLock())
                {
                    var now = DateTime.UtcNow;

                    if (unicastMetadata == null ||
                        unicastMetadata.Type == null ||
                        unicastMetadata.Signature == null ||
                        unicastMetadata.Signature.Id == null || unicastMetadata.Signature.Id.Length == 0 ||
                        string.IsNullOrWhiteSpace(unicastMetadata.Signature.Name) ||
                        (unicastMetadata.CreationTime - now).TotalMinutes > 30 ||
                        unicastMetadata.Certificate == null)
                    {
                        return(false);
                    }

                    if (!_unicastMetadatas.TryGetValue(unicastMetadata.Type, out var dic))
                    {
                        dic = new Dictionary <Signature, Dictionary <Signature, HashSet <UnicastMetadata> > >();
                        _unicastMetadatas[unicastMetadata.Type] = dic;
                    }

                    if (!dic.TryGetValue(unicastMetadata.Signature, out var dic2))
                    {
                        dic2 = new Dictionary <Signature, HashSet <UnicastMetadata> >();
                        dic[unicastMetadata.Signature] = dic2;
                    }

                    var signature = unicastMetadata.Certificate.GetSignature();

                    if (!dic2.TryGetValue(signature, out var hashset))
                    {
                        hashset         = new HashSet <UnicastMetadata>();
                        dic2[signature] = hashset;
                    }

                    if (!hashset.Contains(unicastMetadata))
                    {
                        if (!unicastMetadata.VerifyCertificate())
                        {
                            return(false);
                        }

                        hashset.Add(unicastMetadata);
                    }

                    return(true);
                }
            }
コード例 #3
0
        protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int depth)
        {
            using (var reader = new ItemStreamReader(stream, bufferManager))
            {
                while (reader.Available > 0)
                {
                    int id = (int)reader.GetUInt32();

                    if (id == (int)SerializeId.UnicastMetadatas)
                    {
                        for (int i = (int)reader.GetUInt32() - 1; i >= 0; i--)
                        {
                            this.ProtectedUnicastMetadatas.Add(UnicastMetadata.Import(reader.GetStream(), bufferManager));
                        }
                    }
                }
            }
        }