Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
bb4ad449
Commit
bb4ad449
authored
Jan 22, 2015
by
Jeromy
Browse files
really ugly impl of 'ipfs dht query' command
parent
b20f767e
Changes
1
Show whitespace changes
Inline
Side-by-side
peer/peer.go
View file @
bb4ad449
...
...
@@ -3,6 +3,7 @@ package peer
import
(
"encoding/hex"
"encoding/json"
"fmt"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
...
...
@@ -131,6 +132,35 @@ type PeerInfo struct {
Addrs
[]
ma
.
Multiaddr
}
func
(
pi
*
PeerInfo
)
MarshalJSON
()
([]
byte
,
error
)
{
out
:=
make
(
map
[
string
]
interface
{})
out
[
"ID"
]
=
IDB58Encode
(
pi
.
ID
)
var
addrs
[]
string
for
_
,
a
:=
range
pi
.
Addrs
{
addrs
=
append
(
addrs
,
a
.
String
())
}
out
[
"Addrs"
]
=
addrs
return
json
.
Marshal
(
out
)
}
func
(
pi
*
PeerInfo
)
UnmarshalJSON
(
b
[]
byte
)
error
{
var
data
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
b
,
&
data
)
if
err
!=
nil
{
return
err
}
pid
,
err
:=
IDB58Decode
(
data
[
"ID"
]
.
(
string
))
if
err
!=
nil
{
return
err
}
pi
.
ID
=
pid
addrs
:=
data
[
"Addrs"
]
.
([]
interface
{})
for
_
,
a
:=
range
addrs
{
pi
.
Addrs
=
append
(
pi
.
Addrs
,
ma
.
StringCast
(
a
.
(
string
)))
}
return
nil
}
// IDSlice for sorting peers
type
IDSlice
[]
ID
...
...
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