Commit 5bf9cf5e authored by Steven Allen's avatar Steven Allen

drop the go-context dependency

This was causing us to build up a bunch of background goroutines. Technically,
we should be resetting all these streams when the DHT stops. However, we don't
actually unregister stream handlers from the host so, really, nothing will
actually stop till the host stops. When it does, it'll kill all the streams
anyways.
parent 0d5dacd2
......@@ -9,7 +9,6 @@ import (
"time"
ggio "github.com/gogo/protobuf/io"
ctxio "github.com/jbenet/go-context/io"
"github.com/libp2p/go-libp2p-kad-dht/metrics"
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
inet "github.com/libp2p/go-libp2p-net"
......@@ -67,10 +66,7 @@ func (dht *IpfsDHT) handleNewStream(s inet.Stream) {
// Returns true on orderly completion of writes (so we can Close the stream).
func (dht *IpfsDHT) handleNewMessage(s inet.Stream) bool {
ctx := dht.ctx
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)
r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
mPeer := s.Conn().RemotePeer()
for {
......@@ -126,7 +122,7 @@ func (dht *IpfsDHT) handleNewMessage(s inet.Stream) bool {
}
// send out response msg
err = writeMsg(cw, resp)
err = writeMsg(s, resp)
if err != nil {
stats.Record(ctx, metrics.ReceivedMessageErrors.M(1))
logger.Debugf("error writing response: %v", err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment