use of org.jgroups.protocols.pbcast.NakAckHeader2 in project JGroups by belaban.
the class EncryptTest method testCapturingOfMessageByNonMemberAndResending.
/**
* Tests the scenario where the non-member R captures a message from some cluster member in {A,B,C}, then
* increments the NAKACK2 seqno and resends that message. The message must not be received by {A,B,C};
* it should be discarded. see https://issues.jboss.org/browse/JGRP-2273
*/
public void testCapturingOfMessageByNonMemberAndResending() throws Exception {
// this one won't succeed
for (JChannel ch : Arrays.asList(a, b, c)) {
SERIALIZE s = new SERIALIZE();
ch.getProtocolStack().insertProtocol(s, ProtocolStack.Position.ABOVE, Encrypt.class);
s.init();
}
rogue.setReceiver(new Receiver() {
public void receive(Message msg) {
System.out.printf("rogue: modifying and resending msg %s, hdrs: %s\n", msg, msg.printHeaders());
// to prevent recursive cycle
rogue.setReceiver(null);
try {
short prot_id = ClassConfigurator.getProtocolId(NAKACK2.class);
NakAckHeader2 hdr = msg.getHeader(prot_id);
if (hdr != null) {
long seqno = hdr.getSeqno();
Util.setField(Util.getField(NakAckHeader2.class, "seqno"), hdr, seqno + 1);
} else {
System.out.printf("Rogue was not able to get the %s header, fabricating one with seqno=50\n", NAKACK2.class.getSimpleName());
NakAckHeader2 hdr2 = NakAckHeader2.createMessageHeader(50);
msg.putHeader(prot_id, hdr2);
}
rogue.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
});
a.send(null, "Hello world from A");
// everybody in {A,B,C} should receive this message, but NOT the rogue's resent message
for (int i = 0; i < 10; i++) {
if (ra.size() > 1 || rb.size() > 1 || rc.size() > 1)
// this should NOT happen
break;
Util.sleep(500);
}
Stream.of(ra, rb, rc).map(MyReceiver::list).map(l -> l.stream().map(msg -> (String) msg.getObject()).collect(Collectors.toList())).forEach(System.out::println);
assert ra.size() == 1 : String.format("received msgs from non-member: '%s'; this should not be the case", print(ra.list()));
assert rb.size() == 1 : String.format("received msgs from non-member: '%s'; this should not be the case", print(rb.list()));
assert rc.size() == 1 : String.format("received msgs from non-member: '%s'; this should not be the case", print(rc.list()));
}
use of org.jgroups.protocols.pbcast.NakAckHeader2 in project JGroups by belaban.
the class MessageTestBase method addHeaders.
protected static void addHeaders(Message msg) {
TpHeader tp_hdr = new TpHeader("DemoChannel2");
msg.putHeader(UDP_ID, tp_hdr);
PingHeader ping_hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName("demo-cluster");
msg.putHeader(PING_ID, ping_hdr);
NakAckHeader2 nak_hdr = NakAckHeader2.createXmitRequestHeader(Util.createRandomAddress("S"));
msg.putHeader(NAKACK_ID, nak_hdr);
}
Aggregations