Пример #1
0
 public RSLClient(ServiceIdentity i_serviceIdentity, string serviceName, bool i_verbose = false)
 {
     serviceIdentity = i_serviceIdentity;
     if (serviceIdentity.ServiceType != "IronRSL" + serviceName)
     {
         Console.Error.WriteLine("Provided service identity has type {0}, not IronRSL{1}.",
                                 serviceIdentity.ServiceType, serviceName);
         throw new Exception("Wrong service type");
     }
     serverPublicKeys   = serviceIdentity.Servers.Select(server => server.PublicKey).ToArray();
     verbose            = i_verbose;
     nextSeqNum         = 0;
     primaryServerIndex = 0;
     scheduler          = IoScheduler.CreateClient(serviceIdentity.Servers, verbose);
 }
Пример #2
0
        public void Experiment()
        {
            ulong requestKey;
            int   serverIdx = 0;

            scheduler = IoScheduler.CreateClient(serviceIdentity.Servers, ps.Verbose);

            byte[] myPublicKey = IoScheduler.GetCertificatePublicKey(scheduler.MyCert);
            ulong  seqNum      = 0;

            // Test the functionality of the Sharding
            if (ps.Workload == 'f')
            {
                // A delegation can delegate at most 61 keys, so make sure
                // there can't be that many keys in the range by having the
                // range be smaller than 61.
                ulong k_lo = 125;
                ulong k_hi = 175;
                requestKey = 150;
                var recipient = serviceIdentity.Servers[(serverIdx + 1) % serviceIdentity.Servers.Count()];

                seqNum++;
                var msg = new GetRequestMessage(seqNum, myPublicKey, requestKey);
                this.Send(msg, serviceIdentity.Servers[serverIdx].PublicKey);
                ReceiveReply(serverIdx, myPublicKey, requestKey, false);

                seqNum++;
                Console.WriteLine("Sending a Shard request with a sequence number {0}", seqNum);
                var shardMessage = new ShardRequestMessage(seqNum, myPublicKey, k_lo, k_hi, recipient.PublicKey);
                this.Send(shardMessage, serviceIdentity.Servers[serverIdx].PublicKey);
                ReceiveReply(serverIdx, myPublicKey, requestKey, true);

                Thread.Sleep(5000);

                Console.WriteLine("Sending a GetRequest after a Shard, expect a redirect");

                seqNum++;
                msg = new GetRequestMessage(seqNum, myPublicKey, requestKey);
                this.Send(msg, serviceIdentity.Servers[(serverIdx + 0) % serviceIdentity.Servers.Count()].PublicKey);
                ReceiveReply(serverIdx, myPublicKey, requestKey, false, expectRedirect: true);

                Thread.Sleep(5000);

                Console.WriteLine("Sending a GetRequest after a Shard to the second host, expect a reply");
                // Must use sequence number 1 since this is the first message
                // to this server.
                msg = new GetRequestMessage(1, myPublicKey, requestKey);
                this.Send(msg, serviceIdentity.Servers[(serverIdx + 1) % serviceIdentity.Servers.Count()].PublicKey);
                ReceiveReply((serverIdx + 1) % serviceIdentity.Servers.Count(), myPublicKey, requestKey, false);

                Console.WriteLine("Successfully received reply");

                return;
            }

            // Run an actual workload
            while (true)
            {
                seqNum++;
                var receivedReply = false;
                requestKey = seqNum % (ulong)ps.NumKeys;

                MessageBase msg;
                if (ps.Workload == 'g')
                {
                    msg = new GetRequestMessage(seqNum, myPublicKey, requestKey);
                }
                else
                {
                    msg = new SetRequestMessage(seqNum, myPublicKey, requestKey, (ulong)ps.ValueSize);
                }

                var startTime = HiResTimer.Ticks;
                this.Send(msg, serviceIdentity.Servers[serverIdx].PublicKey);

                // Wait for the reply

                while (!receivedReply)
                {
                    byte[] bytes = Receive();
                    if (bytes == null)
                    {
                        //serverIdx = (serverIdx + 1) % serviceIdentity.Servers.Count();
                        //Console.WriteLine("#timeout; rotating to server {0}", serverIdx);
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        this.Send(msg, serviceIdentity.Servers[serverIdx].PublicKey);
                        continue;
                    }
                    var endTime = HiResTimer.Ticks;

                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                    }
                    else if (bytes.Length >= 56)
                    {
                        var replySeqNum = ExtractBE64(bytes, offset: 8);
                        if (ps.Verbose)
                        {
                            Console.WriteLine("Reply sequence number : {0}", replySeqNum);
                            Console.WriteLine("Client {0}: Sending an ack with sequence number {1} to {2}",
                                              id, replySeqNum, serviceIdentity.Servers[serverIdx]);
                        }
                        if (seqNum % 100 == 0)
                        {
                            var ack_msg = new AckMessage(replySeqNum);
                            this.Send(ack_msg, serviceIdentity.Servers[serverIdx].PublicKey);
                        }

                        int publicKeyLength = Convert.ToInt32(ExtractBE64(bytes, offset: 16));
                        if (bytes.Length < publicKeyLength + 40)
                        {
                            Console.WriteLine("ERROR - Received too-short message (size {0} not long enough for public key of length {1})",
                                              bytes.Length, publicKeyLength);
                        }
                        else
                        {
                            var replyKey = ExtractBE64(bytes, offset: 32 + publicKeyLength);
                            // Need to send an ack
                            if (ps.Verbose)
                            {
                                Console.WriteLine("Request key : {0}", requestKey);
                                Console.WriteLine("Reply key : {0}", replyKey);
                                Console.WriteLine("Got packet length: {0}", bytes.Length);
                            }

                            // key is the same as the sequence number
                            if (replyKey == requestKey)
                            {
                                receivedReply = true;
                                Console.WriteLine("#req {0} {1} {2}",
                                                  id,
                                                  seqNum,
                                                  HiResTimer.TicksToMilliseconds(endTime - startTime));
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Received packet of unexpected length {0}", bytes.Length);
                    }
                }
            }
        }
Пример #3
0
        public void Setup()
        {
            scheduler = IoScheduler.CreateClient(serviceIdentity.Servers, ps.Verbose);
            byte[] myPublicKey = IoScheduler.GetCertificatePublicKey(scheduler.MyCert);

            int   serverIdx = 0;
            ulong seqNum    = 0;
            ulong requestKey;

            for (requestKey = 0; requestKey < (ulong)ps.NumKeys; ++requestKey)
            {
                seqNum++;
                var msg = new SetRequestMessage(seqNum, myPublicKey, requestKey, (ulong)ps.ValueSize);

                if (ps.Verbose)
                {
                    Console.WriteLine("Sending set request message with seq {0}, key {1} to server {2}", seqNum, requestKey, serverIdx);
                }
                this.Send(msg, serviceIdentity.Servers[serverIdx].PublicKey);

                // Wait for the reply
                var receivedReply = false;
                while (!receivedReply)
                {
                    byte[] bytes   = Receive();
                    var    endTime = HiResTimer.Ticks;
                    if (bytes == null)
                    {
                        //serverIdx = (serverIdx + 1) % serviceIdentity.Servers.Count();
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        this.Send(msg, serviceIdentity.Servers[serverIdx].PublicKey);
                        continue;
                    }
                    //Trace("Got the following reply:" + ByteArrayToString(bytes));
                    //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                        if (ps.Verbose)
                        {
                            Console.WriteLine("Received ack");
                        }
                    }
                    else if (bytes.Length >= 48)
                    {
                        var replySeqNum = ExtractBE64(bytes, offset: 8);
                        if (ps.Verbose)
                        {
                            Console.WriteLine("Reply sequence number : {0}", replySeqNum);
                        }

                        var ack_msg = new AckMessage(replySeqNum);

                        if (ps.Verbose)
                        {
                            Console.Out.WriteLine("Client {0}: Sending an ack with sequence number {1} to {2}",
                                                  id, replySeqNum, serviceIdentity.Servers[serverIdx]);
                        }
                        this.Send(ack_msg, serviceIdentity.Servers[serverIdx].PublicKey);

                        int publicKeyLength = Convert.ToInt32(ExtractBE64(bytes, offset: 16));
                        if (bytes.Length < publicKeyLength + 40)
                        {
                            Console.WriteLine("ERROR - Received too-short message (size {0} not long enough for public key of length {1})",
                                              bytes.Length, publicKeyLength);
                        }
                        else
                        {
                            var replyKey = ExtractBE64(bytes, offset: 32 + publicKeyLength);
                            // Need to send an ack
                            if (ps.Verbose)
                            {
                                Console.WriteLine("Request key : {0}", requestKey);
                                Console.WriteLine("Reply key : {0}", replyKey);
                                Console.WriteLine("Got packet length: {0}", bytes.Length);
                            }

                            if (replyKey == requestKey)
                            {
                                receivedReply = true;
                            }
                        }
                    }
                }
            }
        }