Commit fc1278e6 authored by Steven Allen's avatar Steven Allen

buffer writes

Let's not split every wantlist into a length and a wantlist...
parent e12de92f
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)
}
......
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