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

remove MultistreamMuxer.NegotiateLazy #92

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions multistream.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,6 @@ func (msm *MultistreamMuxer) findHandler(proto string) *Handler {
return nil
}

// NegotiateLazy performs protocol selection and returns
// 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.
// Deprecated: use Negotiate instead.
func (msm *MultistreamMuxer) NegotiateLazy(rwc io.ReadWriteCloser) (rwc_ io.ReadWriteCloser, proto string, handler HandlerFunc, err error) {
proto, handler, err = msm.Negotiate(rwc)
return rwc, proto, handler, err
}

// Negotiate performs protocol selection and returns the protocol name and
// the matching handler function for it (or an error).
func (msm *MultistreamMuxer) Negotiate(rwc io.ReadWriteCloser) (proto string, handler HandlerFunc, err error) {
Expand Down
16 changes: 6 additions & 10 deletions multistream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ func TestProtocolNegotiationLazy(t *testing.T) {
mux.AddHandler("/b", nil)
mux.AddHandler("/c", nil)

var ac io.ReadWriteCloser
done := make(chan struct{})
go func() {
m, selected, _, err := mux.NegotiateLazy(a)
selected, _, err := mux.Negotiate(a)
if err != nil {
t.Error(err)
}
if selected != "/a" {
t.Error("incorrect protocol selected")
}
ac = m
close(done)
}()

Expand All @@ -146,7 +144,7 @@ func TestProtocolNegotiationLazy(t *testing.T) {
case <-done:
}

verifyPipe(t, ac, b)
verifyPipe(t, a, b)
}

func TestProtocolNegotiationUnsupported(t *testing.T) {
Expand Down Expand Up @@ -183,7 +181,7 @@ func TestNegLazyStressRead(t *testing.T) {
go func() {
defer close(done)
for rwc := range listener {
m, selected, _, err := mux.NegotiateLazy(rwc)
selected, _, err := mux.Negotiate(rwc)
if err != nil {
t.Error(err)
return
Expand All @@ -195,8 +193,7 @@ func TestNegLazyStressRead(t *testing.T) {
}

buf := make([]byte, len(message))
_, err = io.ReadFull(m, buf)
if err != nil {
if _, err := io.ReadFull(rwc, buf); err != nil {
t.Error(err)
return
}
Expand Down Expand Up @@ -237,7 +234,7 @@ func TestNegLazyStressWrite(t *testing.T) {
listener := make(chan io.ReadWriteCloser)
go func() {
for rwc := range listener {
m, selected, _, err := mux.NegotiateLazy(rwc)
selected, _, err := mux.Negotiate(rwc)
if err != nil {
t.Error(err)
return
Expand All @@ -248,8 +245,7 @@ func TestNegLazyStressWrite(t *testing.T) {
return
}

_, err = m.Write(message)
if err != nil {
if _, err := rwc.Write(message); err != nil {
t.Error(err)
return
}
Expand Down