예제 #1
0
  public void begin() {
    global = (FreeMMGNetwork) this.network;

    int total_width = global.getAsInt("cell_width") * global.getAsInt("world_width");
    int total_height = global.getAsInt("cell_height") * global.getAsInt("world_height");

    ia = new IA[global.getAsInt("NUM_PLAYERS")];
    myId = new int[global.getAsInt("NUM_PLAYERS")];
    ownerCell = new int[global.getAsInt("NUM_PLAYERS")];
    downloadEstimative = new int[global.getAsInt("NUM_PLAYERS")];
    uploadEstimative = new int[global.getAsInt("NUM_PLAYERS")];

    int idBase = global.getAsInt("WHN") + 1 + 1;
    for (int k = 0; k < global.getAsInt("NUM_PLAYERS"); k++) {
      myId[k] = idBase + k;
      ia[k] = new IARandomWalk(total_width, total_height, 128.0);

      int[] xy = ia[k].get_pos();
      int col = xy[0] / global.getAsInt("cell_width");
      int row = xy[1] / global.getAsInt("cell_height");
      ownerCell[k] = row * global.getAsInt("world_width") + col;

      downloadEstimative[k] = 0;
      uploadEstimative[k] = 0;
    }

    ReceiveThread recv_thread = new ReceiveThread(this);
    SendThread send_thread = new SendThread(this);
    CountThread count_thread = new CountThread(this);

    recv_thread.launch();
    send_thread.launch();
    count_thread.launch();
  }
    /** @see java.util.TimerTask#run() */
    public void run() {
      if (!_ended) {
        synchronized (_done) {
          int _sendCount = 0;
          for (int i = 0; i < _done.length && _sendCount < _numTx; i++) {
            if (!_done[i]) {
              Partner p = _partners.get(i);

              while (!p.hasFinishedTx() && _sendCount < _numTx) {
                // spawn thread to send for this partner
                p.incrementCounter();
                SendThread t = new SendThread(p);
                _sendCount++;
                t.start();
              }
              if (p.hasFinishedTx()) {
                _done[i] = true;
                logger.log(Level.INFO, "Finished sending all tx to partner " + p.getId());
              }
            }
          }
          if (_sendCount < _numTx) {
            logger.log(Level.INFO, "Finished sending all tx to all partners");
            stop();
            logger.log(Level.INFO, "Test case " + _testCaseId + " finished at " + new Date());
          }
        }
      } else {
        logger.log(Level.INFO, "Send timer has been cancelled.");
      }
    }
예제 #3
0
  private byte[] computeMAC(Vector messages) throws IOException {
    mySHA1.reset(); // Initialize a new hash
    if (myIsDoingHMAC) {
      /* Calculate sha1(key ^ ipad || data) */
      byte[] pad = new byte[HASH_BLOCK_SIZE];
      replicate(pad, (byte) 0x36);
      xor(pad, myMACKey);
      mySHA1.reset();
      mySHA1.update(pad);
    } else {
      mySHA1.update(myMACKey); // The MAC key
    }
    if (null != mySequence) {
      mySHA1.update(mySequence);
      increment(mySequence);
    }
    Enumeration itr = messages.elements();
    while (itr.hasMoreElements()) {
      byte[] b = (byte[]) (itr.nextElement());
      int len = b.length;
      byte[] l = new byte[4];
      int lenlen = SendThread.msgLength(len, l, 0, myIsCompressingMsgLengths);
      mySHA1.update(l, 0, lenlen);
      mySHA1.update(b); // The message
    }
    if (myIsDoingHMAC) {
      byte[] hash = mySHA1.digest();

      /* Calculate sha1(key ^ opad || hash */
      byte[] pad = new byte[HASH_BLOCK_SIZE];
      replicate(pad, (byte) 0x5c);
      xor(pad, myMACKey);
      mySHA1.update(pad);
      mySHA1.update(hash);
      return mySHA1.digest();
    } else {
      return mySHA1.digest(myMACKey); // The MAC key again
    }
  }
예제 #4
0
파일: SendIP.java 프로젝트: hsoftxl/xielei
 private void lanchApp() {
   SendThread th = new SendThread();
   th.start();
 }