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
366bfd4b
Commit
366bfd4b
authored
Aug 13, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update to new datastore interface
parent
e16e1677
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
20 deletions
+7
-20
handlers.go
handlers.go
+5
-18
package.json
package.json
+2
-2
No files found.
handlers.go
View file @
366bfd4b
...
...
@@ -94,8 +94,8 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
func
(
dht
*
IpfsDHT
)
checkLocalDatastore
(
k
[]
byte
)
(
*
recpb
.
Record
,
error
)
{
log
.
Debugf
(
"%s handleGetValue looking into ds"
,
dht
.
self
)
dskey
:=
convertToDsKey
(
k
)
iVal
,
err
:=
dht
.
datastore
.
Get
(
dskey
)
log
.
Debugf
(
"%s handleGetValue looking into ds GOT %v"
,
dht
.
self
,
iVal
)
buf
,
err
:=
dht
.
datastore
.
Get
(
dskey
)
log
.
Debugf
(
"%s handleGetValue looking into ds GOT %v"
,
dht
.
self
,
buf
)
if
err
==
ds
.
ErrNotFound
{
return
nil
,
nil
...
...
@@ -109,13 +109,8 @@ func (dht *IpfsDHT) checkLocalDatastore(k []byte) (*recpb.Record, error) {
// if we have the value, send it back
log
.
Debugf
(
"%s handleGetValue success!"
,
dht
.
self
)
byts
,
ok
:=
iVal
.
([]
byte
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"datastore had non byte-slice value for %v"
,
dskey
)
}
rec
:=
new
(
recpb
.
Record
)
err
=
proto
.
Unmarshal
(
b
yts
,
rec
)
err
=
proto
.
Unmarshal
(
b
uf
,
rec
)
if
err
!=
nil
{
log
.
Debug
(
"failed to unmarshal DHT record from datastore"
)
return
nil
,
err
...
...
@@ -221,7 +216,7 @@ func (dht *IpfsDHT) handlePutValue(ctx context.Context, p peer.ID, pmes *pb.Mess
// returns nil, nil when either nothing is found or the value found doesn't properly validate.
// returns nil, some_error when there's a *datastore* error (i.e., something goes very wrong)
func
(
dht
*
IpfsDHT
)
getRecordFromDatastore
(
dskey
ds
.
Key
)
(
*
recpb
.
Record
,
error
)
{
reci
,
err
:=
dht
.
datastore
.
Get
(
dskey
)
buf
,
err
:=
dht
.
datastore
.
Get
(
dskey
)
if
err
==
ds
.
ErrNotFound
{
return
nil
,
nil
}
...
...
@@ -229,16 +224,8 @@ func (dht *IpfsDHT) getRecordFromDatastore(dskey ds.Key) (*recpb.Record, error)
log
.
Errorf
(
"Got error retrieving record with key %s from datastore: %s"
,
dskey
,
err
)
return
nil
,
err
}
byt
,
ok
:=
reci
.
([]
byte
)
if
!
ok
{
// Bad data in datastore, log it but don't return an error, we'll just overwrite it
log
.
Errorf
(
"Value stored in datastore with key %s is not []byte"
,
dskey
)
return
nil
,
nil
}
rec
:=
new
(
recpb
.
Record
)
err
=
proto
.
Unmarshal
(
b
yt
,
rec
)
err
=
proto
.
Unmarshal
(
b
uf
,
rec
)
if
err
!=
nil
{
// Bad data in datastore, log it but don't return an error, we'll just overwrite it
log
.
Errorf
(
"Bad record data stored in datastore with key %s: could not unmarshal record"
,
dskey
)
...
...
package.json
View file @
366bfd4b
...
...
@@ -42,9 +42,9 @@
},
{
"author"
:
"jbenet"
,
"hash"
:
"Qm
eiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i
"
,
"hash"
:
"Qm
VG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k
"
,
"name"
:
"go-datastore"
,
"version"
:
"
2.4.1
"
"version"
:
"
3.0.0
"
},
{
"author"
:
"hashicorp"
,
...
...
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