-
Notifications
You must be signed in to change notification settings - Fork 276
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
Extensible Messages #48
Conversation
- changed options in constructors - define block and transaction constructors for block and tx messages
- Renamed "Commands" to "builder" - "Messages.parseMessage" to "Messages.parseBuffer" - Changed to use private methods for "discardUntilNextMessage" and "buildFromBuffer" - Cleaned up tests
b066b7e
to
32a28b1
Compare
}; | ||
|
||
module.exports = Buffers; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a pretty useful function. Should we submit it to the global buffers module https://github.com/substack/node-buffers? I'd be happy to give it a go if that's the right thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, we may not need this dependency either though, since we may only be using push()
. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I wanted to take out this dependency as well at some point, don't remember what changed my mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spawned an issue: #52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you unit-test the skip function please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added test in: braydonf@7cfe6d1
* A Peer instance represents a remote bitcoin node and allows to communicate | ||
* with it using the standard messages of the bitcoin p2p protocol. | ||
* A constructor to create Peer instances to send and recieve messages | ||
* using the standard Bitcoin protocol. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about: "The Peer class implements the Bitcoin peer-to-peer (P2P) network protocol. A Peer instance represents one connection on the Bitcoin network. To create a new peer connection to a remote server, provide the host and port options in the class constructor and then invoke the connect method. Incoming peer connections are handled by the Pool class and its listen method."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using "constructor" I think is more descriptive. There is also the option of passing a "socket" in, and "host" and "port" are based on the connected socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that constructor is better here as you had it. There's a typo though *receive. In retrospect my suggestion was really as an update to docs/peer.md class description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in: 664ceb2
Amazing work, great! There are a few nits on the tests names but I'd approve this PR as is. I'll review it more in-deep this afternoon |
Two questions:
|
|
Edit: Took a look at implementing #2 And think the current solution is better. |
getdata: 'GetData', | ||
headers: 'Headers', | ||
notfound: 'NotFound', | ||
inv: 'Inventory', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the message now called InvMessage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, however it's mapped here with just Inventory. messages.Inventory
rather than messages.InvMessage
. Should they be the same?
LGTM, let's merge this |
*/ | ||
InvMessage.forFilteredBlock = function(hash) { | ||
return new InvMessage([Inventory.forFilteredBlock(hash)]); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that these 3 methods (forBlock
, forFilteredBlock
and forTransaction
) are repeated in some classes. Why don't you use a generic method builder like: https://github.com/bitpay/bitcore-p2p/blob/master/lib/messages.js#L974 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be possible. I left them there so that these constructors could be used standalone (i.e. without the Messages factory), though that isn't a prominent use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in: braydonf@34c3846 moved the helpers to builder.
Great work in general, left some small comments. Please fix/reply and I'll be happy to merge this :) |
Messages are now built with a factory that can be customized with an options argument to
Messages
, for example:Additionally, individual message constructors have been organized into separate files.
Peer and Pool now have options defined as an object to avoid needing to pass in "null, null, true" as arguments, for example:
Adds an Inventory constructor to be shared between several of the message types, separate from the Inventory message.
Changes to use BufferWriter instead of needing the "bufferput" dependency.
Adds a
listen()
method to Pool to enable remote peers to be added to the pool upon incoming connections, enables bitcore to bitcore node connectivity.Will disconnect a peer on error (to avoid _connectedPeers having invalid peers).
Increases test coverage