Exemplo n.º 1
0
 /**
  * Pops a header from a message. Creates a new Header from the values contained by the message.
  *
  * @param message message that contains the info to build the header
  * @return a header builted from the values of contained by the message
  */
 public static SEQHeader pop(Message message) {
   SEQHeader header = new SEQHeader();
   header.order = message.popLong();
   header.sn = message.popLong();
   header.id = message.popInt();
   return header;
 }
Exemplo n.º 2
0
  /**
   * Deliver a DATA event received from the network.
   *
   * @param event the event received from the network.
   */
  private void reliableDATADeliver(GroupSendableEvent event) {
    Message msg = event.getMessage();
    long[] uniformInfo = new long[vs.view.length];
    for (int i = uniformInfo.length; i > 0; i--) uniformInfo[i - 1] = msg.popLong();
    mergeUniformInfo(uniformInfo);
    DATAHeader header = DATAHeader.pop(event.getMessage());
    log.debug(
        "Received DATA message: "
            + header.id
            + ":"
            + header.sn
            + " timestpamp is "
            + timeProvider.currentTimeMillis());
    header.setTime(delay[header.id] + timeProvider.currentTimeMillis());
    ListContainer container = new ListContainer(event, header);
    // add the event to the RECEIVED list...
    R.addLast(container);
    // ... and set a timer to be delivered later, according to the delay that came with the message
    setTimer(container, delay[header.id], vs.id);

    // Deliver event to the upper layer (spontaneous order)
    try {
      event.go();
    } catch (AppiaEventException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
 /**
  * Pops a header from a message. Creates a new Header from the values contained by the message.
  *
  * @param message message that contains the info to build the header
  * @return a header builted from the values of contained by the message
  */
 public static DATAHeader pop(Message message) {
   DATAHeader header = new DATAHeader(-1, -1);
   header.delay = message.popLong();
   header.sn = message.popLong();
   header.id = message.popInt();
   return header;
 }
Exemplo n.º 4
0
 private void handleGroupSendableEvent(GroupSendableEvent event) {
   if (debugOn && log.isDebugEnabled()) log.debug("CAUSAL Processing event " + event);
   if (!(event instanceof Send)) {
     if (event.getDir() == Direction.DOWN) {
       Message omsg = event.getMessage();
       for (int i = 0; i < VC.length; i++) omsg.pushLong(VC[i]);
       try {
         event.go();
       } catch (AppiaEventException e) {
         e.printStackTrace();
       }
       VC[ls.my_rank]++;
     } else {
       if (event.orig != ls.my_rank) {
         long[] VCm = new long[VC.length];
         extractVCm(event.getMessage(), VCm);
         pending.add(new EventContainer(event, VCm));
         deliverPending();
       } else {
         clearVC(event.getMessage());
         try {
           event.go();
         } catch (AppiaEventException e) {
           e.printStackTrace();
         }
       }
     }
   } else
     try {
       event.go();
     } catch (AppiaEventException e) {
       e.printStackTrace();
     }
 }
Exemplo n.º 5
0
 private void handleUniformInfo(UniformInfoEvent event) {
   log.debug(
       "Received UniformInfo from " + event.orig + ". Uniformity information table now is: ");
   Message msg = event.getMessage();
   long[] uniformInfo = new long[vs.view.length];
   for (int i = uniformInfo.length; i > 0; i--) uniformInfo[i - 1] = msg.popLong();
   mergeUniformInfo(uniformInfo);
   if (log.isDebugEnabled())
     for (int i = 0; i < lastOrderList.length; i++)
       log.debug("RANK :" + i + " | LAST_ORDER: " + lastOrderList[i]);
   deliverUniform();
 }
Exemplo n.º 6
0
 /**
  * Multicast a SEQUENCER message to the group.
  *
  * @param container the container of the message to be sequenced.
  */
 private void reliableSEQMulticast(ListContainer container) {
   SEQHeader header = new SEQHeader(container.header.sender(), container.header.sn(), globalSN);
   SeqOrderEvent event;
   try {
     event =
         new SeqOrderEvent(container.event.getChannel(), Direction.DOWN, this, vs.group, vs.id);
     SEQHeader.push(header, event.getMessage());
     Message msg = event.getMessage();
     for (int i = 0; i < lastOrderList.length; i++) msg.pushLong(lastOrderList[i]);
     log.debug("Sending SEQ message. Rank=" + ls.my_rank + " Header: " + header);
     event.go();
   } catch (AppiaEventException e2) {
     e2.printStackTrace();
   }
 }
Exemplo n.º 7
0
  /**
   * Handles all events related to messenger features: TextEvent, DrawEvent, ImageEvent,
   * ClearWhiteBoardEvent, MouseButtonEvent
   *
   * <p>If an event direction is DOWN an hash is generated otherwise received and calculated hashes
   * are compared. <br>
   * Different hashes mean that an event is ignored
   *
   * @param ev
   */
  private void handleInterestingEvent(GroupSendableEvent ev) {

    Message message = ev.getMessage();
    byte[] data;
    Hash h = new Hash();
    //		String type;

    if (ev.getDir() == Direction.DOWN) {
      data = message.toByteArray();
      md.update(data);
      md.update(secret);
      byte[] my = md.digest();
      h.setHash(my);
      message.pushObject(h);
      md.reset();
      // out.println("MD calculated");
      ev.setObjectsMessage(message);
      try {
        ev.go();
      } catch (AppiaEventException e) {
        e.printStackTrace();
      }

    } else {
      // incoming hash
      h = (Hash) message.popObject();
      data = message.toByteArray();

      // calculates hash
      md.update(data);
      md.update(secret);

      if (MessageDigest.isEqual(md.digest(), h.getHash())) {
        // out.println("Valid");
        try {
          ev.go();
        } catch (AppiaEventException e) {
          e.printStackTrace();
        }
      }
      //			else{
      //				out.println("Error! Compromised message received!");
      //				out.println("Message ignored!");
      //			}
      md.reset();
    }
  }
Exemplo n.º 8
0
  private void sendUniformInfo(Channel channel) {
    if (!isBlocked) {
      UniformInfoEvent event = new UniformInfoEvent();

      Message msg = event.getMessage();
      for (int i = 0; i < lastOrderList.length; i++) msg.pushLong(lastOrderList[i]);

      event.setChannel(channel);
      event.setDir(Direction.DOWN);
      event.setSource(this);
      try {
        event.init();
        event.go();
      } catch (AppiaEventException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 9
0
 /**
  * Multicast a DATA event to the group.
  *
  * @param event the event to be multicast.
  * @param msgDelay the message delay associated with the event.
  */
 private void reliableDATAMulticast(GroupSendableEvent event, long msgDelay) {
   DATAHeader header = new DATAHeader(ls.my_rank, sendingLocalSN++, msgDelay);
   DATAHeader.push(header, event.getMessage());
   Message msg = event.getMessage();
   for (int i = 0; i < lastOrderList.length; i++) msg.pushLong(lastOrderList[i]);
   log.debug(
       "Sending DATA message from appl. Rank="
           + ls.my_rank
           + " SN="
           + sendingLocalSN
           + " Delay="
           + msgDelay);
   try {
     event.go();
   } catch (AppiaEventException e) {
     e.printStackTrace();
   }
   timeLastMsgSent = timeProvider.currentTimeMillis();
 }
  private void handleSendEvent(SendEvent conf) {
    Message message = conf.getMessage();
    int id = message.popInt();

    System.out.println("[Message received: " + message.peekString() + "]");

    message.pushInt(id);

    DeliverEvent event = new DeliverEvent();
    event.setMessage(message);
    event.setDestProcess(processes.getOther());
    event.setSourceProcess(processes.getSelf());
    event.setChannel(conf.getChannel());
    event.setDir(Direction.DOWN);
    event.setSourceSession(this);

    try {
      event.init();
      event.go();
    } catch (AppiaEventException ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 11
0
 /** Deliver a SEQUENCER message received from the network. */
 private void reliableSEQDeliver(SeqOrderEvent event) {
   Message msg = event.getMessage();
   long[] uniformInfo = new long[vs.view.length];
   for (int i = uniformInfo.length; i > 0; i--) uniformInfo[i - 1] = msg.popLong();
   mergeUniformInfo(uniformInfo);
   SEQHeader header = SEQHeader.pop(event.getMessage());
   log.debug(
       "["
           + ls.my_rank
           + "] Received SEQ message "
           + header.id
           + ":"
           + header.sn
           + " timestamp is "
           + timeProvider.currentTimeMillis());
   lastOrderList[ls.my_rank] = header.order;
   newUniformInfo = true;
   // add it to the sequencer list
   S.add(new ListSEQContainer(header, timeProvider.currentTimeMillis()));
   log.debug("Received SEQ from " + event.orig + " at time " + timeProvider.currentTimeMillis());
   // and tries to deliver messages that already have the order
   deliverRegular();
   deliverUniform();
 }
 public void peekMySelf(Message m) {
   number = m.peekInt();
   message = (RainMessage) m.peekObject();
 }
 public void popMySelf(Message m) {
   number = m.popInt();
   message = (RainMessage) m.popObject();
 }
 public void pushMySelf(Message m) {
   m.pushObject(message);
   m.pushInt(number);
 }
Exemplo n.º 15
0
 /**
  * Extracts the VC from the header of a message.
  *
  * @param omsg the message from where the VC will be extracted.
  * @param VCm array where the values of the VC for the given message will be stored.
  */
 private void extractVCm(Message omsg, long[] VCm) {
   for (int i = VCm.length - 1; i >= 0; i--) VCm[i] = omsg.popLong();
 }
Exemplo n.º 16
0
 /**
  * Push all parameters of a Header into a Appia Message.
  *
  * @param header header to push into the message
  * @param message message to put the header
  */
 public static void push(SEQHeader header, Message message) {
   message.pushInt(header.id);
   message.pushLong(header.sn);
   message.pushLong(header.order);
 }
Exemplo n.º 17
0
 /**
  * Clears the values of the VC in the header of a message.
  *
  * @param omsg the message whose header will be cleared.
  */
 private void clearVC(Message omsg) {
   for (int i = 0; i < VC.length; i++) omsg.popLong();
 }
Exemplo n.º 18
0
 /**
  * Push all parameters of a Header into a Appia Message.
  *
  * @param header header to push into the message
  * @param message message to put the header
  */
 public static void push(DATAHeader header, Message message) {
   message.pushInt(header.id);
   message.pushLong(header.sn);
   message.pushLong(header.delay);
 }