public Runner(ServiceIdentity i_serviceIdentity, PrivateIdentity i_privateIdentity, Params ps) { serviceIdentity = i_serviceIdentity; privateIdentity = i_privateIdentity; scheduler = IoScheduler.CreateServer(privateIdentity, ps.LocalHostNameOrAddress, ps.LocalPort, serviceIdentity.Servers, ps.Verbose); }
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); }
private void SenderThread() { Random rng = new Random(); while (true) { int serverIndex = rng.Next(serviceIdentity.Servers.Count); PublicIdentity serverIdentity = serviceIdentity.Servers[serverIndex]; byte[] serverPublicKey = serverIdentity.PublicKey; int randomNumber = rng.Next(10000); string message = string.Format("Hello {0}", randomNumber); byte[] messageBytes = Encoding.UTF8.GetBytes(message); Console.WriteLine("Sending message {0} to {1}", message, IoScheduler.PublicKeyToString(serverPublicKey)); scheduler.SendPacket(serverPublicKey, messageBytes); Thread.Sleep(1000); } }
public static NetClient Create(PrivateIdentity myIdentity, string localHostNameOrAddress, int localPort, List <PublicIdentity> knownIdentities, bool verbose, int maxSendRetries = 3) { try { var scheduler = IoScheduler.CreateServer(myIdentity, localHostNameOrAddress, localPort, knownIdentities, verbose, maxSendRetries); var myPublicKey = IoScheduler.GetCertificatePublicKey(scheduler.MyCert); if (myPublicKey.Length > MaxPublicKeySize) { System.Console.Error.WriteLine("ERROR: The provided public key for my identity is too big ({0} > {1} bytes)", myPublicKey.Length, MaxPublicKeySize); return(null); } return(new NetClient(scheduler)); } catch (Exception e) { System.Console.Error.WriteLine(e); return(null); } }
private void ReceiverThread() { while (true) { bool ok; bool timedOut; byte[] remote; byte[] messageBytes; scheduler.ReceivePacket(0, out ok, out timedOut, out remote, out messageBytes); if (!ok) { Console.WriteLine("Not OK, so terminating receiver thread"); return; } if (timedOut) { Thread.Sleep(100); continue; } string message = Encoding.UTF8.GetString(messageBytes); Console.WriteLine("Received message {0} from {1}", message, IoScheduler.PublicKeyToString(remote)); } }
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); } } } }
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; } } } } } }
public Dafny.ISequence <byte> MyPublicKey() { return(Dafny.Sequence <byte> .FromArray(IoScheduler.GetCertificatePublicKey(scheduler.MyCert))); }
internal NetClient(IoScheduler i_scheduler) { scheduler = i_scheduler; }