mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-25 15:08:45 +08:00
fix issue with blocks not being trimmed properly and being too large to be sent over the network
This commit is contained in:
@ -220,6 +220,8 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
|
||||
}
|
||||
bs.SendBlock(p, bblk)
|
||||
ledg.SentBytes(len(blk))
|
||||
} else {
|
||||
u.DOut("Decided not to send block.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +250,7 @@ func (bs *BitSwap) GetLedger(p *peer.Peer) *Ledger {
|
||||
}
|
||||
|
||||
l = new(Ledger)
|
||||
l.Strategy = StandardStrategy
|
||||
l.Strategy = bs.strategy
|
||||
l.Partner = p
|
||||
bs.partners[p.Key()] = l
|
||||
return l
|
||||
|
@ -75,6 +75,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
swap.SetStrategy(bitswap.YesManStrategy)
|
||||
}
|
||||
|
||||
bs, err := bserv.NewBlockService(d, swap)
|
||||
|
@ -24,7 +24,7 @@ func SplitterBySize(n int) BlockSplitter {
|
||||
return
|
||||
}
|
||||
if nread < n {
|
||||
chunk = chunk[:n]
|
||||
chunk = chunk[:nread]
|
||||
}
|
||||
out <- chunk
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
// ChanBuffer is the size of the buffer in the Conn Chan
|
||||
const ChanBuffer = 10
|
||||
|
||||
const MaxMessageSize = 1 << 19
|
||||
|
||||
// Conn represents a connection to another Peer (IPFS Node).
|
||||
type Conn struct {
|
||||
Peer *peer.Peer
|
||||
@ -66,13 +68,14 @@ func newConnChans(c *Conn) error {
|
||||
c.Closed = make(chan bool, 1)
|
||||
|
||||
go c.Outgoing.WriteTo(c.Conn)
|
||||
go c.Incoming.ReadFrom(c.Conn, 1<<12)
|
||||
go c.Incoming.ReadFrom(c.Conn, MaxMessageSize)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the connection, and associated channels.
|
||||
func (s *Conn) Close() error {
|
||||
u.DOut("Closing Conn.\n")
|
||||
if s.Conn == nil {
|
||||
return fmt.Errorf("Already closed") // already closed
|
||||
}
|
||||
|
@ -279,6 +279,10 @@ func (s *Swarm) fanOut() {
|
||||
return
|
||||
}
|
||||
|
||||
if len(msg.Data) > MaxMessageSize {
|
||||
s.Error(fmt.Errorf("Exceeded max message size! (tried to send len = %d)", len(msg.Data)))
|
||||
}
|
||||
|
||||
s.connsLock.RLock()
|
||||
conn, found := s.conns[msg.Peer.Key()]
|
||||
s.connsLock.RUnlock()
|
||||
@ -459,6 +463,7 @@ func (s *Swarm) ConnectNew(addr *ma.Multiaddr) (*peer.Peer, error) {
|
||||
|
||||
// Removes a given peer from the swarm and closes connections to it
|
||||
func (s *Swarm) Drop(p *peer.Peer) error {
|
||||
u.DOut("Dropping peer: [%s]\n", p.ID.Pretty())
|
||||
s.connsLock.RLock()
|
||||
conn, found := s.conns[u.Key(p.ID)]
|
||||
s.connsLock.RUnlock()
|
||||
|
Reference in New Issue
Block a user