public void handleUpdatePacket(Packet p, String from) {
    // dont update packets that came from this device
    if (p.getSource().equals(localDevice.getBluetoothAddress())) return;

    // get the md5 of the payload of the packet and store it
    // if the previous md5 is the same with the new one
    // then this packet is redundant
    String hash = md5(p.getPayload());
    if (history.containsKey(p.getSource())) {
      String old = history.get(p.getSource());
      if (old.equals(hash)) return;
    }

    ByteBuffer buffer = ByteBuffer.allocate(p.getPayload().length);
    buffer.put(p.getPayload());
    routingTable.remove(p.getSource());
    routingTable.add(p.getSource());
    byte[] tmp = new byte[12];
    while (buffer.hasRemaining()) {
      buffer.get(tmp, 0, 12);
      routingTable.add(p.getSource(), new String(tmp));
    }

    for (String address : connections.keySet()) {
      if (!address.equals(from)) {
        connections.get(address).offer(p);
      }
    }
    history.put(p.getSource(), hash);
  }
 public void handlePacket(byte[] p, String from) {
   Packet s = Packet.createPacket(p);
   s.decreaseHopCount();
   if (s.getHopCount() > 0) {
     Log("SynCore", s.getSource() + " " + s.getDestination());
     if (s.getType() == Packet.DATA_PACKET) {
       handleDataPacket(s);
     } else {
       handleUpdatePacket(s, from);
     }
   }
 }
  public void handleDataPacket(Packet p) {
    // this packet is for this device
    if (p.getDestination().equals(localDevice.getBluetoothAddress())) {
      offer(p);
    } else {
      String nextHop = routingTable.nextHop(localDevice.getBluetoothAddress(), p.getDestination());

      if (nextHop != null) {
        Log("SynCore", "Packet from: " + p.getSource() + " routed to: " + nextHop);
        for (String n : connections.keySet()) {
          if (n.equals(nextHop)) {
            connections.get(n).offer(p);
          }
        }
      }
    }
  }