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
d98d6cdf
Commit
d98d6cdf
authored
Feb 26, 2015
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #834 from jbenet/fix/815
make the providers manager respect contexts
parents
cb6d161b
3b2bd9bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
5 deletions
+9
-5
routing/dht/handlers.go
routing/dht/handlers.go
+1
-1
routing/dht/providers.go
routing/dht/providers.go
+6
-2
routing/dht/providers_test.go
routing/dht/providers_test.go
+1
-1
routing/dht/routing.go
routing/dht/routing.go
+1
-1
No files found.
routing/dht/handlers.go
View file @
d98d6cdf
...
@@ -223,7 +223,7 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
...
@@ -223,7 +223,7 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
// add the received addresses to our peerstore.
// add the received addresses to our peerstore.
dht
.
peerstore
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
peer
.
ProviderAddrTTL
)
dht
.
peerstore
.
AddAddrs
(
pi
.
ID
,
pi
.
Addrs
,
peer
.
ProviderAddrTTL
)
}
}
dht
.
providers
.
AddProvider
(
key
,
p
)
dht
.
providers
.
AddProvider
(
ctx
,
key
,
p
)
}
}
return
pmes
,
nil
// send back same msg as confirmation.
return
pmes
,
nil
// send back same msg as confirmation.
...
...
routing/dht/providers.go
View file @
d98d6cdf
...
@@ -99,11 +99,15 @@ func (pm *ProviderManager) run() {
...
@@ -99,11 +99,15 @@ func (pm *ProviderManager) run() {
}
}
}
}
func
(
pm
*
ProviderManager
)
AddProvider
(
k
u
.
Key
,
val
peer
.
ID
)
{
func
(
pm
*
ProviderManager
)
AddProvider
(
ctx
context
.
Context
,
k
u
.
Key
,
val
peer
.
ID
)
{
p
m
.
newprovs
<-
&
addProv
{
p
rov
:=
&
addProv
{
k
:
k
,
k
:
k
,
val
:
val
,
val
:
val
,
}
}
select
{
case
pm
.
newprovs
<-
prov
:
case
<-
ctx
.
Done
()
:
}
}
}
func
(
pm
*
ProviderManager
)
GetProviders
(
ctx
context
.
Context
,
k
u
.
Key
)
[]
peer
.
ID
{
func
(
pm
*
ProviderManager
)
GetProviders
(
ctx
context
.
Context
,
k
u
.
Key
)
[]
peer
.
ID
{
...
...
routing/dht/providers_test.go
View file @
d98d6cdf
...
@@ -14,7 +14,7 @@ func TestProviderManager(t *testing.T) {
...
@@ -14,7 +14,7 @@ func TestProviderManager(t *testing.T) {
mid
:=
peer
.
ID
(
"testing"
)
mid
:=
peer
.
ID
(
"testing"
)
p
:=
NewProviderManager
(
ctx
,
mid
)
p
:=
NewProviderManager
(
ctx
,
mid
)
a
:=
u
.
Key
(
"test"
)
a
:=
u
.
Key
(
"test"
)
p
.
AddProvider
(
a
,
peer
.
ID
(
"testingprovider"
))
p
.
AddProvider
(
ctx
,
a
,
peer
.
ID
(
"testingprovider"
))
resp
:=
p
.
GetProviders
(
ctx
,
a
)
resp
:=
p
.
GetProviders
(
ctx
,
a
)
if
len
(
resp
)
!=
1
{
if
len
(
resp
)
!=
1
{
t
.
Fatal
(
"Could not retrieve provider."
)
t
.
Fatal
(
"Could not retrieve provider."
)
...
...
routing/dht/routing.go
View file @
d98d6cdf
...
@@ -141,7 +141,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
...
@@ -141,7 +141,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
defer
log
.
EventBegin
(
ctx
,
"provide"
,
&
key
)
.
Done
()
defer
log
.
EventBegin
(
ctx
,
"provide"
,
&
key
)
.
Done
()
// add self locally
// add self locally
dht
.
providers
.
AddProvider
(
key
,
dht
.
self
)
dht
.
providers
.
AddProvider
(
ctx
,
key
,
dht
.
self
)
peers
,
err
:=
dht
.
GetClosestPeers
(
ctx
,
key
)
peers
,
err
:=
dht
.
GetClosestPeers
(
ctx
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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