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
eb96dbd7
Commit
eb96dbd7
authored
Jan 17, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move dht record code into new package
parent
2327b3c0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
39 deletions
+52
-39
dht/dht.go
dht/dht.go
+2
-1
dht/ext_test.go
dht/ext_test.go
+2
-1
dht/records.go
dht/records.go
+2
-34
dht/routing.go
dht/routing.go
+2
-1
offline/offline.go
offline/offline.go
+2
-2
record/record.go
record/record.go
+42
-0
No files found.
dht/dht.go
View file @
eb96dbd7
...
...
@@ -17,6 +17,7 @@ import (
routing
"github.com/jbenet/go-ipfs/routing"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
kb
"github.com/jbenet/go-ipfs/routing/kbucket"
record
"github.com/jbenet/go-ipfs/routing/record"
"github.com/jbenet/go-ipfs/thirdparty/eventlog"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -253,7 +254,7 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
return
err
}
rec
,
err
:=
MakePutRecord
(
sk
,
key
,
value
)
rec
,
err
:=
record
.
MakePutRecord
(
sk
,
key
,
value
)
if
err
!=
nil
{
return
err
}
...
...
dht/ext_test.go
View file @
eb96dbd7
...
...
@@ -11,6 +11,7 @@ import (
peer
"github.com/jbenet/go-ipfs/p2p/peer"
routing
"github.com/jbenet/go-ipfs/routing"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
record
"github.com/jbenet/go-ipfs/routing/record"
u
"github.com/jbenet/go-ipfs/util"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -104,7 +105,7 @@ func TestGetFailures(t *testing.T) {
t
.
Fatal
(
err
)
}
rec
,
err
:=
MakePutRecord
(
sk
,
u
.
Key
(
str
),
[]
byte
(
"blah"
))
rec
,
err
:=
record
.
MakePutRecord
(
sk
,
u
.
Key
(
str
),
[]
byte
(
"blah"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
dht/records.go
View file @
eb96dbd7
...
...
@@ -7,11 +7,11 @@ import (
"strings"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ci
"github.com/jbenet/go-ipfs/p2p/crypto"
"github.com/jbenet/go-ipfs/p2p/peer"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
record
"github.com/jbenet/go-ipfs/routing/record"
u
"github.com/jbenet/go-ipfs/util"
ctxutil
"github.com/jbenet/go-ipfs/util/ctx"
)
...
...
@@ -34,38 +34,6 @@ func KeyForPublicKey(id peer.ID) u.Key {
return
u
.
Key
(
"/pk/"
+
string
(
id
))
}
// RecordBlobForSig returns the blob protected by the record signature
func
RecordBlobForSig
(
r
*
pb
.
Record
)
[]
byte
{
k
:=
[]
byte
(
r
.
GetKey
())
v
:=
[]
byte
(
r
.
GetValue
())
a
:=
[]
byte
(
r
.
GetAuthor
())
return
bytes
.
Join
([][]
byte
{
k
,
v
,
a
},
[]
byte
{})
}
// MakePutRecord creates and signs a dht record for the given key/value pair
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
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
}
record
.
Signature
=
sig
return
record
,
nil
}
func
(
dht
*
IpfsDHT
)
getPublicKeyOnline
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
log
.
Debugf
(
"getPublicKey for: %s"
,
p
)
...
...
@@ -179,7 +147,7 @@ func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error
// it might be useful for users to have access to.
func
(
dht
*
IpfsDHT
)
verifyRecord
(
r
*
pb
.
Record
,
pk
ci
.
PubKey
)
error
{
// First, validate the signature
blob
:=
RecordBlobForSig
(
r
)
blob
:=
record
.
RecordBlobForSig
(
r
)
ok
,
err
:=
pk
.
Verify
(
blob
,
r
.
GetSignature
())
if
err
!=
nil
{
log
.
Error
(
"Signature verify failed."
)
...
...
dht/routing.go
View file @
eb96dbd7
...
...
@@ -12,6 +12,7 @@ import (
"github.com/jbenet/go-ipfs/routing"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
kb
"github.com/jbenet/go-ipfs/routing/kbucket"
record
"github.com/jbenet/go-ipfs/routing/record"
u
"github.com/jbenet/go-ipfs/util"
errors
"github.com/jbenet/go-ipfs/util/debugerror"
pset
"github.com/jbenet/go-ipfs/util/peerset"
...
...
@@ -41,7 +42,7 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error
return
err
}
rec
,
err
:=
MakePutRecord
(
sk
,
key
,
value
)
rec
,
err
:=
record
.
MakePutRecord
(
sk
,
key
,
value
)
if
err
!=
nil
{
log
.
Error
(
"Creation of record failed!"
)
return
err
...
...
offline/offline.go
View file @
eb96dbd7
...
...
@@ -10,8 +10,8 @@ import (
ci
"github.com/jbenet/go-ipfs/p2p/crypto"
"github.com/jbenet/go-ipfs/p2p/peer"
routing
"github.com/jbenet/go-ipfs/routing"
dht
"github.com/jbenet/go-ipfs/routing/dht"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
record
"github.com/jbenet/go-ipfs/routing/record"
eventlog
"github.com/jbenet/go-ipfs/thirdparty/eventlog"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -36,7 +36,7 @@ type offlineRouting struct {
}
func
(
c
*
offlineRouting
)
PutValue
(
ctx
context
.
Context
,
key
u
.
Key
,
val
[]
byte
)
error
{
rec
,
err
:=
dht
.
MakePutRecord
(
c
.
sk
,
key
,
val
)
rec
,
err
:=
record
.
MakePutRecord
(
c
.
sk
,
key
,
val
)
if
err
!=
nil
{
return
err
}
...
...
record/record.go
0 → 100644
View file @
eb96dbd7
package
record
import
(
"bytes"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ci
"github.com/jbenet/go-ipfs/p2p/crypto"
pb
"github.com/jbenet/go-ipfs/routing/dht/pb"
u
"github.com/jbenet/go-ipfs/util"
)
// MakePutRecord creates and signs a dht record for the given key/value pair
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
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
}
record
.
Signature
=
sig
return
record
,
nil
}
// RecordBlobForSig returns the blob protected by the record signature
func
RecordBlobForSig
(
r
*
pb
.
Record
)
[]
byte
{
k
:=
[]
byte
(
r
.
GetKey
())
v
:=
[]
byte
(
r
.
GetValue
())
a
:=
[]
byte
(
r
.
GetAuthor
())
return
bytes
.
Join
([][]
byte
{
k
,
v
,
a
},
[]
byte
{})
}
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