Fix bug in network simulator. (#830)

Fix bug in network simulator. It failed on cast when requesting signatures from notary, now it's not a SingleMessageRecipient but InMemoryMessagingNetwork.ServiceHandle.
This commit is contained in:
Katarzyna Streich 2017-06-12 14:39:40 +01:00 committed by GitHub
parent d3de125166
commit 58c25b1115
2 changed files with 12 additions and 3 deletions

View File

@ -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()

View File

@ -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())