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
0abc72c0
Commit
0abc72c0
authored
Nov 19, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move some variables into strategy
parent
4d144758
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
8 deletions
+60
-8
blockservice/blockservice.go
blockservice/blockservice.go
+5
-0
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+10
-8
exchange/bitswap/strategy/interface.go
exchange/bitswap/strategy/interface.go
+7
-0
exchange/bitswap/strategy/strategy.go
exchange/bitswap/strategy/strategy.go
+13
-0
net/interface.go
net/interface.go
+4
-0
net/mux/mux.go
net/mux/mux.go
+16
-0
net/net.go
net/net.go
+5
-0
No files found.
blockservice/blockservice.go
View file @
0abc72c0
...
...
@@ -96,6 +96,11 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
}
}
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
(
<-
chan
blocks
.
Block
,
error
)
{
// TODO:
return
nil
,
nil
}
// DeleteBlock deletes a block in the blockservice from the datastore
func
(
s
*
BlockService
)
DeleteBlock
(
k
u
.
Key
)
error
{
return
s
.
Datastore
.
Delete
(
k
.
DsKey
())
...
...
exchange/bitswap/bitswap.go
View file @
0abc72c0
...
...
@@ -157,9 +157,10 @@ func (bs *bitswap) run(ctx context.Context) {
rebroadcastTime
:=
time
.
Second
*
5
var
providers
<-
chan
peer
.
Peer
// NB: must be initialized to zero value
broadcastSignal
:=
time
.
After
(
rebroadcastPeriod
)
unsentKeys
:=
0
broadcastSignal
:=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
// Number of unsent keys for the current batch
unsentKeys
:=
0
for
{
select
{
case
<-
broadcastSignal
:
...
...
@@ -170,14 +171,14 @@ func (bs *bitswap) run(ctx context.Context) {
if
providers
==
nil
{
// rely on semi randomness of maps
firstKey
:=
wantlist
[
0
]
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
6
)
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
maxProvidersPerRequest
)
}
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
providers
=
nil
broadcastSignal
=
time
.
After
(
r
ebroadcast
Period
)
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetR
ebroadcast
Delay
()
)
case
k
:=
<-
bs
.
blockRequests
:
if
unsentKeys
==
0
{
...
...
@@ -185,19 +186,19 @@ func (bs *bitswap) run(ctx context.Context) {
}
unsentKeys
++
if
unsentKeys
>=
numKeysPerBatch
{
if
unsentKeys
>=
bs
.
strategy
.
GetBatchSize
()
{
// send wantlist to providers
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
unsentKeys
=
0
broadcastSignal
=
time
.
After
(
r
ebroadcast
Period
)
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetR
ebroadcast
Delay
()
)
providers
=
nil
}
else
{
// set a timeout to wait for more blocks or send current wantlist
broadcastSignal
=
time
.
After
(
batchDelay
)
broadcastSignal
=
time
.
After
(
b
s
.
strategy
.
GetB
atchDelay
()
)
}
case
<-
ctx
.
Done
()
:
return
...
...
@@ -217,7 +218,7 @@ 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
.
Debugf
(
"ReceiveMessage from %
v
"
,
p
.
Key
()
)
log
.
Debugf
(
"ReceiveMessage from %
s
"
,
p
)
log
.
Debugf
(
"Message wantlist: %v"
,
incoming
.
Wantlist
())
if
p
==
nil
{
...
...
@@ -239,6 +240,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
for
_
,
block
:=
range
incoming
.
Blocks
()
{
// TODO verify blocks?
if
err
:=
bs
.
blockstore
.
Put
(
&
block
);
err
!=
nil
{
log
.
Criticalf
(
"error putting block: %s"
,
err
)
continue
// FIXME(brian): err ignored
}
bs
.
notifications
.
Publish
(
block
)
...
...
exchange/bitswap/strategy/interface.go
View file @
0abc72c0
package
strategy
import
(
"time"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -29,4 +31,9 @@ type Strategy interface {
NumBytesSentTo
(
peer
.
Peer
)
uint64
NumBytesReceivedFrom
(
peer
.
Peer
)
uint64
// Values determining bitswap behavioural patterns
GetBatchSize
()
int
GetBatchDelay
()
time
.
Duration
GetRebroadcastDelay
()
time
.
Duration
}
exchange/bitswap/strategy/strategy.go
View file @
0abc72c0
...
...
@@ -3,6 +3,7 @@ package strategy
import
(
"errors"
"sync"
"time"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -139,3 +140,15 @@ func (s *strategist) ledger(p peer.Peer) *ledger {
}
return
l
}
func
(
s
*
strategist
)
GetBatchSize
()
int
{
return
10
}
func
(
s
*
strategist
)
GetBatchDelay
()
time
.
Duration
{
return
time
.
Millisecond
*
3
}
func
(
s
*
strategist
)
GetRebroadcastDelay
()
time
.
Duration
{
return
time
.
Second
*
2
}
net/interface.go
View file @
0abc72c0
...
...
@@ -42,6 +42,10 @@ type Network interface {
// the network since it was instantiated
GetBandwidthTotals
()
(
uint64
,
uint64
)
// GetMessageCounts returns the total number of messages passed through
// the network since it was instantiated
GetMessageCounts
()
(
uint64
,
uint64
)
// SendMessage sends given Message out
SendMessage
(
msg
.
NetMessage
)
error
...
...
net/mux/mux.go
View file @
0abc72c0
...
...
@@ -45,9 +45,11 @@ type Muxer struct {
bwiLock
sync
.
Mutex
bwIn
uint64
msgIn
uint64
bwoLock
sync
.
Mutex
bwOut
uint64
msgOut
uint64
*
msg
.
Pipe
ctxc
.
ContextCloser
...
...
@@ -76,6 +78,18 @@ func (m *Muxer) GetPipe() *msg.Pipe {
return
m
.
Pipe
}
// GetMessageCounts return the in/out message count measured over this muxer.
func
(
m
*
Muxer
)
GetMessageCounts
()
(
in
uint64
,
out
uint64
)
{
m
.
bwiLock
.
Lock
()
in
=
m
.
msgIn
m
.
bwiLock
.
Unlock
()
m
.
bwoLock
.
Lock
()
out
=
m
.
msgOut
m
.
bwoLock
.
Unlock
()
return
}
// GetBandwidthTotals return the in/out bandwidth measured over this muxer.
func
(
m
*
Muxer
)
GetBandwidthTotals
()
(
in
uint64
,
out
uint64
)
{
m
.
bwiLock
.
Lock
()
...
...
@@ -125,6 +139,7 @@ func (m *Muxer) handleIncomingMessage(m1 msg.NetMessage) {
m
.
bwiLock
.
Lock
()
// TODO: compensate for overhead
m
.
bwIn
+=
uint64
(
len
(
m1
.
Data
()))
m
.
msgIn
++
m
.
bwiLock
.
Unlock
()
data
,
pid
,
err
:=
unwrapData
(
m1
.
Data
())
...
...
@@ -182,6 +197,7 @@ func (m *Muxer) handleOutgoingMessage(pid pb.ProtocolID, m1 msg.NetMessage) {
// TODO: compensate for overhead
// TODO(jbenet): switch this to a goroutine to prevent sync waiting.
m
.
bwOut
+=
uint64
(
len
(
data
))
m
.
msgOut
++
m
.
bwoLock
.
Unlock
()
m2
:=
msg
.
New
(
m1
.
Peer
(),
data
)
...
...
net/net.go
View file @
0abc72c0
...
...
@@ -110,6 +110,11 @@ func (n *IpfsNetwork) GetBandwidthTotals() (in uint64, out uint64) {
return
n
.
muxer
.
GetBandwidthTotals
()
}
// GetBandwidthTotals returns the total amount of messages transferred
func
(
n
*
IpfsNetwork
)
GetMessageCounts
()
(
in
uint64
,
out
uint64
)
{
return
n
.
muxer
.
GetMessageCounts
()
}
// ListenAddresses returns a list of addresses at which this network listens.
func
(
n
*
IpfsNetwork
)
ListenAddresses
()
[]
ma
.
Multiaddr
{
return
n
.
swarm
.
ListenAddresses
()
...
...
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