lots of logging
Jeromy committed
Oct 26, 2014 at 00:45 UTC
d92db1246078fb18e8921fa5c6f79d818f521386
12 files changed
+54
-11
blocks/blocks.go
+6
@@ -1,6 +1,8 @@
1
package blocks
2
3
import (
4
+ "fmt"
5
+
6
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
7
u "github.com/jbenet/go-ipfs/util"
8
)
@@ -20,3 +22,7 @@ func NewBlock(data []byte) *Block {
22
func (b *Block) Key() u.Key {
23
return u.Key(b.Multihash)
24
}
25
+
26
+func (b *Block) String() string {
27
+ return fmt.Sprintf("[Block %s]", b.Key())
28
+}
blockservice/blockservice.go
+1
-1
@@ -52,7 +52,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
52
// GetBlock retrieves a particular block from the service,
53
// Getting it from the datastore using the key (hash).
54
func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, error) {
55
- log.Debug("BlockService GetBlock: '%s'", k)
55
+ log.Debugf("BlockService GetBlock: '%s'", k)
56
datai, err := s.Datastore.Get(k.DsKey())
57
if err == nil {
58
log.Debug("Blockservice: Got data in datastore.")
crypto/spipe/handshake.go
+3
-3
@@ -53,7 +53,7 @@ func (s *SecurePipe) handshake() error {
53
return err
54
}
55
56
- log.Debug("handshake: %s <--> %s", s.local, s.remote)
56
+ log.Debugf("handshake: %s <--> %s", s.local, s.remote)
57
myPubKey, err := s.local.PubKey().Bytes()
58
if err != nil {
59
return err
@@ -105,7 +105,7 @@ func (s *SecurePipe) handshake() error {
105
if err != nil {
106
return err
107
}
108
- log.Debug("%s Remote Peer Identified as %s", s.local, s.remote)
108
+ log.Debugf("%s Remote Peer Identified as %s", s.local, s.remote)
109
110
exchange, err := selectBest(SupportedExchanges, proposeResp.GetExchanges())
111
if err != nil {
@@ -209,7 +209,7 @@ func (s *SecurePipe) handshake() error {
209
return fmt.Errorf("Negotiation failed, got: %s", resp2)
210
}
211
212
- log.Debug("%s handshake: Got node id: %s", s.local, s.remote)
212
+ log.Debugf("%s handshake: Got node id: %s", s.local, s.remote)
213
return nil
214
}
215
exchange/bitswap/bitswap.go
-1
@@ -135,7 +135,6 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
135
peer.Peer, bsmsg.BitSwapMessage) {
136
log.Debugf("ReceiveMessage from %v", p.Key())
137
log.Debugf("Message wantlist: %v", incoming.Wantlist())
138
- log.Debugf("Message blockset: %v", incoming.Blocks())
138
139
if p == nil {
140
log.Error("Received message from nil peer!")
exchange/bitswap/network/net_message_adapter.go
+4
@@ -4,6 +4,7 @@ import (
4
"errors"
5
6
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
+ "github.com/jbenet/go-ipfs/util"
8
9
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
10
inet "github.com/jbenet/go-ipfs/net"
@@ -11,6 +12,8 @@ import (
12
peer "github.com/jbenet/go-ipfs/peer"
13
)
14
15
+var log = util.Logger("net_message_adapter")
16
+
17
// NetMessageAdapter wraps a NetMessage network service
18
func NetMessageAdapter(s inet.Service, n inet.Network, r Receiver) Adapter {
19
adapter := impl{
@@ -60,6 +63,7 @@ func (adapter *impl) HandleMessage(
63
return nil
64
}
65
66
+ log.Debugf("Message size: %d", len(outgoing.Data()))
67
return outgoing
68
}
69
net/conn/conn.go
+12
-1
@@ -21,7 +21,7 @@ const (
21
ChanBuffer = 10
22
23
// MaxMessageSize is the size of the largest single message
24
- MaxMessageSize = 1 << 20 // 1 MB
24
+ MaxMessageSize = 1 << 22 // 4 MB
25
26
// HandshakeTimeout for when nodes first connect
27
HandshakeTimeout = time.Second * 5
@@ -97,6 +97,17 @@ func (c *singleConn) close() error {
97
return err
98
}
99
100
+func (c *singleConn) GetError() error {
101
+ select {
102
+ case err := <-c.msgio.incoming.ErrChan:
103
+ return err
104
+ case err := <-c.msgio.outgoing.ErrChan:
105
+ return err
106
+ default:
107
+ return nil
108
+ }
109
+}
110
+
111
// ID is an identifier unique to this connection.
112
func (c *singleConn) ID() string {
113
return ID(c)
net/conn/handshake.go
+1
-1
@@ -46,7 +46,7 @@ func Handshake1(ctx context.Context, c Conn) error {
46
return fmt.Errorf("could not decode remote version: %q", err)
47
}
48
49
- log.Debug("Received remote version (%s) from %s", remoteH, rpeer)
49
+ log.Debugf("Received remote version (%s) from %s", remoteH, rpeer)
50
}
51
52
if err := handshake.Handshake1Compatible(localH, remoteH); err != nil {
net/conn/interface.go
+2
@@ -37,6 +37,8 @@ type Conn interface {
37
// Out returns a writable message channel
38
Out() chan<- []byte
39
40
+ GetError() error
41
+
42
// Close ends the connection
43
// Close() error -- already in ContextCloser
44
}
net/conn/multiconn.go
+15
-1
@@ -198,6 +198,10 @@ func (c *MultiConn) fanInSingle(child Conn) {
198
case m, more := <-child.In(): // receiving data
199
if !more {
200
log.Infof("%s in channel closed", child)
201
+ err := c.GetError()
202
+ if err != nil {
203
+ log.Errorf("Found error on connection: %s", err)
204
+ }
205
return // closed
206
}
207
i++
@@ -209,7 +213,7 @@ func (c *MultiConn) fanInSingle(child Conn) {
213
214
// close is the internal close function, called by ContextCloser.Close
215
func (c *MultiConn) close() error {
212
- log.Debug("%s closing Conn with %s", c.local, c.remote)
216
+ log.Debugf("%s closing Conn with %s", c.local, c.remote)
217
218
// get connections
219
c.RLock()
@@ -291,3 +295,13 @@ func (c *MultiConn) In() <-chan []byte {
295
func (c *MultiConn) Out() chan<- []byte {
296
return c.duplex.Out
297
}
298
+
299
+func (c *MultiConn) GetError() error {
300
+ for _, sub := range c.conns {
301
+ err := sub.GetError()
302
+ if err != nil {
303
+ return err
304
+ }
305
+ }
306
+ return nil
307
+}
net/conn/secure_conn.go
+4
@@ -134,3 +134,7 @@ func (c *secureConn) In() <-chan []byte {
134
func (c *secureConn) Out() chan<- []byte {
135
return c.secure.Out
136
}
137
+
138
+func (c *secureConn) GetError() error {
139
+ return c.insecure.GetError()
140
+}
net/swarm/conn.go
+5
-2
@@ -154,6 +154,9 @@ func (s *Swarm) fanOut() {
154
log.Infof("%s outgoing channel closed", s)
155
return
156
}
157
+ if len(msg.Data()) >= conn.MaxMessageSize {
158
+ log.Critical("Attempted to send message bigger than max size.")
159
+ }
160
161
s.connsLock.RLock()
162
c, found := s.conns[msg.Peer().Key()]
@@ -167,7 +170,7 @@ func (s *Swarm) fanOut() {
170
}
171
172
i++
170
- //log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
173
+ log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
174
// queue it in the connection's buffer
175
c.Out() <- msg.Data()
176
}
@@ -206,7 +209,7 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
209
return // channel closed.
210
}
211
i++
209
- //log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
212
+ log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
213
s.Incoming <- msg.New(c.RemotePeer(), data)
214
}
215
}
routing/dht/handlers.go
+1
-1
@@ -145,7 +145,7 @@ func (dht *IpfsDHT) handleGetProviders(p peer.Peer, pmes *pb.Message) (*pb.Messa
145
resp := pb.NewMessage(pmes.GetType(), pmes.GetKey(), pmes.GetClusterLevel())
146
147
// check if we have this value, to add ourselves as provider.
148
- log.Debugf("handling GetProviders: '%s'", pmes.GetKey())
148
+ log.Debugf("handling GetProviders: '%s'", u.Key(pmes.GetKey()))
149
dsk := u.Key(pmes.GetKey()).DsKey()
150
has, err := dht.datastore.Has(dsk)
151
if err != nil && err != ds.ErrNotFound {