// TCPAddrFromMultiAddr converts a multiaddress to a string representation of a tcp address.
TCPAddrFromMultiAddr converts a multiaddress to a string representation of a tcp address.
// TCPAddrFromMultiAddr converts a multiaddress to a string representation of a tcp address .
func TCPAddrFromMultiAddr(maddr ma.Multiaddr) (string, error) {
	if maddr == nil {
		return "", fmt.Errorf("invalid address")
	}
	var ip string
	if _, err := maddr.ValueForProtocol(ma.P_DNS4); err == nil {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()
		maddrs, err := dns.Resolve(ctx, maddr)
		if err != nil {
			return "", fmt.Errorf("resolving dns: %s", err)
		}
		for _, m := range maddrs {
			if ip, err = getIPFromMaddr(m); err == nil {
				break
			}
		}
	} else {
		ip, err = getIPFromMaddr(maddr)
		if err != nil {
			return "", fmt.Errorf("getting ip from maddr: %s", err)
		}
	}
	tcp, err := maddr.ValueForProtocol(ma.P_TCP)
	if err != nil {
		return "", fmt.Errorf("getting port from maddr: %s", err)
	}
	return fmt.Sprintf("%s:%s", ip, tcp), nil
}
func TCPAddrFromMultiAddr ( maddr ma . Multiaddr ) ( string , error ) { if maddr == nil { return " " , fmt . Errorf ( " " ) } var ip string if _ , err := maddr . ValueForProtocol ( ma . P_DNS4 ) ; err == nil { ctx , cancel := context . WithTimeout ( context . Background ( ) , time . Second ) defer cancel ( ) maddrs , err := dns . Resolve ( ctx , maddr ) if err != nil { return " " , fmt . Errorf ( " " , err ) } for _ , m := range maddrs { if ip , err = getIPFromMaddr ( m ) ; err == nil { break } } } else { ip , err = getIPFromMaddr ( maddr ) if err != nil { return " " , fmt . Errorf ( " " , err ) } } tcp , err := maddr . ValueForProtocol ( ma . P_TCP ) if err != nil { return " " , fmt . Errorf ( " " , err ) } return fmt . Sprintf ( " " , ip , tcp ) , nil }
TCPAddrFromMultiAddr converts a multiaddress to a string representation of a tcp address.
TCPAddrFromMultiAddr converts a multiaddress to a string representation of a tcp address .