use buffers for nonces.
This commit is contained in:
parent
e74b163b9e
commit
404bdcd109
@ -52,7 +52,7 @@ var constants = bcoin.protocol.constants;
|
||||
* @property {Bloom?} filter - The _peer's_ bloom filter.
|
||||
* @property {Boolean} relay - Whether to relay transactions
|
||||
* immediately to the peer.
|
||||
* @property {BN} challenge - Local nonce.
|
||||
* @property {Buffer} challenge - Local nonce.
|
||||
* @property {Number} lastPong - Timestamp for last `pong`
|
||||
* received (unix time).
|
||||
* @property {String} id - Peer's uid.
|
||||
@ -1235,7 +1235,7 @@ Peer.prototype._handlePing = function handlePing(data) {
|
||||
};
|
||||
|
||||
Peer.prototype._handlePong = function handlePong(data) {
|
||||
if (!this.challenge || this.challenge.cmp(data.nonce) !== 0)
|
||||
if (!this.challenge || utils.cmp(data.nonce, this.challenge) !== 0)
|
||||
return this.emit('pong', false);
|
||||
|
||||
this.lastPong = utils.now();
|
||||
|
||||
@ -450,7 +450,7 @@ Framer.version = function version(options, writer) {
|
||||
p.write64(utils.now());
|
||||
Framer.address(remote, false, p);
|
||||
Framer.address(local, false, p);
|
||||
p.writeU64(utils.nonce());
|
||||
p.writeBytes(utils.nonce());
|
||||
p.writeVarString(agent);
|
||||
p.write32(options.height || 0);
|
||||
p.writeU8(options.relay ? 1 : 0);
|
||||
@ -536,7 +536,7 @@ Framer.notFound = function notFound(items, writer) {
|
||||
|
||||
Framer.ping = function ping(data) {
|
||||
var p = new Buffer(8);
|
||||
utils.writeU64(p, data.nonce, 0);
|
||||
data.nonce.copy(p, 0, 0, 8);
|
||||
return p;
|
||||
};
|
||||
|
||||
@ -549,7 +549,7 @@ Framer.ping = function ping(data) {
|
||||
|
||||
Framer.pong = function pong(data) {
|
||||
var p = new Buffer(8);
|
||||
utils.writeU64(p, data.nonce, 0);
|
||||
data.nonce.copy(p, 0, 0, 8);
|
||||
return p;
|
||||
};
|
||||
|
||||
|
||||
@ -435,7 +435,7 @@ Parser.parsePing = function parsePing(p) {
|
||||
p = new BufferReader(p);
|
||||
|
||||
return {
|
||||
nonce: p.readU64()
|
||||
nonce: p.readBytes(8)
|
||||
};
|
||||
};
|
||||
|
||||
@ -449,7 +449,7 @@ Parser.parsePong = function parsePong(p) {
|
||||
p = new BufferReader(p);
|
||||
|
||||
return {
|
||||
nonce: p.readU64()
|
||||
nonce: p.readBytes(8)
|
||||
};
|
||||
};
|
||||
|
||||
@ -469,7 +469,7 @@ Parser.parseVersion = function parseVersion(p) {
|
||||
ts = p.read53();
|
||||
recv = Parser.parseAddress(p, false);
|
||||
from = Parser.parseAddress(p, false);
|
||||
nonce = p.readU64();
|
||||
nonce = p.readBytes(8);
|
||||
agent = p.readVarString('ascii');
|
||||
height = p.read32();
|
||||
|
||||
|
||||
@ -240,7 +240,7 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} PingPacket
|
||||
* @property {BN} nonce
|
||||
* @property {Buffer} nonce
|
||||
* @global
|
||||
*/
|
||||
|
||||
@ -265,7 +265,7 @@
|
||||
* @property {Number} ts - Timestamp of discovery.
|
||||
* @property {NetworkAddress} local - Our address.
|
||||
* @property {NetworkAddress} remote - Their address.
|
||||
* @property {BN} nonce
|
||||
* @property {Buffer} nonce
|
||||
* @property {String} agent - User agent string.
|
||||
* @property {Number} height - Chain height.
|
||||
* @property {Boolean} relay - Whether transactions
|
||||
|
||||
@ -1286,14 +1286,14 @@ utils.U64 = new bn('ffffffffffffffff', 'hex');
|
||||
|
||||
/**
|
||||
* Create an 8 byte nonce.
|
||||
* @returns {BN}
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
utils.nonce = function _nonce() {
|
||||
var nonce = new Buffer(8);
|
||||
utils.writeU32(nonce, Math.random() * 0x100000000 | 0, 0);
|
||||
utils.writeU32(nonce, Math.random() * 0x100000000 | 0, 4);
|
||||
return new bn(nonce);
|
||||
return nonce;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user