Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
ab7491f8
Commit
ab7491f8
authored
Oct 25, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging, logging, and some minor logging
parent
e1f2fe75
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
12 deletions
+30
-12
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+23
-8
exchange/bitswap/network/net_message_adapter.go
exchange/bitswap/network/net_message_adapter.go
+3
-0
net/swarm/conn.go
net/swarm/conn.go
+3
-3
routing/dht/dht.go
routing/dht/dht.go
+1
-1
No files found.
exchange/bitswap/bitswap.go
View file @
ab7491f8
...
...
@@ -66,7 +66,7 @@ type bitswap struct {
//
// TODO ensure only one active request per key
func
(
bs
*
bitswap
)
Block
(
parent
context
.
Context
,
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
log
.
Debug
(
"Get Block %v"
,
k
)
log
.
Debug
f
(
"Get Block %v"
,
k
)
ctx
,
cancelFunc
:=
context
.
WithCancel
(
parent
)
bs
.
wantlist
.
Add
(
k
)
...
...
@@ -82,10 +82,10 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
}
message
.
AppendWanted
(
k
)
for
peerToQuery
:=
range
peersToQuery
{
log
.
Debug
(
"bitswap got peersToQuery: %s"
,
peerToQuery
)
log
.
Debug
f
(
"bitswap got peersToQuery: %s"
,
peerToQuery
)
go
func
(
p
peer
.
Peer
)
{
log
.
Debug
(
"bitswap dialing peer: %s"
,
p
)
log
.
Debug
f
(
"bitswap dialing peer: %s"
,
p
)
err
:=
bs
.
sender
.
DialPeer
(
p
)
if
err
!=
nil
{
log
.
Errorf
(
"Error sender.DialPeer(%s)"
,
p
)
...
...
@@ -124,7 +124,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
// HasBlock announces the existance of a block to bitswap, potentially sending
// it to peers (Partners) whose WantLists include it.
func
(
bs
*
bitswap
)
HasBlock
(
ctx
context
.
Context
,
blk
blocks
.
Block
)
error
{
log
.
Debug
(
"Has Block %v"
,
blk
.
Key
())
log
.
Debug
f
(
"Has Block %v"
,
blk
.
Key
())
bs
.
wantlist
.
Remove
(
blk
.
Key
())
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
return
bs
.
routing
.
Provide
(
ctx
,
blk
.
Key
())
...
...
@@ -133,17 +133,24 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
// TODO(brian): handle errors
func
(
bs
*
bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
peer
.
Peer
,
bsmsg
.
BitSwapMessage
)
{
log
.
Debug
(
"ReceiveMessage from %v"
,
p
.
Key
())
log
.
Debugf
(
"ReceiveMessage from %v"
,
p
.
Key
())
log
.
Debugf
(
"Message wantlist: %v"
,
incoming
.
Wantlist
())
log
.
Debugf
(
"Message blockset: %v"
,
incoming
.
Blocks
())
if
p
==
nil
{
log
.
Error
(
"Received message from nil peer!"
)
// TODO propagate the error upward
return
nil
,
nil
}
if
incoming
==
nil
{
log
.
Error
(
"Got nil bitswap message!"
)
// TODO propagate the error upward
return
nil
,
nil
}
// Record message bytes in ledger
// TODO: this is bad, and could be easily abused.
// Should only track *useful* messages in ledger
bs
.
strategy
.
MessageReceived
(
p
,
incoming
)
// FIRST
for
_
,
block
:=
range
incoming
.
Blocks
()
{
...
...
@@ -153,7 +160,10 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
go
bs
.
notifications
.
Publish
(
block
)
go
func
(
block
blocks
.
Block
)
{
_
=
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
err
:=
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
if
err
!=
nil
{
log
.
Errorf
(
"HasBlock errored: %s"
,
err
)
}
}(
block
)
}
...
...
@@ -162,6 +172,8 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
message
.
AppendWanted
(
wanted
)
}
for
_
,
key
:=
range
incoming
.
Wantlist
()
{
// TODO: might be better to check if we have the block before checking
// if we should send it to someone
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
key
,
p
)
{
if
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
);
errBlockNotFound
!=
nil
{
continue
...
...
@@ -171,10 +183,13 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
}
defer
bs
.
strategy
.
MessageSent
(
p
,
message
)
log
.
Debug
(
"Returning message."
)
return
p
,
message
}
func
(
bs
*
bitswap
)
ReceiveError
(
err
error
)
{
log
.
Errorf
(
"Bitswap ReceiveError: %s"
,
err
)
// TODO log the network error
// TODO bubble the network error up to the parent context/error logger
}
...
...
@@ -187,10 +202,10 @@ func (bs *bitswap) send(ctx context.Context, p peer.Peer, m bsmsg.BitSwapMessage
}
func
(
bs
*
bitswap
)
sendToPeersThatWant
(
ctx
context
.
Context
,
block
blocks
.
Block
)
{
log
.
Debug
(
"Sending %v to peers that want it"
,
block
.
Key
())
log
.
Debug
f
(
"Sending %v to peers that want it"
,
block
.
Key
())
for
_
,
p
:=
range
bs
.
strategy
.
Peers
()
{
if
bs
.
strategy
.
BlockIsWantedByPeer
(
block
.
Key
(),
p
)
{
log
.
Debug
(
"%v wants %v"
,
p
,
block
.
Key
())
log
.
Debug
f
(
"%v wants %v"
,
p
,
block
.
Key
())
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
block
.
Key
(),
p
)
{
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
block
)
...
...
exchange/bitswap/network/net_message_adapter.go
View file @
ab7491f8
package
network
import
(
"errors"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
...
...
@@ -48,6 +50,7 @@ func (adapter *impl) HandleMessage(
// TODO(brian): put this in a helper function
if
bsmsg
==
nil
||
p
==
nil
{
adapter
.
receiver
.
ReceiveError
(
errors
.
New
(
"ReceiveMessage returned nil peer or message"
))
return
nil
}
...
...
net/swarm/conn.go
View file @
ab7491f8
...
...
@@ -92,7 +92,7 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
return
nil
,
errors
.
New
(
"Tried to start nil connection."
)
}
log
.
Debug
(
"%s Started connection: %s"
,
c
.
LocalPeer
(),
c
.
RemotePeer
())
log
.
Debug
f
(
"%s Started connection: %s"
,
c
.
LocalPeer
(),
c
.
RemotePeer
())
// add address of connection to Peer. Maybe it should happen in connSecure.
// NOT adding this address here, because the incoming address in TCP
...
...
@@ -167,7 +167,7 @@ func (s *Swarm) fanOut() {
}
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
c
.
Out
()
<-
msg
.
Data
()
}
...
...
@@ -206,7 +206,7 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
return
// channel closed.
}
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
)
}
}
...
...
routing/dht/dht.go
View file @
ab7491f8
...
...
@@ -23,7 +23,7 @@ import (
var
log
=
u
.
Logger
(
"dht"
)
const
doPinging
=
tru
e
const
doPinging
=
fals
e
// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment