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-kbucket
Commits
2f8828de
Commit
2f8828de
authored
Aug 10, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more work implementing coral type lookups
parent
534dbca4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
util.go
util.go
+18
-2
No files found.
util.go
View file @
2f8828de
...
...
@@ -3,11 +3,16 @@ package dht
import
(
"bytes"
"crypto/sha256"
"errors"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
)
// Returned if a routing table query returns no results. This is NOT expected
// behaviour
var
ErrLookupFailure
=
errors
.
New
(
"failed to find any peer in table"
)
// ID for IpfsDHT should be a byte slice, to allow for simpler operations
// (xor). DHT ids are based on the peer.IDs.
//
...
...
@@ -19,8 +24,8 @@ func (id ID) Equal(other ID) bool {
return
bytes
.
Equal
(
id
,
other
)
}
func
(
id
ID
)
Less
(
other
interface
{}
)
bool
{
a
,
b
:=
equalizeSizes
(
id
,
other
.
(
ID
)
)
func
(
id
ID
)
Less
(
other
ID
)
bool
{
a
,
b
:=
equalizeSizes
(
id
,
other
)
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
if
a
[
i
]
!=
b
[
i
]
{
return
a
[
i
]
<
b
[
i
]
...
...
@@ -80,3 +85,14 @@ func ConvertKey(id u.Key) ID {
hash
:=
sha256
.
Sum256
([]
byte
(
id
))
return
hash
[
:
]
}
// Returns true if a is closer to key than b is
func
Closer
(
a
,
b
peer
.
ID
,
key
u
.
Key
)
bool
{
aid
:=
ConvertPeerID
(
a
)
bid
:=
ConvertPeerID
(
b
)
tgt
:=
ConvertKey
(
key
)
adist
:=
xor
(
aid
,
tgt
)
bdist
:=
xor
(
bid
,
tgt
)
return
adist
.
Less
(
bdist
)
}
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