コード例 #1
0
        internal void GetObjectNotPresent()
        {
            var storage = new LocalObjectStorage(config, node);

            var user = new User();
            user.ObjectId = KademliaId.RandomId;
            user.Add(new UserFile { ChunkList = new List<byte[]> { KademliaId.RandomId } });

            storage.StoreObject(user, false);

            Assert.IsNull(storage.GetObject(KademliaId.RandomId));
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: zr40/kyru-dotnet
        /// <summary>
        /// Constructor of Session class for a new User
        /// </summary>
        /// <param name="username">Username of the user</param>
        /// <param name="password">Password of the user</param>
        /// <param name="localObjectStorage">LocalObjectStorage</param>
        internal Session(string username, string password, LocalObjectStorage localObjectStorage)
        {
            LocalObjectStorage = localObjectStorage;

            rsaKeyPair = Crypto.DeriveRsaKey(Encoding.UTF8.GetBytes(username), Encoding.UTF8.GetBytes(password));

            KademliaId id = Crypto.Hash(rsaKeyPair.Public);

            Username = username;
            User = localObjectStorage.GetObject(id) as User;
            if (User == null)
            {
                User = new User(rsaKeyPair.Public) {ObjectId = id};
                localObjectStorage.StoreObject(User, true);
            }

            onUserUpdated = UpdateUser;
            localObjectStorage.OnUserUpdated += onUserUpdated;
        }
コード例 #3
0
        internal void GetObject()
        {
            var storage = new LocalObjectStorage(config, node);

            var randomId = KademliaId.RandomId;
            ulong fileId = 123456789;
            var id = KademliaId.RandomId;

            var user = new User();
            user.ObjectId = id;
            user.Add(new UserFile { FileId = fileId, ChunkList = new List<byte[]> { randomId } });

            storage.StoreObject(user, false);

            var readUser = storage.GetObject(id) as User;
            Assert.AreEqual(1, readUser.Files.Count);
            Assert.AreEqual(0, readUser.DeletedFiles.Count);

            var userFile = readUser.Files[0];
            Assert.AreEqual(1, userFile.ChunkList.Count);
            Assert.AreEqual(randomId, (KademliaId)userFile.ChunkList[0]);
            Assert.AreEqual(fileId, userFile.FileId);
        }
コード例 #4
0
ファイル: LoginForm.cs プロジェクト: zr40/kyru-dotnet
 internal LoginForm(LocalObjectStorage localObjectStorage)
 {
     this.localObjectStorage = localObjectStorage;
     InitializeComponent();
 }
コード例 #5
0
        internal void Initialization()
        {
            var storage = new LocalObjectStorage(config, node);

            var user = new User();
            user.ObjectId = KademliaId.RandomId;
            user.Add(new UserFile {ChunkList = new List<byte[]> {KademliaId.RandomId}});
            storage.StoreObject(user, false);

            storage = new LocalObjectStorage(config, node);

            Assert.AreEqual(1, storage.CurrentObjects.Count);
            Assert.AreEqual(user.ObjectId, storage.CurrentObjects[0]);
        }
コード例 #6
0
 internal void EmptyStorage()
 {
     var storage = new LocalObjectStorage(config, node);
     Assert.AreEqual(0, storage.CurrentObjects.Count);
 }
コード例 #7
0
        internal void StoreObject()
        {
            var storage = new LocalObjectStorage(config, node);

            var user = new User();
            user.ObjectId = KademliaId.RandomId;

            storage.StoreObject(user, false);
            Assert.AreEqual(1, storage.CurrentObjects.Count);

            storage.StoreObject(user, false);
            Assert.AreEqual(1, storage.CurrentObjects.Count);

            user.ObjectId = KademliaId.RandomId;
            storage.StoreObject(user, false);
            Assert.AreEqual(2, storage.CurrentObjects.Count);
        }
コード例 #8
0
ファイル: KyruApplication.cs プロジェクト: zr40/kyru-dotnet
 internal KyruApplication(ushort port)
 {
     Config = new Config();
     Node = new Node(port, this);
     LocalObjectStorage = new LocalObjectStorage(Config, Node);
 }