Пример #1
0
 private void parse(PacketMessage packetMessage) throws UnknownHostException {
   this.type = 'D';
   this.transactionID = packetMessage.getTransactionID();
   DataMessage dataMessage = packetMessage.getDataMessage();
   this.finalDestinationIP =
       (Inet4Address) Inet4Address.getByName(dataMessage.getFinalDestinationIP());
   this.deadline = dataMessage.getDeadline() - 1; // automagically decrement Hop Count
   this.fine = dataMessage.getFine();
   this.initialBudget = dataMessage.getInitialBudget();
   this.payload = dataMessage.getPayload();
 }
Пример #2
0
  private byte[] buildPayload() {

    DataMessage dataMessage =
        DataMessage.newBuilder()
            .setFinalDestinationIP(this.finalDestinationIP.getHostAddress())
            .setDeadline(this.deadline)
            .setFine(this.fine)
            .setInitialBudget(this.initialBudget)
            .setPayload(this.payload)
            .build();

    PacketMessage packetMessage =
        PacketMessage.newBuilder()
            .setType(PacketMessage.packetType.DATA)
            .setTransactionID(this.transactionID)
            .setDataMessage(dataMessage)
            .build();

    System.out.println("built Data: " + packetMessage);

    return packetMessage.toByteArray();
  }