Skip to content

Commit

Permalink
node-SDK: add support for using TLS with eventhub
Browse files Browse the repository at this point in the history
This patch adds support for using TLS with eventhub connection
and addresses FAB-429.

Change-Id: I8df2335c93c0a526706024c2e32bcaccdb07f390
Signed-off-by: Patrick Mullaney <pm.mullaney@gmail.com>
  • Loading branch information
pmullaney committed Oct 1, 2016
1 parent 131b36c commit b8e4c98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions sdk/node/src/hfc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ export class Chain {
/**
* Set and connect to the peer to be used as the event source.
*/
eventHubConnect(peeraddr: string):void {
this.eventHub.setPeerAddr(peeraddr);
eventHubConnect(peerUrl: string, opts?:GRPCOptions):void {
this.eventHub.setPeerAddr(peerUrl, opts);
this.eventHub.connect();
};

Expand Down Expand Up @@ -2861,7 +2861,9 @@ export class ChainCodeCBE {
*/
export class EventHub {
// peer addr to connect to
private peeraddr: string;
private ep: Endpoint;
// grpc options
private opts: GRPCOptions;
// grpc events interface
private events: any;
// grpc event client interface
Expand All @@ -2880,12 +2882,14 @@ export class EventHub {
this.chaincodeRegistrants = new HashTable();
this.blockRegistrants = new Set();
this.txRegistrants = new HashTable();
this.peeraddr = null;
this.ep = null;
this.connected = false;
}

public setPeerAddr(peeraddr: string) {
this.peeraddr = peeraddr;
public setPeerAddr(peeraddr: string, opts?:GRPCOptions) {
let pem = getPemFromOpts(opts);
this.opts = getOptsFromOpts(opts);
this.ep = new Endpoint(peeraddr,pem);
}

public isconnected() {
Expand All @@ -2894,9 +2898,9 @@ export class EventHub {

public connect() {
if (this.connected) return;
if (!this.peeraddr) throw Error("Must set peer address before connecting.");
if (!this.ep) throw Error("Must set peer address before connecting.");
this.events = grpc.load(__dirname + "/protos/events.proto" ).protos;
this.client = new this.events.Events(this.peeraddr,grpc.credentials.createInsecure());
this.client = new this.events.Events(this.ep.addr, this.ep.creds, this.opts);
this.call = this.client.chat();
this.connected = true;
this.registerBlockEvent(this.txCallback);
Expand Down
2 changes: 1 addition & 1 deletion sdk/node/test/unit/event-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (fs.existsSync("tlsca.cert")) {
chain.setMemberServicesUrl("grpc://localhost:7054");
}
chain.addPeer("grpc://localhost:7051");
chain.eventHubConnect("localhost:7053");
chain.eventHubConnect("grpc://localhost:7053");

process.on('exit', function (){
chain.eventHubDisconnect();
Expand Down

0 comments on commit b8e4c98

Please sign in to comment.