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-bitswap
Commits
ce2404ec
Commit
ce2404ec
authored
Oct 25, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging, logging, and some minor logging
parent
e5876d9a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
bitswap.go
bitswap.go
+23
-8
network/net_message_adapter.go
network/net_message_adapter.go
+3
-0
No files found.
bitswap.go
View file @
ce2404ec
...
@@ -66,7 +66,7 @@ type bitswap struct {
...
@@ -66,7 +66,7 @@ type bitswap struct {
//
//
// TODO ensure only one active request per key
// TODO ensure only one active request per key
func
(
bs
*
bitswap
)
Block
(
parent
context
.
Context
,
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
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
)
ctx
,
cancelFunc
:=
context
.
WithCancel
(
parent
)
bs
.
wantlist
.
Add
(
k
)
bs
.
wantlist
.
Add
(
k
)
...
@@ -82,10 +82,10 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
...
@@ -82,10 +82,10 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
}
}
message
.
AppendWanted
(
k
)
message
.
AppendWanted
(
k
)
for
peerToQuery
:=
range
peersToQuery
{
for
peerToQuery
:=
range
peersToQuery
{
log
.
Debug
(
"bitswap got peersToQuery: %s"
,
peerToQuery
)
log
.
Debug
f
(
"bitswap got peersToQuery: %s"
,
peerToQuery
)
go
func
(
p
peer
.
Peer
)
{
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
)
err
:=
bs
.
sender
.
DialPeer
(
p
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Error sender.DialPeer(%s)"
,
p
)
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,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
// HasBlock announces the existance of a block to bitswap, potentially sending
// it to peers (Partners) whose WantLists include it.
// it to peers (Partners) whose WantLists include it.
func
(
bs
*
bitswap
)
HasBlock
(
ctx
context
.
Context
,
blk
blocks
.
Block
)
error
{
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
.
wantlist
.
Remove
(
blk
.
Key
())
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
return
bs
.
routing
.
Provide
(
ctx
,
blk
.
Key
())
return
bs
.
routing
.
Provide
(
ctx
,
blk
.
Key
())
...
@@ -133,17 +133,24 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
...
@@ -133,17 +133,24 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
// TODO(brian): handle errors
// TODO(brian): handle errors
func
(
bs
*
bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
func
(
bs
*
bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
peer
.
Peer
,
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
{
if
p
==
nil
{
log
.
Error
(
"Received message from nil peer!"
)
// TODO propagate the error upward
// TODO propagate the error upward
return
nil
,
nil
return
nil
,
nil
}
}
if
incoming
==
nil
{
if
incoming
==
nil
{
log
.
Error
(
"Got nil bitswap message!"
)
// TODO propagate the error upward
// TODO propagate the error upward
return
nil
,
nil
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
bs
.
strategy
.
MessageReceived
(
p
,
incoming
)
// FIRST
for
_
,
block
:=
range
incoming
.
Blocks
()
{
for
_
,
block
:=
range
incoming
.
Blocks
()
{
...
@@ -153,7 +160,10 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
...
@@ -153,7 +160,10 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
}
go
bs
.
notifications
.
Publish
(
block
)
go
bs
.
notifications
.
Publish
(
block
)
go
func
(
block
blocks
.
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
)
}(
block
)
}
}
...
@@ -162,6 +172,8 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
...
@@ -162,6 +172,8 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
message
.
AppendWanted
(
wanted
)
message
.
AppendWanted
(
wanted
)
}
}
for
_
,
key
:=
range
incoming
.
Wantlist
()
{
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
bs
.
strategy
.
ShouldSendBlockToPeer
(
key
,
p
)
{
if
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
);
errBlockNotFound
!=
nil
{
if
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
);
errBlockNotFound
!=
nil
{
continue
continue
...
@@ -171,10 +183,13 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
...
@@ -171,10 +183,13 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
}
}
}
defer
bs
.
strategy
.
MessageSent
(
p
,
message
)
defer
bs
.
strategy
.
MessageSent
(
p
,
message
)
log
.
Debug
(
"Returning message."
)
return
p
,
message
return
p
,
message
}
}
func
(
bs
*
bitswap
)
ReceiveError
(
err
error
)
{
func
(
bs
*
bitswap
)
ReceiveError
(
err
error
)
{
log
.
Errorf
(
"Bitswap ReceiveError: %s"
,
err
)
// TODO log the network error
// TODO log the network error
// TODO bubble the network error up to the parent context/error logger
// 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
...
@@ -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
)
{
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
()
{
for
_
,
p
:=
range
bs
.
strategy
.
Peers
()
{
if
bs
.
strategy
.
BlockIsWantedByPeer
(
block
.
Key
(),
p
)
{
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
)
{
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
block
.
Key
(),
p
)
{
message
:=
bsmsg
.
New
()
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
block
)
message
.
AppendBlock
(
block
)
...
...
network/net_message_adapter.go
View file @
ce2404ec
package
network
package
network
import
(
import
(
"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"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
...
@@ -48,6 +50,7 @@ func (adapter *impl) HandleMessage(
...
@@ -48,6 +50,7 @@ func (adapter *impl) HandleMessage(
// TODO(brian): put this in a helper function
// TODO(brian): put this in a helper function
if
bsmsg
==
nil
||
p
==
nil
{
if
bsmsg
==
nil
||
p
==
nil
{
adapter
.
receiver
.
ReceiveError
(
errors
.
New
(
"ReceiveMessage returned nil peer or message"
))
return
nil
return
nil
}
}
...
...
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