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
365f43ad
Commit
365f43ad
authored
Dec 15, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Dec 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name findOrCreate
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
66c94d77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
strategy/ledgermanager.go
strategy/ledgermanager.go
+6
-6
No files found.
strategy/ledgermanager.go
View file @
365f43ad
...
...
@@ -87,7 +87,7 @@ func (lm *LedgerManager) BlockIsWantedByPeer(k u.Key, p peer.Peer) bool {
lm
.
lock
.
RLock
()
defer
lm
.
lock
.
RUnlock
()
ledger
:=
lm
.
ledger
(
p
)
ledger
:=
lm
.
findOrCreate
(
p
)
return
ledger
.
WantListContains
(
k
)
}
...
...
@@ -97,7 +97,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
lm
.
lock
.
Lock
()
defer
lm
.
lock
.
Unlock
()
l
:=
lm
.
ledger
(
p
)
l
:=
lm
.
findOrCreate
(
p
)
if
m
.
Full
()
{
l
.
wantList
=
wl
.
New
()
}
...
...
@@ -146,7 +146,7 @@ func (lm *LedgerManager) MessageSent(p peer.Peer, m bsmsg.BitSwapMessage) error
lm
.
lock
.
Lock
()
defer
lm
.
lock
.
Unlock
()
l
:=
lm
.
ledger
(
p
)
l
:=
lm
.
findOrCreate
(
p
)
for
_
,
block
:=
range
m
.
Blocks
()
{
l
.
SentBytes
(
len
(
block
.
Data
))
l
.
wantList
.
Remove
(
block
.
Key
())
...
...
@@ -160,18 +160,18 @@ func (lm *LedgerManager) NumBytesSentTo(p peer.Peer) uint64 {
lm
.
lock
.
RLock
()
defer
lm
.
lock
.
RUnlock
()
return
lm
.
ledger
(
p
)
.
Accounting
.
BytesSent
return
lm
.
findOrCreate
(
p
)
.
Accounting
.
BytesSent
}
func
(
lm
*
LedgerManager
)
NumBytesReceivedFrom
(
p
peer
.
Peer
)
uint64
{
lm
.
lock
.
RLock
()
defer
lm
.
lock
.
RUnlock
()
return
lm
.
ledger
(
p
)
.
Accounting
.
BytesRecv
return
lm
.
findOrCreate
(
p
)
.
Accounting
.
BytesRecv
}
// ledger lazily instantiates a ledger
func
(
lm
*
LedgerManager
)
ledger
(
p
peer
.
Peer
)
*
ledger
{
func
(
lm
*
LedgerManager
)
findOrCreate
(
p
peer
.
Peer
)
*
ledger
{
l
,
ok
:=
lm
.
ledgerMap
[
peerKey
(
p
.
Key
())]
if
!
ok
{
l
=
newLedger
(
p
)
...
...
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