Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few minor improvements #75

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ Inventory.prototype.toBufferWriter = function(bw) {
return bw;
};

/**
* @return {String} name of inventory type
*/
Inventory.prototype.typeName = function () {
return Inventory.TYPE_NAME[this.type];
};

/**
* @return {String} name of inventory type : hash
*/
Inventory.prototype.toString = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, all of the toString() methods have matching fromString() methods, and can be passed in as an argument to the constructor. This may be better as an inspect() method (e.g. https://github.com/bitpay/bitcore-p2p/blob/master/lib/pool.js#L337).

return this.typeName() + ':' + BufferUtil.reverse(this.hash).toString('hex');
};

/**
* @param {Buffer} payload - Serialized buffer of the inventory
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ Peer.prototype.disconnect = function() {
* Send a Message to the remote peer.
* @param {Message} message - A message instance
*/
Peer.prototype.sendMessage = function(message) {
this.socket.write(message.toBuffer());
Peer.prototype.sendMessage = function(message, cb) {
this.socket.write(message.toBuffer(), cb);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"bitcore": "^0.12.0",
"bloom-filter": "^0.2.0",
"buffers": "^0.1.1",
"buffers": "olalonde/node-buffers",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to node-buffers look good, however this references an unpublished master branch. There are a few open issues, #52 and #32 with node-buffers already. I believe we only use a small portion of the implemented methods, so we may be able to make this a part of this codebase, since we're also adding the skip method. However we can take care of this in another PR as well as the deprecation warnings.

"socks5-client": "^0.3.6"
},
"devDependencies": {
Expand Down