Skip to content

Commit

Permalink
FABN-912 NodeSDK add connection options
Browse files Browse the repository at this point in the history
Allow a set of connection options to be common
and associated with the client. The client will apply
the common set to each new peer and orderer it builds
including peers and orderers that it builds for discovery.
The user will be allowed to override during create any
of the settings. The option set will originate in the
system configuration (default.json). Users will be
able to override or add new ones at anytime to the
client instance. The options may also be kept in the
common connection profile client section.

Change-Id: I06e27db8835b8453e6289bc1201f8e0d21802912
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Dec 5, 2018
1 parent 532e9d6 commit a688fc2
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 150 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/channel-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ event registrations of the shutdown by using the registered `errorCallBack`s.
#### `peer` parameter
This parameter must be included when getting a new instance of the
`ChannelEventHub`. The value may be a `Peer` instance or the name of a peer when
using a `connection profile` see [How to use a common network configuration file](tutorial-network-config.html).
using a `connection profile` see [How to use a common common connection profile file](tutorial-network-config.html).

#### `eventCallback` parameter
This parameter must be included. This is the callback function to be notified
Expand Down
5 changes: 4 additions & 1 deletion docs/tutorials/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ peers:
```
When a channel is created using the `client.getChannel()` after the client
instance has loaded a connection profile, the fabric-client will create peers
and assign them to the channel. Peers with the the `discover` role will be used
and assign them to the channel.
The peers and orderers will inherent the connection options as assigned to
the client instance. see {@link Client#addConnectionOptions}
Peers with the the `discover` role will be used
when the `channel.initialize()` is called and no peer is passed as a target.

```
Expand Down
17 changes: 14 additions & 3 deletions docs/tutorials/network-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ certificateAuthorities:
caName: caorg2
```

The following example will have an existing fabric client load a connection profile configuration. The definition will only contain client side definitions and no fabric network definitions. Calling for a load on an existing fabric client does an overlay of the top level sections in the file being loaded replacing the sections on those previously loaded. In this case the file being loaded only has a client section, therefore the loaded definition will now have the previously loaded channels, organizations, peers, orderers, and certificateAuthorities section definitions and the newly loaded client section definition. This allows for an existing fabric client to be able to work within different organization. Note: The the SDK's `grpc-max-send-message-length` default is -1 (unlimited).
The following example will have an existing fabric client load a connection profile configuration. The definition will only contain client side definitions and no fabric network definitions. The client may load a new profile at anytime, it will overlay the top level sections it contains of those previously loaded. In this case the file being loaded only has a client section, therefore the loaded definition will now have the previously loaded channels, organizations, peers, orderers, and certificateAuthorities section definitions and the newly loaded client section definition. This allows for an existing fabric client to be able to work within different organization.
Notice this client definition contains a `connection` section with an `options` attribute in the
client section. Settings defined here will be applied to new peer and orderer
instances the client creates.
This will include peers and orderers that will be created automatically when
using the discovery service.
Peers and Orderers may override these connection settings in their `grpcOptions` settings.

Note: The fabric-client `grpc-max-send-message-length` and `grpc-max-receive-message-length` defaults are -1 (unlimited).
```
client.loadFromConfig('test/fixtures/org1.yaml');
```
Expand All @@ -159,6 +167,9 @@ client:
path: "/tmp/hfc-kvs/org1"
cryptoStore:
path: "/tmp/hfc-cvs/org1"
connection:
options
grpc.keepalive_time_ms: 120000
```

### Setup the stores
Expand Down Expand Up @@ -192,7 +203,7 @@ fabric_ca_client.register({enrollmentID: 'user1', affiliation: 'org1'}, admin)
}).then((user)=> {
```
### Work with mutual TLS
When your network configuration includes mutual TLS, the client certificate and private key must be available to the client instance before the endpoints are automatically built. The client instance will be able to pass the required material to the endpoint instance that is needed to establish the connection. The example shown will also retrieve the material. These steps must be performed before any actions on the fabric network.
When your network is using mutual TLS, the client certificate and private key must be available to the client instance before the endpoints are automatically built. The client instance will be able to pass the required material to the endpoint instance that is needed to establish the connection. The example shown will also retrieve the material. These steps must be performed before any actions on the fabric network.
```
// get the CA associated with this client's organization
let fabric_ca_client = client.getCertificateAuthority();
Expand Down Expand Up @@ -221,7 +232,7 @@ Notice in the organizations section of the connection profile configuration that
client.setAdminSigningIdentity('admin privateKey','admin cert');
```

Assume that connection profile configurations have been loaded, setting up both an organization with an admin and indicating that the client is in that organization. Then when the call is made to get a transaction id object, the fabric client will check to see if an admin has been assigned to the fabric client and use that to generate the transaction id. The transaction id returned will be tagged that it was generated with the assigned administrative identity. Notice how the request object being built is using just a name for the orderer rather than a `Orderer` object. The fabric client will look up this name in the loaded connection profile configuration. When the `createChannel` call is made, the fabric client will know that this action should be signed by the administrative identity because the transaction id was marked as an admin based transaction. Note that the administrative signing identity is not required if the logged in user is an administrative user and has been assigned to the fabric client.
Assume that a common connection profile has been loaded, setting up both an organization with an admin and indicating that the client is in that organization. Then when the call is made to get a transaction id object, the fabric client will check to see if an admin has been assigned to the fabric client and use that to generate the transaction id. The transaction id returned will be tagged that it was generated with the assigned administrative identity. Notice how the request object being built is using just a name for the orderer rather than an `Orderer` object. The fabric client will look up this name in the loaded connection profile configuration. When the `createChannel` call is made, the fabric client will know that this action should be signed by the administrative identity because the transaction id was marked as an admin based transaction. Note that the administrative signing identity is not required if the logged in user is an administrative user and has been assigned to the fabric client.
```
let tx_id = client.newTransactionID(true);
Expand Down
11 changes: 9 additions & 2 deletions fabric-client/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
"certificate-authority-client": "fabric-ca-client",
"nonce-size" : 24,
"grpc-ssl-cipher-suites": "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384",
"grpc.max_receive_message_length": -1,
"grpc.max_send_message_length": -1,
"connection-options": {
"grpc.max_receive_message_length": -1,
"grpc.max_send_message_length": -1,
"grpc.keepalive_time_ms": 120000,
"grpc.http2.min_time_between_pings_ms": 120000,
"grpc.keepalive_timeout_ms": 20000,
"grpc.http2.max_pings_without_data": 0,
"grpc.keepalive_permit_without_calls": 1
},
"network-config-schema" : {
"1.0": "./impl/NetworkConfig_1_0.js"
},
Expand Down
4 changes: 2 additions & 2 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ const Channel = class {
* added to the channel object.
* @param {boolean} useAdmin - Optional. Indicates that the admin credentials
* should be used in making this call to the peer. An administrative
* identity must have been loaded by network configuration or by
* identity must have been loaded by common connection profile or by
* using the 'setAdminSigningIdentity' method.
* @returns {Promise} A Promise for a fully decoded {@link ChaincodeQueryResponse} object.
*/
Expand Down Expand Up @@ -3383,7 +3383,7 @@ const Channel = class {
_getTargetForQuery(target) {
if (Array.isArray(target)) {
throw new Error('"target" parameter is an array, but should be a singular peer object' +
' ' + 'or peer name according to the network configuration loaded by the client instance');
' ' + 'or peer name according to the common connection profile loaded by the client instance');
}

const targets = this._getTargets(target, Constants.NetworkConfig.LEDGER_QUERY_ROLE, true);
Expand Down
Loading

0 comments on commit a688fc2

Please sign in to comment.