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
29aa7547
Commit
29aa7547
authored
Dec 07, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
same block cant be sent twice to a peer within a certain time period
parent
13ab516c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
strategy/ledger.go
strategy/ledger.go
+2
-2
strategy/strategy.go
strategy/strategy.go
+6
-3
No files found.
strategy/ledger.go
View file @
29aa7547
...
...
@@ -16,7 +16,7 @@ func newLedger(p peer.Peer, strategy strategyFunc) *ledger {
wantList
:
keySet
{},
Strategy
:
strategy
,
Partner
:
p
,
sentToPeer
:
make
(
map
[
u
.
Key
]
struct
{}
),
sentToPeer
:
make
(
map
[
u
.
Key
]
time
.
Time
),
}
}
...
...
@@ -43,7 +43,7 @@ type ledger struct {
// sentToPeer is a set of keys to ensure we dont send duplicate blocks
// to a given peer
sentToPeer
map
[
u
.
Key
]
struct
{}
sentToPeer
map
[
u
.
Key
]
time
.
Time
Strategy
strategyFunc
}
...
...
strategy/strategy.go
View file @
29aa7547
...
...
@@ -10,6 +10,8 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
const
resendTimeoutPeriod
=
time
.
Minute
var
log
=
u
.
Logger
(
"strategy"
)
// TODO niceness should be on a per-peer basis. Use-case: Certain peers are
...
...
@@ -66,8 +68,9 @@ func (s *strategist) ShouldSendBlockToPeer(k u.Key, p peer.Peer) bool {
ledger
:=
s
.
ledger
(
p
)
// Dont resend blocks
if
_
,
ok
:=
ledger
.
sentToPeer
[
k
];
ok
{
// Dont resend blocks within a certain time period
t
,
ok
:=
ledger
.
sentToPeer
[
k
]
if
ok
&&
t
.
Add
(
resendTimeoutPeriod
)
.
After
(
time
.
Now
())
{
return
false
}
...
...
@@ -79,7 +82,7 @@ func (s *strategist) BlockSentToPeer(k u.Key, p peer.Peer) {
defer
s
.
lock
.
Unlock
()
ledger
:=
s
.
ledger
(
p
)
ledger
.
sentToPeer
[
k
]
=
struct
{}{}
ledger
.
sentToPeer
[
k
]
=
time
.
Now
()
}
func
(
s
*
strategist
)
Seed
(
int64
)
{
...
...
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