// ConnUserid returns the uid that owns the given localhost connection.
// The returned error is ErrNotFound if the connection wasn't found.
167124
func ConnUserid(conn net.Conn) (uid int, err error) {
	return AddrPairUserid(conn.LocalAddr(), conn.RemoteAddr())
}
82688
func (nc *Conn) processErr(ie string) {
	// Trim, remove quotes
	ne := normalizeErr(ie)
	// convert to lower case.
	e := strings.ToLower(ne)

	// FIXME(dlc) - process Slow Consumer signals special.
	if e == STALE_CONNECTION {
		nc.processOpErr(ErrStaleConnection)
	} else if strings.HasPrefix(e, PERMISSIONS_ERR) {
		nc.processPermissionsViolation(ne)
	} else if strings.HasPrefix(e, AUTHORIZATION_ERR) {
		nc.processAuthorizationViolation(ne)
	} else {
		nc.mu.Lock()
		nc.err = errors.New("nats: " + ne)
		nc.mu.Unlock()
		nc.Close()
	}
}
467032
func (p *MysqlProvider) Init(expire int64, connStr string) (err error) {
	p.expire = expire

	p.c, err = sql.Open("mysql", connStr)
	if err != nil {
		return err
	}
	return p.c.Ping()
}
379952
func (nc *Conn) ConnectedServerId() string {
	if nc == nil {
		return _EMPTY_
	}

	nc.mu.RLock()
	defer nc.mu.RUnlock()

	if nc.status != CONNECTED {
		return _EMPTY_
	}
	return nc.info.Id
}
929171
func (v *VPCRouter) VRID() int {
	if v.IsStandardPlan() {
		return -1
	}

	if !v.HasSetting() || v.Settings.Router.VRID == nil {
		return -1
	}

	return *v.Settings.Router.VRID
}
753880
func (u *User) IDForProvider(provider string) string {
	id := u.ProviderCredentials()[provider].Get(common.CredentialsKeyID).Data()
	switch id.(type) {
	case string:
		return id.(string)
	case float64:
		return strconv.FormatFloat(id.(float64), 'f', 0, 64)
	}
	return ""
}
150439
func FnRun(client *docker.Client, containerID, input string) (Stdout *bytes.Buffer, Stderr *bytes.Buffer, err error) {
	err = FnStart(client, containerID)
	if err != nil {
		return
	}

	// attach to write input
	_, err = FnAttach(client, containerID, strings.NewReader(input), nil, nil)
	if err != nil {
		return
	}

	e := FnWaitContainer(client, containerID)
	err = <-e

	stdout := new(bytes.Buffer)
	stderr := new(bytes.Buffer)

	// omit logs because execution error is more important
	_ = FnLogs(client, containerID, stdout, stderr) // nolint

	Stdout = stdout
	Stderr = stderr
	return
}
381527
func NewInitialAEAD(connID protocol.ConnectionID, pers protocol.Perspective) (Sealer, Opener, error) {
	clientSecret, serverSecret := computeSecrets(connID)
	var mySecret, otherSecret []byte
	if pers == protocol.PerspectiveClient {
		mySecret = clientSecret
		otherSecret = serverSecret
	} else {
		mySecret = serverSecret
		otherSecret = clientSecret
	}
	myKey, myHPKey, myIV := computeInitialKeyAndIV(mySecret)
	otherKey, otherHPKey, otherIV := computeInitialKeyAndIV(otherSecret)

	encrypter := qtls.AEADAESGCMTLS13(myKey, myIV)
	hpEncrypter, err := aes.NewCipher(myHPKey)
	if err != nil {
		return nil, nil, err
	}
	decrypter := qtls.AEADAESGCMTLS13(otherKey, otherIV)
	hpDecrypter, err := aes.NewCipher(otherHPKey)
	if err != nil {
		return nil, nil, err
	}
	return newSealer(encrypter, hpEncrypter, false), newOpener(decrypter, hpDecrypter, false), nil
}
415870
func LookupContainerID(id string) *endpoint.Endpoint {
	mutex.RLock()
	ep := lookupContainerID(id)
	mutex.RUnlock()
	return ep
}
1314662
func (p *cniPlugin) doCNIServerAdd(req *cniserver.CNIRequest, hostVeth string) (*current.Result, error) {
	req.HostVeth = hostVeth
	body, err := p.doCNI("http://dummy/", req)
	if err != nil {
		return nil, err
	}

	// We currently expect CNI version 0.3.1 results, because that's the
	// CNIVersion we pass in our config JSON
	result, err := current.NewResult(body)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal response '%s': %v", string(body), err)
	}

	return result.(*current.Result), nil
}
1085527
func UID(numChars int) (uid string, err error) {
	if numChars%4 != 0 {
		err = errors.New("UID length must be a multiple of 4")
		return
	}
	buf := make([]byte, numChars)
	_, err = io.ReadFull(cryptoRand.Reader, buf)
	if err != nil {
		return
	}

	uid = base64.URLEncoding.EncodeToString(buf)
	return
}
349100
func ConnLabel(source, target enode.ID) string {
	var first, second enode.ID
	if bytes.Compare(source.Bytes(), target.Bytes()) > 0 {
		first = target
		second = source
	} else {
		first = source
		second = target
	}
	return fmt.Sprintf("%v-%v", first, second)
}
642137
func getHostID() (hostid string, err error) {
	var mib []C.int = []C.int{ C.CTL_KERN, C.KERN_HOSTID }
	var value C.int64_t = 0
	var length C.size_t = 8
	var unused unsafe.Pointer

	if rc, errno := C.sysctl(&mib[0], 2, unsafe.Pointer(&value), &length, unused, 0); rc == -1 {
		return "", fmt.Errorf("unable to get hostID: errno=%d", errno)
	}

	if uint64(value) > 0 {
		return fmt.Sprintf("%x", uint64(value)), nil
	}

	hostIP, err := getHostIPv4Addr()
	if err != nil {
		return "", err
	}

	var numericIP uint32
	numericIP |= uint32(hostIP[0])
	numericIP |= uint32(hostIP[1]) << 8
	numericIP |= uint32(hostIP[2]) << 16
	numericIP |= uint32(hostIP[3]) << 24

	hostID := uint32(numericIP<<16 | numericIP>>16)
	return fmt.Sprintf("%x", hostID), nil
}
1271814
func (s *EncryptionEntity) SetProviderId(v string) *EncryptionEntity {
	s.ProviderId = &v
	return s
}
462131
func ValidVNID(vnid uint32) error {
	if vnid == GlobalVNID {
		return nil
	}
	if vnid < MinVNID {
		return fmt.Errorf("VNID must be greater than or equal to %d", MinVNID)
	}
	if vnid > MaxVNID {
		return fmt.Errorf("VNID must be less than or equal to %d", MaxVNID)
	}
	return nil
}
834071
func FnFindContainerByID(client *docker.Client, ID string) (container docker.APIContainers, err error) {
	var containers []docker.APIContainers
	containers, err = client.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		return
	}
	for _, v := range containers {
		if v.ID == ID {
			container = v
			return
		}
	}
	err = ErrContainerNotFound
	return
}
38415
func (client *Client) GetServiceInstanceSharedFrom(serviceInstanceGUID string) (ServiceInstanceSharedFrom, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetServiceInstanceSharedFromRequest,
		URIParams:   Params{"service_instance_guid": serviceInstanceGUID},
	})
	if err != nil {
		return ServiceInstanceSharedFrom{}, nil, err
	}

	var serviceInstanceSharedFrom ServiceInstanceSharedFrom
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &serviceInstanceSharedFrom,
	}

	err = client.connection.Make(request, &response)
	return serviceInstanceSharedFrom, response.Warnings, err
}