More net stub
This commit is contained in:
parent
22c7f7c298
commit
2ee782090d
|
@ -56,7 +56,7 @@ API documentation is available [here](https://bitchan.github.io/bitmessage/docs/
|
||||||
- [x] High-level classes
|
- [x] High-level classes
|
||||||
- [x] Address
|
- [x] Address
|
||||||
- [x] UserAgent
|
- [x] UserAgent
|
||||||
- [ ] Network
|
- [ ] Network transports
|
||||||
- [ ] TCP (Node.js only)
|
- [ ] TCP (Node.js only)
|
||||||
- [ ] WebSocket
|
- [ ] WebSocket
|
||||||
- [ ] WebRTC
|
- [ ] WebRTC
|
||||||
|
|
78
lib/net/base.js
Normal file
78
lib/net/base.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
var PPromise = require("./platform").Promise;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Network transport base class.
|
||||||
|
* @constructor
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function BaseTransport() {
|
||||||
|
BaseTransport.super_.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inherits(BaseTransport, EventEmitter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed nodes for this transport. Consist of `[host, port]` pairs.
|
||||||
|
* Note that this nodes shouldn't be advertised via `addr` messages.
|
||||||
|
* @const {Array.}
|
||||||
|
*/
|
||||||
|
BaseTransport.prototype.SEED_NODES = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do the transport-specific bootstrap process and return promise that
|
||||||
|
* contains discovered nodes when fulfilled.
|
||||||
|
* @return {Promise.<Array.>}
|
||||||
|
*/
|
||||||
|
BaseTransport.prototype.bootstrap = function() {
|
||||||
|
return PPromise.resolve([].concat(this.SEED_NODES));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to the transport-specific address.
|
||||||
|
* Should emit `open` event when the connection is established.
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
BaseTransport.prototype.connect = function() {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send [message]{@link module:bitmessage/structs.message} over the
|
||||||
|
* wire.
|
||||||
|
* @param {Buffer} msg - Encoded message
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
BaseTransport.prototype.send = function() {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close connection.
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
BaseTransport.prototype.close = function() {
|
||||||
|
throw new Error("Not implemented");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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");
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.BaseTransport = BaseTransport;
|
|
@ -0,0 +1 @@
|
||||||
|
throw new Error("Not implemented");
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
* TCP transport for Node. Should be compatible with PyBitmessage.
|
||||||
|
* @module bitmessage/net/tcp
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var inherits = require("inherits");
|
||||||
|
var BaseTransport = require("./base").BaseTransport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TCP transport constructor.
|
||||||
|
* @constructor
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function Transport() {
|
||||||
|
Transport.super_.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inherits(Transport, BaseTransport);
|
||||||
|
|
||||||
|
exports.Transport = Transport;
|
|
@ -0,0 +1 @@
|
||||||
|
throw new Error("Not implemented");
|
|
@ -0,0 +1 @@
|
||||||
|
throw new Error("Not implemented");
|
|
@ -56,10 +56,12 @@
|
||||||
"eccrypto": "^0.9.5",
|
"eccrypto": "^0.9.5",
|
||||||
"es6-promise": "^2.0.1",
|
"es6-promise": "^2.0.1",
|
||||||
"hash.js": "^1.0.2",
|
"hash.js": "^1.0.2",
|
||||||
|
"inherits": "^2.0.1",
|
||||||
"nan": "^1.4.1",
|
"nan": "^1.4.1",
|
||||||
"object-assign": "^2.0.0",
|
"object-assign": "^2.0.0",
|
||||||
"sha.js": "^2.3.1",
|
"sha.js": "^2.3.1",
|
||||||
"webworkify": "^1.0.1"
|
"webworkify": "^1.0.1",
|
||||||
|
"ws": "^0.7.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"bignum": "^0.9.0"
|
"bignum": "^0.9.0"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user