Exemple #1
0
        public bool SetMetadata(MulticastClue MulticastClue)
        {
            lock (_lockObject)
            {
                var now = DateTime.UtcNow;

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

                if (!_MulticastClues.TryGetValue(MulticastClue.Type, out var dic))
                {
                    dic = new Dictionary <Channel, Dictionary <OmniSignature, HashSet <MulticastClue> > >();
                    _MulticastClues[MulticastClue.Type] = dic;
                }

                if (!dic.TryGetValue(MulticastClue.Channel, out var dic2))
                {
                    dic2 = new Dictionary <OmniSignature, HashSet <MulticastClue> >();
                    dic[MulticastClue.Channel] = dic2;
                }

                var signature = MulticastClue.Certificate.GetOmniSignature();

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

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

                    hashset.Add(MulticastClue);
                }

                return(true);
            }
        }
Exemple #2
0
        public static async ValueTask <MulticastClue> Create(string type, Channel channel, Timestamp creationTime, Clue clue, OmniDigitalSignature digitalSignature, int miningLimit, TimeSpan miningTimeout, CancellationToken token)
        {
            OmniHashcash hashcash = null;
            {
                var hub = new Hub();

                try
                {
                    var target = new MulticastClue(type, channel, creationTime, clue, null, null);
                    target.Export(hub.Writer, BufferPool.Shared);
                    hub.Writer.Complete();

                    hashcash = await OmniMiner.Create(hub.Reader.GetSequence(), _utf8Encoding.Value.GetBytes(digitalSignature.GetOmniSignature().ToString()), OmniHashcashAlgorithmType.Sha2_256, miningLimit, miningTimeout, token);

                    hub.Reader.Complete();
                }
                finally
                {
                    hub.Reset();
                }
            }

            {
                var hub = new Hub();

                try
                {
                    var target = new MulticastClue(type, channel, creationTime, clue, hashcash, null);
                    target.Export(hub.Writer, BufferPool.Shared);
                    hub.Writer.Complete();

                    var certificate = OmniCertificate.Create(digitalSignature, hub.Reader.GetSequence());
                    hub.Reader.Complete();

                    return(new MulticastClue(type, channel, creationTime, clue, hashcash, certificate));
                }
                finally
                {
                    hub.Reset();
                }
            }
        }
Exemple #3
0
        public bool VerifyCertificate()
        {
            var hub = new Hub();

            try
            {
                var target = new MulticastClue(this.Type, this.Channel, this.CreationTime, this.Clue, this.Hashcash, null);
                target.Export(hub.Writer, BufferPool.Shared);
                hub.Writer.Complete();

                var result = this.Certificate.Verify(hub.Reader.GetSequence());
                hub.Reader.Complete();

                return(result);
            }
            finally
            {
                hub.Reset();
            }
        }