Skip to content

Commit

Permalink
refactor: support passing an autoEncrypter to the connection pool
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jan 1, 2020
1 parent dd1e717 commit 3844dd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/cmap/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const kLastUseTime = Symbol('lastUseTime');
const kClusterTime = Symbol('clusterTime');
const kDescription = Symbol('description');
const kIsMaster = Symbol('ismaster');
const kAutoEncrypter = Symbol('autoEncrypter');

class Connection extends EventEmitter {
constructor(stream, options) {
Expand All @@ -38,6 +39,11 @@ class Connection extends EventEmitter {
this[kGeneration] = options.generation;
this[kLastUseTime] = Date.now();

// retain a reference to an `AutoEncrypter` if present
if (options.autoEncrypter) {
this[kAutoEncrypter] = options.autoEncrypter;
}

// setup parser stream and message handling
this[kQueue] = new Map();
this[kMessageStream] = new MessageStream(options);
Expand Down Expand Up @@ -172,14 +178,20 @@ class Connection extends EventEmitter {
/// protocol methods. Eventually, the operation executor will return a `Connection` to execute
/// against.
function makeServerTrampoline(connection) {
return {
const server = {
description: connection.description,
clusterTime: connection[kClusterTime],
s: {
bson: connection.bson,
pool: { write: write.bind(connection), isConnected: () => true }
}
};

if (connection[kAutoEncrypter]) {
server.autoEncrypter = connection[kAutoEncrypter];
}

return server;
}

function messageHandler(conn) {
Expand Down
3 changes: 2 additions & 1 deletion lib/cmap/connection_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class ConnectionPool extends EventEmitter {
minPoolSize: typeof options.minPoolSize === 'number' ? options.minPoolSize : 0,
maxIdleTimeMS: typeof options.maxIdleTimeMS === 'number' ? options.maxIdleTimeMS : 0,
waitQueueTimeoutMS:
typeof options.waitQueueTimeoutMS === 'number' ? options.waitQueueTimeoutMS : 10000
typeof options.waitQueueTimeoutMS === 'number' ? options.waitQueueTimeoutMS : 10000,
autoEncrypter: options.autoEncrypter
});

if (options.minSize > options.maxSize) {
Expand Down

0 comments on commit 3844dd8

Please sign in to comment.