use of com.radixdlt.network.messaging.InboundMessage in project radixdlt by radixdlt.
the class MessageCentralFuzzyTest method fuzzy_messaged_are_not_accepted.
@Test
@SuppressWarnings("unchecked")
public void fuzzy_messaged_are_not_accepted() throws Exception {
var inboundMessages = PublishSubject.<InboundMessage>create();
var config = mock(MessageCentralConfiguration.class);
var peerControl = mock(PeerControl.class);
var peerManager = mock(PeerManager.class);
var queueFactory = mock(EventQueueFactory.class);
when(config.messagingOutboundQueueMax(anyInt())).thenReturn(1);
when(config.messagingTimeToLive(anyLong())).thenReturn(30_000L);
when(peerManager.messages()).thenReturn(inboundMessages);
when(queueFactory.createEventQueue(anyInt(), any(Comparator.class))).thenReturn(new SimplePriorityBlockingQueue<>(1, OutboundMessageEvent.comparator()));
var messageCentral = new MessageCentralImpl(config, serialization, peerManager, Time::currentTimestamp, queueFactory, new SystemCountersImpl(), () -> peerControl, Addressing.ofNetwork(Network.LOCALNET));
var counter = new AtomicLong(0);
var disposable = messageCentral.messagesOf(Message.class).subscribe(nextItem -> counter.incrementAndGet(), error -> fail(error.getMessage()));
// Insert single valid message to ensure whole pipeline is working properly
emitSingleValidMessage(inboundMessages);
// Insert batch of randomly generated messages
emitFuzzyMessages(inboundMessages);
disposable.dispose();
// Ensure that only one (valid) message passed through
assertEquals(1L, counter.get());
}
use of com.radixdlt.network.messaging.InboundMessage in project radixdlt by radixdlt.
the class PeerManagerStaticTest method should_cleanup_existing_entries_from_same_host_port_on_successful_connect.
@Test
public void should_cleanup_existing_entries_from_same_host_port_on_successful_connect() {
var self = makeNodeUri("10.0.0.1", 30000);
var addressBook = new AddressBook(self, mock(P2PConfig.class), cmock(new TypeLiteral<EventDispatcher<PeerEvent>>() {
}), new InMemoryAddressBookPersistence());
var peerManager = new PeerManager(self, P2PConfig.fromRuntimeProperties(defaultProperties()), Addressing.ofNetwork(Network.LOCALNET), () -> addressBook, () -> mock(PendingOutboundChannelsManager.class), mock(SystemCounters.class));
var peer1 = makeNodeUri("10.0.0.2", 30000);
// second address for same peer
var peer2 = makeNodeUri(peer1.getNodeId().getPublicKey(), "10.0.0.2", 30001);
addressBook.addUncheckedPeers(Set.of(peer1, peer2));
// Before connect
addressBook.findById(peer2.getNodeId()).ifPresentOrElse(entry -> assertEquals(2L, entry.getKnownAddresses().stream().count()), Assert::fail);
var peerChanel = mock(PeerChannel.class);
var inboundMessages = cmock(new TypeLiteral<Flowable<InboundMessage>>() {
});
// new key, but same host/port as peer2
var peer = makeNodeUri("10.0.0.2", 30000);
when(peerChanel.getUri()).thenReturn(Optional.of(peer));
when(peerChanel.inboundMessages()).thenReturn(inboundMessages);
when(inboundMessages.toObservable()).thenReturn(cmock(new TypeLiteral<Observable<InboundMessage>>() {
}));
when(peerChanel.isOutbound()).thenReturn(true);
when(peerChanel.getRemoteNodeId()).thenReturn(peer.getNodeId());
peerManager.peerEventProcessor().process(new PeerConnected(peerChanel));
// One address is removed
addressBook.findById(peer2.getNodeId()).ifPresentOrElse(entry -> assertEquals(1L, entry.getKnownAddresses().stream().count()), Assert::fail);
addressBook.findById(peer2.getNodeId()).ifPresentOrElse(entry -> assertEquals(peer2, entry.getKnownAddresses().stream().map(PeerAddressEntry::getUri).iterator().next()), Assert::fail);
}
Aggregations