mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 05:52:20 +08:00
moved util/ctx to github.com/jbenet/go-context
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
@ -4,13 +4,12 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
|
||||
ctxio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-context/io"
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
inet "github.com/ipfs/go-ipfs/p2p/net"
|
||||
peer "github.com/ipfs/go-ipfs/p2p/peer"
|
||||
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
|
||||
ctxutil "github.com/ipfs/go-ipfs/util/ctx"
|
||||
|
||||
ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// handleNewStream implements the inet.StreamHandler
|
||||
@ -22,8 +21,8 @@ func (dht *IpfsDHT) handleNewMessage(s inet.Stream) {
|
||||
defer s.Close()
|
||||
|
||||
ctx := dht.Context()
|
||||
cr := ctxutil.NewReader(ctx, s) // ok to use. we defer close stream in this func
|
||||
cw := ctxutil.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
cr := ctxio.NewReader(ctx, s) // ok to use. we defer close stream in this func
|
||||
cw := ctxio.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
r := ggio.NewDelimitedReader(cr, inet.MessageSizeMax)
|
||||
w := ggio.NewDelimitedWriter(cw)
|
||||
mPeer := s.Conn().RemotePeer()
|
||||
@ -78,8 +77,8 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
cr := ctxutil.NewReader(ctx, s) // ok to use. we defer close stream in this func
|
||||
cw := ctxutil.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
cr := ctxio.NewReader(ctx, s) // ok to use. we defer close stream in this func
|
||||
cw := ctxio.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
r := ggio.NewDelimitedReader(cr, inet.MessageSizeMax)
|
||||
w := ggio.NewDelimitedWriter(cw)
|
||||
|
||||
@ -116,7 +115,7 @@ func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
cw := ctxutil.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
cw := ctxio.NewWriter(ctx, s) // ok to use. we defer close stream in this func
|
||||
w := ggio.NewDelimitedWriter(cw)
|
||||
|
||||
if err := w.WriteMsg(pmes); err != nil {
|
||||
|
@ -3,13 +3,13 @@ package dht
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ctxfrac "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-context/frac"
|
||||
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
ci "github.com/ipfs/go-ipfs/p2p/crypto"
|
||||
peer "github.com/ipfs/go-ipfs/p2p/peer"
|
||||
routing "github.com/ipfs/go-ipfs/routing"
|
||||
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
|
||||
record "github.com/ipfs/go-ipfs/routing/record"
|
||||
ctxutil "github.com/ipfs/go-ipfs/util/ctx"
|
||||
)
|
||||
|
||||
func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error) {
|
||||
@ -22,7 +22,7 @@ func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, err
|
||||
}
|
||||
|
||||
// ok, try the node itself. if they're overwhelmed or slow we can move on.
|
||||
ctxT, cancelFunc := ctxutil.WithDeadlineFraction(ctx, 0.3)
|
||||
ctxT, cancelFunc := ctxfrac.WithDeadlineFraction(ctx, 0.3)
|
||||
defer cancelFunc()
|
||||
if pk, err := dht.getPublicKeyFromNode(ctx, p); err == nil {
|
||||
err := dht.peerstore.AddPubKey(p, pk)
|
||||
|
Reference in New Issue
Block a user