Commit 844e5d0d authored by Jeromy's avatar Jeromy

fix receive loop error handling

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 17aaaa9c
...@@ -135,7 +135,10 @@ func (m *impl) AddBlock(b blocks.Block) { ...@@ -135,7 +135,10 @@ func (m *impl) AddBlock(b blocks.Block) {
func FromNet(r io.Reader) (BitSwapMessage, error) { func FromNet(r io.Reader) (BitSwapMessage, error) {
pbr := ggio.NewDelimitedReader(r, inet.MessageSizeMax) pbr := ggio.NewDelimitedReader(r, inet.MessageSizeMax)
return FromPBReader(pbr)
}
func FromPBReader(pbr ggio.Reader) (BitSwapMessage, error) {
pb := new(pb.Message) pb := new(pb.Message)
if err := pbr.ReadMsg(pb); err != nil { if err := pbr.ReadMsg(pb); err != nil {
return nil, err return nil, err
......
package network package network
import ( import (
"io"
key "github.com/ipfs/go-ipfs/blocks/key" key "github.com/ipfs/go-ipfs/blocks/key"
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
routing "github.com/ipfs/go-ipfs/routing" routing "github.com/ipfs/go-ipfs/routing"
host "gx/ipfs/QmVL44QeoQDTYK8RVdpkyja7uYcK3WDNoBNHVLonf9YDtm/go-libp2p/p2p/host" host "gx/ipfs/QmVL44QeoQDTYK8RVdpkyja7uYcK3WDNoBNHVLonf9YDtm/go-libp2p/p2p/host"
inet "gx/ipfs/QmVL44QeoQDTYK8RVdpkyja7uYcK3WDNoBNHVLonf9YDtm/go-libp2p/p2p/net" inet "gx/ipfs/QmVL44QeoQDTYK8RVdpkyja7uYcK3WDNoBNHVLonf9YDtm/go-libp2p/p2p/net"
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
logging "gx/ipfs/QmaDNZ4QMdBdku1YZWBysufYyoQt1negQGNav6PLYarbY8/go-log" logging "gx/ipfs/QmaDNZ4QMdBdku1YZWBysufYyoQt1negQGNav6PLYarbY8/go-log"
peer "gx/ipfs/QmbyvM8zRFDkbFdYyt1MnevUMJ62SiSGbfDFZ3Z8nkrzr4/go-libp2p-peer" peer "gx/ipfs/QmbyvM8zRFDkbFdYyt1MnevUMJ62SiSGbfDFZ3Z8nkrzr4/go-libp2p-peer"
...@@ -150,11 +153,14 @@ func (bsnet *impl) handleNewStream(s inet.Stream) { ...@@ -150,11 +153,14 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
return return
} }
reader := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
for { for {
received, err := bsmsg.FromNet(s) received, err := bsmsg.FromPBReader(reader)
if err != nil { if err != nil {
go bsnet.receiver.ReceiveError(err) if err != io.EOF {
log.Debugf("bitswap net handleNewStream from %s error: %s", s.Conn().RemotePeer(), err) go bsnet.receiver.ReceiveError(err)
log.Debugf("bitswap net handleNewStream from %s error: %s", s.Conn().RemotePeer(), err)
}
return return
} }
......
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