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
p2p
go-p2p-kad-dht
Commits
71f6e255
Commit
71f6e255
authored
Jan 16, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix fuse mounting issues
this time, without loading the private key on every startup
parent
9cc5c86e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
10 deletions
+38
-10
dht.go
dht.go
+16
-1
ext_test.go
ext_test.go
+7
-1
records.go
records.go
+7
-7
routing.go
routing.go
+8
-1
No files found.
dht.go
View file @
71f6e255
...
...
@@ -10,6 +10,7 @@ import (
"sync"
"time"
ci
"github.com/jbenet/go-ipfs/p2p/crypto"
host
"github.com/jbenet/go-ipfs/p2p/host"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
protocol
"github.com/jbenet/go-ipfs/p2p/protocol"
...
...
@@ -234,9 +235,23 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
return
rec
.
GetValue
(),
nil
}
func
(
dht
*
IpfsDHT
)
getOwnPrivateKey
()
(
ci
.
PrivKey
,
error
)
{
sk
:=
dht
.
peerstore
.
PrivKey
(
dht
.
self
)
if
sk
==
nil
{
log
.
Errorf
(
"%s dht cannot get own private key!"
,
dht
.
self
)
return
nil
,
fmt
.
Errorf
(
"cannot get private key to sign record!"
)
}
return
sk
,
nil
}
// putLocal stores the key value pair in the datastore
func
(
dht
*
IpfsDHT
)
putLocal
(
key
u
.
Key
,
value
[]
byte
)
error
{
rec
,
err
:=
dht
.
makePutRecord
(
key
,
value
)
sk
,
err
:=
dht
.
getOwnPrivateKey
()
if
err
!=
nil
{
return
err
}
rec
,
err
:=
MakePutRecord
(
sk
,
key
,
value
)
if
err
!=
nil
{
return
err
}
...
...
ext_test.go
View file @
71f6e255
...
...
@@ -98,7 +98,13 @@ func TestGetFailures(t *testing.T) {
{
typ
:=
pb
.
Message_GET_VALUE
str
:=
"hello"
rec
,
err
:=
d
.
makePutRecord
(
u
.
Key
(
str
),
[]
byte
(
"blah"
))
sk
,
err
:=
d
.
getOwnPrivateKey
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rec
,
err
:=
MakePutRecord
(
sk
,
u
.
Key
(
str
),
[]
byte
(
"blah"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
records.go
View file @
71f6e255
...
...
@@ -43,20 +43,20 @@ func RecordBlobForSig(r *pb.Record) []byte {
}
// creates and signs a dht record for the given key/value pair
func
(
dht
*
IpfsDHT
)
makePutRecord
(
key
u
.
Key
,
value
[]
byte
)
(
*
pb
.
Record
,
error
)
{
func
MakePutRecord
(
sk
ci
.
PrivKey
,
key
u
.
Key
,
value
[]
byte
)
(
*
pb
.
Record
,
error
)
{
record
:=
new
(
pb
.
Record
)
record
.
Key
=
proto
.
String
(
string
(
key
))
record
.
Value
=
value
record
.
Author
=
proto
.
String
(
string
(
dht
.
self
))
blob
:=
RecordBlobForSig
(
record
)
sk
:=
dht
.
peerstore
.
PrivKey
(
dht
.
self
)
if
sk
==
nil
{
log
.
Errorf
(
"%s dht cannot get own private key!"
,
dht
.
self
)
return
nil
,
fmt
.
Errorf
(
"cannot get private key to sign record!"
)
pkh
,
err
:=
sk
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
return
nil
,
err
}
record
.
Author
=
proto
.
String
(
string
(
pkh
))
blob
:=
RecordBlobForSig
(
record
)
sig
,
err
:=
sk
.
Sign
(
blob
)
if
err
!=
nil
{
return
nil
,
err
...
...
routing.go
View file @
71f6e255
...
...
@@ -36,7 +36,12 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error
return
err
}
rec
,
err
:=
dht
.
makePutRecord
(
key
,
value
)
sk
,
err
:=
dht
.
getOwnPrivateKey
()
if
err
!=
nil
{
return
err
}
rec
,
err
:=
MakePutRecord
(
sk
,
key
,
value
)
if
err
!=
nil
{
log
.
Error
(
"Creation of record failed!"
)
return
err
...
...
@@ -75,6 +80,8 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
if
err
==
nil
{
log
.
Debug
(
"have it locally"
)
return
val
,
nil
}
else
{
log
.
Debug
(
"failed to get value locally: %s"
,
err
)
}
// get closest peers in the routing table
...
...
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