diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 12:46:04 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 12:46:04 +0000 |
| commit | 7bee9b7e0968b650b3dbe2e35bf3a0d7d6e5e00e (patch) | |
| tree | 4e63af46a6e306bfeac1ef4b8bd83e1b45a37257 /node_modules/mongodb-core | |
| parent | 6520aa92a114d65b17b178a952c8985e84afd231 (diff) | |
Removed some unused modules with prune
Diffstat (limited to 'node_modules/mongodb-core')
37 files changed, 0 insertions, 22998 deletions
diff --git a/node_modules/mongodb-core/.coveralls.yml b/node_modules/mongodb-core/.coveralls.yml deleted file mode 100644 index a0b4fb6..0000000 --- a/node_modules/mongodb-core/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: 47iIZ0B3llo2Wc4dxWRltvgdImqcrVDTi diff --git a/node_modules/mongodb-core/HISTORY.md b/node_modules/mongodb-core/HISTORY.md deleted file mode 100644 index e1b7a72..0000000 --- a/node_modules/mongodb-core/HISTORY.md +++ /dev/null @@ -1,501 +0,0 @@ -2.0.5 2016-07-15 ----------------- -* Minor fixes to handle faster MongoClient connectivity from the driver, allowing single server instances to detect if they are a proxy. -* Added numberOfConsecutiveTimeouts to pool that will destroy the pool if the number of consecutive timeouts > reconnectTries. -* Print warning if seedlist servers host name does not match the one provided in it's ismaster.me field for Replicaset members. -* Fix issue where Replicaset connection would not succeeed if there the replicaset was a single primary server setup. - -2.0.4 2016-07-11 ------------------ -* Updated bson to version 0.5.1. -* handle situation where user is providing seedlist names that do not match host list. fix allows for a single full discovery connection sweep before erroring out. -* NODE-747 Polyfill for Object.assign for 0.12.x or 0.10.x. -* NODE-746 Improves replicaset errors for wrong setName. - -2.0.3 2016-07-08 ------------------ -* Implemented Server Selection Specification test suite. -* Added warning level to logger. -* Added warning message when sockeTimeout < haInterval for Replset/Mongos. - -2.0.2 2016-07-06 ------------------ -* Mongos emits close event on no proxies available or when reconnect attempt fails. -* Replset emits close event when no servers available or when attemptReconnect fails to reconnect. -* Don't throw in auth methods but return error in callback. - -2.0.1 2016-07-05 ------------------ -* Added missing logout method on mongos proxy topology. -* Fixed logger error serialization issue. -* Documentation fixes. - -2.0.0 2016-07-05 ------------------ -* Moved all authentication and handling of growing/shrinking of pool connections into actual pool. -* All authentication methods now handle both auth/reauthenticate and logout events. -* Introduced logout method to get rid of onAll option for logout command. -* Updated bson to 0.5.0 that includes Decimal128 support. - -1.3.21 2016-05-30 ------------------ -* Pool gets stuck if a connection marked for immediateRelease times out (Issue #99, https://github.com/nbrachet). -* Make authentication process retry up to authenticationRetries at authenticationRetryIntervalMS interval. -* Made ismaster replicaset calls operate with connectTimeout or monitorSocketTimeout to lower impact of big socketTimeouts on monitoring performance. -* Make sure connections mark as "immediateRelease" don't linger the inUserConnections list. Otherwise, after that connection times out, getAll() incorrectly returns more connections than are effectively present, causing the pool to not get restarted by reconnectServer. (Issue #99, https://github.com/nbrachet). -* Make cursor getMore or killCursor correctly trigger pool reconnect to single server if pool has not been destroyed. -* Make ismaster monitoring for single server connection default to avoid user confusion due to change in behavior. - -1.3.20 2016-05-25 ------------------ -* NODE-710 Allow setting driver loggerLevel and logger function from MongoClient options. -* Minor fix for SSL errors on connection attempts, minor fix to reconnect handler for the server. -* Don't write to socket before having registered the callback for commands, work around for windows issuing error events twice on node.js when socket gets destroyed by firewall. -* Fix minor issue where connectingServers would not be removed correctly causing single server connections to not auto-reconnect. - -1.3.19 2016-05-17 ------------------ -- Handle situation where a server connection in a replicaset sometimes fails to be destroyed properly due to being in the middle of authentication when the destroy method is called on the replicaset causing it to be orphaned and never collected. -- Set keepAlive to false by default to work around bug in node.js for Windows XP and Windows 2003. -- Ensure replicaset topology destroy is never called by SDAM. -- Ensure all paths are correctly returned on inspectServer in replset. - -1.3.18 2016-04-27 ------------------ -- Hardened cursor connection handling for getMore and killCursor to ensure mid operation connection kill does not throw null exception. -- Fixes for Node 6.0 support. - -1.3.17 2016-04-26 ------------------ -- Added improved handling of reconnect when topology is a single server. -- Added better handling of $query queries passed down for 3.2 or higher. -- Introduced getServerFrom method to topologies to let cursor grab a new pool for getMore and killCursors commands and not use connection pipelining. -- NODE-693 Move authentication to be after ismaster call to avoid authenticating against arbiters. - -1.3.16 2016-04-07 ------------------ -- Only call unref on destroy if it exists to ensure proper working destroy method on early node v0.10.x versions. - -1.3.15 2016-04-06 ------------------ -- NODE-687 Fixed issue where a server object failed to be destroyed if the replicaset state did not update successfully. This could leave active connections accumulating over time. -- Fixed some situations where all connections are flushed due to a single connection in the connection pool closing. - -1.3.14 2016-04-01 ------------------ -- Ensure server inquireServerState exits immediately on server.destroy call. -- Refactored readPreference handling in 2.4, 2.6 and 3.2 wire protocol handling. - -1.3.13 2016-03-30 ------------------ -- Handle missing cursor on getMore when going through a mongos proxy by pinning to socket connection and not server. - -1.3.12 2016-03-29 ------------------ -- Mongos pickProxies fall back to closest mongos if no proxies meet latency window specified. - -1.3.11 2016-03-29 ------------------ -- isConnected method for mongos uses same selection code as getServer. -- Exceptions in cursor getServer trapped and correctly delegated to high level handler. - -1.3.10 2016-03-22 ------------------ -- SDAM Monitoring emits diff for Replicasets to simplify detecting the state changes. -- SDAM Monitoring correctly emits Mongos as serverDescriptionEvent. - -1.3.9 2016-03-20 ----------------- -- Removed monitoring exclusive connection, should resolve timeouts and reconnects on idle replicasets where haInteval > socketTimeout. - -1.3.8 2016-03-18 ----------------- -- Implements the SDAM monitoring specification. -- Fix issue where cursor would error out and not be buffered when primary is not connected. - -1.3.7 2016-03-16 ----------------- -- Fixed issue with replicasetInquirer where it could stop performing monitoring if there was no servers available. - -1.3.6 2016-03-15 ----------------- -- Fixed raise condition where multiple replicasetInquirer operations could be started in parallel creating redundant connections. - -1.3.5 2016-03-14 ----------------- -- Handle rogue SSL exceptions (Issue #85, https://github.com/durran). - -1.3.4 2016-03-14 ----------------- -- Added unref options on server, replicaset and mongos (Issue #81, https://github.com/allevo) -- cursorNotFound flag always false (Issue #83, https://github.com/xgfd) -- refactor of events emission of fullsetup and all events (Issue #84, https://github.com/xizhibei) - -1.3.3 2016-03-08 ----------------- -- Added support for promoteLongs option for command function. -- Return connection if no callback available -- Emit connect event when server reconnects after initial connection failed (Issue #76, https://github.com/vkarpov15) -- Introduced optional monitoringSocketTimeout option to allow better control of SDAM monitoring timeouts. -- Made monitoringSocketTimeout default to 30000 if no connectionTimeout value specified or if set to 0. -- Fixed issue where tailable cursor would not retry even though cursor was still alive. -- Disabled exhaust flag support to avoid issues where users could easily write code that would cause memory to run out. -- Handle the case where the first command result document returns an empty list of documents but a live cursor. -- Allow passing down off CANONICALIZE_HOST_NAME and SERVICE_REALM options for kerberos. - -1.3.2 2016-02-09 ----------------- -- Harden MessageHandler in server.js to avoid issues where we cannot find a callback for an operation. -- Ensure RequestId can never be larger than Max Number integer size. - -1.3.1 2016-02-05 ----------------- -- Removed annoying missing Kerberos error (NODE-654). - -1.3.0 2016-02-03 ----------------- -- Added raw support for the command function on topologies. -- Fixed issue where raw results that fell on batchSize boundaries failed (Issue #72) -- Copy over all the properties to the callback returned from bindToDomain, (Issue #72) -- Added connection hash id to be able to reference connection host/name without leaking it outside of driver. -- NODE-638, Cannot authenticate database user with utf-8 password. -- Refactored pool to be worker queue based, minimizing the impact a slow query have on throughput as long as # slow queries < # connections in the pool. -- Pool now grows and shrinks correctly depending on demand not causing a full pool reconnect. -- Improvements in monitoring of a Replicaset where in certain situations the inquiry process could get exited. -- Switched to using Array.push instead of concat for use cases of a lot of documents. -- Fixed issue where re-authentication could loose the credentials if whole Replicaset disconnected at once. -- Added peer optional dependencies support using require_optional module. - -1.2.32 2016-01-12 ------------------ -- Bumped bson to V0.4.21 to allow using minor optimizations. - -1.2.31 2016-01-04 ------------------ -- Allow connection to secondary if primaryPreferred or secondaryPreferred (Issue #70, https://github.com/leichter) - -1.2.30 2015-12-23 ------------------ -- Pool allocates size + 1 connections when using replicasets, reserving additional pool connection for monitoring exclusively. -- Fixes bug when all replicaset members are down, that would cause it to fail to reconnect using the originally provided seedlist. - -1.2.29 2015-12-17 ------------------ -- Correctly emit close event when calling destroy on server topology. - -1.2.28 2015-12-13 ------------------ -- Backed out Prevent Maximum call stack exceeded by calling all callbacks on nextTick, (Issue #64, https://github.com/iamruinous) as it breaks node 0.10.x support. - -1.2.27 2015-12-13 ------------------ -- Added [options.checkServerIdentity=true] {boolean|function}. Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function, (Issue #29). -- Prevent Maximum call stack exceeded by calling all callbacks on nextTick, (Issue #64, https://github.com/iamruinous). -- State is not defined in mongos, (Issue #63, https://github.com/flyingfisher). -- Fixed corner case issue on exhaust cursors on pre 3.0.x MongoDB. - -1.2.26 2015-11-23 ------------------ -- Converted test suite to use mongodb-topology-manager. -- Upgraded bson library to V0.4.20. -- Minor fixes for 3.2 readPreferences. - -1.2.25 2015-11-23 ------------------ -- Correctly error out when passed a seedlist of non-valid server members. - -1.2.24 2015-11-20 ------------------ -- Fix Automattic/mongoose#3481; flush callbacks on error, (Issue #57, https://github.com/vkarpov15). -- $explain query for wire protocol 2.6 and 2.4 does not set number of returned documents to -1 but to 0. - -1.2.23 2015-11-16 ------------------ -- ismaster runs against admin.$cmd instead of system.$cmd. - -1.2.22 2015-11-16 ------------------ -- Fixes to handle getMore command errors for MongoDB 3.2 -- Allows the process to properly close upon a Db.close() call on the replica set by shutting down the haTimer and closing arbiter connections. - -1.2.21 2015-11-07 ------------------ -- Hardened the checking for replicaset equality checks. -- OpReplay flag correctly set on Wire protocol query. -- Mongos load balancing added, introduced localThresholdMS to control the feature. -- Kerberos now a peerDependency, making it not install it by default in Node 5.0 or higher. - -1.2.20 2015-10-28 ------------------ -- Fixed bug in arbiter connection capping code. -- NODE-599 correctly handle arrays of server tags in order of priority. -- Fix for 2.6 wire protocol handler related to readPreference handling. -- Added maxAwaitTimeMS support for 3.2 getMore to allow for custom timeouts on tailable cursors. -- Make CoreCursor check for $err before saying that 'next' succeeded (Issue #53, https://github.com/vkarpov15). - -1.2.19 2015-10-15 ------------------ -- Make batchSize always be > 0 for 3.2 wire protocol to make it work consistently with pre 3.2 servers. -- Locked to bson 0.4.19. - -1.2.18 2015-10-15 ------------------ -- Minor 3.2 fix for handling readPreferences on sharded commands. -- Minor fixes to correctly pass APM specification test suite. - -1.2.17 2015-10-08 ------------------ -- Connections to arbiters only maintain a single connection. - -1.2.15 2015-10-06 ------------------ -- Set slaveOk to true for getMore and killCursors commands. -- Don't swallow callback errors for 2.4 single server (Issue #49, https://github.com/vkarpov15). -- Apply toString('hex') to each buffer in an array when logging (Issue #48, https://github.com/nbrachet). - -1.2.14 2015-09-28 ------------------ -- NODE-547 only emit error if there are any listeners. -- Fixed APM issue with issuing readConcern. - -1.2.13 2015-09-18 ------------------ -- Added BSON serializer ignoreUndefined option for insert/update/remove/command/cursor. - -1.2.12 2015-09-08 ------------------ -- NODE-541 Added initial support for readConcern. - -1.2.11 2015-08-31 ------------------ -- NODE-535 If connectWithNoPrimary is true then primary-only connection is not allowed. -- NODE-534 Passive secondaries are not allowed for secondaryOnlyConnectionAllowed. -- Fixed filtering bug for logging (Issue 30, https://github.com/christkv/mongodb-core/issues/30). - -1.2.10 2015-08-14 ------------------ -- Added missing Mongos.prototype.parserType function. - -1.2.9 2015-08-05 ----------------- -- NODE-525 Reset connectionTimeout after it's overwritten by tls.connect. -- NODE-518 connectTimeoutMS is doubled in 2.0.39. - -1.2.8 2015-07-24 ------------------ -- Minor fix to handle 2.4.x errors better by correctly return driver layer issues. - -1.2.7 2015-07-16 ------------------ -- Refactoring to allow to tap into find/getmore/killcursor in cursors for APM monitoring in driver. - -1.2.6 2015-07-14 ------------------ -- NODE-505 Query fails to find records that have a 'result' property with an array value. - -1.2.5 2015-07-14 ------------------ -- NODE-492 correctly handle hanging replicaset monitoring connections when server is unavailable due to network partitions or firewalls dropping packets, configureable using the connectionTimeoutMS setting. - -1.2.4 2015-07-07 ------------------ -- NODE-493 staggering the socket connections to avoid overwhelming the mongod process. - -1.2.3 2015-06-26 ------------------ -- Minor bug fixes. - -1.2.2 2015-06-22 ------------------ -- Fix issue with SCRAM authentication causing authentication to return true on failed authentication (Issue 26, https://github.com/cglass17). - -1.2.1 2015-06-17 ------------------ -- Ensure serializeFunctions passed down correctly to wire protocol. - -1.2.0 2015-06-17 ------------------ -- Switching to using the 0.4.x pure JS serializer, removing dependency on C++ parser. -- Refactoring wire protocol messages to avoid expensive size calculations of documents in favor of writing out an array of buffers to the sockets. -- NODE-486 fixed issue related to limit and skip when calling toArray in 2.0 driver. -- NODE-483 throw error if capabilities of topology is queries before topology has performed connection setup. -- NODE-487 fixed issue where killcursor command was not being sent correctly on limit and skip queries. - -1.1.33 2015-05-31 ------------------ -- NODE-478 Work around authentication race condition in mongos authentication due to multi step authentication methods like SCRAM. - -1.1.32 2015-05-20 ------------------ -- After reconnect, it updates the allowable reconnect retries to the option settings (Issue #23, https://github.com/owenallenaz) - -1.1.31 2015-05-19 ------------------ -- Minor fixes for issues with re-authentication of mongos. - -1.1.30 2015-05-18 ------------------ -- Correctly emit 'all' event when primary + all secondaries have connected. - -1.1.29 2015-05-17 ------------------ -- NODE-464 Only use a single socket against arbiters and hidden servers. -- Ensure we filter out hidden servers from any server queries. - -1.1.28 2015-05-12 ------------------ -- Fixed buffer compare for electionId for < node 12.0.2 - -1.1.27 2015-05-12 ------------------ -- NODE-455 Update SDAM specification support to cover electionId and Mongos load balancing. - -1.1.26 2015-05-06 ------------------ -- NODE-456 Allow mongodb-core to pipeline commands (ex findAndModify+GLE) along the same connection and handle the returned results. -- Fixes to make mongodb-core work for node 0.8.x when using scram and setImmediate. - -1.1.25 2015-04-24 ------------------ -- Handle lack of callback in crud operations when returning error on application closed. - -1.1.24 2015-04-22 ------------------ -- Error out when topology has been destroyed either by connection retries being exhausted or destroy called on topology. - -1.1.23 2015-04-15 ------------------ -- Standardizing mongoErrors and its API (Issue #14) -- Creating a new connection is slow because of 100ms setTimeout() (Issue #17, https://github.com/vkarpov15) -- remove mkdirp and rimraf dependencies (Issue #12) -- Updated default value of param options.rejectUnauthorized to match documentation (Issue #16) -- ISSUE: NODE-417 Resolution. Improving behavior of thrown errors (Issue #14, https://github.com/owenallenaz) -- Fix cursor hanging when next() called on exhausted cursor (Issue #18, https://github.com/vkarpov15) - -1.1.22 2015-04-10 ------------------ -- Minor refactorings in cursor code to make extending the cursor simpler. -- NODE-417 Resolution. Improving behavior of thrown errors using Error.captureStackTrace. - -1.1.21 2015-03-26 ------------------ -- Updated bson module to 0.3.0 that extracted the c++ parser into bson-ext and made it an optional dependency. - -1.1.20 2015-03-24 ------------------ -- NODE-395 Socket Not Closing, db.close called before full set finished initalizing leading to server connections in progress not being closed properly. - -1.1.19 2015-03-21 ------------------ -- Made kerberos module ~0.0 to allow for quicker releases due to io.js of kerberos module. - -1.1.18 2015-03-17 ------------------ -- Added support for minHeartbeatFrequencyMS on server reconnect according to the SDAM specification. - -1.1.17 2015-03-16 ------------------ -- NODE-377, fixed issue where tags would correctly be checked on secondary and nearest to filter out eligible server candidates. - -1.1.16 2015-03-06 ------------------ -- rejectUnauthorized parameter is set to true for ssl certificates by default instead of false. - -1.1.15 2015-03-04 ------------------ -- Removed check for type in replset pickserver function. - -1.1.14 2015-02-26 ------------------ -- NODE-374 correctly adding passive secondaries to the list of eligable servers for reads - -1.1.13 2015-02-24 ------------------ -- NODE-365 mongoDB native node.js driver infinite reconnect attempts (fixed issue around handling of retry attempts) - -1.1.12 2015-02-16 ------------------ -- Fixed cursor transforms for buffered document reads from cursor. - -1.1.11 2015-02-02 ------------------ -- Remove the required setName for replicaset connections, if not set it will pick the first setName returned. - -1.1.10 2015-31-01 ------------------ -- Added tranforms.doc option to cursor to allow for pr. document transformations. - -1.1.9 2015-21-01 ----------------- -- Updated BSON dependency to 0.2.18 to fix issues with io.js and node. -- Updated Kerberos dependency to 0.0.8 to fix issues with io.js and node. -- Don't treat findOne() as a command cursor. -- Refactored out state changes into methods to simplify read the next method. - -1.1.8 2015-09-12 ----------------- -- Stripped out Object.defineProperty for performance reasons -- Applied more performance optimizations. -- properties cursorBatchSize, cursorSkip, cursorLimit are not methods setCursorBatchSize/cursorBatchSize, setCursorSkip/cursorSkip, setCursorLimit/cursorLimit - -1.1.7 2014-18-12 ----------------- -- Use ns variable for getMore commands for command cursors to work properly with cursor version of listCollections and listIndexes. - -1.1.6 2014-18-12 ----------------- -- Server manager fixed to support 2.2.X servers for travis test matrix. - -1.1.5 2014-17-12 ----------------- -- Fall back to errmsg when creating MongoError for command errors - -1.1.4 2014-17-12 ----------------- -- Added transform method support for cursor (initially just for initial query results) to support listCollections/listIndexes in 2.8. -- Fixed variable leak in scram. -- Fixed server manager to deal better with killing processes. -- Bumped bson to 0.2.16. - -1.1.3 2014-01-12 ----------------- -- Fixed error handling issue with nonce generation in mongocr. -- Fixed issues with restarting servers when using ssl. -- Using strict for all classes. -- Cleaned up any escaping global variables. - -1.1.2 2014-20-11 ----------------- -- Correctly encoding UTF8 collection names on wire protocol messages. -- Added emitClose parameter to topology destroy methods to allow users to specify that they wish the topology to emit the close event to any listeners. - -1.1.1 2014-14-11 ----------------- -- Refactored code to use prototype instead of privileged methods. -- Fixed issue with auth where a runtime condition could leave replicaset members without proper authentication. -- Several deopt optimizations for v8 to improve performance and reduce GC pauses. - -1.0.5 2014-29-10 ----------------- -- Fixed issue with wrong namespace being created for command cursors. - -1.0.4 2014-24-10 ----------------- -- switched from using shift for the cursor due to bad slowdown on big batchSizes as shift causes entire array to be copied on each call. - -1.0.3 2014-21-10 ----------------- -- fixed error issuing problem on cursor.next when iterating over a huge dataset with a very small batchSize. - -1.0.2 2014-07-10 ----------------- -- fullsetup is now defined as a primary and secondary being available allowing for all read preferences to be satisfied. -- fixed issue with replset_state logging. - -1.0.1 2014-07-10 ----------------- -- Dependency issue solved - -1.0.0 2014-07-10 ----------------- -- Initial release of mongodb-core diff --git a/node_modules/mongodb-core/LICENSE b/node_modules/mongodb-core/LICENSE deleted file mode 100644 index ad410e1..0000000 --- a/node_modules/mongodb-core/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License.
\ No newline at end of file diff --git a/node_modules/mongodb-core/Makefile b/node_modules/mongodb-core/Makefile deleted file mode 100644 index 36e1202..0000000 --- a/node_modules/mongodb-core/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -NODE = node -NPM = npm -JSDOC = jsdoc -name = all - -generate_docs: - # cp -R ./HISTORY.md ./docs/content/meta/release-notes.md - hugo -s docs/reference -d ../../public - $(JSDOC) -c conf.json -t docs/jsdoc-template/ -d ./public/api - cp -R ./public/api/scripts ./public/. - cp -R ./public/api/styles ./public/. diff --git a/node_modules/mongodb-core/README.md b/node_modules/mongodb-core/README.md deleted file mode 100644 index 433dd88..0000000 --- a/node_modules/mongodb-core/README.md +++ /dev/null @@ -1,228 +0,0 @@ -[](http://travis-ci.org/christkv/mongodb-core) -[](https://coveralls.io/github/christkv/mongodb-core?branch=1.3) - -# Description - -The MongoDB Core driver is the low level part of the 2.0 or higher MongoDB driver and is meant for library developers not end users. It does not contain any abstractions or helpers outside of the basic management of MongoDB topology connections, CRUD operations and authentication. - -## MongoDB Node.JS Core Driver - -| what | where | -|---------------|------------------------------------------------| -| documentation | http://mongodb.github.io/node-mongodb-native/ | -| apidoc | http://mongodb.github.io/node-mongodb-native/ | -| source | https://github.com/christkv/mongodb-core | -| mongodb | http://www.mongodb.org/ | - -### Blogs of Engineers involved in the driver -- Christian Kvalheim [@christkv](https://twitter.com/christkv) <http://christiankvalheim.com> - -### Bugs / Feature Requests - -Think you’ve found a bug? Want to see a new feature in node-mongodb-native? Please open a -case in our issue management tool, JIRA: - -- Create an account and login <https://jira.mongodb.org>. -- Navigate to the NODE project <https://jira.mongodb.org/browse/NODE>. -- Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it. - -Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the -Core Server (i.e. SERVER) project are **public**. - -### Questions and Bug Reports - - * mailing list: https://groups.google.com/forum/#!forum/node-mongodb-native - * jira: http://jira.mongodb.org/ - -### Change Log - -http://jira.mongodb.org/browse/NODE - -# QuickStart - -The quick start guide will show you how to set up a simple application using Core driver and MongoDB. It scope is only how to set up the driver and perform the simple crud operations. For more inn depth coverage we encourage reading the tutorials. - -## Create the package.json file - -Let's create a directory where our application will live. In our case we will put this under our projects directory. - -``` -mkdir myproject -cd myproject -``` - -Create a **package.json** using your favorite text editor and fill it in. - -```json -{ - "name": "myproject", - "version": "1.0.0", - "description": "My first project", - "main": "index.js", - "repository": { - "type": "git", - "url": "git://github.com/christkv/myfirstproject.git" - }, - "dependencies": { - "mongodb-core": "~1.0" - }, - "author": "Christian Kvalheim", - "license": "Apache 2.0", - "bugs": { - "url": "https://github.com/christkv/myfirstproject/issues" - }, - "homepage": "https://github.com/christkv/myfirstproject" -} -``` - -Save the file and return to the shell or command prompt and use **NPM** to install all the dependencies. - -``` -npm install -``` - -You should see **NPM** download a lot of files. Once it's done you'll find all the downloaded packages under the **node_modules** directory. - -Booting up a MongoDB Server ---------------------------- -Let's boot up a MongoDB server instance. Download the right MongoDB version from [MongoDB](http://www.mongodb.org), open a new shell or command line and ensure the **mongod** command is in the shell or command line path. Now let's create a database directory (in our case under **/data**). - -``` -mongod --dbpath=/data --port 27017 -``` - -You should see the **mongod** process start up and print some status information. - -## Connecting to MongoDB - -Let's create a new **app.js** file that we will use to show the basic CRUD operations using the MongoDB driver. - -First let's add code to connect to the server. Notice that there is no concept of a database here and we use the topology directly to perform the connection. - -```js -var Server = require('mongodb-core').Server - , assert = require('assert'); - -// Set up server connection -var server = new Server({ - host: 'localhost' - , port: 27017 - , reconnect: true - , reconnectInterval: 50 -}); - -// Add event listeners -server.on('connect', function(_server) { - console.log('connected'); - test.done(); -}); - -server.on('close', function() { - console.log('closed'); -}); - -server.on('reconnect', function() { - console.log('reconnect'); -}); - -// Start connection -server.connect(); -``` - -To connect to a replicaset we would use the `ReplSet` class and for a set of Mongos proxies we use the `Mongos` class. Each topology class offer the same CRUD operations and you operate on the topology directly. Let's look at an example exercising all the different available CRUD operations. - -```js -var Server = require('mongodb-core').Server - , assert = require('assert'); - -// Set up server connection -var server = new Server({ - host: 'localhost' - , port: 27017 - , reconnect: true - , reconnectInterval: 50 -}); - -// Add event listeners -server.on('connect', function(_server) { - console.log('connected'); - - // Execute the ismaster command - _server.command('system.$cmd', {ismaster: true}, function(err, result) { - - // Perform a document insert - _server.insert('myproject.inserts1', [{a:1}, {a:2}], { - writeConcern: {w:1}, ordered:true - }, function(err, results) { - assert.equal(null, err); - assert.equal(2, results.result.n); - - // Perform a document update - _server.update('myproject.inserts1', [{ - q: {a: 1}, u: {'$set': {b:1}} - }], { - writeConcern: {w:1}, ordered:true - }, function(err, results) { - assert.equal(null, err); - assert.equal(1, results.result.n); - - // Remove a document - _server.remove('myproject.inserts1', [{ - q: {a: 1}, limit: 1 - }], { - writeConcern: {w:1}, ordered:true - }, function(err, results) { - assert.equal(null, err); - assert.equal(1, results.result.n); - - // Get a document - var cursor = _server.cursor('integration_tests.inserts_example4', { - find: 'integration_tests.example4' - , query: {a:1} - }); - - // Get the first document - cursor.next(function(err, doc) { - assert.equal(null, err); - assert.equal(2, doc.a); - - // Execute the ismaster command - _server.command("system.$cmd" - , {ismaster: true}, function(err, result) { - assert.equal(null, err) - _server.destroy(); - }); - }); - }); - }); - - test.done(); - }); -}); - -server.on('close', function() { - console.log('closed'); -}); - -server.on('reconnect', function() { - console.log('reconnect'); -}); - -// Start connection -server.connect(); -``` - -The core driver does not contain any helpers or abstractions only the core crud operations. These consist of the following commands. - -* `insert`, Insert takes an array of 1 or more documents to be inserted against the topology and allows you to specify a write concern and if you wish to execute the inserts in order or out of order. -* `update`, Update takes an array of 1 or more update commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the updates in order or out of order. -* `remove`, Remove takes an array of 1 or more remove commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the removes in order or out of order. -* `cursor`, Returns you a cursor for either the 'virtual' `find` command, a command that returns a cursor id or a plain cursor id. Read the cursor tutorial for more inn depth coverage. -* `command`, Executes a command against MongoDB and returns the result. -* `auth`, Authenticates the current topology using a supported authentication scheme. - -The Core Driver is a building block for library builders and is not meant for usage by end users as it lacks a lot of features the end user might need such as automatic buffering of operations when a primary is changing in a replicaset or the db and collections abstraction. - -## Next steps - -The next step is to get more in depth information about how the different aspects of the core driver works and how to leverage them to extend the functionality of the cursors. Please view the tutorials for more detailed information. diff --git a/node_modules/mongodb-core/TESTING.md b/node_modules/mongodb-core/TESTING.md deleted file mode 100644 index fe03ea0..0000000 --- a/node_modules/mongodb-core/TESTING.md +++ /dev/null @@ -1,18 +0,0 @@ -Testing setup -============= - -Single Server -------------- -mongod --dbpath=./db - -Replicaset ----------- -mongo --nodb -var x = new ReplSetTest({"useHostName":"false", "nodes" : {node0 : {}, node1 : {}, node2 : {}}}) -x.startSet(); -var config = x.getReplSetConfig() -x.initiate(config); - -Mongos ------- -var s = new ShardingTest( "auth1", 1 , 0 , 2 , {rs: true, noChunkSize : true});
\ No newline at end of file diff --git a/node_modules/mongodb-core/conf.json b/node_modules/mongodb-core/conf.json deleted file mode 100644 index 12ce4c7..0000000 --- a/node_modules/mongodb-core/conf.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "plugins": ["plugins/markdown", "docs/lib/jsdoc/examples_plugin.js"], - "source": { - "include": [ - "test/tests/functional/operation_example_tests.js", - "lib/connection/command_result.js", - "lib/topologies/mongos.js", - "lib/topologies/read_preference.js", - "lib/topologies/replset.js", - "lib/topologies/server.js", - "lib/topologies/replset_state.js", - "lib/connection/logger.js", - "lib/connection/connection.js", - "lib/cursor.js", - "lib/error.js", - "node_modules/bson/lib/bson/binary.js", - "node_modules/bson/lib/bson/code.js", - "node_modules/bson/lib/bson/db_ref.js", - "node_modules/bson/lib/bson/double.js", - "node_modules/bson/lib/bson/long.js", - "node_modules/bson/lib/bson/objectid.js", - "node_modules/bson/lib/bson/symbol.js", - "node_modules/bson/lib/bson/timestamp.js", - "node_modules/bson/lib/bson/max_key.js", - "node_modules/bson/lib/bson/min_key.js" - ] - }, - "templates": { - "cleverLinks": true, - "monospaceLinks": true, - "default": { - "outputSourceFiles" : true - }, - "applicationName": "Node.js MongoDB Driver API", - "disqus": true, - "googleAnalytics": "UA-29229787-1", - "openGraph": { - "title": "", - "type": "website", - "image": "", - "site_name": "", - "url": "" - }, - "meta": { - "title": "", - "description": "", - "keyword": "" - }, - "linenums": true - }, - "markdown": { - "parser": "gfm", - "hardwrap": true, - "tags": ["examples"] - }, - "examples": { - "indent": 4 - } -} diff --git a/node_modules/mongodb-core/index.js b/node_modules/mongodb-core/index.js deleted file mode 100644 index 5011f4a..0000000 --- a/node_modules/mongodb-core/index.js +++ /dev/null @@ -1,38 +0,0 @@ -// module.exports = { -// MongoError: require('./lib/error') -// , Server: require('./lib/topologies/server') -// , ReplSet: require('./lib/topologies/replset') -// , Mongos: require('./lib/topologies/mongos') -// , Logger: require('./lib/connection/logger') -// , Cursor: require('./lib/cursor') -// , ReadPreference: require('./lib/topologies/read_preference') -// , BSON: require('bson') -// // Raw operations -// , Query: require('./lib/connection/commands').Query -// // Auth mechanisms -// , MongoCR: require('./lib/auth/mongocr') -// , X509: require('./lib/auth/x509') -// , Plain: require('./lib/auth/plain') -// , GSSAPI: require('./lib/auth/gssapi') -// , ScramSHA1: require('./lib/auth/scram') -// } - -module.exports = { - MongoError: require('./lib/error') - , Connection: require('./lib/connection/connection') - , Server: require('./lib/topologies/server') - , ReplSet: require('./lib/topologies/replset') - , Mongos: require('./lib/topologies/mongos') - , Logger: require('./lib/connection/logger') - , Cursor: require('./lib/cursor') - , ReadPreference: require('./lib/topologies/read_preference') - , BSON: require('bson') - // Raw operations - , Query: require('./lib/connection/commands').Query - // Auth mechanisms - , MongoCR: require('./lib/auth/mongocr') - , X509: require('./lib/auth/x509') - , Plain: require('./lib/auth/plain') - , GSSAPI: require('./lib/auth/gssapi') - , ScramSHA1: require('./lib/auth/scram') -} diff --git a/node_modules/mongodb-core/lib/auth/gssapi.js b/node_modules/mongodb-core/lib/auth/gssapi.js deleted file mode 100644 index c3bd6bd..0000000 --- a/node_modules/mongodb-core/lib/auth/gssapi.js +++ /dev/null @@ -1,277 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , require_optional = require('require_optional') - , Query = require('../connection/commands').Query - , MongoError = require('../error'); - -var AuthSession = function(db, username, password, options) { - this.db = db; - this.username = username; - this.password = password; - this.options = options; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -// Kerberos class -var Kerberos = null; -var MongoAuthProcess = null; - -// Try to grab the Kerberos class -try { - Kerberos = require_optional('kerberos').Kerberos; - // Authentication process for Mongo - MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess -} catch(err) {} - -/** - * Creates a new GSSAPI authentication mechanism - * @class - * @return {GSSAPI} A cursor instance - */ -var GSSAPI = function(bson) { - this.bson = bson; - this.authStore = []; -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -GSSAPI.prototype.auth = function(server, connections, db, username, password, options, callback) { - var self = this; - // We don't have the Kerberos library - if(Kerberos == null) return callback(new Error("Kerberos library is not installed")); - var gssapiServiceName = options['gssapiServiceName'] || 'mongodb'; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // For each connection we need to authenticate - while(connections.length > 0) { - // Execute MongoCR - var execute = function(connection) { - // Start Auth process for a connection - GSSAPIInitialize(self, db, username, password, db, gssapiServiceName, server, connection, options, function(err, r) { - // Adjust count - count = count - 1; - - // If we have an error - if(err) { - errorObject = err; - } else if(r.result['$err']) { - errorObject = r.result; - } else if(r.result['errmsg']) { - errorObject = r.result; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - // We have authenticated all connections - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password, options)); - // Return correct authentication - callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr")); - callback(errorObject, false); - } - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - execute(_connection); - }); - } - - _execute(connections.shift()); - } -} - -// -// Initialize step -var GSSAPIInitialize = function(self, db, username, password, authdb, gssapiServiceName, server, connection, options, callback) { - // Create authenticator - var mongo_auth_process = new MongoAuthProcess(connection.host, connection.port, gssapiServiceName, options); - - // Perform initialization - mongo_auth_process.init(username, password, function(err, context) { - if(err) return callback(err, false); - - // Perform the first step - mongo_auth_process.transition('', function(err, payload) { - if(err) return callback(err, false); - - // Call the next db step - MongoDBGSSAPIFirstStep(self, mongo_auth_process, payload, db, username, password, authdb, server, connection, callback); - }); - }); -} - -// -// Perform first step against mongodb -var MongoDBGSSAPIFirstStep = function(self, mongo_auth_process, payload, db, username, password, authdb, server, connection, callback) { - // Build the sasl start command - var command = { - saslStart: 1 - , mechanism: 'GSSAPI' - , payload: payload - , autoAuthorize: 1 - }; - - // Write the commmand on the connection - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // // Execute first sasl step - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - // Execute mongodb transition - mongo_auth_process.transition(r.result.payload, function(err, payload) { - if(err) return callback(err, false); - - // MongoDB API Second Step - MongoDBGSSAPISecondStep(self, mongo_auth_process, payload, doc, db, username, password, authdb, server, connection, callback); - }); - }); -} - -// -// Perform first step against mongodb -var MongoDBGSSAPISecondStep = function(self, mongo_auth_process, payload, doc, db, username, password, authdb, server, connection, callback) { - // Build Authentication command to send to MongoDB - var command = { - saslContinue: 1 - , conversationId: doc.conversationId - , payload: payload - }; - - // Execute the command - // Write the commmand on the connection - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - // Call next transition for kerberos - mongo_auth_process.transition(doc.payload, function(err, payload) { - if(err) return callback(err, false); - - // Call the last and third step - MongoDBGSSAPIThirdStep(self, mongo_auth_process, payload, doc, db, username, password, authdb, server, connection, callback); - }); - }); -} - -var MongoDBGSSAPIThirdStep = function(self, mongo_auth_process, payload, doc, db, username, password, authdb, server, connection, callback) { - // Build final command - var command = { - saslContinue: 1 - , conversationId: doc.conversationId - , payload: payload - }; - - // Execute the command - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - // Write the commmand on the connection - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - if(err) return callback(err, false); - mongo_auth_process.transition(null, function(err, payload) { - if(err) return callback(err, null); - callback(null, r); - }); - }); -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -GSSAPI.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -GSSAPI.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var err = null; - var count = authStore.length; - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, authStore[i].options, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - -/** - * This is a result from a authentication strategy - * - * @callback authResultCallback - * @param {error} error An error object. Set to null if no error present - * @param {boolean} result The result of the authentication process - */ - -module.exports = GSSAPI; diff --git a/node_modules/mongodb-core/lib/auth/mongocr.js b/node_modules/mongodb-core/lib/auth/mongocr.js deleted file mode 100644 index 1f5a670..0000000 --- a/node_modules/mongodb-core/lib/auth/mongocr.js +++ /dev/null @@ -1,192 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , Query = require('../connection/commands').Query - , MongoError = require('../error'); - -var AuthSession = function(db, username, password) { - this.db = db; - this.username = username; - this.password = password; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -/** - * Creates a new MongoCR authentication mechanism - * @class - * @return {MongoCR} A cursor instance - */ -var MongoCR = function(bson) { - this.bson = bson; - this.authStore = []; -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -MongoCR.prototype.auth = function(server, connections, db, username, password, callback) { - var self = this; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // For each connection we need to authenticate - while(connections.length > 0) { - // Execute MongoCR - var executeMongoCR = function(connection) { - // Write the commmand on the connection - server(connection, new Query(self.bson, f("%s.$cmd", db), { - getnonce:1 - }, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // // Let's start the process - // server.command(f("%s.$cmd", db) - // , { getnonce: 1 } - // , { connection: connection }, function(err, r) { - var nonce = null; - var key = null; - - // Adjust the number of connections left - // Get nonce - if(err == null) { - nonce = r.result.nonce; - // Use node md5 generator - var md5 = crypto.createHash('md5'); - // Generate keys used for authentication - md5.update(username + ":mongo:" + password, 'utf8'); - var hash_password = md5.digest('hex'); - // Final key - md5 = crypto.createHash('md5'); - md5.update(nonce + username + hash_password, 'utf8'); - key = md5.digest('hex'); - } - - // Execute command - // Write the commmand on the connection - server(connection, new Query(self.bson, f("%s.$cmd", db), { - authenticate: 1, user: username, nonce: nonce, key:key - }, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command(f("%s.$cmd", db) - // , { authenticate: 1, user: username, nonce: nonce, key:key} - // , { connection: connection }, function(err, r) { - count = count - 1; - - // If we have an error - if(err) { - errorObject = err; - } else if(r.result['$err']) { - errorObject = r.result; - } else if(r.result['errmsg']) { - errorObject = r.result; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - // We have authenticated all connections - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password)); - // Return correct authentication - callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr")); - callback(errorObject, false); - } - }); - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - executeMongoCR(_connection); - }); - } - - _execute(connections.shift()); - } -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -MongoCR.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -MongoCR.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var err = null; - var count = authStore.length; - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - -/** - * This is a result from a authentication strategy - * - * @callback authResultCallback - * @param {error} error An error object. Set to null if no error present - * @param {boolean} result The result of the authentication process - */ - -module.exports = MongoCR; diff --git a/node_modules/mongodb-core/lib/auth/plain.js b/node_modules/mongodb-core/lib/auth/plain.js deleted file mode 100644 index 70210cb..0000000 --- a/node_modules/mongodb-core/lib/auth/plain.js +++ /dev/null @@ -1,173 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , Binary = require('bson').Binary - , Query = require('../connection/commands').Query - , MongoError = require('../error'); - -var AuthSession = function(db, username, password) { - this.db = db; - this.username = username; - this.password = password; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -/** - * Creates a new Plain authentication mechanism - * @class - * @return {Plain} A cursor instance - */ -var Plain = function(bson) { - this.bson = bson; - this.authStore = []; -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -Plain.prototype.auth = function(server, connections, db, username, password, callback) { - var self = this; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // For each connection we need to authenticate - while(connections.length > 0) { - // Execute MongoCR - var execute = function(connection) { - // Create payload - var payload = new Binary(f("\x00%s\x00%s", username, password)); - - // Let's start the sasl process - var command = { - saslStart: 1 - , mechanism: 'PLAIN' - , payload: payload - , autoAuthorize: 1 - }; - - // Let's start the process - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - // Adjust count - count = count - 1; - - // If we have an error - if(err) { - errorObject = err; - } else if(r.result['$err']) { - errorObject = r.result; - } else if(r.result['errmsg']) { - errorObject = r.result; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - // We have authenticated all connections - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password)); - // Return correct authentication - callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr")); - callback(errorObject, false); - } - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - execute(_connection); - }); - } - - _execute(connections.shift()); - } -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -Plain.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -Plain.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var err = null; - var count = authStore.length; - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - -/** - * This is a result from a authentication strategy - * - * @callback authResultCallback - * @param {error} error An error object. Set to null if no error present - * @param {boolean} result The result of the authentication process - */ - -module.exports = Plain; diff --git a/node_modules/mongodb-core/lib/auth/scram.js b/node_modules/mongodb-core/lib/auth/scram.js deleted file mode 100644 index cdb6507..0000000 --- a/node_modules/mongodb-core/lib/auth/scram.js +++ /dev/null @@ -1,345 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , Query = require('../connection/commands').Query - , Binary = require('bson').Binary - , MongoError = require('../error'); - -var AuthSession = function(db, username, password) { - this.db = db; - this.username = username; - this.password = password; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -var id = 0; - -/** - * Creates a new ScramSHA1 authentication mechanism - * @class - * @return {ScramSHA1} A cursor instance - */ -var ScramSHA1 = function(bson) { - this.bson = bson; - this.authStore = []; - this.id = id++; -} - -var parsePayload = function(payload) { - var dict = {}; - var parts = payload.split(','); - - for(var i = 0; i < parts.length; i++) { - var valueParts = parts[i].split('='); - dict[valueParts[0]] = valueParts[1]; - } - - return dict; -} - -var passwordDigest = function(username, password) { - if(typeof username != 'string') throw new MongoError("username must be a string"); - if(typeof password != 'string') throw new MongoError("password must be a string"); - if(password.length == 0) throw new MongoError("password cannot be empty"); - // Use node md5 generator - var md5 = crypto.createHash('md5'); - // Generate keys used for authentication - md5.update(username + ":mongo:" + password, 'utf8'); - return md5.digest('hex'); -} - -// XOR two buffers -var xor = function(a, b) { - if (!Buffer.isBuffer(a)) a = new Buffer(a) - if (!Buffer.isBuffer(b)) b = new Buffer(b) - var res = [] - if (a.length > b.length) { - for (var i = 0; i < b.length; i++) { - res.push(a[i] ^ b[i]) - } - } else { - for (var i = 0; i < a.length; i++) { - res.push(a[i] ^ b[i]) - } - } - return new Buffer(res); -} - -// Create a final digest -var hi = function(data, salt, iterations) { - // Create digest - var digest = function(msg) { - var hmac = crypto.createHmac('sha1', data); - hmac.update(msg); - return new Buffer(hmac.digest('base64'), 'base64'); - } - - // Create variables - salt = Buffer.concat([salt, new Buffer('\x00\x00\x00\x01')]) - var ui = digest(salt); - var u1 = ui; - - for(var i = 0; i < iterations - 1; i++) { - u1 = digest(u1); - ui = xor(ui, u1); - } - - return ui; -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -ScramSHA1.prototype.auth = function(server, connections, db, username, password, callback) { - var self = this; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // Execute MongoCR - var executeScram = function(connection) { - // Clean up the user - username = username.replace('=', "=3D").replace(',', '=2C'); - - // Create a random nonce - var nonce = crypto.randomBytes(24).toString('base64'); - // var nonce = 'MsQUY9iw0T9fx2MUEz6LZPwGuhVvWAhc' - var firstBare = f("n=%s,r=%s", username, nonce); - - // Build command structure - var cmd = { - saslStart: 1 - , mechanism: 'SCRAM-SHA-1' - , payload: new Binary(f("n,,%s", firstBare)) - , autoAuthorize: 1 - } - - // Handle the error - var handleError = function(err, r) { - if(err) { - numberOfValidConnections = numberOfValidConnections - 1; - errorObject = err; return false; - } else if(r.result['$err']) { - errorObject = r.result; return false; - } else if(r.result['errmsg']) { - errorObject = r.result; return false; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - return true - } - - // Finish up - var finish = function(_count, _numberOfValidConnections) { - if(_count == 0 && _numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password)); - // Return correct authentication - return callback(null, true); - } else if(_count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using scram")); - return callback(errorObject, false); - } - } - - var handleEnd = function(_err, _r) { - // Handle any error - handleError(_err, _r) - // Adjust the number of connections - count = count - 1; - // Execute the finish - finish(count, numberOfValidConnections); - } - - // Write the commmand on the connection - server(connection, new Query(self.bson, f("%s.$cmd", db), cmd, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // Do we have an error, handle it - if(handleError(err, r) == false) { - count = count - 1; - - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password)); - // Return correct authentication - return callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using scram")); - return callback(errorObject, false); - } - - return; - } - - // Get the dictionary - var dict = parsePayload(r.result.payload.value()) - - // Unpack dictionary - var iterations = parseInt(dict.i, 10); - var salt = dict.s; - var rnonce = dict.r; - - // Set up start of proof - var withoutProof = f("c=biws,r=%s", rnonce); - var passwordDig = passwordDigest(username, password); - var saltedPassword = hi(passwordDig - , new Buffer(salt, 'base64') - , iterations); - - // Create the client key - var hmac = crypto.createHmac('sha1', saltedPassword); - hmac.update(new Buffer("Client Key")); - var clientKey = new Buffer(hmac.digest('base64'), 'base64'); - - // Create the stored key - var hash = crypto.createHash('sha1'); - hash.update(clientKey); - var storedKey = new Buffer(hash.digest('base64'), 'base64'); - - // Create the authentication message - var authMsg = [firstBare, r.result.payload.value().toString('base64'), withoutProof].join(','); - - // Create client signature - var hmac = crypto.createHmac('sha1', storedKey); - hmac.update(new Buffer(authMsg)); - var clientSig = new Buffer(hmac.digest('base64'), 'base64'); - - // Create client proof - var clientProof = f("p=%s", new Buffer(xor(clientKey, clientSig)).toString('base64')); - - // Create client final - var clientFinal = [withoutProof, clientProof].join(','); - - // Generate server key - var hmac = crypto.createHmac('sha1', saltedPassword); - hmac.update(new Buffer('Server Key')) - var serverKey = new Buffer(hmac.digest('base64'), 'base64'); - - // Generate server signature - var hmac = crypto.createHmac('sha1', serverKey); - hmac.update(new Buffer(authMsg)) - var serverSig = new Buffer(hmac.digest('base64'), 'base64'); - - // - // Create continue message - var cmd = { - saslContinue: 1 - , conversationId: r.result.conversationId - , payload: new Binary(new Buffer(clientFinal)) - } - - // - // Execute sasl continue - // Write the commmand on the connection - server(connection, new Query(self.bson, f("%s.$cmd", db), cmd, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - if(r && r.result.done == false) { - var cmd = { - saslContinue: 1 - , conversationId: r.result.conversationId - , payload: new Buffer(0) - } - - // Write the commmand on the connection - server(connection, new Query(self.bson, f("%s.$cmd", db), cmd, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - handleEnd(err, r); - }); - } else { - handleEnd(err, r); - } - }); - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - executeScram(_connection); - }); - } - - // For each connection we need to authenticate - while(connections.length > 0) { - _execute(connections.shift()); - } -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -ScramSHA1.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -ScramSHA1.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var count = authStore.length; - var err = null; - // No connections - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - - -module.exports = ScramSHA1; diff --git a/node_modules/mongodb-core/lib/auth/sspi.js b/node_modules/mongodb-core/lib/auth/sspi.js deleted file mode 100644 index 60d744f..0000000 --- a/node_modules/mongodb-core/lib/auth/sspi.js +++ /dev/null @@ -1,267 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , require_optional = require('require_optional') - , Query = require('../connection/commands').Query - , MongoError = require('../error'); - -var AuthSession = function(db, username, password, options) { - this.db = db; - this.username = username; - this.password = password; - this.options = options; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -// Kerberos class -var Kerberos = null; -var MongoAuthProcess = null; - -// Try to grab the Kerberos class -try { - Kerberos = require_optional('kerberos').Kerberos - // Authentication process for Mongo - MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess -} catch(err) {} - -/** - * Creates a new SSPI authentication mechanism - * @class - * @return {SSPI} A cursor instance - */ -var SSPI = function(bson) { - this.bson = bson; - this.authStore = []; -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -SSPI.prototype.auth = function(server, connections, db, username, password, options, callback) { - var self = this; - // We don't have the Kerberos library - if(Kerberos == null) return callback(new Error("Kerberos library is not installed")); - var gssapiServiceName = options['gssapiServiceName'] || 'mongodb'; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // For each connection we need to authenticate - while(connections.length > 0) { - // Execute MongoCR - var execute = function(connection) { - // Start Auth process for a connection - SSIPAuthenticate(self, username, password, gssapiServiceName, server, connection, options, function(err, r) { - // Adjust count - count = count - 1; - - // If we have an error - if(err) { - errorObject = err; - } else if(r && typeof r == 'object' && r.result['$err']) { - errorObject = r.result; - } else if(r && typeof r == 'object' && r.result['errmsg']) { - errorObject = r.result; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - // We have authenticated all connections - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password, options)); - // Return correct authentication - callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr")); - callback(errorObject, false); - } - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - execute(_connection); - }); - } - - _execute(connections.shift()); - } -} - -var SSIPAuthenticate = function(self, username, password, gssapiServiceName, server, connection, options, callback) { - // Build Authentication command to send to MongoDB - var command = { - saslStart: 1 - , mechanism: 'GSSAPI' - , payload: '' - , autoAuthorize: 1 - }; - - // Create authenticator - var mongo_auth_process = new MongoAuthProcess(connection.host, connection.port, gssapiServiceName, options); - - // Execute first sasl step - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - - mongo_auth_process.init(username, password, function(err) { - if(err) return callback(err); - - mongo_auth_process.transition(doc.payload, function(err, payload) { - if(err) return callback(err); - - // Perform the next step against mongod - var command = { - saslContinue: 1 - , conversationId: doc.conversationId - , payload: payload - }; - - // Execute the command - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - - mongo_auth_process.transition(doc.payload, function(err, payload) { - if(err) return callback(err); - - // Perform the next step against mongod - var command = { - saslContinue: 1 - , conversationId: doc.conversationId - , payload: payload - }; - - // Execute the command - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - - mongo_auth_process.transition(doc.payload, function(err, payload) { - // Perform the next step against mongod - var command = { - saslContinue: 1 - , conversationId: doc.conversationId - , payload: payload - }; - - // Execute the command - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - if(err) return callback(err, false); - var doc = r.result; - - if(doc.done) return callback(null, true); - callback(new Error("Authentication failed"), false); - }); - }); - }); - }); - }); - }); - }); - }); -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -SSPI.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -SSPI.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var err = null; - var count = authStore.length; - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, authStore[i].options, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - -/** - * This is a result from a authentication strategy - * - * @callback authResultCallback - * @param {error} error An error object. Set to null if no error present - * @param {boolean} result The result of the authentication process - */ - -module.exports = SSPI; diff --git a/node_modules/mongodb-core/lib/auth/x509.js b/node_modules/mongodb-core/lib/auth/x509.js deleted file mode 100644 index b1b8287..0000000 --- a/node_modules/mongodb-core/lib/auth/x509.js +++ /dev/null @@ -1,168 +0,0 @@ -"use strict"; - -var f = require('util').format - , crypto = require('crypto') - , Query = require('../connection/commands').Query - , MongoError = require('../error'); - -var AuthSession = function(db, username, password) { - this.db = db; - this.username = username; - this.password = password; -} - -AuthSession.prototype.equal = function(session) { - return session.db == this.db - && session.username == this.username - && session.password == this.password; -} - -/** - * Creates a new X509 authentication mechanism - * @class - * @return {X509} A cursor instance - */ -var X509 = function(bson) { - this.bson = bson; - this.authStore = []; -} - -/** - * Authenticate - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {string} db Name of the database - * @param {string} username Username - * @param {string} password Password - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -X509.prototype.auth = function(server, connections, db, username, password, callback) { - var self = this; - // Total connections - var count = connections.length; - if(count == 0) return callback(null, null); - - // Valid connections - var numberOfValidConnections = 0; - var credentialsValid = false; - var errorObject = null; - - // For each connection we need to authenticate - while(connections.length > 0) { - // Execute MongoCR - var execute = function(connection) { - // Let's start the sasl process - var command = { - authenticate: 1 - , mechanism: 'MONGODB-X509' - , user: username - }; - - // Let's start the process - server(connection, new Query(self.bson, "$external.$cmd", command, { - numberToSkip: 0, numberToReturn: 1 - }).toBin(), function(err, r) { - // server.command("$external.$cmd" - // , command - // , { connection: connection }, function(err, r) { - // Adjust count - count = count - 1; - - // If we have an error - if(err) { - errorObject = err; - } else if(r.result['$err']) { - errorObject = r.result; - } else if(r.result['errmsg']) { - errorObject = r.result; - } else { - credentialsValid = true; - numberOfValidConnections = numberOfValidConnections + 1; - } - - // We have authenticated all connections - if(count == 0 && numberOfValidConnections > 0) { - // Store the auth details - addAuthSession(self.authStore, new AuthSession(db, username, password)); - // Return correct authentication - callback(null, true); - } else if(count == 0) { - if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr")); - callback(errorObject, false); - } - }); - } - - var _execute = function(_connection) { - process.nextTick(function() { - execute(_connection); - }); - } - - _execute(connections.shift()); - } -} - -// Add to store only if it does not exist -var addAuthSession = function(authStore, session) { - var found = false; - - for(var i = 0; i < authStore.length; i++) { - if(authStore[i].equal(session)) { - found = true; - break; - } - } - - if(!found) authStore.push(session); -} - -/** - * Remove authStore credentials - * @method - * @param {string} db Name of database we are removing authStore details about - * @return {object} - */ -X509.prototype.logout = function(dbName) { - this.authStore = this.authStore.filter(function(x) { - return x.db != dbName; - }); -} - -/** - * Re authenticate pool - * @method - * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on - * @param {[]Connections} connections Connections to authenticate using this authenticator - * @param {authResultCallback} callback The callback to return the result from the authentication - * @return {object} - */ -X509.prototype.reauthenticate = function(server, connections, callback) { - var authStore = this.authStore.slice(0); - var err = null; - var count = authStore.length; - if(count == 0) return callback(null, null); - // Iterate over all the auth details stored - for(var i = 0; i < authStore.length; i++) { - this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, function(err, r) { - if(err) err = err; - count = count - 1; - // Done re-authenticating - if(count == 0) { - callback(err, null); - } - }); - } -} - -/** - * This is a result from a authentication strategy - * - * @callback authResultCallback - * @param {error} error An error object. Set to null if no error present - * @param {boolean} result The result of the authentication process - */ - -module.exports = X509; diff --git a/node_modules/mongodb-core/lib/connection/command_result.js b/node_modules/mongodb-core/lib/connection/command_result.js deleted file mode 100644 index eb7b27a..0000000 --- a/node_modules/mongodb-core/lib/connection/command_result.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; - -var setProperty = require('../connection/utils').setProperty - , getProperty = require('../connection/utils').getProperty - , getSingleProperty = require('../connection/utils').getSingleProperty; - -/** - * Creates a new CommandResult instance - * @class - * @param {object} result CommandResult object - * @param {Connection} connection A connection instance associated with this result - * @return {CommandResult} A cursor instance - */ -var CommandResult = function(result, connection, message) { - this.result = result; - this.connection = connection; - this.message = message; -} - -/** - * Convert CommandResult to JSON - * @method - * @return {object} - */ -CommandResult.prototype.toJSON = function() { - return this.result; -} - -/** - * Convert CommandResult to String representation - * @method - * @return {string} - */ -CommandResult.prototype.toString = function() { - return JSON.stringify(this.toJSON()); -} - -module.exports = CommandResult; diff --git a/node_modules/mongodb-core/lib/connection/commands.js b/node_modules/mongodb-core/lib/connection/commands.js deleted file mode 100644 index dba0d1e..0000000 --- a/node_modules/mongodb-core/lib/connection/commands.js +++ /dev/null @@ -1,539 +0,0 @@ -"use strict"; - -var f = require('util').format - , Long = require('bson').Long - , setProperty = require('./utils').setProperty - , getProperty = require('./utils').getProperty - , getSingleProperty = require('./utils').getSingleProperty; - -// Incrementing request id -var _requestId = 0; - -// Wire command operation ids -var OP_QUERY = 2004; -var OP_GETMORE = 2005; -var OP_KILL_CURSORS = 2007; - -// Query flags -var OPTS_NONE = 0; -var OPTS_TAILABLE_CURSOR = 2; -var OPTS_SLAVE = 4; -var OPTS_OPLOG_REPLAY = 8; -var OPTS_NO_CURSOR_TIMEOUT = 16; -var OPTS_AWAIT_DATA = 32; -var OPTS_EXHAUST = 64; -var OPTS_PARTIAL = 128; - -// Response flags -var CURSOR_NOT_FOUND = 0; -var QUERY_FAILURE = 2; -var SHARD_CONFIG_STALE = 4; -var AWAIT_CAPABLE = 8; - -/************************************************************** - * QUERY - **************************************************************/ -var Query = function(bson, ns, query, options) { - var self = this; - // Basic options needed to be passed in - if(ns == null) throw new Error("ns must be specified for query"); - if(query == null) throw new Error("query must be specified for query"); - - // Validate that we are not passing 0x00 in the colletion name - if(!!~ns.indexOf("\x00")) { - throw new Error("namespace cannot contain a null character"); - } - - // Basic options - this.bson = bson; - this.ns = ns; - this.query = query; - - // Ensure empty options - this.options = options || {}; - - // Additional options - this.numberToSkip = options.numberToSkip || 0; - this.numberToReturn = options.numberToReturn || 0; - this.returnFieldSelector = options.returnFieldSelector || null; - this.requestId = _requestId++; - - // Serialization option - this.serializeFunctions = typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false; - this.ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : false; - this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16; - this.checkKeys = typeof options.checkKeys == 'boolean' ? options.checkKeys : true; - this.batchSize = self.numberToReturn; - - // Flags - this.tailable = false; - this.slaveOk = typeof options.slaveOk == 'boolean'? options.slaveOk : false; - this.oplogReplay = false; - this.noCursorTimeout = false; - this.awaitData = false; - this.exhaust = false; - this.partial = false; -} - -// -// Assign a new request Id -Query.prototype.incRequestId = function() { - this.requestId = _requestId++; -} - -// -// Assign a new request Id -Query.nextRequestId = function() { - return _requestId + 1; -} - -// -// Uses a single allocated buffer for the process, avoiding multiple memory allocations -Query.prototype.toBin = function() { - var self = this; - var buffers = []; - var projection = null; - - // Set up the flags - var flags = 0; - if(this.tailable) { - flags |= OPTS_TAILABLE_CURSOR; - } - - if(this.slaveOk) { - flags |= OPTS_SLAVE; - } - - if(this.oplogReplay) { - flags |= OPTS_OPLOG_REPLAY; - } - - if(this.noCursorTimeout) { - flags |= OPTS_NO_CURSOR_TIMEOUT; - } - - if(this.awaitData) { - flags |= OPTS_AWAIT_DATA; - } - - if(this.exhaust) { - flags |= OPTS_EXHAUST; - } - - if(this.partial) { - flags |= OPTS_PARTIAL; - } - - // If batchSize is different to self.numberToReturn - if(self.batchSize != self.numberToReturn) self.numberToReturn = self.batchSize; - - // Allocate write protocol header buffer - var header = new Buffer( - 4 * 4 // Header - + 4 // Flags - + Buffer.byteLength(self.ns) + 1 // namespace - + 4 // numberToSkip - + 4 // numberToReturn - ); - - // Add header to buffers - buffers.push(header); - - // Serialize the query - var query = self.bson.serialize(this.query - , this.checkKeys - , true - , this.serializeFunctions - , 0, this.ignoreUndefined); - - // Add query document - buffers.push(query); - - if(self.returnFieldSelector && Object.keys(self.returnFieldSelector).length > 0) { - // Serialize the projection document - projection = self.bson.serialize(this.returnFieldSelector, this.checkKeys, true, this.serializeFunctions, this.ignoreUndefined); - // Add projection document - buffers.push(projection); - } - - // Total message size - var totalLength = header.length + query.length + (projection ? projection.length : 0); - - // Set up the index - var index = 4; - - // Write total document length - header[3] = (totalLength >> 24) & 0xff; - header[2] = (totalLength >> 16) & 0xff; - header[1] = (totalLength >> 8) & 0xff; - header[0] = (totalLength) & 0xff; - - // Write header information requestId - header[index + 3] = (this.requestId >> 24) & 0xff; - header[index + 2] = (this.requestId >> 16) & 0xff; - header[index + 1] = (this.requestId >> 8) & 0xff; - header[index] = (this.requestId) & 0xff; - index = index + 4; - - // Write header information responseTo - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Write header information OP_QUERY - header[index + 3] = (OP_QUERY >> 24) & 0xff; - header[index + 2] = (OP_QUERY >> 16) & 0xff; - header[index + 1] = (OP_QUERY >> 8) & 0xff; - header[index] = (OP_QUERY) & 0xff; - index = index + 4; - - // Write header information flags - header[index + 3] = (flags >> 24) & 0xff; - header[index + 2] = (flags >> 16) & 0xff; - header[index + 1] = (flags >> 8) & 0xff; - header[index] = (flags) & 0xff; - index = index + 4; - - // Write collection name - index = index + header.write(this.ns, index, 'utf8') + 1; - header[index - 1] = 0; - - // Write header information flags numberToSkip - header[index + 3] = (this.numberToSkip >> 24) & 0xff; - header[index + 2] = (this.numberToSkip >> 16) & 0xff; - header[index + 1] = (this.numberToSkip >> 8) & 0xff; - header[index] = (this.numberToSkip) & 0xff; - index = index + 4; - - // Write header information flags numberToReturn - header[index + 3] = (this.numberToReturn >> 24) & 0xff; - header[index + 2] = (this.numberToReturn >> 16) & 0xff; - header[index + 1] = (this.numberToReturn >> 8) & 0xff; - header[index] = (this.numberToReturn) & 0xff; - index = index + 4; - - // Return the buffers - return buffers; -} - -Query.getRequestId = function() { - return ++_requestId; -} - -/************************************************************** - * GETMORE - **************************************************************/ -var GetMore = function(bson, ns, cursorId, opts) { - opts = opts || {}; - this.numberToReturn = opts.numberToReturn || 0; - this.requestId = _requestId++; - this.bson = bson; - this.ns = ns; - this.cursorId = cursorId; -} - -// -// Uses a single allocated buffer for the process, avoiding multiple memory allocations -GetMore.prototype.toBin = function() { - var length = 4 + Buffer.byteLength(this.ns) + 1 + 4 + 8 + (4 * 4); - // Create command buffer - var index = 0; - // Allocate buffer - var _buffer = new Buffer(length); - - // Write header information - // index = write32bit(index, _buffer, length); - _buffer[index + 3] = (length >> 24) & 0xff; - _buffer[index + 2] = (length >> 16) & 0xff; - _buffer[index + 1] = (length >> 8) & 0xff; - _buffer[index] = (length) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, requestId); - _buffer[index + 3] = (this.requestId >> 24) & 0xff; - _buffer[index + 2] = (this.requestId >> 16) & 0xff; - _buffer[index + 1] = (this.requestId >> 8) & 0xff; - _buffer[index] = (this.requestId) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, 0); - _buffer[index + 3] = (0 >> 24) & 0xff; - _buffer[index + 2] = (0 >> 16) & 0xff; - _buffer[index + 1] = (0 >> 8) & 0xff; - _buffer[index] = (0) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, OP_GETMORE); - _buffer[index + 3] = (OP_GETMORE >> 24) & 0xff; - _buffer[index + 2] = (OP_GETMORE >> 16) & 0xff; - _buffer[index + 1] = (OP_GETMORE >> 8) & 0xff; - _buffer[index] = (OP_GETMORE) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, 0); - _buffer[index + 3] = (0 >> 24) & 0xff; - _buffer[index + 2] = (0 >> 16) & 0xff; - _buffer[index + 1] = (0 >> 8) & 0xff; - _buffer[index] = (0) & 0xff; - index = index + 4; - - // Write collection name - index = index + _buffer.write(this.ns, index, 'utf8') + 1; - _buffer[index - 1] = 0; - - // Write batch size - // index = write32bit(index, _buffer, numberToReturn); - _buffer[index + 3] = (this.numberToReturn >> 24) & 0xff; - _buffer[index + 2] = (this.numberToReturn >> 16) & 0xff; - _buffer[index + 1] = (this.numberToReturn >> 8) & 0xff; - _buffer[index] = (this.numberToReturn) & 0xff; - index = index + 4; - - // Write cursor id - // index = write32bit(index, _buffer, cursorId.getLowBits()); - _buffer[index + 3] = (this.cursorId.getLowBits() >> 24) & 0xff; - _buffer[index + 2] = (this.cursorId.getLowBits() >> 16) & 0xff; - _buffer[index + 1] = (this.cursorId.getLowBits() >> 8) & 0xff; - _buffer[index] = (this.cursorId.getLowBits()) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, cursorId.getHighBits()); - _buffer[index + 3] = (this.cursorId.getHighBits() >> 24) & 0xff; - _buffer[index + 2] = (this.cursorId.getHighBits() >> 16) & 0xff; - _buffer[index + 1] = (this.cursorId.getHighBits() >> 8) & 0xff; - _buffer[index] = (this.cursorId.getHighBits()) & 0xff; - index = index + 4; - - // Return buffer - return _buffer; -} - -/************************************************************** - * KILLCURSOR - **************************************************************/ -var KillCursor = function(bson, cursorIds) { - this.requestId = _requestId++; - this.cursorIds = cursorIds; -} - -// -// Uses a single allocated buffer for the process, avoiding multiple memory allocations -KillCursor.prototype.toBin = function() { - var length = 4 + 4 + (4 * 4) + (this.cursorIds.length * 8); - - // Create command buffer - var index = 0; - var _buffer = new Buffer(length); - - // Write header information - // index = write32bit(index, _buffer, length); - _buffer[index + 3] = (length >> 24) & 0xff; - _buffer[index + 2] = (length >> 16) & 0xff; - _buffer[index + 1] = (length >> 8) & 0xff; - _buffer[index] = (length) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, requestId); - _buffer[index + 3] = (this.requestId >> 24) & 0xff; - _buffer[index + 2] = (this.requestId >> 16) & 0xff; - _buffer[index + 1] = (this.requestId >> 8) & 0xff; - _buffer[index] = (this.requestId) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, 0); - _buffer[index + 3] = (0 >> 24) & 0xff; - _buffer[index + 2] = (0 >> 16) & 0xff; - _buffer[index + 1] = (0 >> 8) & 0xff; - _buffer[index] = (0) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, OP_KILL_CURSORS); - _buffer[index + 3] = (OP_KILL_CURSORS >> 24) & 0xff; - _buffer[index + 2] = (OP_KILL_CURSORS >> 16) & 0xff; - _buffer[index + 1] = (OP_KILL_CURSORS >> 8) & 0xff; - _buffer[index] = (OP_KILL_CURSORS) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, 0); - _buffer[index + 3] = (0 >> 24) & 0xff; - _buffer[index + 2] = (0 >> 16) & 0xff; - _buffer[index + 1] = (0 >> 8) & 0xff; - _buffer[index] = (0) & 0xff; - index = index + 4; - - // Write batch size - // index = write32bit(index, _buffer, this.cursorIds.length); - _buffer[index + 3] = (this.cursorIds.length >> 24) & 0xff; - _buffer[index + 2] = (this.cursorIds.length >> 16) & 0xff; - _buffer[index + 1] = (this.cursorIds.length >> 8) & 0xff; - _buffer[index] = (this.cursorIds.length) & 0xff; - index = index + 4; - - // Write all the cursor ids into the array - for(var i = 0; i < this.cursorIds.length; i++) { - // Write cursor id - // index = write32bit(index, _buffer, cursorIds[i].getLowBits()); - _buffer[index + 3] = (this.cursorIds[i].getLowBits() >> 24) & 0xff; - _buffer[index + 2] = (this.cursorIds[i].getLowBits() >> 16) & 0xff; - _buffer[index + 1] = (this.cursorIds[i].getLowBits() >> 8) & 0xff; - _buffer[index] = (this.cursorIds[i].getLowBits()) & 0xff; - index = index + 4; - - // index = write32bit(index, _buffer, cursorIds[i].getHighBits()); - _buffer[index + 3] = (this.cursorIds[i].getHighBits() >> 24) & 0xff; - _buffer[index + 2] = (this.cursorIds[i].getHighBits() >> 16) & 0xff; - _buffer[index + 1] = (this.cursorIds[i].getHighBits() >> 8) & 0xff; - _buffer[index] = (this.cursorIds[i].getHighBits()) & 0xff; - index = index + 4; - } - - // Return buffer - return _buffer; -} - -var Response = function(bson, data, opts) { - opts = opts || {promoteLongs: true}; - this.parsed = false; - - // - // Parse Header - // - this.index = 0; - this.raw = data; - this.data = data; - this.bson = bson; - this.opts = opts; - - // Read the message length - this.length = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Fetch the request id for this reply - this.requestId = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Fetch the id of the request that triggered the response - this.responseTo = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Skip op-code field - this.index = this.index + 4; - - // Unpack flags - this.responseFlags = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Unpack the cursor - var lowBits = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - var highBits = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - // Create long object - this.cursorId = new Long(lowBits, highBits); - - // Unpack the starting from - this.startingFrom = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Unpack the number of objects returned - this.numberReturned = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24; - this.index = this.index + 4; - - // Preallocate document array - this.documents = new Array(this.numberReturned); - - // Flag values - this.cursorNotFound = (this.responseFlags & CURSOR_NOT_FOUND) != 0; - this.queryFailure = (this.responseFlags & QUERY_FAILURE) != 0; - this.shardConfigStale = (this.responseFlags & SHARD_CONFIG_STALE) != 0; - this.awaitCapable = (this.responseFlags & AWAIT_CAPABLE) != 0; - this.promoteLongs = typeof opts.promoteLongs == 'boolean' ? opts.promoteLongs : true; -} - -Response.prototype.isParsed = function() { - return this.parsed; -} - -// Validation buffers -var firstBatch = new Buffer('firstBatch', 'utf8'); -var nextBatch = new Buffer('nextBatch', 'utf8'); -var cursorId = new Buffer('id', 'utf8').toString('hex'); - -var documentBuffers = { - firstBatch: firstBatch.toString('hex'), - nextBatch: nextBatch.toString('hex') -}; - -Response.prototype.parse = function(options) { - // Don't parse again if not needed - if(this.parsed) return; - options = options || {}; - - // Allow the return of raw documents instead of parsing - var raw = options.raw || false; - var documentsReturnedIn = options.documentsReturnedIn || null; - - // - // Single document and documentsReturnedIn set - // - if(this.numberReturned == 1 && documentsReturnedIn != null && raw) { - // Calculate the bson size - var bsonSize = this.data[this.index] | this.data[this.index + 1] << 8 | this.data[this.index + 2] << 16 | this.data[this.index + 3] << 24; - // Slice out the buffer containing the command result document - var document = this.data.slice(this.index, this.index + bsonSize); - // Set up field we wish to keep as raw - var fieldsAsRaw = {} - fieldsAsRaw[documentsReturnedIn] = true; - // Set up the options - var _options = {promoteLongs: this.opts.promoteLongs, fieldsAsRaw: fieldsAsRaw}; - - // Deserialize but keep the array of documents in non-parsed form - var doc = this.bson.deserialize(document, _options); - - // Get the documents - this.documents = doc.cursor[documentsReturnedIn]; - this.numberReturned = this.documents.length; - // Ensure we have a Long valie cursor id - this.cursorId = typeof doc.cursor.id == 'number' - ? Long.fromNumber(doc.cursor.id) - : doc.cursor.id; - - // Adjust the index - this.index = this.index + bsonSize; - - // Set as parsed - this.parsed = true - return; - } - - // - // Parse Body - // - for(var i = 0; i < this.numberReturned; i++) { - var bsonSize = this.data[this.index] | this.data[this.index + 1] << 8 | this.data[this.index + 2] << 16 | this.data[this.index + 3] << 24; - // Parse options - var _options = {promoteLongs: this.opts.promoteLongs}; - - // If we have raw results specified slice the return document - if(raw) { - this.documents[i] = this.data.slice(this.index, this.index + bsonSize); - } else { - this.documents[i] = this.bson.deserialize(this.data.slice(this.index, this.index + bsonSize), _options); - } - - // Adjust the index - this.index = this.index + bsonSize; - } - - // Set parsed - this.parsed = true; -} - -module.exports = { - Query: Query - , GetMore: GetMore - , Response: Response - , KillCursor: KillCursor -} diff --git a/node_modules/mongodb-core/lib/connection/connection.js b/node_modules/mongodb-core/lib/connection/connection.js deleted file mode 100644 index b44c4e0..0000000 --- a/node_modules/mongodb-core/lib/connection/connection.js +++ /dev/null @@ -1,531 +0,0 @@ -"use strict"; - -var inherits = require('util').inherits - , EventEmitter = require('events').EventEmitter - , net = require('net') - , tls = require('tls') - , f = require('util').format - , debugOptions = require('./utils').debugOptions - , Response = require('./commands').Response - , MongoError = require('../error') - , Logger = require('./logger'); - -var _id = 0; -var debugFields = ['host', 'port', 'size', 'keepAlive', 'keepAliveInitialDelay', 'noDelay' - , 'connectionTimeout', 'socketTimeout', 'singleBufferSerializtion', 'ssl', 'ca', 'cert' - , 'rejectUnauthorized', 'promoteLongs', 'checkServerIdentity']; -var connectionAccounting = false; -var connections = {}; - -/** - * Creates a new Connection instance - * @class - * @param {string} options.host The server host - * @param {number} options.port The server port - * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled - * @param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled - * @param {boolean} [options.noDelay=true] TCP Connection no delay - * @param {number} [options.connectionTimeout=0] TCP Connection timeout setting - * @param {number} [options.socketTimeout=0] TCP Socket timeout setting - * @param {boolean} [options.singleBufferSerializtion=true] Serialize into single buffer, trade of peak memory for serialization speed - * @param {boolean} [options.ssl=false] Use SSL for connection - * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. - * @param {Buffer} [options.ca] SSL Certificate store binary buffer - * @param {Buffer} [options.cert] SSL Certificate binary buffer - * @param {Buffer} [options.key] SSL Key file binary buffer - * @param {string} [options.passphrase] SSL Certificate pass phrase - * @param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates - * @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits - * @fires Connection#connect - * @fires Connection#close - * @fires Connection#error - * @fires Connection#timeout - * @fires Connection#parseError - * @return {Connection} A cursor instance - */ -var Connection = function(messageHandler, options) { - // Add event listener - EventEmitter.call(this); - // Set empty if no options passed - this.options = options || {}; - // Identification information - this.id = _id++; - // Logger instance - this.logger = Logger('Connection', options); - // No bson parser passed in - if(!options.bson) throw new Error("must pass in valid bson parser"); - // Get bson parser - this.bson = options.bson; - // Grouping tag used for debugging purposes - this.tag = options.tag; - // Message handler - this.messageHandler = messageHandler; - - // Max BSON message size - this.maxBsonMessageSize = options.maxBsonMessageSize || (1024 * 1024 * 16 * 4); - // Debug information - if(this.logger.isDebug()) this.logger.debug(f('creating connection %s with options [%s]', this.id, JSON.stringify(debugOptions(debugFields, options)))); - - // Default options - this.port = options.port || 27017; - this.host = options.host || 'localhost'; - this.keepAlive = typeof options.keepAlive == 'boolean' ? options.keepAlive : true; - this.keepAliveInitialDelay = options.keepAliveInitialDelay || 0; - this.noDelay = typeof options.noDelay == 'boolean' ? options.noDelay : true; - this.connectionTimeout = options.connectionTimeout || 0; - this.socketTimeout = options.socketTimeout || 0; - - // If connection was destroyed - this.destroyed = false; - - // Check if we have a domain socket - this.domainSocket = this.host.indexOf('\/') != -1; - - // Serialize commands using function - this.singleBufferSerializtion = typeof options.singleBufferSerializtion == 'boolean' ? options.singleBufferSerializtion : true; - this.serializationFunction = this.singleBufferSerializtion ? 'toBinUnified' : 'toBin'; - - // SSL options - this.ca = options.ca || null; - this.cert = options.cert || null; - this.key = options.key || null; - this.passphrase = options.passphrase || null; - this.ssl = typeof options.ssl == 'boolean' ? options.ssl : false; - this.rejectUnauthorized = typeof options.rejectUnauthorized == 'boolean' ? options.rejectUnauthorized : true; - this.checkServerIdentity = typeof options.checkServerIdentity == 'boolean' - || typeof options.checkServerIdentity == 'function' ? options.checkServerIdentity : true; - - // If ssl not enabled - if(!this.ssl) this.rejectUnauthorized = false; - - // Response options - this.responseOptions = { - promoteLongs: typeof options.promoteLongs == 'boolean' ? options.promoteLongs : true - } - - // Flushing - this.flushing = false; - this.queue = []; - - // Internal state - this.connection = null; - this.writeStream = null; -} - -inherits(Connection, EventEmitter); - -Connection.prototype.setSocketTimeout = function(value) { - if(this.connection) { - this.connection.setTimeout(value); - } -} - -Connection.prototype.resetSocketTimeout = function(value) { - if(this.connection) { - this.connection.setTimeout(this.socketTimeout);; - } -} - -Connection.enableConnectionAccounting = function() { - connectionAccounting = true; - connections = {}; -} - -Connection.disableConnectionAccounting = function() { - connectionAccounting = false; -} - -Connection.connections = function() { - return connections; -} - -// -// Connection handlers -var errorHandler = function(self) { - return function(err) { - if(connectionAccounting) delete connections[self.id]; - // Debug information - if(self.logger.isDebug()) self.logger.debug(f('connection %s for [%s:%s] errored out with [%s]', self.id, self.host, self.port, JSON.stringify(err))); - // Emit the error - if(self.listeners('error').length > 0) self.emit("error", MongoError.create(err), self); - } -} - -var timeoutHandler = function(self) { - return function(err) { - if(connectionAccounting) delete connections[self.id]; - // Debug information - if(self.logger.isDebug()) self.logger.debug(f('connection %s for [%s:%s] timed out', self.id, self.host, self.port)); - // Emit timeout error - self.emit("timeout" - , MongoError.create(f("connection %s to %s:%s timed out", self.id, self.host, self.port)) - , self); - } -} - -var closeHandler = function(self) { - return function(hadError) { - if(connectionAccounting) delete connections[self.id]; - // Debug information - if(self.logger.isDebug()) self.logger.debug(f('connection %s with for [%s:%s] closed', self.id, self.host, self.port)); - - // Emit close event - if(!hadError) { - self.emit("close" - , MongoError.create(f("connection %s to %s:%s closed", self.id, self.host, self.port)) - , self); - } - } -} - -var dataHandler = function(self) { - return function(data) { - // Parse until we are done with the data - while(data.length > 0) { - // If we still have bytes to read on the current message - if(self.bytesRead > 0 && self.sizeOfMessage > 0) { - // Calculate the amount of remaining bytes - var remainingBytesToRead = self.sizeOfMessage - self.bytesRead; - // Check if the current chunk contains the rest of the message - if(remainingBytesToRead > data.length) { - // Copy the new data into the exiting buffer (should have been allocated when we know the message size) - data.copy(self.buffer, self.bytesRead); - // Adjust the number of bytes read so it point to the correct index in the buffer - self.bytesRead = self.bytesRead + data.length; - - // Reset state of buffer - data = new Buffer(0); - } else { - // Copy the missing part of the data into our current buffer - data.copy(self.buffer, self.bytesRead, 0, remainingBytesToRead); - // Slice the overflow into a new buffer that we will then re-parse - data = data.slice(remainingBytesToRead); - - // Emit current complete message - try { - var emitBuffer = self.buffer; - // Reset state of buffer - self.buffer = null; - self.sizeOfMessage = 0; - self.bytesRead = 0; - self.stubBuffer = null; - // Emit the buffer - self.messageHandler(new Response(self.bson, emitBuffer, self.responseOptions), self); - } catch(err) { - var errorObject = {err:"socketHandler", trace:err, bin:self.buffer, parseState:{ - sizeOfMessage:self.sizeOfMessage, - bytesRead:self.bytesRead, - stubBuffer:self.stubBuffer}}; - // We got a parse Error fire it off then keep going - self.emit("parseError", errorObject, self); - } - } - } else { - // Stub buffer is kept in case we don't get enough bytes to determine the - // size of the message (< 4 bytes) - if(self.stubBuffer != null && self.stubBuffer.length > 0) { - // If we have enough bytes to determine the message size let's do it - if(self.stubBuffer.length + data.length > 4) { - // Prepad the data - var newData = new Buffer(self.stubBuffer.length + data.length); - self.stubBuffer.copy(newData, 0); - data.copy(newData, self.stubBuffer.length); - // Reassign for parsing - data = newData; - - // Reset state of buffer - self.buffer = null; - self.sizeOfMessage = 0; - self.bytesRead = 0; - self.stubBuffer = null; - - } else { - - // Add the the bytes to the stub buffer - var newStubBuffer = new Buffer(self.stubBuffer.length + data.length); - // Copy existing stub buffer - self.stubBuffer.copy(newStubBuffer, 0); - // Copy missing part of the data - data.copy(newStubBuffer, self.stubBuffer.length); - // Exit parsing loop - data = new Buffer(0); - } - } else { - if(data.length > 4) { - // Retrieve the message size - // var sizeOfMessage = data.readUInt32LE(0); - var sizeOfMessage = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; - // If we have a negative sizeOfMessage emit error and return - if(sizeOfMessage < 0 || sizeOfMessage > self.maxBsonMessageSize) { - var errorObject = {err:"socketHandler", trace:'', bin:self.buffer, parseState:{ - sizeOfMessage: sizeOfMessage, - bytesRead: self.bytesRead, - stubBuffer: self.stubBuffer}}; - // We got a parse Error fire it off then keep going - self.emit("parseError", errorObject, self); - return; - } - - // Ensure that the size of message is larger than 0 and less than the max allowed - if(sizeOfMessage > 4 && sizeOfMessage < self.maxBsonMessageSize && sizeOfMessage > data.length) { - self.buffer = new Buffer(sizeOfMessage); - // Copy all the data into the buffer - data.copy(self.buffer, 0); - // Update bytes read - self.bytesRead = data.length; - // Update sizeOfMessage - self.sizeOfMessage = sizeOfMessage; - // Ensure stub buffer is null - self.stubBuffer = null; - // Exit parsing loop - data = new Buffer(0); - - } else if(sizeOfMessage > 4 && sizeOfMessage < self.maxBsonMessageSize && sizeOfMessage == data.length) { - try { - var emitBuffer = data; - // Reset state of buffer - self.buffer = null; - self.sizeOfMessage = 0; - self.bytesRead = 0; - self.stubBuffer = null; - // Exit parsing loop - data = new Buffer(0); - // Emit the message - self.messageHandler(new Response(self.bson, emitBuffer, self.responseOptions), self); - } catch (err) { - self.emit("parseError", err, self); - } - } else if(sizeOfMessage <= 4 || sizeOfMessage > self.maxBsonMessageSize) { - var errorObject = {err:"socketHandler", trace:null, bin:data, parseState:{ - sizeOfMessage:sizeOfMessage, - bytesRead:0, - buffer:null, - stubBuffer:null}}; - // We got a parse Error fire it off then keep going - self.emit("parseError", errorObject, self); - - // Clear out the state of the parser - self.buffer = null; - self.sizeOfMessage = 0; - self.bytesRead = 0; - self.stubBuffer = null; - // Exit parsing loop - data = new Buffer(0); - } else { - var emitBuffer = data.slice(0, sizeOfMessage); - // Reset state of buffer - self.buffer = null; - self.sizeOfMessage = 0; - self.bytesRead = 0; - self.stubBuffer = null; - // Copy rest of message - data = data.slice(sizeOfMessage); - // Emit the message - self.messageHandler(new Response(self.bson, emitBuffer, self.responseOptions), self); - } - } else { - // Create a buffer that contains the space for the non-complete message - self.stubBuffer = new Buffer(data.length) - // Copy the data to the stub buffer - data.copy(self.stubBuffer, 0); - // Exit parsing loop - data = new Buffer(0); - } - } - } - } - } -} - -/** - * Connect - * @method - */ -Connection.prototype.connect = function(_options) { - var self = this; - _options = _options || {}; - // Set the connections - if(connectionAccounting) connections[this.id] = this; - // Check if we are overriding the promoteLongs - if(typeof _options.promoteLongs == 'boolean') { - self.responseOptions.promoteLongs = _options.promoteLongs; - } - - // Create new connection instance - self.connection = self.domainSocket - ? net.createConnection(self.host) - : net.createConnection(self.port, self.host); - - // Set the options for the connection - self.connection.setKeepAlive(self.keepAlive, self.keepAliveInitialDelay); - self.connection.setTimeout(self.connectionTimeout); - self.connection.setNoDelay(self.noDelay); - - // If we have ssl enabled - if(self.ssl) { - var sslOptions = { - socket: self.connection - , rejectUnauthorized: self.rejectUnauthorized - } - - if(self.ca) sslOptions.ca = self.ca; - if(self.cert) sslOptions.cert = self.cert; - if(self.key) sslOptions.key = self.key; - if(self.passphrase) sslOptions.passphrase = self.passphrase; - - // Override checkServerIdentity behavior - if(self.checkServerIdentity == false) { - // Skip the identiy check by retuning undefined as per node documents - // https://nodejs.org/api/tls.html#tls_tls_connect_options_callback - sslOptions.checkServerIdentity = function(servername, cert) { - return undefined; - } - } else if(typeof self.checkServerIdentity == 'function') { - sslOptions.checkServerIdentity = self.checkServerIdentity; - } - - // Attempt SSL connection - self.connection = tls.connect(self.port, self.host, sslOptions, function() { - // Error on auth or skip - if(self.connection.authorizationError && self.rejectUnauthorized) { - return self.emit("error", self.connection.authorizationError, self, {ssl:true}); - } - - // Set socket timeout instead of connection timeout - self.connection.setTimeout(self.socketTimeout); - // We are done emit connect - self.emit('connect', self); - }); - self.connection.setTimeout(self.connectionTimeout); - } else { - self.connection.on('connect', function() { - // Set socket timeout instead of connection timeout - self.connection.setTimeout(self.socketTimeout); - // Emit connect event - self.emit('connect', self); - }); - } - - // Add handlers for events - self.connection.once('error', errorHandler(self)); - self.connection.once('timeout', timeoutHandler(self)); - self.connection.once('close', closeHandler(self)); - self.connection.on('data', dataHandler(self)); -} - -/** - * Unref this connection - * @method - * @return {boolean} - */ -Connection.prototype.unref = function() { - if (this.connection) this.connection.unref(); - else { - var self = this; - this.once('connect', function() { - self.connection.unref(); - }); - } -} - -/** - * Destroy connection - * @method - */ -Connection.prototype.destroy = function() { - // Set the connections - if(connectionAccounting) delete connections[this.id]; - if(this.connection) { - this.connection.end(); - this.connection.destroy(); - } - - this.destroyed = true; -} - -/** - * Write to connection - * @method - * @param {Command} command Command to write out need to implement toBin and toBinUnified - */ -Connection.prototype.write = function(buffer) { - // Debug Log - if(this.logger.isDebug()) { - if(!Array.isArray(buffer)) { - this.logger.debug(f('writing buffer [%s] to %s:%s', buffer.toString('hex'), this.host, this.port)); - } else { - for(var i = 0; i < buffer.length; i++) - this.logger.debug(f('writing buffer [%s] to %s:%s', buffer[i].toString('hex'), this.host, this.port)); - } - } - - // Write out the command - if(!Array.isArray(buffer)) return this.connection.write(buffer, 'binary'); - // Iterate over all buffers and write them in order to the socket - for(var i = 0; i < buffer.length; i++) this.connection.write(buffer[i], 'binary'); -} - -/** - * Return id of connection as a string - * @method - * @return {string} - */ -Connection.prototype.toString = function() { - return "" + this.id; -} - -/** - * Return json object of connection - * @method - * @return {object} - */ -Connection.prototype.toJSON = function() { - return {id: this.id, host: this.host, port: this.port}; -} - -/** - * Is the connection connected - * @method - * @return {boolean} - */ -Connection.prototype.isConnected = function() { - if(this.destroyed) return false; - return !this.connection.destroyed && this.connection.writable; -} - -/** - * A server connect event, used to verify that the connection is up and running - * - * @event Connection#connect - * @type {Connection} - */ - -/** - * The server connection closed, all pool connections closed - * - * @event Connection#close - * @type {Connection} - */ - -/** - * The server connection caused an error, all pool connections closed - * - * @event Connection#error - * @type {Connection} - */ - -/** - * The server connection timed out, all pool connections closed - * - * @event Connection#timeout - * @type {Connection} - */ - -/** - * The driver experienced an invalid message, all pool connections closed - * - * @event Connection#parseError - * @type {Connection} - */ - -module.exports = Connection; diff --git a/node_modules/mongodb-core/lib/connection/logger.js b/node_modules/mongodb-core/lib/connection/logger.js deleted file mode 100644 index cba8954..0000000 --- a/node_modules/mongodb-core/lib/connection/logger.js +++ /dev/null @@ -1,229 +0,0 @@ -"use strict"; - -var f = require('util').format - , MongoError = require('../error'); - -// Filters for classes -var classFilters = {}; -var filteredClasses = {}; -var level = null; -// Save the process id -var pid = process.pid; -// current logger -var currentLogger = null; - -/** - * Creates a new Logger instance - * @class - * @param {string} className The Class name associated with the logging instance - * @param {object} [options=null] Optional settings. - * @param {Function} [options.logger=null] Custom logger function; - * @param {string} [options.loggerLevel=error] Override default global log level. - * @return {Logger} a Logger instance. - */ -var Logger = function(className, options) { - if(!(this instanceof Logger)) return new Logger(className, options); - options = options || {}; - - // Current reference - var self = this; - this.className = className; - - // Current logger - if(options.logger) { - currentLogger = options.logger; - } else if(currentLogger == null) { - currentLogger = console.log; - } - - // Set level of logging, default is error - if(options.loggerLevel) { - level = options.loggerLevel || 'error'; - } - - // Add all class names - if(filteredClasses[this.className] == null) classFilters[this.className] = true; -} - -/** - * Log a message at the debug level - * @method - * @param {string} message The message to log - * @param {object} object additional meta data to log - * @return {null} - */ -Logger.prototype.debug = function(message, object) { - if(this.isDebug() - && ((Object.keys(filteredClasses).length > 0 && filteredClasses[this.className]) - || (Object.keys(filteredClasses).length == 0 && classFilters[this.className]))) { - var dateTime = new Date().getTime(); - var msg = f("[%s-%s:%s] %s %s", 'DEBUG', this.className, pid, dateTime, message); - var state = { - type: 'debug', message: message, className: this.className, pid: pid, date: dateTime - }; - if(object) state.meta = object; - currentLogger(msg, state); - } -} - -/** - * Log a message at the warn level - * @method - * @param {string} message The message to log - * @param {object} object additional meta data to log - * @return {null} - */ -Logger.prototype.warn = function(message, object) { - if(this.isWarn() - && ((Object.keys(filteredClasses).length > 0 && filteredClasses[this.className]) - || (Object.keys(filteredClasses).length == 0 && classFilters[this.className]))) { - var dateTime = new Date().getTime(); - var msg = f("[%s-%s:%s] %s %s", 'WARN', this.className, pid, dateTime, message); - var state = { - type: 'warn', message: message, className: this.className, pid: pid, date: dateTime - }; - if(object) state.meta = object; - currentLogger(msg, state); - } -}, - -/** - * Log a message at the info level - * @method - * @param {string} message The message to log - * @param {object} object additional meta data to log - * @return {null} - */ -Logger.prototype.info = function(message, object) { - if(this.isInfo() - && ((Object.keys(filteredClasses).length > 0 && filteredClasses[this.className]) - || (Object.keys(filteredClasses).length == 0 && classFilters[this.className]))) { - var dateTime = new Date().getTime(); - var msg = f("[%s-%s:%s] %s %s", 'INFO', this.className, pid, dateTime, message); - var state = { - type: 'info', message: message, className: this.className, pid: pid, date: dateTime - }; - if(object) state.meta = object; - currentLogger(msg, state); - } -}, - -/** - * Log a message at the error level - * @method - * @param {string} message The message to log - * @param {object} object additional meta data to log - * @return {null} - */ -Logger.prototype.error = function(message, object) { - if(this.isError() - && ((Object.keys(filteredClasses).length > 0 && filteredClasses[this.className]) - || (Object.keys(filteredClasses).length == 0 && classFilters[this.className]))) { - var dateTime = new Date().getTime(); - var msg = f("[%s-%s:%s] %s %s", 'ERROR', this.className, pid, dateTime, message); - var state = { - type: 'error', message: message, className: this.className, pid: pid, date: dateTime - }; - if(object) state.meta = object; - currentLogger(msg, state); - } -}, - -/** - * Is the logger set at info level - * @method - * @return {boolean} - */ -Logger.prototype.isInfo = function() { - return level == 'info' || level == 'debug'; -}, - -/** - * Is the logger set at error level - * @method - * @return {boolean} - */ -Logger.prototype.isError = function() { - return level == 'error' || level == 'info' || level == 'debug'; -}, - -/** - * Is the logger set at error level - * @method - * @return {boolean} - */ -Logger.prototype.isWarn = function() { - return level == 'error' || level == 'warn' || level == 'info' || level == 'debug'; -}, - -/** - * Is the logger set at debug level - * @method - * @return {boolean} - */ -Logger.prototype.isDebug = function() { - return level == 'debug'; -} - -/** - * Resets the logger to default settings, error and no filtered classes - * @method - * @return {null} - */ -Logger.reset = function() { - level = 'error'; - filteredClasses = {}; -} - -/** - * Get the current logger function - * @method - * @return {function} - */ -Logger.currentLogger = function() { - return currentLogger; -} - -/** - * Set the current logger function - * @method - * @param {function} logger Logger function. - * @return {null} - */ -Logger.setCurrentLogger = function(logger) { - if(typeof logger != 'function') throw new MongoError("current logger must be a function"); - currentLogger = logger; -} - -/** - * Set what classes to log. - * @method - * @param {string} type The type of filter (currently only class) - * @param {string[]} values The filters to apply - * @return {null} - */ -Logger.filter = function(type, values) { - if(type == 'class' && Array.isArray(values)) { - filteredClasses = {}; - - values.forEach(function(x) { - filteredClasses[x] = true; - }); - } -} - -/** - * Set the current log level - * @method - * @param {string} level Set current log level (debug, info, error) - * @return {null} - */ -Logger.setLevel = function(_level) { - if(_level != 'info' && _level != 'error' && _level != 'debug' && _level != 'warn') { - throw new Error(f("%s is an illegal logging level", _level)); - } - - level = _level; -} - -module.exports = Logger; diff --git a/node_modules/mongodb-core/lib/connection/pool.js b/node_modules/mongodb-core/lib/connection/pool.js deleted file mode 100644 index 4f1c83b..0000000 --- a/node_modules/mongodb-core/lib/connection/pool.js +++ /dev/null @@ -1,1122 +0,0 @@ -"use strict"; - -var inherits = require('util').inherits, - EventEmitter = require('events').EventEmitter, - Connection = require('./connection'), - MongoError = require('../error'), - Logger = require('./logger'), - f = require('util').format, - Query = require('./commands').Query, - CommandResult = require('./command_result'), - assign = require('../topologies/shared').assign; - -var MongoCR = require('../auth/mongocr') - , X509 = require('../auth/x509') - , Plain = require('../auth/plain') - , GSSAPI = require('../auth/gssapi') - , SSPI = require('../auth/sspi') - , ScramSHA1 = require('../auth/scram'); - -var DISCONNECTED = 'disconnected'; -var CONNECTING = 'connecting'; -var CONNECTED = 'connected'; -var DESTROYING = 'destroying'; -var DESTROYED = 'destroyed'; - -var _id = 0; - -/** - * Creates a new Pool instance - * @class - * @param {string} options.host The server host - * @param {number} options.port The server port - * @param {number} [options.size=1] Max server connection pool size - * @param {boolean} [options.reconnect=true] Server will attempt to reconnect on loss of connection - * @param {number} [options.reconnectTries=30] Server attempt to reconnect #times - * @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries - * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled - * @param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled - * @param {boolean} [options.noDelay=true] TCP Connection no delay - * @param {number} [options.connectionTimeout=0] TCP Connection timeout setting - * @param {number} [options.socketTimeout=0] TCP Socket timeout setting - * @param {number} [options.monitoringSocketTimeout=30000] TCP Socket timeout setting for replicaset monitoring socket - * @param {boolean} [options.ssl=false] Use SSL for connection - * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. - * @param {Buffer} [options.ca] SSL Certificate store binary buffer - * @param {Buffer} [options.cert] SSL Certificate binary buffer - * @param {Buffer} [options.key] SSL Key file binary buffer - * @param {string} [options.passPhrase] SSL Certificate pass phrase - * @param {boolean} [options.rejectUnauthorized=false] Reject unauthorized server certificates - * @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits - * @fires Pool#connect - * @fires Pool#close - * @fires Pool#error - * @fires Pool#timeout - * @fires Pool#parseError - * @return {Pool} A cursor instance - */ -var Pool = function(options) { - var self = this; - // Add event listener - EventEmitter.call(this); - // Add the options - this.options = assign({ - // Host and port settings - host: 'localhost', - port: 27017, - // Pool default max size - size: 5, - // socket settings - connectionTimeout: 30000, - socketTimeout: 30000, - keepAlive: true, - keepAliveInitialDelay: 0, - noDelay: true, - // SSL Settings - ssl: false, checkServerIdentity: false, - ca: null, cert: null, key: null, passPhrase: null, - rejectUnauthorized: false, - promoteLongs: true, - // Reconnection options - reconnect: true, - reconnectInterval: 1000, - reconnectTries: 30 - }, options); - - // Identification information - this.id = _id++; - // Current reconnect retries - this.retriesLeft = this.options.reconnectTries; - this.reconnectId = null; - // No bson parser passed in - if(!options.bson || (options.bson - && (typeof options.bson.serialize != 'function' || typeof options.bson.deserialize != 'function'))) throw new Error("must pass in valid bson parser"); - // Logger instance - this.logger = Logger('Pool', options); - // Pool state - this.state = DISCONNECTED; - // Connections - this.availableConnections = []; - this.inUseConnections = []; - this.connectingConnections = []; - // Currently executing - this.executing = false; - // Operation work queue - this.queue = []; - - // All the authProviders - this.authProviders = options.authProviders || { - 'mongocr': new MongoCR(options.bson), 'x509': new X509(options.bson) - , 'plain': new Plain(options.bson), 'gssapi': new GSSAPI(options.bson) - , 'sspi': new SSPI(options.bson), 'scram-sha-1': new ScramSHA1(options.bson) - } - - // Are we currently authenticating - this.authenticating = false; - this.loggingout = false; - this.nonAuthenticatedConnections = []; - this.authenticatingTimestamp = null; - // Number of consecutive timeouts caught - this.numberOfConsecutiveTimeouts = 0; -} - -inherits(Pool, EventEmitter); - -Object.defineProperty(Pool.prototype, 'size', { - enumerable:true, - get: function() { return this.options.size; } -}); - -Object.defineProperty(Pool.prototype, 'connectionTimeout', { - enumerable:true, - get: function() { return this.options.connectionTimeout; } -}); - -Object.defineProperty(Pool.prototype, 'socketTimeout', { - enumerable:true, - get: function() { return this.options.socketTimeout; } -}); - -function stateTransition(self, newState) { - var legalTransitions = { - 'disconnected': [CONNECTING, DESTROYING, DISCONNECTED], - 'connecting': [CONNECTING, DESTROYING, CONNECTED, DISCONNECTED], - 'connected': [CONNECTED, DISCONNECTED, DESTROYING], - 'destroying': [DESTROYING, DESTROYED], - 'destroyed': [DESTROYED] - } - - // Get current state - var legalStates = legalTransitions[self.state]; - if(legalStates && legalStates.indexOf(newState) != -1) { - self.state = newState; - } else { - self.logger.error(f('Pool with id [%s] failed attempted illegal state transition from [%s] to [%s] only following state allowed [%s]' - , self.id, self.state, newState, legalStates)); - } -} - -function authenticate(pool, auth, connection, cb) { - if(auth[0] === undefined) return cb(null); - // We need to authenticate the server - var mechanism = auth[0]; - var db = auth[1]; - // Validate if the mechanism exists - if(!pool.authProviders[mechanism]) { - throw new MongoError(f('authMechanism %s not supported', mechanism)); - } - - // Get the provider - var provider = pool.authProviders[mechanism]; - - // Authenticate using the provided mechanism - provider.auth.apply(provider, [write(pool), [connection], db].concat(auth.slice(2)).concat([cb])); -} - -// The write function used by the authentication mechanism (bypasses external) -function write(self) { - return function(connection, buffer, callback) { - // Ensure we stop auth if pool was destroyed - if(self.state == DESTROYED || self.state == DESTROYING) { - return callback(new MongoError('pool destroyed')); - } - // Set the connection workItem callback - connection.workItem = {cb: callback, command: true}; - // Write the buffer out to the connection - connection.write(buffer); - }; -} - - -function reauthenticate(pool, connection, cb) { - // Authenticate - function authenticateAgainstProvider(pool, connection, providers, cb) { - // Finished re-authenticating against providers - if(providers.length == 0) return cb(); - // Get the provider name - var provider = pool.authProviders[providers.pop()]; - - // Auth provider - provider.reauthenticate(write(pool), [connection], function(err, r) { - // We got an error return immediately - if(err) return cb(err); - // Continue authenticating the connection - authenticateAgainstProvider(pool, connection, providers, cb); - }); - } - - // Start re-authenticating process - authenticateAgainstProvider(pool, connection, Object.keys(pool.authProviders), cb); -} - -function connectionFailureHandler(self, event) { - return function(err) { - removeConnection(self, this); - - // Flush out the callback if there is one - if(this.workItem && this.workItem.cb) { - var workItem = this.workItem; - this.workItem = null; - workItem.cb(err); - } - - // Did we catch a timeout, increment the numberOfConsecutiveTimeouts - if(event == 'timeout') { - self.numberOfConsecutiveTimeouts = self.numberOfConsecutiveTimeouts + 1; - - // Have we timed out more than reconnectTries in a row ? - // Force close the pool as we are trying to connect to tcp sink hole - if(self.numberOfConsecutiveTimeouts > self.options.reconnectTries) { - self.numberOfConsecutiveTimeouts = 0; - // Destroy all connections and pool - self.destroy(true); - // Emit close event - return self.emit('close', self); - } - } - - // No more socket available propegate the event - if(self.socketCount() == 0) { - if(self.state != DESTROYED && self.state != DESTROYING) { - stateTransition(self, DISCONNECTED); - } - - // Do not emit error events, they are always close events - // do not trigger the low level error handler in node - event = event == 'error' ? 'close' : event; - self.emit(event, err); - } - - // Start reconnection attempts - if(!self.reconnectId && self.options.reconnect) { - self.reconnectId = setTimeout(attemptReconnect(self), self.options.reconnectInterval); - } - }; -} - -function attemptReconnect(self) { - return function() { - self.emit('attemptReconnect', self); - if(self.state == DESTROYED || self.state == DESTROYING) return; - - // We are connected do not try again - if(self.isConnected()) { - self.reconnectId = null; - return; - } - - // If we have failure schedule a retry - function _connectionFailureHandler(self, event) { - return function() { - self.retriesLeft = self.retriesLeft - 1; - // How many retries are left - if(self.retriesLeft == 0) { - // Destroy the instance - self.destroy(); - // Emit close event - self.emit('reconnectFailed' - , new MongoError(f('failed to reconnect after %s attempts with interval %s ms', self.options.reconnectTries, self.options.reconnectInterval))); - } else { - self.reconnectId = setTimeout(attemptReconnect(self), self.options.reconnectInterval); - } - } - } - - // Got a connect handler - function _connectHandler(self) { - return function() { - // Assign - var connection = this; - - // Pool destroyed stop the connection - if(self.state == DESTROYED || self.state == DESTROYING) { - return connection.destroy(); - } - - // Clear out all handlers - handlers.forEach(function(event) { - connection.removeAllListeners(event); - }); - - // Reset reconnect id - self.reconnectId = null; - - // Apply pool connection handlers - connection.on('error', connectionFailureHandler(self, 'error')); - connection.on('close', connectionFailureHandler(self, 'close')); - connection.on('timeout', connectionFailureHandler(self, 'timeout')); - connection.on('parseError', connectionFailureHandler(self, 'parseError')); - - // Apply any auth to the connection - reauthenticate(self, this, function(err) { - // Reset retries - self.retriesLeft = self.options.reconnectTries; - // Push to available connections - self.availableConnections.push(connection); - // Emit reconnect event - self.emit('reconnect', self); - // Trigger execute to start everything up again - _execute(self)(); - }); - } - } - - // Create a connection - var connection = new Connection(messageHandler(self), self.options); - // Add handlers - connection.on('close', _connectionFailureHandler(self, 'close')); - connection.on('error', _connectionFailureHandler(self, 'error')); - connection.on('timeout', _connectionFailureHandler(self, 'timeout')); - connection.on('parseError', _connectionFailureHandler(self, 'parseError')); - // On connection - connection.on('connect', _connectHandler(self)); - // Attempt connection - connection.connect(); - } -} - -function moveConnectionBetween(connection, from, to) { - var index = from.indexOf(connection); - // Move the connection from connecting to available - if(index != -1) { - from.splice(index, 1); - to.push(connection); - } -} - -function messageHandler(self) { - return function(message, connection) { - // Get the callback - var workItem = connection.workItem; - // Reset timeout counter - self.numberOfConsecutiveTimeouts = 0; - - // Reset the connection timeout if we modified it for - // this operation - if(workItem.socketTimeout) { - connection.resetSocketTimeout(); - } - - // Log if debug enabled - if(self.logger.isDebug()) { - self.logger.debug(f('message [%s] received from %s:%s' - , message.raw.toString('hex'), self.options.host, self.options.port)); - } - - // Authenticate any straggler connections - function authenticateStragglers(self, connection, callback) { - // Get any non authenticated connections - var connections = self.nonAuthenticatedConnections.slice(0); - var nonAuthenticatedConnections = self.nonAuthenticatedConnections; - self.nonAuthenticatedConnections = []; - - // Establish if the connection need to be authenticated - // Add to authentication list if - // 1. we were in an authentication process when the operation was executed - // 2. our current authentication timestamp is from the workItem one, meaning an auth has happened - if(connection.workItem.authenticating == true - || (typeof connection.workItem.authenticatingTimestamp == 'number' - && connection.workItem.authenticatingTimestamp != self.authenticatingTimestamp)) { - // Add connection to the list - connections.push(connection); - } - - // Clear out workItem - connection.workItem = null; - - // No connections need to be re-authenticated - if(connections.length == 0) { - // Release the connection back to the pool - moveConnectionBetween(connection, self.inUseConnections, self.availableConnections); - // Finish - return callback(); - } - - // Apply re-authentication to all connections before releasing back to pool - var connectionCount = connections.length; - // Authenticate all connections - for(var i = 0; i < connectionCount; i++) { - reauthenticate(self, connections[i], function(err) { - connectionCount = connectionCount - 1; - - if(connectionCount == 0) { - // Put non authenticated connections in available connections - self.availableConnections = self.availableConnections.concat(nonAuthenticatedConnections); - // Release the connection back to the pool - moveConnectionBetween(connection, self.inUseConnections, self.availableConnections); - // Return - callback(); - } - }); - } - } - - authenticateStragglers(self, connection, function(err) { - // Keep executing, ensure current message handler does not stop execution - process.nextTick(function() { - _execute(self)(); - }); - - // Time to dispatch the message if we have a callback - if(!workItem.immediateRelease) { - try { - // Parse the message according to the provided options - message.parse(workItem); - } catch(err) { - return workItem.cb(MongoError.create(err)); - } - - // Establish if we have an error - if(workItem.command && message.documents[0] && (message.documents[0].ok == 0 || message.documents[0]['$err'] - || message.documents[0]['errmsg'] || message.documents[0]['code'])) { - return workItem.cb(MongoError.create(message.documents[0])); - } - - // Return the documents - workItem.cb(null, new CommandResult(message.documents[0], connection, message)); - } - }); - } -} - -/** - * Return the total socket count in the pool. - * @method - * @return {Number} The number of socket available. - */ -Pool.prototype.socketCount = function() { - return this.availableConnections.length - + this.inUseConnections.length - + this.connectingConnections.length; -} - -/** - * Return all pool connections - * @method - * @return {Connectio[]} The pool connections - */ -Pool.prototype.allConnections = function() { - return this.availableConnections - .concat(this.inUseConnections) - .concat(this.connectingConnections); -} - -/** - * Get a pool connection (round-robin) - * @method - * @return {Connection} - */ -Pool.prototype.get = function() { - return this.allConnections()[0]; -} - -/** - * Is the pool connected - * @method - * @return {boolean} - */ -Pool.prototype.isConnected = function() { - // We are in a destroyed state - if(this.state == DESTROYED || this.state == DESTROYING) { - return false; - } - - // Get connections - var connections = this.availableConnections - .concat(this.inUseConnections) - .concat(this.connectingConnections); - for(var i = 0; i < connections.length; i++) { - if(connections[i].isConnected()) return true; - } - - // Might be authenticating, but we are still connected - if(connections.length == 0 && this.authenticating) { - return true - } - - // Not connected - return false; -} - -/** - * Was the pool destroyed - * @method - * @return {boolean} - */ -Pool.prototype.isDestroyed = function() { - return this.state == DESTROYED || this.state == DESTROYING; -} - -/** - * Is the pool in a disconnected state - * @method - * @return {boolean} - */ -Pool.prototype.isDisconnected = function() { - return this.state == DISCONNECTED; -} - -/** - * Connect pool - * @method - */ -Pool.prototype.connect = function(auth) { - if(this.state != DISCONNECTED) throw new MongoError('connection in unlawful state ' + this.state); - var self = this; - // Transition to connecting state - stateTransition(this, CONNECTING); - // Create an array of the arguments - var args = Array.prototype.slice.call(arguments, 0); - // Create a connection - var connection = new Connection(messageHandler(self), this.options); - // Add to list of connections - this.connectingConnections.push(connection); - // Add listeners to the connection - connection.once('connect', function(connection) { - if(self.state == DESTROYED || self.state == DESTROYING) return self.destroy(); - - // Apply any store credentials - reauthenticate(self, connection, function(err) { - if(self.state == DESTROYED || self.state == DESTROYING) return self.destroy(); - - // We have an error emit it - if(err) { - // Destroy the pool - self.destroy(); - // Emit the error - return self.emit('error', err); - } - - // Authenticate - authenticate(self, args, connection, function(err) { - if(self.state == DESTROYED || self.state == DESTROYING) return self.destroy(); - - // We have an error emit it - if(err) { - // Destroy the pool - self.destroy(); - // Emit the error - return self.emit('error', err); - } - // Set connected mode - stateTransition(self, CONNECTED); - - // Move the active connection - moveConnectionBetween(connection, self.connectingConnections, self.availableConnections); - - // Emit the connect event - self.emit('connect', self); - }); - }); - }); - - // Add error handlers - connection.once('error', connectionFailureHandler(this, 'error')); - connection.once('close', connectionFailureHandler(this, 'close')); - connection.once('timeout', connectionFailureHandler(this, 'timeout')); - connection.once('parseError', connectionFailureHandler(this, 'parseError')); - - try { - connection.connect(); - } catch(err) { - // SSL or something threw on connect - self.emit('error', err); - } -} - -/** - * Authenticate using a specified mechanism - * @method - * @param {string} mechanism The Auth mechanism we are invoking - * @param {string} db The db we are invoking the mechanism against - * @param {...object} param Parameters for the specific mechanism - * @param {authResultCallback} callback A callback function - */ -Pool.prototype.auth = function(mechanism, db) { - var self = this; - var args = Array.prototype.slice.call(arguments, 0); - var callback = args.pop(); - // If we are not connected don't allow additonal authentications to happen - // if(this.state != CONNECTED) throw new MongoError('connection in unlawful state ' + this.state); - - // If we don't have the mechanism fail - if(self.authProviders[mechanism] == null && mechanism != 'default') { - throw new MongoError(f("auth provider %s does not exist", mechanism)); - } - - // Signal that we are authenticating a new set of credentials - this.authenticating = true; - this.authenticatingTimestamp = new Date().getTime(); - - // Authenticate all live connections - function authenticateLiveConnections(self, args, cb) { - // Get the current viable connections - var connections = self.availableConnections; - // Allow nothing else to use the connections while we authenticate them - self.availableConnections = []; - - var connectionsCount = connections.length; - var error = null; - // No connections available, return - if(connectionsCount == 0) return callback(null); - // Authenticate the connections - for(var i = 0; i < connections.length; i++) { - authenticate(self, args, connections[i], function(err) { - connectionsCount = connectionsCount - 1; - - // Store the error - if(err) error = err; - - // Processed all connections - if(connectionsCount == 0) { - // Auth finished - self.authenticating = false; - // Add the connections back to available connections - self.availableConnections = self.availableConnections.concat(connections); - // We had an error, return it - if(error) { - // Log the error - if(self.logger.isError()) { - self.logger.error(f('[%s] failed to authenticate against server %s:%s' - , self.id, self.options.host, self.options.port)); - } - - return cb(error); - } - cb(null); - } - }); - } - } - - // Wait for a logout in process to happen - function waitForLogout(self, cb) { - if(!self.loggingout) return cb(); - setTimeout(function() { - waitForLogout(self, cb); - }, 1) - } - - // Wait for loggout to finish - waitForLogout(self, function() { - // Authenticate all live connections - authenticateLiveConnections(self, args, function(err) { - // Credentials correctly stored in auth provider if successful - // Any new connections will now reauthenticate correctly - self.authenticating = false; - // Return after authentication connections - callback(err); - }); - }); -} - -/** - * Logout all users against a database - * @method - * @param {string} dbName The database name - * @param {authResultCallback} callback A callback function - */ -Pool.prototype.logout = function(dbName, callback) { - var self = this; - if(typeof dbName != 'string') throw new MongoError('logout method requires a db name as first argument'); - if(typeof callback != 'function') throw new MongoError('logout method requires a callback'); - - // Indicate logout in process - this.loggingout = true; - - // Get all relevant connections - var connections = self.availableConnections.concat(self.inUseConnections); - var count = connections.length; - // Store any error - var error = null; - - // Send logout command over all the connections - for(var i = 0; i < connections.length; i++) { - var query = new Query(this.options.bson - , f('%s.$cmd', dbName) - , {logout:1}, {numberToSkip: 0, numberToReturn: 1}); - write(self)(connections[i], query.toBin(), function(err, r) { - count = count - 1; - if(err) error = err; - - if(count == 0) { - self.loggingout = false; - callback(error); - }; - }); - } -} - -/** - * Unref the pool - * @method - */ -Pool.prototype.unref = function() { - // Get all the known connections - var connections = this.availableConnections - .concat(this.inUseConnections) - .concat(this.connectingConnections); - connections.forEach(function(c) { - c.unref(); - }); -} - -// Events -var events = ['error', 'close', 'timeout', 'parseError', 'connect']; - -// Destroy the connections -function destroy(self, connections) { - // Destroy all connections - connections.forEach(function(c) { - // Remove all listeners - for(var i = 0; i < events.length; i++) { - c.removeAllListeners(events[i]); - } - // Destroy connection - c.destroy(); - }); - - // Zero out all connections - self.inUseConnections = []; - self.availableConnections = []; - self.nonAuthenticatedConnections = []; - self.connectingConnections = []; - - // Set state to destroyed - stateTransition(self, DESTROYED); -} - -/** - * Destroy pool - * @method - */ -Pool.prototype.destroy = function(force) { - var self = this; - // Do not try again if the pool is already dead - if(this.state == DESTROYED || self.state == DESTROYING) return; - // Set state to destroyed - stateTransition(this, DESTROYING); - - // Are we force closing - if(force) { - // Get all the known connections - var connections = self.availableConnections - .concat(self.inUseConnections) - .concat(self.nonAuthenticatedConnections) - .concat(self.connectingConnections); - return destroy(self, connections); - } - - // Wait for the operations to drain before we close the pool - function checkStatus() { - if(self.queue.length == 0) { - // Get all the known connections - var connections = self.availableConnections - .concat(self.inUseConnections) - .concat(self.nonAuthenticatedConnections) - .concat(self.connectingConnections); - - // Check if we have any in flight operations - for(var i = 0; i < connections.length; i++) { - // There is an operation still in flight, reschedule a - // check waiting for it to drain - if(connections[i].workItem) { - return setTimeout(checkStatus, 1); - } - } - - destroy(self, connections); - } else { - setTimeout(checkStatus, 1); - } - } - - // Initiate drain of operations - checkStatus(); -} - -/** - * Write a message to MongoDB - * @method - * @return {Connection} - */ -Pool.prototype.write = function(buffer, options, cb) { - // Ensure we have a callback - if(typeof options == 'function') { - cb = options; - } - - // Always have options - options = options || {}; - - // Pool was destroyed error out - if(this.state == DESTROYED || this.state == DESTROYING) { - // Callback with an error - if(cb) cb(new MongoError('pool destroyed')); - return; - } - - // Do we have an operation - var operation = { - buffer:buffer, cb: cb, raw: false, promoteLongs: true - }; - - // Set the options for the parsing - operation.promoteLongs = typeof options.promoteLongs == 'boolean' ? options.promoteLongs : true; - operation.raw = typeof options.raw == 'boolean' ? options.raw : false; - operation.immediateRelease = typeof options.immediateRelease == 'boolean' ? options.immediateRelease : false; - operation.documentsReturnedIn = options.documentsReturnedIn; - operation.command = typeof options.command == 'boolean' ? options.command : false; - // Optional per operation socketTimeout - operation.socketTimeout = options.socketTimeout; - operation.monitoring = options.monitoring; - // // debug - // operation.cmd = options.cmd; - - // We need to have a callback function unless the message returns no response - if(!(typeof cb == 'function') && !options.noResponse) { - throw new MongoError('write method must provide a callback'); - } - - // If we have a monitoring operation schedule as the very first operation - // Otherwise add to back of queue - if(options.monitoring) { - this.queue.unshift(operation); - } else { - this.queue.push(operation); - } - - // Attempt to execute the operation - _execute(this)(); -} - -// Remove connection method -function remove(connection, connections) { - for(var i = 0; i < connections.length; i++) { - if(connections[i] === connection) { - connections.splice(i, 1); - return true; - } - } -} - -function removeConnection(self, connection) { - if(remove(connection, self.availableConnections)) return; - if(remove(connection, self.inUseConnections)) return; - if(remove(connection, self.connectingConnections)) return; - if(remove(connection, self.nonAuthenticatedConnections)) return; -} - -// All event handlers -var handlers = ["close", "message", "error", "timeout", "parseError", "connect"]; - -function _createConnection(self) { - var connection = new Connection(messageHandler(self), self.options); - - // Push the connection - self.connectingConnections.push(connection); - - // Handle any errors - var tempErrorHandler = function(_connection) { - return function(err) { - // Destroy the connection - _connection.destroy(); - // Remove the connection from the connectingConnections list - removeConnection(self, _connection); - // Start reconnection attempts - if(!self.reconnectId && self.options.reconnect) { - self.reconnectId = setTimeout(attemptReconnect(self), self.options.reconnectInterval); - } - } - } - - // Handle successful connection - var tempConnectHandler = function(_connection) { - return function() { - // Destroyed state return - if(self.state == DESTROYED || self.state == DESTROYING) { - // Remove the connection from the list - removeConnection(self, _connection); - return _connection.destroy(); - } - - // Destroy all event emitters - handlers.forEach(function(e) { - _connection.removeAllListeners(e); - }); - - // Add the final handlers - _connection.once('close', connectionFailureHandler(self, 'close')); - _connection.once('error', connectionFailureHandler(self, 'error')); - _connection.once('timeout', connectionFailureHandler(self, 'timeout')); - _connection.once('parseError', connectionFailureHandler(self, 'parseError')); - - // Signal - reauthenticate(self, _connection, function(err) { - if(self.state == DESTROYED || self.state == DESTROYING) { - return _connection.destroy(); - } - // Remove the connection from the connectingConnections list - removeConnection(self, _connection); - - // Handle error - if(err) { - return _connection.destroy(); - } - - // If we are authenticating at the moment - // Do not automatially put in available connections - // As we need to apply the credentials first - if(self.authenticating) { - self.nonAuthenticatedConnections.push(_connection); - } else { - // Push to available - self.availableConnections.push(_connection); - // Execute any work waiting - _execute(self)(); - } - }); - } - } - - // Add all handlers - connection.once('close', tempErrorHandler(connection)); - connection.once('error', tempErrorHandler(connection)); - connection.once('timeout', tempErrorHandler(connection)); - connection.once('parseError', tempErrorHandler(connection)); - connection.once('connect', tempConnectHandler(connection)); - - // Start connection - connection.connect(); -} - -function flushMonitoringOperations(queue) { - for(var i = 0; i < queue.length; i++) { - if(queue[i].monitoring) { - var workItem = queue[i]; - queue.splice(i, 1); - workItem.cb(new MongoError('no connection available for monitoring')); - } - } -} - -function _execute(self) { - return function() { - if(self.state == DESTROYED) return; - // Already executing, skip - if(self.executing) return; - // Set pool as executing - self.executing = true; - - // Wait for auth to clear before continuing - function waitForAuth(cb) { - if(!self.authenticating) return cb(); - // Wait for a milisecond and try again - setTimeout(function() { - waitForAuth(cb); - }, 1); - } - - // Block on any auth in process - waitForAuth(function() { - // As long as we have available connections - while(true) { - // Total availble connections - var totalConnections = self.availableConnections.length - + self.connectingConnections.length - + self.inUseConnections.length; - - // Have we not reached the max connection size yet - if(self.availableConnections.length == 0 - && self.connectingConnections.length == 0 - && totalConnections < self.options.size - && self.queue.length > 0) { - // // Flush any monitoring operations - // flushMonitoringOperations(self.queue); - // Create a new connection - _createConnection(self); - // Attempt to execute again - self.executing = false; - return; - } - - // No available connections available, flush any monitoring ops - if(self.availableConnections.length == 0) { - // Flush any monitoring operations - flushMonitoringOperations(self.queue); - break; - } - - // No queue break - if(self.queue.length == 0) { - break; - } - - // Get a connection - var connection = self.availableConnections.pop(); - if(connection.isConnected()) { - // Get the next work item - var workItem = self.queue.shift(); - - // Get actual binary commands - var buffer = workItem.buffer; - - // Add connection to workers in flight - self.inUseConnections.push(connection); - - // Set current status of authentication process - workItem.authenticating = self.authenticating; - workItem.authenticatingTimestamp = self.authenticatingTimestamp; - - // Add current associated callback to the connection - connection.workItem = workItem - - // We have a custom socketTimeout - if(!workItem.immediateRelease && typeof workItem.socketTimeout == 'number') { - connection.setSocketTimeout(workItem.socketTimeout); - } - - // Put operation on the wire - if(Array.isArray(buffer)) { - for(var i = 0; i < buffer.length; i++) { - connection.write(buffer[i]) - } - } else { - connection.write(buffer); - } - - // Fire and forgot message, release the socket - if(workItem.immediateRelease && !self.authenticating) { - self.inUseConnections.pop(); - self.availableConnections.push(connection); - } else if(workItem.immediateRelease && self.authenticating) { - self.inUseConnections.pop(); - self.nonAuthenticatedConnections.push(connection); - } - } else { - flushMonitoringOperations(self.queue); - } - } - }); - - self.executing = false; - } -} - -/** - * A server connect event, used to verify that the connection is up and running - * - * @event Pool#connect - * @type {Pool} - */ - -/** - * A server reconnect event, used to verify that pool reconnected. - * - * @event Pool#reconnect - * @type {Pool} - */ - -/** - * The server connection closed, all pool connections closed - * - * @event Pool#close - * @type {Pool} - */ - -/** - * The server connection caused an error, all pool connections closed - * - * @event Pool#error - * @type {Pool} - */ - -/** - * The server connection timed out, all pool connections closed - * - * @event Pool#timeout - * @type {Pool} - */ - -/** - * The driver experienced an invalid message, all pool connections closed - * - * @event Pool#parseError - * @type {Pool} - */ - -/** - * The driver attempted to reconnect - * - * @event Pool#attemptReconnect - * @type {Pool} - */ - -/** - * The driver exhausted all reconnect attempts - * - * @event Pool#reconnectFailed - * @type {Pool} - */ - -module.exports = Pool; diff --git a/node_modules/mongodb-core/lib/connection/utils.js b/node_modules/mongodb-core/lib/connection/utils.js deleted file mode 100644 index 019ef19..0000000 --- a/node_modules/mongodb-core/lib/connection/utils.js +++ /dev/null @@ -1,67 +0,0 @@ -"use strict"; - -// Set property function -var setProperty = function(obj, prop, flag, values) { - Object.defineProperty(obj, prop.name, { - enumerable:true, - set: function(value) { - if(typeof value != 'boolean') throw new Error(f("%s required a boolean", prop.name)); - // Flip the bit to 1 - if(value == true) values.flags |= flag; - // Flip the bit to 0 if it's set, otherwise ignore - if(value == false && (values.flags & flag) == flag) values.flags ^= flag; - prop.value = value; - } - , get: function() { return prop.value; } - }); -} - -// Set property function -var getProperty = function(obj, propName, fieldName, values, func) { - Object.defineProperty(obj, propName, { - enumerable:true, - get: function() { - // Not parsed yet, parse it - if(values[fieldName] == null && obj.isParsed && !obj.isParsed()) { - obj.parse(); - } - - // Do we have a post processing function - if(typeof func == 'function') return func(values[fieldName]); - // Return raw value - return values[fieldName]; - } - }); -} - -// Set simple property -var getSingleProperty = function(obj, name, value) { - Object.defineProperty(obj, name, { - enumerable:true, - get: function() { - return value - } - }); -} - -// Shallow copy -var copy = function(fObj, tObj) { - tObj = tObj || {}; - for(var name in fObj) tObj[name] = fObj[name]; - return tObj; -} - -var debugOptions = function(debugFields, options) { - var finaloptions = {}; - debugFields.forEach(function(n) { - finaloptions[n] = options[n]; - }); - - return finaloptions; -} - -exports.setProperty = setProperty; -exports.getProperty = getProperty; -exports.getSingleProperty = getSingleProperty; -exports.copy = copy; -exports.debugOptions = debugOptions; diff --git a/node_modules/mongodb-core/lib/cursor.js b/node_modules/mongodb-core/lib/cursor.js deleted file mode 100644 index 0ba6d80..0000000 --- a/node_modules/mongodb-core/lib/cursor.js +++ /dev/null @@ -1,677 +0,0 @@ -"use strict"; - -var Long = require('bson').Long - , Logger = require('./connection/logger') - , MongoError = require('./error') - , f = require('util').format; - -/** - * This is a cursor results callback - * - * @callback resultCallback - * @param {error} error An error object. Set to null if no error present - * @param {object} document - */ - -/** - * @fileOverview The **Cursor** class is an internal class that embodies a cursor on MongoDB - * allowing for iteration over the results returned from the underlying query. - * - * **CURSORS Cannot directly be instantiated** - * @example - * var Server = require('mongodb-core').Server - * , ReadPreference = require('mongodb-core').ReadPreference - * , assert = require('assert'); - * - * var server = new Server({host: 'localhost', port: 27017}); - * // Wait for the connection event - * server.on('connect', function(server) { - * assert.equal(null, err); - * - * // Execute the write - * var cursor = _server.cursor('integration_tests.inserts_example4', { - * find: 'integration_tests.example4' - * , query: {a:1} - * }, { - * readPreference: new ReadPreference('secondary'); - * }); - * - * // Get the first document - * cursor.next(function(err, doc) { - * assert.equal(null, err); - * server.destroy(); - * }); - * }); - * - * // Start connecting - * server.connect(); - */ - -/** - * Creates a new Cursor, not to be used directly - * @class - * @param {object} bson An instance of the BSON parser - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {{object}|Long} cmd The selector (can be a command or a cursorId) - * @param {object} [options=null] Optional settings. - * @param {object} [options.batchSize=1000] Batchsize for the operation - * @param {array} [options.documents=[]] Initial documents list for cursor - * @param {object} [options.transforms=null] Transform methods for the cursor results - * @param {function} [options.transforms.query] Transform the value returned from the initial query - * @param {function} [options.transforms.doc] Transform each document returned from Cursor.prototype.next - * @param {object} topology The server topology instance. - * @param {object} topologyOptions The server topology options. - * @return {Cursor} A cursor instance - * @property {number} cursorBatchSize The current cursorBatchSize for the cursor - * @property {number} cursorLimit The current cursorLimit for the cursor - * @property {number} cursorSkip The current cursorSkip for the cursor - */ -var Cursor = function(bson, ns, cmd, options, topology, topologyOptions) { - options = options || {}; - // Cursor reference - var self = this; - // Initial query - var query = null; - - // Cursor pool - this.pool = null; - // Cursor server - this.server = null; - - // Do we have a not connected handler - this.disconnectHandler = options.disconnectHandler; - - // Set local values - this.bson = bson; - this.ns = ns; - this.cmd = cmd; - this.options = options; - this.topology = topology; - - // All internal state - this.cursorState = { - cursorId: null - , cmd: cmd - , documents: options.documents || [] - , cursorIndex: 0 - , dead: false - , killed: false - , init: false - , notified: false - , limit: options.limit || cmd.limit || 0 - , skip: options.skip || cmd.skip || 0 - , batchSize: options.batchSize || cmd.batchSize || 1000 - , currentLimit: 0 - // Result field name if not a cursor (contains the array of results) - , transforms: options.transforms - } - - // Add promoteLong to cursor state - if(typeof topologyOptions.promoteLongs == 'boolean') { - this.cursorState.promoteLongs = topologyOptions.promoteLongs; - } - - // Logger - this.logger = Logger('Cursor', topologyOptions); - - // - // Did we pass in a cursor id - if(typeof cmd == 'number') { - this.cursorState.cursorId = Long.fromNumber(cmd); - this.cursorState.lastCursorId = this.cursorState.cursorId; - } else if(cmd instanceof Long) { - this.cursorState.cursorId = cmd; - this.cursorState.lastCursorId = cmd; - } -} - -Cursor.prototype.setCursorBatchSize = function(value) { - this.cursorState.batchSize = value; -} - -Cursor.prototype.cursorBatchSize = function() { - return this.cursorState.batchSize; -} - -Cursor.prototype.setCursorLimit = function(value) { - this.cursorState.limit = value; -} - -Cursor.prototype.cursorLimit = function() { - return this.cursorState.limit; -} - -Cursor.prototype.setCursorSkip = function(value) { - this.cursorState.skip = value; -} - -Cursor.prototype.cursorSkip = function() { - return this.cursorState.skip; -} - -// -// Handle callback (including any exceptions thrown) -var handleCallback = function(callback, err, result) { - try { - callback(err, result); - } catch(err) { - process.nextTick(function() { - throw err; - }); - } -} - -// Internal methods -Cursor.prototype._find = function(callback) { - var self = this; - - if(self.logger.isDebug()) { - self.logger.debug(f("issue initial query [%s] with flags [%s]" - , JSON.stringify(self.cmd) - , JSON.stringify(self.query))); - } - - var queryCallback = function(err, r) { - if(err) return callback(err); - - // Get the raw message - var result = r.message; - - // Query failure bit set - if(result.queryFailure) { - return callback(MongoError.create(result.documents[0]), null); - } - - // Check if we have a command cursor - if(Array.isArray(result.documents) && result.documents.length == 1 - && (!self.cmd.find || (self.cmd.find && self.cmd.virtual == false)) - && (result.documents[0].cursor != 'string' - || result.documents[0]['$err'] - || result.documents[0]['errmsg'] - || Array.isArray(result.documents[0].result)) - ) { - - // We have a an error document return the error - if(result.documents[0]['$err'] - || result.documents[0]['errmsg']) { - return callback(MongoError.create(result.documents[0]), null); - } - - // We have a cursor document - if(result.documents[0].cursor != null - && typeof result.documents[0].cursor != 'string') { - var id = result.documents[0].cursor.id; - // If we have a namespace change set the new namespace for getmores - if(result.documents[0].cursor.ns) { - self.ns = result.documents[0].cursor.ns; - } - // Promote id to long if needed - self.cursorState.cursorId = typeof id == 'number' ? Long.fromNumber(id) : id; - self.cursorState.lastCursorId = self.cursorState.cursorId; - // If we have a firstBatch set it - if(Array.isArray(result.documents[0].cursor.firstBatch)) { - self.cursorState.documents = result.documents[0].cursor.firstBatch;//.reverse(); - } - - // Return after processing command cursor - return callback(null, null); - } - - if(Array.isArray(result.documents[0].result)) { - self.cursorState.documents = result.documents[0].result; - self.cursorState.cursorId = Long.ZERO; - return callback(null, null); - } - } - - // Otherwise fall back to regular find path - self.cursorState.cursorId = result.cursorId; - self.cursorState.documents = result.documents; - self.cursorState.lastCursorId = result.cursorId; - - // Transform the results with passed in transformation method if provided - if(self.cursorState.transforms && typeof self.cursorState.transforms.query == 'function') { - self.cursorState.documents = self.cursorState.transforms.query(result); - } - - // Return callback - callback(null, null); - } - - // Options passed to the pool - var queryOptions = {}; - - // If we have a raw query decorate the function - if(self.options.raw || self.cmd.raw) { - // queryCallback.raw = self.options.raw || self.cmd.raw; - queryOptions.raw = self.options.raw || self.cmd.raw; - } - - // Do we have documentsReturnedIn set on the query - if(typeof self.query.documentsReturnedIn == 'string') { - // queryCallback.documentsReturnedIn = self.query.documentsReturnedIn; - queryOptions.documentsReturnedIn = self.query.documentsReturnedIn; - } - - // Add promote Long value if defined - if(typeof self.cursorState.promoteLongs == 'boolean') { - // queryCallback.promoteLongs = self.cursorState.promoteLongs; - queryOptions.promoteLongs = self.cursorState.promoteLongs; - } - - // Write the initial command out - self.server.s.pool.write(self.query.toBin(), queryOptions, queryCallback); -} - -Cursor.prototype._getmore = function(callback) { - if(this.logger.isDebug()) this.logger.debug(f("schedule getMore call for query [%s]", JSON.stringify(this.query))) - // Determine if it's a raw query - var raw = this.options.raw || this.cmd.raw; - - // Set the current batchSize - var batchSize = this.cursorState.batchSize; - if(this.cursorState.limit > 0 - && ((this.cursorState.currentLimit + batchSize) > this.cursorState.limit)) { - batchSize = this.cursorState.limit - this.cursorState.currentLimit; - } - - // Default pool - var pool = this.server.s.pool; - - // We have a wire protocol handler - this.server.wireProtocolHandler.getMore(this.bson, this.ns, this.cursorState, batchSize, raw, pool, this.options, callback); -} - -Cursor.prototype._killcursor = function(callback) { - // Set cursor to dead - this.cursorState.dead = true; - this.cursorState.killed = true; - // Remove documents - this.cursorState.documents = []; - - // If no cursor id just return - if(this.cursorState.cursorId == null || this.cursorState.cursorId.isZero() || this.cursorState.init == false) { - if(callback) callback(null, null); - return; - } - - // // Default pool - // var pool = this.pool; - // // If we have a connection get the corresponding pool - // if(this.connection && this.connection.isConnected()) { - // // Get the server - // var server = this.topology.getServerFrom(this.connection); - // // Get the pool - // if(server && server.s.pool) { - // pool = server.s.pool; - // } - // } - - // Default pool - var pool = this.server.s.pool; - // // Set cursorId to ZERO - // this.cursorState.cursorId = Long.fromNumber(0); - // Execute command - this.server.wireProtocolHandler.killCursor(this.bson, this.ns, this.cursorState.cursorId, pool, callback); -} - -/** - * Clone the cursor - * @method - * @return {Cursor} - */ -Cursor.prototype.clone = function() { - return this.topology.cursor(this.ns, this.cmd, this.options); -} - -/** - * Checks if the cursor is dead - * @method - * @return {boolean} A boolean signifying if the cursor is dead or not - */ -Cursor.prototype.isDead = function() { - return this.cursorState.dead == true; -} - -/** - * Checks if the cursor was killed by the application - * @method - * @return {boolean} A boolean signifying if the cursor was killed by the application - */ -Cursor.prototype.isKilled = function() { - return this.cursorState.killed == true; -} - -/** - * Checks if the cursor notified it's caller about it's death - * @method - * @return {boolean} A boolean signifying if the cursor notified the callback - */ -Cursor.prototype.isNotified = function() { - return this.cursorState.notified == true; -} - -/** - * Returns current buffered documents length - * @method - * @return {number} The number of items in the buffered documents - */ -Cursor.prototype.bufferedCount = function() { - return this.cursorState.documents.length - this.cursorState.cursorIndex; -} - -/** - * Returns current buffered documents - * @method - * @return {Array} An array of buffered documents - */ -Cursor.prototype.readBufferedDocuments = function(number) { - var unreadDocumentsLength = this.cursorState.documents.length - this.cursorState.cursorIndex; - var length = number < unreadDocumentsLength ? number : unreadDocumentsLength; - var elements = this.cursorState.documents.slice(this.cursorState.cursorIndex, this.cursorState.cursorIndex + length); - - // Transform the doc with passed in transformation method if provided - if(this.cursorState.transforms && typeof this.cursorState.transforms.doc == 'function') { - // Transform all the elements - for(var i = 0; i < elements.length; i++) { - elements[i] = this.cursorState.transforms.doc(elements[i]); - } - } - - // Ensure we do not return any more documents than the limit imposed - // Just return the number of elements up to the limit - if(this.cursorState.limit > 0 && (this.cursorState.currentLimit + elements.length) > this.cursorState.limit) { - elements = elements.slice(0, (this.cursorState.limit - this.cursorState.currentLimit)); - this.kill(); - } - - // Adjust current limit - this.cursorState.currentLimit = this.cursorState.currentLimit + elements.length; - this.cursorState.cursorIndex = this.cursorState.cursorIndex + elements.length; - - // Return elements - return elements; -} - -/** - * Kill the cursor - * @method - * @param {resultCallback} callback A callback function - */ -Cursor.prototype.kill = function(callback) { - this._killcursor(callback); -} - -/** - * Resets the cursor - * @method - * @return {null} - */ -Cursor.prototype.rewind = function() { - if(this.cursorState.init) { - if(!this.cursorState.dead) { - this.kill(); - } - - this.cursorState.currentLimit = 0; - this.cursorState.init = false; - this.cursorState.dead = false; - this.cursorState.killed = false; - this.cursorState.notified = false; - this.cursorState.documents = []; - this.cursorState.cursorId = null; - this.cursorState.cursorIndex = 0; - } -} - -/** - * Validate if the pool is dead and return error - */ -var isConnectionDead = function(self, callback) { - if(self.pool - && self.pool.isDestroyed()) { - self.cursorState.notified = true; - self.cursorState.killed = true; - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - callback(MongoError.create(f('connection to host %s:%s was destroyed', self.pool.host, self.pool.port))) - return true; - } - - return false; -} - -/** - * Validate if the cursor is dead but was not explicitly killed by user - */ -var isCursorDeadButNotkilled = function(self, callback) { - // Cursor is dead but not marked killed, return null - if(self.cursorState.dead && !self.cursorState.killed) { - self.cursorState.notified = true; - self.cursorState.killed = true; - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - handleCallback(callback, null, null); - return true; - } - - return false; -} - -/** - * Validate if the cursor is dead and was killed by user - */ -var isCursorDeadAndKilled = function(self, callback) { - if(self.cursorState.dead && self.cursorState.killed) { - handleCallback(callback, MongoError.create("cursor is dead")); - return true; - } - - return false; -} - -/** - * Validate if the cursor was killed by the user - */ -var isCursorKilled = function(self, callback) { - if(self.cursorState.killed) { - self.cursorState.notified = true; - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - handleCallback(callback, null, null); - return true; - } - - return false; -} - -/** - * Mark cursor as being dead and notified - */ -var setCursorDeadAndNotified = function(self, callback) { - self.cursorState.dead = true; - self.cursorState.notified = true; - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - handleCallback(callback, null, null); -} - -/** - * Mark cursor as being notified - */ -var setCursorNotified = function(self, callback) { - self.cursorState.notified = true; - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - handleCallback(callback, null, null); -} - -var push = Array.prototype.push; - -var nextFunction = function(self, callback) { - // We have notified about it - if(self.cursorState.notified) { - return callback(new Error('cursor is exhausted')); - } - - // Cursor is killed return null - if(isCursorKilled(self, callback)) return; - - // Cursor is dead but not marked killed, return null - if(isCursorDeadButNotkilled(self, callback)) return; - - // We have a dead and killed cursor, attempting to call next should error - if(isCursorDeadAndKilled(self, callback)) return; - - // We have just started the cursor - if(!self.cursorState.init) { - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if(!self.topology.isConnected(self.options) && self.disconnectHandler != null) { - return self.disconnectHandler.addObjectAndMethod('cursor', self, 'next', [callback], callback); - } - - try { - self.server = self.topology.getServer(self.options); - } catch(err) { - // Handle the error and add object to next method call - if(self.disconnectHandler != null) { - return self.disconnectHandler.addObjectAndMethod('cursor', self, 'next', [callback], callback); - } - - // Otherwise return the error - return callback(err); - } - - // Set as init - self.cursorState.init = true; - - try { - self.query = self.server.wireProtocolHandler.command(self.bson, self.ns, self.cmd, self.cursorState, self.topology, self.options); - } catch(err) { - return callback(err); - } - } - - // If we don't have a cursorId execute the first query - if(self.cursorState.cursorId == null) { - // Check if pool is dead and return if not possible to - // execute the query against the db - if(isConnectionDead(self, callback)) return; - - // Check if topology is destroyed - if(self.topology.isDestroyed()) return callback(new MongoError(f('connection destroyed, not possible to instantiate cursor'))); - - // query, cmd, options, cursorState, callback - self._find(function(err, r) { - if(err) return handleCallback(callback, err, null); - - if(self.cursorState.documents.length == 0 - && self.cursorState.cursorId && self.cursorState.cursorId.isZero() - && !self.cmd.tailable && !self.cmd.awaitData) { - return setCursorNotified(self, callback); - } - - nextFunction(self, callback); - }); - } else if(self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) { - // Ensure we kill the cursor on the server - self.kill(); - // Set cursor in dead and notified state - return setCursorDeadAndNotified(self, callback); - } else if(self.cursorState.cursorIndex == self.cursorState.documents.length - && !Long.ZERO.equals(self.cursorState.cursorId)) { - // Ensure an empty cursor state - self.cursorState.documents = []; - self.cursorState.cursorIndex = 0; - - // Check if topology is destroyed - if(self.topology.isDestroyed()) return callback(new MongoError(f('connection destroyed, not possible to instantiate cursor'))); - - // Check if connection is dead and return if not possible to - // execute a getmore on this connection - if(isConnectionDead(self, callback)) return; - - // Execute the next get more - self._getmore(function(err, doc, connection) { - if(err) return handleCallback(callback, err); - - // Save the returned connection to ensure all getMore's fire over the same connection - self.connection = connection; - - // Tailable cursor getMore result, notify owner about it - // No attempt is made here to retry, this is left to the user of the - // core module to handle to keep core simple - if(self.cursorState.documents.length == 0 - && self.cmd.tailable && Long.ZERO.equals(self.cursorState.cursorId)) { - // No more documents in the tailed cursor - return handleCallback(callback, MongoError.create({ - message: "No more documents in tailed cursor" - , tailable: self.cmd.tailable - , awaitData: self.cmd.awaitData - })); - } else if(self.cursorState.documents.length == 0 - && self.cmd.tailable && !Long.ZERO.equals(self.cursorState.cursorId)) { - return nextFunction(self, callback); - } - - if(self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) { - return setCursorDeadAndNotified(self, callback); - } - - nextFunction(self, callback); - }); - } else if(self.cursorState.documents.length == self.cursorState.cursorIndex - && self.cmd.tailable && Long.ZERO.equals(self.cursorState.cursorId)) { - return handleCallback(callback, MongoError.create({ - message: "No more documents in tailed cursor" - , tailable: self.cmd.tailable - , awaitData: self.cmd.awaitData - })); - } else if(self.cursorState.documents.length == self.cursorState.cursorIndex - && Long.ZERO.equals(self.cursorState.cursorId)) { - setCursorDeadAndNotified(self, callback); - } else { - if(self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) { - // Ensure we kill the cursor on the server - self.kill(); - // Set cursor in dead and notified state - return setCursorDeadAndNotified(self, callback); - } - - // Increment the current cursor limit - self.cursorState.currentLimit += 1; - - // Get the document - var doc = self.cursorState.documents[self.cursorState.cursorIndex++]; - - // Doc overflow - if(doc.$err) { - // Ensure we kill the cursor on the server - self.kill(); - // Set cursor in dead and notified state - return setCursorDeadAndNotified(self, function() { - handleCallback(callback, new MongoError(doc.$err)); - }); - } - - // Transform the doc with passed in transformation method if provided - if(self.cursorState.transforms && typeof self.cursorState.transforms.doc == 'function') { - doc = self.cursorState.transforms.doc(doc); - } - - // Return the document - handleCallback(callback, null, doc); - } -} - -/** - * Retrieve the next document from the cursor - * @method - * @param {resultCallback} callback A callback function - */ -Cursor.prototype.next = function(callback) { - nextFunction(this, callback); -} - -module.exports = Cursor; diff --git a/node_modules/mongodb-core/lib/error.js b/node_modules/mongodb-core/lib/error.js deleted file mode 100644 index 31ede94..0000000 --- a/node_modules/mongodb-core/lib/error.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; - -/** - * Creates a new MongoError - * @class - * @augments Error - * @param {string} message The error message - * @return {MongoError} A MongoError instance - */ -function MongoError(message) { - this.name = 'MongoError'; - this.message = message; - Error.captureStackTrace(this, MongoError); -} - -/** - * Creates a new MongoError object - * @method - * @param {object} options The error options - * @return {MongoError} A MongoError instance - */ -MongoError.create = function(options) { - var err = null; - - if(options instanceof Error) { - err = new MongoError(options.message); - err.stack = options.stack; - } else if(typeof options == 'string') { - err = new MongoError(options); - } else { - err = new MongoError(options.message || options.errmsg || options.$err || "n/a"); - // Other options - for(var name in options) { - err[name] = options[name]; - } - } - - return err; -} - -// Extend JavaScript error -MongoError.prototype = new Error; - -module.exports = MongoError; diff --git a/node_modules/mongodb-core/lib/tools/smoke_plugin.js b/node_modules/mongodb-core/lib/tools/smoke_plugin.js deleted file mode 100644 index dcceda4..0000000 --- a/node_modules/mongodb-core/lib/tools/smoke_plugin.js +++ /dev/null @@ -1,59 +0,0 @@ -var fs = require('fs'); - -/* Note: because this plugin uses process.on('uncaughtException'), only one - * of these can exist at any given time. This plugin and anything else that - * uses process.on('uncaughtException') will conflict. */ -exports.attachToRunner = function(runner, outputFile) { - var smokeOutput = { results : [] }; - var runningTests = {}; - - var integraPlugin = { - beforeTest: function(test, callback) { - test.startTime = Date.now(); - runningTests[test.name] = test; - callback(); - }, - afterTest: function(test, callback) { - smokeOutput.results.push({ - status: test.status, - start: test.startTime, - end: Date.now(), - test_file: test.name, - exit_code: 0, - url: "" - }); - delete runningTests[test.name]; - callback(); - }, - beforeExit: function(obj, callback) { - fs.writeFile(outputFile, JSON.stringify(smokeOutput), function() { - callback(); - }); - } - }; - - // In case of exception, make sure we write file - process.on('uncaughtException', function(err) { - // Mark all currently running tests as failed - for (var testName in runningTests) { - smokeOutput.results.push({ - status: "fail", - start: runningTests[testName].startTime, - end: Date.now(), - test_file: testName, - exit_code: 0, - url: "" - }); - } - - // write file - fs.writeFileSync(outputFile, JSON.stringify(smokeOutput)); - - // Standard NodeJS uncaught exception handler - console.error(err.stack); - process.exit(1); - }); - - runner.plugin(integraPlugin); - return integraPlugin; -}; diff --git a/node_modules/mongodb-core/lib/topologies/mongos.js b/node_modules/mongodb-core/lib/topologies/mongos.js deleted file mode 100644 index 98987f2..0000000 --- a/node_modules/mongodb-core/lib/topologies/mongos.js +++ /dev/null @@ -1,1079 +0,0 @@ -"use strict" - -var inherits = require('util').inherits, - f = require('util').format, - EventEmitter = require('events').EventEmitter, - BSON = require('bson').native().BSON, - ReadPreference = require('./read_preference'), - BasicCursor = require('../cursor'), - Logger = require('../connection/logger'), - debugOptions = require('../connection/utils').debugOptions, - MongoError = require('../error'), - Server = require('./server'), - ReplSetState = require('./replset_state'), - assign = require('./shared').assign; - -/** - * @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is - * used to construct connections. - * - * @example - * var Mongos = require('mongodb-core').Mongos - * , ReadPreference = require('mongodb-core').ReadPreference - * , assert = require('assert'); - * - * var server = new Mongos([{host: 'localhost', port: 30000}]); - * // Wait for the connection event - * server.on('connect', function(server) { - * server.destroy(); - * }); - * - * // Start connecting - * server.connect(); - */ - -var MongoCR = require('../auth/mongocr') - , X509 = require('../auth/x509') - , Plain = require('../auth/plain') - , GSSAPI = require('../auth/gssapi') - , SSPI = require('../auth/sspi') - , ScramSHA1 = require('../auth/scram'); - -// -// States -var DISCONNECTED = 'disconnected'; -var CONNECTING = 'connecting'; -var CONNECTED = 'connected'; -var DESTROYED = 'destroyed'; - -function stateTransition(self, newState) { - var legalTransitions = { - 'disconnected': [CONNECTING, DESTROYED, DISCONNECTED], - 'connecting': [CONNECTING, DESTROYED, CONNECTED, DISCONNECTED], - 'connected': [CONNECTED, DISCONNECTED, DESTROYED], - 'destroyed': [DESTROYED] - } - - // Get current state - var legalStates = legalTransitions[self.state]; - if(legalStates && legalStates.indexOf(newState) != -1) { - self.state = newState; - } else { - self.logger.error(f('Pool with id [%s] failed attempted illegal state transition from [%s] to [%s] only following state allowed [%s]' - , self.id, self.state, newState, legalStates)); - } -} - -// -// ReplSet instance id -var id = 1; -var handlers = ['connect', 'close', 'error', 'timeout', 'parseError']; - -/** - * Creates a new Mongos instance - * @class - * @param {array} seedlist A list of seeds for the replicaset - * @param {number} [options.haInterval=5000] The High availability period for replicaset inquiry - * @param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors - * @param {number} [options.size=5] Server connection pool size - * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled - * @param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled - * @param {number} [options.localThresholdMS=15] Cutoff latency point in MS for MongoS proxy selection - * @param {boolean} [options.noDelay=true] TCP Connection no delay - * @param {number} [options.connectionTimeout=1000] TCP Connection timeout setting - * @param {number} [options.socketTimeout=0] TCP Socket timeout setting - * @param {boolean} [options.singleBufferSerializtion=true] Serialize into single buffer, trade of peak memory for serialization speed - * @param {boolean} [options.ssl=false] Use SSL for connection - * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. - * @param {Buffer} [options.ca] SSL Certificate store binary buffer - * @param {Buffer} [options.cert] SSL Certificate binary buffer - * @param {Buffer} [options.key] SSL Key file binary buffer - * @param {string} [options.passphrase] SSL Certificate pass phrase - * @param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates - * @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits - * @return {Mongos} A cursor instance - * @fires Mongos#connect - * @fires Mongos#reconnect - * @fires Mongos#joined - * @fires Mongos#left - * @fires Mongos#failed - * @fires Mongos#fullsetup - * @fires Mongos#all - * @fires Mongos#serverHeartbeatStarted - * @fires Mongos#serverHeartbeatSucceeded - * @fires Mongos#serverHeartbeatFailed - * @fires Mongos#topologyOpening - * @fires Mongos#topologyClosed - * @fires Mongos#topologyDescriptionChanged - */ -var Mongos = function(seedlist, options) { - var self = this; - options = options || {}; - - // Get replSet Id - this.id = id++; - - // Internal state - this.s = { - options: assign({}, options), - // BSON instance - bson: options.bson || new BSON(), - // Factory overrides - Cursor: options.cursorFactory || BasicCursor, - // Logger instance - logger: Logger('Mongos', options), - // Seedlist - seedlist: seedlist, - // Ha interval - haInterval: options.haInterval ? options.haInterval : 10000, - // Disconnect handler - disconnectHandler: options.disconnectHandler, - // Server selection index - index: 0, - // Connect function options passed in - connectOptions: {}, - // Are we running in debug mode - debug: typeof options.debug == 'boolean' ? options.debug : false, - // localThresholdMS - localThresholdMS: options.localThresholdMS || 15, - } - - // Log info warning if the socketTimeout < haInterval as it will cause - // a lot of recycled connections to happen. - if(this.s.logger.isWarn() - && this.s.options.socketTimeout != 0 - && this.s.options.socketTimeout < this.s.haInterval) { - this.s.logger.warn(f('warning socketTimeout %s is less than haInterval %s. This might cause unnecessary server reconnections due to socket timeouts' - , this.s.options.socketTimeout, this.s.haInterval)); - } - - // All the authProviders - this.authProviders = options.authProviders || { - 'mongocr': new MongoCR(this.s.bson), 'x509': new X509(this.s.bson) - , 'plain': new Plain(this.s.bson), 'gssapi': new GSSAPI(this.s.bson) - , 'sspi': new SSPI(this.s.bson), 'scram-sha-1': new ScramSHA1(this.s.bson) - } - - // Disconnected state - this.state = DISCONNECTED; - - // Current proxies we are connecting to - this.connectingProxies = []; - // Currently connected proxies - this.connectedProxies = []; - // Disconnected proxies - this.disconnectedProxies = []; - // Are we authenticating - this.authenticating = false; - // Index of proxy to run operations against - this.index = 0; - // High availability timeout id - this.haTimeoutId = null; - // Last ismaster - this.ismaster = null; - // Lower bound latency - this.lowerBoundLatency = Number.MAX_VALUE; - - // Add event listener - EventEmitter.call(this); -} - -inherits(Mongos, EventEmitter); - -Object.defineProperty(Mongos.prototype, 'type', { - enumerable:true, get: function() { return 'mongos'; } -}); - -/** - * Emit event if it exists - * @method - */ -function emitSDAMEvent(self, event, description) { - if(self.listeners(event).length > 0) { - self.emit(event, description); - } -} - -/** - * Initiate server connect - * @method - * @param {array} [options.auth=null] Array of auth options to apply on connect - */ -Mongos.prototype.connect = function(options) { - var self = this; - // Add any connect level options to the internal state - this.s.connectOptions = options || {}; - // Set connecting state - stateTransition(this, CONNECTING); - // Create server instances - var servers = this.s.seedlist.map(function(x) { - return new Server(assign({}, self.s.options, x, { - authProviders: self.authProviders, reconnect:false, monitoring:false, inTopology: true - })); - }); - - // Emit the topology opening event - emitSDAMEvent(this, 'topologyOpening', { topologyId: this.id }); - - // Start all server connections - connectProxies(self, servers); -} - -function handleEvent(self, event) { - return function(err) { - if(self.state == DESTROYED) return; - // Move to list of disconnectedProxies - moveServerFrom(self.connectedProxies, self.disconnectedProxies, this); - // Emit the left signal - self.emit('left', 'mongos', this); - } -} - -function handleInitialConnectEvent(self, event) { - return function(err) { - // Destroy the instance - if(self.state == DESTROYED) { - return this.destroy(); - } - - // Check the type of server - if(event == 'connect') { - // Get last known ismaster - self.ismaster = this.lastIsMaster(); - - // Is this not a proxy, remove t - if(self.ismaster.msg == 'isdbgrid') { - // Add to the connectd list - for(var i = 0; i < self.connectedProxies.length; i++) { - if(self.connectedProxies[i].name == this.name) { - this.destroy(); - return self.emit('failed', this); - } - } - - // Remove the handlers - for(var i = 0; i < handlers.length; i++) { - this.removeAllListeners(handlers[i]); - } - - // Add stable state handlers - this.on('error', handleEvent(self, 'error')); - this.on('close', handleEvent(self, 'close')); - this.on('timeout', handleEvent(self, 'timeout')); - this.on('parseError', handleEvent(self, 'parseError')); - - // Move from connecting proxies connected - moveServerFrom(self.connectingProxies, self.connectedProxies, this); - // Emit the joined event - self.emit('joined', 'mongos', this); - } else { - // This is not a mongos proxy, remove it completely - removeProxyFrom(self.connectingProxies, this); - // Emit the left event - self.emit('left', 'server', this); - // Emit failed event - self.emit('failed', this); - } - } else { - moveServerFrom(self.connectingProxies, self.disconnectedProxies, this); - // Emit the left event - self.emit('left', 'mongos', this); - // Emit failed event - self.emit('failed', this); - } - - // Trigger topologyMonitor - if(self.connectingProxies.length == 0) { - // Emit connected if we are connected - if(self.connectedProxies.length > 0) { - // Set initial lowerBoundLatency - for(var i = 0; i < self.connectedProxies.length; i++) { - // Adjust lower bound - if(self.lowerBoundLatency > self.connectedProxies[i].lastIsMasterMS) { - self.lowerBoundLatency = self.connectedProxies[i].lastIsMasterMS; - } - } - - // Set the state to connected - stateTransition(self, CONNECTED); - // Emit the connect event - self.emit('connect', self); - self.emit('fullsetup', self); - self.emit('all', self); - } else if(self.disconnectedProxies.length == 0) { - return self.emit('error', new MongoError('no mongos proxies found in seed list')); - } - - // Topology monitor - topologyMonitor(self, {firstConnect:true}); - } - }; -} - -function connectProxies(self, servers) { - // Update connectingProxies - self.connectingProxies = self.connectingProxies.concat(servers); - - // Index used to interleaf the server connects, avoiding - // runtime issues on io constrained vm's - var timeoutInterval = 0; - - function connect(server, timeoutInterval) { - setTimeout(function() { - // Add event handlers - server.once('close', handleInitialConnectEvent(self, 'close')); - server.once('timeout', handleInitialConnectEvent(self, 'timeout')); - server.once('parseError', handleInitialConnectEvent(self, 'parseError')); - server.once('error', handleInitialConnectEvent(self, 'error')); - server.once('connect', handleInitialConnectEvent(self, 'connect')); - // SDAM Monitoring events - server.on('serverOpening', function(e) { self.emit('serverOpening', e); }); - server.on('serverDescriptionChanged', function(e) { self.emit('serverDescriptionChanged', e); }); - server.on('serverClosed', function(e) { self.emit('serverClosed', e); }); - // Start connection - server.connect(self.s.connectOptions); - }, timeoutInterval); - } - // Start all the servers - while(servers.length > 0) { - connect(servers.shift(), timeoutInterval++); - } -} - -function pickProxy(self) { - // Get the currently connected Proxies - var connectedProxies = self.connectedProxies.slice(0); - - // Filter out the possible servers - connectedProxies = connectedProxies.filter(function(server) { - if((server.lastIsMasterMS <= (self.lowerBoundLatency + self.s.localThresholdMS)) - && server.isConnected()) { - return true; - } - }); - - // We have no connectedProxies pick first of the connected ones - if(connectedProxies.length == 0) { - return self.connectedProxies[0]; - } - - // Get proxy - var proxy = connectedProxies[self.index % connectedProxies.length]; - // Update the index - self.index = (self.index + 1) % connectedProxies.length; - // Return the proxy - return proxy; -} - -function moveServerFrom(from, to, proxy) { - for(var i = 0; i < from.length; i++) { - if(from[i].name == proxy.name) { - from.splice(i, 1); - } - } - - for(var i = 0; i < to.length; i++) { - if(to[i].name == proxy.name) { - to.splice(i, 1); - } - } - - to.push(proxy); -} - -function removeProxyFrom(from, proxy) { - for(var i = 0; i < from.length; i++) { - if(from[i].name == proxy.name) { - from.splice(i, 1); - } - } -} - -function reconnectProxies(self, proxies, callback) { - // Count lefts - var count = proxies.length; - - // Handle events - var _handleEvent = function(self, event) { - return function(err, r) { - var _self = this; - count = count - 1; - - // Destroyed - if(self.state == DESTROYED) { - return this.destroy(); - } - - if(event == 'connect' && !self.authenticating) { - // Destroyed - if(self.state == DESTROYED) { - return _self.destroy(); - } - - // Remove the handlers - for(var i = 0; i < handlers.length; i++) { - _self.removeAllListeners(handlers[i]); - } - - // Add stable state handlers - _self.on('error', handleEvent(self, 'error')); - _self.on('close', handleEvent(self, 'close')); - _self.on('timeout', handleEvent(self, 'timeout')); - _self.on('parseError', handleEvent(self, 'parseError')); - - // Move to the connected servers - moveServerFrom(self.disconnectedProxies, self.connectedProxies, _self); - // Emit joined event - self.emit('joined', 'mongos', _self); - } else if(event == 'connect' && self.authenticating) { - this.destroy(); - } - - // Are we done finish up callback - if(count == 0) { - callback(); - } - } - } - - // No new servers - if(count == 0) { - return callback(); - } - - // Execute method - function execute(_server, i) { - setTimeout(function() { - // Destroyed - if(self.state == DESTROYED) { - return; - } - - // Create a new server instance - var server = new Server(assign({}, self.s.options, { - host: _server.name.split(':')[0], - port: parseInt(_server.name.split(':')[1], 10) - }, { - authProviders: self.authProviders, reconnect:false, monitoring: false, inTopology: true - })); - - // Add temp handlers - server.once('connect', _handleEvent(self, 'connect')); - server.once('close', _handleEvent(self, 'close')); - server.once('timeout', _handleEvent(self, 'timeout')); - server.once('error', _handleEvent(self, 'error')); - server.once('parseError', _handleEvent(self, 'parseError')); - - // SDAM Monitoring events - server.on('serverOpening', function(e) { self.emit('serverOpening', e); }); - server.on('serverDescriptionChanged', function(e) { self.emit('serverDescriptionChanged', e); }); - server.on('serverClosed', function(e) { self.emit('serverClosed', e); }); - server.connect(self.s.connectOptions); - }, i); - } - - // Create new instances - for(var i = 0; i < proxies.length; i++) { - execute(proxies[i], i); - } -} - -function topologyMonitor(self, options) { - options = options || {}; - - // Set momitoring timeout - self.haTimeoutId = setTimeout(function() { - if(self.state == DESTROYED) return; - // If we have a primary and a disconnect handler, execute - // buffered operations - if(self.isConnected() && self.s.disconnectHandler) { - self.s.disconnectHandler.execute(); - } - - // Get the connectingServers - var proxies = self.connectedProxies.slice(0); - // Get the count - var count = proxies.length; - - // If the count is zero schedule a new fast - function pingServer(_self, _server, cb) { - // Measure running time - var start = new Date().getTime(); - - // Emit the server heartbeat start - emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: _server.name }); - - // Execute ismaster - _server.command('admin.$cmd', {ismaster:true}, {monitoring: true}, function(err, r) { - if(self.state == DESTROYED) { - _server.destroy(); - return cb(err, r); - } - - // Calculate latency - var latencyMS = new Date().getTime() - start; - - // Adjust lower bound - if(self.lowerBoundLatency > _server.lastIsMasterMS) { - self.lowerBoundLatency = _server.lastIsMasterMS; - } - - // We had an error, remove it from the state - if(err) { - // Emit the server heartbeat failure - emitSDAMEvent(self, 'serverHearbeatFailed', { durationMS: latencyMS, failure: err, connectionId: _server.name }); - // Move from connected proxies to disconnected proxies - moveServerFrom(self.connectedProxies, self.disconnectedProxies, _server); - // Emit left event - self.emit('left', 'mongos', _server); - _server.destroy(); - } else { - // Update the server ismaster - _server.ismaster = r.result; - _server.lastIsMasterMS = latencyMS; - - // Server heart beat event - emitSDAMEvent(self, 'serverHeartbeatSucceeded', { durationMS: latencyMS, reply: r.result, connectionId: _server.name }); - } - - cb(err, r); - }); - } - - // No proxies initiate monitor again - if(proxies.length == 0) { - // Emit close event if any listeners registered - if(self.listeners("close").length > 0) { - self.emit('close', self); - } - - // Attempt to connect to any unknown servers - return reconnectProxies(self, self.disconnectedProxies, function(err, cb) { - if(self.state == DESTROYED) return; - - // Are we connected ? emit connect event - if(self.state == CONNECTING && options.firstConnect) { - self.emit('connect', self); - self.emit('fullsetup', self); - self.emit('all', self); - } else if(self.isConnected()) { - self.emit('reconnect', self); - } else if(!self.isConnected() && self.listeners("close").length > 0) { - self.emit('close', self); - } - - // Perform topology monitor - topologyMonitor(self); - }); - } - - // Ping all servers - for(var i = 0; i < proxies.length; i++) { - pingServer(self, proxies[i], function(err, r) { - count = count - 1; - - if(count == 0) { - if(self.state == DESTROYED) return; - - // Attempt to connect to any unknown servers - reconnectProxies(self, self.disconnectedProxies, function(err, cb) { - if(self.state == DESTROYED) return; - // Perform topology monitor - topologyMonitor(self); - }); - } - }); - } - }, self.s.haInterval); -} - -/** - * Returns the last known ismaster document for this server - * @method - * @return {object} - */ -Mongos.prototype.lastIsMaster = function() { - return this.ismaster; -} - -/** - * Unref all connections belong to this server - * @method - */ -Mongos.prototype.unref = function(emitClose) { - // Transition state - stateTransition(this, DISCONNECTED); - // Get all proxies - var proxies = self.connectedProxies.concat(self.connectingProxies); - proxies.forEach(function(x) { - x.unref(); - }); - - clearTimeout(this.haTimeoutId); -} - -/** - * Destroy the server connection - * @method - */ -Mongos.prototype.destroy = function(emitClose) { - // Transition state - stateTransition(this, DESTROYED); - // Get all proxies - var proxies = this.connectedProxies.concat(this.connectingProxies); - // Clear out any monitoring process - if(this.haTimeoutId) clearTimeout(this.haTimeoutId); - // Destroy all connecting servers - proxies.forEach(function(x) { - x.destroy(); - }); - - // Emit toplogy closing event - emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id }); - -} - -/** - * Figure out if the server is connected - * @method - * @return {boolean} - */ -Mongos.prototype.isConnected = function(options) { - return this.connectedProxies.length > 0; -} - -/** - * Figure out if the server instance was destroyed by calling destroy - * @method - * @return {boolean} - */ -Mongos.prototype.isDestroyed = function() { - return this.state == DESTROYED; -} - -// -// Operations -// - -// Execute write operation -var executeWriteOperation = function(self, op, ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - // Ensure we have no options - options = options || {}; - // Pick a server - var server = pickProxy(self); - // No server found error out - if(!server) return callback(new MongoError('no mongos proxy available')); - // Execute the command - server[op](ns, ops, options, callback); -} - -/** - * Insert one or more documents - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of documents to insert - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Mongos.prototype.insert = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.isConnected() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // No mongos proxy available - if(!this.isConnected()) { - return callback(new MongoError('no mongos proxy available')); - } - - // Execute write operation - executeWriteOperation(this, 'insert', ns, ops, options, callback); -} - -/** - * Perform one or more update operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of updates - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Mongos.prototype.update = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.isConnected() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // No mongos proxy available - if(!this.isConnected()) { - return callback(new MongoError('no mongos proxy available')); - } - - // Execute write operation - executeWriteOperation(this, 'update', ns, ops, options, callback); -} - -/** - * Perform one or more remove operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of removes - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Mongos.prototype.remove = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.isConnected() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // No mongos proxy available - if(!this.isConnected()) { - return callback(new MongoError('no mongos proxy available')); - } - - // Execute write operation - executeWriteOperation(this, 'remove', ns, ops, options, callback); -} - -/** - * Execute a command - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {object} cmd The command hash - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Connection} [options.connection] Specify connection object to execute command against - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Mongos.prototype.command = function(ns, cmd, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - var self = this; - - // Establish readPreference - var readPreference = options.readPreference ? options.readPreference : ReadPreference.primary; - - // Pick a proxy - var server = pickProxy(self); - - // No server returned we had an error - if(server == null) { - return callback(new MongoError('no mongos proxy available')); - } - - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if((server == null || !server.isConnected()) && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('command', ns, cmd, options, callback); - } - - // Execute the command - server.command(ns, cmd, options, callback); -} - -/** - * Perform one or more remove operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {{object}|{Long}} cmd Can be either a command returning a cursor or a cursorId - * @param {object} [options.batchSize=0] Batchsize for the operation - * @param {array} [options.documents=[]] Initial documents list for cursor - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Mongos.prototype.cursor = function(ns, cmd, cursorOptions) { - cursorOptions = cursorOptions || {}; - var FinalCursor = cursorOptions.cursorFactory || this.s.Cursor; - return new FinalCursor(this.s.bson, ns, cmd, cursorOptions, this, this.s.options); -} - -/** - * Authenticate using a specified mechanism - * @method - * @param {string} mechanism The Auth mechanism we are invoking - * @param {string} db The db we are invoking the mechanism against - * @param {...object} param Parameters for the specific mechanism - * @param {authResultCallback} callback A callback function - */ -Mongos.prototype.auth = function(mechanism, db) { - var allArgs = Array.prototype.slice.call(arguments, 0).slice(0); - var self = this; - var args = Array.prototype.slice.call(arguments, 2); - var callback = args.pop(); - - // If we don't have the mechanism fail - if(this.authProviders[mechanism] == null && mechanism != 'default') { - return callback(new MongoError(f("auth provider %s does not exist", mechanism))); - } - - // Are we already authenticating, throw - if(this.authenticating) { - return callback(new MongoError('authentication or logout allready in process')); - } - - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if(!self.isConnected() && self.s.disconnectHandler != null) { - return self.s.disconnectHandler.add('auth', db, allArgs, {}, callback); - } - - // Set to authenticating - this.authenticating = true; - // All errors - var errors = []; - - // Get all the servers - var servers = this.connectedProxies.slice(0); - // No servers return - if(servers.length == 0) { - this.authenticating = false; - callback(null, true); - } - - // Authenticate - function auth(server) { - // Arguments without a callback - var argsWithoutCallback = [mechanism, db].concat(args.slice(0)); - // Create arguments - var finalArguments = argsWithoutCallback.concat([function(err, r) { - count = count - 1; - // Save all the errors - if(err) errors.push({name: server.name, err: err}); - // We are done - if(count == 0) { - // Auth is done - self.authenticating = false; - - // Return the auth error - if(errors.length) return callback(MongoError.create({ - message: 'authentication fail', errors: errors - }), false); - - // Successfully authenticated session - callback(null, self); - } - }]); - - // Execute the auth only against non arbiter servers - if(!server.lastIsMaster().arbiterOnly) { - server.auth.apply(server, finalArguments); - } - } - - // Get total count - var count = servers.length; - // Authenticate against all servers - while(servers.length > 0) { - auth(servers.shift()); - } -} - -/** - * Logout from a database - * @method - * @param {string} db The db we are logging out from - * @param {authResultCallback} callback A callback function - */ -Mongos.prototype.logout = function(dbName, callback) { - var self = this; - // Are we authenticating or logging out, throw - if(this.authenticating) { - throw new MongoError('authentication or logout allready in process'); - } - - // Ensure no new members are processed while logging out - this.authenticating = true; - - // Remove from all auth providers (avoid any reaplication of the auth details) - var providers = Object.keys(this.authProviders); - for(var i = 0; i < providers.length; i++) { - this.authProviders[providers[i]].logout(dbName); - } - - // Now logout all the servers - var servers = this.connectedProxies.slice(0); - var count = servers.length; - if(count == 0) return callback(); - var errors = []; - - // Execute logout on all server instances - for(var i = 0; i < servers.length; i++) { - servers[i].logout(dbName, function(err) { - count = count - 1; - if(err) errors.push({name: server.name, err: err}); - - if(count == 0) { - // Do not block new operations - self.authenticating = false; - // If we have one or more errors - if(errors.length) return callback(MongoError.create({ - message: f('logout failed against db %s', dbName), errors: errors - }), false); - - // No errors - callback(); - } - }); - } -} - -/** - * Get server - * @method - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @return {Server} - */ -Mongos.prototype.getServer = function() { - var server = pickProxy(this); - if(this.s.debug) this.emit('pickedServer', null, server); - return server; -} - -/** - * All raw connections - * @method - * @return {Connection[]} - */ -Mongos.prototype.connections = function() { - var connections = []; - - for(var i = 0; i < this.connectedProxies.length; i++) { - connections = connections.concat(this.connectedProxies[i].connections()); - } - - return connections; -} - -/** - * A mongos connect event, used to verify that the connection is up and running - * - * @event Mongos#connect - * @type {Mongos} - */ - -/** - * A mongos reconnect event, used to verify that the mongos topology has reconnected - * - * @event Mongos#reconnect - * @type {Mongos} - */ - -/** - * A mongos fullsetup event, used to signal that all topology members have been contacted. - * - * @event Mongos#fullsetup - * @type {Mongos} - */ - -/** - * A mongos all event, used to signal that all topology members have been contacted. - * - * @event Mongos#all - * @type {Mongos} - */ - -/** - * A server member left the mongos list - * - * @event Mongos#left - * @type {Mongos} - * @param {string} type The type of member that left (mongos) - * @param {Server} server The server object that left - */ - -/** - * A server member joined the mongos list - * - * @event Mongos#joined - * @type {Mongos} - * @param {string} type The type of member that left (mongos) - * @param {Server} server The server object that joined - */ - -/** - * A server opening SDAM monitoring event - * - * @event Mongos#serverOpening - * @type {object} - */ - -/** - * A server closed SDAM monitoring event - * - * @event Mongos#serverClosed - * @type {object} - */ - -/** - * A server description SDAM change monitoring event - * - * @event Mongos#serverDescriptionChanged - * @type {object} - */ - -/** - * A topology open SDAM event - * - * @event Mongos#topologyOpening - * @type {object} - */ - -/** - * A topology closed SDAM event - * - * @event Mongos#topologyClosed - * @type {object} - */ - -/** - * A topology structure SDAM change event - * - * @event Mongos#topologyDescriptionChanged - * @type {object} - */ - -/** - * A topology serverHeartbeatStarted SDAM event - * - * @event Mongos#serverHeartbeatStarted - * @type {object} - */ - -/** - * A topology serverHearbeatFailed SDAM event - * - * @event Mongos#serverHearbeatFailed - * @type {object} - */ - -/** - * A topology serverHeartbeatSucceeded SDAM change event - * - * @event Mongos#serverHeartbeatSucceeded - * @type {object} - */ - -module.exports = Mongos; diff --git a/node_modules/mongodb-core/lib/topologies/read_preference.js b/node_modules/mongodb-core/lib/topologies/read_preference.js deleted file mode 100644 index 257b957..0000000 --- a/node_modules/mongodb-core/lib/topologies/read_preference.js +++ /dev/null @@ -1,106 +0,0 @@ -"use strict"; - -var needSlaveOk = ['primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest']; - -/** - * @fileOverview The **ReadPreference** class is a class that represents a MongoDB ReadPreference and is - * used to construct connections. - * - * @example - * var ReplSet = require('mongodb-core').ReplSet - * , ReadPreference = require('mongodb-core').ReadPreference - * , assert = require('assert'); - * - * var server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'}); - * // Wait for the connection event - * server.on('connect', function(server) { - * var cursor = server.cursor('db.test' - * , {find: 'db.test', query: {}} - * , {readPreference: new ReadPreference('secondary')}); - * cursor.next(function(err, doc) { - * server.destroy(); - * }); - * }); - * - * // Start connecting - * server.connect(); - */ - -/** - * Creates a new Pool instance - * @class - * @param {string} preference A string describing the preference (primary|primaryPreferred|secondary|secondaryPreferred|nearest) - * @param {object} tags The tags object - * @param {object} [options] Additional read preference options - * @property {string} preference The preference string (primary|primaryPreferred|secondary|secondaryPreferred|nearest) - * @property {object} tags The tags object - * @property {object} options Additional read preference options - * @return {ReadPreference} - */ -var ReadPreference = function(preference, tags, options) { - this.preference = preference; - this.tags = tags; - this.options = options; -} - -/** - * This needs slaveOk bit set - * @method - * @return {boolean} - */ -ReadPreference.prototype.slaveOk = function() { - return needSlaveOk.indexOf(this.preference) != -1; -} - -/** - * Are the two read preference equal - * @method - * @return {boolean} - */ -ReadPreference.prototype.equals = function(readPreference) { - return readPreference.preference == this.preference; -} - -/** - * Return JSON representation - * @method - * @return {Object} - */ -ReadPreference.prototype.toJSON = function() { - var readPreference = {mode: this.preference}; - if(Array.isArray(this.tags)) readPreference.tags = this.tags; - return readPreference; -} - -/** - * Primary read preference - * @method - * @return {ReadPreference} - */ -ReadPreference.primary = new ReadPreference('primary'); -/** - * Primary Preferred read preference - * @method - * @return {ReadPreference} - */ -ReadPreference.primaryPreferred = new ReadPreference('primaryPreferred'); -/** - * Secondary read preference - * @method - * @return {ReadPreference} - */ -ReadPreference.secondary = new ReadPreference('secondary'); -/** - * Secondary Preferred read preference - * @method - * @return {ReadPreference} - */ -ReadPreference.secondaryPreferred = new ReadPreference('secondaryPreferred'); -/** - * Nearest read preference - * @method - * @return {ReadPreference} - */ -ReadPreference.nearest = new ReadPreference('nearest'); - -module.exports = ReadPreference; diff --git a/node_modules/mongodb-core/lib/topologies/replset.js b/node_modules/mongodb-core/lib/topologies/replset.js deleted file mode 100644 index dc73d59..0000000 --- a/node_modules/mongodb-core/lib/topologies/replset.js +++ /dev/null @@ -1,1278 +0,0 @@ -"use strict" - -var inherits = require('util').inherits, - f = require('util').format, - EventEmitter = require('events').EventEmitter, - BSON = require('bson').native().BSON, - ReadPreference = require('./read_preference'), - BasicCursor = require('../cursor'), - Logger = require('../connection/logger'), - debugOptions = require('../connection/utils').debugOptions, - MongoError = require('../error'), - Server = require('./server'), - ReplSetState = require('./replset_state'), - assign = require('./shared').assign; - -var MongoCR = require('../auth/mongocr') - , X509 = require('../auth/x509') - , Plain = require('../auth/plain') - , GSSAPI = require('../auth/gssapi') - , SSPI = require('../auth/sspi') - , ScramSHA1 = require('../auth/scram'); - -// -// States -var DISCONNECTED = 'disconnected'; -var CONNECTING = 'connecting'; -var CONNECTED = 'connected'; -var DESTROYED = 'destroyed'; - -function stateTransition(self, newState) { - var legalTransitions = { - 'disconnected': [CONNECTING, DESTROYED, DISCONNECTED], - 'connecting': [CONNECTING, DESTROYED, CONNECTED, DISCONNECTED], - 'connected': [CONNECTED, DISCONNECTED, DESTROYED], - 'destroyed': [DESTROYED] - } - - // Get current state - var legalStates = legalTransitions[self.state]; - if(legalStates && legalStates.indexOf(newState) != -1) { - self.state = newState; - } else { - self.logger.error(f('Pool with id [%s] failed attempted illegal state transition from [%s] to [%s] only following state allowed [%s]' - , self.id, self.state, newState, legalStates)); - } -} - -// -// ReplSet instance id -var id = 1; -var handlers = ['connect', 'close', 'error', 'timeout', 'parseError']; - -/** - * Creates a new Replset instance - * @class - * @param {array} seedlist A list of seeds for the replicaset - * @param {boolean} options.setName The Replicaset set name - * @param {boolean} [options.secondaryOnlyConnectionAllowed=false] Allow connection to a secondary only replicaset - * @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry - * @param {boolean} [options.emitError=false] Server will emit errors events - * @param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors - * @param {number} [options.size=5] Server connection pool size - * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled - * @param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled - * @param {boolean} [options.noDelay=true] TCP Connection no delay - * @param {number} [options.connectionTimeout=10000] TCP Connection timeout setting - * @param {number} [options.socketTimeout=0] TCP Socket timeout setting - * @param {boolean} [options.singleBufferSerializtion=true] Serialize into single buffer, trade of peak memory for serialization speed - * @param {boolean} [options.ssl=false] Use SSL for connection - * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. - * @param {Buffer} [options.ca] SSL Certificate store binary buffer - * @param {Buffer} [options.cert] SSL Certificate binary buffer - * @param {Buffer} [options.key] SSL Key file binary buffer - * @param {string} [options.passphrase] SSL Certificate pass phrase - * @param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates - * @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits - * @param {number} [options.pingInterval=5000] Ping interval to check the response time to the different servers - * @param {number} [options.localThresholdMS=15] Cutoff latency point in MS for MongoS proxy selection - * @return {ReplSet} A cursor instance - * @fires ReplSet#connect - * @fires ReplSet#ha - * @fires ReplSet#joined - * @fires ReplSet#left - * @fires ReplSet#failed - * @fires ReplSet#fullsetup - * @fires ReplSet#all - * @fires ReplSet#error - * @fires ReplSet#serverHeartbeatStarted - * @fires ReplSet#serverHeartbeatSucceeded - * @fires ReplSet#serverHeartbeatFailed - * @fires ReplSet#topologyOpening - * @fires ReplSet#topologyClosed - * @fires ReplSet#topologyDescriptionChanged - */ -var ReplSet = function(seedlist, options) { - var self = this; - options = options || {}; - - // Validate seedlist - if(!Array.isArray(seedlist)) throw new MongoError("seedlist must be an array"); - // Validate list - if(seedlist.length == 0) throw new MongoError("seedlist must contain at least one entry"); - // Validate entries - seedlist.forEach(function(e) { - if(typeof e.host != 'string' || typeof e.port != 'number') - throw new MongoError("seedlist entry must contain a host and port"); - }); - - // Add event listener - EventEmitter.call(this); - - // Get replSet Id - this.id = id++; - - // Get the localThresholdMS - var localThresholdMS = options.localThresholdMS || 15; - // Backward compatibility - if(options.acceptableLatency) localThresholdMS = options.acceptableLatency; - - // Create a logger - var logger = Logger('ReplSet', options); - - // Internal state - this.s = { - options: assign({}, options), - // BSON instance - bson: options.bson || new BSON(), - // Factory overrides - Cursor: options.cursorFactory || BasicCursor, - // Logger instance - logger: logger, - // Seedlist - seedlist: seedlist, - // Replicaset state - replicaSetState: new ReplSetState({ - id: this.id, setName: options.setName, - acceptableLatency: localThresholdMS, - logger: logger - }), - // Current servers we are connecting to - connectingServers: [], - // Ha interval - haInterval: options.haInterval ? options.haInterval : 10000, - // Minimum heartbeat frequency used if we detect a server close - minHeartbeatFrequencyMS: 500, - // Disconnect handler - disconnectHandler: options.disconnectHandler, - // Server selection index - index: 0, - // Connect function options passed in - connectOptions: {}, - // Are we running in debug mode - debug: typeof options.debug == 'boolean' ? options.debug : false - } - - // Add handler for topology change - this.s.replicaSetState.on('topologyDescriptionChanged', function(r) { self.emit('topologyDescriptionChanged', r); }); - - // Log info warning if the socketTimeout < haInterval as it will cause - // a lot of recycled connections to happen. - if(this.s.logger.isWarn() - && this.s.options.socketTimeout != 0 - && this.s.options.socketTimeout < this.s.haInterval) { - this.s.logger.warn(f('warning socketTimeout %s is less than haInterval %s. This might cause unnecessary server reconnections due to socket timeouts' - , this.s.options.socketTimeout, this.s.haInterval)); - } - - // All the authProviders - this.authProviders = options.authProviders || { - 'mongocr': new MongoCR(this.s.bson), 'x509': new X509(this.s.bson) - , 'plain': new Plain(this.s.bson), 'gssapi': new GSSAPI(this.s.bson) - , 'sspi': new SSPI(this.s.bson), 'scram-sha-1': new ScramSHA1(this.s.bson) - } - - // Add forwarding of events from state handler - var types = ['joined', 'left']; - types.forEach(function(x) { - self.s.replicaSetState.on(x, function(t, s) { - self.emit(x, t, s); - }); - }); - - // Connect stat - this.initialConnectState = { - connect: false, fullsetup: false, all: false - } - - // Disconnected state - this.state = DISCONNECTED; - this.haTimeoutId = null; - // Are we authenticating - this.authenticating = false; -} - -inherits(ReplSet, EventEmitter); - -Object.defineProperty(ReplSet.prototype, 'type', { - enumerable:true, get: function() { return 'replset'; } -}); - -function attemptReconnect(self) { - self.haTimeoutId = setTimeout(function() { - if(self.state == DESTROYED) return; - - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('attemptReconnect for replset with id %s', self.id)); - } - - // Get all known hosts - var keys = Object.keys(self.s.replicaSetState.set); - var servers = keys.map(function(x) { - return new Server(assign({}, self.s.options, { - host: x.split(':')[0], port: parseInt(x.split(':')[1], 10) - }, { - authProviders: self.authProviders, reconnect:false, monitoring: false, inTopology: true - })); - }); - - // Create the list of servers - self.s.connectingServers = servers.slice(0); - - // Handle all events coming from servers - function _handleEvent(self, event) { - return function(err) { - // Destroy the instance - if(self.state == DESTROYED) { - return this.destroy(); - } - - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('attemptReconnect for replset with id %s using server %s ended with event %s', self.id, this.name, event)); - } - - // Check if we are done - function done() { - // Done with the reconnection attempt - if(self.s.connectingServers.length == 0) { - if(self.state == DESTROYED) return; - - // Do we have a primary - if(self.s.replicaSetState.hasPrimary()) { - // If we have a primary and a disconnect handler, execute - // buffered operations - if(self.s.replicaSetState.hasPrimaryAndSecondary() && self.s.disconnectHandler) { - self.s.disconnectHandler.execute(); - } - - // Connect any missing servers - connectNewServers(self, self.s.replicaSetState.unknownServers, function(err, cb) { - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('attemptReconnect for replset with id successful resuming topologyMonitor', self.id)); - } - // Go back to normal topology monitoring - topologyMonitor(self); - }); - } else { - if(self.listeners("close").length > 0) { - self.emit('close', self); - } - - attemptReconnect(self); - } - } - } - - // Remove the server from our list - for(var i = 0; i < self.s.connectingServers.length; i++) { - if(self.s.connectingServers[i].equals(this)) { - self.s.connectingServers.splice(i, 1); - } - } - - // Keep reference to server - var _self = this; - - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('attemptReconnect in replset with id %s for', self.id)); - } - - // Connect and not authenticating - if(event == 'connect' && !self.authenticating) { - if(self.state == DESTROYED) { - return _self.destroy(); - } - - // Update the replicaset state - if(self.s.replicaSetState.update(_self)) { - // Remove the handlers - for(var i = 0; i < handlers.length; i++) { - _self.removeAllListeners(handlers[i]); - } - - // Add stable state handlers - _self.on('error', handleEvent(self, 'error')); - _self.on('close', handleEvent(self, 'close')); - _self.on('timeout', handleEvent(self, 'timeout')); - _self.on('parseError', handleEvent(self, 'parseError')); - } else { - _self.destroy(); - } - - done(); - } else if(event == 'connect' && self.authenticating) { - this.destroy(); - } - - done(); - } - } - - // Index used to interleaf the server connects, avoiding - // runtime issues on io constrained vm's - var timeoutInterval = 0; - - function connect(server, timeoutInterval) { - setTimeout(function() { - server.once('connect', _handleEvent(self, 'connect')); - server.once('close', _handleEvent(self, 'close')); - server.once('timeout', _handleEvent(self, 'timeout')); - server.once('error', _handleEvent(self, 'error')); - server.once('parseError', _handleEvent(self, 'parseError')); - - // SDAM Monitoring events - server.on('serverOpening', function(e) { self.emit('serverOpening', e); }); - server.on('serverDescriptionChanged', function(e) { self.emit('serverDescriptionChanged', e); }); - server.on('serverClosed', function(e) { self.emit('serverClosed', e); }); - - server.connect(self.s.connectOptions); - }, timeoutInterval); - } - - // Connect all servers - while(servers.length > 0) { - connect(servers.shift(), timeoutInterval++); - } - }, self.s.minHeartbeatFrequencyMS); -} - -function connectNewServers(self, servers, callback) { - // Count lefts - var count = servers.length; - - // Handle events - var _handleEvent = function(self, event) { - return function(err, r) { - var _self = this; - count = count - 1; - - // Destroyed - if(self.state == DESTROYED) { - return this.destroy(); - } - - if(event == 'connect' && !self.authenticating) { - // Destroyed - if(self.state == DESTROYED) { - return _self.destroy(); - } - - var result = self.s.replicaSetState.update(_self); - // Update the state with the new server - if(result) { - // Remove the handlers - for(var i = 0; i < handlers.length; i++) { - _self.removeAllListeners(handlers[i]); - } - - // Add stable state handlers - _self.on('error', handleEvent(self, 'error')); - _self.on('close', handleEvent(self, 'close')); - _self.on('timeout', handleEvent(self, 'timeout')); - _self.on('parseError', handleEvent(self, 'parseError')); - } else { - _self.destroy(); - } - } else if(event == 'connect' && self.authenticating) { - this.destroy(); - } - - // Are we done finish up callback - if(count == 0) { callback(); } - } - } - - // No new servers - if(count == 0) return callback(); - - // Execute method - function execute(_server, i) { - setTimeout(function() { - // Destroyed - if(self.state == DESTROYED) { - return; - } - - // Create a new server instance - var server = new Server(assign({}, self.s.options, { - host: _server.split(':')[0], - port: parseInt(_server.split(':')[1], 10) - }, { - authProviders: self.authProviders, reconnect:false, monitoring: false, inTopology: true - })); - - // Add temp handlers - server.once('connect', _handleEvent(self, 'connect')); - server.once('close', _handleEvent(self, 'close')); - server.once('timeout', _handleEvent(self, 'timeout')); - server.once('error', _handleEvent(self, 'error')); - server.once('parseError', _handleEvent(self, 'parseError')); - - // SDAM Monitoring events - server.on('serverOpening', function(e) { self.emit('serverOpening', e); }); - server.on('serverDescriptionChanged', function(e) { self.emit('serverDescriptionChanged', e); }); - server.on('serverClosed', function(e) { self.emit('serverClosed', e); }); - server.connect(self.s.connectOptions); - }, i); - } - - // Create new instances - for(var i = 0; i < servers.length; i++) { - execute(servers[i], i); - } -} - -function topologyMonitor(self, options) { - options = options || {}; - - // Set momitoring timeout - self.haTimeoutId = setTimeout(function() { - if(self.state == DESTROYED) return; - - // If we have a primary and a disconnect handler, execute - // buffered operations - if(self.s.replicaSetState.hasPrimaryAndSecondary() && self.s.disconnectHandler) { - self.s.disconnectHandler.execute(); - } - - // Get the connectingServers - var connectingServers = self.s.replicaSetState.allServers(); - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('topologyMonitor in replset with id %s connected servers [%s]' - , self.id - , connectingServers.map(function(x) { - return x.name; - }))); - } - // Get the count - var count = connectingServers.length; - // If we have no servers connected - if(count == 0 && !options.haInterval) { - if(self.listeners("close").length > 0) { - self.emit('close', self); - } - - return attemptReconnect(self); - } - - // If the count is zero schedule a new fast - function pingServer(_self, _server, cb) { - // Measure running time - var start = new Date().getTime(); - - // Emit the server heartbeat start - emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: _server.name }); - // Execute ismaster - _server.command('admin.$cmd', {ismaster:true}, {monitoring: true}, function(err, r) { - if(self.state == DESTROYED) { - _server.destroy(); - return cb(err, r); - } - - // Calculate latency - var latencyMS = new Date().getTime() - start; - - // We had an error, remove it from the state - if(err) { - // Emit the server heartbeat failure - emitSDAMEvent(self, 'serverHearbeatFailed', { durationMS: latencyMS, failure: err, connectionId: _server.name }); - // Remove the server from the state - _self.s.replicaSetState.remove(_server); - } else { - // Update the server ismaster - _server.ismaster = r.result; - if(_server.lastIsMasterMS == -1) { - _server.lastIsMasterMS = latencyMS; - } else if(_server.lastIsMasterMS) { - // After the first measurement, average RTT MUST be computed using an - // exponentially-weighted moving average formula, with a weighting factor (alpha) of 0.2. - // If the prior average is denoted old_rtt, then the new average (new_rtt) is - // computed from a new RTT measurement (x) using the following formula: - // alpha = 0.2 - // new_rtt = alpha * x + (1 - alpha) * old_rtt - _server.lastIsMasterMS = 0.2 * latencyMS + (1 - 0.2) * _server.lastIsMasterMS; - } - - // _server.lastIsMasterMS = !latencyMS; - _self.s.replicaSetState.update(_server); - - // Server heart beat event - emitSDAMEvent(self, 'serverHeartbeatSucceeded', { durationMS: latencyMS, reply: r.result, connectionId: _server.name }); - } - - cb(err, r); - }); - } - - // Connect any missing servers - function connectMissingServers() { - if(self.state == DESTROYED) return; - - // Attempt to connect to any unknown servers - connectNewServers(self, self.s.replicaSetState.unknownServers, function(err, cb) { - if(self.state == DESTROYED) return; - // Check if we have an options.haInterval (meaning it was triggered from connect) - if(options.haInterval) { - // Do we have a primary and secondary - if(self.state == CONNECTING - && self.s.replicaSetState.hasPrimaryAndSecondary()) { - // Transition to connected - stateTransition(self, CONNECTED); - // Update initial state - self.initialConnectState.connect = true; - self.initialConnectState.fullsetup = true; - self.initialConnectState.all = true; - // Emit fullsetup and all events - process.nextTick(function() { - self.emit('connect', self); - self.emit('fullsetup', self); - self.emit('all', self); - }); - } else if(self.state == CONNECTING - && self.s.replicaSetState.hasPrimary()) { - // Transition to connected - stateTransition(self, CONNECTED); - // Update initial state - self.initialConnectState.connect = true; - // Emit connected sign - process.nextTick(function() { - self.emit('connect', self); - }); - } else if(self.state == CONNECTING - && self.s.replicaSetState.hasSecondary() - && self.s.options.secondaryOnlyConnectionAllowed) { - // Transition to connected - stateTransition(self, CONNECTED); - // Update initial state - self.initialConnectState.connect = true; - // Emit connected sign - process.nextTick(function() { - self.emit('connect', self); - }); - } else if(self.state == CONNECTING) { - self.emit('error', new MongoError('no primary found in replicaset')); - // Destroy the topology - return self.destroy(); - } else if(self.state == CONNECTED - && self.s.replicaSetState.hasPrimaryAndSecondary() - && !self.initialConnectState.fullsetup) { - self.initialConnectState.fullsetup = true; - // Emit fullsetup and all events - process.nextTick(function() { - self.emit('fullsetup', self); - self.emit('all', self); - }); - } - } - - topologyMonitor(self); - }); - } - - // No connectingServers but unknown servers - if(connectingServers.length == 0 - && self.s.replicaSetState.unknownServers.length > 0 && options.haInterval) { - return connectMissingServers(); - } else if(connectingServers.length == 0 && options.haInterval) { - self.destroy(); - return self.emit('error', new MongoError('no valid replicaset members found')); - } - - // Ping all servers - for(var i = 0; i < connectingServers.length; i++) { - pingServer(self, connectingServers[i], function(err, r) { - count = count - 1; - - if(count == 0) { - connectMissingServers(); - } - }); - } - }, options.haInterval || self.s.haInterval) -} - -function handleEvent(self, event) { - return function(err) { - if(self.state == DESTROYED) return; - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('handleEvent %s from server %s in replset with id %s', event, self.name, self.id)); - } - - self.s.replicaSetState.remove(this); - } -} - -function handleInitialConnectEvent(self, event) { - return function(err) { - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('handleInitialConnectEvent %s from server %s in replset with id %s', event, this.name, self.id)); - } - - // Destroy the instance - if(self.state == DESTROYED) { - return this.destroy(); - } - - // Check the type of server - if(event == 'connect') { - // Update the state - var result = self.s.replicaSetState.update(this); - if(result == true) { - // Debug log - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('handleInitialConnectEvent %s from server %s in replset with id %s has state [%s]', event, this.name, self.id, JSON.stringify(self.s.replicaSetState.set))); - } - - // Remove the handlers - for(var i = 0; i < handlers.length; i++) { - this.removeAllListeners(handlers[i]); - } - - // Add stable state handlers - this.on('error', handleEvent(self, 'error')); - this.on('close', handleEvent(self, 'close')); - this.on('timeout', handleEvent(self, 'timeout')); - this.on('parseError', handleEvent(self, 'parseError')); - } else if(result instanceof MongoError) { - this.destroy(); - self.destroy(); - return self.emit('error', result); - } else { - this.destroy(); - } - } else { - // Emit failure to connect - self.emit('failed', this); - // Remove from the state - self.s.replicaSetState.remove(this); - } - - // Remove from the list from connectingServers - for(var i = 0; i < self.s.connectingServers.length; i++) { - if(self.s.connectingServers[i].equals(this)) { - self.s.connectingServers.splice(i, 1); - } - } - - // Trigger topologyMonitor - if(self.s.connectingServers.length == 0) { - topologyMonitor(self, {haInterval: 1}); - } - }; -} - -function connectServers(self, servers) { - // Update connectingServers - self.s.connectingServers = self.s.connectingServers.concat(servers); - - // Index used to interleaf the server connects, avoiding - // runtime issues on io constrained vm's - var timeoutInterval = 0; - - function connect(server, timeoutInterval) { - setTimeout(function() { - // Add the server to the state - self.s.replicaSetState.update(server); - // Add event handlers - server.once('close', handleInitialConnectEvent(self, 'close')); - server.once('timeout', handleInitialConnectEvent(self, 'timeout')); - server.once('parseError', handleInitialConnectEvent(self, 'parseError')); - server.once('error', handleInitialConnectEvent(self, 'error')); - server.once('connect', handleInitialConnectEvent(self, 'connect')); - // SDAM Monitoring events - server.on('serverOpening', function(e) { self.emit('serverOpening', e); }); - server.on('serverDescriptionChanged', function(e) { self.emit('serverDescriptionChanged', e); }); - server.on('serverClosed', function(e) { self.emit('serverClosed', e); }); - // Start connection - server.connect(self.s.connectOptions); - }, timeoutInterval); - } - - // Start all the servers - while(servers.length > 0) { - connect(servers.shift(), timeoutInterval++); - } -} - -/** - * Emit event if it exists - * @method - */ -function emitSDAMEvent(self, event, description) { - if(self.listeners(event).length > 0) { - self.emit(event, description); - } -} - -/** - * Initiate server connect - * @method - * @param {array} [options.auth=null] Array of auth options to apply on connect - */ -ReplSet.prototype.connect = function(options) { - var self = this; - // Add any connect level options to the internal state - this.s.connectOptions = options || {}; - // Set connecting state - stateTransition(this, CONNECTING); - // Create server instances - var servers = this.s.seedlist.map(function(x) { - return new Server(assign({}, self.s.options, x, { - authProviders: self.authProviders, reconnect:false, monitoring:false, inTopology: true - })); - }); - - // Emit the topology opening event - emitSDAMEvent(this, 'topologyOpening', { topologyId: this.id }); - - // Start all server connections - connectServers(self, servers); -} - -/** - * Destroy the server connection - * @method - */ -ReplSet.prototype.destroy = function() { - // Transition state - stateTransition(this, DESTROYED); - // Clear out any monitoring process - if(this.haTimeoutId) clearTimeout(this.haTimeoutId); - // Destroy the replicaset - this.s.replicaSetState.destroy(); - - // Destroy all connecting servers - this.s.connectingServers.forEach(function(x) { - x.destroy(); - }); - - // Emit toplogy closing event - emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id }); -} - -/** - * Unref all connections belong to this server - * @method - */ -ReplSet.prototype.unref = function() { - // Transition state - stateTransition(this, DISCONNECTED); - - this.s.replicaSetState.allServers().forEach(function(x) { - x.unref(); - }); - - clearTimeout(this.haTimeoutId); -} - -/** - * Returns the last known ismaster document for this server - * @method - * @return {object} - */ -ReplSet.prototype.lastIsMaster = function() { - return this.s.replicaSetState.primary - ? this.s.replicaSetState.primary.lastIsMaster() : null; -} - -/** - * All raw connections - * @method - * @return {Connection[]} - */ -ReplSet.prototype.connections = function() { - var servers = this.s.replicaSetState.allServers(); - var connections = []; - for(var i = 0; i < servers.length; i++) { - connections = connections.concat(servers[i].connections()); - } - - return connections; -} - -/** - * Figure out if the server is connected - * @method - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @return {boolean} - */ -ReplSet.prototype.isConnected = function(options) { - options = options || {}; - - // If we are authenticating signal not connected - // To avoid interleaving of operations - if(this.authenticating) return false; - - // If we specified a read preference check if we are connected to something - // than can satisfy this - if(options.readPreference - && options.readPreference.equals(ReadPreference.secondary)) { - return this.s.replicaSetState.hasSecondary(); - } - - if(options.readPreference - && options.readPreference.equals(ReadPreference.primary)) { - return this.s.replicaSetState.hasPrimary(); - } - - if(options.readPreference - && options.readPreference.equals(ReadPreference.primaryPreferred)) { - return this.s.replicaSetState.hasSecondary() || this.s.replicaSetState.hasPrimary(); - } - - if(options.readPreference - && options.readPreference.equals(ReadPreference.secondaryPreferred)) { - return this.s.replicaSetState.hasSecondary() || this.s.replicaSetState.hasPrimary(); - } - - if(this.s.secondaryOnlyConnectionAllowed - && this.s.replicaSetState.hasSecondary()) { - return true; - } - - return this.s.replicaSetState.hasPrimary(); -} - -/** - * Figure out if the replicaset instance was destroyed by calling destroy - * @method - * @return {boolean} - */ -ReplSet.prototype.isDestroyed = function() { - return this.state == DESTROYED; -} - -/** - * Get server - * @method - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @return {Server} - */ -ReplSet.prototype.getServer = function(options) { - // Ensure we have no options - options = options || {}; - // Pick the right server baspickServerd on readPreference - // var server = pickServer(this, this.s, options.readPreference); - var server = this.s.replicaSetState.pickServer(options.readPreference); - if(this.s.debug) this.emit('pickedServer', options.readPreference, server); - return server; -} - -/** - * Get all connected servers - * @method - * @return {Server[]} - */ -ReplSet.prototype.getServers = function() { - return this.s.replicaSetState.allServers(); -} - -function basicReadPreferenceValidation(self, options) { - if(options.readPreference && !(options.readPreference instanceof ReadPreference)) { - throw new Error("readPreference must be an instance of ReadPreference"); - } -} - -// -// Execute write operation -var executeWriteOperation = function(self, op, ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - // Ensure we have no options - options = options || {}; - - // No server returned we had an error - if(self.s.replicaSetState.primary == null) { - return callback(new MongoError("no primary server found")); - } - - // Execute the command - self.s.replicaSetState.primary[op](ns, ops, options, callback); -} - -/** - * Insert one or more documents - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of documents to insert - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -ReplSet.prototype.insert = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.s.replicaSetState.hasPrimary() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // Execute write operation - executeWriteOperation(this, 'insert', ns, ops, options, callback); -} - -/** - * Perform one or more update operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of updates - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -ReplSet.prototype.update = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.s.replicaSetState.hasPrimary() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // Execute write operation - executeWriteOperation(this, 'update', ns, ops, options, callback); -} - -/** - * Perform one or more remove operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of removes - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -ReplSet.prototype.remove = function(ns, ops, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - - // Not connected but we have a disconnecthandler - if(!this.s.replicaSetState.hasPrimary() && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('insert', ns, ops, options, callback); - } - - // Execute write operation - executeWriteOperation(this, 'remove', ns, ops, options, callback); -} - -/** - * Execute a command - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {object} cmd The command hash - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Connection} [options.connection] Specify connection object to execute command against - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -ReplSet.prototype.command = function(ns, cmd, options, callback) { - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - if(this.state == DESTROYED) return callback(new MongoError(f('topology was destroyed'))); - var self = this; - - // Establish readPreference - var readPreference = options.readPreference ? options.readPreference : ReadPreference.primary; - // Pick a server - // var server = pickServer(self, self.s, readPreference); - // var server = self.s.replicaSetState.pickServer(readPreference); - var server = this.s.replicaSetState.pickServer(readPreference); - if(!(server instanceof Server)) return callback(server); - if(self.s.debug) self.emit('pickedServer', ReadPreference.primary, server); - - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if(!server && this.s.disconnectHandler != null) { - return this.s.disconnectHandler.add('command', ns, cmd, options, callback); - } - - // No server returned we had an error - if(server == null) { - return callback(new MongoError(f("no server found that matches the provided readPreference %s", readPreference))); - } - - // Execute the command - server.command(ns, cmd, options, callback); -} - -/** - * Authenticate using a specified mechanism - * @method - * @param {string} mechanism The Auth mechanism we are invoking - * @param {string} db The db we are invoking the mechanism against - * @param {...object} param Parameters for the specific mechanism - * @param {authResultCallback} callback A callback function - */ -ReplSet.prototype.auth = function(mechanism, db) { - var allArgs = Array.prototype.slice.call(arguments, 0).slice(0); - var self = this; - var args = Array.prototype.slice.call(arguments, 2); - var callback = args.pop(); - - // If we don't have the mechanism fail - if(this.authProviders[mechanism] == null && mechanism != 'default') { - return callback(new MongoError(f("auth provider %s does not exist", mechanism))); - } - - // Are we already authenticating, throw - if(this.authenticating) { - return callback(new MongoError('authentication or logout allready in process')); - } - - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if(!self.s.replicaSetState.hasPrimary() && self.s.disconnectHandler != null) { - return self.s.disconnectHandler.add('auth', db, allArgs, {}, callback); - } - - // Set to authenticating - this.authenticating = true; - // All errors - var errors = []; - - // Get all the servers - var servers = this.s.replicaSetState.allServers(); - // No servers return - if(servers.length == 0) { - this.authenticating = false; - callback(null, true); - } - - // Authenticate - function auth(server) { - // Arguments without a callback - var argsWithoutCallback = [mechanism, db].concat(args.slice(0)); - // Create arguments - var finalArguments = argsWithoutCallback.concat([function(err, r) { - count = count - 1; - // Save all the errors - if(err) errors.push({name: server.name, err: err}); - // We are done - if(count == 0) { - // Auth is done - self.authenticating = false; - - // Return the auth error - if(errors.length) return callback(MongoError.create({ - message: 'authentication fail', errors: errors - }), false); - - // Successfully authenticated session - callback(null, self); - } - }]); - - if(!server.lastIsMaster().arbiterOnly) { - // Execute the auth only against non arbiter servers - server.auth.apply(server, finalArguments); - } else { - // If we are authenticating against an arbiter just ignore it - finalArguments.pop()(null); - } - } - - // Get total count - var count = servers.length; - // Authenticate against all servers - while(servers.length > 0) { - auth(servers.shift()); - } -} - -/** - * Logout from a database - * @method - * @param {string} db The db we are logging out from - * @param {authResultCallback} callback A callback function - */ -ReplSet.prototype.logout = function(dbName, callback) { - var self = this; - // Are we authenticating or logging out, throw - if(this.authenticating) { - throw new MongoError('authentication or logout allready in process'); - } - - // Ensure no new members are processed while logging out - this.authenticating = true; - - // Remove from all auth providers (avoid any reaplication of the auth details) - var providers = Object.keys(this.authProviders); - for(var i = 0; i < providers.length; i++) { - this.authProviders[providers[i]].logout(dbName); - } - - // Now logout all the servers - var servers = this.s.replicaSetState.allServers(); - var count = servers.length; - if(count == 0) return callback(); - var errors = []; - - // Execute logout on all server instances - for(var i = 0; i < servers.length; i++) { - servers[i].logout(dbName, function(err) { - count = count - 1; - if(err) errors.push({name: server.name, err: err}); - - if(count == 0) { - // Do not block new operations - self.authenticating = false; - // If we have one or more errors - if(errors.length) return callback(MongoError.create({ - message: f('logout failed against db %s', dbName), errors: errors - }), false); - - // No errors - callback(); - } - }); - } -} - -/** - * Perform one or more remove operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {{object}|{Long}} cmd Can be either a command returning a cursor or a cursorId - * @param {object} [options.batchSize=0] Batchsize for the operation - * @param {array} [options.documents=[]] Initial documents list for cursor - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -ReplSet.prototype.cursor = function(ns, cmd, cursorOptions) { - cursorOptions = cursorOptions || {}; - var FinalCursor = cursorOptions.cursorFactory || this.s.Cursor; - return new FinalCursor(this.s.bson, ns, cmd, cursorOptions, this, this.s.options); -} - -/** - * A replset connect event, used to verify that the connection is up and running - * - * @event ReplSet#connect - * @type {ReplSet} - */ - -/** - * A replset reconnect event, used to verify that the topology reconnected - * - * @event ReplSet#reconnect - * @type {ReplSet} - */ - -/** - * A replset fullsetup event, used to signal that all topology members have been contacted. - * - * @event ReplSet#fullsetup - * @type {ReplSet} - */ - -/** - * A replset all event, used to signal that all topology members have been contacted. - * - * @event ReplSet#all - * @type {ReplSet} - */ - -/** - * A replset failed event, used to signal that initial replset connection failed. - * - * @event ReplSet#failed - * @type {ReplSet} - */ - -/** - * A server member left the replicaset - * - * @event ReplSet#left - * @type {function} - * @param {string} type The type of member that left (primary|secondary|arbiter) - * @param {Server} server The server object that left - */ - -/** - * A server member joined the replicaset - * - * @event ReplSet#joined - * @type {function} - * @param {string} type The type of member that joined (primary|secondary|arbiter) - * @param {Server} server The server object that joined - */ - -/** - * A server opening SDAM monitoring event - * - * @event ReplSet#serverOpening - * @type {object} - */ - -/** - * A server closed SDAM monitoring event - * - * @event ReplSet#serverClosed - * @type {object} - */ - -/** - * A server description SDAM change monitoring event - * - * @event ReplSet#serverDescriptionChanged - * @type {object} - */ - -/** - * A topology open SDAM event - * - * @event ReplSet#topologyOpening - * @type {object} - */ - -/** - * A topology closed SDAM event - * - * @event ReplSet#topologyClosed - * @type {object} - */ - -/** - * A topology structure SDAM change event - * - * @event ReplSet#topologyDescriptionChanged - * @type {object} - */ - -/** - * A topology serverHeartbeatStarted SDAM event - * - * @event ReplSet#serverHeartbeatStarted - * @type {object} - */ - -/** - * A topology serverHearbeatFailed SDAM event - * - * @event ReplSet#serverHearbeatFailed - * @type {object} - */ - -/** - * A topology serverHeartbeatSucceeded SDAM change event - * - * @event ReplSet#serverHeartbeatSucceeded - * @type {object} - */ - -module.exports = ReplSet; diff --git a/node_modules/mongodb-core/lib/topologies/replset_state.js b/node_modules/mongodb-core/lib/topologies/replset_state.js deleted file mode 100644 index 96249eb..0000000 --- a/node_modules/mongodb-core/lib/topologies/replset_state.js +++ /dev/null @@ -1,812 +0,0 @@ -"use strict" - -var inherits = require('util').inherits, - f = require('util').format, - EventEmitter = require('events').EventEmitter, - Logger = require('../connection/logger'), - ObjectId = require('bson').ObjectId, - ReadPreference = require('./read_preference'), - MongoError = require('../error'); - -var TopologyType = { - 'Single': 'Single', 'ReplicaSetNoPrimary': 'ReplicaSetNoPrimary', - 'ReplicaSetWithPrimary': 'ReplicaSetWithPrimary', 'Sharded': 'Sharded', - 'Unknown': 'Unknown' -}; - -var ServerType = { - 'Standalone': 'Standalone', 'Mongos': 'Mongos', 'PossiblePrimary': 'PossiblePrimary', - 'RSPrimary': 'RSPrimary', 'RSSecondary': 'RSSecondary', 'RSArbiter': 'RSArbiter', - 'RSOther': 'RSOther', 'RSGhost': 'RSGhost', 'Unknown': 'Unknown' -}; - -var ReplSetState = function(options) { - options = options || {}; - // Add event listener - EventEmitter.call(this); - // Topology state - this.topologyType = TopologyType.ReplicaSetNoPrimary; - this.setName = options.setName; - - // Server set - this.set = {}; - - // Unpacked options - this.id = options.id; - this.setName = options.setName; - - // Replicaset logger - this.logger = options.logger || Logger('ReplSet', options); - - // Server selection index - this.index = 0; - // Acceptable latency - this.acceptableLatency = options.acceptableLatency || 15; - - // Server side - this.primary = null; - this.secondaries = []; - this.arbiters = []; - this.passives = []; - this.ghosts = []; - // Current unknown hosts - this.unknownServers = []; - // In set status - this.set = {}; - // Status - this.maxElectionId = null; - this.maxSetVersion = 0; - // Description of the Replicaset - this.replicasetDescription = { - "topologyType": "Unknown", "servers": [] - }; -} - -inherits(ReplSetState, EventEmitter); - -ReplSetState.prototype.hasPrimaryAndSecondary = function(server) { - return this.primary && this.secondaries.length > 0; -} - -ReplSetState.prototype.hasPrimary = function(server) { - return this.primary != null; -} - -ReplSetState.prototype.hasSecondary = function(server) { - return this.secondaries.length > 0; -} - -ReplSetState.prototype.allServers = function(options) { - options = options || {}; - var servers = this.primary ? [this.primary] : []; - servers = servers.concat(this.secondaries); - if(!options.ignoreArbiters) servers = servers.concat(this.arbiters); - servers = servers.concat(this.passives); - return servers; -} - -ReplSetState.prototype.destroy = function() { - // Destroy all sockets - if(this.primary) this.primary.destroy(); - this.secondaries.forEach(function(x) { x.destroy(); }); - this.arbiters.forEach(function(x) { x.destroy(); }); - this.passives.forEach(function(x) { x.destroy(); }); - this.ghosts.forEach(function(x) { x.destroy(); }); - // Clear out the complete state - this.secondaries = []; - this.arbiters = []; - this.passives = []; - this.ghosts = []; - this.unknownServers = []; - this.set = {}; -} - -ReplSetState.prototype.remove = function(server, options) { - options = options || {}; - - // Only remove if the current server is not connected - var servers = this.primary ? [this.primary] : []; - servers = servers.concat(this.secondaries); - servers = servers.concat(this.arbiters); - servers = servers.concat(this.passives); - - // Check if it's active and this is just a failed connection attempt - for(var i = 0; i < servers.length; i++) { - if(!options.force && servers[i].equals(server) && servers[i].isConnected && servers[i].isConnected()) { - return; - } - } - - // If we have it in the set remove it - if(this.set[server.name]) { - this.set[server.name].type = ServerType.Unknown; - this.set[server.name].electionId = null; - this.set[server.name].setName = null; - this.set[server.name].setVersion = null; - } - - // Remove type - var removeType = null; - - // Remove from any lists - if(this.primary && this.primary.equals(server)) { - this.primary = null; - this.topologyType = TopologyType.ReplicaSetNoPrimary; - removeType = 'primary'; - } - - // Remove from any other server lists - removeType = removeFrom(server, this.secondaries) ? 'secondary' : removeType; - removeType = removeFrom(server, this.arbiters) ? 'arbiter' : removeType; - removeType = removeFrom(server, this.passives) ? 'secondary' : removeType; - removeFrom(server, this.ghosts); - removeFrom(server, this.unknownServers); - - // Do we have a removeType - if(removeType) { - this.emit('left', removeType, server); - } -} - -ReplSetState.prototype.update = function(server) { - var self = this; - // Get the current ismaster - var ismaster = server.lastIsMaster(); - - // - // Add any hosts - // - if(ismaster) { - // Join all the possible new hosts - var hosts = Array.isArray(ismaster.hosts) ? ismaster.hosts : []; - hosts = hosts.concat(Array.isArray(ismaster.arbiters) ? ismaster.arbiters : []); - hosts = hosts.concat(Array.isArray(ismaster.passives) ? ismaster.passives : []); - - // Add all hosts as unknownServers - for(var i = 0; i < hosts.length; i++) { - // Add to the list of unknown server - if(this.unknownServers.indexOf(hosts[i]) == -1 - && (!this.set[hosts[i]] || this.set[hosts[i]].type == ServerType.Unknown)) { - this.unknownServers.push(hosts[i]); - } - - if(!this.set[hosts[i]]) { - this.set[hosts[i]] = { - type: ServerType.Unknown, - electionId: null, - setName: null, - setVersion: null - } - } - } - } - - // - // Unknown server - // - if(!ismaster && !inList(ismaster, server, this.unknownServers)) { - self.set[server.name] = { - type: ServerType.Unknown, setVersion: null, electionId: null, setName: null - } - // Update set information about the server instance - self.set[server.name].type = ServerType.Unknown; - self.set[server.name].electionId = ismaster ? ismaster.electionId : ismaster; - self.set[server.name].setName = ismaster ? ismaster.setName : ismaster; - self.set[server.name].setVersion = ismaster ? ismaster.setVersion : ismaster; - - if(self.unknownServers.indexOf(server.name) == -1) { - self.unknownServers.push(server.name); - } - - // Set the topology - return false; - } - - // - // Is this a mongos - // - if(ismaster && ismaster.msg == 'isdbgrid') { - return false; - } - - // A RSOther instance - if((ismaster.setName && ismaster.hidden) - || (ismaster.setName && !ismaster.ismaster && !ismaster.secondary && !ismaster.arbiterOnly && !ismaster.passive)) { - self.set[server.name] = { - type: ServerType.RSOther, setVersion: null, - electionId: null, setName: ismaster.setName - } - // Set the topology - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - return false; - } - - // A RSGhost instance - if(ismaster.isreplicaset) { - self.set[server.name] = { - type: ServerType.RSGhost, setVersion: null, - electionId: null, setName: null - } - - // Set the topology - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - - // Set the topology - return false; - } - - // - // Standalone server, destroy and return - // - if(ismaster && ismaster.ismaster && !ismaster.setName) { - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.Unknown; - this.remove(server, {force:true}); - return false; - } - - // - // Server in maintanance mode - // - if(ismaster && !ismaster.ismaster && !ismaster.secondary && !ismaster.arbiterOnly) { - this.remove(server, {force:true}); - return false; - } - - // - // If the .me field does not match the passed in server - // - if(ismaster.me && ismaster.me != server.name) { - if(this.logger.isWarn()) { - this.logger.warn(f('the seedlist server was removed due to its address %s not matching its ismaster.me address %s', server.name, ismaster.me)); - } - - // Set the type of topology we have - if(this.primary && !this.primary.equals(server)) { - this.topologyType = TopologyType.ReplicaSetWithPrimary; - } else { - this.topologyType = TopologyType.ReplicaSetNoPrimary; - } - - return false; - } - - // - // Primary handling - // - if(!this.primary && ismaster.ismaster && ismaster.setName) { - var ismasterElectionId = server.lastIsMaster().electionId; - if(this.setName && this.setName != ismaster.setName) { - this.topologyType = TopologyType.ReplicaSetNoPrimary; - return new MongoError(f('setName from ismaster does not match provided connection setName [%s] != [%s]', ismaster.setName, this.setName)); - } - - if(!this.maxElectionId && ismasterElectionId) { - this.maxElectionId = ismasterElectionId; - } else if(this.maxElectionId && ismasterElectionId) { - var result = compareObjectIds(this.maxElectionId, ismasterElectionId); - // Get the electionIds - var ismasterSetVersion = server.lastIsMaster().setVersion; - - // if(result == 1 || result == 0) { - if(result == 1) { - this.topologyType = TopologyType.ReplicaSetNoPrimary; - return false; - } else if(result == 0 && ismasterSetVersion) { - if(ismasterSetVersion < this.maxSetVersion) { - this.topologyType = TopologyType.ReplicaSetNoPrimary; - return false; - } - } - - this.maxSetVersion = ismasterSetVersion; - this.maxElectionId = ismasterElectionId; - } - - self.primary = server; - self.set[server.name] = { - type: ServerType.RSPrimary, - setVersion: ismaster.setVersion, - electionId: ismaster.electionId, - setName: ismaster.setName - } - - // Set the topology - this.topologyType = TopologyType.ReplicaSetWithPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - removeFrom(server, self.unknownServers); - removeFrom(server, self.secondaries); - removeFrom(server, self.passives); - self.emit('joined', 'primary', server); - emitTopologyDescriptionChanged(self); - return true; - } else if(ismaster.ismaster && ismaster.setName) { - // Get the electionIds - var currentElectionId = self.set[self.primary.name].electionId; - var currentSetVersion = self.set[self.primary.name].setVersion; - var currentSetName = self.set[self.primary.name].setName; - var ismasterElectionId = server.lastIsMaster().electionId; - var ismasterSetVersion = server.lastIsMaster().setVersion; - var ismasterSetName = server.lastIsMaster().setName; - - // Is it the same server instance - if(this.primary.equals(server) - && currentSetName == ismasterSetName) { - return false; - } - - // If we do not have the same rs name - if(currentSetName && currentSetName != ismasterSetName) { - if(!this.primary.equals(server)) { - this.topologyType = TopologyType.ReplicaSetWithPrimary; - } else { - this.topologyType = TopologyType.ReplicaSetNoPrimary; - } - - return false; - } - - // Check if we need to replace the server - if(currentElectionId && ismasterElectionId) { - var result = compareObjectIds(currentElectionId, ismasterElectionId); - - if(result == 1) { - return false; - } else if(result == 0 && (currentSetVersion > ismasterSetVersion)) { - return false; - } - } else if(!currentElectionId && ismasterElectionId - && ismasterSetVersion) { - if(ismasterSetVersion < this.maxSetVersion) { - return false; - } - } - - if(!this.maxElectionId && ismasterElectionId) { - this.maxElectionId = ismasterElectionId; - } else if(this.maxElectionId && ismasterElectionId) { - var result = compareObjectIds(this.maxElectionId, ismasterElectionId); - - if(result == 1) { - return false; - } else if(result == 0 && currentSetVersion && ismasterSetVersion) { - if(ismasterSetVersion < this.maxSetVersion) { - return false; - } - } else { - if(ismasterSetVersion < this.maxSetVersion) { - return false; - } - } - - this.maxElectionId = ismasterElectionId; - this.maxSetVersion = ismasterSetVersion; - } else { - this.maxSetVersion = ismasterSetVersion; - } - - // Modify the entry to unknown - self.set[self.primary.name] = { - type: ServerType.Unknown, setVersion: null, - electionId: null, setName: null - } - - // Signal primary left - self.emit('left', 'primary', this.primary); - // Destroy the instance - self.primary.destroy(); - // Set the new instance - self.primary = server; - // Set the set information - self.set[server.name] = { - type: ServerType.RSPrimary, setVersion: ismaster.setVersion, - electionId: ismaster.electionId, setName: ismaster.setName - } - - // Set the topology - this.topologyType = TopologyType.ReplicaSetWithPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - removeFrom(server, self.unknownServers); - removeFrom(server, self.secondaries); - removeFrom(server, self.passives); - self.emit('joined', 'primary', server); - emitTopologyDescriptionChanged(self); - return true; - } - - // A possible instance - if(!this.primary && ismaster.primary) { - self.set[ismaster.primary] = { - type: ServerType.PossiblePrimary, setVersion: null, - electionId: null, setName: null - } - } - - // - // Secondary handling - // - if(ismaster.secondary && ismaster.setName - && !inList(ismaster, server, this.secondaries) - && this.setName && this.setName == ismaster.setName) { - addToList(self, ServerType.RSSecondary, ismaster, server, this.secondaries); - // Set the topology - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - removeFrom(server, self.unknownServers); - - // Remove primary - if(this.primary && this.primary.name == server.name) { - server.destroy(); - this.primary = null; - self.emit('left', 'primary', server); - } - - self.emit('joined', 'secondary', server); - emitTopologyDescriptionChanged(self); - return true; - } - - // - // Arbiter handling - // - if(ismaster.arbiterOnly && ismaster.setName - && !inList(ismaster, server, this.arbiters) - && this.setName && this.setName == ismaster.setName) { - addToList(self, ServerType.RSArbiter, ismaster, server, this.arbiters); - // Set the topology - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - removeFrom(server, self.unknownServers); - self.emit('joined', 'arbiter', server); - emitTopologyDescriptionChanged(self); - return true; - } - - // - // Passive handling - // - if(ismaster.passive && ismaster.setName - && !inList(ismaster, server, this.passives) - && this.setName && this.setName == ismaster.setName) { - addToList(self, ServerType.RSSecondary, ismaster, server, this.passives); - // Set the topology - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - if(ismaster.setName) this.setName = ismaster.setName; - removeFrom(server, self.unknownServers); - - // Remove primary - if(this.primary && this.primary.name == server.name) { - server.destroy(); - this.primary = null; - self.emit('left', 'primary', server); - } - - self.emit('joined', 'secondary', server); - emitTopologyDescriptionChanged(self); - return true; - } - - // - // Remove the primary - // - if(this.set[server.name] && this.set[server.name].type == ServerType.RSPrimary) { - self.emit('left', 'primary', this.primary); - this.primary.destroy(); - this.primary = null; - this.topologyType = TopologyType.ReplicaSetNoPrimary; - return false; - } - - this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.ReplicaSetNoPrimary; - return false; -} - -ReplSetState.prototype.pickServer = function(readPreference) { - // If no read Preference set to primary by default - readPreference = readPreference || ReadPreference.primary; - - // Do we have the nearest readPreference - if(readPreference.preference == 'nearest') { - return pickNearest(this, readPreference); - } - - // Get all the secondaries - var secondaries = this.secondaries; - - // Check if we can satisfy and of the basic read Preferences - if(readPreference.equals(ReadPreference.secondary) - && secondaries.length == 0) { - return new MongoError("no secondary server available"); - } - - if(readPreference.equals(ReadPreference.secondaryPreferred) - && secondaries.length == 0 - && this.primary == null) { - return new MongoError("no secondary or primary server available"); - } - - if(readPreference.equals(ReadPreference.primary) - && this.primary == null) { - return new MongoError("no primary server available"); - } - - // Secondary preferred or just secondaries - if(readPreference.equals(ReadPreference.secondaryPreferred) - || readPreference.equals(ReadPreference.secondary)) { - - if(secondaries.length > 0) { - // Apply tags if present - var servers = filterByTags(readPreference, secondaries); - // Pick nearest of any other servers available - var server = pickNearest(this, readPreference); - // No server in the window return primary - if(!server && readPreference.equals(ReadPreference.secondaryPreferred)) { - return this.primary; - } else { - return server; - } - } - - return null; - } - - // Primary preferred - if(readPreference.equals(ReadPreference.primaryPreferred)) { - if(this.primary) return this.primary; - - if(secondaries.length > 0) { - // Apply tags if present - var servers = filterByTags(readPreference, secondaries); - // Pick nearest of any other servers available - return pickNearest(this, readPreference); - } - } - - // Return the primary - return this.primary; -} - -// -// Filter serves by tags -var filterByTags = function(readPreference, servers) { - if(readPreference.tags == null) return servers; - var filteredServers = []; - var tagsArray = Array.isArray(readPreference.tags) ? readPreference.tags : [readPreference.tags]; - - // Iterate over the tags - for(var j = 0; j < tagsArray.length; j++) { - var tags = tagsArray[j]; - - // Iterate over all the servers - for(var i = 0; i < servers.length; i++) { - var serverTag = servers[i].lastIsMaster().tags || {}; - // Did we find the a matching server - var found = true; - // Check if the server is valid - for(var name in tags) { - if(serverTag[name] != tags[name]) found = false; - } - - // Add to candidate list - if(found) { - filteredServers.push(servers[i]); - } - } - - // We found servers by the highest priority - if(found) break; - } - - // Returned filtered servers - return filteredServers; -} - -function pickNearest(self, readPreference) { - // Only get primary and secondaries as seeds - var seeds = {}; - var servers = []; - - // Add primary to list if not a secondary read preference - if(self.primary && readPreference.preference != 'secondary') { - servers.push(self.primary); - } - - // Add all the secondaries - for(var i = 0; i < self.secondaries.length; i++) { - servers.push(self.secondaries[i]); - } - - // Filter by tags - servers = filterByTags(readPreference, servers); - - // Sort by time - servers.sort(function(a, b) { - // return a.time > b.time; - return a.lastIsMasterMS > b.lastIsMasterMS - }); - - // Locate lowest time (picked servers are lowest time + acceptable Latency margin) - var lowest = servers.length > 0 ? servers[0].lastIsMasterMS : 0; - - // Filter by latency - servers = servers.filter(function(s) { - return s.lastIsMasterMS <= lowest + self.acceptableLatency; - }); - - // No servers, default to primary - if(servers.length == 0) { - return null - } - - // Add to the index - self.index = self.index + 1; - // Select the index - self.index = self.index % servers.length; - - // Return the first server of the sorted and filtered list - return servers[self.index]; -} - -function inList(ismaster, server, list) { - for(var i = 0; i < list.length; i++) { - if(list[i].name == server.name) return true; - } - - return false; -} - -function addToList(self, type, ismaster, server, list) { - // Update set information about the server instance - self.set[server.name].type = type; - self.set[server.name].electionId = ismaster ? ismaster.electionId : ismaster; - self.set[server.name].setName = ismaster ? ismaster.setName : ismaster; - self.set[server.name].setVersion = ismaster ? ismaster.setVersion : ismaster; - // Add to the list - list.push(server); -} - -function compareObjectIds(id1, id2) { - var a = new Buffer(id1.toHexString(), 'hex'); - var b = new Buffer(id2.toHexString(), 'hex'); - - if(a === b) { - return 0; - } - - if(typeof Buffer.compare === 'function') { - return Buffer.compare(a, b); - } - - var x = a.length; - var y = b.length; - var len = Math.min(x, y); - - for (var i = 0; i < len; i++) { - if (a[i] !== b[i]) { - break; - } - } - - if (i !== len) { - x = a[i]; - y = b[i]; - } - - return x < y ? -1 : y < x ? 1 : 0; -} - -function removeFrom(server, list) { - for(var i = 0; i < list.length; i++) { - if(list[i].equals && list[i].equals(server)) { - list.splice(i, 1); - return true; - } else if(typeof list[i] == 'string' && list[i] == server.name) { - list.splice(i, 1); - return true; - } - } - - return false; -} - -function emitTopologyDescriptionChanged(self) { - if(self.listeners('topologyDescriptionChanged').length > 0) { - var topology = 'Unknown'; - var setName = self.setName; - - if(self.hasPrimaryAndSecondary()) { - topology = 'ReplicaSetWithPrimary'; - } else if(!self.hasPrimary() && self.hasSecondary()) { - topology = 'ReplicaSetNoPrimary'; - } - - // Generate description - var description = { - topologyType: topology, - setName: setName, - servers: [] - } - - // Add the primary to the list - if(self.hasPrimary()) { - var desc = self.primary.getDescription(); - desc.type = 'RSPrimary'; - description.servers.push(desc); - } - - // Add all the secondaries - description.servers = description.servers.concat(self.secondaries.map(function(x) { - var description = x.getDescription(); - description.type = 'RSSecondary'; - return description; - })); - - // Add all the arbiters - description.servers = description.servers.concat(self.arbiters.map(function(x) { - var description = x.getDescription(); - description.type = 'RSArbiter'; - return description; - })); - - // Add all the passives - description.servers = description.servers.concat(self.passives.map(function(x) { - var description = x.getDescription(); - description.type = 'RSSecondary'; - return description; - })); - - // Create the result - var result = { - topologyId: self.id, - previousDescription: self.replicasetDescription, - newDescription: description, - diff: diff(self.replicasetDescription, description) - }; - - // Emit the topologyDescription change - self.emit('topologyDescriptionChanged', result); - - // Set the new description - self.replicasetDescription = description; - } -} - -function diff(previous, current) { - // Difference document - var diff = { - servers: [] - } - - // Previous entry - if(!previous) { - previous = { servers: [] }; - } - - // Got through all the servers - for(var i = 0; i < previous.servers.length; i++) { - var prevServer = previous.servers[i]; - - // Go through all current servers - for(var j = 0; j < current.servers.length; j++) { - var currServer = current.servers[j]; - - // Matching server - if(prevServer.address === currServer.address) { - // We had a change in state - if(prevServer.type != currServer.type) { - diff.servers.push({ - address: prevServer.address, - from: prevServer.type, - to: currServer.type - }); - } - } - } - } - - // Return difference - return diff; -} - -module.exports = ReplSetState; diff --git a/node_modules/mongodb-core/lib/topologies/server.js b/node_modules/mongodb-core/lib/topologies/server.js deleted file mode 100644 index 6304274..0000000 --- a/node_modules/mongodb-core/lib/topologies/server.js +++ /dev/null @@ -1,805 +0,0 @@ -"use strict" - -var inherits = require('util').inherits, - f = require('util').format, - EventEmitter = require('events').EventEmitter, - BSON = require('bson').native().BSON, - ReadPreference = require('./read_preference'), - Logger = require('../connection/logger'), - debugOptions = require('../connection/utils').debugOptions, - Pool = require('../connection/pool'), - Query = require('../connection/commands').Query, - MongoError = require('../error'), - PreTwoSixWireProtocolSupport = require('../wireprotocol/2_4_support'), - TwoSixWireProtocolSupport = require('../wireprotocol/2_6_support'), - ThreeTwoWireProtocolSupport = require('../wireprotocol/3_2_support'), - BasicCursor = require('../cursor'), - sdam = require('./shared'), - assign = require('./shared').assign; - -// Used for filtering out fields for loggin -var debugFields = ['reconnect', 'reconnectTries', 'reconnectInterval', 'emitError', 'cursorFactory', 'host' - , 'port', 'size', 'keepAlive', 'keepAliveInitialDelay', 'noDelay', 'connectionTimeout', 'checkServerIdentity' - , 'socketTimeout', 'singleBufferSerializtion', 'ssl', 'ca', 'cert', 'key', 'rejectUnauthorized', 'promoteLongs']; - -// Server instance id -var id = 0; -var serverAccounting = false; -var servers = {}; - -/** - * Creates a new Server instance - * @class - * @param {boolean} [options.reconnect=true] Server will attempt to reconnect on loss of connection - * @param {number} [options.reconnectTries=30] Server attempt to reconnect #times - * @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries - * @param {number} [options.monitoring=true] Enable the server state monitoring (calling ismaster at monitoringInterval) - * @param {number} [options.monitoringInterval=5000] The interval of calling ismaster when monitoring is enabled. - * @param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors - * @param {string} options.host The server host - * @param {number} options.port The server port - * @param {number} [options.size=5] Server connection pool size - * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled - * @param {number} [options.keepAliveInitialDelay=0] Initial delay before TCP keep alive enabled - * @param {boolean} [options.noDelay=true] TCP Connection no delay - * @param {number} [options.connectionTimeout=0] TCP Connection timeout setting - * @param {number} [options.socketTimeout=0] TCP Socket timeout setting - * @param {boolean} [options.ssl=false] Use SSL for connection - * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. - * @param {Buffer} [options.ca] SSL Certificate store binary buffer - * @param {Buffer} [options.cert] SSL Certificate binary buffer - * @param {Buffer} [options.key] SSL Key file binary buffer - * @param {string} [options.passphrase] SSL Certificate pass phrase - * @param {boolean} [options.rejectUnauthorized=true] Reject unauthorized server certificates - * @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits - * @return {Server} A cursor instance - * @fires Server#connect - * @fires Server#close - * @fires Server#error - * @fires Server#timeout - * @fires Server#parseError - * @fires Server#reconnect - * @fires Server#reconnectFailed - * @fires Server#serverHeartbeatStarted - * @fires Server#serverHeartbeatSucceeded - * @fires Server#serverHeartbeatFailed - * @fires Server#topologyOpening - * @fires Server#topologyClosed - * @fires Server#topologyDescriptionChanged - */ -var Server = function(options) { - options = options || {}; - - // Add event listener - EventEmitter.call(this); - - // Server instance id - this.id = id++; - - // Reconnect retries - var reconnectTries = options.reconnectTries || 30; - - // Internal state - this.s = { - // Options - options: options, - // Logger - logger: Logger('Server', options), - // Factory overrides - Cursor: options.cursorFactory || BasicCursor, - // BSON instance - bson: options.bson || new BSON(), - // Pool - pool: null, - // Disconnect handler - disconnectHandler: options.disconnectHandler, - // Monitor thread (keeps the connection alive) - monitoring: typeof options.monitoring == 'boolean' ? options.monitoring : true, - // Is the server in a topology - inTopology: typeof options.inTopology == 'boolean' ? options.inTopology : false, - // Monitoring timeout - monitoringInterval: typeof options.monitoringInterval == 'number' - ? options.monitoringInterval - : 5000, - // Topology id - topologyId: -1 - } - - // Curent ismaster - this.ismaster = null; - // Current ping time - this.lastIsMasterMS = -1; - // The monitoringProcessId - this.monitoringProcessId = null; - // Initial connection - this.initalConnect = true; - // Wire protocol handler, default to oldest known protocol handler - // this gets changed when the first ismaster is called. - this.wireProtocolHandler = new PreTwoSixWireProtocolSupport(); - // Default type - this._type = 'server'; -} - -inherits(Server, EventEmitter); - -Object.defineProperty(Server.prototype, 'type', { - enumerable:true, get: function() { return this._type; } -}); - -Server.enableServerAccounting = function() { - serverAccounting = true; - servers = {}; -} - -Server.disableServerAccounting = function() { - serverAccounting = false; -} - -Server.servers = function() { - return servers; -} - -Object.defineProperty(Server.prototype, 'name', { - enumerable:true, - get: function() { return this.s.options.host + ":" + this.s.options.port; } -}); - -function configureWireProtocolHandler(self, ismaster) { - // 3.2 wire protocol handler - if(ismaster.maxWireVersion >= 4) { - return new ThreeTwoWireProtocolSupport(new TwoSixWireProtocolSupport()); - } - - // 2.6 wire protocol handler - if(ismaster.maxWireVersion >= 2) { - return new TwoSixWireProtocolSupport(); - } - - // 2.4 or earlier wire protocol handler - return new PreTwoSixWireProtocolSupport(); -} - -function disconnectHandler(self, type, ns, cmd, options, callback) { - // Topology is not connected, save the call in the provided store to be - // Executed at some point when the handler deems it's reconnected - if(!self.s.pool.isConnected() && self.s.disconnectHandler != null && !options.monitoring) { - self.s.disconnectHandler.add(type, ns, cmd, options, callback); - return true; - } - - // If we have no connection error - if(!self.s.pool.isConnected()) { - callback(MongoError.create(f("no connection available to server %s", self.name))); - return true; - } -} - -function monitoringProcess(self) { - return function() { - // Pool was destroyed do not continue process - if(self.s.pool.isDestroyed()) return; - // Emit monitoring Process event - self.emit('monitoring', self); - // Perform ismaster call - // Query options - var queryOptions = { numberToSkip: 0, numberToReturn: -1, checkKeys: false, slaveOk: true }; - // Create a query instance - var query = new Query(self.s.bson, 'admin.$cmd', {ismaster:true}, queryOptions); - // Get start time - var start = new Date().getTime(); - // Execute the ismaster query - self.s.pool.write(query.toBin(), {}, function(err, result) { - // Set initial lastIsMasterMS - self.lastIsMasterMS = new Date().getTime() - start; - if(self.s.pool.isDestroyed()) return; - // Update the ismaster view if we have a result - if(result) { - self.ismaster = result.result; - // It's a proxy change the type so - // the wireprotocol will send $readPreference - if(self.ismaster.msg == 'isdbgrid') { - self._type = 'mongos'; - } - } - // Re-schedule the monitoring process - self.monitoringProcessId = setTimeout(monitoringProcess(self), self.s.monitoringInterval); - }); - } -} - -var eventHandler = function(self, event) { - return function(err) { - // Log information of received information if in info mode - if(self.s.logger.isInfo()) { - var object = err instanceof MongoError ? JSON.stringify(err) : {} - self.s.logger.info(f('server %s fired event %s out with message %s' - , self.name, event, object)); - } - - // Handle connect event - if(event == 'connect') { - // Issue an ismaster command at connect - // Query options - var queryOptions = { numberToSkip: 0, numberToReturn: -1, checkKeys: false, slaveOk: true }; - // Create a query instance - var query = new Query(self.s.bson, 'admin.$cmd', {ismaster:true}, queryOptions); - // Get start time - var start = new Date().getTime(); - // Execute the ismaster query - self.s.pool.write(query.toBin(), {}, function(err, result) { - // Set initial lastIsMasterMS - self.lastIsMasterMS = new Date().getTime() - start; - if(err) { - self.destroy(); - if(self.listeners('error').length > 0) self.emit('error', err); - return; - } - - // Ensure no error emitted after initial connect when reconnecting - self.initalConnect = false; - // Save the ismaster - self.ismaster = result.result; - // Add the correct wire protocol handler - self.wireProtocolHandler = configureWireProtocolHandler(self, self.ismaster); - // Have we defined self monitoring - if(self.s.monitoring) { - self.monitoringProcessId = setTimeout(monitoringProcess(self), self.s.monitoringInterval); - } - - // Emit server description changed if something listening - sdam.emitServerDescriptionChanged(self, { - address: self.name, arbiters: [], hosts: [], passives: [], type: !self.s.inTopology ? 'Standalone' : sdam.getTopologyType(self) - }); - - // Emit topology description changed if something listening - sdam.emitTopologyDescriptionChanged(self, { - topologyType: 'Single', servers: [{address: self.name, arbiters: [], hosts: [], passives: [], type: 'Standalone'}] - }); - - // Log the ismaster if available - if(self.s.logger.isInfo()) { - self.s.logger.info(f('server %s connected with ismaster [%s]', self.name, JSON.stringify(self.ismaster))); - } - - // Emit connect - self.emit('connect', self); - }); - } else if(event == 'error' || event == 'parseError' - || event == 'close' || event == 'timeout' || event == 'reconnect' - || event == 'attemptReconnect' || 'reconnectFailed') { - - // Remove server instance from accounting - if(serverAccounting && ['close', 'timeout', 'error', 'parseError', 'reconnectFailed'].indexOf(event) != -1) { - // Emit toplogy opening event if not in topology - if(!self.s.inTopology) { - self.emit('topologyOpening', { topologyId: self.id }); - } - - delete servers[self.id]; - } - - // Reconnect failed return error - if(event == 'reconnectFailed') { - self.emit('reconnectFailed', err); - // Emit error if any listeners - if(self.listeners('error').length > 0) { - self.emit('error', err); - } - // Terminate - return; - } - - // On first connect fail - if(self.s.pool.state == 'disconnected' && self.initalConnect && ['close', 'timeout', 'error', 'parseError'].indexOf(event) != -1) { - self.initalConnect = false; - return self.emit('error', new MongoError(f('failed to connect to server [%s] on first connect', self.name))); - } - - // Reconnect event, emit the server - if(event == 'reconnect') { - return self.emit(event, self); - } - - // Emit the event - self.emit(event, err); - } - } -} - -/** - * Initiate server connect - * @method - * @param {array} [options.auth=null] Array of auth options to apply on connect - */ -Server.prototype.connect = function(options) { - var self = this; - options = options || {}; - - // Set the connections - if(serverAccounting) servers[this.id] = this; - - // Do not allow connect to be called on anything that's not disconnected - if(self.s.pool && !self.s.pool.isDisconnected() && !self.s.pool.isDestroyed()) { - throw MongoError.create(f('server instance in invalid state %s', self.s.state)); - } - - // Create a pool - self.s.pool = new Pool(assign(self.s.options, options, {bson: this.s.bson})); - - // Set up listeners - self.s.pool.on('close', eventHandler(self, 'close')); - self.s.pool.on('error', eventHandler(self, 'error')); - self.s.pool.on('timeout', eventHandler(self, 'timeout')); - self.s.pool.on('parseError', eventHandler(self, 'parseError')); - self.s.pool.on('connect', eventHandler(self, 'connect')); - self.s.pool.on('reconnect', eventHandler(self, 'reconnect')); - self.s.pool.on('reconnectFailed', eventHandler(self, 'reconnectFailed')); - - // Emit toplogy opening event if not in topology - if(!self.s.inTopology) { - this.emit('topologyOpening', { topologyId: self.id }); - } - - // Emit opening server event - self.emit('serverOpening', { - topologyId: self.s.topologyId != -1 ? self.s.topologyId : self.id, - address: self.name - }); - - // Connect with optional auth settings - if(options.auth) { - self.s.pool.connect.apply(self.s.pool, options.auth); - } else { - self.s.pool.connect(); - } -} - -/** - * Get the server description - * @method - * @return {object} -*/ -Server.prototype.getDescription = function() { - var ismaster = this.ismaster || {}; - var description = { - type: sdam.getTopologyType(this), - address: this.name, - }; - - // Add fields if available - if(ismaster.hosts) description.hosts = ismaster.hosts; - if(ismaster.arbiters) description.arbiters = ismaster.arbiters; - if(ismaster.passives) description.passives = ismaster.passives; - if(ismaster.setName) description.setName = ismaster.setName; - return description; -} - -/** - * Returns the last known ismaster document for this server - * @method - * @return {object} - */ -Server.prototype.lastIsMaster = function() { - return this.ismaster; -} - -/** - * Unref all connections belong to this server - * @method - */ -Server.prototype.unref = function() { - this.s.pool.unref(); -} - -/** - * Figure out if the server is connected - * @method - * @return {boolean} - */ -Server.prototype.isConnected = function() { - if(!this.s.pool) return false; - return this.s.pool.isConnected(); -} - -/** - * Figure out if the server instance was destroyed by calling destroy - * @method - * @return {boolean} - */ -Server.prototype.isDestroyed = function() { - if(!this.s.pool) return false; - return this.s.pool.isDestroyed(); -} - -function basicWriteValidations(self, options) { - if(!self.s.pool) return MongoError.create('server instance is not connected'); - if(self.s.pool.isDestroyed()) return MongoError.create('server instance pool was destroyed'); -} - -function basicReadValidations(self, options) { - basicWriteValidations(self, options); - - if(options.readPreference && !(options.readPreference instanceof ReadPreference)) { - throw new Error("readPreference must be an instance of ReadPreference"); - } -} - -/** - * Execute a command - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {object} cmd The command hash - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {Boolean} [options.fullResult=false] Return the full envelope instead of just the result document. - * @param {opResultCallback} callback A callback function - */ -Server.prototype.command = function(ns, cmd, options, callback) { - var self = this; - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - var result = basicReadValidations(self, options); - if(result) return callback(result); - - // Debug log - if(self.s.logger.isDebug()) self.s.logger.debug(f('executing command [%s] against %s', JSON.stringify({ - ns: ns, cmd: cmd, options: debugOptions(debugFields, options) - }), self.name)); - - // If we are not connected or have a disconnectHandler specified - if(disconnectHandler(self, 'command', ns, cmd, options, callback)) return; - - // Query options - var queryOptions = { - numberToSkip: 0, - numberToReturn: -1, - checkKeys: typeof options.checkKeys == 'boolean' ? options.checkKeys: false, - serializeFunctions: typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false, - ignoreUndefined: typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : false - }; - - // Create a query instance - var query = new Query(self.s.bson, ns, cmd, queryOptions); - // Set slave OK of the query - query.slaveOk = options.readPreference ? options.readPreference.slaveOk() : false; - - // Write options - var writeOptions = { - raw: typeof options.raw == 'boolean' ? options.raw : false, - promoteLongs: typeof options.promoteLongs == 'boolean' ? options.promoteLongs : true, - command: true, - monitoring: typeof options.monitoring == 'boolean' ? options.monitoring : false, - }; - - // Write the operation to the pool - self.s.pool.write(query.toBin(), writeOptions, callback); -} - -/** - * Insert one or more documents - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of documents to insert - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Server.prototype.insert = function(ns, ops, options, callback) { - var self = this; - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - var result = basicWriteValidations(self, options); - if(result) return callback(result); - - // If we are not connected or have a disconnectHandler specified - if(disconnectHandler(self, 'insert', ns, ops, options, callback)) return; - - // Setup the docs as an array - ops = Array.isArray(ops) ? ops : [ops]; - - // Execute write - return self.wireProtocolHandler.insert(self.s.pool, self.ismaster, ns, self.s.bson, ops, options, callback); -} - -/** - * Perform one or more update operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of updates - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Server.prototype.update = function(ns, ops, options, callback) { - var self = this; - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - var result = basicWriteValidations(self, options); - if(result) return callback(result); - - // If we are not connected or have a disconnectHandler specified - if(disconnectHandler(self, 'update', ns, ops, options, callback)) return; - - // Setup the docs as an array - ops = Array.isArray(ops) ? ops : [ops]; - // Execute write - return self.wireProtocolHandler.update(self.s.pool, self.ismaster, ns, self.s.bson, ops, options, callback); -} - -/** - * Perform one or more remove operations - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {array} ops An array of removes - * @param {boolean} [options.ordered=true] Execute in order or out of order - * @param {object} [options.writeConcern={}] Write concern for the operation - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Server.prototype.remove = function(ns, ops, options, callback) { - var self = this; - if(typeof options == 'function') callback = options, options = {}, options = options || {}; - var result = basicWriteValidations(self, options); - if(result) return callback(result); - - // If we are not connected or have a disconnectHandler specified - if(disconnectHandler(self, 'remove', ns, ops, options, callback)) return; - - // Setup the docs as an array - ops = Array.isArray(ops) ? ops : [ops]; - // Execute write - return self.wireProtocolHandler.remove(self.s.pool, self.ismaster, ns, self.s.bson, ops, options, callback); -} - -/** - * Get a new cursor - * @method - * @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1) - * @param {{object}|{Long}} cmd Can be either a command returning a cursor or a cursorId - * @param {object} [options.batchSize=0] Batchsize for the operation - * @param {array} [options.documents=[]] Initial documents list for cursor - * @param {ReadPreference} [options.readPreference] Specify read preference if command supports it - * @param {Boolean} [options.serializeFunctions=false] Specify if functions on an object should be serialized. - * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. - * @param {opResultCallback} callback A callback function - */ -Server.prototype.cursor = function(ns, cmd, cursorOptions) { - var s = this.s; - cursorOptions = cursorOptions || {}; - // Set up final cursor type - var FinalCursor = cursorOptions.cursorFactory || s.Cursor; - // Return the cursor - return new FinalCursor(s.bson, ns, cmd, cursorOptions, this, s.options); -} - -/** - * Logout from a database - * @method - * @param {string} db The db we are logging out from - * @param {authResultCallback} callback A callback function - */ -Server.prototype.logout = function(dbName, callback) { - this.s.pool.logout(dbName, callback); -} - -/** - * Authenticate using a specified mechanism - * @method - * @param {string} mechanism The Auth mechanism we are invoking - * @param {string} db The db we are invoking the mechanism against - * @param {...object} param Parameters for the specific mechanism - * @param {authResultCallback} callback A callback function - */ -Server.prototype.auth = function(mechanism, db) { - var self = this; - - // If we have the default mechanism we pick mechanism based on the wire - // protocol max version. If it's >= 3 then scram-sha1 otherwise mongodb-cr - if(mechanism == 'default' && self.ismaster && self.ismaster.maxWireVersion >= 3) { - mechanism = 'scram-sha-1'; - } else if(mechanism == 'default') { - mechanism = 'mongocr'; - } - - // Slice all the arguments off - var args = Array.prototype.slice.call(arguments, 0); - // Set the mechanism - args[0] = mechanism; - // Get the callback - var callback = args[args.length - 1]; - - // If we are not connected or have a disconnectHandler specified - //function disconnectHandler(self, type, ns, cmd, options, callback) { - if(disconnectHandler(self, 'auth', db, args, {}, callback)) { - return; - } - - // Do not authenticate if we are an arbiter - if(this.lastIsMaster() && this.lastIsMaster().arbiterOnly) { - return callback(null, true); - } - - // Apply the arguments to the pool - self.s.pool.auth.apply(self.s.pool, args); -} - -/** - * Compare two server instances - * @method - * @param {Server} server Server to compare equality against - * @return {boolean} - */ -Server.prototype.equals = function(server) { - if(typeof server == 'string') return this.name == server; - if(server.name) return this.name == server.name; - return false; -} - -/** - * All raw connections - * @method - * @return {Connection[]} - */ -Server.prototype.connections = function() { - return this.s.pool.allConnections(); -} - -/** - * Get server - * @method - * @return {Server} - */ -Server.prototype.getServer = function() { - return this; -} - -/** - * Get connection - * @method - * @return {Connection} - */ -Server.prototype.getConnection = function() { - return this.s.pool.get(); -} - -var listeners = ['close', 'error', 'timeout', 'parseError', 'connect']; - -/** - * Destroy the server connection - * @method - * @param {boolean} [options.emitClose=false] Emit close event on destroy - * @param {boolean} [options.emitDestroy=false] Emit destroy event on destroy - */ -Server.prototype.destroy = function(options) { - options = options || {}; - var self = this; - - // Set the connections - if(serverAccounting) delete servers[this.id]; - - // Destroy the monitoring process if any - if(this.monitoringProcessId) { - clearTimeout(this.monitoringProcessId); - } - - // Emit close event - if(options.emitClose) { - self.emit('close', self); - } - - // Emit destroy event - if(options.emitDestroy) { - self.emit('destroy', self); - } - - // Remove all listeners - listeners.forEach(function(event) { - self.s.pool.removeAllListeners(event); - }); - - // Emit opening server event - if(self.listeners('serverClosed').length > 0) self.emit('serverClosed', { - topologyId: self.s.topologyId != -1 ? self.s.topologyId : self.id, address: self.name - }); - - // Emit toplogy opening event if not in topology - if(self.listeners('topologyClosed').length > 0 && !self.s.inTopology) { - self.emit('topologyClosed', { topologyId: self.id }); - } - - if(self.s.logger.isDebug()) { - self.s.logger.debug(f('destroy called on server %s', self.name)); - } - - // Destroy the pool - this.s.pool.destroy(); -} - -/** - * A server connect event, used to verify that the connection is up and running - * - * @event Server#connect - * @type {Server} - */ - -/** - * A server reconnect event, used to verify that the server topology has reconnected - * - * @event Server#reconnect - * @type {Server} - */ - -/** - * A server opening SDAM monitoring event - * - * @event Server#serverOpening - * @type {object} - */ - -/** - * A server closed SDAM monitoring event - * - * @event Server#serverClosed - * @type {object} - */ - -/** - * A server description SDAM change monitoring event - * - * @event Server#serverDescriptionChanged - * @type {object} - */ - -/** - * A topology open SDAM event - * - * @event Server#topologyOpening - * @type {object} - */ - -/** - * A topology closed SDAM event - * - * @event Server#topologyClosed - * @type {object} - */ - -/** - * A topology structure SDAM change event - * - * @event Server#topologyDescriptionChanged - * @type {object} - */ - -/** - * Server reconnect failed - * - * @event Server#reconnectFailed - * @type {Error} - */ - -/** - * Server connection pool closed - * - * @event Server#close - * @type {object} - */ - -/** - * Server connection pool caused an error - * - * @event Server#error - * @type {Error} - */ - -/** - * Server destroyed was called - * - * @event Server#destroy - * @type {Server} - */ - -module.exports = Server; diff --git a/node_modules/mongodb-core/lib/topologies/shared.js b/node_modules/mongodb-core/lib/topologies/shared.js deleted file mode 100644 index 902ac98..0000000 --- a/node_modules/mongodb-core/lib/topologies/shared.js +++ /dev/null @@ -1,173 +0,0 @@ -"use strict" - -/** - * Emit event if it exists - * @method - */ -function emitSDAMEvent(self, event, description) { - if(self.listeners(event).length > 0) { - self.emit(event, description); - } -} - -var getPreviousDescription = function(self) { - if(!self.s.serverDescription) { - self.s.serverDescription = { - address: self.name, - arbiters: [], hosts: [], passives: [], type: 'Unknown' - } - } - - return self.s.serverDescription; -} - -var emitServerDescriptionChanged = function(self, description) { - if(self.listeners('serverDescriptionChanged').length > 0) { - // Emit the server description changed events - self.emit('serverDescriptionChanged', { - topologyId: self.s.topologyId != -1 ? self.s.topologyId : self.id, address: self.name, - previousDescription: getPreviousDescription(self), - newDescription: description - }); - - self.s.serverDescription = description; - } -} - -var getPreviousTopologyDescription = function(self) { - if(!self.s.topologyDescription) { - self.s.topologyDescription = { - topologyType: 'Unknown', - servers: [{ - address: self.name, arbiters: [], hosts: [], passives: [], type: 'Unknown' - }] - } - } - - return self.s.topologyDescription; -} - -var emitTopologyDescriptionChanged = function(self, description) { - if(self.listeners('topologyDescriptionChanged').length > 0) { - // Emit the server description changed events - self.emit('topologyDescriptionChanged', { - topologyId: self.s.topologyId != -1 ? self.s.topologyId : self.id, address: self.name, - previousDescription: getPreviousTopologyDescription(self), - newDescription: description - }); - - self.s.serverDescription = description; - } -} - -var changedIsMaster = function(self, currentIsmaster, ismaster) { - var currentType = getTopologyType(self, currentIsmaster); - var newType = getTopologyType(self, ismaster); - if(newType != currentType) return true; - return false; -} - -var getTopologyType = function(self, ismaster) { - if(!ismaster) { - ismaster = self.ismaster; - } - - if(!ismaster) return 'Unknown'; - if(ismaster.ismaster && !ismaster.hosts) return 'Standalone'; - if(ismaster.ismaster && ismaster.msg == 'isdbgrid') return 'Mongos'; - if(ismaster.ismaster) return 'RSPrimary'; - if(ismaster.secondary) return 'RSSecondary'; - if(ismaster.arbiterOnly) return 'RSArbiter'; - return 'Unknown'; -} - -var inquireServerState = function(self) { - return function(callback) { - if(self.s.state == 'destroyed') return; - // Record response time - var start = new Date().getTime(); - - // emitSDAMEvent - emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: self.name }); - - // Attempt to execute ismaster command - self.command('admin.$cmd', { ismaster:true }, { monitoring:true }, function(err, r) { - if(!err) { - // Legacy event sender - self.emit('ismaster', r, self); - - // Calculate latencyMS - var latencyMS = new Date().getTime() - start; - - // Server heart beat event - emitSDAMEvent(self, 'serverHeartbeatSucceeded', { durationMS: latencyMS, reply: r.result, connectionId: self.name }); - - // Did the server change - if(changedIsMaster(self, self.s.ismaster, r.result)) { - // Emit server description changed if something listening - emitServerDescriptionChanged(self, { - address: self.name, arbiters: [], hosts: [], passives: [], type: !self.s.inTopology ? 'Standalone' : getTopologyType(self) - }); - } - - // Updat ismaster view - self.s.ismaster = r.result; - - // Set server response time - self.s.isMasterLatencyMS = latencyMS; - } else { - emitSDAMEvent(self, 'serverHearbeatFailed', { durationMS: latencyMS, failure: err, connectionId: self.name }); - } - - // Peforming an ismaster monitoring callback operation - if(typeof callback == 'function') { - return callback(err, r); - } - - // Perform another sweep - self.s.inquireServerStateTimeout = setTimeout(inquireServerState(self), self.s.haInterval); - }); - }; -} - -// Object.assign method or polyfille -var assign = Object.assign ? Object.assign : function assign(target, firstSource) { - if (target === undefined || target === null) { - throw new TypeError('Cannot convert first argument to object'); - } - - var to = Object(target); - for (var i = 1; i < arguments.length; i++) { - var nextSource = arguments[i]; - if (nextSource === undefined || nextSource === null) { - continue; - } - - var keysArray = Object.keys(Object(nextSource)); - for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { - var nextKey = keysArray[nextIndex]; - var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); - if (desc !== undefined && desc.enumerable) { - to[nextKey] = nextSource[nextKey]; - } - } - } - return to; -} - -// -// Clone the options -var cloneOptions = function(options) { - var opts = {}; - for(var name in options) { - opts[name] = options[name]; - } - return opts; -} - -module.exports.inquireServerState = inquireServerState -module.exports.getTopologyType = getTopologyType; -module.exports.emitServerDescriptionChanged = emitServerDescriptionChanged; -module.exports.emitTopologyDescriptionChanged = emitTopologyDescriptionChanged; -module.exports.cloneOptions = cloneOptions; -module.exports.assign = assign; diff --git a/node_modules/mongodb-core/lib/wireprotocol/2_4_support.js b/node_modules/mongodb-core/lib/wireprotocol/2_4_support.js deleted file mode 100644 index 88c758c..0000000 --- a/node_modules/mongodb-core/lib/wireprotocol/2_4_support.js +++ /dev/null @@ -1,555 +0,0 @@ -"use strict"; - -var Insert = require('./commands').Insert - , Update = require('./commands').Update - , Remove = require('./commands').Remove - , Query = require('../connection/commands').Query - , copy = require('../connection/utils').copy - , KillCursor = require('../connection/commands').KillCursor - , GetMore = require('../connection/commands').GetMore - , Query = require('../connection/commands').Query - , ReadPreference = require('../topologies/read_preference') - , f = require('util').format - , CommandResult = require('../connection/command_result') - , MongoError = require('../error') - , Long = require('bson').Long - , getReadPreference = require('./shared').getReadPreference; - -// Write concern fields -var writeConcernFields = ['w', 'wtimeout', 'j', 'fsync']; - -var WireProtocol = function() {} - -// -// Needs to support legacy mass insert as well as ordered/unordered legacy -// emulation -// -WireProtocol.prototype.insert = function(pool, ismaster, ns, bson, ops, options, callback) { - options = options || {}; - // Default is ordered execution - var ordered = typeof options.ordered == 'boolean' ? options.ordered : true; - var legacy = typeof options.legacy == 'boolean' ? options.legacy : false; - ops = Array.isArray(ops) ? ops :[ops]; - - // If we have more than a 1000 ops fails - if(ops.length > 1000) return callback(new MongoError("exceeded maximum write batch size of 1000")); - - // Write concern - var writeConcern = options.writeConcern || {w:1}; - - // We are unordered - if(!ordered || writeConcern.w == 0) { - return executeUnordered('insert', Insert, ismaster, ns, bson, pool, ops, options, callback); - } - - return executeOrdered('insert', Insert, ismaster, ns, bson, pool, ops, options, callback); -} - -WireProtocol.prototype.update = function(pool, ismaster, ns, bson, ops, options, callback) { - options = options || {}; - // Default is ordered execution - var ordered = typeof options.ordered == 'boolean' ? options.ordered : true; - ops = Array.isArray(ops) ? ops :[ops]; - - // Write concern - var writeConcern = options.writeConcern || {w:1}; - - // We are unordered - if(!ordered || writeConcern.w == 0) { - return executeUnordered('update', Update, ismaster, ns, bson, pool, ops, options, callback); - } - - return executeOrdered('update', Update, ismaster, ns, bson, pool, ops, options, callback); -} - -WireProtocol.prototype.remove = function(pool, ismaster, ns, bson, ops, options, callback) { - options = options || {}; - // Default is ordered execution - var ordered = typeof options.ordered == 'boolean' ? options.ordered : true; - ops = Array.isArray(ops) ? ops :[ops]; - - // Write concern - var writeConcern = options.writeConcern || {w:1}; - - // We are unordered - if(!ordered || writeConcern.w == 0) { - return executeUnordered('remove', Remove, ismaster, ns, bson, pool, ops, options, callback); - } - - return executeOrdered('remove', Remove, ismaster, ns, bson, pool, ops, options, callback); -} - -WireProtocol.prototype.killCursor = function(bson, ns, cursorId, pool, callback) { - // Create a kill cursor command - var killCursor = new KillCursor(bson, [cursorId]); - // Execute the kill cursor command - if(pool && pool.isConnected()) { - pool.write(killCursor.toBin(), { - immediateRelease:true, noResponse: true - }); - } - - // Callback - if(typeof callback == 'function') callback(null, null); -} - -WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, options, callback) { - // Create getMore command - var getMore = new GetMore(bson, ns, cursorState.cursorId, {numberToReturn: batchSize}); - - // Query callback - var queryCallback = function(err, result) { - if(err) return callback(err); - // Get the raw message - var r = result.message; - - // If we have a timed out query or a cursor that was killed - if((r.responseFlags & (1 << 0)) != 0) { - return callback(new MongoError("cursor does not exist, was killed or timed out"), null); - } - - // Ensure we have a Long valie cursor id - var cursorId = typeof r.cursorId == 'number' - ? Long.fromNumber(r.cursorId) - : r.cursorId; - - // Set all the values - cursorState.documents = r.documents; - cursorState.cursorId = cursorId; - - // Return - callback(null, null, r.connection); - } - - // If we have a raw query decorate the function - if(raw) { - queryCallback.raw = raw; - } - - // Check if we need to promote longs - if(typeof cursorState.promoteLongs == 'boolean') { - queryCallback.promoteLongs = cursorState.promoteLongs; - } - - // Write out the getMore command - connection.write(getMore.toBin(), queryCallback); -} - -WireProtocol.prototype.command = function(bson, ns, cmd, cursorState, topology, options) { - // Establish type of command - if(cmd.find) { - return setupClassicFind(bson, ns, cmd, cursorState, topology, options) - } else if(cursorState.cursorId != null) { - } else if(cmd) { - return setupCommand(bson, ns, cmd, cursorState, topology, options); - } else { - throw new MongoError(f("command %s does not return a cursor", JSON.stringify(cmd))); - } -} - -// -// Execute a find command -var setupClassicFind = function(bson, ns, cmd, cursorState, topology, options) { - // Ensure we have at least some options - options = options || {}; - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - // Set the optional batchSize - cursorState.batchSize = cmd.batchSize || cursorState.batchSize; - var numberToReturn = 0; - - // Unpack the limit and batchSize values - if(cursorState.limit == 0) { - numberToReturn = cursorState.batchSize; - } else if(cursorState.limit < 0 || cursorState.limit < cursorState.batchSize || (cursorState.limit > 0 && cursorState.batchSize == 0)) { - numberToReturn = cursorState.limit; - } else { - numberToReturn = cursorState.batchSize; - } - - var numberToSkip = cursorState.skip || 0; - // Build actual find command - var findCmd = {}; - // Using special modifier - var usesSpecialModifier = false; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' && readPreference) { - findCmd['$readPreference'] = readPreference.toJSON(); - usesSpecialModifier = true; - } - - // Add special modifiers to the query - if(cmd.sort) findCmd['orderby'] = cmd.sort, usesSpecialModifier = true; - if(cmd.hint) findCmd['$hint'] = cmd.hint, usesSpecialModifier = true; - if(cmd.snapshot) findCmd['$snapshot'] = cmd.snapshot, usesSpecialModifier = true; - if(cmd.returnKey) findCmd['$returnKey'] = cmd.returnKey, usesSpecialModifier = true; - if(cmd.maxScan) findCmd['$maxScan'] = cmd.maxScan, usesSpecialModifier = true; - if(cmd.min) findCmd['$min'] = cmd.min, usesSpecialModifier = true; - if(cmd.max) findCmd['$max'] = cmd.max, usesSpecialModifier = true; - if(cmd.showDiskLoc) findCmd['$showDiskLoc'] = cmd.showDiskLoc, usesSpecialModifier = true; - if(cmd.comment) findCmd['$comment'] = cmd.comment, usesSpecialModifier = true; - if(cmd.maxTimeMS) findCmd['$maxTimeMS'] = cmd.maxTimeMS, usesSpecialModifier = true; - - if(cmd.explain) { - // nToReturn must be 0 (match all) or negative (match N and close cursor) - // nToReturn > 0 will give explain results equivalent to limit(0) - numberToReturn = -Math.abs(cmd.limit || 0); - usesSpecialModifier = true; - findCmd['$explain'] = true; - } - - // If we have a special modifier - if(usesSpecialModifier) { - findCmd['$query'] = cmd.query; - } else { - findCmd = cmd.query; - } - - // Throw on majority readConcern passed in - if(cmd.readConcern && cmd.readConcern.level != 'local') { - throw new MongoError(f('server find command does not support a readConcern level of %s', cmd.readConcern.level)); - } - - // Remove readConcern, ensure no failing commands - if(cmd.readConcern) { - cmd = copy(cmd); - delete cmd['readConcern']; - } - - // Set up the serialize and ignoreUndefined fields - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // Build Query object - var query = new Query(bson, ns, findCmd, { - numberToSkip: numberToSkip, numberToReturn: numberToReturn - , checkKeys: false, returnFieldSelector: cmd.fields - , serializeFunctions: serializeFunctions, ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Set up the option bits for wire protocol - if(typeof cmd.tailable == 'boolean') query.tailable = cmd.tailable; - if(typeof cmd.oplogReplay == 'boolean') query.oplogReplay = cmd.oplogReplay; - if(typeof cmd.noCursorTimeout == 'boolean') query.noCursorTimeout = cmd.noCursorTimeout; - if(typeof cmd.awaitData == 'boolean') query.awaitData = cmd.awaitData; - if(typeof cmd.partial == 'boolean') query.partial = cmd.partial; - // Return the query - return query; -} - -// -// Set up a command cursor -var setupCommand = function(bson, ns, cmd, cursorState, topology, options) { - // Set empty options object - options = options || {} - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - // Final query - var finalCmd = {}; - for(var name in cmd) { - finalCmd[name] = cmd[name]; - } - - // Build command namespace - var parts = ns.split(/\./); - - // Throw on majority readConcern passed in - if(cmd.readConcern && cmd.readConcern.level != 'local') { - throw new MongoError(f('server %s command does not support a readConcern level of %s', JSON.stringify(cmd), cmd.readConcern.level)); - } - - // Remove readConcern, ensure no failing commands - if(cmd.readConcern) delete cmd['readConcern']; - - // Serialize functions - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - - // Set up the serialize and ignoreUndefined fields - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' - && readPreference - && readPreference.preference != 'primary') { - finalCmd = { - '$query': finalCmd, - '$readPreference': readPreference.toJSON() - }; - } - - // Build Query object - var query = new Query(bson, f('%s.$cmd', parts.shift()), finalCmd, { - numberToSkip: 0, numberToReturn: -1 - , checkKeys: false, serializeFunctions: serializeFunctions - , ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Return the query - return query; -} - -var hasWriteConcern = function(writeConcern) { - if(writeConcern.w - || writeConcern.wtimeout - || writeConcern.j == true - || writeConcern.fsync == true - || Object.keys(writeConcern).length == 0) { - return true; - } - return false; -} - -var cloneWriteConcern = function(writeConcern) { - var wc = {}; - if(writeConcern.w != null) wc.w = writeConcern.w; - if(writeConcern.wtimeout != null) wc.wtimeout = writeConcern.wtimeout; - if(writeConcern.j != null) wc.j = writeConcern.j; - if(writeConcern.fsync != null) wc.fsync = writeConcern.fsync; - return wc; -} - -// -// Aggregate up all the results -// -var aggregateWriteOperationResults = function(opType, ops, results, connection) { - var finalResult = { ok: 1, n: 0 } - - // Map all the results coming back - for(var i = 0; i < results.length; i++) { - var result = results[i]; - var op = ops[i]; - - if((result.upserted || (result.updatedExisting == false)) && finalResult.upserted == null) { - finalResult.upserted = []; - } - - // Push the upserted document to the list of upserted values - if(result.upserted) { - finalResult.upserted.push({index: i, _id: result.upserted}); - } - - // We have an upsert where we passed in a _id - if(result.updatedExisting == false && result.n == 1 && result.upserted == null) { - finalResult.upserted.push({index: i, _id: op.q._id}); - } - - // We have an insert command - if(result.ok == 1 && opType == 'insert' && result.err == null) { - finalResult.n = finalResult.n + 1; - } - - // We have a command error - if(result != null && result.ok == 0 || result.err || result.errmsg) { - if(result.ok == 0) finalResult.ok = 0; - finalResult.code = result.code; - finalResult.errmsg = result.errmsg || result.err || result.errMsg; - - // Check if we have a write error - if(result.code == 11000 - || result.code == 11001 - || result.code == 12582 - || result.code == 16544 - || result.code == 16538 - || result.code == 16542 - || result.code == 14 - || result.code == 13511) { - if(finalResult.writeErrors == null) finalResult.writeErrors = []; - finalResult.writeErrors.push({ - index: i - , code: result.code - , errmsg: result.errmsg || result.err || result.errMsg - }); - } else { - finalResult.writeConcernError = { - code: result.code - , errmsg: result.errmsg || result.err || result.errMsg - } - } - } else if(typeof result.n == 'number') { - finalResult.n += result.n; - } else { - finalResult.n += 1; - } - - // Result as expected - if(result != null && result.lastOp) finalResult.lastOp = result.lastOp; - } - - // Return finalResult aggregated results - return new CommandResult(finalResult, connection); -} - -// -// Execute all inserts in an ordered manner -// -var executeOrdered = function(opType ,command, ismaster, ns, bson, pool, ops, options, callback) { - var _ops = ops.slice(0); - // Collect all the getLastErrors - var getLastErrors = []; - // Execute an operation - var executeOp = function(list, _callback) { - // No more items in the list - if(list.length == 0) { - return process.nextTick(function() { - _callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, null)); - }); - } - - // Get the first operation - var doc = list.shift(); - // Create an insert command - var op = new command(Query.getRequestId(), ismaster, bson, ns, [doc], options); - // Write concern - var optionWriteConcern = options.writeConcern || {w:1}; - // Final write concern - var writeConcern = cloneWriteConcern(optionWriteConcern); - - // Get the db name - var db = ns.split('.').shift(); - - try { - // Add binary message to list of commands to execute - var commands = [op.toBin()]; - - // Add getLastOrdered - var getLastErrorCmd = {getlasterror: 1}; - // Merge all the fields - for(var i = 0; i < writeConcernFields.length; i++) { - if(writeConcern[writeConcernFields[i]] != null) { - getLastErrorCmd[writeConcernFields[i]] = writeConcern[writeConcernFields[i]]; - } - } - - // Create a getLastError command - var getLastErrorOp = new Query(bson, f("%s.$cmd", db), getLastErrorCmd, {numberToReturn: -1}); - // Add getLastError command to list of ops to execute - commands.push(getLastErrorOp.toBin()); - - // getLastError callback - var getLastErrorCallback = function(err, result) { - if(err) return callback(err); - // Get the document - var doc = result.result; - // Save the getLastError document - getLastErrors.push(doc); - - // If we have an error terminate - if(doc.ok == 0 || doc.err || doc.errmsg) { - return callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, result.connection)); - } - - // Execute the next op in the list - executeOp(list, callback); - } - - // Write both commands out at the same time - pool.write(commands, getLastErrorCallback); - } catch(err) { - if(typeof err == 'string') err = new MongoError(err); - // We have a serialization error, rewrite as a write error to have same behavior as modern - // write commands - getLastErrors.push({ ok: 1, errmsg: err.message, code: 14 }); - // Return due to an error - process.nextTick(function() { - _callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, null)); - }); - } - } - - // Execute the operations - executeOp(_ops, callback); -} - -var executeUnordered = function(opType, command, ismaster, ns, bson, pool, ops, options, callback) { - // Total operations to write - var totalOps = ops.length; - // Collect all the getLastErrors - var getLastErrors = []; - // Write concern - var optionWriteConcern = options.writeConcern || {w:1}; - // Final write concern - var writeConcern = cloneWriteConcern(optionWriteConcern); - // Driver level error - var error; - - // Execute all the operations - for(var i = 0; i < ops.length; i++) { - // Create an insert command - var op = new command(Query.getRequestId(), ismaster, bson, ns, [ops[i]], options); - // Get db name - var db = ns.split('.').shift(); - - try { - // Add binary message to list of commands to execute - var commands = [op.toBin()]; - - // If write concern 0 don't fire getLastError - if(hasWriteConcern(writeConcern)) { - var getLastErrorCmd = {getlasterror: 1}; - // Merge all the fields - for(var j = 0; j < writeConcernFields.length; j++) { - if(writeConcern[writeConcernFields[j]] != null) - getLastErrorCmd[writeConcernFields[j]] = writeConcern[writeConcernFields[j]]; - } - - // Create a getLastError command - var getLastErrorOp = new Query(bson, f("%s.$cmd", db), getLastErrorCmd, {numberToReturn: -1}); - // Add getLastError command to list of ops to execute - commands.push(getLastErrorOp.toBin()); - - // Give the result from getLastError the right index - var callbackOp = function(_index) { - return function(err, result) { - if(err) error = err; - // Update the number of operations executed - totalOps = totalOps - 1; - // Save the getLastError document - if(!err) getLastErrors[_index] = result.result; - // Check if we are done - if(totalOps == 0) { - process.nextTick(function() { - if(error) return callback(error); - callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, result.connection)); - }); - } - } - } - - // Write both commands out at the same time - pool.write(commands, callbackOp(i)); - } else { - pool.write(commands, {immediateRelease:true, noResponse:true}); - } - } catch(err) { - if(typeof err == 'string') err = new MongoError(err); - // Update the number of operations executed - totalOps = totalOps - 1; - // We have a serialization error, rewrite as a write error to have same behavior as modern - // write commands - getLastErrors[i] = { ok: 1, errmsg: err.message, code: 14 }; - // Check if we are done - if(totalOps == 0) { - callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, null)); - } - } - } - - // Empty w:0 return - if(writeConcern - && writeConcern.w == 0 && callback) { - callback(null, new CommandResult({ok:1}, null)); - } -} - -module.exports = WireProtocol; diff --git a/node_modules/mongodb-core/lib/wireprotocol/2_6_support.js b/node_modules/mongodb-core/lib/wireprotocol/2_6_support.js deleted file mode 100644 index 0349dc6..0000000 --- a/node_modules/mongodb-core/lib/wireprotocol/2_6_support.js +++ /dev/null @@ -1,324 +0,0 @@ -"use strict"; - -var Insert = require('./commands').Insert - , Update = require('./commands').Update - , Remove = require('./commands').Remove - , Query = require('../connection/commands').Query - , copy = require('../connection/utils').copy - , KillCursor = require('../connection/commands').KillCursor - , GetMore = require('../connection/commands').GetMore - , Query = require('../connection/commands').Query - , ReadPreference = require('../topologies/read_preference') - , f = require('util').format - , CommandResult = require('../connection/command_result') - , MongoError = require('../error') - , Long = require('bson').Long - , getReadPreference = require('./shared').getReadPreference; - -var WireProtocol = function() {} - -// -// Execute a write operation -var executeWrite = function(pool, bson, type, opsField, ns, ops, options, callback) { - if(ops.length == 0) throw new MongoError("insert must contain at least one document"); - if(typeof options == 'function') { - callback = options; - options = {}; - options = options || {}; - } - - // Split the ns up to get db and collection - var p = ns.split("."); - var d = p.shift(); - // Options - var ordered = typeof options.ordered == 'boolean' ? options.ordered : true; - var writeConcern = options.writeConcern; - - // return skeleton - var writeCommand = {}; - writeCommand[type] = p.join('.'); - writeCommand[opsField] = ops; - writeCommand.ordered = ordered; - - // Did we specify a write concern - if(writeConcern && Object.keys(writeConcern).length > 0) { - writeCommand.writeConcern = writeConcern; - } - - // Do we have bypassDocumentValidation set, then enable it on the write command - if(typeof options.bypassDocumentValidation == 'boolean') { - writeCommand.bypassDocumentValidation = options.bypassDocumentValidation; - } - - // Options object - var opts = { command: true }; - var queryOptions = { checkKeys : false, numberToSkip: 0, numberToReturn: 1 }; - if(type == 'insert') queryOptions.checkKeys = true; - // Ensure we support serialization of functions - if(options.serializeFunctions) queryOptions.serializeFunctions = options.serializeFunctions; - // Do not serialize the undefined fields - if(options.ignoreUndefined) queryOptions.ignoreUndefined = options.ignoreUndefined; - - try { - // Create write command - var cmd = new Query(bson, f("%s.$cmd", d), writeCommand, queryOptions); - // Execute command - pool.write(cmd.toBin(), opts, callback); - } catch(err) { - callback(err); - } -} - -// -// Needs to support legacy mass insert as well as ordered/unordered legacy -// emulation -// -WireProtocol.prototype.insert = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'insert', 'documents', ns, ops, options, callback); -} - -WireProtocol.prototype.update = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'update', 'updates', ns, ops, options, callback); -} - -WireProtocol.prototype.remove = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'delete', 'deletes', ns, ops, options, callback); -} - -WireProtocol.prototype.killCursor = function(bson, ns, cursorId, pool, callback) { - // Create a kill cursor command - var killCursor = new KillCursor(bson, [cursorId]); - // Execute the kill cursor command - if(pool && pool.isConnected()) { - pool.write(killCursor.toBin(), { - immediateRelease:true, noResponse: true - }); - } - - // Callback - if(typeof callback == 'function') callback(null, null); -} - -WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, options, callback) { - // Create getMore command - var getMore = new GetMore(bson, ns, cursorState.cursorId, {numberToReturn: batchSize}); - - // Query callback - var queryCallback = function(err, result) { - if(err) return callback(err); - // Get the raw message - var r = result.message; - - // If we have a timed out query or a cursor that was killed - if((r.responseFlags & (1 << 0)) != 0) { - return callback(new MongoError("cursor does not exist, was killed or timed out"), null); - } - - // Ensure we have a Long valie cursor id - var cursorId = typeof r.cursorId == 'number' - ? Long.fromNumber(r.cursorId) - : r.cursorId; - - // Set all the values - cursorState.documents = r.documents; - cursorState.cursorId = cursorId; - - // Return - callback(null, null, r.connection); - } - - // If we have a raw query decorate the function - if(raw) { - queryCallback.raw = raw; - } - - // Check if we need to promote longs - if(typeof cursorState.promoteLongs == 'boolean') { - queryCallback.promoteLongs = cursorState.promoteLongs; - } - - // Write out the getMore command - connection.write(getMore.toBin(), queryCallback); -} - -WireProtocol.prototype.command = function(bson, ns, cmd, cursorState, topology, options) { - // Establish type of command - if(cmd.find) { - return setupClassicFind(bson, ns, cmd, cursorState, topology, options) - } else if(cursorState.cursorId != null) { - } else if(cmd) { - return setupCommand(bson, ns, cmd, cursorState, topology, options); - } else { - throw new MongoError(f("command %s does not return a cursor", JSON.stringify(cmd))); - } -} - -// -// Execute a find command -var setupClassicFind = function(bson, ns, cmd, cursorState, topology, options) { - // Ensure we have at least some options - options = options || {}; - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - // Set the optional batchSize - cursorState.batchSize = cmd.batchSize || cursorState.batchSize; - var numberToReturn = 0; - - // Unpack the limit and batchSize values - if(cursorState.limit == 0) { - numberToReturn = cursorState.batchSize; - } else if(cursorState.limit < 0 || cursorState.limit < cursorState.batchSize || (cursorState.limit > 0 && cursorState.batchSize == 0)) { - numberToReturn = cursorState.limit; - } else { - numberToReturn = cursorState.batchSize; - } - - var numberToSkip = cursorState.skip || 0; - // Build actual find command - var findCmd = {}; - // Using special modifier - var usesSpecialModifier = false; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' && readPreference) { - findCmd['$readPreference'] = readPreference.toJSON(); - usesSpecialModifier = true; - } - - // Add special modifiers to the query - if(cmd.sort) findCmd['orderby'] = cmd.sort, usesSpecialModifier = true; - if(cmd.hint) findCmd['$hint'] = cmd.hint, usesSpecialModifier = true; - if(cmd.snapshot) findCmd['$snapshot'] = cmd.snapshot, usesSpecialModifier = true; - if(cmd.returnKey) findCmd['$returnKey'] = cmd.returnKey, usesSpecialModifier = true; - if(cmd.maxScan) findCmd['$maxScan'] = cmd.maxScan, usesSpecialModifier = true; - if(cmd.min) findCmd['$min'] = cmd.min, usesSpecialModifier = true; - if(cmd.max) findCmd['$max'] = cmd.max, usesSpecialModifier = true; - if(cmd.showDiskLoc) findCmd['$showDiskLoc'] = cmd.showDiskLoc, usesSpecialModifier = true; - if(cmd.comment) findCmd['$comment'] = cmd.comment, usesSpecialModifier = true; - if(cmd.maxTimeMS) findCmd['$maxTimeMS'] = cmd.maxTimeMS, usesSpecialModifier = true; - - if(cmd.explain) { - // nToReturn must be 0 (match all) or negative (match N and close cursor) - // nToReturn > 0 will give explain results equivalent to limit(0) - numberToReturn = -Math.abs(cmd.limit || 0); - usesSpecialModifier = true; - findCmd['$explain'] = true; - } - - // If we have a special modifier - if(usesSpecialModifier) { - findCmd['$query'] = cmd.query; - } else { - findCmd = cmd.query; - } - - // Throw on majority readConcern passed in - if(cmd.readConcern && cmd.readConcern.level != 'local') { - throw new MongoError(f('server find command does not support a readConcern level of %s', cmd.readConcern.level)); - } - - // Remove readConcern, ensure no failing commands - if(cmd.readConcern) { - cmd = copy(cmd); - delete cmd['readConcern']; - } - - // Serialize functions - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // Build Query object - var query = new Query(bson, ns, findCmd, { - numberToSkip: numberToSkip, numberToReturn: numberToReturn - , checkKeys: false, returnFieldSelector: cmd.fields - , serializeFunctions: serializeFunctions - , ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Set up the option bits for wire protocol - if(typeof cmd.tailable == 'boolean') { - query.tailable = cmd.tailable; - } - - if(typeof cmd.oplogReplay == 'boolean') { - query.oplogReplay = cmd.oplogReplay; - } - - if(typeof cmd.noCursorTimeout == 'boolean') { - query.noCursorTimeout = cmd.noCursorTimeout; - } - - if(typeof cmd.awaitData == 'boolean') { - query.awaitData = cmd.awaitData; - } - - if(typeof cmd.partial == 'boolean') { - query.partial = cmd.partial; - } - - // Return the query - return query; -} - -// -// Set up a command cursor -var setupCommand = function(bson, ns, cmd, cursorState, topology, options) { - // Set empty options object - options = options || {} - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - - // Final query - var finalCmd = {}; - for(var name in cmd) { - finalCmd[name] = cmd[name]; - } - - // Build command namespace - var parts = ns.split(/\./); - - // Serialize functions - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // Throw on majority readConcern passed in - if(cmd.readConcern && cmd.readConcern.level != 'local') { - throw new MongoError(f('server %s command does not support a readConcern level of %s', JSON.stringify(cmd), cmd.readConcern.level)); - } - - // Remove readConcern, ensure no failing commands - if(cmd.readConcern) delete cmd['readConcern']; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' - && readPreference - && readPreference.preference != 'primary') { - finalCmd = { - '$query': finalCmd, - '$readPreference': readPreference.toJSON() - }; - } - - // Build Query object - var query = new Query(bson, f('%s.$cmd', parts.shift()), finalCmd, { - numberToSkip: 0, numberToReturn: -1 - , checkKeys: false, serializeFunctions: serializeFunctions - , ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Return the query - return query; -} - -module.exports = WireProtocol; diff --git a/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js b/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js deleted file mode 100644 index dc919e1..0000000 --- a/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js +++ /dev/null @@ -1,520 +0,0 @@ -"use strict"; - -var Insert = require('./commands').Insert - , Update = require('./commands').Update - , Remove = require('./commands').Remove - , Query = require('../connection/commands').Query - , copy = require('../connection/utils').copy - , KillCursor = require('../connection/commands').KillCursor - , GetMore = require('../connection/commands').GetMore - , Query = require('../connection/commands').Query - , ReadPreference = require('../topologies/read_preference') - , f = require('util').format - , CommandResult = require('../connection/command_result') - , MongoError = require('../error') - , Long = require('bson').Long - , getReadPreference = require('./shared').getReadPreference; - -var WireProtocol = function(legacyWireProtocol) { - this.legacyWireProtocol = legacyWireProtocol; -} - -// -// Execute a write operation -var executeWrite = function(pool, bson, type, opsField, ns, ops, options, callback) { - if(ops.length == 0) throw new MongoError("insert must contain at least one document"); - if(typeof options == 'function') { - callback = options; - options = {}; - options = options || {}; - } - - // Split the ns up to get db and collection - var p = ns.split("."); - var d = p.shift(); - // Options - var ordered = typeof options.ordered == 'boolean' ? options.ordered : true; - var writeConcern = options.writeConcern; - - // return skeleton - var writeCommand = {}; - writeCommand[type] = p.join('.'); - writeCommand[opsField] = ops; - writeCommand.ordered = ordered; - - // Did we specify a write concern - if(writeConcern && Object.keys(writeConcern).length > 0) { - writeCommand.writeConcern = writeConcern; - } - - // Do we have bypassDocumentValidation set, then enable it on the write command - if(typeof options.bypassDocumentValidation == 'boolean') { - writeCommand.bypassDocumentValidation = options.bypassDocumentValidation; - } - - // Options object - var opts = { command: true }; - var queryOptions = { checkKeys : false, numberToSkip: 0, numberToReturn: 1 }; - if(type == 'insert') queryOptions.checkKeys = true; - - // Ensure we support serialization of functions - if(options.serializeFunctions) queryOptions.serializeFunctions = options.serializeFunctions; - // Do not serialize the undefined fields - if(options.ignoreUndefined) queryOptions.ignoreUndefined = options.ignoreUndefined; - - try { - // Create write command - var cmd = new Query(bson, f("%s.$cmd", d), writeCommand, queryOptions); - // Execute command - pool.write(cmd.toBin(), opts, callback); - } catch(err) { - callback(err); - } -} - -// -// Needs to support legacy mass insert as well as ordered/unordered legacy -// emulation -// -WireProtocol.prototype.insert = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'insert', 'documents', ns, ops, options, callback); -} - -WireProtocol.prototype.update = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'update', 'updates', ns, ops, options, callback); -} - -WireProtocol.prototype.remove = function(pool, ismaster, ns, bson, ops, options, callback) { - executeWrite(pool, bson, 'delete', 'deletes', ns, ops, options, callback); -} - -WireProtocol.prototype.killCursor = function(bson, ns, cursorId, pool, callback) { - // Build command namespace - var parts = ns.split(/\./); - // Command namespace - var commandns = f('%s.$cmd', parts.shift()); - // Create getMore command - var killcursorCmd = { - killCursors: parts.join('.'), - cursors: [cursorId] - } - - // Build Query object - var query = new Query(bson, commandns, killcursorCmd, { - numberToSkip: 0, numberToReturn: -1 - , checkKeys: false, returnFieldSelector: null - }); - - // Set query flags - query.slaveOk = true; - - // Kill cursor callback - var killCursorCallback = function(err, result) { - if(err) { - if(typeof callback != 'function') return; - return callback(err); - } - - // Result - var r = result.message; - // If we have a timed out query or a cursor that was killed - if((r.responseFlags & (1 << 0)) != 0) { - if(typeof callback != 'function') return; - return callback(new MongoError("cursor killed or timed out"), null); - } - - if(!Array.isArray(r.documents) || r.documents.length == 0) { - if(typeof callback != 'function') return; - return callback(new MongoError(f('invalid killCursors result returned for cursor id %s', cursorState.cursorId))); - } - - // Return the result - if(typeof callback == 'function') { - callback(null, r.documents[0]); - } - } - - // Execute the kill cursor command - if(pool && pool.isConnected()) { - pool.write(query.toBin(), { command: true }, killCursorCallback); - } -} - -WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, options, callback) { - options = options || {}; - // Build command namespace - var parts = ns.split(/\./); - // Command namespace - var commandns = f('%s.$cmd', parts.shift()); - - // Check if we have an maxTimeMS set - var maxTimeMS = typeof cursorState.cmd.maxTimeMS == 'number' ? cursorState.cmd.maxTimeMS : 3000; - - // Create getMore command - var getMoreCmd = { - getMore: cursorState.cursorId, - collection: parts.join('.'), - batchSize: Math.abs(batchSize) - } - - if(cursorState.cmd.tailable - && typeof cursorState.cmd.maxAwaitTimeMS == 'number') { - getMoreCmd.maxTimeMS = cursorState.cmd.maxAwaitTimeMS; - } - - // Build Query object - var query = new Query(bson, commandns, getMoreCmd, { - numberToSkip: 0, numberToReturn: -1 - , checkKeys: false, returnFieldSelector: null - }); - - // Set query flags - query.slaveOk = true; - - // Query callback - var queryCallback = function(err, result) { - if(err) return callback(err); - // Get the raw message - var r = result.message; - - // If we have a timed out query or a cursor that was killed - if((r.responseFlags & (1 << 0)) != 0) { - return callback(new MongoError("cursor killed or timed out"), null); - } - - // Raw, return all the extracted documents - if(raw) { - cursorState.documents = r.documents; - cursorState.cursorId = r.cursorId; - return callback(null, r.documents); - } - - // We have an error detected - if(r.documents[0].ok == 0) { - return callback(MongoError.create(r.documents[0])); - } - - // Ensure we have a Long valid cursor id - var cursorId = typeof r.documents[0].cursor.id == 'number' - ? Long.fromNumber(r.documents[0].cursor.id) - : r.documents[0].cursor.id; - - // Set all the values - cursorState.documents = r.documents[0].cursor.nextBatch; - cursorState.cursorId = cursorId; - - // Return the result - callback(null, r.documents[0], r.connection); - } - - // Query options - var queryOptions = { command: true }; - - // If we have a raw query decorate the function - if(raw) { - queryOptions.raw = raw; - } - - // Add the result field needed - queryOptions.documentsReturnedIn = 'nextBatch'; - - // Check if we need to promote longs - if(typeof cursorState.promoteLongs == 'boolean') { - queryOptions.promoteLongs = cursorState.promoteLongs; - } - - // Write out the getMore command - connection.write(query.toBin(), queryOptions, queryCallback); - global.debug = true -} - -WireProtocol.prototype.command = function(bson, ns, cmd, cursorState, topology, options) { - // Establish type of command - if(cmd.find) { - // Create the find command - var query = executeFindCommand(bson, ns, cmd, cursorState, topology, options) - // Mark the cmd as virtual - cmd.virtual = false; - // Signal the documents are in the firstBatch value - query.documentsReturnedIn = 'firstBatch'; - // Return the query - return query; - } else if(cursorState.cursorId != null) { - } else if(cmd) { - return setupCommand(bson, ns, cmd, cursorState, topology, options); - } else { - throw new MongoError(f("command %s does not return a cursor", JSON.stringify(cmd))); - } -} - -// // Command -// { -// find: ns -// , query: <object> -// , limit: <n> -// , fields: <object> -// , skip: <n> -// , hint: <string> -// , explain: <boolean> -// , snapshot: <boolean> -// , batchSize: <n> -// , returnKey: <boolean> -// , maxScan: <n> -// , min: <n> -// , max: <n> -// , showDiskLoc: <boolean> -// , comment: <string> -// , maxTimeMS: <n> -// , raw: <boolean> -// , readPreference: <ReadPreference> -// , tailable: <boolean> -// , oplogReplay: <boolean> -// , noCursorTimeout: <boolean> -// , awaitdata: <boolean> -// , exhaust: <boolean> -// , partial: <boolean> -// } - -// FIND/GETMORE SPEC -// { -// “find”: <string>, -// “filter”: { ... }, -// “sort”: { ... }, -// “projection”: { ... }, -// “hint”: { ... }, -// “skip”: <int>, -// “limit”: <int>, -// “batchSize”: <int>, -// “singleBatch”: <bool>, -// “comment”: <string>, -// “maxScan”: <int>, -// “maxTimeMS”: <int>, -// “max”: { ... }, -// “min”: { ... }, -// “returnKey”: <bool>, -// “showRecordId”: <bool>, -// “snapshot”: <bool>, -// “tailable”: <bool>, -// “oplogReplay”: <bool>, -// “noCursorTimeout”: <bool>, -// “awaitData”: <bool>, -// “partial”: <bool>, -// “$readPreference”: { ... } -// } - -// -// Execute a find command -var executeFindCommand = function(bson, ns, cmd, cursorState, topology, options) { - // Ensure we have at least some options - options = options || {}; - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - // Set the optional batchSize - cursorState.batchSize = cmd.batchSize || cursorState.batchSize; - - // Build command namespace - var parts = ns.split(/\./); - // Command namespace - var commandns = f('%s.$cmd', parts.shift()); - - // Build actual find command - var findCmd = { - find: parts.join('.') - }; - - // I we provided a filter - if(cmd.query) { - // Check if the user is passing in the $query parameter - if(cmd.query['$query']) { - findCmd.filter = cmd.query['$query']; - } else { - findCmd.filter = cmd.query; - } - } - - // Sort value - var sortValue = cmd.sort; - - // Handle issue of sort being an Array - if(Array.isArray(sortValue)) { - var sortObject = {}; - - if(sortValue.length > 0 && !Array.isArray(sortValue[0])) { - var sortDirection = sortValue[1]; - // Translate the sort order text - if(sortDirection == 'asc') { - sortDirection = 1; - } else if(sortDirection == 'desc') { - sortDirection = -1; - } - - // Set the sort order - sortObject[sortValue[0]] = sortDirection; - } else { - for(var i = 0; i < sortValue.length; i++) { - var sortDirection = sortValue[i][1]; - // Translate the sort order text - if(sortDirection == 'asc') { - sortDirection = 1; - } else if(sortDirection == 'desc') { - sortDirection = -1; - } - - // Set the sort order - sortObject[sortValue[i][0]] = sortDirection; - } - } - - sortValue = sortObject; - }; - - // Add sort to command - if(cmd.sort) findCmd.sort = sortValue; - // Add a projection to the command - if(cmd.fields) findCmd.projection = cmd.fields; - // Add a hint to the command - if(cmd.hint) findCmd.hint = cmd.hint; - // Add a skip - if(cmd.skip) findCmd.skip = cmd.skip; - // Add a limit - if(cmd.limit) findCmd.limit = cmd.limit; - // Add a batchSize - if(typeof cmd.batchSize == 'number') findCmd.batchSize = Math.abs(cmd.batchSize); - - // Check if we wish to have a singleBatch - if(cmd.limit < 0) { - findCmd.limit = Math.abs(cmd.limit); - findCmd.singleBatch = true; - } - - // If we have comment set - if(cmd.comment) findCmd.comment = cmd.comment; - - // If we have maxScan - if(cmd.maxScan) findCmd.maxScan = cmd.maxScan; - - // If we have maxTimeMS set - if(cmd.maxTimeMS) findCmd.maxTimeMS = cmd.maxTimeMS; - - // If we have min - if(cmd.min) findCmd.min = cmd.min; - - // If we have max - if(cmd.max) findCmd.max = cmd.max; - - // If we have returnKey set - if(cmd.returnKey) findCmd.returnKey = cmd.returnKey; - - // If we have showDiskLoc set - if(cmd.showDiskLoc) findCmd.showRecordId = cmd.showDiskLoc; - - // If we have snapshot set - if(cmd.snapshot) findCmd.snapshot = cmd.snapshot; - - // If we have tailable set - if(cmd.tailable) findCmd.tailable = cmd.tailable; - - // If we have oplogReplay set - if(cmd.oplogReplay) findCmd.oplogReplay = cmd.oplogReplay; - - // If we have noCursorTimeout set - if(cmd.noCursorTimeout) findCmd.noCursorTimeout = cmd.noCursorTimeout; - - // If we have awaitData set - if(cmd.awaitData) findCmd.awaitData = cmd.awaitData; - if(cmd.awaitdata) findCmd.awaitData = cmd.awaitdata; - - // If we have partial set - if(cmd.partial) findCmd.partial = cmd.partial; - - // If we have explain, we need to rewrite the find command - // to wrap it in the explain command - if(cmd.explain) { - findCmd = { - explain: findCmd - } - } - - // Did we provide a readConcern - if(cmd.readConcern) findCmd.readConcern = cmd.readConcern; - - // Set up the serialize and ignoreUndefined fields - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' - && readPreference - && readPreference.preference != 'primary') { - findCmd = { - '$query': findCmd, - '$readPreference': readPreference.toJSON() - }; - } - - // Build Query object - var query = new Query(bson, commandns, findCmd, { - numberToSkip: 0, numberToReturn: 1 - , checkKeys: false, returnFieldSelector: null - , serializeFunctions: serializeFunctions, ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Return the query - return query; -} - -// -// Set up a command cursor -var setupCommand = function(bson, ns, cmd, cursorState, topology, options) { - // Set empty options object - options = options || {} - // Get the readPreference - var readPreference = getReadPreference(cmd, options); - - // Final query - var finalCmd = {}; - for(var name in cmd) { - finalCmd[name] = cmd[name]; - } - - // Build command namespace - var parts = ns.split(/\./); - - // Serialize functions - var serializeFunctions = typeof options.serializeFunctions == 'boolean' - ? options.serializeFunctions : false; - - // Set up the serialize and ignoreUndefined fields - var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' - ? options.ignoreUndefined : false; - - // We have a Mongos topology, check if we need to add a readPreference - if(topology.type == 'mongos' - && readPreference - && readPreference.preference != 'primary') { - finalCmd = { - '$query': finalCmd, - '$readPreference': readPreference.toJSON() - }; - } - - // Build Query object - var query = new Query(bson, f('%s.$cmd', parts.shift()), finalCmd, { - numberToSkip: 0, numberToReturn: -1 - , checkKeys: false, serializeFunctions: serializeFunctions - , ignoreUndefined: ignoreUndefined - }); - - // Set query flags - query.slaveOk = readPreference.slaveOk(); - - // Return the query - return query; -} - -module.exports = WireProtocol; diff --git a/node_modules/mongodb-core/lib/wireprotocol/commands.js b/node_modules/mongodb-core/lib/wireprotocol/commands.js deleted file mode 100644 index 9c665ee..0000000 --- a/node_modules/mongodb-core/lib/wireprotocol/commands.js +++ /dev/null @@ -1,357 +0,0 @@ -"use strict"; - -var MongoError = require('../error'); - -// Wire command operation ids -var OP_UPDATE = 2001; -var OP_INSERT = 2002; -var OP_DELETE = 2006; - -var Insert = function(requestId, ismaster, bson, ns, documents, options) { - // Basic options needed to be passed in - if(ns == null) throw new MongoError("ns must be specified for query"); - if(!Array.isArray(documents) || documents.length == 0) throw new MongoError("documents array must contain at least one document to insert"); - - // Validate that we are not passing 0x00 in the colletion name - if(!!~ns.indexOf("\x00")) { - throw new MongoError("namespace cannot contain a null character"); - } - - // Set internal - this.requestId = requestId; - this.bson = bson; - this.ns = ns; - this.documents = documents; - this.ismaster = ismaster; - - // Ensure empty options - options = options || {}; - - // Unpack options - this.serializeFunctions = typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false; - this.ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : false; - this.checkKeys = typeof options.checkKeys == 'boolean' ? options.checkKeys : true; - this.continueOnError = typeof options.continueOnError == 'boolean' ? options.continueOnError : false; - // Set flags - this.flags = this.continueOnError ? 1 : 0; -} - -// To Binary -Insert.prototype.toBin = function() { - // Contains all the buffers to be written - var buffers = []; - - // Header buffer - var header = new Buffer( - 4 * 4 // Header - + 4 // Flags - + Buffer.byteLength(this.ns) + 1 // namespace - ); - - // Add header to buffers - buffers.push(header); - - // Total length of the message - var totalLength = header.length; - - // Serialize all the documents - for(var i = 0; i < this.documents.length; i++) { - var buffer = this.bson.serialize(this.documents[i] - , this.checkKeys - , true - , this.serializeFunctions - , 0, this.ignoreUndefined); - - // Document is larger than maxBsonObjectSize, terminate serialization - if(buffer.length > this.ismaster.maxBsonObjectSize) { - throw new MongoError("Document exceeds maximum allowed bson size of " + this.ismaster.maxBsonObjectSize + " bytes"); - } - - // Add to total length of wire protocol message - totalLength = totalLength + buffer.length; - // Add to buffer - buffers.push(buffer); - } - - // Command is larger than maxMessageSizeBytes terminate serialization - if(totalLength > this.ismaster.maxMessageSizeBytes) { - throw new MongoError("Command exceeds maximum message size of " + this.ismaster.maxMessageSizeBytes + " bytes"); - } - - // Add all the metadata - var index = 0; - - // Write header length - header[index + 3] = (totalLength >> 24) & 0xff; - header[index + 2] = (totalLength >> 16) & 0xff; - header[index + 1] = (totalLength >> 8) & 0xff; - header[index] = (totalLength) & 0xff; - index = index + 4; - - // Write header requestId - header[index + 3] = (this.requestId >> 24) & 0xff; - header[index + 2] = (this.requestId >> 16) & 0xff; - header[index + 1] = (this.requestId >> 8) & 0xff; - header[index] = (this.requestId) & 0xff; - index = index + 4; - - // No flags - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Operation - header[index + 3] = (OP_INSERT >> 24) & 0xff; - header[index + 2] = (OP_INSERT >> 16) & 0xff; - header[index + 1] = (OP_INSERT >> 8) & 0xff; - header[index] = (OP_INSERT) & 0xff; - index = index + 4; - - // Flags - header[index + 3] = (this.flags >> 24) & 0xff; - header[index + 2] = (this.flags >> 16) & 0xff; - header[index + 1] = (this.flags >> 8) & 0xff; - header[index] = (this.flags) & 0xff; - index = index + 4; - - // Write collection name - index = index + header.write(this.ns, index, 'utf8') + 1; - header[index - 1] = 0; - - // Return the buffers - return buffers; -} - -var Update = function(requestId, ismaster, bson, ns, update, options) { - // Basic options needed to be passed in - if(ns == null) throw new MongoError("ns must be specified for query"); - - // Ensure empty options - options = options || {}; - - // Set internal - this.requestId = requestId; - this.bson = bson; - this.ns = ns; - this.ismaster = ismaster; - - // Unpack options - this.serializeFunctions = typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false; - this.ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : false; - this.checkKeys = typeof options.checkKeys == 'boolean' ? options.checkKeys : false; - - // Unpack the update document - this.upsert = typeof update[0].upsert == 'boolean' ? update[0].upsert : false; - this.multi = typeof update[0].multi == 'boolean' ? update[0].multi : false; - this.q = update[0].q; - this.u = update[0].u; - - // Create flag value - this.flags = this.upsert ? 1 : 0; - this.flags = this.multi ? this.flags | 2 : this.flags; -} - -// To Binary -Update.prototype.toBin = function() { - // Contains all the buffers to be written - var buffers = []; - - // Header buffer - var header = new Buffer( - 4 * 4 // Header - + 4 // ZERO - + Buffer.byteLength(this.ns) + 1 // namespace - + 4 // Flags - ); - - // Add header to buffers - buffers.push(header); - - // Total length of the message - var totalLength = header.length; - - // Serialize the selector - var selector = this.bson.serialize(this.q - , this.checkKeys - , true - , this.serializeFunctions - , 0, this.ignoreUndefined); - buffers.push(selector); - totalLength = totalLength + selector.length; - - // Serialize the update - var update = this.bson.serialize(this.u - , this.checkKeys - , true - , this.serializeFunctions - , 0, this.ignoreUndefined); - buffers.push(update); - totalLength = totalLength + update.length; - - // Index in header buffer - var index = 0; - - // Write header length - header[index + 3] = (totalLength >> 24) & 0xff; - header[index + 2] = (totalLength >> 16) & 0xff; - header[index + 1] = (totalLength >> 8) & 0xff; - header[index] = (totalLength) & 0xff; - index = index + 4; - - // Write header requestId - header[index + 3] = (this.requestId >> 24) & 0xff; - header[index + 2] = (this.requestId >> 16) & 0xff; - header[index + 1] = (this.requestId >> 8) & 0xff; - header[index] = (this.requestId) & 0xff; - index = index + 4; - - // No flags - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Operation - header[index + 3] = (OP_UPDATE >> 24) & 0xff; - header[index + 2] = (OP_UPDATE >> 16) & 0xff; - header[index + 1] = (OP_UPDATE >> 8) & 0xff; - header[index] = (OP_UPDATE) & 0xff; - index = index + 4; - - // Write ZERO - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Write collection name - index = index + header.write(this.ns, index, 'utf8') + 1; - header[index - 1] = 0; - - // Flags - header[index + 3] = (this.flags >> 24) & 0xff; - header[index + 2] = (this.flags >> 16) & 0xff; - header[index + 1] = (this.flags >> 8) & 0xff; - header[index] = (this.flags) & 0xff; - index = index + 4; - - // Return the buffers - return buffers; -} - -var Remove = function(requestId, ismaster, bson, ns, remove, options) { - // Basic options needed to be passed in - if(ns == null) throw new MongoError("ns must be specified for query"); - - // Ensure empty options - options = options || {}; - - // Set internal - this.requestId = requestId; - this.bson = bson; - this.ns = ns; - this.ismaster = ismaster; - - // Unpack options - this.serializeFunctions = typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false; - this.ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : false; - this.checkKeys = typeof options.checkKeys == 'boolean' ? options.checkKeys : false; - - // Unpack the update document - this.limit = typeof remove[0].limit == 'number' ? remove[0].limit : 1; - this.q = remove[0].q; - - // Create flag value - this.flags = this.limit == 1 ? 1 : 0; -} - -// To Binary -Remove.prototype.toBin = function() { - // Contains all the buffers to be written - var buffers = []; - - // Header buffer - var header = new Buffer( - 4 * 4 // Header - + 4 // ZERO - + Buffer.byteLength(this.ns) + 1 // namespace - + 4 // Flags - ); - - // Add header to buffers - buffers.push(header); - - // Total length of the message - var totalLength = header.length; - - // Serialize the selector - var selector = this.bson.serialize(this.q - , this.checkKeys - , true - , this.serializeFunctions - , 0, this.ignoreUndefined); - buffers.push(selector); - totalLength = totalLength + selector.length; - - // Index in header buffer - var index = 0; - - // Write header length - header[index + 3] = (totalLength >> 24) & 0xff; - header[index + 2] = (totalLength >> 16) & 0xff; - header[index + 1] = (totalLength >> 8) & 0xff; - header[index] = (totalLength) & 0xff; - index = index + 4; - - // Write header requestId - header[index + 3] = (this.requestId >> 24) & 0xff; - header[index + 2] = (this.requestId >> 16) & 0xff; - header[index + 1] = (this.requestId >> 8) & 0xff; - header[index] = (this.requestId) & 0xff; - index = index + 4; - - // No flags - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Operation - header[index + 3] = (OP_DELETE >> 24) & 0xff; - header[index + 2] = (OP_DELETE >> 16) & 0xff; - header[index + 1] = (OP_DELETE >> 8) & 0xff; - header[index] = (OP_DELETE) & 0xff; - index = index + 4; - - // Write ZERO - header[index + 3] = (0 >> 24) & 0xff; - header[index + 2] = (0 >> 16) & 0xff; - header[index + 1] = (0 >> 8) & 0xff; - header[index] = (0) & 0xff; - index = index + 4; - - // Write collection name - index = index + header.write(this.ns, index, 'utf8') + 1; - header[index - 1] = 0; - - // Write ZERO - header[index + 3] = (this.flags >> 24) & 0xff; - header[index + 2] = (this.flags >> 16) & 0xff; - header[index + 1] = (this.flags >> 8) & 0xff; - header[index] = (this.flags) & 0xff; - index = index + 4; - - // Return the buffers - return buffers; -} - -module.exports = { - Insert: Insert - , Update: Update - , Remove: Remove -} diff --git a/node_modules/mongodb-core/lib/wireprotocol/shared.js b/node_modules/mongodb-core/lib/wireprotocol/shared.js deleted file mode 100644 index 3a20f51..0000000 --- a/node_modules/mongodb-core/lib/wireprotocol/shared.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict" - -var ReadPreference = require('../topologies/read_preference'); - -var getReadPreference = function(cmd, options) { - // Default to command version of the readPreference - var readPreference = cmd.readPreference || new ReadPreference('primary'); - // If we have an option readPreference override the command one - if(options.readPreference) { - readPreference = options.readPreference; - } - - if(typeof readPreference == 'string') { - readPreference = new ReadPreference(readPreference); - } - - if(!(readPreference instanceof ReadPreference)) { - throw new MongoError('readPreference must be a ReadPreference instance'); - } - - return readPreference; -} - -module.exports = { - getReadPreference: getReadPreference -} diff --git a/node_modules/mongodb-core/package.json b/node_modules/mongodb-core/package.json deleted file mode 100644 index 7118c5d..0000000 --- a/node_modules/mongodb-core/package.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "_args": [ - [ - { - "name": "mongodb-core", - "raw": "mongodb-core@2.0.5", - "rawSpec": "2.0.5", - "scope": null, - "spec": "2.0.5", - "type": "version" - }, - "/Users/warefhaque/CSC309/solutions_repo/node_modules/mongodb" - ] - ], - "_from": "mongodb-core@2.0.5", - "_id": "mongodb-core@2.0.5", - "_inCache": true, - "_installable": true, - "_location": "/mongodb-core", - "_nodeVersion": "4.4.4", - "_npmOperationalInternal": { - "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/mongodb-core-2.0.5.tgz_1468603095051_0.6176625408697873" - }, - "_npmUser": { - "email": "christkv@gmail.com", - "name": "christkv" - }, - "_npmVersion": "2.15.1", - "_phantomChildren": {}, - "_requested": { - "name": "mongodb-core", - "raw": "mongodb-core@2.0.5", - "rawSpec": "2.0.5", - "scope": null, - "spec": "2.0.5", - "type": "version" - }, - "_requiredBy": [ - "/mongodb" - ], - "_resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.0.5.tgz", - "_shasum": "eb1d72e6b085c8de7aad399bcb66f41cb3674267", - "_shrinkwrap": null, - "_spec": "mongodb-core@2.0.5", - "_where": "/Users/warefhaque/CSC309/solutions_repo/node_modules/mongodb", - "author": { - "name": "Christian Kvalheim" - }, - "bugs": { - "url": "https://github.com/christkv/mongodb-core/issues" - }, - "dependencies": { - "bson": "~0.5.1", - "require_optional": "~1.0.0" - }, - "description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications", - "devDependencies": { - "co": "4.5.4", - "coveralls": "^2.11.6", - "es6-promise": "^3.0.2", - "gleak": "0.5.0", - "integra": "0.1.8", - "jsdoc": "3.3.0-alpha8", - "mkdirp": "0.5.0", - "mongodb-topology-manager": "1.0.x", - "mongodb-version-manager": "^1.x", - "nyc": "^5.5.0", - "optimist": "latest", - "rimraf": "2.2.6", - "semver": "4.1.0" - }, - "directories": {}, - "dist": { - "shasum": "eb1d72e6b085c8de7aad399bcb66f41cb3674267", - "tarball": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.0.5.tgz" - }, - "gitHead": "ea0de7053b38c48ae54e0105cfc4a0726050a655", - "homepage": "https://github.com/christkv/mongodb-core", - "keywords": [ - "mongodb", - "core" - ], - "license": "Apache-2.0", - "main": "index.js", - "maintainers": [ - { - "email": "christkv@gmail.com", - "name": "christkv" - } - ], - "name": "mongodb-core", - "optionalDependencies": {}, - "peerOptionalDependencies": { - "kerberos": "~0.0" - }, - "readme": "ERROR: No README data found!", - "repository": { - "type": "git", - "url": "git://github.com/christkv/mongodb-core.git" - }, - "scripts": { - "coverage": "nyc node test/runner.js -t functional -l && node_modules/.bin/nyc report --reporter=text-lcov | node_modules/.bin/coveralls", - "test": "node test/runner.js -t functional" - }, - "version": "2.0.5" -} diff --git a/node_modules/mongodb-core/simple_2_document_limit_toArray.dat b/node_modules/mongodb-core/simple_2_document_limit_toArray.dat deleted file mode 100644 index 25ccf0b..0000000 --- a/node_modules/mongodb-core/simple_2_document_limit_toArray.dat +++ /dev/null @@ -1,11000 +0,0 @@ -1 2 -2 1 -3 0 -4 0 -5 1 -6 0 -7 0 -8 0 -9 0 -10 1 -11 0 -12 0 -13 0 -14 1 -15 0 -16 0 -17 0 -18 1 -19 0 -20 0 -21 0 -22 1 -23 0 -24 0 -25 0 -26 0 -27 1 -28 0 -29 0 -30 0 -31 1 -32 0 -33 0 -34 0 -35 0 -36 0 -37 1 -38 0 -39 0 -40 0 -41 0 -42 0 -43 1 -44 0 -45 0 -46 0 -47 0 -48 0 -49 0 -50 0 -51 0 -52 0 -53 0 -54 0 -55 0 -56 0 -57 0 -58 0 -59 1 -60 0 -61 2 -62 0 -63 0 -64 1 -65 0 -66 0 -67 0 -68 1 -69 0 -70 0 -71 0 -72 0 -73 1 -74 0 -75 0 -76 0 -77 0 -78 0 -79 1 -80 0 -81 0 -82 0 -83 0 -84 0 -85 0 -86 1 -87 0 -88 0 -89 0 -90 0 -91 0 -92 0 -93 1 -94 0 -95 0 -96 0 -97 0 -98 0 -99 0 -100 0 -101 1 -102 0 -103 0 -104 0 -105 0 -106 0 -107 0 -108 1 -109 0 -110 0 -111 0 -112 0 -113 0 -114 0 -115 1 -116 0 -117 0 -118 0 -119 1 -120 0 -121 0 -122 0 -123 0 -124 0 -125 0 -126 1 -127 0 -128 1 -129 0 -130 0 -131 0 -132 1 -133 1 -134 0 -135 0 -136 0 -137 1 -138 0 -139 0 -140 0 -141 0 -142 0 -143 0 -144 1 -145 0 -146 0 -147 0 -148 0 -149 0 -150 0 -151 0 -152 0 -153 1 -154 0 -155 0 -156 0 -157 0 -158 0 -159 0 -160 0 -161 0 -162 0 -163 0 -164 0 -165 0 -166 0 -167 0 -168 0 -169 0 -170 1 -171 0 -172 0 -173 0 -174 0 -175 0 -176 0 -177 0 -178 1 -179 0 -180 0 -181 0 -182 0 -183 0 -184 0 -185 0 -186 1 -187 0 -188 0 -189 0 -190 0 -191 0 -192 1 -193 0 -194 0 -195 0 -196 1 -197 0 -198 0 -199 0 -200 1 -201 0 -202 0 -203 0 -204 0 -205 0 -206 0 -207 1 -208 0 -209 0 -210 0 -211 0 -212 0 -213 0 -214 0 -215 1 -216 0 -217 0 -218 0 -219 0 -220 0 -221 0 -222 0 -223 1 -224 0 -225 0 -226 0 -227 0 -228 0 -229 0 -230 1 -231 0 -232 0 -233 0 -234 0 -235 0 -236 0 -237 1 -238 0 -239 0 -240 0 -241 0 -242 0 -243 0 -244 0 -245 1 -246 0 -247 0 -248 0 -249 0 -250 0 -251 0 -252 0 -253 0 -254 1 -255 0 -256 0 -257 0 -258 0 -259 1 -260 0 -261 0 -262 0 -263 0 -264 0 -265 1 -266 0 -267 0 -268 0 -269 0 -270 0 -271 0 -272 1 -273 0 -274 0 -275 0 -276 0 -277 0 -278 0 -279 0 -280 0 -281 1 -282 0 -283 1 -284 0 -285 0 -286 1 -287 0 -288 0 -289 0 -290 0 -291 1 -292 0 -293 0 -294 0 -295 0 -296 1 -297 0 -298 0 -299 0 -300 0 -301 0 -302 0 -303 1 -304 0 -305 0 -306 0 -307 0 -308 0 -309 1 -310 0 -311 0 -312 0 -313 0 -314 0 -315 0 -316 1 -317 0 -318 0 -319 0 -320 0 -321 0 -322 0 -323 0 -324 0 -325 1 -326 0 -327 0 -328 0 -329 0 -330 0 -331 0 -332 0 -333 0 -334 1 -335 0 -336 0 -337 0 -338 0 -339 0 -340 0 -341 0 -342 0 -343 1 -344 0 -345 0 -346 0 -347 0 -348 0 -349 0 -350 0 -351 0 -352 1 -353 0 -354 0 -355 0 -356 0 -357 0 -358 0 -359 0 -360 0 -361 1 -362 0 -363 0 -364 0 -365 0 -366 0 -367 0 -368 0 -369 1 -370 0 -371 0 -372 0 -373 0 -374 0 -375 0 -376 0 -377 1 -378 0 -379 0 -380 0 -381 0 -382 0 -383 0 -384 0 -385 1 -386 0 -387 0 -388 0 -389 0 -390 1 -391 0 -392 0 -393 0 -394 0 -395 0 -396 0 -397 0 -398 0 -399 0 -400 0 -401 0 -402 1 -403 0 -404 0 -405 0 -406 0 -407 0 -408 0 -409 0 -410 1 -411 0 -412 0 -413 0 -414 0 -415 0 -416 0 -417 0 -418 0 -419 1 -420 0 -421 0 -422 0 -423 0 -424 0 -425 0 -426 0 -427 1 -428 0 -429 0 -430 0 -431 0 -432 0 -433 0 -434 0 -435 1 -436 0 -437 0 -438 0 -439 0 -440 0 -441 0 -442 0 -443 1 -444 0 -445 0 -446 0 -447 0 -448 0 -449 0 -450 1 -451 0 -452 0 -453 0 -454 0 -455 0 -456 1 -457 0 -458 0 -459 0 -460 0 -461 0 -462 0 -463 0 -464 1 -465 0 -466 0 -467 0 -468 0 -469 0 -470 0 -471 0 -472 0 -473 1 -474 0 -475 0 -476 0 -477 0 -478 0 -479 0 -480 0 -481 1 -482 0 -483 0 -484 0 -485 0 -486 0 -487 0 -488 0 -489 0 -490 1 -491 0 -492 0 -493 0 -494 0 -495 0 -496 0 -497 0 -498 0 -499 0 -500 0 -501 0 -502 0 -503 0 -504 1 -505 0 -506 0 -507 0 -508 0 -509 0 -510 0 -511 0 -512 1 -513 0 -514 0 -515 0 -516 0 -517 0 -518 0 -519 4 -520 0 -521 1 -522 0 -523 0 -524 0 -525 1 -526 0 -527 0 -528 0 -529 0 -530 1 -531 0 -532 0 -533 0 -534 1 -535 0 -536 0 -537 0 -538 0 -539 1 -540 0 -541 0 -542 0 -543 0 -544 0 -545 1 -546 0 -547 0 -548 0 -549 0 -550 0 -551 1 -552 0 -553 0 -554 0 -555 0 -556 0 -557 0 -558 0 -559 1 -560 0 -561 0 -562 0 -563 0 -564 0 -565 0 -566 0 -567 1 -568 0 -569 0 -570 0 -571 0 -572 0 -573 0 -574 0 -575 0 -576 1 -577 0 -578 0 -579 0 -580 0 -581 0 -582 0 -583 0 -584 0 -585 0 -586 0 -587 0 -588 0 -589 0 -590 0 -591 0 -592 0 -593 1 -594 0 -595 0 -596 0 -597 0 -598 0 -599 0 -600 0 -601 0 -602 1 -603 0 -604 0 -605 0 -606 0 -607 0 -608 0 -609 0 -610 0 -611 1 -612 0 -613 0 -614 0 -615 0 -616 0 -617 0 -618 0 -619 0 -620 1 -621 0 -622 0 -623 0 -624 0 -625 0 -626 0 -627 0 -628 0 -629 1 -630 0 -631 0 -632 0 -633 0 -634 0 -635 0 -636 0 -637 0 -638 0 -639 1 -640 0 -641 0 -642 0 -643 0 -644 0 -645 0 -646 1 -647 0 -648 0 -649 0 -650 0 -651 0 -652 1 -653 1 -654 0 -655 0 -656 1 -657 0 -658 1 -659 0 -660 0 -661 0 -662 0 -663 0 -664 1 -665 0 -666 0 -667 0 -668 0 -669 0 -670 0 -671 0 -672 0 -673 0 -674 0 -675 0 -676 0 -677 1 -678 0 -679 0 -680 0 -681 0 -682 0 -683 0 -684 0 -685 0 -686 1 -687 0 -688 0 -689 0 -690 0 -691 0 -692 0 -693 0 -694 0 -695 1 -696 0 -697 0 -698 0 -699 0 -700 0 -701 0 -702 0 -703 1 -704 0 -705 0 -706 0 -707 0 -708 0 -709 0 -710 0 -711 0 -712 1 -713 0 -714 0 -715 0 -716 0 -717 0 -718 0 -719 0 -720 1 -721 0 -722 0 -723 0 -724 0 -725 0 -726 0 -727 0 -728 1 -729 0 -730 0 -731 0 -732 0 -733 0 -734 0 -735 0 -736 0 -737 1 -738 0 -739 0 -740 0 -741 0 -742 0 -743 0 -744 0 -745 1 -746 0 -747 0 -748 0 -749 0 -750 0 -751 0 -752 0 -753 1 -754 0 -755 0 -756 0 -757 0 -758 0 -759 0 -760 0 -761 1 -762 0 -763 0 -764 0 -765 0 -766 0 -767 0 -768 1 -769 0 -770 0 -771 0 -772 0 -773 0 -774 0 -775 0 -776 0 -777 1 -778 0 -779 0 -780 0 -781 0 -782 0 -783 0 -784 0 -785 0 -786 1 -787 0 -788 0 -789 0 -790 0 -791 0 -792 1 -793 0 -794 0 -795 0 -796 0 -797 0 -798 0 -799 0 -800 0 -801 1 -802 0 -803 0 -804 0 -805 0 -806 0 -807 0 -808 0 -809 0 -810 0 -811 0 -812 0 -813 0 -814 0 -815 0 -816 0 -817 0 -818 0 -819 0 -820 1 -821 0 -822 0 -823 0 -824 0 -825 0 -826 0 -827 0 -828 0 -829 1 -830 0 -831 0 -832 0 -833 0 -834 0 -835 0 -836 0 -837 1 -838 0 -839 0 -840 0 -841 0 -842 0 -843 0 -844 0 -845 0 -846 1 -847 0 -848 0 -849 0 -850 0 -851 0 -852 0 -853 0 -854 0 -855 2 -856 0 -857 0 -858 0 -859 0 -860 0 -861 0 -862 1 -863 0 -864 0 -865 0 -866 0 -867 0 -868 0 -869 0 -870 0 -871 1 -872 0 -873 0 -874 0 -875 0 -876 0 -877 0 -878 1 -879 0 -880 0 -881 0 -882 0 -883 0 -884 0 -885 0 -886 0 -887 0 -888 0 -889 0 -890 0 -891 0 -892 0 -893 0 -894 0 -895 0 -896 1 -897 0 -898 0 -899 0 -900 0 -901 0 -902 0 -903 0 -904 0 -905 0 -906 1 -907 0 -908 0 -909 0 -910 0 -911 0 -912 0 -913 0 -914 0 -915 1 -916 0 -917 0 -918 0 -919 0 -920 0 -921 0 -922 1 -923 0 -924 0 -925 0 -926 0 -927 0 -928 0 -929 0 -930 1 -931 0 -932 0 -933 0 -934 0 -935 0 -936 0 -937 0 -938 0 -939 1 -940 0 -941 0 -942 0 -943 0 -944 0 -945 0 -946 0 -947 0 -948 0 -949 1 -950 0 -951 0 -952 0 -953 0 -954 0 -955 0 -956 0 -957 0 -958 1 -959 0 -960 0 -961 0 -962 0 -963 0 -964 0 -965 0 -966 0 -967 0 -968 1 -969 0 -970 0 -971 0 -972 0 -973 0 -974 0 -975 0 -976 0 -977 0 -978 1 -979 0 -980 0 -981 0 -982 0 -983 0 -984 0 -985 0 -986 0 -987 0 -988 1 -989 0 -990 0 -991 0 -992 0 -993 0 -994 0 -995 0 -996 0 -997 1 -998 0 -999 0 -1000 0 -1001 0 -1002 0 -1003 0 -1004 0 -1005 1 -1006 0 -1007 0 -1008 0 -1009 0 -1010 0 -1011 0 -1012 1 -1013 0 -1014 0 -1015 0 -1016 0 -1017 0 -1018 0 -1019 0 -1020 0 -1021 0 -1022 0 -1023 0 -1024 0 -1025 0 -1026 0 -1027 0 -1028 0 -1029 0 -1030 0 -1031 1 -1032 0 -1033 0 -1034 0 -1035 0 -1036 0 -1037 0 -1038 0 -1039 0 -1040 0 -1041 0 -1042 1 -1043 0 -1044 0 -1045 0 -1046 0 -1047 0 -1048 0 -1049 0 -1050 1 -1051 0 -1052 0 -1053 0 -1054 0 -1055 0 -1056 0 -1057 1 -1058 0 -1059 0 -1060 0 -1061 0 -1062 0 -1063 0 -1064 0 -1065 0 -1066 0 -1067 1 -1068 0 -1069 0 -1070 0 -1071 0 -1072 0 -1073 0 -1074 0 -1075 0 -1076 0 -1077 1 -1078 0 -1079 0 -1080 0 -1081 0 -1082 0 -1083 0 -1084 0 -1085 0 -1086 0 -1087 1 -1088 0 -1089 0 -1090 0 -1091 0 -1092 0 -1093 0 -1094 1 -1095 0 -1096 0 -1097 0 -1098 0 -1099 0 -1100 0 -1101 0 -1102 1 -1103 0 -1104 0 -1105 0 -1106 0 -1107 0 -1108 0 -1109 0 -1110 0 -1111 1 -1112 0 -1113 0 -1114 0 -1115 0 -1116 0 -1117 0 -1118 0 -1119 0 -1120 1 -1121 0 -1122 0 -1123 0 -1124 0 -1125 0 -1126 0 -1127 0 -1128 0 -1129 0 -1130 1 -1131 0 -1132 0 -1133 0 -1134 0 -1135 0 -1136 0 -1137 0 -1138 0 -1139 0 -1140 1 -1141 0 -1142 0 -1143 0 -1144 0 -1145 0 -1146 0 -1147 0 -1148 0 -1149 0 -1150 0 -1151 1 -1152 0 -1153 0 -1154 0 -1155 0 -1156 0 -1157 0 -1158 0 -1159 0 -1160 1 -1161 0 -1162 0 -1163 0 -1164 0 -1165 0 -1166 0 -1167 1 -1168 0 -1169 0 -1170 0 -1171 0 -1172 0 -1173 0 -1174 0 -1175 0 -1176 1 -1177 0 -1178 0 -1179 0 -1180 0 -1181 0 -1182 1 -1183 0 -1184 0 -1185 0 -1186 0 -1187 0 -1188 0 -1189 0 -1190 1 -1191 0 -1192 0 -1193 0 -1194 0 -1195 0 -1196 0 -1197 0 -1198 1 -1199 0 -1200 0 -1201 0 -1202 0 -1203 0 -1204 0 -1205 0 -1206 1 -1207 0 -1208 0 -1209 0 -1210 0 -1211 0 -1212 0 -1213 0 -1214 0 -1215 0 -1216 1 -1217 0 -1218 0 -1219 0 -1220 0 -1221 0 -1222 0 -1223 0 -1224 0 -1225 0 -1226 1 -1227 0 -1228 0 -1229 0 -1230 0 -1231 0 -1232 0 -1233 0 -1234 0 -1235 0 -1236 0 -1237 0 -1238 0 -1239 1 -1240 0 -1241 0 -1242 0 -1243 0 -1244 0 -1245 0 -1246 0 -1247 0 -1248 1 -1249 0 -1250 0 -1251 0 -1252 0 -1253 0 -1254 0 -1255 0 -1256 0 -1257 1 -1258 0 -1259 0 -1260 0 -1261 0 -1262 0 -1263 0 -1264 0 -1265 0 -1266 1 -1267 0 -1268 0 -1269 0 -1270 0 -1271 0 -1272 0 -1273 0 -1274 0 -1275 1 -1276 0 -1277 0 -1278 0 -1279 0 -1280 0 -1281 0 -1282 0 -1283 0 -1284 0 -1285 0 -1286 0 -1287 0 -1288 0 -1289 0 -1290 0 -1291 0 -1292 0 -1293 1 -1294 0 -1295 0 -1296 0 -1297 0 -1298 0 -1299 0 -1300 0 -1301 0 -1302 0 -1303 0 -1304 0 -1305 0 -1306 0 -1307 0 -1308 0 -1309 0 -1310 1 -1311 0 -1312 0 -1313 0 -1314 0 -1315 0 -1316 0 -1317 0 -1318 1 -1319 0 -1320 0 -1321 0 -1322 0 -1323 0 -1324 0 -1325 0 -1326 0 -1327 1 -1328 0 -1329 0 -1330 0 -1331 0 -1332 0 -1333 0 -1334 0 -1335 0 -1336 1 -1337 0 -1338 0 -1339 0 -1340 0 -1341 0 -1342 0 -1343 0 -1344 0 -1345 0 -1346 1 -1347 0 -1348 0 -1349 0 -1350 0 -1351 0 -1352 0 -1353 0 -1354 0 -1355 0 -1356 1 -1357 0 -1358 0 -1359 0 -1360 0 -1361 0 -1362 0 -1363 0 -1364 0 -1365 1 -1366 0 -1367 0 -1368 0 -1369 0 -1370 0 -1371 0 -1372 0 -1373 1 -1374 0 -1375 0 -1376 0 -1377 0 -1378 0 -1379 0 -1380 0 -1381 0 -1382 0 -1383 1 -1384 0 -1385 0 -1386 0 -1387 0 -1388 0 -1389 0 -1390 0 -1391 0 -1392 1 -1393 0 -1394 0 -1395 0 -1396 0 -1397 0 -1398 0 -1399 0 -1400 1 -1401 0 -1402 0 -1403 0 -1404 0 -1405 0 -1406 0 -1407 0 -1408 0 -1409 0 -1410 1 -1411 0 -1412 0 -1413 0 -1414 0 -1415 0 -1416 0 -1417 0 -1418 0 -1419 0 -1420 1 -1421 0 -1422 0 -1423 0 -1424 0 -1425 0 -1426 0 -1427 0 -1428 0 -1429 0 -1430 0 -1431 1 -1432 0 -1433 0 -1434 0 -1435 0 -1436 0 -1437 0 -1438 0 -1439 0 -1440 0 -1441 1 -1442 0 -1443 0 -1444 0 -1445 0 -1446 0 -1447 2 -1448 0 -1449 0 -1450 0 -1451 0 -1452 0 -1453 0 -1454 0 -1455 1 -1456 0 -1457 0 -1458 0 -1459 0 -1460 0 -1461 0 -1462 0 -1463 0 -1464 0 -1465 1 -1466 0 -1467 0 -1468 0 -1469 0 -1470 0 -1471 0 -1472 0 -1473 0 -1474 0 -1475 1 -1476 0 -1477 0 -1478 0 -1479 0 -1480 0 -1481 0 -1482 0 -1483 0 -1484 0 -1485 1 -1486 0 -1487 0 -1488 0 -1489 0 -1490 0 -1491 0 -1492 0 -1493 0 -1494 1 -1495 0 -1496 0 -1497 0 -1498 0 -1499 0 -1500 0 -1501 0 -1502 0 -1503 1 -1504 0 -1505 0 -1506 0 -1507 0 -1508 0 -1509 0 -1510 0 -1511 0 -1512 0 -1513 0 -1514 0 -1515 0 -1516 0 -1517 0 -1518 0 -1519 0 -1520 1 -1521 0 -1522 0 -1523 0 -1524 0 -1525 0 -1526 0 -1527 0 -1528 0 -1529 1 -1530 0 -1531 0 -1532 0 -1533 0 -1534 0 -1535 0 -1536 0 -1537 0 -1538 0 -1539 1 -1540 0 -1541 0 -1542 0 -1543 0 -1544 0 -1545 0 -1546 0 -1547 0 -1548 1 -1549 0 -1550 0 -1551 0 -1552 0 -1553 0 -1554 0 -1555 0 -1556 0 -1557 1 -1558 0 -1559 0 -1560 0 -1561 0 -1562 0 -1563 0 -1564 0 -1565 0 -1566 0 -1567 1 -1568 0 -1569 0 -1570 0 -1571 0 -1572 0 -1573 0 -1574 0 -1575 1 -1576 0 -1577 0 -1578 0 -1579 0 -1580 0 -1581 0 -1582 0 -1583 0 -1584 1 -1585 0 -1586 0 -1587 0 -1588 0 -1589 0 -1590 0 -1591 0 -1592 0 -1593 1 -1594 0 -1595 0 -1596 0 -1597 0 -1598 0 -1599 0 -1600 0 -1601 0 -1602 1 -1603 0 -1604 0 -1605 0 -1606 0 -1607 0 -1608 0 -1609 0 -1610 0 -1611 1 -1612 0 -1613 0 -1614 0 -1615 0 -1616 0 -1617 0 -1618 0 -1619 0 -1620 0 -1621 1 -1622 0 -1623 0 -1624 0 -1625 0 -1626 0 -1627 0 -1628 0 -1629 0 -1630 0 -1631 1 -1632 0 -1633 0 -1634 0 -1635 0 -1636 0 -1637 0 -1638 0 -1639 0 -1640 1 -1641 0 -1642 0 -1643 0 -1644 0 -1645 0 -1646 0 -1647 0 -1648 0 -1649 0 -1650 1 -1651 0 -1652 0 -1653 0 -1654 0 -1655 0 -1656 0 -1657 0 -1658 0 -1659 0 -1660 1 -1661 0 -1662 0 -1663 0 -1664 0 -1665 0 -1666 0 -1667 0 -1668 0 -1669 0 -1670 1 -1671 0 -1672 0 -1673 0 -1674 0 -1675 0 -1676 0 -1677 0 -1678 0 -1679 0 -1680 1 -1681 0 -1682 0 -1683 0 -1684 0 -1685 0 -1686 0 -1687 0 -1688 0 -1689 0 -1690 1 -1691 0 -1692 0 -1693 0 -1694 0 -1695 0 -1696 0 -1697 0 -1698 0 -1699 0 -1700 0 -1701 1 -1702 0 -1703 0 -1704 0 -1705 0 -1706 0 -1707 0 -1708 1 -1709 0 -1710 0 -1711 0 -1712 0 -1713 0 -1714 0 -1715 0 -1716 1 -1717 0 -1718 0 -1719 0 -1720 0 -1721 0 -1722 0 -1723 0 -1724 0 -1725 0 -1726 0 -1727 0 -1728 0 -1729 0 -1730 0 -1731 0 -1732 0 -1733 0 -1734 1 -1735 0 -1736 0 -1737 0 -1738 0 -1739 0 -1740 0 -1741 0 -1742 0 -1743 1 -1744 0 -1745 0 -1746 0 -1747 0 -1748 0 -1749 0 -1750 0 -1751 0 -1752 0 -1753 1 -1754 0 -1755 0 -1756 0 -1757 0 -1758 0 -1759 0 -1760 0 -1761 0 -1762 0 -1763 1 -1764 0 -1765 0 -1766 0 -1767 0 -1768 0 -1769 0 -1770 0 -1771 0 -1772 0 -1773 1 -1774 0 -1775 0 -1776 0 -1777 0 -1778 0 -1779 0 -1780 0 -1781 0 -1782 0 -1783 1 -1784 0 -1785 0 -1786 0 -1787 0 -1788 0 -1789 0 -1790 0 -1791 0 -1792 0 -1793 1 -1794 0 -1795 0 -1796 0 -1797 0 -1798 0 -1799 0 -1800 0 -1801 0 -1802 0 -1803 1 -1804 0 -1805 0 -1806 0 -1807 0 -1808 0 -1809 0 -1810 0 -1811 0 -1812 0 -1813 1 -1814 0 -1815 0 -1816 0 -1817 0 -1818 0 -1819 0 -1820 0 -1821 0 -1822 1 -1823 0 -1824 0 -1825 0 -1826 0 -1827 0 -1828 0 -1829 1 -1830 0 -1831 0 -1832 0 -1833 0 -1834 0 -1835 0 -1836 0 -1837 0 -1838 0 -1839 1 -1840 0 -1841 0 -1842 0 -1843 0 -1844 0 -1845 0 -1846 0 -1847 0 -1848 0 -1849 1 -1850 0 -1851 0 -1852 0 -1853 0 -1854 0 -1855 0 -1856 0 -1857 0 -1858 0 -1859 1 -1860 0 -1861 0 -1862 0 -1863 0 -1864 0 -1865 0 -1866 0 -1867 0 -1868 0 -1869 1 -1870 0 -1871 0 -1872 0 -1873 0 -1874 0 -1875 0 -1876 0 -1877 0 -1878 0 -1879 1 -1880 0 -1881 0 -1882 0 -1883 0 -1884 0 -1885 0 -1886 0 -1887 0 -1888 0 -1889 1 -1890 0 -1891 0 -1892 0 -1893 0 -1894 0 -1895 0 -1896 0 -1897 0 -1898 0 -1899 0 -1900 0 -1901 0 -1902 0 -1903 0 -1904 0 -1905 0 -1906 0 -1907 0 -1908 0 -1909 0 -1910 1 -1911 0 -1912 0 -1913 0 -1914 0 -1915 0 -1916 0 -1917 0 -1918 0 -1919 0 -1920 0 -1921 0 -1922 0 -1923 0 -1924 0 -1925 0 -1926 0 -1927 0 -1928 0 -1929 0 -1930 1 -1931 0 -1932 0 -1933 0 -1934 0 -1935 0 -1936 0 -1937 0 -1938 0 -1939 1 -1940 0 -1941 0 -1942 0 -1943 0 -1944 0 -1945 0 -1946 0 -1947 0 -1948 0 -1949 1 -1950 0 -1951 0 -1952 0 -1953 0 -1954 0 -1955 0 -1956 0 -1957 0 -1958 1 -1959 0 -1960 0 -1961 0 -1962 0 -1963 0 -1964 0 -1965 0 -1966 0 -1967 0 -1968 1 -1969 0 -1970 0 -1971 0 -1972 0 -1973 0 -1974 0 -1975 0 -1976 0 -1977 0 -1978 1 -1979 0 -1980 0 -1981 0 -1982 0 -1983 0 -1984 0 -1985 0 -1986 0 -1987 0 -1988 1 -1989 0 -1990 0 -1991 0 -1992 0 -1993 0 -1994 0 -1995 0 -1996 1 -1997 0 -1998 0 -1999 0 -2000 0 -2001 0 -2002 0 -2003 0 -2004 1 -2005 0 -2006 0 -2007 0 -2008 0 -2009 0 -2010 0 -2011 0 -2012 0 -2013 0 -2014 1 -2015 0 -2016 0 -2017 0 -2018 0 -2019 0 -2020 0 -2021 0 -2022 0 -2023 0 -2024 1 -2025 0 -2026 0 -2027 0 -2028 0 -2029 0 -2030 0 -2031 0 -2032 0 -2033 1 -2034 0 -2035 0 -2036 0 -2037 0 -2038 0 -2039 0 -2040 0 -2041 2 -2042 0 -2043 0 -2044 0 -2045 0 -2046 0 -2047 0 -2048 0 -2049 1 -2050 0 -2051 0 -2052 0 -2053 0 -2054 0 -2055 0 -2056 0 -2057 0 -2058 0 -2059 0 -2060 0 -2061 0 -2062 0 -2063 0 -2064 0 -2065 0 -2066 0 -2067 1 -2068 0 -2069 0 -2070 0 -2071 0 -2072 0 -2073 0 -2074 0 -2075 0 -2076 1 -2077 0 -2078 0 -2079 0 -2080 0 -2081 0 -2082 0 -2083 0 -2084 0 -2085 0 -2086 1 -2087 0 -2088 0 -2089 0 -2090 0 -2091 0 -2092 0 -2093 0 -2094 0 -2095 0 -2096 1 -2097 0 -2098 0 -2099 0 -2100 0 -2101 0 -2102 0 -2103 0 -2104 0 -2105 1 -2106 0 -2107 0 -2108 0 -2109 0 -2110 0 -2111 0 -2112 0 -2113 0 -2114 0 -2115 0 -2116 1 -2117 0 -2118 0 -2119 0 -2120 0 -2121 0 -2122 0 -2123 0 -2124 0 -2125 1 -2126 0 -2127 0 -2128 0 -2129 0 -2130 0 -2131 0 -2132 0 -2133 1 -2134 0 -2135 0 -2136 0 -2137 0 -2138 0 -2139 0 -2140 0 -2141 1 -2142 0 -2143 0 -2144 0 -2145 0 -2146 0 -2147 0 -2148 0 -2149 0 -2150 1 -2151 0 -2152 0 -2153 0 -2154 0 -2155 0 -2156 0 -2157 0 -2158 0 -2159 1 -2160 0 -2161 0 -2162 0 -2163 0 -2164 0 -2165 0 -2166 0 -2167 0 -2168 0 -2169 1 -2170 0 -2171 0 -2172 0 -2173 0 -2174 0 -2175 0 -2176 0 -2177 1 -2178 0 -2179 0 -2180 0 -2181 0 -2182 0 -2183 0 -2184 0 -2185 0 -2186 0 -2187 1 -2188 0 -2189 0 -2190 0 -2191 0 -2192 0 -2193 0 -2194 0 -2195 0 -2196 1 -2197 0 -2198 0 -2199 0 -2200 0 -2201 0 -2202 0 -2203 0 -2204 1 -2205 0 -2206 0 -2207 0 -2208 0 -2209 0 -2210 0 -2211 0 -2212 0 -2213 0 -2214 1 -2215 0 -2216 0 -2217 0 -2218 0 -2219 0 -2220 0 -2221 0 -2222 0 -2223 0 -2224 1 -2225 0 -2226 0 -2227 0 -2228 0 -2229 0 -2230 0 -2231 0 -2232 0 -2233 1 -2234 0 -2235 0 -2236 0 -2237 0 -2238 0 -2239 0 -2240 0 -2241 0 -2242 1 -2243 0 -2244 0 -2245 0 -2246 0 -2247 0 -2248 0 -2249 0 -2250 1 -2251 0 -2252 0 -2253 0 -2254 0 -2255 0 -2256 0 -2257 0 -2258 0 -2259 0 -2260 1 -2261 0 -2262 0 -2263 0 -2264 0 -2265 0 -2266 0 -2267 0 -2268 0 -2269 0 -2270 1 -2271 0 -2272 0 -2273 0 -2274 0 -2275 0 -2276 0 -2277 0 -2278 0 -2279 0 -2280 1 -2281 0 -2282 0 -2283 0 -2284 0 -2285 0 -2286 0 -2287 0 -2288 0 -2289 0 -2290 1 -2291 0 -2292 0 -2293 0 -2294 0 -2295 0 -2296 0 -2297 0 -2298 1 -2299 0 -2300 0 -2301 0 -2302 0 -2303 0 -2304 0 -2305 0 -2306 1 -2307 0 -2308 0 -2309 0 -2310 0 -2311 0 -2312 0 -2313 0 -2314 0 -2315 1 -2316 0 -2317 0 -2318 0 -2319 0 -2320 0 -2321 0 -2322 0 -2323 0 -2324 0 -2325 1 -2326 0 -2327 0 -2328 0 -2329 0 -2330 0 -2331 0 -2332 0 -2333 0 -2334 0 -2335 1 -2336 0 -2337 0 -2338 0 -2339 0 -2340 0 -2341 0 -2342 0 -2343 0 -2344 0 -2345 1 -2346 0 -2347 0 -2348 0 -2349 0 -2350 0 -2351 0 -2352 0 -2353 1 -2354 0 -2355 0 -2356 0 -2357 0 -2358 0 -2359 0 -2360 0 -2361 1 -2362 0 -2363 0 -2364 0 -2365 0 -2366 0 -2367 0 -2368 0 -2369 0 -2370 0 -2371 1 -2372 0 -2373 0 -2374 0 -2375 0 -2376 0 -2377 0 -2378 0 -2379 0 -2380 0 -2381 1 -2382 0 -2383 0 -2384 0 -2385 0 -2386 0 -2387 0 -2388 0 -2389 0 -2390 1 -2391 0 -2392 0 -2393 0 -2394 0 -2395 0 -2396 0 -2397 0 -2398 0 -2399 0 -2400 0 -2401 0 -2402 0 -2403 0 -2404 0 -2405 0 -2406 0 -2407 0 -2408 0 -2409 0 -2410 0 -2411 1 -2412 0 -2413 0 -2414 0 -2415 0 -2416 0 -2417 0 -2418 0 -2419 0 -2420 0 -2421 1 -2422 0 -2423 0 -2424 0 -2425 0 -2426 0 -2427 0 -2428 0 -2429 0 -2430 0 -2431 0 -2432 0 -2433 0 -2434 0 -2435 0 -2436 0 -2437 0 -2438 0 -2439 0 -2440 1 -2441 0 -2442 0 -2443 0 -2444 0 -2445 0 -2446 0 -2447 0 -2448 0 -2449 0 -2450 0 -2451 1 -2452 0 -2453 0 -2454 0 -2455 0 -2456 0 -2457 0 -2458 0 -2459 0 -2460 0 -2461 1 -2462 0 -2463 0 -2464 0 -2465 0 -2466 0 -2467 0 -2468 0 -2469 1 -2470 0 -2471 0 -2472 0 -2473 0 -2474 0 -2475 0 -2476 0 -2477 1 -2478 0 -2479 0 -2480 0 -2481 0 -2482 0 -2483 0 -2484 0 -2485 0 -2486 1 -2487 0 -2488 0 -2489 0 -2490 0 -2491 0 -2492 0 -2493 0 -2494 0 -2495 0 -2496 1 -2497 0 -2498 0 -2499 0 -2500 0 -2501 0 -2502 0 -2503 0 -2504 0 -2505 0 -2506 1 -2507 0 -2508 0 -2509 0 -2510 0 -2511 0 -2512 0 -2513 0 -2514 0 -2515 0 -2516 1 -2517 0 -2518 0 -2519 0 -2520 0 -2521 0 -2522 0 -2523 0 -2524 0 -2525 0 -2526 0 -2527 1 -2528 0 -2529 0 -2530 0 -2531 0 -2532 0 -2533 0 -2534 0 -2535 0 -2536 0 -2537 1 -2538 0 -2539 0 -2540 0 -2541 0 -2542 0 -2543 0 -2544 0 -2545 0 -2546 0 -2547 0 -2548 0 -2549 0 -2550 0 -2551 0 -2552 0 -2553 0 -2554 0 -2555 0 -2556 0 -2557 1 -2558 0 -2559 0 -2560 0 -2561 0 -2562 0 -2563 0 -2564 0 -2565 0 -2566 1 -2567 0 -2568 0 -2569 0 -2570 0 -2571 0 -2572 0 -2573 0 -2574 0 -2575 1 -2576 0 -2577 0 -2578 0 -2579 0 -2580 0 -2581 0 -2582 0 -2583 0 -2584 1 -2585 0 -2586 0 -2587 0 -2588 0 -2589 0 -2590 0 -2591 0 -2592 0 -2593 0 -2594 0 -2595 1 -2596 0 -2597 0 -2598 0 -2599 0 -2600 0 -2601 0 -2602 0 -2603 0 -2604 0 -2605 1 -2606 0 -2607 0 -2608 0 -2609 0 -2610 0 -2611 0 -2612 0 -2613 0 -2614 0 -2615 0 -2616 0 -2617 0 -2618 0 -2619 0 -2620 0 -2621 0 -2622 0 -2623 0 -2624 0 -2625 1 -2626 0 -2627 0 -2628 0 -2629 0 -2630 0 -2631 0 -2632 0 -2633 0 -2634 0 -2635 1 -2636 0 -2637 0 -2638 0 -2639 1 -2640 0 -2641 0 -2642 0 -2643 1 -2644 0 -2645 0 -2646 0 -2647 0 -2648 0 -2649 0 -2650 0 -2651 0 -2652 0 -2653 1 -2654 0 -2655 0 -2656 0 -2657 0 -2658 0 -2659 0 -2660 0 -2661 0 -2662 0 -2663 1 -2664 0 -2665 0 -2666 0 -2667 0 -2668 0 -2669 0 -2670 0 -2671 1 -2672 0 -2673 0 -2674 0 -2675 0 -2676 0 -2677 0 -2678 0 -2679 1 -2680 0 -2681 0 -2682 0 -2683 0 -2684 0 -2685 0 -2686 0 -2687 0 -2688 0 -2689 1 -2690 0 -2691 0 -2692 0 -2693 0 -2694 0 -2695 0 -2696 0 -2697 0 -2698 0 -2699 1 -2700 0 -2701 0 -2702 0 -2703 0 -2704 0 -2705 0 -2706 0 -2707 0 -2708 0 -2709 1 -2710 0 -2711 0 -2712 0 -2713 0 -2714 0 -2715 0 -2716 1 -2717 0 -2718 0 -2719 0 -2720 0 -2721 0 -2722 0 -2723 0 -2724 1 -2725 0 -2726 0 -2727 0 -2728 0 -2729 0 -2730 0 -2731 0 -2732 0 -2733 0 -2734 1 -2735 0 -2736 0 -2737 0 -2738 0 -2739 0 -2740 0 -2741 0 -2742 0 -2743 0 -2744 1 -2745 0 -2746 0 -2747 0 -2748 0 -2749 0 -2750 0 -2751 0 -2752 0 -2753 1 -2754 0 -2755 0 -2756 0 -2757 0 -2758 0 -2759 0 -2760 0 -2761 0 -2762 0 -2763 1 -2764 0 -2765 0 -2766 0 -2767 0 -2768 0 -2769 0 -2770 0 -2771 0 -2772 0 -2773 1 -2774 0 -2775 0 -2776 0 -2777 0 -2778 0 -2779 0 -2780 0 -2781 0 -2782 0 -2783 1 -2784 0 -2785 0 -2786 0 -2787 0 -2788 0 -2789 0 -2790 0 -2791 0 -2792 1 -2793 0 -2794 0 -2795 0 -2796 0 -2797 0 -2798 0 -2799 0 -2800 0 -2801 0 -2802 0 -2803 0 -2804 0 -2805 0 -2806 0 -2807 0 -2808 0 -2809 0 -2810 0 -2811 0 -2812 0 -2813 0 -2814 0 -2815 0 -2816 0 -2817 0 -2818 0 -2819 0 -2820 0 -2821 1 -2822 0 -2823 0 -2824 0 -2825 0 -2826 0 -2827 0 -2828 0 -2829 0 -2830 0 -2831 1 -2832 0 -2833 0 -2834 0 -2835 0 -2836 0 -2837 0 -2838 0 -2839 0 -2840 0 -2841 1 -2842 0 -2843 0 -2844 0 -2845 0 -2846 0 -2847 0 -2848 0 -2849 0 -2850 0 -2851 1 -2852 0 -2853 0 -2854 0 -2855 0 -2856 0 -2857 0 -2858 0 -2859 0 -2860 0 -2861 1 -2862 0 -2863 0 -2864 0 -2865 0 -2866 0 -2867 0 -2868 0 -2869 0 -2870 0 -2871 1 -2872 0 -2873 0 -2874 0 -2875 0 -2876 0 -2877 0 -2878 0 -2879 0 -2880 1 -2881 0 -2882 0 -2883 0 -2884 0 -2885 0 -2886 0 -2887 0 -2888 1 -2889 0 -2890 0 -2891 0 -2892 0 -2893 0 -2894 0 -2895 0 -2896 0 -2897 1 -2898 0 -2899 0 -2900 0 -2901 0 -2902 0 -2903 0 -2904 0 -2905 0 -2906 1 -2907 0 -2908 0 -2909 0 -2910 0 -2911 0 -2912 0 -2913 0 -2914 1 -2915 0 -2916 0 -2917 0 -2918 0 -2919 0 -2920 0 -2921 0 -2922 1 -2923 0 -2924 0 -2925 0 -2926 0 -2927 0 -2928 0 -2929 0 -2930 0 -2931 0 -2932 0 -2933 0 -2934 0 -2935 0 -2936 0 -2937 0 -2938 1 -2939 0 -2940 0 -2941 0 -2942 0 -2943 0 -2944 0 -2945 0 -2946 0 -2947 0 -2948 0 -2949 1 -2950 0 -2951 0 -2952 0 -2953 0 -2954 0 -2955 0 -2956 0 -2957 0 -2958 0 -2959 1 -2960 0 -2961 0 -2962 0 -2963 0 -2964 0 -2965 0 -2966 0 -2967 0 -2968 1 -2969 0 -2970 0 -2971 0 -2972 0 -2973 0 -2974 0 -2975 0 -2976 0 -2977 1 -2978 0 -2979 0 -2980 0 -2981 0 -2982 0 -2983 0 -2984 0 -2985 0 -2986 0 -2987 1 -2988 0 -2989 0 -2990 0 -2991 0 -2992 0 -2993 0 -2994 0 -2995 0 -2996 0 -2997 1 -2998 0 -2999 0 -3000 0 -3001 0 -3002 0 -3003 0 -3004 0 -3005 0 -3006 0 -3007 0 -3008 0 -3009 0 -3010 0 -3011 0 -3012 0 -3013 0 -3014 0 -3015 1 -3016 0 -3017 0 -3018 0 -3019 0 -3020 0 -3021 0 -3022 0 -3023 0 -3024 0 -3025 1 -3026 0 -3027 0 -3028 0 -3029 0 -3030 0 -3031 0 -3032 0 -3033 0 -3034 1 -3035 0 -3036 0 -3037 0 -3038 0 -3039 0 -3040 0 -3041 0 -3042 1 -3043 0 -3044 0 -3045 0 -3046 0 -3047 0 -3048 0 -3049 0 -3050 0 -3051 0 -3052 1 -3053 0 -3054 0 -3055 0 -3056 0 -3057 0 -3058 0 -3059 0 -3060 0 -3061 0 -3062 1 -3063 0 -3064 0 -3065 0 -3066 0 -3067 0 -3068 0 -3069 0 -3070 0 -3071 0 -3072 1 -3073 0 -3074 0 -3075 0 -3076 0 -3077 0 -3078 0 -3079 0 -3080 0 -3081 0 -3082 1 -3083 0 -3084 0 -3085 0 -3086 0 -3087 0 -3088 0 -3089 0 -3090 0 -3091 0 -3092 1 -3093 0 -3094 0 -3095 0 -3096 0 -3097 0 -3098 0 -3099 0 -3100 0 -3101 0 -3102 1 -3103 0 -3104 0 -3105 0 -3106 0 -3107 0 -3108 0 -3109 0 -3110 0 -3111 0 -3112 1 -3113 0 -3114 0 -3115 0 -3116 0 -3117 0 -3118 0 -3119 0 -3120 1 -3121 0 -3122 0 -3123 0 -3124 0 -3125 0 -3126 0 -3127 0 -3128 0 -3129 1 -3130 0 -3131 0 -3132 0 -3133 0 -3134 0 -3135 0 -3136 0 -3137 0 -3138 0 -3139 1 -3140 0 -3141 0 -3142 0 -3143 0 -3144 0 -3145 0 -3146 0 -3147 0 -3148 0 -3149 1 -3150 0 -3151 0 -3152 0 -3153 0 -3154 0 -3155 0 -3156 0 -3157 1 -3158 0 -3159 0 -3160 0 -3161 0 -3162 0 -3163 0 -3164 0 -3165 1 -3166 0 -3167 0 -3168 0 -3169 0 -3170 0 -3171 0 -3172 0 -3173 0 -3174 0 -3175 1 -3176 0 -3177 0 -3178 0 -3179 0 -3180 0 -3181 0 -3182 0 -3183 0 -3184 0 -3185 1 -3186 0 -3187 0 -3188 0 -3189 0 -3190 0 -3191 0 -3192 0 -3193 0 -3194 0 -3195 0 -3196 1 -3197 0 -3198 0 -3199 0 -3200 0 -3201 0 -3202 0 -3203 0 -3204 0 -3205 0 -3206 0 -3207 1 -3208 0 -3209 0 -3210 0 -3211 0 -3212 0 -3213 0 -3214 0 -3215 1 -3216 0 -3217 0 -3218 0 -3219 0 -3220 0 -3221 0 -3222 0 -3223 1 -3224 0 -3225 0 -3226 0 -3227 0 -3228 0 -3229 0 -3230 0 -3231 0 -3232 1 -3233 0 -3234 1 -3235 0 -3236 0 -3237 0 -3238 0 -3239 1 -3240 0 -3241 0 -3242 0 -3243 0 -3244 0 -3245 0 -3246 0 -3247 0 -3248 1 -3249 0 -3250 0 -3251 0 -3252 0 -3253 0 -3254 0 -3255 0 -3256 0 -3257 0 -3258 1 -3259 0 -3260 0 -3261 0 -3262 0 -3263 0 -3264 0 -3265 0 -3266 0 -3267 0 -3268 0 -3269 1 -3270 0 -3271 0 -3272 0 -3273 0 -3274 0 -3275 0 -3276 0 -3277 0 -3278 1 -3279 0 -3280 0 -3281 0 -3282 0 -3283 0 -3284 0 -3285 0 -3286 0 -3287 1 -3288 0 -3289 0 -3290 0 -3291 0 -3292 0 -3293 0 -3294 0 -3295 0 -3296 0 -3297 1 -3298 0 -3299 0 -3300 0 -3301 0 -3302 0 -3303 0 -3304 0 -3305 0 -3306 0 -3307 1 -3308 0 -3309 0 -3310 0 -3311 0 -3312 0 -3313 0 -3314 0 -3315 0 -3316 0 -3317 1 -3318 0 -3319 0 -3320 0 -3321 0 -3322 0 -3323 0 -3324 0 -3325 1 -3326 0 -3327 0 -3328 0 -3329 0 -3330 0 -3331 0 -3332 0 -3333 0 -3334 0 -3335 1 -3336 0 -3337 0 -3338 0 -3339 0 -3340 0 -3341 0 -3342 0 -3343 0 -3344 1 -3345 0 -3346 0 -3347 0 -3348 0 -3349 0 -3350 0 -3351 0 -3352 0 -3353 0 -3354 1 -3355 0 -3356 0 -3357 0 -3358 0 -3359 0 -3360 0 -3361 0 -3362 0 -3363 0 -3364 0 -3365 1 -3366 0 -3367 0 -3368 0 -3369 0 -3370 0 -3371 0 -3372 0 -3373 0 -3374 0 -3375 1 -3376 0 -3377 0 -3378 0 -3379 0 -3380 0 -3381 0 -3382 0 -3383 0 -3384 0 -3385 0 -3386 1 -3387 0 -3388 0 -3389 0 -3390 0 -3391 0 -3392 0 -3393 0 -3394 0 -3395 0 -3396 0 -3397 1 -3398 0 -3399 0 -3400 0 -3401 0 -3402 0 -3403 0 -3404 0 -3405 0 -3406 0 -3407 1 -3408 0 -3409 0 -3410 0 -3411 0 -3412 0 -3413 0 -3414 0 -3415 0 -3416 0 -3417 1 -3418 0 -3419 0 -3420 0 -3421 0 -3422 0 -3423 0 -3424 0 -3425 0 -3426 0 -3427 0 -3428 1 -3429 0 -3430 0 -3431 0 -3432 0 -3433 0 -3434 0 -3435 0 -3436 0 -3437 1 -3438 0 -3439 0 -3440 0 -3441 0 -3442 0 -3443 0 -3444 0 -3445 1 -3446 0 -3447 0 -3448 0 -3449 0 -3450 0 -3451 0 -3452 0 -3453 0 -3454 1 -3455 0 -3456 0 -3457 0 -3458 0 -3459 0 -3460 0 -3461 0 -3462 0 -3463 0 -3464 1 -3465 0 -3466 0 -3467 0 -3468 0 -3469 0 -3470 0 -3471 0 -3472 0 -3473 0 -3474 1 -3475 0 -3476 0 -3477 0 -3478 0 -3479 0 -3480 0 -3481 0 -3482 0 -3483 0 -3484 1 -3485 0 -3486 0 -3487 0 -3488 0 -3489 0 -3490 0 -3491 0 -3492 0 -3493 0 -3494 1 -3495 0 -3496 0 -3497 0 -3498 0 -3499 0 -3500 0 -3501 0 -3502 0 -3503 0 -3504 1 -3505 0 -3506 0 -3507 0 -3508 0 -3509 0 -3510 0 -3511 0 -3512 0 -3513 0 -3514 1 -3515 0 -3516 0 -3517 0 -3518 0 -3519 0 -3520 0 -3521 0 -3522 0 -3523 0 -3524 1 -3525 0 -3526 0 -3527 0 -3528 0 -3529 0 -3530 0 -3531 0 -3532 0 -3533 1 -3534 0 -3535 0 -3536 0 -3537 0 -3538 0 -3539 0 -3540 0 -3541 0 -3542 0 -3543 0 -3544 0 -3545 0 -3546 0 -3547 0 -3548 0 -3549 0 -3550 0 -3551 1 -3552 0 -3553 0 -3554 0 -3555 0 -3556 0 -3557 0 -3558 0 -3559 0 -3560 0 -3561 1 -3562 0 -3563 0 -3564 0 -3565 0 -3566 0 -3567 0 -3568 0 -3569 0 -3570 1 -3571 0 -3572 0 -3573 0 -3574 0 -3575 0 -3576 0 -3577 0 -3578 0 -3579 0 -3580 1 -3581 0 -3582 0 -3583 0 -3584 0 -3585 0 -3586 0 -3587 0 -3588 0 -3589 0 -3590 1 -3591 0 -3592 0 -3593 0 -3594 0 -3595 0 -3596 0 -3597 0 -3598 0 -3599 1 -3600 0 -3601 0 -3602 0 -3603 0 -3604 0 -3605 0 -3606 0 -3607 0 -3608 0 -3609 1 -3610 0 -3611 0 -3612 0 -3613 0 -3614 0 -3615 0 -3616 0 -3617 0 -3618 0 -3619 0 -3620 1 -3621 0 -3622 0 -3623 0 -3624 0 -3625 0 -3626 0 -3627 0 -3628 0 -3629 0 -3630 1 -3631 0 -3632 0 -3633 0 -3634 0 -3635 0 -3636 0 -3637 0 -3638 0 -3639 1 -3640 0 -3641 0 -3642 0 -3643 0 -3644 0 -3645 1 -3646 0 -3647 0 -3648 0 -3649 0 -3650 0 -3651 1 -3652 0 -3653 0 -3654 0 -3655 0 -3656 0 -3657 0 -3658 1 -3659 0 -3660 0 -3661 0 -3662 0 -3663 0 -3664 0 -3665 0 -3666 1 -3667 0 -3668 0 -3669 0 -3670 0 -3671 0 -3672 0 -3673 0 -3674 0 -3675 0 -3676 1 -3677 0 -3678 0 -3679 0 -3680 0 -3681 0 -3682 0 -3683 0 -3684 0 -3685 1 -3686 0 -3687 0 -3688 0 -3689 0 -3690 0 -3691 0 -3692 0 -3693 0 -3694 0 -3695 1 -3696 0 -3697 0 -3698 0 -3699 0 -3700 0 -3701 0 -3702 0 -3703 0 -3704 0 -3705 0 -3706 1 -3707 0 -3708 0 -3709 0 -3710 0 -3711 0 -3712 0 -3713 0 -3714 0 -3715 0 -3716 1 -3717 0 -3718 0 -3719 0 -3720 0 -3721 0 -3722 0 -3723 0 -3724 0 -3725 0 -3726 0 -3727 0 -3728 0 -3729 0 -3730 0 -3731 0 -3732 0 -3733 0 -3734 0 -3735 0 -3736 1 -3737 0 -3738 0 -3739 0 -3740 0 -3741 0 -3742 0 -3743 0 -3744 0 -3745 0 -3746 1 -3747 0 -3748 0 -3749 0 -3750 0 -3751 0 -3752 0 -3753 0 -3754 0 -3755 0 -3756 1 -3757 0 -3758 0 -3759 0 -3760 0 -3761 0 -3762 0 -3763 1 -3764 0 -3765 0 -3766 0 -3767 0 -3768 0 -3769 0 -3770 0 -3771 1 -3772 0 -3773 0 -3774 0 -3775 0 -3776 0 -3777 0 -3778 1 -3779 0 -3780 0 -3781 0 -3782 0 -3783 0 -3784 0 -3785 0 -3786 0 -3787 0 -3788 0 -3789 0 -3790 0 -3791 0 -3792 0 -3793 0 -3794 0 -3795 0 -3796 0 -3797 1 -3798 0 -3799 0 -3800 0 -3801 0 -3802 0 -3803 0 -3804 0 -3805 0 -3806 1 -3807 0 -3808 0 -3809 0 -3810 0 -3811 0 -3812 0 -3813 0 -3814 0 -3815 0 -3816 0 -3817 1 -3818 0 -3819 0 -3820 0 -3821 0 -3822 0 -3823 0 -3824 0 -3825 0 -3826 0 -3827 1 -3828 0 -3829 1 -3830 0 -3831 0 -3832 0 -3833 0 -3834 1 -3835 0 -3836 0 -3837 0 -3838 0 -3839 0 -3840 0 -3841 0 -3842 0 -3843 0 -3844 0 -3845 1 -3846 0 -3847 0 -3848 0 -3849 0 -3850 0 -3851 0 -3852 0 -3853 0 -3854 0 -3855 1 -3856 0 -3857 0 -3858 0 -3859 0 -3860 0 -3861 0 -3862 0 -3863 1 -3864 0 -3865 0 -3866 0 -3867 0 -3868 0 -3869 0 -3870 0 -3871 0 -3872 0 -3873 1 -3874 0 -3875 0 -3876 0 -3877 0 -3878 0 -3879 0 -3880 0 -3881 0 -3882 0 -3883 1 -3884 0 -3885 0 -3886 0 -3887 0 -3888 0 -3889 0 -3890 0 -3891 0 -3892 0 -3893 0 -3894 1 -3895 0 -3896 0 -3897 0 -3898 0 -3899 0 -3900 0 -3901 0 -3902 0 -3903 0 -3904 0 -3905 1 -3906 0 -3907 0 -3908 0 -3909 0 -3910 0 -3911 0 -3912 0 -3913 0 -3914 1 -3915 0 -3916 0 -3917 0 -3918 0 -3919 0 -3920 0 -3921 0 -3922 0 -3923 0 -3924 0 -3925 1 -3926 0 -3927 0 -3928 0 -3929 0 -3930 0 -3931 0 -3932 0 -3933 0 -3934 1 -3935 0 -3936 0 -3937 0 -3938 0 -3939 0 -3940 0 -3941 0 -3942 0 -3943 0 -3944 0 -3945 1 -3946 0 -3947 0 -3948 0 -3949 0 -3950 0 -3951 0 -3952 0 -3953 0 -3954 0 -3955 1 -3956 0 -3957 0 -3958 0 -3959 0 -3960 0 -3961 0 -3962 0 -3963 0 -3964 0 -3965 0 -3966 1 -3967 0 -3968 0 -3969 0 -3970 0 -3971 0 -3972 0 -3973 0 -3974 0 -3975 1 -3976 0 -3977 0 -3978 0 -3979 0 -3980 0 -3981 0 -3982 0 -3983 0 -3984 1 -3985 0 -3986 0 -3987 0 -3988 0 -3989 0 -3990 0 -3991 0 -3992 0 -3993 0 -3994 1 -3995 0 -3996 0 -3997 0 -3998 0 -3999 0 -4000 0 -4001 0 -4002 0 -4003 0 -4004 0 -4005 0 -4006 0 -4007 0 -4008 0 -4009 0 -4010 0 -4011 0 -4012 0 -4013 0 -4014 1 -4015 0 -4016 0 -4017 0 -4018 0 -4019 0 -4020 0 -4021 0 -4022 0 -4023 0 -4024 1 -4025 0 -4026 0 -4027 0 -4028 0 -4029 0 -4030 0 -4031 0 -4032 0 -4033 0 -4034 0 -4035 1 -4036 0 -4037 0 -4038 0 -4039 0 -4040 0 -4041 0 -4042 0 -4043 0 -4044 0 -4045 1 -4046 0 -4047 0 -4048 0 -4049 0 -4050 0 -4051 0 -4052 0 -4053 0 -4054 0 -4055 0 -4056 1 -4057 0 -4058 0 -4059 0 -4060 0 -4061 0 -4062 0 -4063 0 -4064 0 -4065 0 -4066 1 -4067 0 -4068 0 -4069 0 -4070 0 -4071 0 -4072 0 -4073 0 -4074 1 -4075 0 -4076 0 -4077 0 -4078 0 -4079 0 -4080 0 -4081 0 -4082 0 -4083 0 -4084 1 -4085 0 -4086 0 -4087 0 -4088 0 -4089 0 -4090 0 -4091 0 -4092 0 -4093 1 -4094 0 -4095 0 -4096 0 -4097 0 -4098 0 -4099 0 -4100 0 -4101 0 -4102 1 -4103 0 -4104 0 -4105 0 -4106 0 -4107 0 -4108 0 -4109 0 -4110 0 -4111 0 -4112 1 -4113 0 -4114 0 -4115 0 -4116 0 -4117 0 -4118 0 -4119 0 -4120 0 -4121 0 -4122 1 -4123 0 -4124 0 -4125 0 -4126 0 -4127 0 -4128 0 -4129 0 -4130 0 -4131 0 -4132 0 -4133 1 -4134 0 -4135 0 -4136 0 -4137 0 -4138 0 -4139 0 -4140 0 -4141 0 -4142 0 -4143 0 -4144 1 -4145 0 -4146 0 -4147 0 -4148 0 -4149 0 -4150 0 -4151 0 -4152 0 -4153 0 -4154 1 -4155 0 -4156 0 -4157 0 -4158 0 -4159 0 -4160 0 -4161 0 -4162 0 -4163 0 -4164 0 -4165 1 -4166 0 -4167 0 -4168 0 -4169 0 -4170 0 -4171 0 -4172 0 -4173 0 -4174 0 -4175 0 -4176 1 -4177 0 -4178 0 -4179 0 -4180 0 -4181 0 -4182 0 -4183 0 -4184 0 -4185 1 -4186 0 -4187 0 -4188 0 -4189 0 -4190 0 -4191 0 -4192 0 -4193 0 -4194 0 -4195 1 -4196 0 -4197 0 -4198 0 -4199 0 -4200 0 -4201 0 -4202 0 -4203 0 -4204 0 -4205 0 -4206 0 -4207 0 -4208 0 -4209 0 -4210 0 -4211 0 -4212 1 -4213 0 -4214 0 -4215 0 -4216 0 -4217 0 -4218 0 -4219 0 -4220 0 -4221 1 -4222 0 -4223 0 -4224 0 -4225 0 -4226 0 -4227 0 -4228 0 -4229 0 -4230 1 -4231 0 -4232 0 -4233 0 -4234 0 -4235 0 -4236 0 -4237 0 -4238 0 -4239 1 -4240 0 -4241 0 -4242 0 -4243 0 -4244 0 -4245 0 -4246 0 -4247 0 -4248 0 -4249 1 -4250 0 -4251 0 -4252 0 -4253 0 -4254 0 -4255 0 -4256 0 -4257 0 -4258 1 -4259 0 -4260 0 -4261 0 -4262 0 -4263 0 -4264 0 -4265 0 -4266 0 -4267 0 -4268 1 -4269 0 -4270 0 -4271 0 -4272 0 -4273 0 -4274 0 -4275 0 -4276 0 -4277 0 -4278 1 -4279 0 -4280 0 -4281 0 -4282 0 -4283 0 -4284 0 -4285 0 -4286 0 -4287 0 -4288 0 -4289 1 -4290 0 -4291 0 -4292 0 -4293 0 -4294 0 -4295 0 -4296 0 -4297 0 -4298 0 -4299 1 -4300 0 -4301 0 -4302 0 -4303 0 -4304 0 -4305 0 -4306 0 -4307 0 -4308 0 -4309 1 -4310 0 -4311 0 -4312 0 -4313 0 -4314 0 -4315 0 -4316 0 -4317 0 -4318 1 -4319 0 -4320 0 -4321 0 -4322 0 -4323 0 -4324 0 -4325 0 -4326 0 -4327 1 -4328 0 -4329 0 -4330 0 -4331 0 -4332 0 -4333 0 -4334 0 -4335 0 -4336 0 -4337 1 -4338 0 -4339 0 -4340 0 -4341 0 -4342 0 -4343 0 -4344 0 -4345 0 -4346 0 -4347 1 -4348 0 -4349 0 -4350 0 -4351 0 -4352 0 -4353 0 -4354 0 -4355 1 -4356 0 -4357 0 -4358 0 -4359 0 -4360 0 -4361 0 -4362 0 -4363 0 -4364 0 -4365 0 -4366 0 -4367 0 -4368 0 -4369 0 -4370 0 -4371 0 -4372 0 -4373 0 -4374 1 -4375 0 -4376 0 -4377 0 -4378 0 -4379 0 -4380 0 -4381 0 -4382 0 -4383 0 -4384 1 -4385 0 -4386 0 -4387 0 -4388 0 -4389 0 -4390 0 -4391 0 -4392 0 -4393 1 -4394 0 -4395 0 -4396 0 -4397 0 -4398 0 -4399 0 -4400 0 -4401 0 -4402 0 -4403 1 -4404 0 -4405 0 -4406 0 -4407 0 -4408 0 -4409 0 -4410 0 -4411 0 -4412 1 -4413 0 -4414 0 -4415 0 -4416 0 -4417 0 -4418 0 -4419 0 -4420 0 -4421 0 -4422 0 -4423 1 -4424 0 -4425 0 -4426 0 -4427 0 -4428 0 -4429 0 -4430 2 -4431 0 -4432 0 -4433 0 -4434 0 -4435 0 -4436 0 -4437 1 -4438 0 -4439 0 -4440 0 -4441 0 -4442 0 -4443 0 -4444 0 -4445 1 -4446 0 -4447 0 -4448 0 -4449 0 -4450 0 -4451 0 -4452 0 -4453 0 -4454 1 -4455 0 -4456 0 -4457 0 -4458 0 -4459 0 -4460 0 -4461 0 -4462 1 -4463 0 -4464 0 -4465 0 -4466 0 -4467 0 -4468 0 -4469 0 -4470 0 -4471 1 -4472 0 -4473 0 -4474 0 -4475 0 -4476 0 -4477 0 -4478 0 -4479 0 -4480 1 -4481 0 -4482 0 -4483 0 -4484 0 -4485 0 -4486 0 -4487 0 -4488 1 -4489 0 -4490 0 -4491 0 -4492 0 -4493 0 -4494 0 -4495 0 -4496 0 -4497 1 -4498 0 -4499 0 -4500 0 -4501 0 -4502 0 -4503 0 -4504 0 -4505 1 -4506 0 -4507 0 -4508 0 -4509 0 -4510 0 -4511 0 -4512 0 -4513 1 -4514 0 -4515 0 -4516 0 -4517 0 -4518 0 -4519 0 -4520 1 -4521 0 -4522 0 -4523 0 -4524 0 -4525 0 -4526 0 -4527 0 -4528 0 -4529 1 -4530 0 -4531 0 -4532 0 -4533 0 -4534 0 -4535 0 -4536 0 -4537 0 -4538 1 -4539 0 -4540 0 -4541 0 -4542 0 -4543 0 -4544 0 -4545 0 -4546 1 -4547 0 -4548 0 -4549 0 -4550 0 -4551 0 -4552 1 -4553 0 -4554 0 -4555 0 -4556 0 -4557 0 -4558 0 -4559 1 -4560 0 -4561 0 -4562 0 -4563 0 -4564 0 -4565 0 -4566 0 -4567 1 -4568 0 -4569 0 -4570 0 -4571 0 -4572 0 -4573 0 -4574 0 -4575 1 -4576 0 -4577 0 -4578 0 -4579 0 -4580 0 -4581 0 -4582 0 -4583 1 -4584 0 -4585 0 -4586 0 -4587 0 -4588 0 -4589 0 -4590 0 -4591 1 -4592 0 -4593 0 -4594 0 -4595 0 -4596 0 -4597 0 -4598 0 -4599 0 -4600 1 -4601 0 -4602 0 -4603 0 -4604 0 -4605 0 -4606 0 -4607 1 -4608 0 -4609 0 -4610 0 -4611 0 -4612 0 -4613 0 -4614 0 -4615 0 -4616 1 -4617 0 -4618 0 -4619 0 -4620 0 -4621 0 -4622 0 -4623 0 -4624 0 -4625 1 -4626 0 -4627 0 -4628 0 -4629 0 -4630 0 -4631 0 -4632 0 -4633 0 -4634 1 -4635 0 -4636 0 -4637 0 -4638 0 -4639 0 -4640 0 -4641 0 -4642 0 -4643 0 -4644 0 -4645 0 -4646 0 -4647 0 -4648 0 -4649 0 -4650 0 -4651 0 -4652 1 -4653 0 -4654 0 -4655 0 -4656 0 -4657 0 -4658 0 -4659 0 -4660 0 -4661 1 -4662 0 -4663 0 -4664 0 -4665 1 -4666 0 -4667 0 -4668 0 -4669 0 -4670 0 -4671 0 -4672 1 -4673 0 -4674 0 -4675 0 -4676 0 -4677 0 -4678 1 -4679 0 -4680 0 -4681 0 -4682 0 -4683 0 -4684 0 -4685 0 -4686 1 -4687 0 -4688 0 -4689 0 -4690 0 -4691 0 -4692 0 -4693 0 -4694 1 -4695 0 -4696 0 -4697 0 -4698 0 -4699 0 -4700 0 -4701 0 -4702 1 -4703 0 -4704 0 -4705 0 -4706 0 -4707 0 -4708 0 -4709 1 -4710 0 -4711 0 -4712 0 -4713 0 -4714 0 -4715 0 -4716 0 -4717 1 -4718 0 -4719 0 -4720 0 -4721 0 -4722 0 -4723 0 -4724 0 -4725 1 -4726 0 -4727 0 -4728 0 -4729 0 -4730 0 -4731 0 -4732 0 -4733 0 -4734 1 -4735 0 -4736 0 -4737 0 -4738 0 -4739 0 -4740 0 -4741 0 -4742 0 -4743 0 -4744 1 -4745 0 -4746 0 -4747 0 -4748 0 -4749 0 -4750 0 -4751 0 -4752 1 -4753 0 -4754 0 -4755 0 -4756 0 -4757 0 -4758 0 -4759 0 -4760 1 -4761 0 -4762 0 -4763 0 -4764 0 -4765 0 -4766 0 -4767 0 -4768 0 -4769 1 -4770 0 -4771 0 -4772 0 -4773 0 -4774 0 -4775 0 -4776 0 -4777 0 -4778 1 -4779 0 -4780 0 -4781 0 -4782 0 -4783 0 -4784 0 -4785 0 -4786 1 -4787 0 -4788 0 -4789 0 -4790 0 -4791 0 -4792 0 -4793 0 -4794 0 -4795 0 -4796 1 -4797 0 -4798 0 -4799 0 -4800 0 -4801 0 -4802 0 -4803 0 -4804 1 -4805 0 -4806 0 -4807 0 -4808 0 -4809 0 -4810 0 -4811 0 -4812 0 -4813 1 -4814 0 -4815 0 -4816 0 -4817 0 -4818 0 -4819 0 -4820 0 -4821 0 -4822 1 -4823 0 -4824 0 -4825 0 -4826 0 -4827 0 -4828 0 -4829 0 -4830 0 -4831 1 -4832 0 -4833 0 -4834 0 -4835 0 -4836 0 -4837 0 -4838 0 -4839 0 -4840 0 -4841 0 -4842 0 -4843 0 -4844 0 -4845 0 -4846 0 -4847 0 -4848 0 -4849 0 -4850 0 -4851 0 -4852 0 -4853 0 -4854 0 -4855 0 -4856 0 -4857 0 -4858 0 -4859 0 -4860 0 -4861 0 -4862 0 -4863 0 -4864 0 -4865 1 -4866 0 -4867 0 -4868 0 -4869 0 -4870 0 -4871 0 -4872 1 -4873 0 -4874 0 -4875 0 -4876 0 -4877 0 -4878 0 -4879 0 -4880 1 -4881 0 -4882 0 -4883 0 -4884 0 -4885 0 -4886 0 -4887 0 -4888 0 -4889 0 -4890 1 -4891 0 -4892 0 -4893 0 -4894 0 -4895 0 -4896 0 -4897 0 -4898 1 -4899 0 -4900 0 -4901 0 -4902 0 -4903 0 -4904 0 -4905 1 -4906 0 -4907 0 -4908 0 -4909 0 -4910 0 -4911 0 -4912 0 -4913 1 -4914 0 -4915 0 -4916 0 -4917 0 -4918 0 -4919 0 -4920 0 -4921 0 -4922 0 -4923 1 -4924 0 -4925 0 -4926 0 -4927 0 -4928 0 -4929 0 -4930 0 -4931 0 -4932 0 -4933 1 -4934 0 -4935 0 -4936 0 -4937 0 -4938 0 -4939 0 -4940 0 -4941 0 -4942 0 -4943 0 -4944 0 -4945 0 -4946 0 -4947 0 -4948 1 -4949 0 -4950 0 -4951 0 -4952 0 -4953 0 -4954 0 -4955 0 -4956 1 -4957 0 -4958 0 -4959 0 -4960 0 -4961 0 -4962 0 -4963 0 -4964 1 -4965 0 -4966 0 -4967 0 -4968 0 -4969 0 -4970 0 -4971 0 -4972 1 -4973 0 -4974 0 -4975 0 -4976 0 -4977 0 -4978 0 -4979 1 -4980 0 -4981 0 -4982 0 -4983 0 -4984 0 -4985 0 -4986 0 -4987 1 -4988 0 -4989 0 -4990 0 -4991 0 -4992 0 -4993 0 -4994 1 -4995 0 -4996 0 -4997 0 -4998 0 -4999 0 -5000 0 -5001 0 -5002 0 -5003 1 -5004 0 -5005 0 -5006 0 -5007 0 -5008 0 -5009 0 -5010 0 -5011 0 -5012 1 -5013 0 -5014 0 -5015 0 -5016 0 -5017 0 -5018 0 -5019 0 -5020 1 -5021 0 -5022 0 -5023 0 -5024 0 -5025 0 -5026 0 -5027 0 -5028 0 -5029 1 -5030 0 -5031 0 -5032 0 -5033 0 -5034 0 -5035 0 -5036 0 -5037 1 -5038 0 -5039 0 -5040 0 -5041 0 -5042 0 -5043 0 -5044 0 -5045 1 -5046 0 -5047 0 -5048 0 -5049 0 -5050 0 -5051 0 -5052 0 -5053 1 -5054 0 -5055 0 -5056 0 -5057 0 -5058 0 -5059 0 -5060 0 -5061 0 -5062 1 -5063 0 -5064 0 -5065 0 -5066 0 -5067 0 -5068 0 -5069 0 -5070 0 -5071 0 -5072 0 -5073 0 -5074 0 -5075 0 -5076 0 -5077 0 -5078 0 -5079 1 -5080 0 -5081 0 -5082 0 -5083 0 -5084 0 -5085 0 -5086 1 -5087 0 -5088 0 -5089 0 -5090 0 -5091 0 -5092 0 -5093 0 -5094 1 -5095 0 -5096 0 -5097 0 -5098 0 -5099 0 -5100 0 -5101 0 -5102 0 -5103 1 -5104 0 -5105 0 -5106 0 -5107 0 -5108 0 -5109 0 -5110 1 -5111 0 -5112 0 -5113 0 -5114 0 -5115 0 -5116 0 -5117 0 -5118 1 -5119 0 -5120 0 -5121 0 -5122 0 -5123 0 -5124 0 -5125 0 -5126 0 -5127 1 -5128 0 -5129 0 -5130 0 -5131 0 -5132 0 -5133 0 -5134 1 -5135 0 -5136 0 -5137 0 -5138 0 -5139 0 -5140 0 -5141 1 -5142 0 -5143 0 -5144 0 -5145 0 -5146 0 -5147 0 -5148 0 -5149 1 -5150 0 -5151 0 -5152 0 -5153 0 -5154 0 -5155 0 -5156 0 -5157 0 -5158 1 -5159 0 -5160 0 -5161 0 -5162 0 -5163 0 -5164 0 -5165 0 -5166 0 -5167 1 -5168 0 -5169 0 -5170 0 -5171 0 -5172 0 -5173 0 -5174 0 -5175 1 -5176 0 -5177 0 -5178 0 -5179 0 -5180 0 -5181 0 -5182 1 -5183 0 -5184 0 -5185 0 -5186 0 -5187 0 -5188 0 -5189 0 -5190 1 -5191 0 -5192 0 -5193 0 -5194 0 -5195 0 -5196 0 -5197 0 -5198 0 -5199 1 -5200 0 -5201 0 -5202 0 -5203 0 -5204 0 -5205 0 -5206 0 -5207 0 -5208 1 -5209 0 -5210 0 -5211 0 -5212 0 -5213 0 -5214 0 -5215 0 -5216 0 -5217 0 -5218 1 -5219 0 -5220 0 -5221 0 -5222 0 -5223 0 -5224 0 -5225 0 -5226 1 -5227 0 -5228 0 -5229 0 -5230 0 -5231 0 -5232 0 -5233 0 -5234 1 -5235 0 -5236 0 -5237 0 -5238 0 -5239 0 -5240 0 -5241 0 -5242 1 -5243 0 -5244 0 -5245 0 -5246 0 -5247 0 -5248 0 -5249 0 -5250 0 -5251 1 -5252 0 -5253 0 -5254 0 -5255 0 -5256 0 -5257 0 -5258 0 -5259 0 -5260 0 -5261 0 -5262 0 -5263 0 -5264 0 -5265 0 -5266 0 -5267 0 -5268 1 -5269 0 -5270 0 -5271 0 -5272 0 -5273 0 -5274 0 -5275 0 -5276 1 -5277 0 -5278 0 -5279 0 -5280 0 -5281 0 -5282 0 -5283 1 -5284 0 -5285 0 -5286 0 -5287 0 -5288 0 -5289 0 -5290 0 -5291 0 -5292 0 -5293 1 -5294 0 -5295 0 -5296 0 -5297 0 -5298 0 -5299 0 -5300 0 -5301 1 -5302 0 -5303 0 -5304 0 -5305 0 -5306 0 -5307 0 -5308 0 -5309 0 -5310 1 -5311 0 -5312 0 -5313 0 -5314 0 -5315 0 -5316 0 -5317 0 -5318 1 -5319 0 -5320 0 -5321 0 -5322 0 -5323 0 -5324 0 -5325 1 -5326 0 -5327 0 -5328 0 -5329 0 -5330 0 -5331 0 -5332 0 -5333 0 -5334 0 -5335 0 -5336 0 -5337 0 -5338 0 -5339 0 -5340 0 -5341 0 -5342 1 -5343 0 -5344 0 -5345 0 -5346 0 -5347 0 -5348 0 -5349 1 -5350 0 -5351 0 -5352 0 -5353 0 -5354 0 -5355 0 -5356 0 -5357 0 -5358 1 -5359 0 -5360 0 -5361 0 -5362 0 -5363 0 -5364 0 -5365 0 -5366 1 -5367 0 -5368 0 -5369 0 -5370 0 -5371 0 -5372 0 -5373 1 -5374 0 -5375 0 -5376 0 -5377 0 -5378 0 -5379 0 -5380 0 -5381 1 -5382 0 -5383 0 -5384 0 -5385 0 -5386 0 -5387 0 -5388 0 -5389 0 -5390 1 -5391 0 -5392 0 -5393 0 -5394 0 -5395 0 -5396 0 -5397 0 -5398 1 -5399 0 -5400 0 -5401 0 -5402 0 -5403 0 -5404 0 -5405 0 -5406 1 -5407 0 -5408 0 -5409 0 -5410 0 -5411 0 -5412 0 -5413 0 -5414 1 -5415 0 -5416 0 -5417 0 -5418 0 -5419 0 -5420 0 -5421 0 -5422 1 -5423 0 -5424 0 -5425 0 -5426 0 -5427 0 -5428 0 -5429 0 -5430 0 -5431 0 -5432 0 -5433 0 -5434 0 -5435 0 -5436 0 -5437 0 -5438 1 -5439 0 -5440 0 -5441 0 -5442 0 -5443 0 -5444 0 -5445 0 -5446 0 -5447 1 -5448 0 -5449 0 -5450 0 -5451 0 -5452 0 -5453 0 -5454 0 -5455 0 -5456 1 -5457 0 -5458 0 -5459 0 -5460 0 -5461 0 -5462 0 -5463 0 -5464 1 -5465 0 -5466 0 -5467 0 -5468 0 -5469 0 -5470 0 -5471 0 -5472 1 -5473 0 -5474 0 -5475 0 -5476 0 -5477 0 -5478 0 -5479 0 -5480 0 -5481 1 -5482 0 -5483 0 -5484 0 -5485 0 -5486 0 -5487 0 -5488 0 -5489 1 -5490 0 -5491 0 -5492 0 -5493 0 -5494 0 -5495 0 -5496 0 -5497 0 -5498 1 -5499 0 -5500 0 -5501 0 -5502 0 -5503 0 -5504 0 -5505 0 -5506 1 -5507 0 -5508 0 -5509 0 -5510 0 -5511 0 -5512 0 -5513 0 -5514 1 -5515 0 -5516 0 -5517 0 -5518 0 -5519 0 -5520 0 -5521 0 -5522 0 -5523 1 -5524 0 -5525 0 -5526 0 -5527 0 -5528 0 -5529 0 -5530 0 -5531 1 -5532 0 -5533 0 -5534 0 -5535 0 -5536 0 -5537 0 -5538 0 -5539 0 -5540 1 -5541 0 -5542 0 -5543 0 -5544 0 -5545 0 -5546 0 -5547 0 -5548 0 -5549 1 -5550 0 -5551 0 -5552 0 -5553 0 -5554 0 -5555 0 -5556 0 -5557 0 -5558 0 -5559 0 -5560 0 -5561 0 -5562 0 -5563 0 -5564 0 -5565 1 -5566 0 -5567 0 -5568 0 -5569 0 -5570 0 -5571 1 -5572 0 -5573 0 -5574 0 -5575 0 -5576 0 -5577 0 -5578 0 -5579 1 -5580 0 -5581 0 -5582 0 -5583 0 -5584 0 -5585 0 -5586 0 -5587 0 -5588 1 -5589 0 -5590 0 -5591 0 -5592 0 -5593 0 -5594 0 -5595 0 -5596 1 -5597 0 -5598 0 -5599 0 -5600 0 -5601 0 -5602 0 -5603 0 -5604 0 -5605 0 -5606 1 -5607 0 -5608 0 -5609 0 -5610 0 -5611 0 -5612 0 -5613 0 -5614 1 -5615 0 -5616 0 -5617 0 -5618 0 -5619 0 -5620 0 -5621 0 -5622 1 -5623 0 -5624 0 -5625 0 -5626 0 -5627 0 -5628 0 -5629 0 -5630 0 -5631 0 -5632 0 -5633 0 -5634 0 -5635 0 -5636 0 -5637 0 -5638 1 -5639 0 -5640 0 -5641 0 -5642 0 -5643 0 -5644 0 -5645 0 -5646 0 -5647 1 -5648 0 -5649 0 -5650 0 -5651 0 -5652 0 -5653 0 -5654 1 -5655 0 -5656 0 -5657 0 -5658 0 -5659 0 -5660 0 -5661 0 -5662 1 -5663 0 -5664 0 -5665 0 -5666 0 -5667 0 -5668 0 -5669 0 -5670 1 -5671 0 -5672 0 -5673 0 -5674 0 -5675 0 -5676 0 -5677 0 -5678 0 -5679 1 -5680 2 -5681 1 -5682 0 -5683 0 -5684 0 -5685 0 -5686 0 -5687 1 -5688 0 -5689 0 -5690 0 -5691 0 -5692 1 -5693 0 -5694 0 -5695 0 -5696 0 -5697 1 -5698 0 -5699 0 -5700 0 -5701 0 -5702 0 -5703 0 -5704 0 -5705 1 -5706 0 -5707 0 -5708 0 -5709 0 -5710 0 -5711 1 -5712 0 -5713 0 -5714 0 -5715 0 -5716 0 -5717 0 -5718 0 -5719 0 -5720 0 -5721 0 -5722 0 -5723 0 -5724 0 -5725 0 -5726 1 -5727 0 -5728 0 -5729 0 -5730 0 -5731 0 -5732 0 -5733 0 -5734 1 -5735 0 -5736 0 -5737 0 -5738 0 -5739 0 -5740 0 -5741 0 -5742 1 -5743 0 -5744 0 -5745 0 -5746 0 -5747 0 -5748 0 -5749 0 -5750 0 -5751 1 -5752 0 -5753 0 -5754 0 -5755 0 -5756 0 -5757 0 -5758 0 -5759 1 -5760 0 -5761 0 -5762 0 -5763 0 -5764 0 -5765 0 -5766 1 -5767 0 -5768 0 -5769 0 -5770 0 -5771 0 -5772 0 -5773 0 -5774 1 -5775 0 -5776 0 -5777 0 -5778 0 -5779 0 -5780 0 -5781 0 -5782 1 -5783 0 -5784 0 -5785 0 -5786 0 -5787 0 -5788 0 -5789 0 -5790 0 -5791 1 -5792 0 -5793 0 -5794 0 -5795 0 -5796 0 -5797 0 -5798 0 -5799 0 -5800 1 -5801 0 -5802 0 -5803 0 -5804 0 -5805 0 -5806 0 -5807 0 -5808 0 -5809 1 -5810 0 -5811 0 -5812 0 -5813 0 -5814 0 -5815 0 -5816 1 -5817 0 -5818 0 -5819 0 -5820 0 -5821 0 -5822 0 -5823 0 -5824 0 -5825 1 -5826 0 -5827 0 -5828 0 -5829 0 -5830 0 -5831 0 -5832 0 -5833 0 -5834 1 -5835 0 -5836 0 -5837 0 -5838 0 -5839 0 -5840 0 -5841 0 -5842 1 -5843 0 -5844 0 -5845 0 -5846 0 -5847 0 -5848 0 -5849 0 -5850 1 -5851 0 -5852 0 -5853 0 -5854 0 -5855 0 -5856 0 -5857 0 -5858 1 -5859 0 -5860 0 -5861 0 -5862 0 -5863 0 -5864 0 -5865 0 -5866 0 -5867 1 -5868 0 -5869 0 -5870 0 -5871 0 -5872 0 -5873 0 -5874 0 -5875 1 -5876 0 -5877 0 -5878 0 -5879 0 -5880 0 -5881 0 -5882 0 -5883 0 -5884 1 -5885 0 -5886 0 -5887 0 -5888 0 -5889 0 -5890 0 -5891 1 -5892 0 -5893 0 -5894 0 -5895 0 -5896 0 -5897 0 -5898 0 -5899 0 -5900 1 -5901 0 -5902 0 -5903 0 -5904 0 -5905 0 -5906 0 -5907 0 -5908 0 -5909 1 -5910 0 -5911 0 -5912 0 -5913 0 -5914 0 -5915 0 -5916 0 -5917 1 -5918 0 -5919 0 -5920 0 -5921 0 -5922 0 -5923 0 -5924 0 -5925 0 -5926 1 -5927 0 -5928 0 -5929 0 -5930 0 -5931 0 -5932 0 -5933 0 -5934 1 -5935 0 -5936 0 -5937 0 -5938 0 -5939 0 -5940 0 -5941 0 -5942 0 -5943 0 -5944 1 -5945 0 -5946 0 -5947 0 -5948 0 -5949 0 -5950 0 -5951 0 -5952 0 -5953 0 -5954 0 -5955 0 -5956 0 -5957 0 -5958 0 -5959 0 -5960 0 -5961 0 -5962 0 -5963 0 -5964 0 -5965 0 -5966 0 -5967 0 -5968 0 -5969 0 -5970 1 -5971 0 -5972 0 -5973 0 -5974 0 -5975 0 -5976 0 -5977 0 -5978 1 -5979 0 -5980 0 -5981 0 -5982 0 -5983 0 -5984 0 -5985 0 -5986 0 -5987 1 -5988 0 -5989 0 -5990 0 -5991 0 -5992 0 -5993 0 -5994 0 -5995 0 -5996 1 -5997 0 -5998 0 -5999 0 -6000 0 -6001 0 -6002 0 -6003 0 -6004 0 -6005 0 -6006 1 -6007 0 -6008 0 -6009 0 -6010 0 -6011 0 -6012 0 -6013 0 -6014 1 -6015 0 -6016 0 -6017 0 -6018 0 -6019 0 -6020 0 -6021 0 -6022 0 -6023 1 -6024 0 -6025 0 -6026 0 -6027 0 -6028 0 -6029 0 -6030 0 -6031 1 -6032 0 -6033 0 -6034 0 -6035 0 -6036 0 -6037 0 -6038 1 -6039 0 -6040 0 -6041 0 -6042 0 -6043 0 -6044 0 -6045 0 -6046 0 -6047 0 -6048 1 -6049 0 -6050 0 -6051 0 -6052 0 -6053 0 -6054 0 -6055 1 -6056 0 -6057 0 -6058 0 -6059 0 -6060 0 -6061 1 -6062 0 -6063 0 -6064 0 -6065 0 -6066 0 -6067 0 -6068 1 -6069 0 -6070 0 -6071 0 -6072 0 -6073 0 -6074 0 -6075 0 -6076 1 -6077 0 -6078 0 -6079 0 -6080 0 -6081 0 -6082 0 -6083 0 -6084 0 -6085 1 -6086 0 -6087 0 -6088 0 -6089 0 -6090 0 -6091 0 -6092 0 -6093 0 -6094 0 -6095 1 -6096 0 -6097 0 -6098 0 -6099 0 -6100 0 -6101 0 -6102 0 -6103 0 -6104 1 -6105 0 -6106 0 -6107 0 -6108 0 -6109 0 -6110 0 -6111 0 -6112 1 -6113 0 -6114 0 -6115 0 -6116 0 -6117 0 -6118 0 -6119 0 -6120 0 -6121 0 -6122 0 -6123 0 -6124 0 -6125 1 -6126 0 -6127 0 -6128 0 -6129 0 -6130 0 -6131 0 -6132 0 -6133 0 -6134 0 -6135 0 -6136 0 -6137 0 -6138 0 -6139 0 -6140 0 -6141 0 -6142 1 -6143 0 -6144 0 -6145 0 -6146 0 -6147 0 -6148 0 -6149 0 -6150 1 -6151 0 -6152 0 -6153 0 -6154 0 -6155 0 -6156 0 -6157 0 -6158 0 -6159 1 -6160 0 -6161 0 -6162 0 -6163 0 -6164 0 -6165 0 -6166 0 -6167 1 -6168 0 -6169 0 -6170 0 -6171 0 -6172 0 -6173 0 -6174 0 -6175 1 -6176 0 -6177 0 -6178 0 -6179 0 -6180 0 -6181 0 -6182 0 -6183 1 -6184 0 -6185 0 -6186 0 -6187 0 -6188 0 -6189 0 -6190 0 -6191 0 -6192 1 -6193 0 -6194 0 -6195 0 -6196 0 -6197 0 -6198 0 -6199 0 -6200 0 -6201 1 -6202 0 -6203 0 -6204 0 -6205 0 -6206 0 -6207 0 -6208 0 -6209 0 -6210 1 -6211 0 -6212 0 -6213 0 -6214 0 -6215 0 -6216 0 -6217 1 -6218 0 -6219 0 -6220 0 -6221 0 -6222 0 -6223 0 -6224 0 -6225 1 -6226 0 -6227 0 -6228 0 -6229 0 -6230 0 -6231 0 -6232 0 -6233 0 -6234 1 -6235 0 -6236 0 -6237 0 -6238 0 -6239 0 -6240 0 -6241 1 -6242 0 -6243 0 -6244 0 -6245 0 -6246 0 -6247 0 -6248 0 -6249 0 -6250 1 -6251 0 -6252 0 -6253 0 -6254 0 -6255 0 -6256 0 -6257 0 -6258 1 -6259 0 -6260 0 -6261 0 -6262 0 -6263 0 -6264 0 -6265 0 -6266 0 -6267 0 -6268 1 -6269 0 -6270 0 -6271 0 -6272 0 -6273 0 -6274 0 -6275 0 -6276 0 -6277 1 -6278 0 -6279 0 -6280 0 -6281 0 -6282 0 -6283 0 -6284 0 -6285 1 -6286 0 -6287 0 -6288 0 -6289 0 -6290 0 -6291 0 -6292 1 -6293 0 -6294 0 -6295 0 -6296 0 -6297 0 -6298 0 -6299 1 -6300 0 -6301 0 -6302 0 -6303 0 -6304 0 -6305 0 -6306 0 -6307 1 -6308 0 -6309 0 -6310 0 -6311 0 -6312 0 -6313 0 -6314 0 -6315 1 -6316 0 -6317 0 -6318 0 -6319 0 -6320 0 -6321 0 -6322 0 -6323 0 -6324 1 -6325 0 -6326 0 -6327 0 -6328 0 -6329 0 -6330 0 -6331 0 -6332 1 -6333 0 -6334 0 -6335 0 -6336 0 -6337 0 -6338 0 -6339 0 -6340 0 -6341 1 -6342 0 -6343 0 -6344 0 -6345 0 -6346 0 -6347 0 -6348 0 -6349 0 -6350 1 -6351 0 -6352 0 -6353 0 -6354 0 -6355 0 -6356 0 -6357 0 -6358 1 -6359 0 -6360 0 -6361 0 -6362 0 -6363 0 -6364 0 -6365 0 -6366 1 -6367 0 -6368 0 -6369 0 -6370 0 -6371 0 -6372 0 -6373 0 -6374 0 -6375 1 -6376 0 -6377 0 -6378 0 -6379 0 -6380 0 -6381 0 -6382 0 -6383 1 -6384 0 -6385 0 -6386 0 -6387 0 -6388 0 -6389 0 -6390 0 -6391 4 -6392 0 -6393 1 -6394 0 -6395 0 -6396 0 -6397 1 -6398 0 -6399 0 -6400 0 -6401 0 -6402 1 -6403 0 -6404 0 -6405 0 -6406 0 -6407 1 -6408 0 -6409 0 -6410 0 -6411 0 -6412 1 -6413 0 -6414 0 -6415 0 -6416 0 -6417 0 -6418 1 -6419 0 -6420 0 -6421 0 -6422 0 -6423 0 -6424 0 -6425 1 -6426 0 -6427 0 -6428 0 -6429 0 -6430 0 -6431 0 -6432 0 -6433 0 -6434 1 -6435 0 -6436 0 -6437 0 -6438 0 -6439 0 -6440 0 -6441 0 -6442 0 -6443 1 -6444 0 -6445 0 -6446 0 -6447 0 -6448 0 -6449 0 -6450 0 -6451 0 -6452 1 -6453 0 -6454 0 -6455 0 -6456 0 -6457 0 -6458 0 -6459 0 -6460 0 -6461 0 -6462 0 -6463 1 -6464 0 -6465 0 -6466 0 -6467 0 -6468 0 -6469 0 -6470 0 -6471 0 -6472 1 -6473 0 -6474 0 -6475 0 -6476 0 -6477 0 -6478 0 -6479 0 -6480 0 -6481 0 -6482 1 -6483 0 -6484 0 -6485 0 -6486 0 -6487 0 -6488 0 -6489 0 -6490 0 -6491 0 -6492 1 -6493 0 -6494 0 -6495 0 -6496 0 -6497 0 -6498 0 -6499 0 -6500 0 -6501 0 -6502 0 -6503 0 -6504 0 -6505 0 -6506 0 -6507 0 -6508 0 -6509 0 -6510 0 -6511 0 -6512 1 -6513 0 -6514 0 -6515 0 -6516 0 -6517 0 -6518 0 -6519 0 -6520 0 -6521 1 -6522 0 -6523 0 -6524 0 -6525 0 -6526 0 -6527 0 -6528 0 -6529 0 -6530 0 -6531 1 -6532 0 -6533 0 -6534 0 -6535 0 -6536 0 -6537 0 -6538 0 -6539 0 -6540 1 -6541 0 -6542 0 -6543 0 -6544 0 -6545 0 -6546 0 -6547 0 -6548 0 -6549 0 -6550 1 -6551 0 -6552 0 -6553 0 -6554 0 -6555 0 -6556 0 -6557 0 -6558 0 -6559 0 -6560 1 -6561 0 -6562 0 -6563 0 -6564 0 -6565 0 -6566 0 -6567 0 -6568 0 -6569 1 -6570 0 -6571 0 -6572 0 -6573 0 -6574 0 -6575 0 -6576 0 -6577 1 -6578 0 -6579 0 -6580 0 -6581 0 -6582 0 -6583 0 -6584 0 -6585 0 -6586 1 -6587 0 -6588 0 -6589 0 -6590 0 -6591 0 -6592 0 -6593 0 -6594 0 -6595 1 -6596 0 -6597 0 -6598 0 -6599 0 -6600 0 -6601 0 -6602 0 -6603 0 -6604 1 -6605 0 -6606 0 -6607 0 -6608 0 -6609 0 -6610 0 -6611 0 -6612 0 -6613 1 -6614 0 -6615 0 -6616 0 -6617 0 -6618 0 -6619 0 -6620 0 -6621 0 -6622 1 -6623 0 -6624 0 -6625 0 -6626 0 -6627 0 -6628 0 -6629 0 -6630 0 -6631 1 -6632 0 -6633 0 -6634 0 -6635 0 -6636 0 -6637 0 -6638 0 -6639 0 -6640 1 -6641 0 -6642 0 -6643 0 -6644 0 -6645 0 -6646 0 -6647 0 -6648 0 -6649 0 -6650 1 -6651 0 -6652 0 -6653 0 -6654 0 -6655 0 -6656 0 -6657 0 -6658 0 -6659 0 -6660 1 -6661 0 -6662 0 -6663 0 -6664 0 -6665 0 -6666 0 -6667 0 -6668 0 -6669 1 -6670 0 -6671 0 -6672 0 -6673 0 -6674 0 -6675 0 -6676 0 -6677 0 -6678 0 -6679 1 -6680 0 -6681 0 -6682 0 -6683 0 -6684 0 -6685 0 -6686 0 -6687 0 -6688 1 -6689 0 -6690 0 -6691 0 -6692 0 -6693 0 -6694 0 -6695 0 -6696 0 -6697 0 -6698 1 -6699 0 -6700 0 -6701 0 -6702 0 -6703 0 -6704 0 -6705 0 -6706 1 -6707 0 -6708 0 -6709 0 -6710 0 -6711 0 -6712 0 -6713 0 -6714 0 -6715 0 -6716 1 -6717 0 -6718 0 -6719 0 -6720 0 -6721 0 -6722 0 -6723 0 -6724 0 -6725 0 -6726 1 -6727 0 -6728 0 -6729 0 -6730 0 -6731 0 -6732 0 -6733 0 -6734 0 -6735 0 -6736 0 -6737 1 -6738 0 -6739 0 -6740 0 -6741 0 -6742 0 -6743 0 -6744 0 -6745 0 -6746 1 -6747 0 -6748 0 -6749 0 -6750 0 -6751 0 -6752 0 -6753 0 -6754 0 -6755 0 -6756 1 -6757 0 -6758 0 -6759 0 -6760 0 -6761 0 -6762 0 -6763 0 -6764 0 -6765 0 -6766 1 -6767 0 -6768 0 -6769 0 -6770 0 -6771 0 -6772 0 -6773 0 -6774 0 -6775 1 -6776 0 -6777 0 -6778 0 -6779 0 -6780 0 -6781 0 -6782 0 -6783 0 -6784 1 -6785 0 -6786 0 -6787 0 -6788 0 -6789 0 -6790 0 -6791 0 -6792 0 -6793 0 -6794 1 -6795 0 -6796 0 -6797 0 -6798 0 -6799 0 -6800 0 -6801 0 -6802 0 -6803 1 -6804 0 -6805 0 -6806 0 -6807 0 -6808 0 -6809 0 -6810 0 -6811 0 -6812 0 -6813 1 -6814 0 -6815 0 -6816 0 -6817 0 -6818 0 -6819 0 -6820 0 -6821 0 -6822 0 -6823 0 -6824 1 -6825 0 -6826 0 -6827 0 -6828 0 -6829 0 -6830 0 -6831 0 -6832 1 -6833 0 -6834 0 -6835 0 -6836 0 -6837 0 -6838 0 -6839 0 -6840 0 -6841 0 -6842 1 -6843 0 -6844 0 -6845 0 -6846 0 -6847 0 -6848 0 -6849 0 -6850 0 -6851 1 -6852 0 -6853 0 -6854 0 -6855 0 -6856 0 -6857 0 -6858 0 -6859 0 -6860 0 -6861 0 -6862 1 -6863 0 -6864 0 -6865 0 -6866 0 -6867 0 -6868 0 -6869 0 -6870 0 -6871 1 -6872 0 -6873 0 -6874 0 -6875 0 -6876 0 -6877 0 -6878 0 -6879 1 -6880 0 -6881 0 -6882 0 -6883 0 -6884 0 -6885 0 -6886 1 -6887 0 -6888 0 -6889 0 -6890 0 -6891 0 -6892 0 -6893 0 -6894 0 -6895 1 -6896 0 -6897 0 -6898 0 -6899 0 -6900 0 -6901 0 -6902 0 -6903 0 -6904 0 -6905 0 -6906 0 -6907 0 -6908 0 -6909 0 -6910 0 -6911 0 -6912 0 -6913 0 -6914 1 -6915 0 -6916 0 -6917 0 -6918 0 -6919 0 -6920 0 -6921 0 -6922 0 -6923 1 -6924 0 -6925 0 -6926 0 -6927 0 -6928 0 -6929 0 -6930 0 -6931 0 -6932 0 -6933 0 -6934 1 -6935 0 -6936 0 -6937 0 -6938 0 -6939 0 -6940 0 -6941 0 -6942 0 -6943 0 -6944 1 -6945 0 -6946 0 -6947 0 -6948 0 -6949 0 -6950 0 -6951 0 -6952 0 -6953 0 -6954 1 -6955 0 -6956 0 -6957 0 -6958 0 -6959 0 -6960 0 -6961 0 -6962 0 -6963 0 -6964 1 -6965 0 -6966 0 -6967 0 -6968 0 -6969 0 -6970 0 -6971 0 -6972 0 -6973 0 -6974 1 -6975 0 -6976 0 -6977 0 -6978 0 -6979 0 -6980 0 -6981 0 -6982 0 -6983 1 -6984 0 -6985 0 -6986 0 -6987 0 -6988 0 -6989 0 -6990 0 -6991 0 -6992 1 -6993 0 -6994 0 -6995 0 -6996 0 -6997 0 -6998 0 -6999 0 -7000 0 -7001 1 -7002 0 -7003 0 -7004 0 -7005 0 -7006 0 -7007 0 -7008 0 -7009 0 -7010 1 -7011 0 -7012 0 -7013 0 -7014 0 -7015 0 -7016 0 -7017 0 -7018 0 -7019 0 -7020 1 -7021 0 -7022 0 -7023 0 -7024 0 -7025 0 -7026 0 -7027 0 -7028 0 -7029 0 -7030 1 -7031 0 -7032 0 -7033 0 -7034 0 -7035 0 -7036 0 -7037 0 -7038 0 -7039 1 -7040 0 -7041 0 -7042 0 -7043 0 -7044 0 -7045 0 -7046 0 -7047 0 -7048 1 -7049 0 -7050 0 -7051 0 -7052 0 -7053 0 -7054 0 -7055 0 -7056 0 -7057 0 -7058 0 -7059 1 -7060 0 -7061 0 -7062 0 -7063 0 -7064 0 -7065 0 -7066 0 -7067 0 -7068 0 -7069 1 -7070 0 -7071 0 -7072 0 -7073 0 -7074 0 -7075 0 -7076 0 -7077 0 -7078 0 -7079 1 -7080 0 -7081 0 -7082 0 -7083 0 -7084 0 -7085 0 -7086 0 -7087 1 -7088 0 -7089 0 -7090 0 -7091 0 -7092 0 -7093 0 -7094 0 -7095 0 -7096 0 -7097 1 -7098 0 -7099 0 -7100 0 -7101 0 -7102 0 -7103 0 -7104 0 -7105 1 -7106 0 -7107 0 -7108 0 -7109 0 -7110 0 -7111 0 -7112 0 -7113 0 -7114 1 -7115 0 -7116 0 -7117 0 -7118 0 -7119 0 -7120 0 -7121 0 -7122 0 -7123 0 -7124 1 -7125 0 -7126 0 -7127 0 -7128 0 -7129 0 -7130 0 -7131 0 -7132 0 -7133 0 -7134 1 -7135 0 -7136 0 -7137 0 -7138 0 -7139 0 -7140 0 -7141 0 -7142 0 -7143 1 -7144 0 -7145 0 -7146 0 -7147 0 -7148 0 -7149 0 -7150 0 -7151 0 -7152 1 -7153 0 -7154 0 -7155 0 -7156 0 -7157 0 -7158 0 -7159 0 -7160 0 -7161 0 -7162 1 -7163 0 -7164 0 -7165 0 -7166 0 -7167 0 -7168 0 -7169 0 -7170 0 -7171 0 -7172 1 -7173 0 -7174 0 -7175 0 -7176 0 -7177 0 -7178 0 -7179 0 -7180 0 -7181 0 -7182 1 -7183 0 -7184 0 -7185 0 -7186 0 -7187 0 -7188 0 -7189 0 -7190 0 -7191 0 -7192 0 -7193 1 -7194 0 -7195 0 -7196 0 -7197 0 -7198 0 -7199 0 -7200 0 -7201 0 -7202 0 -7203 1 -7204 0 -7205 0 -7206 0 -7207 0 -7208 0 -7209 0 -7210 0 -7211 0 -7212 0 -7213 0 -7214 0 -7215 0 -7216 0 -7217 0 -7218 0 -7219 0 -7220 0 -7221 0 -7222 1 -7223 0 -7224 0 -7225 0 -7226 0 -7227 0 -7228 0 -7229 0 -7230 0 -7231 0 -7232 1 -7233 0 -7234 0 -7235 0 -7236 0 -7237 0 -7238 0 -7239 0 -7240 0 -7241 0 -7242 0 -7243 1 -7244 0 -7245 0 -7246 0 -7247 0 -7248 0 -7249 0 -7250 0 -7251 0 -7252 0 -7253 1 -7254 0 -7255 0 -7256 0 -7257 0 -7258 0 -7259 0 -7260 0 -7261 0 -7262 0 -7263 0 -7264 1 -7265 0 -7266 0 -7267 0 -7268 0 -7269 0 -7270 0 -7271 0 -7272 0 -7273 0 -7274 1 -7275 0 -7276 0 -7277 0 -7278 0 -7279 0 -7280 0 -7281 0 -7282 0 -7283 0 -7284 0 -7285 1 -7286 0 -7287 0 -7288 0 -7289 0 -7290 0 -7291 0 -7292 0 -7293 0 -7294 0 -7295 0 -7296 0 -7297 0 -7298 0 -7299 0 -7300 0 -7301 0 -7302 0 -7303 0 -7304 1 -7305 0 -7306 0 -7307 0 -7308 0 -7309 0 -7310 0 -7311 0 -7312 0 -7313 0 -7314 0 -7315 1 -7316 0 -7317 0 -7318 0 -7319 0 -7320 0 -7321 0 -7322 0 -7323 0 -7324 1 -7325 0 -7326 0 -7327 0 -7328 0 -7329 0 -7330 0 -7331 0 -7332 0 -7333 1 -7334 0 -7335 0 -7336 0 -7337 0 -7338 0 -7339 0 -7340 0 -7341 0 -7342 1 -7343 0 -7344 0 -7345 0 -7346 0 -7347 0 -7348 0 -7349 0 -7350 0 -7351 0 -7352 1 -7353 0 -7354 0 -7355 0 -7356 0 -7357 0 -7358 0 -7359 0 -7360 0 -7361 0 -7362 0 -7363 1 -7364 0 -7365 0 -7366 0 -7367 0 -7368 0 -7369 0 -7370 0 -7371 0 -7372 1 -7373 0 -7374 0 -7375 0 -7376 0 -7377 0 -7378 0 -7379 0 -7380 0 -7381 0 -7382 1 -7383 0 -7384 0 -7385 0 -7386 0 -7387 0 -7388 0 -7389 0 -7390 0 -7391 1 -7392 0 -7393 0 -7394 0 -7395 0 -7396 0 -7397 0 -7398 0 -7399 0 -7400 0 -7401 1 -7402 0 -7403 0 -7404 0 -7405 0 -7406 0 -7407 0 -7408 0 -7409 0 -7410 0 -7411 0 -7412 1 -7413 0 -7414 0 -7415 0 -7416 0 -7417 0 -7418 0 -7419 0 -7420 0 -7421 0 -7422 1 -7423 0 -7424 0 -7425 0 -7426 0 -7427 0 -7428 0 -7429 0 -7430 0 -7431 0 -7432 1 -7433 0 -7434 0 -7435 0 -7436 0 -7437 0 -7438 0 -7439 0 -7440 0 -7441 1 -7442 0 -7443 0 -7444 0 -7445 0 -7446 0 -7447 0 -7448 0 -7449 1 -7450 0 -7451 0 -7452 0 -7453 0 -7454 0 -7455 0 -7456 0 -7457 0 -7458 0 -7459 0 -7460 1 -7461 0 -7462 0 -7463 0 -7464 0 -7465 0 -7466 0 -7467 0 -7468 0 -7469 1 -7470 0 -7471 0 -7472 0 -7473 0 -7474 0 -7475 0 -7476 0 -7477 0 -7478 1 -7479 0 -7480 0 -7481 0 -7482 0 -7483 0 -7484 0 -7485 0 -7486 0 -7487 1 -7488 0 -7489 0 -7490 0 -7491 0 -7492 0 -7493 0 -7494 0 -7495 0 -7496 0 -7497 1 -7498 0 -7499 0 -7500 0 -7501 0 -7502 0 -7503 0 -7504 0 -7505 0 -7506 0 -7507 0 -7508 1 -7509 0 -7510 0 -7511 0 -7512 0 -7513 0 -7514 0 -7515 0 -7516 0 -7517 0 -7518 1 -7519 0 -7520 0 -7521 0 -7522 0 -7523 0 -7524 0 -7525 0 -7526 0 -7527 0 -7528 0 -7529 0 -7530 0 -7531 0 -7532 0 -7533 0 -7534 0 -7535 0 -7536 0 -7537 0 -7538 0 -7539 1 -7540 0 -7541 0 -7542 0 -7543 0 -7544 0 -7545 0 -7546 0 -7547 0 -7548 0 -7549 2 -7550 0 -7551 0 -7552 0 -7553 0 -7554 0 -7555 0 -7556 0 -7557 1 -7558 0 -7559 0 -7560 0 -7561 0 -7562 0 -7563 0 -7564 0 -7565 0 -7566 0 -7567 0 -7568 1 -7569 0 -7570 0 -7571 0 -7572 0 -7573 0 -7574 0 -7575 0 -7576 0 -7577 0 -7578 0 -7579 0 -7580 0 -7581 0 -7582 0 -7583 0 -7584 0 -7585 0 -7586 0 -7587 0 -7588 1 -7589 0 -7590 0 -7591 0 -7592 0 -7593 0 -7594 0 -7595 0 -7596 0 -7597 0 -7598 0 -7599 1 -7600 0 -7601 0 -7602 0 -7603 0 -7604 0 -7605 0 -7606 0 -7607 0 -7608 0 -7609 0 -7610 1 -7611 0 -7612 0 -7613 0 -7614 0 -7615 0 -7616 0 -7617 0 -7618 0 -7619 0 -7620 0 -7621 1 -7622 0 -7623 0 -7624 0 -7625 0 -7626 0 -7627 1 -7628 0 -7629 0 -7630 0 -7631 0 -7632 0 -7633 0 -7634 1 -7635 0 -7636 0 -7637 0 -7638 0 -7639 0 -7640 0 -7641 1 -7642 0 -7643 0 -7644 0 -7645 0 -7646 0 -7647 0 -7648 0 -7649 1 -7650 0 -7651 0 -7652 0 -7653 0 -7654 0 -7655 0 -7656 0 -7657 0 -7658 0 -7659 0 -7660 1 -7661 0 -7662 0 -7663 0 -7664 0 -7665 0 -7666 0 -7667 0 -7668 0 -7669 0 -7670 1 -7671 0 -7672 0 -7673 0 -7674 0 -7675 0 -7676 0 -7677 0 -7678 0 -7679 0 -7680 0 -7681 1 -7682 0 -7683 0 -7684 0 -7685 0 -7686 0 -7687 0 -7688 0 -7689 0 -7690 0 -7691 1 -7692 0 -7693 0 -7694 0 -7695 0 -7696 0 -7697 0 -7698 0 -7699 0 -7700 0 -7701 0 -7702 1 -7703 0 -7704 0 -7705 0 -7706 0 -7707 0 -7708 0 -7709 0 -7710 0 -7711 0 -7712 1 -7713 0 -7714 0 -7715 0 -7716 0 -7717 0 -7718 0 -7719 0 -7720 0 -7721 0 -7722 1 -7723 0 -7724 0 -7725 0 -7726 0 -7727 0 -7728 0 -7729 0 -7730 0 -7731 0 -7732 1 -7733 0 -7734 0 -7735 0 -7736 0 -7737 0 -7738 0 -7739 0 -7740 0 -7741 0 -7742 1 -7743 0 -7744 0 -7745 0 -7746 0 -7747 0 -7748 0 -7749 0 -7750 0 -7751 0 -7752 1 -7753 0 -7754 0 -7755 0 -7756 0 -7757 0 -7758 0 -7759 0 -7760 0 -7761 1 -7762 0 -7763 0 -7764 0 -7765 0 -7766 0 -7767 0 -7768 0 -7769 0 -7770 1 -7771 0 -7772 0 -7773 0 -7774 0 -7775 0 -7776 0 -7777 0 -7778 0 -7779 1 -7780 0 -7781 0 -7782 0 -7783 0 -7784 0 -7785 0 -7786 0 -7787 0 -7788 0 -7789 1 -7790 0 -7791 0 -7792 0 -7793 0 -7794 0 -7795 0 -7796 0 -7797 0 -7798 0 -7799 1 -7800 0 -7801 0 -7802 0 -7803 0 -7804 0 -7805 0 -7806 0 -7807 0 -7808 0 -7809 0 -7810 1 -7811 0 -7812 0 -7813 0 -7814 0 -7815 0 -7816 0 -7817 0 -7818 0 -7819 1 -7820 0 -7821 0 -7822 0 -7823 0 -7824 0 -7825 0 -7826 0 -7827 0 -7828 1 -7829 0 -7830 0 -7831 0 -7832 0 -7833 0 -7834 0 -7835 0 -7836 0 -7837 0 -7838 0 -7839 1 -7840 0 -7841 0 -7842 0 -7843 0 -7844 0 -7845 0 -7846 0 -7847 0 -7848 0 -7849 1 -7850 0 -7851 0 -7852 0 -7853 0 -7854 0 -7855 0 -7856 0 -7857 0 -7858 1 -7859 0 -7860 0 -7861 0 -7862 0 -7863 0 -7864 0 -7865 0 -7866 0 -7867 0 -7868 1 -7869 0 -7870 0 -7871 0 -7872 0 -7873 0 -7874 0 -7875 0 -7876 0 -7877 0 -7878 0 -7879 0 -7880 0 -7881 0 -7882 0 -7883 0 -7884 0 -7885 0 -7886 0 -7887 1 -7888 0 -7889 0 -7890 0 -7891 0 -7892 0 -7893 0 -7894 0 -7895 0 -7896 0 -7897 0 -7898 1 -7899 0 -7900 0 -7901 0 -7902 0 -7903 0 -7904 0 -7905 0 -7906 0 -7907 0 -7908 1 -7909 0 -7910 0 -7911 0 -7912 0 -7913 0 -7914 0 -7915 0 -7916 0 -7917 0 -7918 1 -7919 0 -7920 0 -7921 0 -7922 0 -7923 0 -7924 0 -7925 0 -7926 0 -7927 0 -7928 1 -7929 0 -7930 0 -7931 0 -7932 0 -7933 0 -7934 0 -7935 0 -7936 0 -7937 0 -7938 1 -7939 0 -7940 0 -7941 0 -7942 0 -7943 0 -7944 0 -7945 0 -7946 0 -7947 0 -7948 1 -7949 0 -7950 0 -7951 0 -7952 0 -7953 0 -7954 0 -7955 0 -7956 0 -7957 0 -7958 1 -7959 0 -7960 0 -7961 0 -7962 0 -7963 0 -7964 0 -7965 0 -7966 0 -7967 0 -7968 1 -7969 0 -7970 0 -7971 0 -7972 0 -7973 0 -7974 0 -7975 0 -7976 0 -7977 0 -7978 1 -7979 0 -7980 0 -7981 0 -7982 0 -7983 0 -7984 0 -7985 1 -7986 0 -7987 0 -7988 0 -7989 0 -7990 0 -7991 0 -7992 0 -7993 0 -7994 0 -7995 1 -7996 0 -7997 0 -7998 0 -7999 0 -8000 0 -8001 0 -8002 0 -8003 0 -8004 0 -8005 0 -8006 1 -8007 0 -8008 0 -8009 0 -8010 0 -8011 0 -8012 0 -8013 0 -8014 0 -8015 1 -8016 0 -8017 0 -8018 0 -8019 0 -8020 0 -8021 0 -8022 0 -8023 0 -8024 0 -8025 1 -8026 0 -8027 0 -8028 0 -8029 0 -8030 0 -8031 0 -8032 0 -8033 0 -8034 0 -8035 0 -8036 1 -8037 0 -8038 0 -8039 0 -8040 0 -8041 0 -8042 0 -8043 0 -8044 0 -8045 0 -8046 1 -8047 0 -8048 0 -8049 0 -8050 0 -8051 0 -8052 0 -8053 0 -8054 0 -8055 0 -8056 0 -8057 1 -8058 0 -8059 0 -8060 0 -8061 0 -8062 0 -8063 0 -8064 0 -8065 0 -8066 0 -8067 1 -8068 0 -8069 0 -8070 0 -8071 0 -8072 0 -8073 0 -8074 0 -8075 0 -8076 0 -8077 0 -8078 1 -8079 0 -8080 0 -8081 0 -8082 0 -8083 0 -8084 0 -8085 0 -8086 0 -8087 0 -8088 1 -8089 0 -8090 0 -8091 0 -8092 0 -8093 0 -8094 0 -8095 0 -8096 0 -8097 0 -8098 1 -8099 0 -8100 0 -8101 0 -8102 0 -8103 0 -8104 0 -8105 1 -8106 0 -8107 0 -8108 0 -8109 0 -8110 0 -8111 0 -8112 0 -8113 0 -8114 0 -8115 1 -8116 0 -8117 0 -8118 0 -8119 0 -8120 0 -8121 0 -8122 0 -8123 0 -8124 0 -8125 1 -8126 0 -8127 0 -8128 0 -8129 0 -8130 0 -8131 0 -8132 0 -8133 0 -8134 1 -8135 0 -8136 0 -8137 0 -8138 0 -8139 0 -8140 0 -8141 0 -8142 0 -8143 0 -8144 0 -8145 1 -8146 0 -8147 0 -8148 0 -8149 0 -8150 0 -8151 0 -8152 0 -8153 0 -8154 0 -8155 0 -8156 1 -8157 0 -8158 0 -8159 0 -8160 0 -8161 0 -8162 0 -8163 0 -8164 0 -8165 0 -8166 1 -8167 0 -8168 0 -8169 0 -8170 0 -8171 0 -8172 0 -8173 0 -8174 0 -8175 0 -8176 1 -8177 0 -8178 0 -8179 0 -8180 0 -8181 0 -8182 0 -8183 0 -8184 0 -8185 0 -8186 1 -8187 0 -8188 0 -8189 0 -8190 0 -8191 0 -8192 0 -8193 0 -8194 0 -8195 0 -8196 0 -8197 1 -8198 0 -8199 0 -8200 0 -8201 0 -8202 0 -8203 0 -8204 0 -8205 0 -8206 0 -8207 1 -8208 0 -8209 0 -8210 0 -8211 0 -8212 0 -8213 0 -8214 0 -8215 0 -8216 1 -8217 0 -8218 0 -8219 0 -8220 0 -8221 0 -8222 0 -8223 0 -8224 0 -8225 1 -8226 0 -8227 0 -8228 0 -8229 0 -8230 0 -8231 0 -8232 0 -8233 0 -8234 0 -8235 1 -8236 0 -8237 0 -8238 0 -8239 0 -8240 0 -8241 0 -8242 0 -8243 0 -8244 1 -8245 0 -8246 0 -8247 0 -8248 0 -8249 0 -8250 0 -8251 0 -8252 0 -8253 0 -8254 1 -8255 0 -8256 0 -8257 0 -8258 0 -8259 0 -8260 0 -8261 0 -8262 0 -8263 0 -8264 0 -8265 1 -8266 0 -8267 0 -8268 0 -8269 0 -8270 0 -8271 0 -8272 0 -8273 0 -8274 0 -8275 1 -8276 0 -8277 0 -8278 0 -8279 0 -8280 0 -8281 0 -8282 0 -8283 0 -8284 0 -8285 0 -8286 1 -8287 0 -8288 0 -8289 0 -8290 0 -8291 0 -8292 0 -8293 0 -8294 0 -8295 0 -8296 1 -8297 0 -8298 0 -8299 0 -8300 0 -8301 0 -8302 0 -8303 0 -8304 1 -8305 0 -8306 0 -8307 0 -8308 0 -8309 0 -8310 0 -8311 0 -8312 0 -8313 0 -8314 1 -8315 0 -8316 0 -8317 0 -8318 0 -8319 0 -8320 0 -8321 0 -8322 0 -8323 0 -8324 1 -8325 0 -8326 0 -8327 0 -8328 0 -8329 0 -8330 0 -8331 0 -8332 0 -8333 0 -8334 0 -8335 0 -8336 0 -8337 0 -8338 0 -8339 0 -8340 0 -8341 0 -8342 1 -8343 0 -8344 0 -8345 0 -8346 0 -8347 0 -8348 0 -8349 0 -8350 0 -8351 1 -8352 0 -8353 0 -8354 0 -8355 0 -8356 0 -8357 0 -8358 0 -8359 0 -8360 0 -8361 1 -8362 0 -8363 0 -8364 0 -8365 0 -8366 0 -8367 0 -8368 0 -8369 0 -8370 0 -8371 1 -8372 0 -8373 0 -8374 0 -8375 0 -8376 0 -8377 0 -8378 0 -8379 0 -8380 1 -8381 0 -8382 0 -8383 0 -8384 0 -8385 0 -8386 0 -8387 0 -8388 0 -8389 1 -8390 0 -8391 0 -8392 0 -8393 0 -8394 0 -8395 0 -8396 0 -8397 0 -8398 0 -8399 1 -8400 0 -8401 0 -8402 0 -8403 0 -8404 0 -8405 0 -8406 0 -8407 0 -8408 0 -8409 1 -8410 0 -8411 0 -8412 0 -8413 0 -8414 0 -8415 0 -8416 0 -8417 0 -8418 0 -8419 1 -8420 0 -8421 0 -8422 0 -8423 0 -8424 0 -8425 0 -8426 0 -8427 0 -8428 0 -8429 0 -8430 1 -8431 0 -8432 0 -8433 0 -8434 0 -8435 0 -8436 0 -8437 0 -8438 1 -8439 0 -8440 0 -8441 0 -8442 0 -8443 0 -8444 0 -8445 0 -8446 0 -8447 1 -8448 0 -8449 0 -8450 0 -8451 0 -8452 0 -8453 0 -8454 0 -8455 0 -8456 0 -8457 1 -8458 0 -8459 0 -8460 0 -8461 0 -8462 0 -8463 0 -8464 0 -8465 0 -8466 0 -8467 1 -8468 0 -8469 0 -8470 0 -8471 0 -8472 0 -8473 0 -8474 0 -8475 0 -8476 0 -8477 1 -8478 0 -8479 0 -8480 0 -8481 0 -8482 0 -8483 0 -8484 0 -8485 0 -8486 1 -8487 0 -8488 0 -8489 0 -8490 0 -8491 0 -8492 0 -8493 0 -8494 0 -8495 0 -8496 0 -8497 0 -8498 0 -8499 0 -8500 0 -8501 0 -8502 0 -8503 0 -8504 0 -8505 0 -8506 1 -8507 0 -8508 0 -8509 0 -8510 0 -8511 0 -8512 0 -8513 0 -8514 0 -8515 0 -8516 0 -8517 0 -8518 0 -8519 0 -8520 0 -8521 0 -8522 0 -8523 1 -8524 0 -8525 0 -8526 0 -8527 0 -8528 0 -8529 0 -8530 0 -8531 0 -8532 1 -8533 0 -8534 0 -8535 0 -8536 0 -8537 0 -8538 0 -8539 0 -8540 0 -8541 1 -8542 0 -8543 0 -8544 0 -8545 0 -8546 0 -8547 0 -8548 0 -8549 1 -8550 0 -8551 0 -8552 0 -8553 0 -8554 0 -8555 0 -8556 0 -8557 0 -8558 0 -8559 1 -8560 0 -8561 0 -8562 0 -8563 0 -8564 0 -8565 0 -8566 0 -8567 0 -8568 1 -8569 0 -8570 0 -8571 0 -8572 0 -8573 0 -8574 0 -8575 0 -8576 0 -8577 1 -8578 0 -8579 0 -8580 0 -8581 0 -8582 0 -8583 0 -8584 0 -8585 0 -8586 1 -8587 0 -8588 0 -8589 0 -8590 0 -8591 0 -8592 0 -8593 0 -8594 0 -8595 0 -8596 1 -8597 0 -8598 0 -8599 0 -8600 0 -8601 0 -8602 0 -8603 0 -8604 0 -8605 0 -8606 1 -8607 0 -8608 0 -8609 0 -8610 0 -8611 0 -8612 0 -8613 0 -8614 0 -8615 0 -8616 1 -8617 0 -8618 0 -8619 0 -8620 0 -8621 0 -8622 0 -8623 0 -8624 0 -8625 1 -8626 0 -8627 0 -8628 0 -8629 0 -8630 0 -8631 0 -8632 0 -8633 1 -8634 0 -8635 0 -8636 0 -8637 0 -8638 0 -8639 0 -8640 0 -8641 0 -8642 0 -8643 1 -8644 0 -8645 0 -8646 0 -8647 0 -8648 0 -8649 0 -8650 0 -8651 1 -8652 0 -8653 0 -8654 0 -8655 0 -8656 0 -8657 0 -8658 0 -8659 0 -8660 1 -8661 0 -8662 0 -8663 0 -8664 0 -8665 0 -8666 0 -8667 0 -8668 0 -8669 1 -8670 0 -8671 0 -8672 0 -8673 0 -8674 0 -8675 0 -8676 0 -8677 1 -8678 0 -8679 0 -8680 0 -8681 0 -8682 0 -8683 0 -8684 0 -8685 0 -8686 1 -8687 0 -8688 0 -8689 0 -8690 0 -8691 0 -8692 0 -8693 0 -8694 0 -8695 0 -8696 1 -8697 0 -8698 0 -8699 0 -8700 0 -8701 0 -8702 0 -8703 0 -8704 0 -8705 1 -8706 0 -8707 0 -8708 0 -8709 0 -8710 0 -8711 0 -8712 0 -8713 0 -8714 0 -8715 1 -8716 0 -8717 0 -8718 0 -8719 0 -8720 0 -8721 0 -8722 0 -8723 0 -8724 0 -8725 1 -8726 0 -8727 0 -8728 0 -8729 0 -8730 0 -8731 0 -8732 0 -8733 0 -8734 0 -8735 1 -8736 0 -8737 0 -8738 0 -8739 0 -8740 0 -8741 0 -8742 0 -8743 0 -8744 0 -8745 1 -8746 0 -8747 0 -8748 0 -8749 0 -8750 0 -8751 0 -8752 0 -8753 0 -8754 0 -8755 1 -8756 0 -8757 0 -8758 0 -8759 0 -8760 0 -8761 0 -8762 0 -8763 1 -8764 0 -8765 0 -8766 0 -8767 0 -8768 0 -8769 0 -8770 1 -8771 0 -8772 0 -8773 0 -8774 0 -8775 0 -8776 0 -8777 0 -8778 0 -8779 0 -8780 1 -8781 0 -8782 0 -8783 0 -8784 0 -8785 0 -8786 0 -8787 0 -8788 0 -8789 1 -8790 0 -8791 0 -8792 0 -8793 0 -8794 0 -8795 0 -8796 0 -8797 0 -8798 1 -8799 0 -8800 0 -8801 0 -8802 0 -8803 0 -8804 0 -8805 0 -8806 0 -8807 3 -8808 0 -8809 0 -8810 1 -8811 0 -8812 0 -8813 0 -8814 0 -8815 1 -8816 0 -8817 0 -8818 0 -8819 0 -8820 1 -8821 0 -8822 0 -8823 0 -8824 1 -8825 0 -8826 0 -8827 0 -8828 0 -8829 0 -8830 1 -8831 0 -8832 0 -8833 0 -8834 0 -8835 0 -8836 0 -8837 1 -8838 0 -8839 0 -8840 0 -8841 0 -8842 0 -8843 0 -8844 0 -8845 1 -8846 0 -8847 0 -8848 0 -8849 0 -8850 0 -8851 0 -8852 0 -8853 0 -8854 0 -8855 1 -8856 0 -8857 0 -8858 0 -8859 0 -8860 0 -8861 0 -8862 0 -8863 0 -8864 0 -8865 1 -8866 0 -8867 0 -8868 0 -8869 0 -8870 0 -8871 0 -8872 1 -8873 0 -8874 0 -8875 0 -8876 0 -8877 0 -8878 0 -8879 0 -8880 1 -8881 0 -8882 0 -8883 0 -8884 0 -8885 0 -8886 0 -8887 0 -8888 1 -8889 0 -8890 0 -8891 0 -8892 0 -8893 0 -8894 0 -8895 0 -8896 0 -8897 0 -8898 0 -8899 0 -8900 0 -8901 0 -8902 0 -8903 0 -8904 0 -8905 1 -8906 0 -8907 0 -8908 0 -8909 0 -8910 0 -8911 0 -8912 1 -8913 0 -8914 0 -8915 0 -8916 0 -8917 0 -8918 0 -8919 0 -8920 1 -8921 0 -8922 0 -8923 0 -8924 0 -8925 0 -8926 0 -8927 0 -8928 0 -8929 1 -8930 0 -8931 0 -8932 0 -8933 0 -8934 0 -8935 0 -8936 0 -8937 0 -8938 0 -8939 1 -8940 0 -8941 0 -8942 0 -8943 0 -8944 0 -8945 0 -8946 0 -8947 0 -8948 0 -8949 1 -8950 0 -8951 0 -8952 0 -8953 0 -8954 0 -8955 0 -8956 0 -8957 0 -8958 0 -8959 1 -8960 0 -8961 0 -8962 0 -8963 0 -8964 0 -8965 0 -8966 0 -8967 0 -8968 0 -8969 1 -8970 0 -8971 0 -8972 0 -8973 0 -8974 0 -8975 0 -8976 0 -8977 0 -8978 1 -8979 0 -8980 0 -8981 0 -8982 0 -8983 0 -8984 0 -8985 0 -8986 0 -8987 1 -8988 0 -8989 0 -8990 0 -8991 0 -8992 0 -8993 0 -8994 0 -8995 0 -8996 0 -8997 1 -8998 0 -8999 0 -9000 0 -9001 0 -9002 0 -9003 0 -9004 0 -9005 0 -9006 1 -9007 0 -9008 0 -9009 0 -9010 0 -9011 0 -9012 0 -9013 0 -9014 1 -9015 0 -9016 0 -9017 0 -9018 0 -9019 0 -9020 0 -9021 0 -9022 1 -9023 0 -9024 0 -9025 0 -9026 0 -9027 0 -9028 0 -9029 0 -9030 1 -9031 0 -9032 0 -9033 0 -9034 0 -9035 0 -9036 0 -9037 0 -9038 1 -9039 0 -9040 0 -9041 0 -9042 0 -9043 0 -9044 0 -9045 0 -9046 0 -9047 1 -9048 0 -9049 0 -9050 0 -9051 0 -9052 0 -9053 0 -9054 0 -9055 1 -9056 0 -9057 0 -9058 0 -9059 0 -9060 0 -9061 0 -9062 0 -9063 1 -9064 0 -9065 0 -9066 0 -9067 0 -9068 0 -9069 0 -9070 0 -9071 0 -9072 0 -9073 1 -9074 0 -9075 0 -9076 0 -9077 0 -9078 0 -9079 0 -9080 0 -9081 0 -9082 0 -9083 0 -9084 0 -9085 0 -9086 0 -9087 0 -9088 0 -9089 0 -9090 0 -9091 0 -9092 1 -9093 0 -9094 0 -9095 0 -9096 0 -9097 0 -9098 0 -9099 0 -9100 1 -9101 0 -9102 0 -9103 0 -9104 0 -9105 0 -9106 0 -9107 0 -9108 1 -9109 0 -9110 0 -9111 0 -9112 0 -9113 0 -9114 0 -9115 0 -9116 0 -9117 1 -9118 0 -9119 0 -9120 0 -9121 0 -9122 0 -9123 0 -9124 0 -9125 0 -9126 1 -9127 0 -9128 0 -9129 0 -9130 0 -9131 0 -9132 0 -9133 0 -9134 0 -9135 1 -9136 0 -9137 0 -9138 0 -9139 0 -9140 0 -9141 0 -9142 0 -9143 1 -9144 0 -9145 0 -9146 0 -9147 0 -9148 0 -9149 0 -9150 0 -9151 0 -9152 1 -9153 0 -9154 0 -9155 0 -9156 0 -9157 0 -9158 0 -9159 0 -9160 0 -9161 1 -9162 0 -9163 0 -9164 0 -9165 0 -9166 0 -9167 0 -9168 0 -9169 1 -9170 0 -9171 0 -9172 0 -9173 0 -9174 0 -9175 0 -9176 0 -9177 0 -9178 1 -9179 0 -9180 0 -9181 0 -9182 0 -9183 0 -9184 0 -9185 0 -9186 0 -9187 0 -9188 1 -9189 0 -9190 0 -9191 0 -9192 0 -9193 0 -9194 0 -9195 0 -9196 0 -9197 1 -9198 0 -9199 0 -9200 0 -9201 0 -9202 0 -9203 0 -9204 0 -9205 0 -9206 0 -9207 0 -9208 0 -9209 0 -9210 0 -9211 0 -9212 0 -9213 0 -9214 0 -9215 0 -9216 0 -9217 0 -9218 0 -9219 0 -9220 0 -9221 1 -9222 0 -9223 0 -9224 0 -9225 0 -9226 0 -9227 0 -9228 1 -9229 0 -9230 0 -9231 0 -9232 0 -9233 0 -9234 0 -9235 0 -9236 0 -9237 1 -9238 0 -9239 0 -9240 0 -9241 0 -9242 0 -9243 0 -9244 0 -9245 0 -9246 1 -9247 0 -9248 0 -9249 0 -9250 0 -9251 0 -9252 0 -9253 0 -9254 0 -9255 1 -9256 0 -9257 0 -9258 0 -9259 0 -9260 0 -9261 1 -9262 0 -9263 0 -9264 0 -9265 0 -9266 0 -9267 0 -9268 0 -9269 0 -9270 0 -9271 0 -9272 0 -9273 0 -9274 0 -9275 0 -9276 1 -9277 0 -9278 0 -9279 0 -9280 0 -9281 0 -9282 0 -9283 0 -9284 0 -9285 0 -9286 0 -9287 0 -9288 0 -9289 0 -9290 1 -9291 0 -9292 0 -9293 0 -9294 0 -9295 0 -9296 0 -9297 0 -9298 0 -9299 0 -9300 1 -9301 0 -9302 0 -9303 0 -9304 0 -9305 0 -9306 0 -9307 0 -9308 1 -9309 0 -9310 0 -9311 0 -9312 0 -9313 0 -9314 0 -9315 0 -9316 1 -9317 0 -9318 0 -9319 0 -9320 0 -9321 0 -9322 0 -9323 1 -9324 0 -9325 0 -9326 0 -9327 0 -9328 0 -9329 0 -9330 0 -9331 1 -9332 0 -9333 0 -9334 0 -9335 0 -9336 0 -9337 0 -9338 1 -9339 0 -9340 0 -9341 0 -9342 0 -9343 0 -9344 0 -9345 1 -9346 0 -9347 0 -9348 0 -9349 0 -9350 0 -9351 0 -9352 0 -9353 0 -9354 0 -9355 1 -9356 0 -9357 0 -9358 0 -9359 0 -9360 0 -9361 0 -9362 0 -9363 1 -9364 0 -9365 0 -9366 0 -9367 0 -9368 0 -9369 0 -9370 1 -9371 0 -9372 0 -9373 0 -9374 0 -9375 0 -9376 0 -9377 0 -9378 1 -9379 0 -9380 0 -9381 0 -9382 0 -9383 0 -9384 0 -9385 0 -9386 0 -9387 0 -9388 0 -9389 0 -9390 0 -9391 0 -9392 0 -9393 0 -9394 0 -9395 1 -9396 0 -9397 0 -9398 0 -9399 0 -9400 0 -9401 0 -9402 0 -9403 1 -9404 0 -9405 0 -9406 0 -9407 0 -9408 0 -9409 0 -9410 0 -9411 0 -9412 1 -9413 0 -9414 0 -9415 0 -9416 0 -9417 0 -9418 0 -9419 0 -9420 1 -9421 0 -9422 0 -9423 0 -9424 0 -9425 0 -9426 0 -9427 0 -9428 0 -9429 1 -9430 0 -9431 0 -9432 0 -9433 0 -9434 0 -9435 0 -9436 0 -9437 0 -9438 0 -9439 1 -9440 0 -9441 0 -9442 0 -9443 0 -9444 0 -9445 0 -9446 0 -9447 0 -9448 0 -9449 1 -9450 0 -9451 0 -9452 0 -9453 0 -9454 0 -9455 0 -9456 0 -9457 1 -9458 0 -9459 0 -9460 0 -9461 0 -9462 0 -9463 0 -9464 1 -9465 0 -9466 0 -9467 0 -9468 0 -9469 0 -9470 0 -9471 0 -9472 0 -9473 1 -9474 0 -9475 0 -9476 0 -9477 0 -9478 0 -9479 0 -9480 0 -9481 1 -9482 0 -9483 0 -9484 0 -9485 0 -9486 0 -9487 0 -9488 1 -9489 0 -9490 0 -9491 0 -9492 0 -9493 0 -9494 0 -9495 0 -9496 0 -9497 1 -9498 0 -9499 0 -9500 0 -9501 0 -9502 0 -9503 0 -9504 0 -9505 0 -9506 0 -9507 0 -9508 0 -9509 0 -9510 0 -9511 0 -9512 0 -9513 0 -9514 1 -9515 0 -9516 0 -9517 0 -9518 0 -9519 0 -9520 0 -9521 0 -9522 1 -9523 0 -9524 0 -9525 0 -9526 0 -9527 0 -9528 0 -9529 0 -9530 1 -9531 0 -9532 0 -9533 0 -9534 0 -9535 0 -9536 0 -9537 0 -9538 1 -9539 0 -9540 0 -9541 0 -9542 0 -9543 0 -9544 0 -9545 0 -9546 0 -9547 1 -9548 0 -9549 0 -9550 0 -9551 0 -9552 0 -9553 0 -9554 0 -9555 1 -9556 0 -9557 0 -9558 0 -9559 0 -9560 0 -9561 0 -9562 0 -9563 1 -9564 0 -9565 0 -9566 0 -9567 0 -9568 0 -9569 0 -9570 0 -9571 0 -9572 1 -9573 0 -9574 0 -9575 0 -9576 0 -9577 0 -9578 0 -9579 0 -9580 1 -9581 0 -9582 0 -9583 0 -9584 0 -9585 0 -9586 0 -9587 0 -9588 0 -9589 1 -9590 0 -9591 0 -9592 0 -9593 0 -9594 0 -9595 0 -9596 0 -9597 0 -9598 0 -9599 0 -9600 0 -9601 0 -9602 0 -9603 0 -9604 0 -9605 0 -9606 0 -9607 0 -9608 1 -9609 0 -9610 0 -9611 0 -9612 0 -9613 0 -9614 0 -9615 1 -9616 0 -9617 0 -9618 0 -9619 0 -9620 0 -9621 0 -9622 1 -9623 0 -9624 0 -9625 0 -9626 0 -9627 0 -9628 0 -9629 0 -9630 1 -9631 0 -9632 0 -9633 0 -9634 0 -9635 0 -9636 0 -9637 0 -9638 0 -9639 1 -9640 0 -9641 0 -9642 0 -9643 0 -9644 0 -9645 0 -9646 0 -9647 0 -9648 1 -9649 0 -9650 0 -9651 0 -9652 0 -9653 0 -9654 0 -9655 0 -9656 1 -9657 0 -9658 0 -9659 0 -9660 0 -9661 0 -9662 0 -9663 1 -9664 0 -9665 0 -9666 0 -9667 0 -9668 0 -9669 0 -9670 0 -9671 0 -9672 0 -9673 1 -9674 0 -9675 0 -9676 0 -9677 0 -9678 0 -9679 0 -9680 0 -9681 1 -9682 0 -9683 0 -9684 0 -9685 0 -9686 0 -9687 0 -9688 0 -9689 1 -9690 0 -9691 0 -9692 0 -9693 0 -9694 0 -9695 0 -9696 1 -9697 0 -9698 0 -9699 0 -9700 0 -9701 0 -9702 0 -9703 0 -9704 1 -9705 0 -9706 0 -9707 0 -9708 0 -9709 0 -9710 0 -9711 0 -9712 1 -9713 0 -9714 0 -9715 0 -9716 0 -9717 0 -9718 0 -9719 0 -9720 0 -9721 0 -9722 1 -9723 0 -9724 0 -9725 0 -9726 0 -9727 0 -9728 0 -9729 0 -9730 0 -9731 1 -9732 0 -9733 0 -9734 0 -9735 0 -9736 0 -9737 0 -9738 0 -9739 0 -9740 1 -9741 0 -9742 0 -9743 0 -9744 0 -9745 0 -9746 0 -9747 0 -9748 0 -9749 1 -9750 0 -9751 0 -9752 0 -9753 0 -9754 0 -9755 0 -9756 1 -9757 0 -9758 0 -9759 0 -9760 0 -9761 0 -9762 0 -9763 0 -9764 0 -9765 0 -9766 0 -9767 0 -9768 0 -9769 0 -9770 0 -9771 0 -9772 0 -9773 1 -9774 0 -9775 0 -9776 0 -9777 0 -9778 0 -9779 0 -9780 1 -9781 0 -9782 0 -9783 0 -9784 0 -9785 0 -9786 0 -9787 0 -9788 1 -9789 0 -9790 0 -9791 0 -9792 0 -9793 0 -9794 0 -9795 0 -9796 0 -9797 0 -9798 0 -9799 0 -9800 0 -9801 0 -9802 0 -9803 1 -9804 0 -9805 0 -9806 0 -9807 0 -9808 0 -9809 0 -9810 0 -9811 0 -9812 1 -9813 0 -9814 0 -9815 0 -9816 0 -9817 0 -9818 0 -9819 0 -9820 1 -9821 0 -9822 0 -9823 0 -9824 0 -9825 0 -9826 0 -9827 0 -9828 0 -9829 1 -9830 0 -9831 0 -9832 0 -9833 0 -9834 0 -9835 0 -9836 0 -9837 0 -9838 1 -9839 0 -9840 0 -9841 0 -9842 0 -9843 0 -9844 0 -9845 0 -9846 0 -9847 0 -9848 1 -9849 0 -9850 0 -9851 0 -9852 0 -9853 0 -9854 4 -9855 0 -9856 0 -9857 1 -9858 0 -9859 0 -9860 0 -9861 0 -9862 1 -9863 0 -9864 0 -9865 0 -9866 0 -9867 0 -9868 1 -9869 0 -9870 0 -9871 0 -9872 0 -9873 1 -9874 0 -9875 0 -9876 0 -9877 0 -9878 1 -9879 0 -9880 0 -9881 0 -9882 0 -9883 0 -9884 0 -9885 0 -9886 1 -9887 0 -9888 0 -9889 0 -9890 0 -9891 0 -9892 0 -9893 0 -9894 0 -9895 1 -9896 0 -9897 0 -9898 0 -9899 0 -9900 0 -9901 0 -9902 0 -9903 0 -9904 1 -9905 0 -9906 0 -9907 0 -9908 0 -9909 0 -9910 0 -9911 0 -9912 0 -9913 0 -9914 0 -9915 0 -9916 0 -9917 0 -9918 0 -9919 0 -9920 0 -9921 0 -9922 0 -9923 0 -9924 1 -9925 0 -9926 0 -9927 0 -9928 0 -9929 0 -9930 0 -9931 0 -9932 0 -9933 0 -9934 1 -9935 0 -9936 0 -9937 0 -9938 0 -9939 0 -9940 0 -9941 0 -9942 0 -9943 0 -9944 1 -9945 0 -9946 0 -9947 0 -9948 0 -9949 0 -9950 0 -9951 0 -9952 0 -9953 0 -9954 1 -9955 0 -9956 0 -9957 0 -9958 0 -9959 0 -9960 0 -9961 0 -9962 0 -9963 1 -9964 0 -9965 0 -9966 0 -9967 0 -9968 0 -9969 0 -9970 0 -9971 0 -9972 1 -9973 0 -9974 0 -9975 0 -9976 0 -9977 0 -9978 0 -9979 0 -9980 0 -9981 0 -9982 0 -9983 1 -9984 0 -9985 0 -9986 0 -9987 0 -9988 0 -9989 0 -9990 0 -9991 0 -9992 0 -9993 1 -9994 0 -9995 0 -9996 0 -9997 0 -9998 0 -9999 0 -10000 0 -10001 0 -10002 0 -10003 0 -10004 1 -10005 0 -10006 0 -10007 0 -10008 0 -10009 0 -10010 0 -10011 0 -10012 0 -10013 1 -10014 0 -10015 0 -10016 0 -10017 0 -10018 0 -10019 0 -10020 0 -10021 0 -10022 0 -10023 1 -10024 0 -10025 0 -10026 0 -10027 0 -10028 0 -10029 0 -10030 0 -10031 1 -10032 0 -10033 0 -10034 0 -10035 0 -10036 0 -10037 0 -10038 0 -10039 0 -10040 0 -10041 1 -10042 0 -10043 0 -10044 0 -10045 0 -10046 0 -10047 0 -10048 0 -10049 0 -10050 0 -10051 1 -10052 0 -10053 0 -10054 0 -10055 0 -10056 0 -10057 0 -10058 0 -10059 0 -10060 1 -10061 0 -10062 0 -10063 0 -10064 0 -10065 0 -10066 0 -10067 0 -10068 0 -10069 1 -10070 0 -10071 0 -10072 0 -10073 0 -10074 0 -10075 0 -10076 0 -10077 0 -10078 1 -10079 0 -10080 0 -10081 0 -10082 0 -10083 0 -10084 0 -10085 0 -10086 0 -10087 1 -10088 0 -10089 0 -10090 0 -10091 0 -10092 0 -10093 0 -10094 0 -10095 0 -10096 0 -10097 1 -10098 0 -10099 0 -10100 0 -10101 0 -10102 0 -10103 0 -10104 0 -10105 0 -10106 0 -10107 0 -10108 1 -10109 0 -10110 0 -10111 0 -10112 0 -10113 0 -10114 0 -10115 0 -10116 0 -10117 0 -10118 1 -10119 0 -10120 0 -10121 0 -10122 0 -10123 0 -10124 0 -10125 0 -10126 0 -10127 1 -10128 0 -10129 0 -10130 0 -10131 0 -10132 0 -10133 0 -10134 0 -10135 0 -10136 0 -10137 1 -10138 0 -10139 0 -10140 0 -10141 0 -10142 0 -10143 0 -10144 0 -10145 0 -10146 0 -10147 1 -10148 0 -10149 0 -10150 0 -10151 0 -10152 0 -10153 0 -10154 0 -10155 0 -10156 0 -10157 1 -10158 0 -10159 0 -10160 0 -10161 0 -10162 0 -10163 0 -10164 0 -10165 0 -10166 0 -10167 1 -10168 0 -10169 0 -10170 0 -10171 0 -10172 0 -10173 0 -10174 0 -10175 0 -10176 1 -10177 0 -10178 0 -10179 0 -10180 0 -10181 0 -10182 0 -10183 0 -10184 0 -10185 1 -10186 0 -10187 0 -10188 0 -10189 0 -10190 0 -10191 0 -10192 0 -10193 1 -10194 0 -10195 0 -10196 0 -10197 0 -10198 0 -10199 0 -10200 0 -10201 1 -10202 0 -10203 0 -10204 0 -10205 0 -10206 0 -10207 0 -10208 0 -10209 0 -10210 0 -10211 1 -10212 0 -10213 0 -10214 0 -10215 0 -10216 0 -10217 0 -10218 0 -10219 0 -10220 1 -10221 0 -10222 0 -10223 0 -10224 0 -10225 0 -10226 0 -10227 0 -10228 0 -10229 0 -10230 1 -10231 0 -10232 0 -10233 0 -10234 0 -10235 0 -10236 0 -10237 0 -10238 0 -10239 0 -10240 1 -10241 0 -10242 0 -10243 0 -10244 0 -10245 0 -10246 0 -10247 0 -10248 0 -10249 0 -10250 1 -10251 0 -10252 0 -10253 0 -10254 0 -10255 0 -10256 0 -10257 0 -10258 0 -10259 0 -10260 1 -10261 0 -10262 0 -10263 0 -10264 1 -10265 0 -10266 0 -10267 0 -10268 0 -10269 0 -10270 1 -10271 0 -10272 0 -10273 0 -10274 0 -10275 0 -10276 0 -10277 0 -10278 1 -10279 0 -10280 0 -10281 0 -10282 0 -10283 0 -10284 0 -10285 0 -10286 1 -10287 0 -10288 0 -10289 0 -10290 0 -10291 0 -10292 0 -10293 0 -10294 0 -10295 0 -10296 1 -10297 0 -10298 0 -10299 0 -10300 0 -10301 0 -10302 0 -10303 0 -10304 0 -10305 1 -10306 0 -10307 0 -10308 0 -10309 0 -10310 0 -10311 0 -10312 0 -10313 0 -10314 1 -10315 0 -10316 0 -10317 0 -10318 0 -10319 0 -10320 0 -10321 0 -10322 0 -10323 1 -10324 0 -10325 0 -10326 0 -10327 0 -10328 0 -10329 0 -10330 0 -10331 0 -10332 0 -10333 1 -10334 0 -10335 0 -10336 0 -10337 0 -10338 0 -10339 0 -10340 0 -10341 0 -10342 0 -10343 0 -10344 0 -10345 0 -10346 0 -10347 0 -10348 0 -10349 0 -10350 0 -10351 1 -10352 0 -10353 0 -10354 0 -10355 0 -10356 0 -10357 0 -10358 0 -10359 0 -10360 1 -10361 0 -10362 0 -10363 0 -10364 0 -10365 0 -10366 0 -10367 0 -10368 0 -10369 0 -10370 1 -10371 0 -10372 0 -10373 0 -10374 0 -10375 0 -10376 0 -10377 0 -10378 0 -10379 0 -10380 1 -10381 0 -10382 0 -10383 0 -10384 0 -10385 0 -10386 0 -10387 1 -10388 0 -10389 0 -10390 0 -10391 0 -10392 0 -10393 0 -10394 0 -10395 1 -10396 0 -10397 0 -10398 0 -10399 0 -10400 0 -10401 0 -10402 0 -10403 0 -10404 1 -10405 0 -10406 0 -10407 0 -10408 0 -10409 0 -10410 0 -10411 0 -10412 0 -10413 0 -10414 1 -10415 0 -10416 0 -10417 0 -10418 0 -10419 0 -10420 0 -10421 0 -10422 0 -10423 1 -10424 0 -10425 0 -10426 0 -10427 0 -10428 0 -10429 0 -10430 0 -10431 0 -10432 0 -10433 1 -10434 0 -10435 0 -10436 0 -10437 0 -10438 0 -10439 0 -10440 0 -10441 0 -10442 0 -10443 1 -10444 0 -10445 0 -10446 0 -10447 0 -10448 0 -10449 0 -10450 0 -10451 0 -10452 1 -10453 0 -10454 0 -10455 0 -10456 0 -10457 0 -10458 0 -10459 0 -10460 1 -10461 0 -10462 0 -10463 0 -10464 0 -10465 0 -10466 0 -10467 0 -10468 0 -10469 1 -10470 0 -10471 0 -10472 0 -10473 0 -10474 0 -10475 0 -10476 0 -10477 0 -10478 0 -10479 1 -10480 0 -10481 0 -10482 0 -10483 0 -10484 0 -10485 0 -10486 0 -10487 0 -10488 0 -10489 1 -10490 0 -10491 0 -10492 0 -10493 0 -10494 0 -10495 0 -10496 0 -10497 0 -10498 1 -10499 0 -10500 0 -10501 0 -10502 0 -10503 0 -10504 0 -10505 0 -10506 1 -10507 0 -10508 0 -10509 0 -10510 0 -10511 0 -10512 0 -10513 0 -10514 0 -10515 0 -10516 0 -10517 1 -10518 0 -10519 0 -10520 0 -10521 0 -10522 0 -10523 0 -10524 0 -10525 0 -10526 0 -10527 1 -10528 0 -10529 0 -10530 0 -10531 0 -10532 0 -10533 0 -10534 0 -10535 0 -10536 1 -10537 0 -10538 0 -10539 0 -10540 0 -10541 0 -10542 0 -10543 0 -10544 0 -10545 1 -10546 0 -10547 0 -10548 0 -10549 0 -10550 0 -10551 0 -10552 0 -10553 0 -10554 0 -10555 1 -10556 0 -10557 0 -10558 0 -10559 0 -10560 0 -10561 0 -10562 0 -10563 0 -10564 0 -10565 0 -10566 1 -10567 0 -10568 0 -10569 0 -10570 0 -10571 0 -10572 0 -10573 0 -10574 0 -10575 0 -10576 0 -10577 0 -10578 0 -10579 0 -10580 0 -10581 0 -10582 0 -10583 0 -10584 0 -10585 0 -10586 0 -10587 1 -10588 0 -10589 0 -10590 0 -10591 0 -10592 0 -10593 0 -10594 0 -10595 0 -10596 0 -10597 0 -10598 1 -10599 0 -10600 0 -10601 0 -10602 0 -10603 0 -10604 0 -10605 0 -10606 0 -10607 0 -10608 0 -10609 1 -10610 0 -10611 0 -10612 0 -10613 0 -10614 0 -10615 0 -10616 0 -10617 1 -10618 0 -10619 0 -10620 0 -10621 0 -10622 0 -10623 0 -10624 0 -10625 1 -10626 0 -10627 0 -10628 0 -10629 0 -10630 0 -10631 0 -10632 0 -10633 0 -10634 1 -10635 0 -10636 0 -10637 0 -10638 0 -10639 0 -10640 0 -10641 0 -10642 0 -10643 0 -10644 1 -10645 0 -10646 0 -10647 0 -10648 0 -10649 0 -10650 0 -10651 0 -10652 0 -10653 1 -10654 0 -10655 0 -10656 0 -10657 0 -10658 0 -10659 0 -10660 0 -10661 1 -10662 0 -10663 0 -10664 0 -10665 0 -10666 0 -10667 0 -10668 0 -10669 0 -10670 0 -10671 1 -10672 0 -10673 0 -10674 0 -10675 0 -10676 0 -10677 0 -10678 0 -10679 0 -10680 0 -10681 1 -10682 0 -10683 0 -10684 0 -10685 0 -10686 0 -10687 0 -10688 0 -10689 0 -10690 0 -10691 0 -10692 0 -10693 0 -10694 0 -10695 0 -10696 0 -10697 0 -10698 0 -10699 0 -10700 0 -10701 1 -10702 0 -10703 0 -10704 0 -10705 0 -10706 0 -10707 0 -10708 0 -10709 0 -10710 0 -10711 1 -10712 0 -10713 0 -10714 0 -10715 0 -10716 0 -10717 0 -10718 0 -10719 0 -10720 0 -10721 1 -10722 0 -10723 0 -10724 0 -10725 0 -10726 0 -10727 0 -10728 0 -10729 0 -10730 1 -10731 0 -10732 0 -10733 0 -10734 0 -10735 0 -10736 0 -10737 0 -10738 0 -10739 0 -10740 1 -10741 0 -10742 0 -10743 0 -10744 0 -10745 0 -10746 0 -10747 0 -10748 0 -10749 1 -10750 0 -10751 0 -10752 0 -10753 0 -10754 0 -10755 0 -10756 0 -10757 0 -10758 0 -10759 1 -10760 0 -10761 0 -10762 0 -10763 0 -10764 0 -10765 0 -10766 0 -10767 0 -10768 0 -10769 0 -10770 1 -10771 0 -10772 0 -10773 0 -10774 0 -10775 0 -10776 0 -10777 0 -10778 0 -10779 0 -10780 1 -10781 0 -10782 0 -10783 0 -10784 0 -10785 0 -10786 0 -10787 0 -10788 0 -10789 0 -10790 1 -10791 0 -10792 0 -10793 0 -10794 0 -10795 0 -10796 0 -10797 0 -10798 0 -10799 0 -10800 1 -10801 0 -10802 0 -10803 0 -10804 0 -10805 0 -10806 0 -10807 0 -10808 0 -10809 0 -10810 0 -10811 0 -10812 0 -10813 0 -10814 0 -10815 0 -10816 0 -10817 0 -10818 0 -10819 0 -10820 1 -10821 0 -10822 0 -10823 0 -10824 0 -10825 0 -10826 0 -10827 0 -10828 0 -10829 0 -10830 0 -10831 1 -10832 0 -10833 0 -10834 0 -10835 0 -10836 0 -10837 0 -10838 0 -10839 0 -10840 1 -10841 0 -10842 0 -10843 0 -10844 0 -10845 0 -10846 0 -10847 0 -10848 0 -10849 0 -10850 0 -10851 0 -10852 0 -10853 0 -10854 0 -10855 0 -10856 0 -10857 0 -10858 0 -10859 0 -10860 1 -10861 0 -10862 0 -10863 0 -10864 0 -10865 0 -10866 0 -10867 0 -10868 0 -10869 1 -10870 0 -10871 0 -10872 0 -10873 0 -10874 0 -10875 0 -10876 0 -10877 0 -10878 0 -10879 0 -10880 1 -10881 0 -10882 0 -10883 0 -10884 0 -10885 0 -10886 0 -10887 0 -10888 0 -10889 0 -10890 1 -10891 0 -10892 0 -10893 0 -10894 0 -10895 0 -10896 0 -10897 0 -10898 0 -10899 0 -10900 1 -10901 0 -10902 0 -10903 0 -10904 0 -10905 0 -10906 0 -10907 0 -10908 0 -10909 0 -10910 0 -10911 1 -10912 0 -10913 0 -10914 0 -10915 0 -10916 0 -10917 0 -10918 0 -10919 0 -10920 0 -10921 1 -10922 0 -10923 0 -10924 0 -10925 0 -10926 0 -10927 0 -10928 0 -10929 0 -10930 0 -10931 1 -10932 0 -10933 0 -10934 0 -10935 0 -10936 0 -10937 0 -10938 0 -10939 0 -10940 1 -10941 0 -10942 0 -10943 0 -10944 0 -10945 0 -10946 0 -10947 0 -10948 0 -10949 1 -10950 0 -10951 0 -10952 0 -10953 0 -10954 0 -10955 0 -10956 0 -10957 0 -10958 1 -10959 0 -10960 0 -10961 0 -10962 0 -10963 0 -10964 0 -10965 0 -10966 0 -10967 0 -10968 1 -10969 0 -10970 0 -10971 0 -10972 0 -10973 0 -10974 0 -10975 0 -10976 0 -10977 0 -10978 1 -10979 0 -10980 0 -10981 0 -10982 0 -10983 0 -10984 0 -10985 0 -10986 0 -10987 0 -10988 0 -10989 1 -10990 0 -10991 0 -10992 0 -10993 0 -10994 0 -10995 0 -10996 0 -10997 0 -10998 0 -10999 0 -11000 1
\ No newline at end of file diff --git a/node_modules/mongodb-core/test.js b/node_modules/mongodb-core/test.js deleted file mode 100644 index 8864284..0000000 --- a/node_modules/mongodb-core/test.js +++ /dev/null @@ -1,71 +0,0 @@ -var ReplSet = require('./lib2/topologies/replset'), - ReadPreference = require('./lib2/topologies/read_preference'); - -// Attempt to connect -var server = new ReplSet([{ - host: 'localhost', port: 31000 -}, { - host: 'localhost', port: 31001 -}], { - setName: 'rs' -}); - -function executeCursors(_server, cb) { - var count = 100; - - for(var i = 0; i < 100; i++) { - // Execute the write - var cursor = _server.cursor('test.test', { - find: 'test.test' - , query: {a:1} - }, {readPreference: new ReadPreference('secondary')}); - - // Get the first document - cursor.next(function(err, doc) { - count = count - 1; - if(err) console.dir(err) - if(count == 0) return cb(); - }); - } -} - -server.on('connect', function(_server) { - console.log("---------------------------------- 0") - // Attempt authentication - _server.auth('scram-sha-1', 'admin', 'root', 'root', function(err, r) { - console.log("---------------------------------- 1") - // console.dir(err) - // console.dir(r) - - _server.insert('test.test', [{a:1}], function(err, r) { - console.log("---------------------------------- 2") - console.dir(err) - if(r)console.dir(r.result) - var name = null; - - _server.on('joined', function(_t, _server) { - if(name == _server.name) { - console.log("=========== joined :: " + _t + " :: " + _server.name) - executeCursors(_server, function() { - }); - } - }) - - // var s = _server.s.replicaSetState.secondaries[0]; - // s.destroy({emitClose:true}); - executeCursors(_server, function() { - console.log("============== 0") - // Attempt to force a server reconnect - var s = _server.s.replicaSetState.secondaries[0]; - name = s.name; - s.destroy({emitClose:true}); - // console.log("============== 1") - - // _server.destroy(); - // test.done(); - }); - }); - }); -}); - -server.connect(); |
