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 dependency on go-libp2p-core and introduce new errors. #72

Merged
merged 2 commits into from
Feb 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module github.com/libp2p/go-mplex

go 1.13

require (
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-buffer-pool v0.0.2
github.com/libp2p/go-libp2p-core v0.3.0
)
4 changes: 1 addition & 3 deletions multiplex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"net"
"testing"
"time"

tmux "github.com/libp2p/go-libp2p-core/mux"
)

func init() {
Expand Down Expand Up @@ -391,7 +389,7 @@ func TestResetAfterEOF(t *testing.T) {
sb.Reset()

n, err = sa.Read([]byte{0})
if n != 0 || err != tmux.ErrReset {
if n != 0 || err != ErrStreamReset {
t.Fatal(err)
}
}
Expand Down
15 changes: 9 additions & 6 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p-core/mux"

pool "github.com/libp2p/go-buffer-pool"
)

var (
ErrStreamReset = errors.New("stream reset")
ErrStreamClosed = errors.New("closed stream")
)

// streamID is a convenience type for operating on stream IDs
type streamID struct {
id uint64
Expand Down Expand Up @@ -74,7 +77,7 @@ func (s *Stream) waitForData() error {
case <-s.reset:
// This is the only place where it's safe to return these.
s.returnBuffers()
return mux.ErrReset
return ErrStreamReset
case read, ok := <-s.dataIn:
if !ok {
return io.EOF
Expand Down Expand Up @@ -112,7 +115,7 @@ func (s *Stream) returnBuffers() {
func (s *Stream) Read(b []byte) (int, error) {
select {
case <-s.reset:
return 0, mux.ErrReset
return 0, ErrStreamReset
default:
}
if s.extra == nil {
Expand Down Expand Up @@ -160,14 +163,14 @@ func (s *Stream) Write(b []byte) (int, error) {

func (s *Stream) write(b []byte) (int, error) {
if s.isClosed() {
return 0, errors.New("cannot write to closed stream")
return 0, ErrStreamClosed
}

err := s.mp.sendMsg(s.wDeadline.wait(), s.id.header(messageTag), b)

if err != nil {
if err == context.Canceled {
err = errors.New("cannot write to closed stream")
err = ErrStreamClosed
}
return 0, err
}
Expand Down