Exemplo n.º 1
0
        public static void TestOperationGETDoesNotFail()
        {
            _provider.PutAsset(_asset);

            Assert.DoesNotThrow(() => {
                _provider.GetAsset(_asset.Uuid);
            }, "Failed to retreive the asset just stored.");
        }
        private static void RunCompare(RemoteServer server1, RemoteServer server2)
        {
            MD5 md5 = MD5.Create();

            for (int i = 0; i <= 0xFFF; i++)
            {
                string   ids      = server1.GetAssetIds(i.ToString("X3"));
                string[] splitIds = ids.Split(',');

                foreach (string id in splitIds)
                {
                    if (id == "")
                    {
                        continue;
                    }

                    Asset a = server1.GetAsset(id);
                    Asset b = server2.GetAsset(id);

                    string hashA = GetMd5Hash(md5, a.Data);
                    string hashB = GetMd5Hash(md5, b.Data);

                    if (hashA != hashB)
                    {
                        Console.WriteLine("Fail: {0} != {1}");
                    }
                }
            }
        }
Exemplo n.º 3
0
        static void CopyAsset(string uuid, RemoteServer src, RemoteServer dst)
        {
            lock (Conn)
            {
                using (SQLiteCommand countCmd = new SQLiteCommand("SELECT COUNT(*) FROM copied_assets WHERE uuid = '" + uuid + "'", Conn))
                {
                    int count = Convert.ToInt32(countCmd.ExecuteScalar());

                    if (count != 0)
                    {
                        Console.WriteLine("Skipping {0}", uuid);
                        return;
                    }
                }
            }

            Console.WriteLine("Copying {0} ({1})", uuid, NumCopied);

            try
            {
                Asset asset = src.GetAsset(uuid);
                dst.PutAsset(asset);

                lock (Conn)
                {
                    using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO copied_assets(uuid) VALUES('" + uuid + "');", Conn))
                    {
                        cmd.ExecuteNonQuery();

                        NumCopied++;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to copy asset: " + e.Message);
                using (StreamWriter writer = new StreamWriter("error.txt"))
                {
                    writer.WriteLine("Unable to copy asset: " + e.Message);
                    writer.Close();
                }

                Console.WriteLine("Error detected, any key continues");
                Console.ReadLine();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles an incoming request for an asset from the remote server.
        /// </summary>
        /// <returns>The asset or null if not found.</returns>
        /// <param name="assetID">Asset identifier.</param>
        public StratusAsset RequestAssetSync(Guid assetID)
        {
            Asset whipAsset = null;

            try {
                whipAsset = _provider.GetAsset(assetID.ToString());
            }
            catch (AssetServerError e) {
                LOG.Log(Logging.LogLevel.Error, () => $"[{_serverHandle}] Error getting asset from server.", e);
                return(null);
            }
            catch (AuthException e) {
                LOG.Log(Logging.LogLevel.Error, () => $"[{_serverHandle}] Authentication error getting asset from server.", e);
                return(null);
            }

            return(StratusAsset.FromWHIPAsset(whipAsset));
        }
Exemplo n.º 5
0
        public void ThreadProc(Object obj)
        {
            int    threadIdx = (int)obj;
            Random random    = new Random();

            //run 20,000 iterations of reads and writes
            for (int i = 0; i < 20000; i++)
            {
                if (i % 100 == 0)
                {
                    Console.WriteLine("Thread " + threadIdx + " is making progress " + i);
                }

                if (random.NextDouble() > 0.97)
                {
                    this.SingleWrite();
                    this.SingleAsyncRead(random);
                }
                else
                {
                    SHA1 sha = new SHA1CryptoServiceProvider();

                    //read an existing asset and check the data hash
                    int index = (int)Math.Floor(_assetUuids.Count * random.NextDouble());

                    Asset  a    = _server.GetAsset(_assetUuids[index]);
                    byte[] hash = sha.ComputeHash(a.Data);
                    if (!TestUtil.Test.test(hash, _existingAssets[_assetUuids[index]]))
                    {
                        Console.WriteLine("Mismatched hash on " + _assetUuids[index]);
                        Console.WriteLine("Got " + Util.HashToHex(hash) + " expected " + Util.HashToHex(_existingAssets[_assetUuids[index]]));

                        ASCIIEncoding encoding = new ASCIIEncoding();

                        Console.WriteLine("Data " + encoding.GetString(a.Data));
                    }
                }
            }

            Console.WriteLine("Thread " + threadIdx + " has finished");
        }
        static void ExecCmd(RemoteServer server, string cmd)
        {
            if (cmd == "iwim_heartbeat")
            {
                Socket sendSocket = new Socket(AddressFamily.InterNetwork,
                                               SocketType.Dgram, ProtocolType.Udp);

                sendSocket.Bind(new IPEndPoint(IPAddress.Any, 32702));

                Console.WriteLine("Sending heartbeat to server");
                IPAddress  sendTo       = Dns.GetHostAddresses(server.HostName)[0];
                IPEndPoint sendEndPoint = new IPEndPoint(sendTo, 32701);


                byte[] buffer = new byte[5];
                buffer[0] = 2;
                buffer[1] = 0xFF;
                buffer[2] = 0xFF;
                buffer[3] = 0xFF;
                buffer[4] = 0xFF;

                sendSocket.SendTo(buffer, 5, SocketFlags.None, sendEndPoint);
                sendSocket.Close();
            }

            if (cmd == "iwim_query_random" || cmd == "iwim_query_random_loop")
            {
                Socket sendSocket = new Socket(AddressFamily.InterNetwork,
                                               SocketType.Dgram, ProtocolType.Udp);

                int loops;

                if (cmd == "iwim_query_random")
                {
                    loops = 1;
                }
                else
                {
                    loops = 1000;
                }

                Console.WriteLine("Searching for {0} random assets starting {1}", loops, DateTime.Now);
                IPAddress  sendTo       = Dns.GetHostAddresses(server.HostName)[0];
                IPEndPoint sendEndPoint = new IPEndPoint(sendTo, 32701);
                byte[]     buffer       = new byte[33];
                buffer[0] = 0;

                for (int i = 0; i < loops; i++)
                {
                    Guid   guid  = Guid.NewGuid();
                    string fguid = guid.ToString().Replace("-", "");
                    Array.Copy(Util.UuidToAscii(fguid), 0, buffer, 1, 32);

                    sendSocket.SendTo(buffer, 33, SocketFlags.None, sendEndPoint);

                    EndPoint recvEndpoint = new IPEndPoint(IPAddress.Any, sendEndPoint.Port);
                    byte[]   response     = new byte[34];
                    sendSocket.ReceiveFrom(response, ref recvEndpoint);
                }

                Console.WriteLine("Done {0}", DateTime.Now);
            }

            if (cmd.Length > 10 && cmd.Substring(0, 10) == "iwim_query")
            {
                string uuid = cmd.Substring(11);

                Console.WriteLine("Asking for named asset " + uuid);
                server.GetAsset(uuid);
            }

            if (cmd == "getrandom")
            {
                Guid guid = Guid.NewGuid();
                Console.WriteLine("Asking for random asset " + guid.ToString());
                server.GetAsset(guid.ToString());
            }

            if (cmd.Length > 11 && cmd.Substring(0, 11) == "randomforce")
            {
                string begUUID = cmd.Substring(12);
                Guid   guid    = Guid.NewGuid();
                string newGuid = guid.ToString();
                newGuid = begUUID + newGuid.Substring(3);

                Console.WriteLine("Asking for semirandom asset " + newGuid);
                server.GetAsset(newGuid);
            }

            if (cmd.Length > 10 && cmd.Substring(0, 10) == "srandomput")
            {
                string begUUID = cmd.Substring(11);
                Guid   guid    = Guid.NewGuid();
                string newGuid = guid.ToString();
                newGuid = begUUID + newGuid.Substring(3);

                Console.WriteLine("Putting semirandom asset " + newGuid);

                Asset asset = new Asset(newGuid, 1,
                                        false, false, 0, "Random Asset", "Radom Asset Desc", TestUtil.RandomBytes());
                server.PutAsset(asset);
            }

            if (cmd.Length > 6 && cmd.Substring(0, 6) == "getone")
            {
                string uuid = cmd.Substring(7);

                Console.WriteLine("Asking for named asset " + uuid);
                Asset asset = server.GetAsset(uuid);

                using (System.IO.FileStream outstream = System.IO.File.OpenWrite("asset.txt"))
                {
                    outstream.Write(asset.Data, 0, asset.Data.Length);
                    outstream.Close();
                }
            }

            if (cmd == "put")
            {
                Console.WriteLine("Putting 1000 random assets to server");
                Console.WriteLine(DateTime.Now);
                for (int i = 0; i < 1000; i++)
                {
                    Asset asset = new Asset(OpenMetaverse.UUID.Random().ToString(), 1,
                                            false, false, 0, "Random Asset", "Radom Asset Desc", TestUtil.RandomBytes());
                    server.PutAsset(asset);
                }
                Console.WriteLine("Done: " + DateTime.Now);
            }

            if (cmd == "putone")
            {
                string uuid = OpenMetaverse.UUID.Random().ToString();
                _lastRandom = uuid;

                Console.WriteLine("Putting 1 random asset to server");
                Console.WriteLine(uuid);
                Console.WriteLine(DateTime.Now);

                Asset asset = new Asset(uuid, 1,
                                        false, false, 0, "Random Asset", "Radom Asset Desc", TestUtil.RandomBytes());
                server.PutAsset(asset);

                Console.WriteLine("Done: " + DateTime.Now);
            }

            if (cmd == "repeatput")
            {
                Console.WriteLine("Reputting random asset to server");
                Console.WriteLine(_lastRandom);
                Console.WriteLine(DateTime.Now);

                Asset asset = new Asset(_lastRandom, 1,
                                        false, false, 0, "Random Asset", "Radom Asset Desc", TestUtil.RandomBytes());
                server.PutAsset(asset);

                Console.WriteLine("Done: " + DateTime.Now);
            }

            if (cmd == "verify")
            {
                Dictionary <string, byte[]> uuids = new Dictionary <string, byte[]>();

                Console.WriteLine("Putting 1000 random 100K assets to server");
                Console.WriteLine(DateTime.Now);

                SHA1 sha = new SHA1CryptoServiceProvider();


                for (int i = 0; i < 1000; i++)
                {
                    string uuidstr       = OpenMetaverse.UUID.Random().ToString();
                    byte[] randomBytes   = TestUtil.RandomBytes();
                    byte[] challengeHash = sha.ComputeHash(randomBytes);
                    uuids.Add(uuidstr, challengeHash);

                    Asset asset = new Asset(uuidstr, 1,
                                            false, false, 0, "Random Asset", "Radom Asset Desc", randomBytes);
                    server.PutAsset(asset);
                }
                Console.WriteLine("Done: " + DateTime.Now);
                Console.WriteLine("Rereading written assets");
                Console.WriteLine(DateTime.Now);

                foreach (KeyValuePair <string, byte[]> kvp in uuids)
                {
                    Asset  a    = server.GetAsset(kvp.Key);
                    byte[] hash = sha.ComputeHash(a.Data);
                    if (!TestUtil.Test.test(hash, kvp.Value))
                    {
                        Console.WriteLine("Mismatched hash on " + kvp.Key);
                        Console.WriteLine("Got " + Util.HashToHex(hash) + " expected " + Util.HashToHex(kvp.Value));

                        ASCIIEncoding encoding = new ASCIIEncoding();

                        Console.WriteLine("Data " + encoding.GetString(a.Data));
                    }
                }

                Console.WriteLine("finished verifing assets");
                Console.WriteLine(DateTime.Now);
            }

            if (cmd == "purgelocals")
            {
                server.MaintPurgeLocals();
            }

            if (cmd == "thread")
            {
                Console.WriteLine("Starting heavy thread test");
                ThreadTest test = new ThreadTest(server, false);
                test.Start();
            }

            if (cmd == "thread_purgelocal")
            {
                Console.WriteLine("Starting heavy thread test");
                ThreadTest test = new ThreadTest(server, true);
                test.Start();
            }

            if (cmd == "threadmesh")
            {
                RemoteServer server2 = ConnectServerByConsole();

                Console.WriteLine("Starting heavy thread mesh test");
                CrossServerThreadTest test = new CrossServerThreadTest(server, server2);
                test.Start();
            }

            if (cmd == "threadmesh3")
            {
                RemoteServer server2 = ConnectServerByConsole();
                RemoteServer server3 = ConnectServerByConsole();

                Console.WriteLine("Starting heavy thread mesh test");
                CrossServerThreadTest3 test = new CrossServerThreadTest3(server, server2, server3);
                test.Start();
            }

            if (cmd == "testmulticonn")
            {
                RemoteServer[] server1 = ConnectServerByConsoleX(10);
                RemoteServer[] server2 = ConnectServerByConsoleX(10);
                RemoteServer[] server3 = ConnectServerByConsoleX(10);

                List <RemoteServer> allServers = new List <RemoteServer>();
                allServers.AddRange(server1);
                allServers.AddRange(server2);
                allServers.AddRange(server3);

                CrossServerTestMulticonn test = new CrossServerTestMulticonn(server1[0], server2[0], server3[0], allServers.ToArray(), true);
                test.Start();
            }

            if (cmd == "testmulticonnsingle")
            {
                RemoteServer[] server1 = ConnectServerByConsoleX(10);

                CrossServerTestMulticonn test = new CrossServerTestMulticonn(server1[0], server1[0], server1[0], server1, false);
                test.Start();
            }

            if (cmd == "meshbias3")
            {
                RemoteServer[] servers2 = ConnectServerByConsoleX(10);
                RemoteServer   server3  = ConnectServerByConsole();

                Console.WriteLine("Starting heavy thread biased mesh test");
                CrossServerBiasTest3 test = new CrossServerBiasTest3(server, servers2, server3);
                test.Start();
            }

            if (cmd == "connect")
            {
                //fast connect and disconnect to try and kill the whip service
                for (int i = 0; i < 1000; i++)
                {
                    server.Stop();
                    server.Start();
                }
            }

            if (cmd == "status")
            {
                Console.WriteLine(server.GetServerStatus());
            }

            if (cmd == "prefix")
            {
                Console.WriteLine(server.GetAssetIds("00000000000000000000000000000000"));
            }

            if (cmd == "compare")
            {
                RemoteServer server1 = ConnectServerByConsole();
                RemoteServer server2 = ConnectServerByConsole();
                RunCompare(server1, server2);
            }

            if (cmd == "import")
            {
                Console.Write("Connection String: ");
                string connString = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Start at: ");
                int startAt = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();

                _import = new AssetImport(server, connString, startAt);
                _import.Start();
            }

            if (cmd == "msimport")
            {
                Console.Write("Connection String: ");
                string connString = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Start at: ");
                Guid startAt = new Guid(Console.ReadLine());
                Console.WriteLine();

                _msimport = new MsSqlAssetImport(server, connString, startAt);
                _msimport.Start();
            }

            if (cmd == "stop import")
            {
                if (_import != null)
                {
                    _import.Stop();
                }
                _import = null;
                if (_msimport != null)
                {
                    _msimport.Stop();
                }
                _msimport = null;
            }
        }