aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-08-12 19:53:03 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-08-12 19:53:03 +0200
commit9b6248fc6d3be0e3970e19138bedd0655e4565e8 (patch)
treeee2852ba33f5638d9d3973c944ccc604b5e6fb99 /src/node
parentb457cd831ad519d5ec023005ba6ccfb52ff4c9cb (diff)
parent3b226512d4aa84d58e1e61ce3f9adb9315f2d619 (diff)
Merge branch 'master' of github.com:grpc/grpc into the-ultimate-showdown
Conflicts: src/node/ext/call.cc src/node/ext/channel.cc
Diffstat (limited to 'src/node')
-rw-r--r--src/node/examples/perf_test.js2
-rw-r--r--src/node/ext/call.cc19
-rw-r--r--src/node/ext/channel.cc25
-rw-r--r--src/node/ext/channel.h6
-rw-r--r--src/node/interop/interop_client.js11
-rw-r--r--src/node/src/client.js59
-rw-r--r--src/node/test/call_test.js5
-rw-r--r--src/node/test/end_to_end_test.js8
8 files changed, 65 insertions, 70 deletions
diff --git a/src/node/examples/perf_test.js b/src/node/examples/perf_test.js
index 0f38725f72..214b9384d5 100644
--- a/src/node/examples/perf_test.js
+++ b/src/node/examples/perf_test.js
@@ -63,7 +63,7 @@ function runTest(iterations, callback) {
var timeDiff = process.hrtime(startTime);
intervals[i] = timeDiff[0] * 1000000 + timeDiff[1] / 1000;
next(i+1);
- }, {}, deadline);
+ }, {}, {deadline: deadline});
}
}
next(0);
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index 7e677ebd67..6fc1bc424f 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -510,10 +510,21 @@ NAN_METHOD(Call::New) {
NanUtf8String method(args[1]);
double deadline = args[2]->NumberValue();
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
- grpc_call *wrapped_call = grpc_channel_create_call(
- wrapped_channel, NULL, GRPC_PROPAGATE_DEFAULTS,
- CompletionQueueAsyncWorker::GetQueue(), *method, channel->GetHost(),
- MillisecondsToTimespec(deadline), NULL);
+ grpc_call *wrapped_call;
+ if (args[3]->IsString()) {
+ NanUtf8String host_override(args[3]);
+ wrapped_call = grpc_channel_create_call(
+ wrapped_channel, NULL, GRPC_PROPAGATE_DEFAULTS,
+ CompletionQueueAsyncWorker::GetQueue(), *method,
+ *host_override, MillisecondsToTimespec(deadline), NULL);
+ } else if (args[3]->IsUndefined() || args[3]->IsNull()) {
+ wrapped_call = grpc_channel_create_call(
+ wrapped_channel, NULL, GRPC_PROPAGATE_DEFAULTS,
+ CompletionQueueAsyncWorker::GetQueue(), *method,
+ NULL, MillisecondsToTimespec(deadline), NULL);
+ } else {
+ return NanThrowTypeError("Call's fourth argument must be a string");
+ }
call = new Call(wrapped_call);
args.This()->SetHiddenValue(NanNew("channel_"), channel_object);
}
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index 53b1522f46..3ff310f172 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -59,14 +59,12 @@ using v8::Value;
NanCallback *Channel::constructor;
Persistent<FunctionTemplate> Channel::fun_tpl;
-Channel::Channel(grpc_channel *channel, NanUtf8String *host)
- : wrapped_channel(channel), host(host) {}
+Channel::Channel(grpc_channel *channel) : wrapped_channel(channel) {}
Channel::~Channel() {
if (wrapped_channel != NULL) {
grpc_channel_destroy(wrapped_channel);
}
- delete host;
}
void Channel::Init(Handle<Object> exports) {
@@ -91,8 +89,6 @@ bool Channel::HasInstance(Handle<Value> val) {
grpc_channel *Channel::GetWrappedChannel() { return this->wrapped_channel; }
-char *Channel::GetHost() { return **this->host; }
-
NAN_METHOD(Channel::New) {
NanScope();
@@ -103,8 +99,7 @@ NAN_METHOD(Channel::New) {
}
grpc_channel *wrapped_channel;
// Owned by the Channel object
- NanUtf8String *host = new NanUtf8String(args[0]);
- NanUtf8String *host_override = NULL;
+ NanUtf8String host(args[0]);
grpc_credentials *creds;
if (!Credentials::HasInstance(args[1])) {
return NanThrowTypeError(
@@ -116,12 +111,9 @@ NAN_METHOD(Channel::New) {
grpc_channel_args *channel_args_ptr;
if (args[2]->IsUndefined()) {
channel_args_ptr = NULL;
- wrapped_channel = grpc_insecure_channel_create(**host, NULL, NULL);
+ wrapped_channel = grpc_insecure_channel_create(*host, NULL, NULL);
} else if (args[2]->IsObject()) {
Handle<Object> args_hash(args[2]->ToObject()->Clone());
- if (args_hash->HasOwnProperty(NanNew(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG))) {
- host_override = new NanUtf8String(args_hash->Get(NanNew(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
- }
Handle<Array> keys(args_hash->GetOwnPropertyNames());
grpc_channel_args channel_args;
channel_args.num_args = keys->Length();
@@ -153,20 +145,15 @@ NAN_METHOD(Channel::New) {
return NanThrowTypeError("Channel expects a string and an object");
}
if (creds == NULL) {
- wrapped_channel = grpc_insecure_channel_create(**host, channel_args_ptr);
+ wrapped_channel = grpc_insecure_channel_create(*host, channel_args_ptr);
} else {
wrapped_channel =
- grpc_secure_channel_create(creds, **host, channel_args_ptr);
+ grpc_secure_channel_create(creds, *host, channel_args_ptr);
}
if (channel_args_ptr != NULL) {
free(channel_args_ptr->args);
}
- Channel *channel;
- if (host_override == NULL) {
- channel = new Channel(wrapped_channel, host);
- } else {
- channel = new Channel(wrapped_channel, host_override);
- }
+ Channel *channel = new Channel(wrapped_channel);
channel->Wrap(args.This());
NanReturnValue(args.This());
} else {
diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h
index 6725ebb03f..e2182cb45c 100644
--- a/src/node/ext/channel.h
+++ b/src/node/ext/channel.h
@@ -53,11 +53,8 @@ class Channel : public ::node::ObjectWrap {
/* Returns the grpc_channel struct that this object wraps */
grpc_channel *GetWrappedChannel();
- /* Return the hostname that this channel connects to */
- char *GetHost();
-
private:
- explicit Channel(grpc_channel *channel, NanUtf8String *host);
+ explicit Channel(grpc_channel *channel);
~Channel();
// Prevent copying
@@ -71,7 +68,6 @@ class Channel : public ::node::ObjectWrap {
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_channel *wrapped_channel;
- NanUtf8String *host;
};
} // namespace node
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 221d69e246..27f6c19c13 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -67,7 +67,7 @@ function zeroBuffer(size) {
* primarily for use with mocha
*/
function emptyUnary(client, done) {
- var call = client.emptyCall({}, function(err, resp) {
+ client.emptyCall({}, function(err, resp) {
assert.ifError(err);
if (done) {
done();
@@ -89,7 +89,7 @@ function largeUnary(client, done) {
body: zeroBuffer(271828)
}
};
- var call = client.unaryCall(arg, function(err, resp) {
+ client.unaryCall(arg, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.payload.type, 'COMPRESSABLE');
assert.strictEqual(resp.payload.body.length, 314159);
@@ -259,7 +259,7 @@ function cancelAfterFirstResponse(client, done) {
function timeoutOnSleepingServer(client, done) {
var deadline = new Date();
deadline.setMilliseconds(deadline.getMilliseconds() + 1);
- var call = client.fullDuplexCall(null, deadline);
+ var call = client.fullDuplexCall(null, {deadline: deadline});
call.write({
payload: {body: zeroBuffer(27182)}
});
@@ -293,7 +293,7 @@ function authTest(expected_user, scope, client, done) {
fill_username: true,
fill_oauth_scope: true
};
- var call = client.unaryCall(arg, function(err, resp) {
+ client.unaryCall(arg, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.payload.type, 'COMPRESSABLE');
assert.strictEqual(resp.payload.body.length, 314159);
@@ -328,7 +328,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) {
};
var makeTestCall = function(error, client_metadata) {
assert.ifError(error);
- var call = client.unaryCall(arg, function(err, resp) {
+ client.unaryCall(arg, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.username, expected_user);
assert.strictEqual(resp.oauth_scope, AUTH_SCOPE_RESPONSE);
@@ -393,6 +393,7 @@ function runTest(address, host_override, test_case, tls, test_ca, done) {
creds = grpc.Credentials.createSsl(ca_data);
if (host_override) {
options['grpc.ssl_target_name_override'] = host_override;
+ options['grpc.default_authority'] = host_override;
}
} else {
creds = grpc.Credentials.createInsecure();
diff --git a/src/node/src/client.js b/src/node/src/client.js
index b2b4423707..87c7690dc0 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.js
@@ -208,6 +208,25 @@ ClientWritableStream.prototype.getPeer = getPeer;
ClientDuplexStream.prototype.getPeer = getPeer;
/**
+ * Get a call object built with the provided options. Keys for options are
+ * 'deadline', which takes a date or number, and 'host', which takes a string
+ * and overrides the hostname to connect to.
+ * @param {Object} options Options map.
+ */
+function getCall(channel, method, options) {
+ var deadline;
+ var host;
+ if (options) {
+ deadline = options.deadline;
+ host = options.host;
+ }
+ if (deadline === undefined) {
+ deadline = Infinity;
+ }
+ return new grpc.Call(channel, method, deadline, host);
+}
+
+/**
* Get a function that can make unary requests to the specified method.
* @param {string} method The name of the method to request
* @param {function(*):Buffer} serialize The serialization function for inputs
@@ -226,17 +245,13 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
* response is received
* @param {array=} metadata Array of metadata key/value pairs to add to the
* call
- * @param {(number|Date)=} deadline The deadline for processing this request.
- * Defaults to infinite future
+ * @param {Object=} options Options map
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeUnaryRequest(argument, callback, metadata, deadline) {
+ function makeUnaryRequest(argument, callback, metadata, options) {
/* jshint validthis: true */
- if (deadline === undefined) {
- deadline = Infinity;
- }
var emitter = new EventEmitter();
- var call = new grpc.Call(this.channel, method, deadline);
+ var call = getCall(this.channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
@@ -300,16 +315,12 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
* response is received
* @param {array=} metadata Array of metadata key/value pairs to add to the
* call
- * @param {(number|Date)=} deadline The deadline for processing this request.
- * Defaults to infinite future
+ * @param {Object=} options Options map
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeClientStreamRequest(callback, metadata, deadline) {
+ function makeClientStreamRequest(callback, metadata, options) {
/* jshint validthis: true */
- if (deadline === undefined) {
- deadline = Infinity;
- }
- var call = new grpc.Call(this.channel, method, deadline);
+ var call = getCall(this.channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
@@ -374,16 +385,12 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
* serialize
* @param {array=} metadata Array of metadata key/value pairs to add to the
* call
- * @param {(number|Date)=} deadline The deadline for processing this request.
- * Defaults to infinite future
+ * @param {Object} options Options map
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeServerStreamRequest(argument, metadata, deadline) {
+ function makeServerStreamRequest(argument, metadata, options) {
/* jshint validthis: true */
- if (deadline === undefined) {
- deadline = Infinity;
- }
- var call = new grpc.Call(this.channel, method, deadline);
+ var call = getCall(this.channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
@@ -446,16 +453,12 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
* @this {SurfaceClient} Client object. Must have a channel member.
* @param {array=} metadata Array of metadata key/value pairs to add to the
* call
- * @param {(number|Date)=} deadline The deadline for processing this request.
- * Defaults to infinite future
+ * @param {Options} options Options map
* @return {EventEmitter} An event emitter for stream related events
*/
- function makeBidiStreamRequest(metadata, deadline) {
+ function makeBidiStreamRequest(metadata, options) {
/* jshint validthis: true */
- if (deadline === undefined) {
- deadline = Infinity;
- }
- var call = new grpc.Call(this.channel, method, deadline);
+ var call = getCall(this.channel, method, options);
if (metadata === null || metadata === undefined) {
metadata = {};
}
diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js
index 48d859a8ec..8d0f20b074 100644
--- a/src/node/test/call_test.js
+++ b/src/node/test/call_test.js
@@ -84,6 +84,11 @@ describe('call', function() {
new grpc.Call(channel, 'method', 0);
});
});
+ it('should accept an optional fourth string parameter', function() {
+ assert.doesNotThrow(function() {
+ new grpc.Call(channel, 'method', new Date(), 'host_override');
+ });
+ });
it('should fail with a closed channel', function() {
var local_channel = new grpc.Channel('hostname', insecureCreds);
local_channel.close();
diff --git a/src/node/test/end_to_end_test.js b/src/node/test/end_to_end_test.js
index ea41dfc28c..7574d98b8a 100644
--- a/src/node/test/end_to_end_test.js
+++ b/src/node/test/end_to_end_test.js
@@ -74,8 +74,6 @@ describe('end-to-end', function() {
});
it('should start and end a request without error', function(complete) {
var done = multiDone(complete, 2);
- var deadline = new Date();
- deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'xyz';
var call = new grpc.Call(channel,
'dummy_method',
@@ -126,8 +124,6 @@ describe('end-to-end', function() {
});
it('should successfully send and receive metadata', function(complete) {
var done = multiDone(complete, 2);
- var deadline = new Date();
- deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'xyz';
var call = new grpc.Call(channel,
'dummy_method',
@@ -184,8 +180,6 @@ describe('end-to-end', function() {
var req_text = 'client_request';
var reply_text = 'server_response';
var done = multiDone(complete, 2);
- var deadline = new Date();
- deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'success';
var call = new grpc.Call(channel,
'dummy_method',
@@ -241,8 +235,6 @@ describe('end-to-end', function() {
it('should send multiple messages', function(complete) {
var done = multiDone(complete, 2);
var requests = ['req1', 'req2'];
- var deadline = new Date();
- deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'xyz';
var call = new grpc.Call(channel,
'dummy_method',