@cryptotaxi247 / kubo / commits / ab7491f80

logging, logging, and some minor logging

Jeromy committed Oct 25, 2014 at 14:50 UTC ab7491f809aeba551d9de6bdbcb722249a0382f9
4 files changed +30 -12
exchange/bitswap/bitswap.go
+23 -8
@@ -66,7 +66,7 @@ type bitswap struct {
66 //
67 // TODO ensure only one active request per key
68 func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error) {
69 - log.Debug("Get Block %v", k)
69 + log.Debugf("Get Block %v", k)
70
71 ctx, cancelFunc := context.WithCancel(parent)
72 bs.wantlist.Add(k)
@@ -82,10 +82,10 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
82 }
83 message.AppendWanted(k)
84 for peerToQuery := range peersToQuery {
85 - log.Debug("bitswap got peersToQuery: %s", peerToQuery)
85 + log.Debugf("bitswap got peersToQuery: %s", peerToQuery)
86 go func(p peer.Peer) {
87
88 - log.Debug("bitswap dialing peer: %s", p)
88 + log.Debugf("bitswap dialing peer: %s", p)
89 err := bs.sender.DialPeer(p)
90 if err != nil {
91 log.Errorf("Error sender.DialPeer(%s)", p)
@@ -124,7 +124,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
124 // HasBlock announces the existance of a block to bitswap, potentially sending
125 // it to peers (Partners) whose WantLists include it.
126 func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
127 - log.Debug("Has Block %v", blk.Key())
127 + log.Debugf("Has Block %v", blk.Key())
128 bs.wantlist.Remove(blk.Key())
129 bs.sendToPeersThatWant(ctx, blk)
130 return bs.routing.Provide(ctx, blk.Key())
@@ -133,17 +133,24 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
133 // TODO(brian): handle errors
134 func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsmsg.BitSwapMessage) (
135 peer.Peer, bsmsg.BitSwapMessage) {
136 - log.Debug("ReceiveMessage from %v", p.Key())
136 + log.Debugf("ReceiveMessage from %v", p.Key())
137 + log.Debugf("Message wantlist: %v", incoming.Wantlist())
138 + log.Debugf("Message blockset: %v", incoming.Blocks())
139
140 if p == nil {
141 + log.Error("Received message from nil peer!")
142 // TODO propagate the error upward
143 return nil, nil
144 }
145 if incoming == nil {
146 + log.Error("Got nil bitswap message!")
147 // TODO propagate the error upward
148 return nil, nil
149 }
150
151 + // Record message bytes in ledger
152 + // TODO: this is bad, and could be easily abused.
153 + // Should only track *useful* messages in ledger
154 bs.strategy.MessageReceived(p, incoming) // FIRST
155
156 for _, block := range incoming.Blocks() {
@@ -153,7 +160,10 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
160 }
161 go bs.notifications.Publish(block)
162 go func(block blocks.Block) {
156 - _ = bs.HasBlock(ctx, block) // FIXME err ignored
163 + err := bs.HasBlock(ctx, block) // FIXME err ignored
164 + if err != nil {
165 + log.Errorf("HasBlock errored: %s", err)
166 + }
167 }(block)
168 }
169
@@ -162,6 +172,8 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
172 message.AppendWanted(wanted)
173 }
174 for _, key := range incoming.Wantlist() {
175 + // TODO: might be better to check if we have the block before checking
176 + // if we should send it to someone
177 if bs.strategy.ShouldSendBlockToPeer(key, p) {
178 if block, errBlockNotFound := bs.blockstore.Get(key); errBlockNotFound != nil {
179 continue
@@ -171,10 +183,13 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
183 }
184 }
185 defer bs.strategy.MessageSent(p, message)
186 +
187 + log.Debug("Returning message.")
188 return p, message
189 }
190
191 func (bs *bitswap) ReceiveError(err error) {
192 + log.Errorf("Bitswap ReceiveError: %s", err)
193 // TODO log the network error
194 // TODO bubble the network error up to the parent context/error logger
195 }
@@ -187,10 +202,10 @@ func (bs *bitswap) send(ctx context.Context, p peer.Peer, m bsmsg.BitSwapMessage
202 }
203
204 func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block) {
190 - log.Debug("Sending %v to peers that want it", block.Key())
205 + log.Debugf("Sending %v to peers that want it", block.Key())
206 for _, p := range bs.strategy.Peers() {
207 if bs.strategy.BlockIsWantedByPeer(block.Key(), p) {
193 - log.Debug("%v wants %v", p, block.Key())
208 + log.Debugf("%v wants %v", p, block.Key())
209 if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
210 message := bsmsg.New()
211 message.AppendBlock(block)
exchange/bitswap/network/net_message_adapter.go
+3
@@ -1,6 +1,8 @@
1 package network
2
3 import (
4 + "errors"
5 +
6 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
8 bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
@@ -48,6 +50,7 @@ func (adapter *impl) HandleMessage(
50
51 // TODO(brian): put this in a helper function
52 if bsmsg == nil || p == nil {
53 + adapter.receiver.ReceiveError(errors.New("ReceiveMessage returned nil peer or message"))
54 return nil
55 }
56
net/swarm/conn.go
+3 -3
@@ -92,7 +92,7 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
92 return nil, errors.New("Tried to start nil connection.")
93 }
94
95 - log.Debug("%s Started connection: %s", c.LocalPeer(), c.RemotePeer())
95 + log.Debugf("%s Started connection: %s", c.LocalPeer(), c.RemotePeer())
96
97 // add address of connection to Peer. Maybe it should happen in connSecure.
98 // NOT adding this address here, because the incoming address in TCP
@@ -167,7 +167,7 @@ func (s *Swarm) fanOut() {
167 }
168
169 i++
170 - log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
170 + //log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
171 // queue it in the connection's buffer
172 c.Out() <- msg.Data()
173 }
@@ -206,7 +206,7 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
206 return // channel closed.
207 }
208 i++
209 - log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
209 + //log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
210 s.Incoming <- msg.New(c.RemotePeer(), data)
211 }
212 }
routing/dht/dht.go
+1 -1
@@ -23,7 +23,7 @@ import (
23
24 var log = u.Logger("dht")
25
26 -const doPinging = true
26 +const doPinging = false
27
28 // TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
29