itns-sidechain/lib/net/common.js

137 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-01-06 09:57:55 -08:00
/*!
* common.js - p2p constants for bcoin
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
2017-02-03 22:47:26 -08:00
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
2017-01-06 09:57:55 -08:00
* https://github.com/bcoin-org/bcoin
*/
'use strict';
2017-02-03 22:47:26 -08:00
/**
* @module net/common
*/
2017-06-29 20:54:07 -07:00
const pkg = require('../pkg');
2017-01-06 09:57:55 -08:00
/**
* Default protocol version.
* @const {Number}
* @default
*/
2018-01-02 20:24:56 -08:00
exports.PROTOCOL_VERSION = 1;
2017-01-06 09:57:55 -08:00
/**
* Minimum protocol version we're willing to talk to.
* @const {Number}
* @default
*/
2018-01-02 20:24:56 -08:00
exports.MIN_VERSION = 1;
2017-01-20 22:24:45 -08:00
2017-01-06 09:57:55 -08:00
/**
* Service bits.
* @enum {Number}
* @default
*/
exports.services = {
/**
* Whether network services are enabled.
*/
NETWORK: 1 << 0,
/**
* Whether the peer supports BIP37.
*/
2018-01-02 20:24:56 -08:00
BLOOM: 1 << 1
2017-01-06 09:57:55 -08:00
};
/**
2017-02-03 22:47:26 -08:00
* Bcoin's services (we support everything).
2017-01-06 09:57:55 -08:00
* @const {Number}
* @default
*/
exports.LOCAL_SERVICES = 0
2018-01-02 20:24:56 -08:00
| exports.services.NETWORK;
2017-01-06 09:57:55 -08:00
/**
* Required services (network and segwit).
* @const {Number}
* @default
*/
exports.REQUIRED_SERVICES = 0
2017-01-23 14:47:42 -08:00
| exports.services.NETWORK;
2017-01-06 09:57:55 -08:00
/**
* Default user agent: `/bcoin:[version]/`.
* @const {String}
* @default
*/
2018-01-02 20:24:56 -08:00
exports.USER_AGENT = `/chainwork:${pkg.version}/`;
2017-01-06 09:57:55 -08:00
/**
* Max message size (~4mb with segwit, formerly 2mb)
* @const {Number}
* @default
*/
exports.MAX_MESSAGE = 4 * 1000 * 1000;
/**
* Amount of time to ban misbheaving peers.
* @const {Number}
* @default
*/
exports.BAN_TIME = 24 * 60 * 60;
/**
* Ban score threshold before ban is placed in effect.
* @const {Number}
* @default
*/
exports.BAN_SCORE = 100;
2017-10-26 04:07:36 -07:00
/**
* Create a nonce.
* @returns {Buffer}
*/
exports.nonce = function nonce() {
const data = Buffer.allocUnsafe(8);
data.writeUInt32LE(Math.random() * 0x100000000, true, 0);
data.writeUInt32LE(Math.random() * 0x100000000, true, 4);
return data;
};
2017-11-16 23:52:14 -08:00
/**
* A compressed pubkey of all zeroes.
* @const {Buffer}
* @default
*/
exports.ZERO_KEY = Buffer.alloc(33, 0x00);
/**
* A 64 byte signature of all zeroes.
* @const {Buffer}
* @default
*/
exports.ZERO_SIG = Buffer.alloc(64, 0x00);
/**
* 8 zero bytes.
* @const {Buffer}
* @default
*/
exports.ZERO_NONCE = Buffer.alloc(8, 0x00);