mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
lots of logging
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
package blocks
|
package blocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
)
|
)
|
||||||
@ -20,3 +22,7 @@ func NewBlock(data []byte) *Block {
|
|||||||
func (b *Block) Key() u.Key {
|
func (b *Block) Key() u.Key {
|
||||||
return u.Key(b.Multihash)
|
return u.Key(b.Multihash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Block) String() string {
|
||||||
|
return fmt.Sprintf("[Block %s]", b.Key())
|
||||||
|
}
|
||||||
|
@ -52,7 +52,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
|
|||||||
// GetBlock retrieves a particular block from the service,
|
// GetBlock retrieves a particular block from the service,
|
||||||
// Getting it from the datastore using the key (hash).
|
// Getting it from the datastore using the key (hash).
|
||||||
func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, error) {
|
func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, error) {
|
||||||
log.Debug("BlockService GetBlock: '%s'", k)
|
log.Debugf("BlockService GetBlock: '%s'", k)
|
||||||
datai, err := s.Datastore.Get(k.DsKey())
|
datai, err := s.Datastore.Get(k.DsKey())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Debug("Blockservice: Got data in datastore.")
|
log.Debug("Blockservice: Got data in datastore.")
|
||||||
|
@ -53,7 +53,7 @@ func (s *SecurePipe) handshake() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("handshake: %s <--> %s", s.local, s.remote)
|
log.Debugf("handshake: %s <--> %s", s.local, s.remote)
|
||||||
myPubKey, err := s.local.PubKey().Bytes()
|
myPubKey, err := s.local.PubKey().Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -105,7 +105,7 @@ func (s *SecurePipe) handshake() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debug("%s Remote Peer Identified as %s", s.local, s.remote)
|
log.Debugf("%s Remote Peer Identified as %s", s.local, s.remote)
|
||||||
|
|
||||||
exchange, err := selectBest(SupportedExchanges, proposeResp.GetExchanges())
|
exchange, err := selectBest(SupportedExchanges, proposeResp.GetExchanges())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -209,7 +209,7 @@ func (s *SecurePipe) handshake() error {
|
|||||||
return fmt.Errorf("Negotiation failed, got: %s", resp2)
|
return fmt.Errorf("Negotiation failed, got: %s", resp2)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("%s handshake: Got node id: %s", s.local, s.remote)
|
log.Debugf("%s handshake: Got node id: %s", s.local, s.remote)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,6 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
|
|||||||
peer.Peer, bsmsg.BitSwapMessage) {
|
peer.Peer, bsmsg.BitSwapMessage) {
|
||||||
log.Debugf("ReceiveMessage from %v", p.Key())
|
log.Debugf("ReceiveMessage from %v", p.Key())
|
||||||
log.Debugf("Message wantlist: %v", incoming.Wantlist())
|
log.Debugf("Message wantlist: %v", incoming.Wantlist())
|
||||||
log.Debugf("Message blockset: %v", incoming.Blocks())
|
|
||||||
|
|
||||||
if p == nil {
|
if p == nil {
|
||||||
log.Error("Received message from nil peer!")
|
log.Error("Received message from nil peer!")
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||||
|
"github.com/jbenet/go-ipfs/util"
|
||||||
|
|
||||||
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
||||||
inet "github.com/jbenet/go-ipfs/net"
|
inet "github.com/jbenet/go-ipfs/net"
|
||||||
@ -11,6 +12,8 @@ import (
|
|||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = util.Logger("net_message_adapter")
|
||||||
|
|
||||||
// NetMessageAdapter wraps a NetMessage network service
|
// NetMessageAdapter wraps a NetMessage network service
|
||||||
func NetMessageAdapter(s inet.Service, n inet.Network, r Receiver) Adapter {
|
func NetMessageAdapter(s inet.Service, n inet.Network, r Receiver) Adapter {
|
||||||
adapter := impl{
|
adapter := impl{
|
||||||
@ -60,6 +63,7 @@ func (adapter *impl) HandleMessage(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("Message size: %d", len(outgoing.Data()))
|
||||||
return outgoing
|
return outgoing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ const (
|
|||||||
ChanBuffer = 10
|
ChanBuffer = 10
|
||||||
|
|
||||||
// MaxMessageSize is the size of the largest single message
|
// MaxMessageSize is the size of the largest single message
|
||||||
MaxMessageSize = 1 << 20 // 1 MB
|
MaxMessageSize = 1 << 22 // 4 MB
|
||||||
|
|
||||||
// HandshakeTimeout for when nodes first connect
|
// HandshakeTimeout for when nodes first connect
|
||||||
HandshakeTimeout = time.Second * 5
|
HandshakeTimeout = time.Second * 5
|
||||||
@ -97,6 +97,17 @@ func (c *singleConn) close() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *singleConn) GetError() error {
|
||||||
|
select {
|
||||||
|
case err := <-c.msgio.incoming.ErrChan:
|
||||||
|
return err
|
||||||
|
case err := <-c.msgio.outgoing.ErrChan:
|
||||||
|
return err
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ID is an identifier unique to this connection.
|
// ID is an identifier unique to this connection.
|
||||||
func (c *singleConn) ID() string {
|
func (c *singleConn) ID() string {
|
||||||
return ID(c)
|
return ID(c)
|
||||||
|
@ -46,7 +46,7 @@ func Handshake1(ctx context.Context, c Conn) error {
|
|||||||
return fmt.Errorf("could not decode remote version: %q", err)
|
return fmt.Errorf("could not decode remote version: %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Received remote version (%s) from %s", remoteH, rpeer)
|
log.Debugf("Received remote version (%s) from %s", remoteH, rpeer)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := handshake.Handshake1Compatible(localH, remoteH); err != nil {
|
if err := handshake.Handshake1Compatible(localH, remoteH); err != nil {
|
||||||
|
@ -37,6 +37,8 @@ type Conn interface {
|
|||||||
// Out returns a writable message channel
|
// Out returns a writable message channel
|
||||||
Out() chan<- []byte
|
Out() chan<- []byte
|
||||||
|
|
||||||
|
GetError() error
|
||||||
|
|
||||||
// Close ends the connection
|
// Close ends the connection
|
||||||
// Close() error -- already in ContextCloser
|
// Close() error -- already in ContextCloser
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,10 @@ func (c *MultiConn) fanInSingle(child Conn) {
|
|||||||
case m, more := <-child.In(): // receiving data
|
case m, more := <-child.In(): // receiving data
|
||||||
if !more {
|
if !more {
|
||||||
log.Infof("%s in channel closed", child)
|
log.Infof("%s in channel closed", child)
|
||||||
|
err := c.GetError()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Found error on connection: %s", err)
|
||||||
|
}
|
||||||
return // closed
|
return // closed
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -209,7 +213,7 @@ func (c *MultiConn) fanInSingle(child Conn) {
|
|||||||
|
|
||||||
// close is the internal close function, called by ContextCloser.Close
|
// close is the internal close function, called by ContextCloser.Close
|
||||||
func (c *MultiConn) close() error {
|
func (c *MultiConn) close() error {
|
||||||
log.Debug("%s closing Conn with %s", c.local, c.remote)
|
log.Debugf("%s closing Conn with %s", c.local, c.remote)
|
||||||
|
|
||||||
// get connections
|
// get connections
|
||||||
c.RLock()
|
c.RLock()
|
||||||
@ -291,3 +295,13 @@ func (c *MultiConn) In() <-chan []byte {
|
|||||||
func (c *MultiConn) Out() chan<- []byte {
|
func (c *MultiConn) Out() chan<- []byte {
|
||||||
return c.duplex.Out
|
return c.duplex.Out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *MultiConn) GetError() error {
|
||||||
|
for _, sub := range c.conns {
|
||||||
|
err := sub.GetError()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -134,3 +134,7 @@ func (c *secureConn) In() <-chan []byte {
|
|||||||
func (c *secureConn) Out() chan<- []byte {
|
func (c *secureConn) Out() chan<- []byte {
|
||||||
return c.secure.Out
|
return c.secure.Out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *secureConn) GetError() error {
|
||||||
|
return c.insecure.GetError()
|
||||||
|
}
|
||||||
|
@ -154,6 +154,9 @@ func (s *Swarm) fanOut() {
|
|||||||
log.Infof("%s outgoing channel closed", s)
|
log.Infof("%s outgoing channel closed", s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(msg.Data()) >= conn.MaxMessageSize {
|
||||||
|
log.Critical("Attempted to send message bigger than max size.")
|
||||||
|
}
|
||||||
|
|
||||||
s.connsLock.RLock()
|
s.connsLock.RLock()
|
||||||
c, found := s.conns[msg.Peer().Key()]
|
c, found := s.conns[msg.Peer().Key()]
|
||||||
@ -167,7 +170,7 @@ func (s *Swarm) fanOut() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
//log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
|
log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
|
||||||
// queue it in the connection's buffer
|
// queue it in the connection's buffer
|
||||||
c.Out() <- msg.Data()
|
c.Out() <- msg.Data()
|
||||||
}
|
}
|
||||||
@ -206,7 +209,7 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
|
|||||||
return // channel closed.
|
return // channel closed.
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
//log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
|
log.Debugf("%s received message from %s (%d)", s.local, c.RemotePeer(), i)
|
||||||
s.Incoming <- msg.New(c.RemotePeer(), data)
|
s.Incoming <- msg.New(c.RemotePeer(), data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (dht *IpfsDHT) handleGetProviders(p peer.Peer, pmes *pb.Message) (*pb.Messa
|
|||||||
resp := pb.NewMessage(pmes.GetType(), pmes.GetKey(), pmes.GetClusterLevel())
|
resp := pb.NewMessage(pmes.GetType(), pmes.GetKey(), pmes.GetClusterLevel())
|
||||||
|
|
||||||
// check if we have this value, to add ourselves as provider.
|
// check if we have this value, to add ourselves as provider.
|
||||||
log.Debugf("handling GetProviders: '%s'", pmes.GetKey())
|
log.Debugf("handling GetProviders: '%s'", u.Key(pmes.GetKey()))
|
||||||
dsk := u.Key(pmes.GetKey()).DsKey()
|
dsk := u.Key(pmes.GetKey()).DsKey()
|
||||||
has, err := dht.datastore.Has(dsk)
|
has, err := dht.datastore.Has(dsk)
|
||||||
if err != nil && err != ds.ErrNotFound {
|
if err != nil && err != ds.ErrNotFound {
|
||||||
|
Reference in New Issue
Block a user