Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Make everything more 'streamy' #1

Closed
daviddias opened this issue Sep 17, 2015 · 2 comments
Closed

Make everything more 'streamy' #1

daviddias opened this issue Sep 17, 2015 · 2 comments

Comments

@daviddias
Copy link
Member

multistream-select and libp2p-spdy can get a lot simpler (and nicer!) once spdy-transport starts returning a duplex stream, so that we have:

from the dialer end

var isListener = false
var ms = new MultiStream('/ipfs/protocol/1.0.0')
var spdy = new SpdyMuxer(isListener)

// internally there is a multistream handshake to upgrade this transport to spdy muxing
transport.pipe(spdy).pipe(transport)

someDuplex
  .pipe(ms)                  // to handshake the protocol we want to speak through the muxed stream
  .pipe(spdy.createStream()) // mux a new stream
  .pipe(ms)                  // confirm the handshake 
  .pipe(someDuplex)

and from listener end

var isListener = true
var ms = new MultiStream('/ipfs/protocol/1.0.0', function handler(stream) {
  // your handler code for this protocol
}) 
// we can have more than one handler on a MultiStream simply by calling ms.addHandler(protocol, handlerFunc)

var spdy = new SpdyMuxer(isListener)

// we get the multistream handshake into spdy internally
transport.pipe(spdy).pipe(transport)

spdy.on('stream', function (stream) {
  // this would start the multistream handshake on this stream
  stream.pipe(ms).pipe(stream)
})
@daviddias
Copy link
Member Author

@mafintosh would you mind reviewing the idea above? Want to make sure that I'm not missing anything with all this streaming goodness.

It will make swarm and the whole idea of upgrading connections through multistream handshakes so much simple

Thank you :)

@daviddias
Copy link
Member Author

(until then, I'll have to work it out with a less elegant solution)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant