本文整理汇总了Golang中github.com/ipfs/go-ipfs/p2p/peer.IDB58Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang IDB58Decode函数的具体用法?Golang IDB58Decode怎么用?Golang IDB58Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IDB58Decode函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ParseMultiaddr
// ParseMultiaddr parses a multiaddr into an IPFSAddr
func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) {
// never panic.
defer func() {
if r := recover(); r != nil {
log.Debug("recovered from panic: ", r)
a = nil
err = ErrInvalidAddr
}
}()
if m == nil {
return nil, ErrInvalidAddr
}
// make sure it's an ipfs addr
parts := ma.Split(m)
if len(parts) < 1 {
return nil, ErrInvalidAddr
}
ipfspart := parts[len(parts)-1] // last part
if ipfspart.Protocols()[0].Code != ma.P_IPFS {
return nil, ErrInvalidAddr
}
// make sure ipfs id parses as a peer.ID
peerIdParts := strings.Split(ipfspart.String(), "/")
peerIdStr := peerIdParts[len(peerIdParts)-1]
id, err := peer.IDB58Decode(peerIdStr)
if err != nil {
return nil, err
}
return ipfsAddr{ma: m, id: id}, nil
}
开发者ID:rdterner,项目名称:go-ipfs,代码行数:35,代码来源:ipfsaddr.go
示例2: handleEntry
func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
mpeer, err := peer.IDB58Decode(e.Info)
if err != nil {
log.Warning("Error parsing peer ID from mdns entry: ", err)
return
}
if mpeer == m.host.ID() {
return
}
maddr, err := manet.FromNetAddr(&net.TCPAddr{
IP: e.AddrV4,
Port: e.Port,
})
if err != nil {
log.Warning("Error parsing multiaddr from mdns entry: ", err)
return
}
pi := peer.PeerInfo{
ID: mpeer,
Addrs: []ma.Multiaddr{maddr},
}
m.lk.Lock()
for _, n := range m.notifees {
n.HandlePeerFound(pi)
}
m.lk.Unlock()
}
开发者ID:JeffreyRodriguez,项目名称:go-ipfs,代码行数:31,代码来源:mdns.go
示例3: Connect
//Connect to a peer at an address and add the connection
func (s *Service) Connect(address string) {
target, err := peer.IDB58Decode(address)
if err != nil {
fmt.Printf("IDB58 error: %s\n ", err)
return
}
fmt.Printf("I am peer %s dialing %s\n", s.node.Identity.Pretty(), target.Pretty())
con, err := corenet.Dial(s.node, target, s.name)
if err != nil {
fmt.Println(err)
return
}
if s.connections == nil {
s.connections = make(map[string]connection)
}
key := con.Conn().RemotePeer().Pretty()
s.connections[key] = connection{con, &sync.RWMutex{}, make(chan []byte), make(chan []byte), make(chan bool)}
go s.handleCon(s.connections[key])
defer func() {
delete(s.connections, key)
con.Close()
}()
}
开发者ID:vijayee,项目名称:Account,代码行数:26,代码来源:ipfs.go
示例4: New
//New returns new Peer obj from B58 decoded str.
func New(idstr string, my *Self) (*Peer, error) {
id, err := peer.IDB58Decode(idstr)
if log.If(err) {
return nil, err
}
return &Peer{
ID: id,
myself: my,
}, nil
}
开发者ID:utamaro,项目名称:core,代码行数:11,代码来源:peer.go
示例5: ParsePeerParam
func ParsePeerParam(text string) (ma.Multiaddr, peer.ID, error) {
// to be replaced with just multiaddr parsing, once ptp is a multiaddr protocol
idx := strings.LastIndex(text, "/")
if idx == -1 {
pid, err := peer.IDB58Decode(text)
if err != nil {
return nil, "", err
}
return nil, pid, nil
}
addrS := text[:idx]
peeridS := text[idx+1:]
var maddr ma.Multiaddr
var pid peer.ID
// make sure addrS parses as a multiaddr.
if len(addrS) > 0 {
var err error
maddr, err = ma.NewMultiaddr(addrS)
if err != nil {
return nil, "", err
}
}
// make sure idS parses as a peer.ID
var err error
pid, err = peer.IDB58Decode(peeridS)
if err != nil {
return nil, "", err
}
return maddr, pid, nil
}
开发者ID:thomas-gardner,项目名称:go-ipfs,代码行数:36,代码来源:ping.go
示例6: TestIDMatches
func TestIDMatches(t *testing.T) {
for _, g := range good {
a, err := ParseString(g)
if err != nil {
t.Error("failed to parse", g, err)
continue
}
sp := strings.Split(g, "/")
sid := sp[len(sp)-1]
id, err := peer.IDB58Decode(sid)
if err != nil {
t.Error("failed to parse", sid, err)
continue
}
if a.ID() != id {
t.Error("not equal", a.ID(), id)
}
}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:21,代码来源:ipfsaddr_test.go
示例7: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please give a peer ID as an argument")
return
}
target, err := peer.IDB58Decode(os.Args[1])
if err != nil {
panic(err)
}
// Basic ipfsnode setup
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
nd, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
fmt.Printf("I am peer %s dialing %s\n", nd.Identity, target)
con, err := corenet.Dial(nd, target, "/app/whyrusleeping")
if err != nil {
fmt.Println(err)
return
}
io.Copy(os.Stdout, con)
}
开发者ID:f3r,项目名称:examples,代码行数:40,代码来源:client.go
示例8: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please give a peer ID as an argument")
return
}
target, err := peer.IDB58Decode(os.Args[1])
if err != nil {
panic(err)
}
// Basic ipfsnode setup
r := fsrepo.At("~/.ipfs")
if err := r.Open(); err != nil {
panic(err)
}
nb := core.NewNodeBuilder().Online()
nb.SetRepo(r)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nd, err := nb.Build(ctx)
if err != nil {
panic(err)
}
fmt.Printf("I am peer %s dialing %s\n", nd.Identity, target)
con, err := corenet.Dial(nd, target, "/app/whyrusleeping")
if err != nil {
fmt.Println(err)
return
}
io.Copy(os.Stdout, con)
}
开发者ID:jchown,项目名称:abe,代码行数:38,代码来源:client.go
示例9: UnmarshalJSON
func (qe *QueryEvent) UnmarshalJSON(b []byte) error {
temp := struct {
ID string
Type int
Responses []*peer.PeerInfo
Extra string
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
if len(temp.ID) > 0 {
pid, err := peer.IDB58Decode(temp.ID)
if err != nil {
return err
}
qe.ID = pid
}
qe.Type = QueryEventType(temp.Type)
qe.Responses = temp.Responses
qe.Extra = temp.Extra
return nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:23,代码来源:query.go
示例10:
cmds.StringArg("peerID", true, true, "The peer to search for"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
dht, ok := n.Routing.(*ipdht.IpfsDHT)
if !ok {
res.SetError(ErrNotDHT, cmds.ErrNormal)
return
}
pid, err := peer.IDB58Decode(req.Arguments()[0])
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
outChan := make(chan interface{})
res.SetOutput((<-chan interface{})(outChan))
events := make(chan *notif.QueryEvent)
ctx := notif.RegisterForQueryEvents(req.Context(), events)
go func() {
defer close(outChan)
for v := range events {
outChan <- v
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:31,代码来源:dht.go
示例11:
return
}
bs, ok := nd.Exchange.(*bitswap.Bitswap)
if !ok {
res.SetError(u.ErrCast(), cmds.ErrNormal)
return
}
pstr, found, err := req.Option("peer").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if found {
pid, err := peer.IDB58Decode(pstr)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(&KeyList{bs.WantlistForPeer(pid)})
} else {
res.SetOutput(&KeyList{bs.GetWantlist()})
}
},
Marshalers: cmds.MarshalerMap{
cmds.Text: KeyListTextMarshaler,
},
}
var bitswapStatCmd = &cmds.Command{
开发者ID:riversparks,项目名称:go-ipfs,代码行数:31,代码来源:bitswap.go
注:本文中的github.com/ipfs/go-ipfs/p2p/peer.IDB58Decode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论