// doDial is an ugly shim method to retain all the logging and backoff logic
// of the old dialsync code
184101
func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) {
	// Short circuit.
	// By the time we take the dial lock, we may already *have* a connection
	// to the peer.
	c := s.bestConnToPeer(p)
	if c != nil {
		return c, nil
	}

	logdial := lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil)

	// ok, we have been charged to dial! let's do it.
	// if it succeeds, dial will add the conn to the swarm itself.
	defer log.EventBegin(ctx, "swarmDialAttemptStart", logdial).Done()

	conn, err := s.dial(ctx, p)
	if err != nil {
		conn = s.bestConnToPeer(p)
		if conn != nil {
			// Hm? What error?
			// Could have canceled the dial because we received a
			// connection or some other random reason.
			// Just ignore the error and return the connection.
			log.Debugf("ignoring dial error because we have a connection: %s", err)
			return conn, nil
		}
		if err != context.Canceled {
			log.Event(ctx, "swarmDialBackoffAdd", logdial)
			s.backf.AddBackoff(p) // let others know to backoff
		}

		// ok, we failed.
		return nil, err
	}
	return conn, nil
}
1267885
func (h *Handle) XfrmPolicyDel(policy *XfrmPolicy) error {
	_, err := h.xfrmPolicyGetOrDelete(policy, nl.XFRM_MSG_DELPOLICY)
	return err
}
1134488
func (d *GrovePiDriver) readDigital(pin byte) (val int, err error) {
	buf := []byte{CommandReadDigital, pin, 0, 0}
	_, err = d.connection.Write(buf)
	if err != nil {
		return
	}

	time.Sleep(2 * time.Millisecond)

	data := make([]byte, 2)
	_, err = d.connection.Read(data)
	if err != nil || data[0] != CommandReadDigital {
		return 0, err
	}

	return int(data[1]), err
}
159619
func MkdirAll(dirpath string) error {
	// TODO: am I swallowing err?
	if _, err := os.Stat(dirpath); os.IsNotExist(err) {
		return os.MkdirAll(dirpath, os.ModeDir|0700)
	}
	return nil
}
1231013
func (bee *Bee) LogFatal(args ...interface{}) {
	a := []interface{}{"[" + bee.Name() + "]:"}
	for _, v := range args {
		a = append(a, v)
	}
	log.Panicln(a...)
	Log(bee.Name(), fmt.Sprintln(args...), 2)
}
871737
func (bl *BeeLogger) Informational(format string, v ...interface{}) {
	if LevelInformational > bl.level {
		return
	}
	msg := fmt.Sprintf("[I] "+format, v...)
	bl.writerMsg(LevelInformational, msg)
}
1255588
func OptDialerTimeout(d time.Duration) Option {
	return func(h *HCI) error {
		h.dialerTmo = d
		return nil
	}
}
425452
func (a *Autopilot) MinRaftProtocol() (int, error) {
	return minRaftProtocol(a.delegate.Serf().Members(), a.delegate.IsServer)
}
1232408
func TTL(secsFromCitrusLeafEpoc uint32) uint32 {
	switch secsFromCitrusLeafEpoc {
	// don't convert magic values
	case 0: // when set to don't expire, this value is returned
		return math.MaxUint32
	default:
		// Record may not have expired on server, but delay or clock differences may
		// cause it to look expired on client. Floor at 1, not 0, to avoid old
		// "never expires" interpretation.
		now := time.Now().Unix()
		expiration := int64(CITRUSLEAF_EPOCH + secsFromCitrusLeafEpoc)
		if expiration < 0 || expiration > now {
			return uint32(expiration - now)
		}
		return 1
	}
}
584434
func (h *Handle) QdiscDel(qdisc Qdisc) error {
	return h.qdiscModify(unix.RTM_DELQDISC, 0, qdisc)
}
478497
func TouchDirAll(dir string) error {
	err := os.MkdirAll(dir, privateDirMode)
	if err != nil && err != os.ErrExist {
		return err
	}
	return IsDirWriteable(dir)
}
1198346
func (l *Slog) Di() *Slog {
	l = l.copy()
	l.Log.DoDi = true
	return l
}
1071701
func (s *TableStatistics) SetDdls(v int64) *TableStatistics {
	s.Ddls = &v
	return s
}
1297971
func TTL(d time.Duration) Option {
	return func(c Cache) error {
		switch oc := c.(type) {
		case *cache:
			oc.ttl = d
			return nil
		default:
			return errors.New(ErrIllegalCache, errorMessages)
		}
	}
}
433028
func (r Network_LBaaS_Listener) DeleteLoadBalancerProtocols(loadBalancerUuid *string, listenerUuids []string) (resp datatypes.Network_LBaaS_LoadBalancer, err error) {
	params := []interface{}{
		loadBalancerUuid,
		listenerUuids,
	}
	err = r.Session.DoRequest("SoftLayer_Network_LBaaS_Listener", "deleteLoadBalancerProtocols", params, &r.Options, &resp)
	return
}
1166285
func OptServerDataDir(dir string) ServerOption {
	return func(s *Server) error {
		s.dataDir = dir
		return nil
	}
}
620024
func chooseDelay(prevSleepCount uint) (d time.Duration) {
	const baseDelay = time.Millisecond

	// Choose a a delay in [0, 2^prevSleepCount * baseDelay).
	d = (1 << prevSleepCount) * baseDelay
	d = time.Duration(rand.Int63n(int64(d)))

	return
}