// serviceAddress returns the address of the service
// managing the pods in which the unit workload is running.
550967
func (u *Unit) serviceAddress(scope string) (network.Address, error) {
	addresses, err := u.AllAddresses()
	if err != nil {
		return network.Address{}, errors.Trace(err)
	}
	if len(addresses) == 0 {
		return network.Address{}, network.NoAddressError(scope)
	}

	getStrictPublicAddr := func(addresses []network.Address) (network.Address, bool) {
		addr, ok := network.SelectPublicAddress(addresses)
		ok = ok && addr.Scope == network.ScopePublic
		return addr, ok
	}

	getInternalAddr := func(addresses []network.Address) (network.Address, bool) {
		return network.SelectInternalAddress(addresses, false)
	}

	var addrMatch func([]network.Address) (network.Address, bool)
	switch scope {
	case "public":
		addrMatch = getStrictPublicAddr
	case "private":
		addrMatch = getInternalAddr
	default:
		return network.Address{}, errors.NotValidf("address scope %q", scope)
	}

	addr, found := addrMatch(addresses)
	if !found {
		return network.Address{}, network.NoAddressError(scope)
	}
	return addr, nil
}
403916
func (m *Machine) ProviderAddresses() ([]network.Address, error) {
	var results params.MachineAddressesResults
	args := params.Entities{Entities: []params.Entity{
		{Tag: m.tag.String()},
	}}
	err := m.facade.FacadeCall("ProviderAddresses", args, &results)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if len(results.Results) != 1 {
		err := errors.Errorf("expected 1 result, got %d", len(results.Results))
		return nil, err
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	return params.NetworkAddresses(result.Addresses...), nil
}
585175
func (a *NetAddr) FullAddress() string {
	return fmt.Sprintf("%v://%v", a.AddrNetwork, a.Addr)
}
1217254
func (c *Cluster) GetAdvertiseAddress() string {
	c.mu.RLock()
	defer c.mu.RUnlock()
	if c.nr != nil && c.nr.config.AdvertiseAddr != "" {
		advertiseHost, _, _ := net.SplitHostPort(c.nr.config.AdvertiseAddr)
		return advertiseHost
	}
	return c.currentNodeState().actualLocalAddr
}
1123234
func (addr *address) networkAddress() network.Address {
	return network.Address{
		Value:     addr.Value,
		Type:      network.AddressType(addr.AddressType),
		Scope:     network.Scope(addr.Scope),
		SpaceName: network.SpaceName(addr.SpaceName),
	}
}
1191165
func (u *Unit) AllAddresses() ([]network.Address, error) {
	if u.ShouldBeAssigned() {
		return nil, nil
	}
	// First the addresses of the service.
	app, err := u.Application()
	if err != nil {
		return nil, errors.Trace(err)
	}
	serviceInfo, err := app.ServiceInfo()
	if errors.IsNotFound(err) {
		return nil, nil
	}
	if err != nil {
		return nil, errors.Trace(err)
	}
	addresses := serviceInfo.Addresses()

	// Second the address of the container.
	addr, err := u.containerAddress()
	if network.IsNoAddressError(err) {
		return addresses, nil
	}
	if err != nil {
		return nil, errors.Trace(err)
	}
	addresses = append(addresses, addr)
	return addresses, nil
}
714441
func (r *RegisterMonitor) serviceID() string {
	id := fmt.Sprintf("%s-proxy", r.Service)
	if r.IDSuffix != "" {
		id += "-" + r.IDSuffix
	}

	return id
}
152210
func (d *DNSServer) serviceLookup(cfg *dnsConfig, network, datacenter, service, tag string, connect bool, req, resp *dns.Msg, maxRecursionLevel int) {
	out, err := d.lookupServiceNodes(cfg, datacenter, service, tag, connect, maxRecursionLevel)
	if err != nil {
		d.logger.Printf("[ERR] dns: rpc error: %v", err)
		resp.SetRcode(req, dns.RcodeServerFailure)
		return
	}

	// If we have no nodes, return not found!
	if len(out.Nodes) == 0 {
		d.addSOA(cfg, resp)
		resp.SetRcode(req, dns.RcodeNameError)
		return
	}

	// Perform a random shuffle
	out.Nodes.Shuffle()

	// Determine the TTL
	ttl, _ := cfg.GetTTLForService(service)

	// Add various responses depending on the request
	qType := req.Question[0].Qtype
	if qType == dns.TypeSRV {
		d.serviceSRVRecords(cfg, datacenter, out.Nodes, req, resp, ttl, maxRecursionLevel)
	} else {
		d.serviceNodeRecords(cfg, datacenter, out.Nodes, req, resp, ttl, maxRecursionLevel)
	}

	d.trimDNSResponse(cfg, network, req, resp)

	// If the answer is empty and the response isn't truncated, return not found
	if len(resp.Answer) == 0 && !resp.Truncated {
		d.addSOA(cfg, resp)
		return
	}
}
440701
func GetByAddress(c context.Context, client *v1.Service, address string) (*Build, error) {
	msg, err := v1.GetByAddress(c, client, address)
	if err != nil {
		return nil, err
	}

	var build Build
	err = build.ParseMessage(msg)
	return &build, err
}
689475
func (se *ServiceEndpoint) GetAssignment() *addressassignment.AddressAssignment {
	if se.AddressAssignment.ID == "" {
		return nil
	}
	//return reference to copy
	result := se.AddressAssignment
	return &result
}
84284
func (ipv6 IPv6Addr) NetworkAddress() IPv6Network {
	addr := new(big.Int)
	addr.SetBytes((*ipv6.Address).Bytes())

	mask := new(big.Int)
	mask.SetBytes(*ipv6.NetIPMask())

	netAddr := new(big.Int)
	netAddr.And(addr, mask)

	return IPv6Network(netAddr)
}
933025
func GetAddress() Addresser {
	mu.Lock()
	defer mu.Unlock()

	if address == nil {
		address = &Address{}
	}
	return address
}
953410
func (p *Service) SanitizedAddress() (sanitizedAddress string, err error) {
	var (
		canonicalizedAddress string
	)

	if p.Outputaddress != "" {
		return p.Outputaddress, nil
	}

	if strings.HasPrefix(p.Address, "postgres://") || strings.HasPrefix(p.Address, "postgresql://") {
		if canonicalizedAddress, err = parseURL(p.Address); err != nil {
			return sanitizedAddress, err
		}
	} else {
		canonicalizedAddress = p.Address
	}

	sanitizedAddress = kvMatcher.ReplaceAllString(canonicalizedAddress, "")

	return sanitizedAddress, err
}
1123068
func (s *ServiceRecord) ServiceName() string {
	if s.serviceName == "" {
		s.serviceName = fmt.Sprintf("%s.%s.", trimDot(s.Service), trimDot(s.Domain))
	}
	return s.serviceName
}
900203
func (n *NIC) AddAddress(protocol tcpip.NetworkProtocolNumber, addr tcpip.Address) *tcpip.Error {
	return n.AddAddressWithOptions(protocol, addr, CanBePrimaryEndpoint)
}
361064
func (r Network_Storage_MassDataMigration_Request) GetAddress() (resp datatypes.Account_Address, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Storage_MassDataMigration_Request", "getAddress", nil, &r.Options, &resp)
	return
}
783499
func serviceKey2L3n4Addr(svcKey ServiceKey) *loadbalancer.L3n4Addr {
	log.WithField(logfields.ServiceID, svcKey).Debug("creating L3n4Addr for ServiceKey")
	var (
		feIP   net.IP
		fePort uint16
	)
	if svcKey.IsIPv6() {
		svc6Key := svcKey.(*Service6Key)
		feIP = svc6Key.Address.IP()
		fePort = svc6Key.Port
	} else {
		svc4Key := svcKey.(*Service4Key)
		feIP = svc4Key.Address.IP()
		fePort = svc4Key.Port
	}
	return loadbalancer.NewL3n4Addr(loadbalancer.NONE, feIP, fePort)
}