version packet.
This commit is contained in:
parent
b563fe5de1
commit
1f0f9eb59e
@ -56,8 +56,13 @@ Framer.prototype.packet = function packet(cmd, payload) {
|
||||
return Buffer.concat([h, payload]);
|
||||
};
|
||||
|
||||
Framer.prototype.version = function version(packet) {
|
||||
return this.packet('version', Framer.version(packet, this.agent));
|
||||
Framer.prototype.version = function version(options) {
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
options.agent = this.agent;
|
||||
|
||||
return this.packet('version', Framer.version(options));
|
||||
};
|
||||
|
||||
Framer.prototype.verack = function verack() {
|
||||
@ -179,17 +184,19 @@ Framer.address = function addr(data, full) {
|
||||
return p;
|
||||
};
|
||||
|
||||
Framer.version = function version(packet, agent) {
|
||||
Framer.version = function version(options) {
|
||||
var off = 0;
|
||||
var p, i, remote, local;
|
||||
|
||||
if (!agent)
|
||||
agent = new Buffer(constants.userAgent, 'ascii');
|
||||
if (!options.agent)
|
||||
options.agent = new Buffer(constants.userAgent, 'ascii');
|
||||
|
||||
p = new Buffer(85 + utils.sizeIntv(agent.length) + agent.length);
|
||||
p = new Buffer(85
|
||||
+ utils.sizeIntv(options.agent.length)
|
||||
+ options.agent.length);
|
||||
|
||||
if (!packet)
|
||||
packet = {};
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
// Version
|
||||
off += utils.writeU32(p, constants.version, off);
|
||||
@ -201,11 +208,11 @@ Framer.version = function version(packet, agent) {
|
||||
off += utils.write64(p, utils.now(), off);
|
||||
|
||||
// Their address (recv)
|
||||
remote = Framer.address(packet.remote || {});
|
||||
remote = Framer.address(options.remote || {});
|
||||
off += utils.copy(remote, p, off);
|
||||
|
||||
// Our address (from)
|
||||
local = Framer.address(packet.local || {});
|
||||
local = Framer.address(options.local || {});
|
||||
off += utils.copy(local, p, off);
|
||||
|
||||
// Nonce, very dramatic
|
||||
@ -218,10 +225,10 @@ Framer.version = function version(packet, agent) {
|
||||
off += utils.copy(agent, p, off);
|
||||
|
||||
// Start height
|
||||
off += utils.writeU32(p, packet.height || 0, off);
|
||||
off += utils.writeU32(p, options.height || 0, off);
|
||||
|
||||
// Relay
|
||||
p[off++] = packet.relay ? 1 : 0;
|
||||
p[off++] = options.relay ? 1 : 0;
|
||||
|
||||
assert(off === p.length);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user