本文整理汇总了Golang中gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/peer.Peerstore类的典型用法代码示例。如果您正苦于以下问题:Golang Peerstore类的具体用法?Golang Peerstore怎么用?Golang Peerstore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Peerstore类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeRecord
// creates and signs a record for the given key/value pair
func makeRecord(ps peer.Peerstore, p peer.ID, k key.Key, v []byte) (*pb.Record, error) {
blob := bytes.Join([][]byte{[]byte(k), v, []byte(p)}, []byte{})
sig, err := ps.PrivKey(p).Sign(blob)
if err != nil {
return nil, err
}
return &pb.Record{
Key: proto.String(string(k)),
Value: v,
Author: proto.String(string(p)),
Signature: sig,
}, nil
}
示例2: storeProvidersToPeerstore
func storeProvidersToPeerstore(ps peer.Peerstore, p peer.ID, providers []*dhtpb.Message_Peer) {
for _, provider := range providers {
providerID := peer.ID(provider.GetId())
if providerID != p {
log.Errorf("provider message came from third-party %s", p)
continue
}
for _, maddr := range provider.Addresses() {
// as a router, we want to store addresses for peers who have provided
ps.AddAddr(p, maddr, peer.AddressTTL)
}
}
}
示例3: printPeer
func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
if p == "" {
return nil, errors.New("Attempted to print nil peer!")
}
info := new(IdOutput)
info.ID = p.Pretty()
if pk := ps.PubKey(p); pk != nil {
pkb, err := ic.MarshalPublicKey(pk)
if err != nil {
return nil, err
}
info.PublicKey = base64.StdEncoding.EncodeToString(pkb)
}
for _, a := range ps.Addrs(p) {
info.Addresses = append(info.Addresses, a.String())
}
if v, err := ps.Get(p, "ProtocolVersion"); err == nil {
if vs, ok := v.(string); ok {
info.ProtocolVersion = vs
}
}
if v, err := ps.Get(p, "AgentVersion"); err == nil {
if vs, ok := v.(string); ok {
info.AgentVersion = vs
}
}
return info, nil
}
示例4: verify
func verify(ps peer.Peerstore, r *dhtpb.Record) error {
v := make(record.Validator)
v["pk"] = record.PublicKeyValidator
p := peer.ID(r.GetAuthor())
pk := ps.PubKey(p)
if pk == nil {
return fmt.Errorf("do not have public key for %s", p)
}
if err := record.CheckRecordSig(r, pk); err != nil {
return err
}
if err := v.VerifyRecord(r); err != nil {
return err
}
return nil
}