+ return resp, nil
+}
+
+func parseStorageClassesConfirmedHeader(hdr string) (map[string]int, error) {
+ if hdr == "" {
+ return nil, nil
+ }
+ classesStored := map[string]int{}
+ for _, cr := range strings.Split(hdr, ",") {
+ cr = strings.TrimSpace(cr)
+ if cr == "" {
+ continue
+ }
+ fields := strings.SplitN(cr, "=", 2)
+ if len(fields) != 2 {
+ return nil, fmt.Errorf("expected exactly one '=' char in entry %q", cr)
+ }
+ className := fields[0]
+ if className == "" {
+ return nil, fmt.Errorf("empty class name in entry %q", cr)
+ }
+ replicas, err := strconv.Atoi(fields[1])
+ if err != nil || replicas < 1 {
+ return nil, fmt.Errorf("invalid replica count %q", fields[1])
+ }
+ classesStored[className] = replicas
+ }
+ return classesStored, nil
+}
+
+// delayCalculator calculates a series of delays for implementing
+// exponential backoff with jitter. The first call to Next() returns
+// a random duration between MinimumRetryDelay and the specified
+// InitialMaxDelay (or DefaultRetryDelay if 0). The max delay is
+// doubled on each subsequent call to Next(), up to 10x the initial
+// max delay.
+type delayCalculator struct {
+ InitialMaxDelay time.Duration
+ n int // number of delays returned so far
+ nextmax time.Duration
+ limit time.Duration
+}
+
+func (dc *delayCalculator) Next() time.Duration {
+ if dc.nextmax <= MinimumRetryDelay {
+ // initialize
+ if dc.InitialMaxDelay > 0 {
+ dc.nextmax = dc.InitialMaxDelay
+ } else {
+ dc.nextmax = DefaultRetryDelay
+ }
+ dc.limit = 10 * dc.nextmax
+ }
+ d := time.Duration(rand.Float64() * float64(dc.nextmax))
+ if d < MinimumRetryDelay {
+ d = MinimumRetryDelay
+ }
+ dc.nextmax *= 2
+ if dc.nextmax > dc.limit {
+ dc.nextmax = dc.limit
+ }
+ return d