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-unixfs
Commits
99db07c3
Commit
99db07c3
authored
Sep 10, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hide ledger wantlist manipulation
parent
182604c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
bitswap/bitswap.go
bitswap/bitswap.go
+7
-8
bitswap/ledger.go
bitswap/ledger.go
+10
-0
No files found.
bitswap/bitswap.go
View file @
99db07c3
...
...
@@ -137,7 +137,7 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) ([]byt
func
(
bs
*
BitSwap
)
HaveBlock
(
blk
*
blocks
.
Block
)
error
{
go
func
()
{
for
_
,
ledger
:=
range
bs
.
partners
{
if
_
,
ok
:=
ledger
.
WantList
[
blk
.
Key
()
];
ok
{
if
ledger
.
WantList
Contains
(
blk
.
Key
()
)
{
//send block to node
if
ledger
.
ShouldSend
()
{
bs
.
SendBlock
(
ledger
.
Partner
,
blk
)
...
...
@@ -192,14 +192,13 @@ func (bs *BitSwap) handleMessages() {
// and then if we do, check the ledger for whether or not we should send it.
func
(
bs
*
BitSwap
)
peerWantsBlock
(
p
*
peer
.
Peer
,
want
string
)
{
u
.
DOut
(
"peer [%s] wants block [%s]
\n
"
,
p
.
ID
.
Pretty
(),
u
.
Key
(
want
)
.
Pretty
())
ledg
:=
bs
.
getLedger
(
p
)
ledg
er
:=
bs
.
getLedger
(
p
)
dsk
:=
ds
.
NewKey
(
want
)
blk_i
,
err
:=
bs
.
datastore
.
Get
(
dsk
)
if
err
!=
nil
{
if
err
==
ds
.
ErrNotFound
{
// TODO: this needs to be different. We need timeouts.
ledg
.
WantList
[
u
.
Key
(
want
)]
=
struct
{}{}
ledger
.
Wants
(
u
.
Key
(
want
))
}
u
.
PErr
(
"datastore get error: %v
\n
"
,
err
)
return
...
...
@@ -211,7 +210,7 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
return
}
if
ledg
.
ShouldSend
()
{
if
ledg
er
.
ShouldSend
()
{
u
.
DOut
(
"Sending block to peer.
\n
"
)
bblk
,
err
:=
blocks
.
NewBlock
(
blk
)
if
err
!=
nil
{
...
...
@@ -219,7 +218,7 @@ func (bs *BitSwap) peerWantsBlock(p *peer.Peer, want string) {
return
}
bs
.
SendBlock
(
p
,
bblk
)
ledg
.
SentBytes
(
len
(
blk
))
ledg
er
.
SentBytes
(
len
(
blk
))
}
else
{
u
.
DOut
(
"Decided not to send block."
)
}
...
...
@@ -276,7 +275,7 @@ func (bs *BitSwap) Halt() {
func
(
bs
*
BitSwap
)
SetStrategy
(
sf
StrategyFunc
)
{
bs
.
strategy
=
sf
for
_
,
ledg
:=
range
bs
.
partners
{
ledg
.
Strategy
=
sf
for
_
,
ledg
er
:=
range
bs
.
partners
{
ledg
er
.
Strategy
=
sf
}
}
bitswap/ledger.go
View file @
99db07c3
...
...
@@ -49,3 +49,13 @@ func (l *Ledger) ReceivedBytes(n int) {
l
.
LastExchange
=
time
.
Now
()
l
.
Accounting
.
BytesRecv
+=
uint64
(
n
)
}
// TODO: this needs to be different. We need timeouts.
func
(
l
*
Ledger
)
Wants
(
k
u
.
Key
)
{
l
.
WantList
[
k
]
=
struct
{}{}
}
func
(
l
*
Ledger
)
WantListContains
(
k
u
.
Key
)
bool
{
_
,
ok
:=
l
.
WantList
[
k
]
return
ok
}
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