id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c17100
{ return nil, err } // decrypt var decrypted []byte decrypted, ok := secretbox.Open(decrypted, e.CiphertextBytes(), nonce, s.secretKey) if !ok { return nil, fmt.Errorf("unable to decrypt message") } return decrypted, nil }
c17101
- new index is %d", err, cErr.Index+1) // Re-create the watcher with a newer index until we catch up watcher = s.api.Watcher(s.conf.Election, nil) return true } } if err != context.DeadlineExceeded { logrus.WithField("category", "election"). Errorf("EtcdElection etcd error: %s...
c17102
return nil, err } // convert to array and return return KeySliceToArray(keySlice) }
c17103
"", err } return base64.URLEncoding.EncodeToString(b), nil }
c17104
err = json.Unmarshal(bytes, &sb) if err != nil { return nil, err } return &sb, nil }
c17105
_, channel := range b.clients { channel <- struct{}{} } b.mutex.Unlock() }
c17106
10000) channel = b.clients[name] } b.mutex.Unlock() // Wait for a new event or done is closed select { case <-channel: return case <-b.done: return } }
c17107
struct{}, 10000) channel = b.clients[name] } b.mutex.Unlock() return channel }
c17108
return &NonceCache{ cache: holster.NewTTLMapWithClock(capacity, clock), cacheTTL: cacheTTL, clock: clock, } }
c17109
// it's not, so let's put it in the cache n.cache.Set(nonce, "", n.cacheTTL) return false }
c17110
ll: list.New(), cache: make(map[interface{}]*list.Element), } }
c17111
c.addRecord(&cacheRecord{key: key, value: value}) }
c17112
c.addRecord(&cacheRecord{ key: key, value: value, expireAt: &expireAt, }) }
c17113
true } ele := c.ll.PushFront(record) c.cache[record.key] = ele if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries { c.removeOldest() } return false }
c17114
}() c.mutex.Lock() c.stats.Size = int64(len(c.cache)) return c.stats }
c17115
c.mutex.Lock() for key := range c.cache { keys = append(keys, key) } return }
c17116
c.mutex.Lock() if ele, hit := c.cache[key]; hit { entry := ele.Value.(*cacheRecord) return entry.value, true } return nil, false }
c17117
el.Priority = priority heap.Push(p.impl, el) }
c17118
random number from /dev/urandom _, err := io.ReadFull(rand.Reader, n) if err != nil { return nil, err } return n, nil }
c17119
} wg.mutex.Lock() wg.errs = append(wg.errs, err) wg.wg.Done() wg.mutex.Unlock() }() }
c17120
wg.wg.Add(1) go func() { cb() wg.wg.Done() }() }
c17121
if !callBack() { wg.wg.Done() break } } }() }
c17122
if len(wg.errs) == 0 { return nil } return wg.errs }
c17123
fmt.Printf("Passphrase: ") fmt.Scanln(&passphrase) // derive key and return it keySlice := pbkdf2.Key([]byte(passphrase), salt, keyiter, 32, sha256.New) keyBytes, err := secret.KeySliceToArray(keySlice) if err != nil { return nil, true, err } return keyBytes, true, nil }
c17124
} // marshal encoded ciphertext into a json string b, err := json.MarshalIndent(ec, "", " ") if err != nil { return err } // write to disk with read only permissions for the current user return ioutil.WriteFile(filename, b, 0600) }
c17125
nil, err } sealedBytes := &secret.SealedBytes{ Ciphertext: ec.Ciphertext, Nonce: ec.CiphertextNonce, } return ec.KeySalt, ec.KeyIter, sealedBytes, nil }
c17126
no one else doing ops with this key return myOp } op := opIface.(*opResult) // someone else doing ops with this key, wait for // the result op.mu.RLock() if op.success { return nil } // if we are here, we will retry the operation } }
c17127
} else if !os.IsNotExist(err) { return err } // Rename and add new file's diskUsage. If the rename fails, // it will either a) Re-add the size of an existing file, which // was sustracted before b) Add 0 if there is no existing file. err = os.Rename(tmpPath, path) fs.updateDiskUsage(path, true) return err }
c17128
-fSize) fs.checkpointDiskUsage() return nil case os.IsNotExist(err): return datastore.ErrNotFound default: return err } }
c17129
} else { // in any other case, add the file size du += st.Size() filesProcessed++ } i++ } nonProcessed := totalFiles - filesProcessed // Avg is total size in this folder up to now / total files processed // it includes folders ant not folders avg := 0.0 if filesProcessed > 0 { avg = float64(du) /...
c17130
atomic.AddInt64(&fs.diskUsage, fsize) fs.checkpointDiskUsage() } }
c17131
a large datastore, the differences should be // are negligible though. du := atomic.LoadInt64(&fs.diskUsage) return uint64(du), nil }
c17132
} fs.shutdown = true close(fs.checkpointCh) <-fs.done return nil }
c17133
*api.SQLLEN { p.StrLen_or_IndPtr = v return &p.StrLen_or_IndPtr }
c17134
i++ case surr1 <= r && r < surr3: // invalid surrogate sequence rr = replacementChar default: // normal rune rr = rune(r) } b := b[:cap(b)] n := utf8.EncodeRune(b, rr) b = b[:n] buf = append(buf, b...) } return buf }
c17135
// Adapt router if fnR != nil { fnR(r) } // Parse templates var err error if templates, err = astitemplate.ParseDirectory(filepath.Join(baseDirectoryPath, "resources", "templates"), ".html"); err != nil { astilog.Fatal(err) } // Listen if ln, err = net.Listen("tcp", "127.0.0.1:"); err != nil { astilog...
c17136
while retrieving data for template %s", err, name) rw.WriteHeader(http.StatusInternalServerError) return } } // Execute template if err = templates.ExecuteTemplate(rw, name, d); err != nil { astilog.Errorf("%s while handling template %s", err, name) rw.WriteHeader(http.StatusInternalServerError...
c17137
ws.handleInvMsg(&msg) case txMsg: ws.handleTxMsg(&msg) case updateFiltersMsg: ws.handleUpdateFiltersMsg() default: log.Warningf("Unknown message type sent to WireService message chan: %T", msg) } case <-ws.quit: break out } } }
c17138
if err = e.Unmarshal(&m); err != nil { astilog.Errorf("Unmarshaling message %+v failed", *e) return } // Handle message messageHandler(w, m) return } }
c17139
if utxo.Op.Hash.IsEqual(&input.PreviousOutPoint.Hash) && utxo.Op.Index == input.PreviousOutPoint.Index { inval += utxo.Value break } } } if inval < outval { return 0, errors.New("Error building transaction: inputs less than outputs") } return uint64(inval - outval), err }
c17140
add 20-byte pubkeyhash f.Add(a.ScriptAddress()) } ts.addrMutex.Unlock() for _, u := range allUtxos { f.AddOutPoint(&u.Op) } for _, s := range allStxos { f.AddOutPoint(&s.Utxo.Op) } for _, w := range ts.watchedScripts { _, addrs, _, err := txscript.ExtractPkScriptAddrs(w, ts.params) if err != nil { ...
c17141
for _, compIn := range msgTx.TxIn { if outPointsEqual(argIn.PreviousOutPoint, compIn.PreviousOutPoint) && !compTxid.IsEqual(&argTxid) { // found double spend dubs = append(dubs, &compTxid) break // back to argIn loop } } } } return dubs, nil }
c17142
ts.addrMutex.Unlock() ts.watchedScripts, _ = ts.WatchedScripts().GetAll() txns, _ := ts.Txns().GetAll(true) ts.txidsMutex.Lock() for _, t := range txns { ts.txids[t.Txid] = t.Height } ts.txidsMutex.Unlock() return nil }
c17143
than root ") return true } h := msb for pos >= h { h = h>>1 | msb last = last>>1 | msb } return pos > last }
c17144
err := km.datastore.MarkKeyAsUsed(scriptAddress); err != nil { return err } return km.lookahead() }
c17145
// In that case we should just return checkpoint bits if err == nil { prevHeader = sh } } return prevHeader.header.Bits, nil } } } // Just return the bits from the last header return prevHeader.header.Bits, nil } // We are on a difficulty adjustment period so we need t...
c17146
if err != nil { return nil, err } } for { majorityHash := majority.header.BlockHash() minorityHash := minority.header.BlockHash() if majorityHash.IsEqual(&minorityHash) { return &majority, nil } majority, err = b.db.GetPreviousHeader(majority.header) if err != nil { return nil, err } min...
c17147
return nil } rollbackHeight := uint32(0) for i := 0; i < 1000000000; i++ { sh, err = b.db.GetPreviousHeader(sh.header) if err != nil { return err } checkHash := sh.header.BlockHash() // If we rolled back to the checkpoint then stop here and set the checkpoint as the tip if checkHash.IsEqual(&checkPoi...
c17148
// The header hash must be less than the claimed target in the header. blockHash := header.BlockHash() hashNum := blockchain.HashToBig(&blockHash) if hashNum.Cmp(target) > 0 { log.Debugf("Block hash %064x is higher than "+ "required target of %064x", hashNum, target) return false } return true }
c17149
prevTarget := blockchain.CompactToBig(end.Bits) // new target is old * duration... newTarget := new(big.Int).Mul(prevTarget, big.NewInt(duration)) // divided by 2 weeks newTarget.Div(newTarget, big.NewInt(int64(targetTimespan))) // clip again if above minimum target (too easy) if newTarget.Cmp(p.PowLimit) > 0 {...
c17150
else if err != nil { err = errors.Wrapf(err, "stating %s failed", pr) return } else { astilog.Debugf("%s already exists, skipping restoring assets...", pr) } // Custom provision if fnP != nil { if err = fnP(baseDirectoryPath); err != nil { err = errors.Wrap(err, "custom provisioning failed") return ...
c17151
// Don't return addresses we're still connected to for _, p := range pm.connectedPeers { if p.NA().IP.String() == knownAddress.IP.String() { continue loop } } addr := &net.TCPAddr{ Port: int(knownAddress.Port), IP: knownAddress.IP, } pm.addrManager.Attempt(knownAddress) return ...
c17152
wg.Done() return } } for _, addr := range addrs { netAddr := wire.NewNetAddressIPPort(net.ParseIP(addr), defaultPort, 0) pm.addrManager.AddAddress(netAddr, pm.sourceAddr) returnedAddresses++ } log.Debugf("%s returned %s addresses\n", host, strconv.Itoa(returnedAddresses)) wg.Done()...
c17153
:= range pm.connectedPeers { p.QueueMessage(wire.NewMsgGetAddr(), nil) } } else { pm.queryDNSSeeds() } } }
c17154
*Geometry) { cGEOSGeom_destroy(ptr) }) return g }
c17155
return nil, Error() } return &Geometry{g: ptr}, nil }
c17156
XXX: error if wrong geometry types return float64(cGEOSProject(g.g, p.g)) }
c17157
// XXX: error if wrong geometry types return float64(cGEOSProjectNormalized(g.g, p.g)) }
c17158
geomFromC("Interpolate", cGEOSInterpolate(g.g, C.double(dist))) }
c17159
} b, err := g.Point(i + 1) if err != nil { return nil, err } // Find the relative length of this segment. slength, err := a.Distance(b) if err != nil { return nil, err } slength /= length if dist < tlength+slength { dseg := (dist - tlength) / slength pt, err := interpolatePoint2D(a, b, ...
c17160
geomFromC("OffsetCurve", cGEOSOffsetCurve(g.g, C.double(distance), C.int(opts.QuadSegs), C.int(opts.JoinStyle), C.double(opts.MitreLimit))) }
c17161
g.simplify("simplify", cGEOSTopologyPreserveSimplify, tolerance) }
c17162
geomFromC("Snap", cGEOSSnap(g.g, other.g, C.double(tolerance))) }
c17163
g.binaryTopo("Intersection", cGEOSIntersection, other) }
c17164
g.binaryTopo("Difference", cGEOSDifference, other) }
c17165
g.binaryTopo("SymDifference", cGEOSSymDifference, other) }
c17166
g.binaryTopo("Union", cGEOSUnion, other) }
c17167
g.binaryPred("Disjoint", cGEOSDisjoint, other) }
c17168
g.binaryPred("Touches", cGEOSTouches, other) }
c17169
g.binaryPred("Intersects", cGEOSIntersects, other) }
c17170
g.binaryPred("Crosses", cGEOSCrosses, other) }
c17171
g.binaryPred("Within", cGEOSWithin, other) }
c17172
g.binaryPred("Contains", cGEOSContains, other) }
c17173
g.binaryPred("Overlaps", cGEOSOverlaps, other) }
c17174
g.binaryPred("Equals", cGEOSEquals, other) }
c17175
g.binaryPred("Covers", cGEOSCovers, other) }
c17176
g.binaryPred("CoveredBy", cGEOSCoveredBy, other) }
c17177
boolFromC("EqualsExact", cGEOSEqualsExact(g.g, other.g, C.double(tolerance))) }
c17178
XXX: error return -1, Error() } return cGeomTypeIds[i], nil }
c17179
int) { cGEOSSetSRID(g.g, C.int(srid)) }
c17180
if ptr == nil { return nil, Error() } //cs := coordSeqFromPtr(ptr) cs := &coordSeq{c: ptr} return coordSlice(cs) }
c17181
cGEOSGeomGetPointN(g.g, C.int(n))) }
c17182
g.binaryFloat("Distance", cGEOSDistance, other) }
c17183
return boolFromC("RelatePat", cGEOSRelatePattern(g.g, other.g, cs)) }
c17184
:= cs.y(i) if err != nil { return nil, err } coords[i] = Coord{X: x, Y: y} } return coords, nil }
c17185
d := &wktDecoder{r} runtime.SetFinalizer(d, (*wktDecoder).destroy) return d }
c17186
C.free(unsafe.Pointer(cstr)) g := cGEOSWKTReader_read(d.r, cstr) if g == nil { return nil, Error() } return geomFromPtr(g), nil }
c17187
return "", Error() } return C.GoString(cstr), nil }
c17188
runtime.SetFinalizer(p, (*PGeometry).destroy) return p }
c17189
p.predicate("contains", cGEOSPreparedContains, other) }
c17190
p.predicate("contains", cGEOSPreparedContainsProperly, other) }
c17191
p.predicate("covered by", cGEOSPreparedCoveredBy, other) }
c17192
p.predicate("covers", cGEOSPreparedCovers, other) }
c17193
p.predicate("crosses", cGEOSPreparedCrosses, other) }
c17194
p.predicate("disjoint", cGEOSPreparedDisjoint, other) }
c17195
p.predicate("intersects", cGEOSPreparedIntersects, other) }
c17196
p.predicate("overlaps", cGEOSPreparedOverlaps, other) }
c17197
p.predicate("touches", cGEOSPreparedTouches, other) }
c17198
p.predicate("within", cGEOSPreparedWithin, other) }
c17199
if err != nil { return false, err } return res.(int64) == 1, nil }