boolean oobMulticast = false;
if (receivedPacket.isMulticast()) { // multicast messages may overlap with unicast ones if the original broadcast was sent as a unicast, say if the peers sentPacket wasn't empty
long maxIdInPacket = -1;
for (Iterator<Message> it = receivedPacket.iterator(); it.hasNext();) {
final Message message = it.next();
// if (message.getMessageId() < lastReceivedBroadcastId) {
// LOG.trace("Peer {} received a multicast message {} which has already been seen.", this, message);
// it.remove();
// }
maxIdInPacket = Math.max(maxIdInPacket, message.getMessageId());
}
if (maxIdInPacket < lastReceivedBroadcastId) {
LOG.debug("Peer {} received an out-of-band multicast packet {} which has already been seen.", this, receivedPacket);
oobMulticast = true;
}
}
if (receivedPacket.isEmpty())
return;
if (!oobMulticast && sentPacket != null) {
for (Iterator<Message> it = sentPacket.iterator(); it.hasNext();) {
final Message message = it.next();
// here we rely on Message.equals() to match request/response
if (message.isResponse() && !receivedPacket.contains(message)) {
LOG.debug("Peer {} removing response {} from sent packet because it was no longer asked for.", this, message);
it.remove(); // if our peer hasn't requested again then it must have received our response
}
}
}
for (Message message : receivedPacket) {
message.setTimestamp(receivedPacket.getTimestamp());
if (message.isBroadcast()) {
if (message.getMessageId() > lastReceivedBroadcastId)
lastReceivedBroadcastId = message.getMessageId();
}
// here we rely on Message.equals() to match request/response
if (message.isResponse()) {
final Message request = (sentPacket != null ? sentPacket.getMessage(message) : null);
if (request == null && !(isTimeout(message) || (broadcast && broadcastPeer.isTimeout(message)))) {
LOG.debug("Peer {} ignoring repeat response {}", this, message);
continue; // we may be re-receiving the response, so the request may be gone. in this case we don't need to pass the message again to the receiver
}
if (LOG.isDebugEnabled())
LOG.debug("Peer {} received response {} for request ({})", new Object[]{this, message, request != null ? request : "TIMEOUT"});
if (request != null) {
if (request.isBroadcast())
broadcastResponses.add(message);
// if(message.getType() == Message.Type.CHNGD_OWNR && ((Message.CHNGD_OWNR)message).getNewOwner() == message.getNode()) {
// // this is a quickReplyToBroadcast
// // TODO