예제 #1
0
 //tests sending a QueryRequest and receiving a response
 static void testQueryRequestClient()
 {
     Guid myGuid = Guid.NewGuid();
     TcpClient tcpClient = new TcpClient("172.18.9.11", 7890);
     ClientThread ct = new ClientThread(tcpClient, false, myGuid);
     QueryRequest qr = new QueryRequest(IPAddress.Parse(Node.GetInternetAddress()), myGuid, 777);
     qr.QueryType = QueryType.Hostname;
     ct.EnqueueWork(qr);
     int x = 0;
     while (ct.EventCount() == 0)
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for response. " + x);
     }
     NetworkResponse response = (NetworkResponse) ct.DequeueEvent();
     Print("response: " + response.Type + " reason: " + response.Reason);
     ct.RequestStop();
     Print("requested stop");
     while (ct.IsAlive())
     {
         x++;
         Thread.Sleep(1000);
         Print("waiting for thread to die. " + x);
     }
     Print("thread dead.");
     Console.WriteLine("press a key to continue");
     Console.ReadKey();
 }
예제 #2
0
 protected void processQueryRequest(ClientThread ct, QueryRequest request)
 {
     Logger.Debug("EchoBackupService:processQueryRequest doing nothing");
     //todo
 }
예제 #3
0
 private void processRemoteQueryRequest(QueryRequest request)
 {
     //todo: process queries by responding with values from Node staitc methods
     //each query's Field string should have the name of the Backend.QueryType enum
     QueryType qt = request.QueryType;
     string reason = "";
     ResponseType rt = ResponseType.Yes;
     switch (qt)
     {
         case QueryType.BackupSpace:
             reason = Node.GetBackupSpace().ToString();
             break;
         case QueryType.FreeSpace:
             reason = Node.GetFreeSpace().ToString();
             break;
         case QueryType.Hostname:
             reason = Node.GetHostName();
             break;
         case QueryType.IPAddress:
             reason = Node.GetInternetAddress();
             break;
         case QueryType.MACAddress:
             reason = Node.GetMAC();
             break;
         case QueryType.NonBackupSpace:
             reason = Node.GetNonBackupSpace().ToString();
             break;
         case QueryType.TotalSpace:
             reason = Node.GetTotalSize().ToString();
             break;
         default:
             rt = ResponseType.NotImplemented;
             break;
     }
     sendMessage(tcpClient, new NetworkResponse(rt, reason, this.guid, request.SequenceNumber));
 }
예제 #4
0
 private void processMyQueryRequest(QueryRequest request)
 {
     int ret = sendMessage(tcpClient, request);
     NetworkResponse response = (NetworkResponse)receiveMessage(tcpClient);
     //add response to eventQueue
     lock (_lock)
     {
         eventQueue.Enqueue(response);
     }
 }
예제 #5
0
 /*/// <summary>
 /// Responds to a QueryRequest from a remote node by sending a NetworkResponse object. This method blocks until the response is sent.
 /// </summary>
 /// <param name="request">The NetworkRequest that we are responding to</param>
 /// <param name="response">The response code to be sent to the remote node</param>
 /// <param name="details">The details of or reason for the response</param>
 public void RespondToQuery(QueryRequest request, ResponseType response, string details)
 {
     NetworkResponse networkResponse = new NetworkResponse(response, details, guid, request.SequenceNumber);
     int ret = sendMessage(tcpClient, networkResponse);
     if (ret == -1)
     {
         Logger.Error("ClientThread:respondToQuery failed to respond to a node. Response: " + response + " sequenceNumber: " + request.SequenceNumber + " Details: " + details);
     }
     else
     {
         Logger.Info("ClientThread:respondToQuery successfully responded to a node. Response: " + response + " sequenceNumber: " + request.SequenceNumber + " Details: " + details);
     }
 }*/
 public void RespondToQuery(QueryRequest request)
 {
     lock (_lock)
     {
         working = true;
         workQueue.Enqueue(request);
     }
 }
예제 #6
0
 protected void processQueryRequest(ClientThread ct, QueryRequest request)
 {
     Logger.Debug("EchoBackupService:processQueryRequest doing nothing");
     //todo
 }