UNPKG

thali

Version:
211 lines (175 loc) 11.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: NextGeneration/thaliPeerAction.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: NextGeneration/thaliPeerAction.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>'use strict'; var Promise = require('lie'); /** @module thaliPeerAction */ /** * Records the current state of the action. * * @public * @readonly * @enum {string} */ module.exports.actionState = { /** The action has been created but hasn't started or ended yet. */ CREATED: 'created', /** The action is out of the queue and is currently running */ STARTED: 'started', /** The action is not running and not in the queue */ KILLED: 'killed' }; /** * An action that has been given to the pool to manage. * * When an action is created its state MUST be CREATED. * * @public * @interface PeerAction * @constructor * @param {string} peerIdentifier * @param {module:thaliMobile.connectionTypes} connectionType * @param {string} actionType */ function PeerAction (peerIdentifier, connectionType, actionType) { this.peerIdentifier = peerIdentifier; this.connectionType = connectionType; this.actionType = actionType; this.actionState = module.exports.actionState.STARTED; } /** * The remote peer this action targets * @private * @type {string} */ PeerAction.prototype.peerIdentifier = null; PeerAction.prototype.getPeerIdentifier = function () { return this.peerIdentifier; }; /** * The type of connection the requests will be sent over * @private * @type {module:thaliMobile.connectionTypes} */ PeerAction.prototype.connectionType = null; PeerAction.prototype.getConnectionType = function () { return this.connectionType; }; /** * The type of action that will be taken * @private * @type {string} */ PeerAction.prototype.actionType = null; PeerAction.prototype.getActionType = function () { return this.actionType; }; /** * The current state of the action * @private * @type {module:thaliPeerAction.actionState} */ PeerAction.prototype.actionState = null; PeerAction.prototype.getActionState = function () { return this.actionState; }; /** * Tells the action to begin processing. When the action has completed it will * resolve the returned promise successfully with a null value. Once the * returned promise resolves then the pool MUST stop tracking this action. * Errors from the promise results SHOULD be logged. * * Start is idempotent so multiple calls MUST NOT directly cause a state change. * That is, if the action hasn't started then the first call to start will * start it and further calls will accomplish nothing. * * If start is called on an action that has completed, successfully or not, then * an error object MUST be returned with the value "action has completed." * * If the action fails due to a network issue it is important that this be * reported to the pool because it can use this information to decide how to * schedule things. The pool is expected to have subscribed for events like * {@link module:thaliMobile.event:networkChanged} and * {@link module:thaliMobile.event:discoveryAdvertisingStateUpdate} and so * understand when there are general connections failures. The action MUST use * the following error messages if the related errors occur. * * "Could not establish TCP connection" - This error indicates that the action * gave up because it got too many errors trying to connect over TCP to its * target peer. * * "Could establish TCP connection but couldn't keep it running" - In a HTTP * context this primarily to cases where a connection appears to exist but * all HTTP requests never seem to be able to successfully complete. * * When start returns the action's state MUST be STARTED. * * @public * @param {http.Agent} httpAgentPool The HTTP client connection pool to * use when making requests to the requested peer. * @returns {Promise&lt;?Error>} returns a promise that will resolve when the * action is done. Note that if kill is called on an action then it MUST still * return success with null. After all, kill doesn't reflect a failure * of the action but a change in outside circumstances. */ PeerAction.prototype.start = function (httpAgentPool) { this.actionState = module.exports.actionState.STARTED; return new Promise(); }; /** * Tells an action to stop executing immediately and synchronously. * * If the action is already dead then there is no error. If the action isn't * dead then once it is killed off it MUST return null to its promise as defined * above. * * This method is idempotent so multiple calls MUST NOT directly cause a state * change. * * When kill returns the action's state MUST be set to KILLED. * * @public * @returns {?Error} */ PeerAction.prototype.kill = function () { this.actionState = module.exports.actionState.KILLED; return null; }; /** * * @returns {*} */ PeerAction.prototype.getActionState = function () { return this.actionState; }; module.exports.PeerAction = PeerAction; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliMobile.html">thaliMobile</a></li><li><a href="module-thaliMobileNative.html">thaliMobileNative</a></li><li><a href="module-thaliMobileNativeWrapper.html">thaliMobileNativeWrapper</a></li><li><a href="module-thaliNotificationAction.html">thaliNotificationAction</a></li><li><a href="module-thaliNotificationBeacons.html">thaliNotificationBeacons</a></li><li><a href="module-thaliNotificationClient.html">thaliNotificationClient</a></li><li><a href="module-thaliNotificationServer.html">thaliNotificationServer</a></li><li><a href="module-thaliPeerAction.html">thaliPeerAction</a></li><li><a href="module-thaliPeerDictionary.html">thaliPeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface.html">thaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Externals</h3><ul><li><a href="external-_Mobile(_connect_)_.html">Mobile('connect')</a></li><li><a href="external-_Mobile(_discoveryAdvertisingStateUpdateNonTCP_)_.html">Mobile('discoveryAdvertisingStateUpdateNonTCP')</a></li><li><a href="external-_Mobile(_incomingConnectionToPortNumberFailed_)_.html">Mobile('incomingConnectionToPortNumberFailed')</a></li><li><a href="external-_Mobile(_killConnections_)_.html">Mobile('killConnections')</a></li><li><a href="external-_Mobile(_networkChanged_)_.html">Mobile('networkChanged')</a></li><li><a href="external-_Mobile(_peerAvailabilityChanged_)_.html">Mobile('peerAvailabilityChanged')</a></li><li><a href="external-_Mobile(_startListeningForAdvertisements_)_.html">Mobile('startListeningForAdvertisements')</a></li><li><a href="external-_Mobile(_startUpdateAdvertisingAndListening_)_.html">Mobile('startUpdateAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopAdvertisingAndListening_)_.html">Mobile('stopAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopListeningForAdvertisements_)_.html">Mobile('stopListeningForAdvertisements')</a></li></ul><h3>Classes</h3><ul><li><a href="ConnectionTable.html">ConnectionTable</a></li><li><a href="module-TCPServersManager-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html">NotificationAction</a></li><li><a href="module-thaliNotificationBeacons-ParseBeaconsResponse.html">ParseBeaconsResponse</a></li><li><a href="module-thaliNotificationClient-ThaliNotificationClient.html">ThaliNotificationClient</a></li><li><a href="module-thaliNotificationServer-ThaliNotificationServer.html">ThaliNotificationServer</a></li><li><a href="module-thaliPeerAction-PeerAction.html">PeerAction</a></li><li><a href="module-thaliPeerDictionary-NotificationPeerDictionaryEntry.html">NotificationPeerDictionaryEntry</a></li><li><a href="module-thaliPeerDictionary-PeerConnectionInformation.html">PeerConnectionInformation</a></li><li><a href="module-thaliPeerDictionary-PeerDictionary.html">PeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface-ThaliPeerPoolInterface.html">ThaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock-MobileCallInstance.html">MobileCallInstance</a></li><li><a href="module-WifiBasedNativeMock-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Events</h3><ul><li><a href="module-thaliMobileNativeWrapper.html#~event:discoveryAdvertisingStateUpdateNonTCPEvent">discoveryAdvertisingStateUpdateNonTCPEvent</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:discoveryAdvertisingStateUpdateWifiEvent">discoveryAdvertisingStateUpdateWifiEvent</a></li><li><a href="module-TCPServersManager.html#~event:failedConnection">failedConnection</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:incomingConnectionToPortNumberFailed">incomingConnectionToPortNumberFailed</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:networkChangedNonTCP">networkChangedNonTCP</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:networkChangedWifi">networkChangedWifi</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:nonTCPPeerAvailabilityChangedEvent">nonTCPPeerAvailabilityChangedEvent</a></li><li><a href="module-TCPServersManager.html#~event:routerPortConnectionFailed">routerPortConnectionFailed</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">wifiPeerAvailabilityChanged</a></li><li><a href="module-thaliMobile.html#.event:event:discoveryAdvertisingStateUpdate">discoveryAdvertisingStateUpdate</a></li><li><a href="module-thaliMobile.html#.event:event:networkChanged">networkChanged</a></li><li><a href="module-thaliMobile.html#.event:event:peerAvailabilityChanged">peerAvailabilityChanged</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html#.event:event:Resolved">Resolved</a></li><li><a href="module-thaliNotificationClient.html#.event:event:peerAdvertisesDataForUs">peerAdvertisesDataForUs</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getPKCS12Content">getPKCS12Content</a></li><li><a href="global.html#getPublicKeyHash">getPublicKeyHash</a></li><li><a href="global.html#stopThaliReplicationManager">stopThaliReplicationManager</a></li><li><a href="global.html#ThaliEmitter">ThaliEmitter</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Jan 18 2016 11:19:31 GMT+0200 (EET) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>