@cryptotaxi247 / kubo / commits / 5aa6ccbad

refac(bitswap) nil slices are 'range'able

Brian Tiger Chow committed Sep 19, 2014 at 15:44 UTC 5aa6ccbad59c8107b4a8dc161bcc8110b177782b
1 file changed +18 -22
exchange/bitswap/bitswap.go
+18 -22
@@ -117,32 +117,28 @@ func (bs *bitswap) ReceiveMessage(
117
118 bs.strategy.MessageReceived(p, incoming)
119
120 - if incoming.Blocks() != nil {
121 - for _, block := range incoming.Blocks() {
122 - err := bs.blockstore.Put(block) // FIXME(brian): err ignored
123 - if err != nil {
124 - return nil, nil, err
125 - }
126 - bs.notifications.Publish(block)
127 - err = bs.HasBlock(ctx, block) // FIXME err ignored
128 - if err != nil {
129 - return nil, nil, err
130 - }
120 + for _, block := range incoming.Blocks() {
121 + err := bs.blockstore.Put(block) // FIXME(brian): err ignored
122 + if err != nil {
123 + return nil, nil, err
124 + }
125 + bs.notifications.Publish(block)
126 + err = bs.HasBlock(ctx, block) // FIXME err ignored
127 + if err != nil {
128 + return nil, nil, err
129 }
130 }
131
134 - if incoming.Wantlist() != nil {
135 - for _, key := range incoming.Wantlist() {
136 - if bs.strategy.ShouldSendBlockToPeer(key, p) {
137 - block, errBlockNotFound := bs.blockstore.Get(key)
138 - if errBlockNotFound != nil {
139 - return nil, nil, errBlockNotFound
140 - }
141 - message := bsmsg.New()
142 - message.AppendBlock(*block)
143 - defer bs.strategy.MessageSent(p, message)
144 - return p, message, nil
132 + for _, key := range incoming.Wantlist() {
133 + if bs.strategy.ShouldSendBlockToPeer(key, p) {
134 + block, errBlockNotFound := bs.blockstore.Get(key)
135 + if errBlockNotFound != nil {
136 + return nil, nil, errBlockNotFound
137 }
138 + message := bsmsg.New()
139 + message.AppendBlock(*block)
140 + defer bs.strategy.MessageSent(p, message)
141 + return p, message, nil
142 }
143 }
144 return nil, nil, nil