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
8f742c12
Commit
8f742c12
authored
Nov 11, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Nov 16, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix routing resolver
parent
f9018750
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-1
dht/dht.go
dht/dht.go
+3
-0
dht/records.go
dht/records.go
+35
-1
mock/routing.go
mock/routing.go
+5
-0
No files found.
dht/dht.go
View file @
8f742c12
...
...
@@ -355,10 +355,12 @@ func (dht *IpfsDHT) getFromPeerList(ctx context.Context, key u.Key,
func
(
dht
*
IpfsDHT
)
getLocal
(
key
u
.
Key
)
([]
byte
,
error
)
{
dht
.
dslock
.
Lock
()
defer
dht
.
dslock
.
Unlock
()
log
.
Debug
(
"getLocal %s"
,
key
)
v
,
err
:=
dht
.
datastore
.
Get
(
key
.
DsKey
())
if
err
!=
nil
{
return
nil
,
err
}
log
.
Debug
(
"found in db"
)
byt
,
ok
:=
v
.
([]
byte
)
if
!
ok
{
...
...
@@ -374,6 +376,7 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
if
u
.
Debug
{
err
=
dht
.
verifyRecord
(
rec
)
if
err
!=
nil
{
log
.
Errorf
(
"local record verify failed: %s"
,
err
)
return
nil
,
err
}
}
...
...
dht/records.go
View file @
8f742c12
...
...
@@ -4,8 +4,11 @@ import (
"bytes"
"errors"
"strings"
"time"
"code.google.com/p/go.net/context"
"code.google.com/p/goprotobuf/proto"
ci
"github.com/jbenet/go-ipfs/crypto"
"github.com/jbenet/go-ipfs/peer"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -32,6 +35,29 @@ func (dht *IpfsDHT) makePutRecord(key u.Key, value []byte) (*pb.Record, error) {
return
record
,
nil
}
func
(
dht
*
IpfsDHT
)
getPublicKey
(
pid
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
log
.
Debug
(
"getPublicKey for: %s"
,
pid
)
p
,
err
:=
dht
.
peerstore
.
Get
(
pid
)
if
err
==
nil
{
return
p
.
PubKey
(),
nil
}
log
.
Debug
(
"not in peerstore, searching dht."
)
ctxT
,
_
:=
context
.
WithTimeout
(
dht
.
ContextCloser
.
Context
(),
time
.
Second
*
5
)
val
,
err
:=
dht
.
GetValue
(
ctxT
,
u
.
Key
(
"/pk/"
+
string
(
pid
)))
if
err
!=
nil
{
log
.
Warning
(
"Failed to find requested public key."
)
return
nil
,
err
}
pubkey
,
err
:=
ci
.
UnmarshalPublicKey
(
val
)
if
err
!=
nil
{
log
.
Errorf
(
"Failed to unmarshal public key: %s"
,
err
)
return
nil
,
err
}
return
pubkey
,
nil
}
func
(
dht
*
IpfsDHT
)
verifyRecord
(
r
*
pb
.
Record
)
error
{
// First, validate the signature
p
,
err
:=
dht
.
peerstore
.
Get
(
peer
.
ID
(
r
.
GetAuthor
()))
...
...
@@ -76,6 +102,14 @@ func ValidateIpnsRecord(k u.Key, val []byte) error {
}
func
ValidatePublicKeyRecord
(
k
u
.
Key
,
val
[]
byte
)
error
{
// TODO:
keyparts
:=
bytes
.
Split
([]
byte
(
k
),
[]
byte
(
"/"
))
if
len
(
keyparts
)
<
3
{
return
errors
.
New
(
"invalid key"
)
}
pkh
:=
u
.
Hash
(
val
)
if
!
bytes
.
Equal
(
keyparts
[
2
],
pkh
)
{
return
errors
.
New
(
"public key does not match storage key"
)
}
return
nil
}
mock/routing.go
View file @
8f742c12
...
...
@@ -12,6 +12,8 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
var
log
=
u
.
Logger
(
"mockrouter"
)
var
_
routing
.
IpfsRouting
=
&
MockRouter
{}
type
MockRouter
struct
{
...
...
@@ -33,10 +35,12 @@ func (mr *MockRouter) SetRoutingServer(rs RoutingServer) {
}
func
(
mr
*
MockRouter
)
PutValue
(
ctx
context
.
Context
,
key
u
.
Key
,
val
[]
byte
)
error
{
log
.
Debugf
(
"PutValue: %s"
,
key
)
return
mr
.
datastore
.
Put
(
key
.
DsKey
(),
val
)
}
func
(
mr
*
MockRouter
)
GetValue
(
ctx
context
.
Context
,
key
u
.
Key
)
([]
byte
,
error
)
{
log
.
Debugf
(
"GetValue: %s"
,
key
)
v
,
err
:=
mr
.
datastore
.
Get
(
key
.
DsKey
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,6 +59,7 @@ func (mr *MockRouter) FindProviders(ctx context.Context, key u.Key) ([]peer.Peer
}
func
(
mr
*
MockRouter
)
FindPeer
(
ctx
context
.
Context
,
pid
peer
.
ID
)
(
peer
.
Peer
,
error
)
{
log
.
Debug
(
"FindPeer: %s"
,
pid
)
return
nil
,
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