Example #1
0
 public void reply() {
   // TODO Auto-generated method stub
   byte[] msg =
       Utility.createMessage(
           CMessage.MAGIC, myId, currentState, found, found, Utility.hash(found));
   sendMessageToServer(msg);
   if (!toldTheServer
       && (currentState == CMessage.DONE_NOT_FOUND || currentState == CMessage.DONE_FOUND)) {
     toldTheServer = true;
     currentState = CMessage.IDLE;
   }
 }
Example #2
0
 public void breakHash(String start, String end, String hash) {
   // TODO Auto-generated method stub
   searching = true;
   currentState = CMessage.NOT_DONE;
   toldTheServer = false;
   String str = start;
   int i = 0;
   while (searching) {
     if (i++ % 500000 == 0) System.out.println("Searching... " + str);
     if (Utility.hash(str).equals(hash)) {
       found = str;
       searching = false;
       currentState = CMessage.DONE_FOUND;
     } else {
       str = Utility.getNextString(str, str.length() - 1, str.length());
     }
     if (str.equals(end)) {
       searching = false;
       currentState = CMessage.DONE_NOT_FOUND;
     }
   }
 }
Example #3
0
 public void start() {
   byte[] msg = new byte[256];
   byte[] arr =
       Utility.createMessage(
           CMessage.MAGIC, myId, CMessage.REQUEST_TO_JOIN, found, found, Utility.hash(found));
   sendMessageToServer(arr);
   DatagramPacket packet = new DatagramPacket(msg, msg.length);
   try {
     while (running) {
       socket.receive(packet);
       byte[] data = packet.getData();
       CMessage mesg = Utility.openMessage(data);
       if (mesg.magic == CMessage.MAGIC) {
         (new Killer(mesg, this)).start();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     socket.close();
   }
 }
Example #4
0
 public void sendAck(String start) {
   byte[] msg =
       Utility.createMessage(
           CMessage.MAGIC, myId, CMessage.ACK_JOB, start, found, Utility.hash(found));
   sendMessageToServer(msg);
 }