diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt index 96b0ec170a..201a6e492d 100644 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt +++ b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt @@ -12,7 +12,6 @@ import javafx.scene.layout.VBox import javafx.stage.Stage import javafx.util.Duration import net.corda.core.crypto.commonName -import net.corda.core.messaging.SingleMessageRecipient import net.corda.core.serialization.deserialize import net.corda.core.then import net.corda.core.utilities.ProgressTracker @@ -112,7 +111,7 @@ class NetworkMapVisualiser : Application() { // Fire the message bullets between nodes. simulation.mockNet.messagingNetwork.sentMessages.observeOn(uiThread).subscribe { msg: InMemoryMessagingNetwork.MessageTransfer -> val senderNode: MockNetwork.MockNode = simulation.mockNet.addressToNode(msg.sender) - val destNode: MockNetwork.MockNode = simulation.mockNet.addressToNode(msg.recipients as SingleMessageRecipient) + val destNode: MockNetwork.MockNode = simulation.mockNet.addressToNode(msg.recipients) if (transferIsInteresting(msg)) { viewModel.nodesToWidgets[senderNode]!!.pulseAnim.play() diff --git a/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt b/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt index f316911fcb..beacfa2b41 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -8,6 +8,7 @@ import net.corda.core.* import net.corda.core.crypto.entropyToKeyPair import net.corda.flows.TxKeyFlow import net.corda.core.identity.PartyAndCertificate +import net.corda.core.messaging.MessageRecipients import net.corda.core.messaging.RPCOps import net.corda.core.messaging.SingleMessageRecipient import net.corda.core.node.CordaPluginRegistry @@ -385,7 +386,16 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, } @Suppress("unused") // This is used from the network visualiser tool. - fun addressToNode(address: SingleMessageRecipient): MockNode = nodes.single { it.network.myAddress == address } + fun addressToNode(msgRecipient: MessageRecipients): MockNode { + return when (msgRecipient) { + is SingleMessageRecipient -> nodes.single { it.network.myAddress == msgRecipient } + is InMemoryMessagingNetwork.ServiceHandle -> { + nodes.filter { it.advertisedServices.any { it == msgRecipient.service.info } }.firstOrNull() + ?: throw IllegalArgumentException("Couldn't find node advertising service with info: ${msgRecipient.service.info} ") + } + else -> throw IllegalArgumentException("Method not implemented for different type of message recipients") + } + } fun startNodes() { require(nodes.isNotEmpty())