Пример #1
0
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
func (k Key) Pretty() string {
	return b58.Encode([]byte(k))
}
Пример #4
0
func (id ID) Pretty() string {
	return b58.Encode(id)
}