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
59143696
Commit
59143696
authored
Aug 12, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
not quite working yet, but closer
parent
b0f6618d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
3 deletions
+22
-3
dht/dht.go
dht/dht.go
+3
-2
dht/routing.go
dht/routing.go
+19
-1
No files found.
dht/dht.go
View file @
59143696
...
...
@@ -158,8 +158,8 @@ func (dht *IpfsDHT) handleMessages() {
}
//
u
.
DOut
(
"[peer: %s]
"
,
dht
.
self
.
ID
.
Pretty
())
u
.
DOut
(
"Got message type: '%s' [id = %x, from = %s]"
,
u
.
DOut
(
"[peer: %s]
\n
Got message type: '%s' [id = %x, from = %s]"
,
dht
.
self
.
ID
.
Pretty
()
,
PBDHTMessage_MessageType_name
[
int32
(
pmes
.
GetType
())],
pmes
.
GetId
(),
mes
.
Peer
.
ID
.
Pretty
())
switch
pmes
.
GetType
()
{
...
...
@@ -235,6 +235,7 @@ func (dht *IpfsDHT) putValueToNetwork(p *peer.Peer, key string, value []byte) er
}
func
(
dht
*
IpfsDHT
)
handleGetValue
(
p
*
peer
.
Peer
,
pmes
*
PBDHTMessage
)
{
u
.
DOut
(
"handleGetValue for key: %s"
,
pmes
.
GetKey
())
dskey
:=
ds
.
NewKey
(
pmes
.
GetKey
())
resp
:=
&
DHTMessage
{
Response
:
true
,
...
...
dht/routing.go
View file @
59143696
...
...
@@ -62,11 +62,22 @@ func (s *IpfsDHT) PutValue(key u.Key, value []byte) {
func
(
s
*
IpfsDHT
)
GetValue
(
key
u
.
Key
,
timeout
time
.
Duration
)
([]
byte
,
error
)
{
route_level
:=
0
// If we have it local, dont bother doing an RPC!
// NOTE: this might not be what we want to do...
val
,
err
:=
s
.
GetLocal
(
key
)
if
err
!=
nil
{
return
val
,
nil
}
p
:=
s
.
routes
[
route_level
]
.
NearestPeer
(
kb
.
ConvertKey
(
key
))
if
p
==
nil
{
return
nil
,
kb
.
ErrLookupFailure
}
if
kb
.
Closer
(
s
.
self
.
ID
,
p
.
ID
,
key
)
{
return
nil
,
u
.
ErrNotFound
}
for
route_level
<
len
(
s
.
routes
)
&&
p
!=
nil
{
pmes
,
err
:=
s
.
getValueSingle
(
p
,
key
,
timeout
,
route_level
)
if
err
!=
nil
{
...
...
@@ -84,17 +95,21 @@ func (s *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
// We were given a closer node
closers
:=
pmes
.
GetPeers
()
if
len
(
closers
)
>
0
{
if
peer
.
ID
(
closers
[
0
]
.
GetId
())
.
Equal
(
s
.
self
.
ID
)
{
return
nil
,
u
.
ErrNotFound
}
maddr
,
err
:=
ma
.
NewMultiaddr
(
closers
[
0
]
.
GetAddr
())
if
err
!=
nil
{
// ??? Move up route level???
panic
(
"not yet implemented"
)
}
p
,
err
=
s
.
network
.
GetConnection
(
peer
.
ID
(
closers
[
0
]
.
GetId
()),
maddr
)
n
p
,
err
:
=
s
.
network
.
GetConnection
(
peer
.
ID
(
closers
[
0
]
.
GetId
()),
maddr
)
if
err
!=
nil
{
u
.
PErr
(
"[%s] Failed to connect to: %s"
,
s
.
self
.
ID
.
Pretty
(),
closers
[
0
]
.
GetAddr
())
route_level
++
}
p
=
np
}
else
{
route_level
++
}
...
...
@@ -159,6 +174,9 @@ func (s *IpfsDHT) FindProviders(key u.Key, timeout time.Duration) ([]*peer.Peer,
var
prov_arr
[]
*
peer
.
Peer
for
_
,
prov
:=
range
pmes_out
.
GetPeers
()
{
if
peer
.
ID
(
prov
.
GetId
())
.
Equal
(
s
.
self
.
ID
)
{
continue
}
p
:=
s
.
network
.
Find
(
u
.
Key
(
prov
.
GetId
()))
if
p
==
nil
{
u
.
DOut
(
"given provider %s was not in our network already."
,
peer
.
ID
(
prov
.
GetId
())
.
Pretty
())
...
...
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