bitmessage-js/lib/net/base.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-02-01 21:34:47 +01:00
/**
* Networking base module. You should import some transport instead in
* order to connect/accept connections to/from other nodes.
* @module bitmessage/net/base
*/
// TODO(Kagami): Write some sort of tutorial.
"use strict";
var inherits = require("inherits");
var EventEmitter = require("events").EventEmitter;
2015-02-02 16:30:05 +01:00
var PPromise = require("../platform").Promise;
2015-02-01 21:34:47 +01:00
/**
* Network transport base class.
* @constructor
* @static
*/
function BaseTransport() {
BaseTransport.super_.call(this);
}
inherits(BaseTransport, EventEmitter);
/**
* Do the transport-specific bootstrap process and return promise that
* contains discovered nodes when fulfilled.
* @return {Promise.<Array.>}
2015-02-05 19:38:36 +01:00
* @abstract
2015-02-01 21:34:47 +01:00
*/
BaseTransport.prototype.bootstrap = function() {
2015-02-05 19:38:36 +01:00
return PPromise.reject(new Error("Not implemented"));
2015-02-01 21:34:47 +01:00
};
/**
* Connect to the transport-specific address.
2015-02-02 15:34:00 +01:00
* Should emit `open` event after successful connect and `established`
* event after `verack` messages exchange.
2015-02-01 21:34:47 +01:00
* @abstract
*/
BaseTransport.prototype.connect = function() {
throw new Error("Not implemented");
};
2015-02-05 19:38:36 +01:00
/**
* Listen for the transport-specific incoming connections.
* Should emit `connection` event with a transport instance for each new
* connection.
* @abstract
*/
BaseTransport.prototype.listen = function() {
throw new Error("Not implemented");
};
2015-02-01 21:34:47 +01:00
/**
* Send [message]{@link module:bitmessage/structs.message} over the
2015-02-05 19:38:36 +01:00
* wire (client mode).
2015-02-01 21:34:47 +01:00
* @param {Buffer} msg - Encoded message
* @abstract
*/
BaseTransport.prototype.send = function() {
throw new Error("Not implemented");
};
/**
2015-02-05 19:38:36 +01:00
* Send [message]{@link module:bitmessage/structs.message} to all
* connected clients (server mode).
* @param {Buffer} msg - Encoded message
2015-02-01 21:34:47 +01:00
* @abstract
*/
2015-02-05 19:38:36 +01:00
BaseTransport.prototype.broadcast = function() {
2015-02-01 21:34:47 +01:00
throw new Error("Not implemented");
};
/**
2015-02-05 19:38:36 +01:00
* Close connection(s) and/or stop listening.
2015-02-01 21:34:47 +01:00
* @abstract
*/
2015-02-05 19:38:36 +01:00
BaseTransport.prototype.close = function() {
2015-02-01 21:34:47 +01:00
throw new Error("Not implemented");
};
2015-02-06 10:47:40 +01:00
module.exports = BaseTransport;