fix issue with blocks not being trimmed properly and being too large to be sent over the network
Jeromy committed
Sep 5, 2014 at 02:58 UTC
e6498b37338d6b0653a1c80e8aa4580e1aadb49c
5 files changed
+14
-3
bitswap/bitswap.go
+3
-1
@@ -220,6 +220,8 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
220
}
221
bs.SendBlock(p, bblk)
222
ledg.SentBytes(len(blk))
223
+ } else {
224
+ u.DOut("Decided not to send block.")
225
}
226
}
227
@@ -248,7 +250,7 @@ func (bs *BitSwap) GetLedger(p *peer.Peer) *Ledger {
250
}
251
252
l = new(Ledger)
251
- l.Strategy = StandardStrategy
253
+ l.Strategy = bs.strategy
254
l.Partner = p
255
bs.partners[p.Key()] = l
256
return l
core/core.go
+1
@@ -75,6 +75,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
75
if err != nil {
76
return nil, err
77
}
78
+ swap.SetStrategy(bitswap.YesManStrategy)
79
}
80
81
bs, err := bserv.NewBlockService(d, swap)
importer/splitting.go
+1
-1
@@ -24,7 +24,7 @@ func SplitterBySize(n int) BlockSplitter {
24
return
25
}
26
if nread < n {
27
- chunk = chunk[:n]
27
+ chunk = chunk[:nread]
28
}
29
out <- chunk
30
}
swarm/conn.go
+4
-1
@@ -13,6 +13,8 @@ import (
13
// ChanBuffer is the size of the buffer in the Conn Chan
14
const ChanBuffer = 10
15
16
+const MaxMessageSize = 1 << 19
17
+
18
// Conn represents a connection to another Peer (IPFS Node).
19
type Conn struct {
20
Peer *peer.Peer
@@ -66,13 +68,14 @@ func newConnChans(c *Conn) error {
68
c.Closed = make(chan bool, 1)
69
70
go c.Outgoing.WriteTo(c.Conn)
69
- go c.Incoming.ReadFrom(c.Conn, 1<<12)
71
+ go c.Incoming.ReadFrom(c.Conn, MaxMessageSize)
72
73
return nil
74
}
75
76
// Close closes the connection, and associated channels.
77
func (s *Conn) Close() error {
78
+ u.DOut("Closing Conn.\n")
79
if s.Conn == nil {
80
return fmt.Errorf("Already closed") // already closed
81
}
swarm/swarm.go
+5
@@ -279,6 +279,10 @@ func (s *Swarm) fanOut() {
279
return
280
}
281
282
+ if len(msg.Data) > MaxMessageSize {
283
+ s.Error(fmt.Errorf("Exceeded max message size! (tried to send len = %d)", len(msg.Data)))
284
+ }
285
+
286
s.connsLock.RLock()
287
conn, found := s.conns[msg.Peer.Key()]
288
s.connsLock.RUnlock()
@@ -459,6 +463,7 @@ func (s *Swarm) ConnectNew(addr *ma.Multiaddr) (*peer.Peer, error) {
463
464
// Removes a given peer from the swarm and closes connections to it
465
func (s *Swarm) Drop(p *peer.Peer) error {
466
+ u.DOut("Dropping peer: [%s]\n", p.ID.Pretty())
467
s.connsLock.RLock()
468
conn, found := s.conns[u.Key(p.ID)]
469
s.connsLock.RUnlock()