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-unixfs
Commits
8542380e
Commit
8542380e
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
not quite working yet, but closer
parent
b8a6fbbf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
routing/dht/dht.go
routing/dht/dht.go
+3
-2
routing/dht/routing.go
routing/dht/routing.go
+19
-1
swarm/swarm.go
swarm/swarm.go
+4
-0
No files found.
routing/dht/dht.go
View file @
8542380e
...
...
@@ -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]
\nGot 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,
...
...
This diff is collapsed.
Click to expand it.
routing/dht/routing.go
View file @
8542380e
...
...
@@ -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
())
...
...
This diff is collapsed.
Click to expand it.
swarm/swarm.go
View file @
8542380e
...
...
@@ -316,6 +316,10 @@ func (s *Swarm) GetConnection(id peer.ID, addr *ma.Multiaddr) (*peer.Peer, error
Addresses
:
[]
*
ma
.
Multiaddr
{
addr
},
}
if
id
.
Equal
(
s
.
local
.
ID
)
{
panic
(
"Attempted connection to self!"
)
}
conn
,
err
,
reused
:=
s
.
Dial
(
p
)
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
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