From fc1278e68095a1d8f367ea4b37a571a0a137d65c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 17 Oct 2018 15:34:30 +0100 Subject: [PATCH] buffer writes Let's not split every wantlist into a length and a wantlist... --- network/ipfs_impl.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/network/ipfs_impl.go b/network/ipfs_impl.go index cd0670ae..78dee0dc 100644 --- a/network/ipfs_impl.go +++ b/network/ipfs_impl.go @@ -1,6 +1,7 @@ package network import ( + "bufio" "context" "fmt" "io" @@ -70,19 +71,20 @@ func msgToStream(ctx context.Context, s inet.Stream, msg bsmsg.BitSwapMessage) e if dl, ok := ctx.Deadline(); ok { deadline = dl } - if err := s.SetWriteDeadline(deadline); err != nil { log.Warningf("error setting deadline: %s", err) } + w := bufio.NewWriter(s) + switch s.Protocol() { case ProtocolBitswap: - if err := msg.ToNetV1(s); err != nil { + if err := msg.ToNetV1(w); err != nil { log.Debugf("error: %s", err) return err } case ProtocolBitswapOne, ProtocolBitswapNoVers: - if err := msg.ToNetV0(s); err != nil { + if err := msg.ToNetV0(w); err != nil { log.Debugf("error: %s", err) return err } @@ -90,6 +92,11 @@ func msgToStream(ctx context.Context, s inet.Stream, msg bsmsg.BitSwapMessage) e return fmt.Errorf("unrecognized protocol on remote: %s", s.Protocol()) } + if err := w.Flush(); err != nil { + log.Debugf("error: %s", err) + return err + } + if err := s.SetWriteDeadline(time.Time{}); err != nil { log.Warningf("error resetting deadline: %s", err) }