This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: refactor peer class #63
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vasco-santos
suggested changes
Jul 16, 2020
Member
vasco-santos
left a comment
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 is great!!
src/index.js
Outdated
| * @param {Object} props | ||
| * @param {string} props.protocol | ||
| * @param {DuplexStream} props.strean | ||
| * @param {Stream} props.stream |
Member
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.
Suggested change
| * @param {Stream} props.stream | |
| * @param {IterableStream} props.stream |
Per https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9, we should call this an IterableStream. This is not a node stream and might create confusion
Member
Author
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 called it DuplexIterableStream so its known to be a duplex object ({ sink, source })
vasco-santos
approved these changes
Jul 16, 2020
26 tasks
vasco-santos
pushed a commit
that referenced
this pull request
Aug 11, 2020
This was referenced Aug 28, 2020
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #54 and #56
Peerhas been renamed/replaced withPeerStreamsclass that manages incoming and outgoing streams._addPeerand_removePeerhave been slightly modified to suit - _removePeer closes a peer's streamsgetSubscribersnow usesthis.topicsrather thanpeer.topicsto determine the subscribers for a topicPeerStreamsmanages:id- thePeerIdof the peerprotocol- the protocol negotiated with the peer (previously was an array of protocols, which is described in Outgoing peer connections - peer protocols #54 )_rawOutboundStream(previously namedthis.conn) - this is the stream returned fromconn.newStreamoutboundStream(previously namedthis.stream) - this is the pushable stream to write outgoing messages to. Data pushed here is sent to _rawOutboundStream after first being transformed with a length-prefix encoding transform.It now manages an inbound stream as well
_rawInboundStream- this is the stream returned in the callback attached toregistrar.handle. Called when a peer dials us.inboundStream- this is an abortable stream with first a length-prefix decoding tranform applied. This is the stream that should be read from to receive incoming rpc messages.async attachOutboundStream(stream)- method to attach a new outgoing stream for management. If the stream is the first outgoing stream to be attached, this method triggers astream:outboundevent. If there is already an existing outgoing stream, the existing stream is gently shutdown (without triggering acloseevent) first, then the new stream is attached.attachInboundStream(stream)- method to attach a new incoming stream for management. If the stream is the first incoming stream to be attached, this method triggers astream:inboundevent. If there is already an existing incoming stream, the existing stream is gently shutdown (without triggering acloseevent) first, then the new stream is attached.write(data)- convenience method to push data to theoutboundStream, if it exists. If it doesn't, this method throws an error.close()- method to shutdown both incoming and outgoing streams, triggers acloseevent. In conjunction with the base Pubsub impl, thecloseevent will_removePeer.