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
d01ee111
Commit
d01ee111
authored
Sep 22, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better parsing logic for dht keys containing prefixes
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
e812abbc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
core/commands/dht.go
core/commands/dht.go
+32
-3
No files found.
core/commands/dht.go
View file @
d01ee111
...
...
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"
key
"github.com/ipfs/go-ipfs/blocks/key"
...
...
@@ -396,6 +397,12 @@ GetValue will return the value stored in the dht at the given key.
events
:=
make
(
chan
*
notif
.
QueryEvent
)
ctx
:=
notif
.
RegisterForQueryEvents
(
req
.
Context
(),
events
)
dhtkey
,
err
:=
escapeDhtKey
(
req
.
Arguments
()[
0
])
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
go
func
()
{
defer
close
(
outChan
)
for
e
:=
range
events
{
...
...
@@ -405,7 +412,7 @@ GetValue will return the value stored in the dht at the given key.
go
func
()
{
defer
close
(
events
)
val
,
err
:=
dht
.
GetValue
(
ctx
,
key
.
B58KeyDecode
(
req
.
Arguments
()[
0
])
)
val
,
err
:=
dht
.
GetValue
(
ctx
,
dht
key
)
if
err
!=
nil
{
notif
.
PublishQueryEvent
(
ctx
,
&
notif
.
QueryEvent
{
Type
:
notif
.
QueryError
,
...
...
@@ -452,7 +459,11 @@ GetValue will return the value stored in the dht at the given key.
fmt
.
Fprintf
(
buf
,
"* querying %s
\n
"
,
obj
.
ID
)
}
case
notif
.
Value
:
fmt
.
Fprintf
(
buf
,
"got value: '%s'
\n
"
,
obj
.
Extra
)
if
verbose
{
fmt
.
Fprintf
(
buf
,
"got value: '%s'
\n
"
,
obj
.
Extra
)
}
else
{
buf
.
WriteString
(
obj
.
Extra
)
}
case
notif
.
QueryError
:
fmt
.
Fprintf
(
buf
,
"error: %s
\n
"
,
obj
.
Extra
)
default
:
...
...
@@ -505,7 +516,12 @@ PutValue will store the given key value pair in the dht.
events
:=
make
(
chan
*
notif
.
QueryEvent
)
ctx
:=
notif
.
RegisterForQueryEvents
(
req
.
Context
(),
events
)
key
:=
key
.
B58KeyDecode
(
req
.
Arguments
()[
0
])
key
,
err
:=
escapeDhtKey
(
req
.
Arguments
()[
0
])
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
data
:=
req
.
Arguments
()[
1
]
go
func
()
{
...
...
@@ -581,3 +597,16 @@ PutValue will store the given key value pair in the dht.
},
Type
:
notif
.
QueryEvent
{},
}
func
escapeDhtKey
(
s
string
)
(
key
.
Key
,
error
)
{
parts
:=
strings
.
Split
(
s
,
"/"
)
switch
len
(
parts
)
{
case
1
:
return
key
.
B58KeyDecode
(
s
),
nil
case
3
:
k
:=
key
.
B58KeyDecode
(
parts
[
2
])
return
key
.
Key
(
strings
.
Join
(
append
(
parts
[
:
2
],
string
(
k
)),
"/"
)),
nil
default
:
return
""
,
errors
.
New
(
"invalid key"
)
}
}
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