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));
        }
Exemple #2
0
        /// <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;
        }
        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);
        }
Exemple #4
0
 internal LoginForm(LocalObjectStorage localObjectStorage)
 {
     this.localObjectStorage = localObjectStorage;
     InitializeComponent();
 }
        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]);
        }
 internal void EmptyStorage()
 {
     var storage = new LocalObjectStorage(config, node);
     Assert.AreEqual(0, storage.CurrentObjects.Count);
 }
        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);
        }
Exemple #8
0
 internal KyruApplication(ushort port)
 {
     Config = new Config();
     Node = new Node(port, this);
     LocalObjectStorage = new LocalObjectStorage(Config, Node);
 }