Skip to content

Commit b8e4c98

Browse files
committed
node-SDK: add support for using TLS with eventhub
This patch adds support for using TLS with eventhub connection and addresses FAB-429. Change-Id: I8df2335c93c0a526706024c2e32bcaccdb07f390 Signed-off-by: Patrick Mullaney <[email protected]>
1 parent 131b36c commit b8e4c98

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

sdk/node/src/hfc.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ export class Chain {
567567
/**
568568
* Set and connect to the peer to be used as the event source.
569569
*/
570-
eventHubConnect(peeraddr: string):void {
571-
this.eventHub.setPeerAddr(peeraddr);
570+
eventHubConnect(peerUrl: string, opts?:GRPCOptions):void {
571+
this.eventHub.setPeerAddr(peerUrl, opts);
572572
this.eventHub.connect();
573573
};
574574

@@ -2861,7 +2861,9 @@ export class ChainCodeCBE {
28612861
*/
28622862
export class EventHub {
28632863
// peer addr to connect to
2864-
private peeraddr: string;
2864+
private ep: Endpoint;
2865+
// grpc options
2866+
private opts: GRPCOptions;
28652867
// grpc events interface
28662868
private events: any;
28672869
// grpc event client interface
@@ -2880,12 +2882,14 @@ export class EventHub {
28802882
this.chaincodeRegistrants = new HashTable();
28812883
this.blockRegistrants = new Set();
28822884
this.txRegistrants = new HashTable();
2883-
this.peeraddr = null;
2885+
this.ep = null;
28842886
this.connected = false;
28852887
}
28862888

2887-
public setPeerAddr(peeraddr: string) {
2888-
this.peeraddr = peeraddr;
2889+
public setPeerAddr(peeraddr: string, opts?:GRPCOptions) {
2890+
let pem = getPemFromOpts(opts);
2891+
this.opts = getOptsFromOpts(opts);
2892+
this.ep = new Endpoint(peeraddr,pem);
28892893
}
28902894

28912895
public isconnected() {
@@ -2894,9 +2898,9 @@ export class EventHub {
28942898

28952899
public connect() {
28962900
if (this.connected) return;
2897-
if (!this.peeraddr) throw Error("Must set peer address before connecting.");
2901+
if (!this.ep) throw Error("Must set peer address before connecting.");
28982902
this.events = grpc.load(__dirname + "/protos/events.proto" ).protos;
2899-
this.client = new this.events.Events(this.peeraddr,grpc.credentials.createInsecure());
2903+
this.client = new this.events.Events(this.ep.addr, this.ep.creds, this.opts);
29002904
this.call = this.client.chat();
29012905
this.connected = true;
29022906
this.registerBlockEvent(this.txCallback);

sdk/node/test/unit/event-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if (fs.existsSync("tlsca.cert")) {
4444
chain.setMemberServicesUrl("grpc://localhost:7054");
4545
}
4646
chain.addPeer("grpc://localhost:7051");
47-
chain.eventHubConnect("localhost:7053");
47+
chain.eventHubConnect("grpc://localhost:7053");
4848

4949
process.on('exit', function (){
5050
chain.eventHubDisconnect();

0 commit comments

Comments
 (0)