aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-03-02 17:28:02 -0800
committerGravatar murgatroid99 <mlumish@google.com>2015-03-02 17:31:25 -0800
commitda02a67e0551228e5ecd2055c116310edd0aa202 (patch)
treedd875d1f69e8149b3b65d8752e29934b280654d3 /src
parent22176cbbf89aeef3128d4e01bc51014e11e3e28a (diff)
Updated Node library to new secure server API
Diffstat (limited to 'src')
-rw-r--r--src/node/ext/server.cc32
-rw-r--r--src/node/interop/interop_server.js10
-rw-r--r--src/node/src/server.js19
3 files changed, 27 insertions, 34 deletions
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index ab45da8d19..a87f9194e9 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -164,19 +164,7 @@ NAN_METHOD(Server::New) {
if (args[0]->IsUndefined()) {
wrapped_server = grpc_server_create(queue, NULL);
} else if (args[0]->IsObject()) {
- grpc_server_credentials *creds = NULL;
- Handle<Object> args_hash(args[0]->ToObject()->Clone());
- if (args_hash->HasOwnProperty(NanNew("credentials"))) {
- Handle<Value> creds_value = args_hash->Get(NanNew("credentials"));
- if (!ServerCredentials::HasInstance(creds_value)) {
- return NanThrowTypeError(
- "credentials arg must be a ServerCredentials object");
- }
- ServerCredentials *creds_object =
- ObjectWrap::Unwrap<ServerCredentials>(creds_value->ToObject());
- creds = creds_object->GetWrappedServerCredentials();
- args_hash->Delete(NanNew("credentials"));
- }
+ Handle<Object> args_hash(args[0]->ToObject());
Handle<Array> keys(args_hash->GetOwnPropertyNames());
grpc_channel_args channel_args;
channel_args.num_args = keys->Length();
@@ -203,11 +191,7 @@ NAN_METHOD(Server::New) {
return NanThrowTypeError("Arg values must be strings");
}
}
- if (creds == NULL) {
- wrapped_server = grpc_server_create(queue, &channel_args);
- } else {
- wrapped_server = grpc_secure_server_create(creds, queue, &channel_args);
- }
+ wrapped_server = grpc_server_create(queue, &channel_args);
free(channel_args.args);
} else {
return NanThrowTypeError("Server expects an object");
@@ -258,11 +242,19 @@ NAN_METHOD(Server::AddSecureHttp2Port) {
"addSecureHttp2Port can only be called on a Server");
}
if (!args[0]->IsString()) {
- return NanThrowTypeError("addSecureHttp2Port's argument must be a String");
+ return NanThrowTypeError(
+ "addSecureHttp2Port's first argument must be a String");
+ }
+ if (!ServerCredentials::HasInstance(args[1])) {
+ return NanThrowTypeError(
+ "addSecureHttp2Port's second argument must be ServerCredentials");
}
Server *server = ObjectWrap::Unwrap<Server>(args.This());
+ ServerCredentials *creds = ObjectWrap::Unwrap<ServerCredentials>(
+ args[1]->ToObject());
NanReturnValue(NanNew<Number>(grpc_server_add_secure_http2_port(
- server->wrapped_server, *NanUtf8String(args[0]))));
+ server->wrapped_server, *NanUtf8String(args[0]),
+ creds->GetWrappedServerCredentials())));
}
NAN_METHOD(Server::Start) {
diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js
index 125ede1746..8e5c03666f 100644
--- a/src/node/interop/interop_server.js
+++ b/src/node/interop/interop_server.js
@@ -165,16 +165,16 @@ function handleHalfDuplex(call) {
function getServer(port, tls) {
// TODO(mlumish): enable TLS functionality
var options = {};
+ var server_creds = null;
if (tls) {
var key_path = path.join(__dirname, '../test/data/server1.key');
var pem_path = path.join(__dirname, '../test/data/server1.pem');
var key_data = fs.readFileSync(key_path);
var pem_data = fs.readFileSync(pem_path);
- var server_creds = grpc.ServerCredentials.createSsl(null,
- key_data,
- pem_data);
- options.credentials = server_creds;
+ server_creds = grpc.ServerCredentials.createSsl(null,
+ key_data,
+ pem_data);
}
var server = new Server({
'grpc.testing.TestService' : {
@@ -186,7 +186,7 @@ function getServer(port, tls) {
halfDuplexCall: handleHalfDuplex
}
}, null, options);
- var port_num = server.bind('0.0.0.0:' + port, tls);
+ var port_num = server.bind('0.0.0.0:' + port, server_creds);
return {server: server, port: port_num};
}
diff --git a/src/node/src/server.js b/src/node/src/server.js
index 91dde02251..b72d110666 100644
--- a/src/node/src/server.js
+++ b/src/node/src/server.js
@@ -517,14 +517,15 @@ Server.prototype.register = function(name, handler, serialize, deserialize,
};
/**
- * Binds the server to the given port, with SSL enabled if secure is specified
+ * Binds the server to the given port, with SSL enabled if creds is given
* @param {string} port The port that the server should bind on, in the format
* "address:port"
- * @param {boolean=} secure Whether the server should open a secure port
+ * @param {boolean=} creds Server credential object to be used for SSL. Pass
+ * nothing for an insecure port
*/
-Server.prototype.bind = function(port, secure) {
- if (secure) {
- return this._server.addSecureHttp2Port(port);
+Server.prototype.bind = function(port, creds) {
+ if (creds) {
+ return this._server.addSecureHttp2Port(port, creds);
} else {
return this._server.addHttp2Port(port);
}
@@ -604,14 +605,14 @@ function makeServerConstructor(services) {
}
/**
- * Binds the server to the given port, with SSL enabled if secure is specified
+ * Binds the server to the given port, with SSL enabled if creds is supplied
* @param {string} port The port that the server should bind on, in the format
* "address:port"
- * @param {boolean=} secure Whether the server should open a secure port
+ * @param {boolean=} creds Credentials to use for SSL
* @return {SurfaceServer} this
*/
- SurfaceServer.prototype.bind = function(port, secure) {
- return this.inner_server.bind(port, secure);
+ SurfaceServer.prototype.bind = function(port, creds) {
+ return this.inner_server.bind(port, creds);
};
/**