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
a3cdab1e
Commit
a3cdab1e
authored
Nov 20, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return sentinel error for invalid records
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
0df847e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
13 deletions
+20
-13
dht.go
dht.go
+5
-3
routing.go
routing.go
+15
-10
No files found.
dht.go
View file @
a3cdab1e
...
...
@@ -150,6 +150,8 @@ func (dht *IpfsDHT) putProvider(ctx context.Context, p peer.ID, skey string) err
return
nil
}
var
errInvalidRecord
=
errors
.
New
(
"received invalid record"
)
// getValueOrPeers queries a particular peer p for the value for
// key. It returns either the value or a list of closer peers.
// NOTE: it will update the dht's peerstore with any new addresses
...
...
@@ -173,11 +175,11 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID,
err
=
dht
.
verifyRecordOnline
(
ctx
,
record
)
if
err
!=
nil
{
log
.
Info
(
"Received invalid record! (discarded)"
)
//
still
return a
non-nil record to signify that we
received
// a bad record from this peer
// return a
sentinal to signify an invalid record was
received
err
=
errInvalidRecord
record
=
new
(
pb
.
Record
)
}
return
record
,
peers
,
nil
return
record
,
peers
,
err
}
if
len
(
peers
)
>
0
{
...
...
routing.go
View file @
a3cdab1e
...
...
@@ -171,21 +171,26 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key key.Key, nvals int) ([]ro
})
rec
,
peers
,
err
:=
dht
.
getValueOrPeers
(
ctx
,
p
,
key
)
if
err
!=
nil
{
if
err
==
routing
.
ErrNotFound
{
// in this case, they responded with nothing,
// still send a notification
notif
.
PublishQueryEvent
(
parent
,
&
notif
.
QueryEvent
{
Type
:
notif
.
PeerResponse
,
ID
:
p
,
})
}
switch
err
{
case
routing
.
ErrNotFound
:
// in this case, they responded with nothing,
// still send a notification so listeners can know the
// request has completed 'successfully'
notif
.
PublishQueryEvent
(
parent
,
&
notif
.
QueryEvent
{
Type
:
notif
.
PeerResponse
,
ID
:
p
,
})
return
nil
,
err
default
:
return
nil
,
err
case
nil
,
errInvalidRecord
:
// in either of these cases, we want to keep going
}
res
:=
&
dhtQueryResult
{
closerPeers
:
peers
}
if
rec
.
GetValue
()
!=
nil
{
if
rec
.
GetValue
()
!=
nil
||
err
==
errInvalidRecord
{
rv
:=
routing
.
RecvdVal
{
Val
:
rec
.
GetValue
(),
From
:
p
,
...
...
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