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
0bd6ae45
Commit
0bd6ae45
authored
Mar 31, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address comments from PR
parent
fdf7dbf6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
dht/records.go
dht/records.go
+3
-9
routing.go
routing.go
+22
-0
No files found.
dht/records.go
View file @
0bd6ae45
...
...
@@ -6,18 +6,12 @@ import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
ci
"github.com/ipfs/go-ipfs/p2p/crypto"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
routing
"github.com/ipfs/go-ipfs/routing"
pb
"github.com/ipfs/go-ipfs/routing/dht/pb"
record
"github.com/ipfs/go-ipfs/routing/record"
u
"github.com/ipfs/go-ipfs/util"
ctxutil
"github.com/ipfs/go-ipfs/util/ctx"
)
// KeyForPublicKey returns the key used to retrieve public keys
// from the dht.
func
KeyForPublicKey
(
id
peer
.
ID
)
u
.
Key
{
return
u
.
Key
(
"/pk/"
+
string
(
id
))
}
func
(
dht
*
IpfsDHT
)
GetPublicKey
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
log
.
Debugf
(
"getPublicKey for: %s"
,
p
)
...
...
@@ -40,7 +34,7 @@ func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, err
// last ditch effort: let's try the dht.
log
.
Debugf
(
"pk for %s not in peerstore, and peer failed. trying dht."
,
p
)
pkkey
:=
KeyForPublicKey
(
p
)
pkkey
:=
routing
.
KeyForPublicKey
(
p
)
val
,
err
:=
dht
.
GetValue
(
ctxT
,
pkkey
)
if
err
!=
nil
{
...
...
@@ -65,7 +59,7 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
return
pk
,
nil
}
pkkey
:=
KeyForPublicKey
(
p
)
pkkey
:=
routing
.
KeyForPublicKey
(
p
)
pmes
,
err
:=
dht
.
getValueSingle
(
ctx
,
p
,
pkkey
)
if
err
!=
nil
{
return
nil
,
err
...
...
routing.go
View file @
0bd6ae45
...
...
@@ -51,3 +51,25 @@ type IpfsRouting interface {
type
PubKeyFetcher
interface
{
GetPublicKey
(
context
.
Context
,
peer
.
ID
)
(
ci
.
PubKey
,
error
)
}
// KeyForPublicKey returns the key used to retrieve public keys
// from the dht.
func
KeyForPublicKey
(
id
peer
.
ID
)
u
.
Key
{
return
u
.
Key
(
"/pk/"
+
string
(
id
))
}
func
GetPublicKey
(
r
IpfsRouting
,
ctx
context
.
Context
,
pkhash
[]
byte
)
(
ci
.
PubKey
,
error
)
{
if
dht
,
ok
:=
r
.
(
PubKeyFetcher
);
ok
{
// If we have a DHT as our routing system, use optimized fetcher
return
dht
.
GetPublicKey
(
ctx
,
peer
.
ID
(
pkhash
))
}
else
{
key
:=
u
.
Key
(
"/pk/"
+
string
(
pkhash
))
pkval
,
err
:=
r
.
GetValue
(
ctx
,
key
)
if
err
!=
nil
{
return
nil
,
err
}
// get PublicKey from node.Data
return
ci
.
UnmarshalPublicKey
(
pkval
)
}
}
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