-
Notifications
You must be signed in to change notification settings - Fork 27
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
improve negotiation flushing #52
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"bufio" | ||
"bytes" | ||
"errors" | ||
|
||
"io" | ||
"sync" | ||
|
||
|
@@ -51,6 +52,13 @@ func NewMultistreamMuxer() *MultistreamMuxer { | |
return new(MultistreamMuxer) | ||
} | ||
|
||
// LazyConn is the connection type returned by the lazy negotiation functions. | ||
type LazyConn interface { | ||
io.ReadWriteCloser | ||
// Flush flushes the lazy negotiation, if any. | ||
Flush() error | ||
} | ||
|
||
func writeUvarint(w io.Writer, i uint64) error { | ||
varintbuf := make([]byte, 16) | ||
n := varint.PutUvarint(varintbuf, i) | ||
|
@@ -201,7 +209,7 @@ func (msm *MultistreamMuxer) findHandler(proto string) *Handler { | |
// a multistream, the protocol used, the handler and an error. It is lazy | ||
// because the write-handshake is performed on a subroutine, allowing this | ||
// to return before that handshake is completed. | ||
func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (io.ReadWriteCloser, string, HandlerFunc, error) { | ||
func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (LazyConn, string, HandlerFunc, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is breaking, and it's a problem. Currently, go-libp2p-core expects this to return an However, there is no explicit dependency relationship between this module and go-libp2p-core (intentionally). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I've reverted this. I'm going to do type assertions in go-libp2p where necessary. |
||
pval := make(chan string, 1) | ||
writeErr := make(chan error, 1) | ||
defer close(pval) | ||
|
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.
Replacing this with an explicit
LazyConn
is technically breaking, but nothing uses it (and the interface was quite useless...).