示例#1
0
文件: peers.go 项目: mappum/go-ipfs
func Peers(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
	enc := json.NewEncoder(out)
	peers := make([]peerInfo, len(*n.PeerMap))

	for i, p := range *n.PeerMap {
		addrs := make([]string, len(p.Addresses))
		for j, addr := range p.Addresses {
			addrStr, err := addr.String()
			if err != nil {
				return err
			}
			addrs[j] = addrStr
		}

		pubkeyBytes, err := p.PubKey.Bytes()
		if err != nil {
			return err
		}

		peer := peerInfo{
			ID:        p.ID.Pretty(),
			Addresses: addrs,
			PubKey:    b58.Encode(pubkeyBytes),
			Latency:   p.GetLatency().Nanoseconds(),
		}
		peers[i] = peer
	}

	enc.Encode(peers)

	return nil
}
示例#2
0
func (m Multihash) B58String() string {
	return b58.Encode([]byte(m))
}
示例#3
0
文件: util.go 项目: mappum/go-ipfs
func (k Key) Pretty() string {
	return b58.Encode([]byte(k))
}
示例#4
0
文件: peer.go 项目: mappum/go-ipfs
func (id ID) Pretty() string {
	return b58.Encode(id)
}