本文整理汇总了Golang中github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr.Split函数的典型用法代码示例。如果您正苦于以下问题:Golang Split函数的具体用法?Golang Split怎么用?Golang Split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Split函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pickLocalAddr
func pickLocalAddr(laddrs []ma.Multiaddr, raddr ma.Multiaddr) (laddr ma.Multiaddr) {
if len(laddrs) < 1 {
return nil
}
// make sure that we ONLY use local addrs that match the remote addr.
laddrs = manet.AddrMatch(raddr, laddrs)
if len(laddrs) < 1 {
return nil
}
// make sure that we ONLY use local addrs that CAN dial the remote addr.
// filter out all the local addrs that aren't capable
raddrIPLayer := ma.Split(raddr)[0]
raddrIsLoopback := manet.IsIPLoopback(raddrIPLayer)
raddrIsLinkLocal := manet.IsIP6LinkLocal(raddrIPLayer)
laddrs = addrutil.FilterAddrs(laddrs, func(a ma.Multiaddr) bool {
laddrIPLayer := ma.Split(a)[0]
laddrIsLoopback := manet.IsIPLoopback(laddrIPLayer)
laddrIsLinkLocal := manet.IsIP6LinkLocal(laddrIPLayer)
if laddrIsLoopback { // our loopback addrs can only dial loopbacks.
return raddrIsLoopback
}
if laddrIsLinkLocal {
return raddrIsLinkLocal // out linklocal addrs can only dial link locals.
}
return true
})
// TODO pick with a good heuristic
// we use a random one for now to prevent bad addresses from making nodes unreachable
// with a random selection, multiple tries may work.
return laddrs[rand.Intn(len(laddrs))]
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:34,代码来源:dial.go
示例2: ResolveUnspecifiedAddress
// ResolveUnspecifiedAddress expands an unspecified ip addresses (/ip4/0.0.0.0, /ip6/::) to
// use the known local interfaces. If ifaceAddr is nil, we request interface addresses
// from the network stack. (this is so you can provide a cached value if resolving many addrs)
func ResolveUnspecifiedAddress(resolve ma.Multiaddr, ifaceAddrs []ma.Multiaddr) ([]ma.Multiaddr, error) {
// split address into its components
split := ma.Split(resolve)
// if first component (ip) is not unspecified, use it as is.
if !manet.IsIPUnspecified(split[0]) {
return []ma.Multiaddr{resolve}, nil
}
out := make([]ma.Multiaddr, 0, len(ifaceAddrs))
for _, ia := range ifaceAddrs {
// must match the first protocol to be resolve.
if ia.Protocols()[0].Code != resolve.Protocols()[0].Code {
continue
}
split[0] = ia
joined := ma.Join(split...)
out = append(out, joined)
log.Debug("adding resolved addr:", resolve, joined, out)
}
if len(out) < 1 {
return nil, fmt.Errorf("failed to resolve: %s", resolve)
}
return out, nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:29,代码来源:addr.go
示例3: 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
示例4: AddrOverNonLocalIP
// AddrOverNonLocalIP returns whether the addr uses a non-local ip link
func AddrOverNonLocalIP(a ma.Multiaddr) bool {
split := ma.Split(a)
if len(split) < 1 {
return false
}
if manet.IsIP6LinkLocal(split[0]) {
return false
}
return true
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:11,代码来源:addr.go
示例5: AddrIsShareableOnWAN
// AddrIsShareableOnWAN returns whether the given address should be shareable on the
// wide area network (wide internet).
func AddrIsShareableOnWAN(addr ma.Multiaddr) bool {
s := ma.Split(addr)
if len(s) < 1 {
return false
}
a := s[0]
if manet.IsIPLoopback(a) || manet.IsIP6LinkLocal(a) || manet.IsIPUnspecified(a) {
return false
}
return manet.IsThinWaist(a)
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:13,代码来源:addr.go
示例6: toPeerInfo
func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
// for now, we drop the "ipfs addr" part of the multiaddr. the rest
// of the codebase currently uses addresses without the peerid part.
m := bp.Multiaddr()
s := ma.Split(m)
m = ma.Join(s[:len(s)-1]...)
return peer.PeerInfo{
ID: bp.ID(),
Addrs: []ma.Multiaddr{m},
}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:12,代码来源:bootstrap.go
示例7: TestTransport
func TestTransport(t *testing.T) {
for _, g := range good {
a, err := ParseString(g)
if err != nil {
t.Error("failed to parse", g, err)
continue
}
m := newMultiaddr(t, g)
split := ma.Split(m)
m = ma.Join(split[:len(split)-1]...)
if a.Multiaddr().Equal(m) {
t.Error("should not be equal", a.Multiaddr(), m)
}
if !Transport(a).Equal(m) {
t.Error("should be equal", Transport(a), m)
}
}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:19,代码来源:ipfsaddr_test.go
示例8: observerGroup
// observerGroup is a function that determines what part of
// a multiaddr counts as a different observer. for example,
// two ipfs nodes at the same IP/TCP transport would get
// the exact same NAT mapping; they would count as the
// same observer. This may protect against NATs who assign
// different ports to addresses at different IP hosts, but
// not TCP ports.
//
// Here, we use the root multiaddr address. This is mostly
// IP addresses. In practice, this is what we want.
func observerGroup(m ma.Multiaddr) string {
return ma.Split(m)[0].String()
}
开发者ID:wemeetagain,项目名称:go-libp2p,代码行数:13,代码来源:obsaddr.go
示例9: Transport
func Transport(iaddr IPFSAddr) (maddr ma.Multiaddr) {
maddr = iaddr.Multiaddr()
split := ma.Split(maddr)
maddr = ma.Join(split[:len(split)-1]...)
return
}
开发者ID:rdterner,项目名称:go-ipfs,代码行数:6,代码来源:ipfsaddr.go
注:本文中的github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr.Split函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论