Skip to content

Commit

Permalink
use a context when opening streams
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Dec 17, 2020
1 parent 3155ff3 commit 973870b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion p2p/net/mock/mock_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mocknet

import (
"container/list"
"context"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -151,7 +152,7 @@ func (c *conn) openStream() *stream {
return sl
}

func (c *conn) NewStream() (network.Stream, error) {
func (c *conn) NewStream(context.Context) (network.Stream, error) {
log.Debugf("Conn.NewStreamWithProtocol: %s --> %s", c.local, c.remote)

s := c.openStream()
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/mock/mock_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestNotifications(t *testing.T) {
for _, s := range nets {
conns := s.Conns()
for _, c := range conns {
st1, err := c.NewStream()
st1, err := c.NewStream(context.Background())
if err != nil {
t.Error(err)
continue
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/mock/mock_peernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (pn *peernet) NewStream(ctx context.Context, p peer.ID) (network.Stream, er
if err != nil {
return nil, err
}
return c.NewStream()
return c.NewStream(ctx)
}

// SetStreamHandler sets the new stream handler on the Network.
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (ids *IDService) identifyConn(c network.Conn, signal chan struct{}) {
}
}()

s, err = c.NewStream()
s, err = c.NewStream(context.Background())
if err != nil {
log.Debugw("error opening identify stream", "error", err)
// the connection is probably already closed if we hit this.
Expand Down

0 comments on commit 973870b

Please sign in to comment.