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-routing
Commits
9215b454
Commit
9215b454
authored
Sep 19, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provider testing
parent
2e150db8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
8 deletions
+15
-8
dht/dht.go
dht/dht.go
+8
-3
dht/dht_test.go
dht/dht_test.go
+5
-4
dht/routing.go
dht/routing.go
+2
-1
No files found.
dht/dht.go
View file @
9215b454
...
...
@@ -208,13 +208,18 @@ func (dht *IpfsDHT) putValueToNetwork(ctx context.Context, p *peer.Peer,
}
func
(
dht
*
IpfsDHT
)
putProvider
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
key
string
)
error
{
pmes
:=
newMessage
(
Message_ADD_PROVIDER
,
string
(
key
),
0
)
mes
,
err
:=
msg
.
FromObject
(
p
,
pmes
)
pmes
:=
newMessage
(
Message_ADD_PROVIDER
,
string
(
key
),
0
)
rpmes
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
if
err
!=
nil
{
return
err
}
return
dht
.
sender
.
SendMessage
(
ctx
,
mes
)
if
*
rpmes
.
Key
!=
*
pmes
.
Key
{
return
errors
.
New
(
"provider not added correctly"
)
}
return
nil
}
func
(
dht
*
IpfsDHT
)
getValueOrPeers
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
...
...
dht/dht_test.go
View file @
9215b454
package
dht
import
(
"bytes"
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -44,7 +45,7 @@ func setupDHT(t *testing.T, p *peer.Peer) *IpfsDHT {
func
setupDHTS
(
n
int
,
t
*
testing
.
T
)
([]
*
ma
.
Multiaddr
,
[]
*
peer
.
Peer
,
[]
*
IpfsDHT
)
{
var
addrs
[]
*
ma
.
Multiaddr
for
i
:=
0
;
i
<
4
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
a
,
err
:=
ma
.
NewMultiaddr
(
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
5000
+
i
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -53,13 +54,13 @@ func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT)
}
var
peers
[]
*
peer
.
Peer
for
i
:=
0
;
i
<
4
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
p
:=
makePeer
(
addrs
[
i
])
peers
=
append
(
peers
,
p
)
}
var
dhts
[]
*
IpfsDHT
for
i
:=
0
;
i
<
4
;
i
++
{
dhts
:=
make
(
[]
*
IpfsDHT
,
n
)
for
i
:=
0
;
i
<
n
;
i
++
{
dhts
[
i
]
=
setupDHT
(
t
,
peers
[
i
])
}
...
...
dht/routing.go
View file @
9215b454
...
...
@@ -90,7 +90,6 @@ func (dht *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
}
u
.
DOut
(
"[%s] GetValue %v %v
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
key
,
result
.
value
)
if
result
.
value
==
nil
{
return
nil
,
u
.
ErrNotFound
}
...
...
@@ -111,6 +110,8 @@ func (dht *IpfsDHT) Provide(key u.Key) error {
return
kb
.
ErrLookupFailure
}
//TODO FIX: this doesn't work! it needs to be sent to the actual nearest peers.
// `peers` are the closest peers we have, not the ones that should get the value.
for
_
,
p
:=
range
peers
{
err
:=
dht
.
putProvider
(
ctx
,
p
,
string
(
key
))
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