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
de9fcf5d
Commit
de9fcf5d
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(bitswap) rename strategist -> strategy
parent
b7806947
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
17 deletions
+17
-17
bitswap/bitswap.go
bitswap/bitswap.go
+11
-11
bitswap/strategy/interface.go
bitswap/strategy/interface.go
+3
-3
bitswap/strategy/strategy.go
bitswap/strategy/strategy.go
+3
-3
No files found.
bitswap/bitswap.go
View file @
de9fcf5d
...
...
@@ -41,10 +41,10 @@ type bitswap struct {
notifications
notifications
.
PubSub
// strateg
ist
listens to network traffic and makes decisions about how to
// strateg
y
listens to network traffic and makes decisions about how to
// interact with partners.
// TODO(brian): save the strateg
ist
's state to the datastore
strateg
ist
strategy
.
Strateg
ist
// TODO(brian): save the strateg
y
's state to the datastore
strateg
y
strategy
.
Strateg
y
}
// NewSession initializes a bitswap session.
...
...
@@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
bs
:=
&
bitswap
{
blockstore
:
blockstore
.
NewBlockstore
(
d
),
notifications
:
notifications
.
New
(),
strateg
ist
:
strategy
.
New
(),
strateg
y
:
strategy
.
New
(),
peer
:
p
,
routing
:
directory
,
sender
:
bsnet
.
NewNetworkAdapter
(
s
,
&
receiver
),
...
...
@@ -112,7 +112,7 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
// that accounting is _always_ performed when SendMessage and
// ReceiveMessage are called
bs
.
sender
.
SendMessage
(
ctx
,
p
,
message
)
bs
.
strateg
ist
.
MessageSent
(
p
,
message
)
bs
.
strateg
y
.
MessageSent
(
p
,
message
)
block
,
ok
:=
<-
blockChannel
if
!
ok
{
...
...
@@ -122,9 +122,9 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
}
func
(
bs
*
bitswap
)
sendToPeersThatWant
(
block
blocks
.
Block
)
{
for
_
,
p
:=
range
bs
.
strateg
ist
.
Peers
()
{
if
bs
.
strateg
ist
.
IsWantedByPeer
(
block
.
Key
(),
p
)
{
if
bs
.
strateg
ist
.
ShouldSendToPeer
(
block
.
Key
(),
p
)
{
for
_
,
p
:=
range
bs
.
strateg
y
.
Peers
()
{
if
bs
.
strateg
y
.
Block
IsWantedByPeer
(
block
.
Key
(),
p
)
{
if
bs
.
strateg
y
.
ShouldSend
Block
ToPeer
(
block
.
Key
(),
p
)
{
go
bs
.
send
(
p
,
block
)
}
}
...
...
@@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message
.
AppendBlock
(
b
)
// FIXME(brian): pass ctx
bs
.
sender
.
SendMessage
(
context
.
Background
(),
p
,
message
)
bs
.
strateg
ist
.
MessageSent
(
p
,
message
)
bs
.
strateg
y
.
MessageSent
(
p
,
message
)
}
// TODO(brian): handle errors
...
...
@@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage(
ctx
context
.
Context
,
sender
*
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
*
peer
.
Peer
,
bsmsg
.
BitSwapMessage
,
error
)
{
bs
.
strateg
ist
.
MessageReceived
(
sender
,
incoming
)
bs
.
strateg
y
.
MessageReceived
(
sender
,
incoming
)
if
incoming
.
Blocks
()
!=
nil
{
for
_
,
block
:=
range
incoming
.
Blocks
()
{
...
...
@@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage(
if
incoming
.
Wantlist
()
!=
nil
{
for
_
,
key
:=
range
incoming
.
Wantlist
()
{
if
bs
.
strateg
ist
.
ShouldSendToPeer
(
key
,
sender
)
{
if
bs
.
strateg
y
.
ShouldSend
Block
ToPeer
(
key
,
sender
)
{
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
)
if
errBlockNotFound
!=
nil
{
// TODO(brian): log/return the error
...
...
bitswap/strategy/interface.go
View file @
de9fcf5d
...
...
@@ -6,17 +6,17 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
type
Strateg
ist
interface
{
type
Strateg
y
interface
{
Accountant
// Returns a slice of Peers that
Peers
()
[]
*
peer
.
Peer
// WantList returns the WantList for the given Peer
IsWantedByPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
Block
IsWantedByPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
// ShouldSendTo(Peer) decides whether to send data to this Peer
ShouldSendToPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
ShouldSend
Block
ToPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
// Seed initializes the decider to a deterministic state
Seed
(
int64
)
...
...
bitswap/strategy/strategy.go
View file @
de9fcf5d
...
...
@@ -9,7 +9,7 @@ import (
)
// TODO declare thread-safe datastore
func
New
()
Strateg
ist
{
func
New
()
Strateg
y
{
return
&
strategist
{
ledgerMap
:
ledgerMap
{},
strategyFunc
:
yesManStrategy
,
...
...
@@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer {
return
response
}
func
(
s
*
strategist
)
IsWantedByPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
func
(
s
*
strategist
)
Block
IsWantedByPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
ledger
:=
s
.
ledger
(
p
)
return
ledger
.
WantListContains
(
k
)
}
func
(
s
*
strategist
)
ShouldSendToPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
func
(
s
*
strategist
)
ShouldSend
Block
ToPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
ledger
:=
s
.
ledger
(
p
)
return
ledger
.
ShouldSend
()
}
...
...
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