Example #1
0
        public CacheListViewItem(Key key)
        {
            this.Category = key.Cache_Category;
            this.CreationTime = key.Cache_CreationTime;
            this.Hash = key.Cache_Hash;
            this.Name = key.Cache_FileName;
            this.Sign = key.Cache_Sign;
            this.Signature = key.Signature;
            this.Signature_SHA1 = key.Signature_SHA1;
            this.SignatureHash = key.Cache_SignatureHash;
            this.Size = key.Cache_Size;
            this.CacheBlockLength = key.CacheBlockBitmap.Length;
            this.PublicKey = key.PublicKey;

            this.UploadBlockBitmap = new bool[this.CacheBlockLength];

            this.Key = key;
        }
Example #2
0
        public void Store(Key[] item)
        {
            DebugWrite(this, "FileShareService.Store:キー情報を受信しました");

            if (item == null) return;

            Settings.Default._keyController.AddRange(item);
            Settings.Default._routeTable.AddRange(item.Select(n => n.FileLocation).ToArray());
        }
Example #3
0
File: Key.cs Project: asapo/Profes
        /// <summary>
        /// Keyを追加します
        /// </summary>
        public void Add(Key item)
        {
            if (item == null) return;
            if (item.FileLocation == null) return;
            if (!Verification.VerificationIPAddress(item.FileLocation.Endpoint)) return;
            if (!item.VerifyDigitalSignature()) return;

            var t = DateTime.Now - item.KeyCreateTime;
            if (t.Hours < 1 && t.Ticks >= 0)
            {
                string stringHash = BinaryEditor.BytesToHexString(item.Hash);
                string stringSignatureHash = BinaryEditor.BytesToHexString(item.Cache_SignatureHash);

                AddedNew(this, item);

                lock (_keyDic)
                {
                    if (!_keyDic.ContainsKey(stringHash))
                    {
                        _keyDic.Add(stringHash, item);
                    }
                    else
                    {
                        if (_keyDic[stringHash].KeyCreateTime < item.KeyCreateTime)
                        {
                            _keyDic[stringHash] = item;
                        }
                    }
                }

                lock (_reviewDic)
                {
                    if (item.Review != null && item.Review.Review != Review.なし &&
                        item.Review.ReviewComments != null && item.Review.ReviewComments.Trim() != "")
                    {
                        if (!_reviewDic.ContainsKey(stringSignatureHash))
                        {
                            _reviewDic[stringSignatureHash] = new List<CacheReview>();
                        }
                        if (!_reviewDic[stringSignatureHash].Any(n => BinaryEditor.ArrayEquals(n.SignatureHash, item.Review.SignatureHash)))
                        {
                            _reviewDic[stringSignatureHash].RemoveAll(n => n.PublicKey == item.PublicKey);
                            _reviewDic[stringSignatureHash].Add(item.Review);
                        }
                    }
                }
            }
        }
Example #4
0
        void _keyController_AddedNew(object sender, Key e)
        {
            if (BinaryEditor.ArrayEquals(e.FileLocation.NodeID, Settings.Default._routeTable.MyNode.NodeID)) return;

            string stringHash = BinaryEditor.BytesToHexString(e.FileLocation.NodeID) + BinaryEditor.BytesToHexString(e.Cache_Hash);
            bool flag;

            if (_rewriteDic.ContainsKey(stringHash))
            {
                flag = _rewriteDic[stringHash];
            }
            else
            {
                try
                {
                    if (((double)_rewriteDic.Values.Count(n => n == true) / (double)_rewriteDic.Values.Count()) * 100 < 30)
                    {
                        _rewriteDic.Add(stringHash, true);
                        flag = true;
                    }
                    else
                    {
                        _rewriteDic.Add(stringHash, false);
                        flag = false;
                    }
                }
                catch (DivideByZeroException)
                {
                    _rewriteDic.Add(stringHash, true);
                    flag = true;
                }
            }

            if (flag == true)
            {
                Key CloneKey = Clone.DeepCopyClone<Key>(e);
                CloneKey.FileLocation = Settings.Default._routeTable.MyNode;

                Settings.Default._keyController.Add(CloneKey);
            }
        }