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
Commits
dafa140e
Commit
dafa140e
authored
Jan 30, 2018
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
License: MIT Signed-off-by:
Dirk McCormick
<
dirkmdev@gmail.com
>
parent
5e8c9481
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
14 deletions
+19
-14
namesys/ipns_validate_test.go
namesys/ipns_validate_test.go
+1
-1
namesys/selector.go
namesys/selector.go
+15
-13
namesys/validator.go
namesys/validator.go
+3
-0
No files found.
namesys/ipns_validate_test.go
View file @
dafa140e
...
...
@@ -64,7 +64,7 @@ func TestValidation(t *testing.T) {
t
.
Fatal
(
err
)
}
if
resp
!=
p
{
t
.
Fatal
(
"Mismatch between published path %s and resolved path %s"
,
p
,
resp
)
t
.
Fatal
f
(
"Mismatch between published path %s and resolved path %s"
,
p
,
resp
)
}
// Create expired entry
...
...
namesys/selector.go
View file @
dafa140e
...
...
@@ -10,6 +10,8 @@ import (
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
)
// Selects best record by checking which has the highest sequence number
// and latest EOL
func
IpnsSelectorFunc
(
k
string
,
vals
[][]
byte
)
(
int
,
error
)
{
var
recs
[]
*
pb
.
IpnsEntry
for
_
,
v
:=
range
vals
{
...
...
@@ -26,40 +28,40 @@ func IpnsSelectorFunc(k string, vals [][]byte) (int, error) {
}
func
selectRecord
(
recs
[]
*
pb
.
IpnsEntry
,
vals
[][]
byte
)
(
int
,
error
)
{
var
best
_s
eq
uint64
best
_
i
:=
-
1
var
best
S
eq
uint64
besti
:=
-
1
for
i
,
r
:=
range
recs
{
if
r
==
nil
||
r
.
GetSequence
()
<
best
_s
eq
{
if
r
==
nil
||
r
.
GetSequence
()
<
best
S
eq
{
continue
}
if
best
_
i
==
-
1
||
r
.
GetSequence
()
>
best
_s
eq
{
best
_s
eq
=
r
.
GetSequence
()
best
_
i
=
i
}
else
if
r
.
GetSequence
()
==
best
_s
eq
{
if
besti
==
-
1
||
r
.
GetSequence
()
>
best
S
eq
{
best
S
eq
=
r
.
GetSequence
()
besti
=
i
}
else
if
r
.
GetSequence
()
==
best
S
eq
{
rt
,
err
:=
u
.
ParseRFC3339
(
string
(
r
.
GetValidity
()))
if
err
!=
nil
{
continue
}
bestt
,
err
:=
u
.
ParseRFC3339
(
string
(
recs
[
best
_
i
]
.
GetValidity
()))
bestt
,
err
:=
u
.
ParseRFC3339
(
string
(
recs
[
besti
]
.
GetValidity
()))
if
err
!=
nil
{
continue
}
if
rt
.
After
(
bestt
)
{
best
_
i
=
i
besti
=
i
}
else
if
rt
==
bestt
{
if
bytes
.
Compare
(
vals
[
i
],
vals
[
best
_
i
])
>
0
{
best
_
i
=
i
if
bytes
.
Compare
(
vals
[
i
],
vals
[
besti
])
>
0
{
besti
=
i
}
}
}
}
if
best
_
i
==
-
1
{
if
besti
==
-
1
{
return
0
,
errors
.
New
(
"no usable records in given set"
)
}
return
best
_
i
,
nil
return
besti
,
nil
}
namesys/validator.go
View file @
dafa140e
...
...
@@ -29,6 +29,9 @@ var ErrInvalidPath = errors.New("record path invalid")
// signature verification
var
ErrSignature
=
errors
.
New
(
"record signature verification failed"
)
// Returns a ValidChecker for IPNS records
// The validator function will get a public key from the KeyBook
// to verify the record's signature
func
NewIpnsRecordValidator
(
kbook
pstore
.
KeyBook
)
*
record
.
ValidChecker
{
// ValidateIpnsRecord implements ValidatorFunc and verifies that the
// given 'val' is an IpnsEntry and that that entry is valid.
...
...
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