From 2d557d04b436947922be52b6c5e244c04a905e8f Mon Sep 17 00:00:00 2001 From: Joel Dudley Date: Tue, 30 Jan 2018 16:06:20 +0000 Subject: [PATCH 1/2] Minor rewrites. Better documentation of granting RPC permissions to RPC users. --- docs/source/clientrpc.rst | 102 ++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/docs/source/clientrpc.rst b/docs/source/clientrpc.rst index 0b9e83afa4..38602ad5b7 100644 --- a/docs/source/clientrpc.rst +++ b/docs/source/clientrpc.rst @@ -1,32 +1,35 @@ Client RPC ========== -There are multiple ways to interact with a node from a *client program*, but if your client is written in a JVM -compatible language the easiest way to do so is using the client library. The library connects to your running -node using a message queue protocol and then provides a simple RPC interface to interact with it. You make calls -on a Java object as normal, and the marshalling back and forth is handled for you. +.. contents:: -The starting point for the client library is the `CordaRPCClient`_ class. This provides a ``start`` method that -returns a `CordaRPCConnection`_, holding an implementation of the `CordaRPCOps`_ that may be accessed with ``proxy`` -in Kotlin and ``getProxy()`` in Java. Observables that are returned by RPCs can be subscribed to in order to receive -an ongoing stream of updates from the node. More detail on how to use this is provided in the docs for the proxy method. +Overview +-------- +Corda provides a client library that allows you to easily write clients in a JVM-compatible language to interact +with a running node. The library connects to the node using a message queue protocol and then provides a simple RPC +interface to interact with the node. You make calls on a Java object as normal, and the marshalling back and forth is +handled for you. + +The starting point for the client library is the `CordaRPCClient`_ class. `CordaRPCClient`_ provides a ``start`` method +that returns a `CordaRPCConnection`_. A `CordaRPCConnection`_ allows you to access an implementation of the +`CordaRPCOps`_ interface with ``proxy`` in Kotlin or ``getProxy()`` in Java. The observables that are returned by RPC +operations can be subscribed to in order to receive an ongoing stream of updates from the node. More detail on this +functionality is provided in the docs for the ``proxy`` method. .. warning:: The returned `CordaRPCConnection`_ is somewhat expensive to create and consumes a small amount of server side resources. When you're done with it, call ``close`` on it. Alternatively you may use the ``use`` method on `CordaRPCClient`_ which cleans up automatically after the passed in lambda finishes. Don't create a new proxy for every call you make - reuse an existing one. -For a brief tutorial on how one can use the RPC API see :doc:`tutorial-clientrpc-api`. +For a brief tutorial on using the RPC API, see :doc:`tutorial-clientrpc-api`. RPC permissions --------------- -If a node's owner needs to interact with their node via RPC (e.g. to read the contents of the node's storage), they -must define one or more RPC users. Each user is authenticated with a username and password, and is assigned a set of -permissions that RPC can use for fine-grain access control. +For a node's owner to interact with their node via RPC, they must define one or more RPC users. Each user is +authenticated with a username and password, and is assigned a set of permissions that control which RPC operations they +can perform. -These users are added to the node's ``node.conf`` file. - -The simplest way of adding an RPC user is to include it in the ``rpcUsers`` list: +RPC users are created by adding them to the ``rpcUsers`` list in the node's ``node.conf`` file: .. container:: codeset @@ -41,7 +44,12 @@ The simplest way of adding an RPC user is to include it in the ``rpcUsers`` list ... ] -Users need permissions to invoke any RPC call. By default, nothing is allowed. These permissions are specified as follows: +By default, RPC users are not permissioned to perform any RPC operations. + +Granting flow permissions +~~~~~~~~~~~~~~~~~~~~~~~~~ +You provide an RPC user with the permission to start a specific flow using the syntax +``StartFlow.``: .. container:: codeset @@ -59,14 +67,64 @@ Users need permissions to invoke any RPC call. By default, nothing is allowed. T ... ] -Permissions Syntax -^^^^^^^^^^^^^^^^^^ +You can also provide an RPC user with the permission to start any flow using the syntax +``InvokeRpc.startFlow``: -Fine grained permissions allow a user to invoke a specific RPC operation, or to start a specific flow. The syntax is: +.. container:: codeset -- to start a specific flow: ``StartFlow.`` e.g., ``StartFlow.net.corda.flows.ExampleFlow1``. -- to invoke a RPC operation: ``InvokeRpc.`` e.g., ``InvokeRpc.nodeInfo``. -.. note:: Permission ``InvokeRpc.startFlow`` allows a user to initiate all flows. + .. sourcecode:: groovy + + rpcUsers=[ + { + username=exampleUser + password=examplePass + permissions=[ + "InvokeRpc.startFlow" + ] + } + ... + ] + +Granting other RPC permissions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +You provide an RPC user with the permission to perform a specific RPC operation using the syntax +``InvokeRpc.``: + +.. container:: codeset + + .. sourcecode:: groovy + + rpcUsers=[ + { + username=exampleUser + password=examplePass + permissions=[ + "InvokeRpc.nodeInfo", + "InvokeRpc.networkMapSnapshot" + ] + } + ... + ] + +Granting all permissions +~~~~~~~~~~~~~~~~~~~~~~~~ +You can provide an RPC user with the permission to perform any RPC operation (including starting any flow) using the +``ALL`` permission: + +.. container:: codeset + + .. sourcecode:: groovy + + rpcUsers=[ + { + username=exampleUser + password=examplePass + permissions=[ + "ALL" + ] + } + ... + ] RPC security management ----------------------- From ceff50d6565989765413eab7051bf87211b253cc Mon Sep 17 00:00:00 2001 From: Matthew Nesbit Date: Tue, 30 Jan 2018 16:29:59 +0000 Subject: [PATCH 2/2] Refactor location of bridge code to allow out of process bridging (#2431) Fix some issues Andras has seen --- .../internal}/ArtemisMessagingClient.kt | 2 +- .../internal/bridging}/AMQPBridgeManager.kt | 13 ++++++----- .../bridging}/BridgeControlListener.kt | 12 +++++----- .../{ => bridging}/BridgeControlMessages.kt | 2 +- .../internal/bridging}/BridgeManager.kt | 4 ++-- .../engine/ConnectionStateMachine.kt | 8 +++---- .../protonwrapper/engine/EventProcessor.kt | 8 +++---- .../protonwrapper/engine/NettyWritable.kt | 2 +- .../messages/ApplicationMessage.kt | 2 +- .../protonwrapper/messages/MessageStatus.kt | 2 +- .../protonwrapper/messages/ReceivedMessage.kt | 2 +- .../protonwrapper/messages/SendableMessage.kt | 2 +- .../messages/impl/ReceivedMessageImpl.kt | 6 ++--- .../messages/impl/SendableMessageImpl.kt | 6 ++--- .../protonwrapper/netty/AMQPChannelHandler.kt | 10 ++++---- .../protonwrapper/netty/AMQPClient.kt | 8 +++---- .../protonwrapper/netty/AMQPServer.kt | 8 +++---- .../protonwrapper/netty/ConnectionChange.kt | 2 +- .../internal/protonwrapper/netty/SSLHelper.kt | 2 +- .../net/corda/node/amqp/AMQPBridgeTest.kt | 8 +++---- .../net/corda/node/amqp/ProtonWrapperTests.kt | 8 +++---- .../kotlin/net/corda/node/internal/Node.kt | 1 + .../services/messaging/P2PMessagingClient.kt | 23 +++++++++++-------- .../services/messaging/RPCMessagingClient.kt | 1 + .../messaging/VerifierMessagingClient.kt | 1 + 25 files changed, 75 insertions(+), 68 deletions(-) rename {node/src/main/kotlin/net/corda/node/services/messaging => node-api/src/main/kotlin/net/corda/nodeapi/internal}/ArtemisMessagingClient.kt (98%) rename {node/src/main/kotlin/net/corda/node/services/messaging => node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging}/AMQPBridgeManager.kt (94%) rename {node/src/main/kotlin/net/corda/node/services/messaging => node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging}/BridgeControlListener.kt (93%) rename node-api/src/main/kotlin/net/corda/nodeapi/internal/{ => bridging}/BridgeControlMessages.kt (98%) rename {node/src/main/kotlin/net/corda/node/services/messaging => node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging}/BridgeManager.kt (78%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/engine/ConnectionStateMachine.kt (98%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/engine/EventProcessor.kt (94%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/engine/NettyWritable.kt (96%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/ApplicationMessage.kt (85%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/MessageStatus.kt (68%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/ReceivedMessage.kt (83%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/SendableMessage.kt (78%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt (86%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/messages/impl/SendableMessageImpl.kt (86%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/netty/AMQPChannelHandler.kt (95%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/netty/AMQPClient.kt (96%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/netty/AMQPServer.kt (96%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/netty/ConnectionChange.kt (55%) rename {node/src/main/kotlin/net/corda/node => node-api/src/main/kotlin/net/corda/nodeapi}/internal/protonwrapper/netty/SSLHelper.kt (97%) diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingClient.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/ArtemisMessagingClient.kt similarity index 98% rename from node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingClient.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/ArtemisMessagingClient.kt index 72d0e1ca07..99b3ab8e38 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingClient.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/ArtemisMessagingClient.kt @@ -1,4 +1,4 @@ -package net.corda.node.services.messaging +package net.corda.nodeapi.internal import net.corda.core.serialization.internal.nodeSerializationEnv import net.corda.core.utilities.NetworkHostAndPort diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/AMQPBridgeManager.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/AMQPBridgeManager.kt similarity index 94% rename from node/src/main/kotlin/net/corda/node/services/messaging/AMQPBridgeManager.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/AMQPBridgeManager.kt index a6e2dbe7a5..523369b370 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/AMQPBridgeManager.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/AMQPBridgeManager.kt @@ -1,4 +1,4 @@ -package net.corda.node.services.messaging +package net.corda.nodeapi.internal.bridging import io.netty.channel.EventLoopGroup import io.netty.channel.nio.NioEventLoopGroup @@ -7,14 +7,15 @@ import net.corda.core.internal.VisibleForTesting import net.corda.core.node.NodeInfo import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.debug -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.netty.AMQPClient -import net.corda.node.services.config.NodeConfiguration -import net.corda.node.services.messaging.AMQPBridgeManager.AMQPBridge.Companion.getBridgeName +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.NODE_USER import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.PEER_USER import net.corda.nodeapi.internal.ArtemisMessagingComponent.RemoteInboxAddress.Companion.translateLocalQueueToInboxAddress +import net.corda.nodeapi.internal.bridging.AMQPBridgeManager.AMQPBridge.Companion.getBridgeName +import net.corda.nodeapi.internal.config.NodeSSLConfiguration +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.netty.AMQPClient import org.apache.activemq.artemis.api.core.SimpleString import org.apache.activemq.artemis.api.core.client.ActiveMQClient.DEFAULT_ACK_BATCH_SIZE import org.apache.activemq.artemis.api.core.client.ClientConsumer @@ -34,7 +35,7 @@ import kotlin.concurrent.withLock * The Netty thread pool used by the AMQPBridges is also shared and managed by the AMQPBridgeManager. */ @VisibleForTesting -class AMQPBridgeManager(val config: NodeConfiguration, val p2pAddress: NetworkHostAndPort, val maxMessageSize: Int) : BridgeManager { +class AMQPBridgeManager(val config: NodeSSLConfiguration, val p2pAddress: NetworkHostAndPort, val maxMessageSize: Int) : BridgeManager { private val lock = ReentrantLock() private val bridgeNameToBridgeMap = mutableMapOf() diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/BridgeControlListener.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlListener.kt similarity index 93% rename from node/src/main/kotlin/net/corda/node/services/messaging/BridgeControlListener.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlListener.kt index f7706b6b9d..570f28cf48 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/BridgeControlListener.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlListener.kt @@ -1,25 +1,25 @@ -package net.corda.node.services.messaging +package net.corda.nodeapi.internal.bridging import net.corda.core.serialization.SerializationDefaults import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.contextLogger -import net.corda.node.services.config.NodeConfiguration +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.BRIDGE_CONTROL import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.BRIDGE_NOTIFY import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.P2P_PREFIX import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.PEERS_PREFIX -import net.corda.nodeapi.internal.BridgeControl +import net.corda.nodeapi.internal.config.NodeSSLConfiguration import org.apache.activemq.artemis.api.core.RoutingType import org.apache.activemq.artemis.api.core.SimpleString import org.apache.activemq.artemis.api.core.client.ClientConsumer import org.apache.activemq.artemis.api.core.client.ClientMessage import java.util.* -internal class BridgeControlListener(val config: NodeConfiguration, - val p2pAddress: NetworkHostAndPort, - val maxMessageSize: Int) : AutoCloseable { +class BridgeControlListener(val config: NodeSSLConfiguration, + val p2pAddress: NetworkHostAndPort, + val maxMessageSize: Int) : AutoCloseable { private val bridgeId: String = UUID.randomUUID().toString() private val bridgeManager: BridgeManager = AMQPBridgeManager(config, p2pAddress, maxMessageSize) private val validInboundQueues = mutableSetOf() diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/BridgeControlMessages.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlMessages.kt similarity index 98% rename from node-api/src/main/kotlin/net/corda/nodeapi/internal/BridgeControlMessages.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlMessages.kt index a9ec02a109..6a2f30bcd4 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/BridgeControlMessages.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeControlMessages.kt @@ -1,4 +1,4 @@ -package net.corda.nodeapi.internal +package net.corda.nodeapi.internal.bridging import net.corda.core.identity.CordaX500Name import net.corda.core.serialization.CordaSerializable diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/BridgeManager.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeManager.kt similarity index 78% rename from node/src/main/kotlin/net/corda/node/services/messaging/BridgeManager.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeManager.kt index 3d87e10af0..cd7db964cf 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/BridgeManager.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/BridgeManager.kt @@ -1,4 +1,4 @@ -package net.corda.node.services.messaging +package net.corda.nodeapi.internal.bridging import net.corda.core.identity.CordaX500Name import net.corda.core.internal.VisibleForTesting @@ -6,7 +6,7 @@ import net.corda.core.node.NodeInfo import net.corda.core.utilities.NetworkHostAndPort /** - * Provides an internal interface that the [ArtemisMessagingServer] delegates to for Bridge activities. + * Provides an internal interface that the [BridgeControlListener] delegates to for Bridge activities. */ @VisibleForTesting interface BridgeManager : AutoCloseable { diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/ConnectionStateMachine.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/ConnectionStateMachine.kt similarity index 98% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/ConnectionStateMachine.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/ConnectionStateMachine.kt index 6812f3fc70..1ab83fcc4e 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/ConnectionStateMachine.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/ConnectionStateMachine.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.engine +package net.corda.nodeapi.internal.protonwrapper.engine import io.netty.buffer.ByteBuf import io.netty.buffer.PooledByteBufAllocator @@ -7,9 +7,9 @@ import io.netty.channel.Channel import io.netty.channel.ChannelHandlerContext import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.debug -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.messages.impl.ReceivedMessageImpl -import net.corda.node.internal.protonwrapper.messages.impl.SendableMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.messages.impl.ReceivedMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.impl.SendableMessageImpl import org.apache.qpid.proton.Proton import org.apache.qpid.proton.amqp.Binary import org.apache.qpid.proton.amqp.Symbol diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/EventProcessor.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/EventProcessor.kt similarity index 94% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/EventProcessor.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/EventProcessor.kt index 31c7de7aed..14c21b97f2 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/EventProcessor.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/EventProcessor.kt @@ -1,12 +1,12 @@ -package net.corda.node.internal.protonwrapper.engine +package net.corda.nodeapi.internal.protonwrapper.engine import io.netty.buffer.ByteBuf import io.netty.channel.Channel import io.netty.channel.ChannelHandlerContext import net.corda.core.utilities.debug -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.messages.impl.ReceivedMessageImpl -import net.corda.node.internal.protonwrapper.messages.impl.SendableMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.messages.impl.ReceivedMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.impl.SendableMessageImpl import org.apache.qpid.proton.Proton import org.apache.qpid.proton.amqp.messaging.Accepted import org.apache.qpid.proton.amqp.messaging.Rejected diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/NettyWritable.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/NettyWritable.kt similarity index 96% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/NettyWritable.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/NettyWritable.kt index b8e8085273..1bb97851ed 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/engine/NettyWritable.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/engine/NettyWritable.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.engine +package net.corda.nodeapi.internal.protonwrapper.engine import io.netty.buffer.ByteBuf import org.apache.qpid.proton.codec.WritableBuffer diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ApplicationMessage.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ApplicationMessage.kt similarity index 85% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ApplicationMessage.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ApplicationMessage.kt index f90c1b172a..f42116f950 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ApplicationMessage.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ApplicationMessage.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.messages +package net.corda.nodeapi.internal.protonwrapper.messages import net.corda.core.utilities.NetworkHostAndPort diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/MessageStatus.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/MessageStatus.kt similarity index 68% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/MessageStatus.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/MessageStatus.kt index 6b792dd59e..ca696a2a45 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/MessageStatus.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/MessageStatus.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.messages +package net.corda.nodeapi.internal.protonwrapper.messages /** * The processing state of a message. diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ReceivedMessage.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ReceivedMessage.kt similarity index 83% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ReceivedMessage.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ReceivedMessage.kt index df4a1fddff..bd3a11aa23 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/ReceivedMessage.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/ReceivedMessage.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.messages +package net.corda.nodeapi.internal.protonwrapper.messages import net.corda.core.utilities.NetworkHostAndPort diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/SendableMessage.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/SendableMessage.kt similarity index 78% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/SendableMessage.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/SendableMessage.kt index bc4a405e26..b6dd1a4167 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/SendableMessage.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/SendableMessage.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.messages +package net.corda.nodeapi.internal.protonwrapper.messages import net.corda.core.concurrent.CordaFuture diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt similarity index 86% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt index 1d5f25d59f..15c893e41a 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/ReceivedMessageImpl.kt @@ -1,9 +1,9 @@ -package net.corda.node.internal.protonwrapper.messages.impl +package net.corda.nodeapi.internal.protonwrapper.messages.impl import io.netty.channel.Channel import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.messages.ReceivedMessage +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.messages.ReceivedMessage import org.apache.qpid.proton.engine.Delivery /** diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/SendableMessageImpl.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/SendableMessageImpl.kt similarity index 86% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/SendableMessageImpl.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/SendableMessageImpl.kt index 52dd1ed08f..13065c960e 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/messages/impl/SendableMessageImpl.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/messages/impl/SendableMessageImpl.kt @@ -1,11 +1,11 @@ -package net.corda.node.internal.protonwrapper.messages.impl +package net.corda.nodeapi.internal.protonwrapper.messages.impl import io.netty.buffer.ByteBuf import net.corda.core.concurrent.CordaFuture import net.corda.core.internal.concurrent.openFuture import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.messages.SendableMessage +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.messages.SendableMessage /** * An internal packet management class that allows handling of the encoded buffers and diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPChannelHandler.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPChannelHandler.kt similarity index 95% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPChannelHandler.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPChannelHandler.kt index 115dcb1da8..4054b7c7fd 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPChannelHandler.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPChannelHandler.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.netty +package net.corda.nodeapi.internal.protonwrapper.netty import io.netty.buffer.ByteBuf import io.netty.channel.ChannelDuplexHandler @@ -10,11 +10,11 @@ import io.netty.handler.ssl.SslHandshakeCompletionEvent import io.netty.util.ReferenceCountUtil import net.corda.core.identity.CordaX500Name import net.corda.core.utilities.debug -import net.corda.node.internal.protonwrapper.engine.EventProcessor -import net.corda.node.internal.protonwrapper.messages.ReceivedMessage -import net.corda.node.internal.protonwrapper.messages.impl.ReceivedMessageImpl -import net.corda.node.internal.protonwrapper.messages.impl.SendableMessageImpl import net.corda.nodeapi.internal.crypto.x509 +import net.corda.nodeapi.internal.protonwrapper.engine.EventProcessor +import net.corda.nodeapi.internal.protonwrapper.messages.ReceivedMessage +import net.corda.nodeapi.internal.protonwrapper.messages.impl.ReceivedMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.impl.SendableMessageImpl import org.apache.qpid.proton.engine.ProtonJTransport import org.apache.qpid.proton.engine.Transport import org.apache.qpid.proton.engine.impl.ProtocolTracer diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPClient.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPClient.kt similarity index 96% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPClient.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPClient.kt index 761248797f..7e8a8853f7 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPClient.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPClient.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.netty +package net.corda.nodeapi.internal.protonwrapper.netty import io.netty.bootstrap.Bootstrap import io.netty.channel.* @@ -12,9 +12,9 @@ import io.netty.util.internal.logging.Slf4JLoggerFactory import net.corda.core.identity.CordaX500Name import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.contextLogger -import net.corda.node.internal.protonwrapper.messages.ReceivedMessage -import net.corda.node.internal.protonwrapper.messages.SendableMessage -import net.corda.node.internal.protonwrapper.messages.impl.SendableMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.ReceivedMessage +import net.corda.nodeapi.internal.protonwrapper.messages.SendableMessage +import net.corda.nodeapi.internal.protonwrapper.messages.impl.SendableMessageImpl import rx.Observable import rx.subjects.PublishSubject import java.security.KeyStore diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPServer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPServer.kt similarity index 96% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPServer.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPServer.kt index 6398a6776b..588c7fb8a0 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/AMQPServer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/AMQPServer.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.netty +package net.corda.nodeapi.internal.protonwrapper.netty import io.netty.bootstrap.ServerBootstrap import io.netty.channel.Channel @@ -14,9 +14,9 @@ import io.netty.util.internal.logging.InternalLoggerFactory import io.netty.util.internal.logging.Slf4JLoggerFactory import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.contextLogger -import net.corda.node.internal.protonwrapper.messages.ReceivedMessage -import net.corda.node.internal.protonwrapper.messages.SendableMessage -import net.corda.node.internal.protonwrapper.messages.impl.SendableMessageImpl +import net.corda.nodeapi.internal.protonwrapper.messages.ReceivedMessage +import net.corda.nodeapi.internal.protonwrapper.messages.SendableMessage +import net.corda.nodeapi.internal.protonwrapper.messages.impl.SendableMessageImpl import org.apache.qpid.proton.engine.Delivery import rx.Observable import rx.subjects.PublishSubject diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/ConnectionChange.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/ConnectionChange.kt similarity index 55% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/ConnectionChange.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/ConnectionChange.kt index f0d83a8cf5..5488823de7 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/ConnectionChange.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/ConnectionChange.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.netty +package net.corda.nodeapi.internal.protonwrapper.netty import java.net.InetSocketAddress import java.security.cert.X509Certificate diff --git a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/SSLHelper.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/SSLHelper.kt similarity index 97% rename from node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/SSLHelper.kt rename to node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/SSLHelper.kt index 7a778d26cf..bf1be88377 100644 --- a/node/src/main/kotlin/net/corda/node/internal/protonwrapper/netty/SSLHelper.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/protonwrapper/netty/SSLHelper.kt @@ -1,4 +1,4 @@ -package net.corda.node.internal.protonwrapper.netty +package net.corda.nodeapi.internal.protonwrapper.netty import io.netty.handler.ssl.SslHandler import net.corda.core.utilities.NetworkHostAndPort diff --git a/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt b/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt index 38abdaa958..f13e73de06 100644 --- a/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt @@ -5,15 +5,15 @@ import com.nhaarman.mockito_kotlin.whenever import net.corda.core.crypto.toStringShort import net.corda.core.internal.div import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.protonwrapper.netty.AMQPServer import net.corda.node.services.config.CertChainPolicyConfig import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.configureWithDevSSLCertificate -import net.corda.node.services.messaging.AMQPBridgeManager -import net.corda.node.services.messaging.ArtemisMessagingClient import net.corda.node.services.messaging.ArtemisMessagingServer -import net.corda.node.services.messaging.BridgeManager +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent +import net.corda.nodeapi.internal.bridging.AMQPBridgeManager +import net.corda.nodeapi.internal.bridging.BridgeManager +import net.corda.nodeapi.internal.protonwrapper.netty.AMQPServer import net.corda.testing.core.* import net.corda.testing.internal.rigorousMock import org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID diff --git a/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt b/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt index 783b8cf533..64d7c09990 100644 --- a/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt @@ -8,16 +8,16 @@ import net.corda.core.identity.CordaX500Name import net.corda.core.internal.div import net.corda.core.toFuture import net.corda.core.utilities.NetworkHostAndPort -import net.corda.node.internal.protonwrapper.messages.MessageStatus -import net.corda.node.internal.protonwrapper.netty.AMQPClient -import net.corda.node.internal.protonwrapper.netty.AMQPServer import net.corda.node.services.config.CertChainPolicyConfig import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.configureWithDevSSLCertificate -import net.corda.node.services.messaging.ArtemisMessagingClient import net.corda.node.services.messaging.ArtemisMessagingServer +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.P2P_PREFIX import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.PEER_USER +import net.corda.nodeapi.internal.protonwrapper.messages.MessageStatus +import net.corda.nodeapi.internal.protonwrapper.netty.AMQPClient +import net.corda.nodeapi.internal.protonwrapper.netty.AMQPServer import net.corda.testing.core.* import net.corda.testing.internal.rigorousMock import org.apache.activemq.artemis.api.core.RoutingType diff --git a/node/src/main/kotlin/net/corda/node/internal/Node.kt b/node/src/main/kotlin/net/corda/node/internal/Node.kt index c80d5cebb1..8d5dbad49b 100644 --- a/node/src/main/kotlin/net/corda/node/internal/Node.kt +++ b/node/src/main/kotlin/net/corda/node/internal/Node.kt @@ -33,6 +33,7 @@ import net.corda.node.utilities.AffinityExecutor import net.corda.node.utilities.DemoClock import net.corda.nodeapi.internal.ShutdownHook import net.corda.nodeapi.internal.addShutdownHook +import net.corda.nodeapi.internal.bridging.BridgeControlListener import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.serialization.* import net.corda.nodeapi.internal.serialization.amqp.AMQPServerSerializationScheme diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt b/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt index 4e9d495b16..52195fd72c 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt @@ -24,12 +24,13 @@ import net.corda.node.services.statemachine.StateMachineManagerImpl import net.corda.node.utilities.AffinityExecutor import net.corda.node.utilities.AppendOnlyPersistentMap import net.corda.node.utilities.PersistentMap +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent.* import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.BRIDGE_CONTROL import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.BRIDGE_NOTIFY import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.PEERS_PREFIX -import net.corda.nodeapi.internal.BridgeControl -import net.corda.nodeapi.internal.BridgeEntry +import net.corda.nodeapi.internal.bridging.BridgeControl +import net.corda.nodeapi.internal.bridging.BridgeEntry import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException @@ -237,14 +238,16 @@ class P2PMessagingClient(config: NodeConfiguration, val bridgeConsumer = session.createConsumer(bridgeNotifyQueue) bridgeNotifyConsumer = bridgeConsumer bridgeConsumer.setMessageHandler { msg -> - val data: ByteArray = ByteArray(msg.bodySize).apply { msg.bodyBuffer.readBytes(this) } - val notifyMessage = data.deserialize(context = SerializationDefaults.P2P_CONTEXT) - log.info(notifyMessage.toString()) - when (notifyMessage) { - is BridgeControl.BridgeToNodeSnapshotRequest -> enumerateBridges(session, inboxes) - else -> log.error("Unexpected Bridge Control message type on notify topc $notifyMessage") + state.locked { + val data: ByteArray = ByteArray(msg.bodySize).apply { msg.bodyBuffer.readBytes(this) } + val notifyMessage = data.deserialize(context = SerializationDefaults.P2P_CONTEXT) + log.info(notifyMessage.toString()) + when (notifyMessage) { + is BridgeControl.BridgeToNodeSnapshotRequest -> enumerateBridges(session, inboxes) + else -> log.error("Unexpected Bridge Control message type on notify topc $notifyMessage") + } + msg.acknowledge() } - msg.acknowledge() } networkChangeSubscription = networkMap.changed.subscribe { updateBridgesOnNetworkChange(it) } } @@ -262,7 +265,7 @@ class P2PMessagingClient(config: NodeConfiguration, fun gatherAddresses(node: NodeInfo): Sequence { return node.legalIdentitiesAndCerts.map { val messagingAddress = NodeAddress(it.party.owningKey, node.addresses.first()) - BridgeEntry(messagingAddress.queueName, node.addresses, listOf(it.party.name)) + BridgeEntry(messagingAddress.queueName, node.addresses, node.legalIdentities.map { it.name }) }.filter { artemis.started!!.session.queueQuery(SimpleString(it.queueName)).isExists }.asSequence() } diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/RPCMessagingClient.kt b/node/src/main/kotlin/net/corda/node/services/messaging/RPCMessagingClient.kt index 874c030641..6543cbb6fb 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/RPCMessagingClient.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/RPCMessagingClient.kt @@ -5,6 +5,7 @@ import net.corda.core.messaging.RPCOps import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.utilities.NetworkHostAndPort import net.corda.node.internal.security.RPCSecurityManager +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.NODE_USER import net.corda.nodeapi.internal.config.SSLConfiguration import net.corda.nodeapi.internal.crypto.X509Utilities diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/VerifierMessagingClient.kt b/node/src/main/kotlin/net/corda/node/services/messaging/VerifierMessagingClient.kt index 9a8c82c4eb..4020542033 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/VerifierMessagingClient.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/VerifierMessagingClient.kt @@ -11,6 +11,7 @@ import net.corda.node.utilities.AffinityExecutor import net.corda.nodeapi.VerifierApi import net.corda.nodeapi.VerifierApi.VERIFICATION_REQUESTS_QUEUE_NAME import net.corda.nodeapi.VerifierApi.VERIFICATION_RESPONSES_QUEUE_NAME_PREFIX +import net.corda.nodeapi.internal.ArtemisMessagingClient import net.corda.nodeapi.internal.config.SSLConfiguration import org.apache.activemq.artemis.api.core.RoutingType import org.apache.activemq.artemis.api.core.SimpleString