func (store *BoltStore) Del(uri string) error { namespace, key := util.NamespaceKey(uri) bucketkeys := util.PathFolders(namespace) var bucket *bolt.Bucket = nil var err error e := store.db.Update(func(tx *bolt.Tx) error { for _, bucketkey := range bucketkeys { if bucket == nil { bucket, err = tx.CreateBucketIfNotExists([]byte(bucketkey)) if err != nil { return err } } else { bucket, err = bucket.CreateBucketIfNotExists([]byte(bucketkey)) if err != nil { return err } } } bucket.DeleteBucket([]byte(key)) bucket.Delete([]byte(key)) return nil }) return e }
// commitSiacoinOutputDiff applies or reverts a SiacoinOutputDiff from within // a database transaction. func (cs *ConsensusSet) commitBucketSiacoinOutputDiff(scoBucket *bolt.Bucket, scod modules.SiacoinOutputDiff, dir modules.DiffDirection) error { if build.DEBUG && (scoBucket.Get(scod.ID[:]) == nil) != (scod.Direction == dir) { panic(errRepeatInsert) } if scod.Direction == dir { return scoBucket.Put(scod.ID[:], encoding.Marshal(scod.SiacoinOutput)) } return scoBucket.Delete(scod.ID[:]) }
func deleteRange(bucket *bolt.Bucket, prefix tuple.Key) error { cursor := bucket.Cursor() for k, _ := cursor.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = cursor.Next() { if err := bucket.Delete(k); err != nil { return err } } return nil }
func deleteChanTotalFlow(openChanBucket *bolt.Bucket, chanID []byte) error { keyPrefix := make([]byte, 3+len(chanID)) copy(keyPrefix[3:], chanID) copy(keyPrefix[:3], satSentPrefix) if err := openChanBucket.Delete(keyPrefix); err != nil { return err } copy(keyPrefix[:3], satRecievedPrefix) return openChanBucket.Delete(keyPrefix) }
func (db *bwdb) sumAndShift(pullBkt, putBkt *bolt.Bucket, putKey []byte) error { //pull all the values out of the pullBkt and sum them s := db.newVar() err := pullBkt.ForEach(func(k, v []byte) error { sx := db.newVar() if err := sx.Decode(v); err != nil { return err } if err := s.Add(sx); err != nil { return err } s.SetTS(sx.TS()) return pullBkt.Delete(k) }) if err != nil { return err } return db.updateVal(putBkt, putKey, s) //if for some reason the key already exists, add it }
// Process makes sure incoming requests do not exceed the configured rate // limit. func (RateLimitFilter) Process(h Hook, r Request, b *bolt.Bucket) error { amount, _ := strconv.Atoi(string(b.Get([]byte(fmt.Sprintf("%s-amount", h.ID))))) interval, _ := strconv.Atoi(string(b.Get([]byte(fmt.Sprintf("%s-interval", h.ID))))) if amount <= 0 || interval <= 0 { return errors.New("rate limit filter not initialized") } b = b.Bucket([]byte("requests")) // store current timestamp now := time.Now() k := []byte(fmt.Sprintf("%d", now.UnixNano())) if err := b.Put(k, nil); err != nil { return err } // count requests c := b.Cursor() from := []byte(fmt.Sprintf("%d", now.Add(time.Duration(-interval)*time.Second).UnixNano())) var count int for k, _ := c.Seek(from); k != nil; k, _ = c.Next() { count++ } if count > amount { return fmt.Errorf("rate limit exceeded (limit=%d count=%d)", amount, count) } // cleanup old entries for k, _ := c.First(); k != nil && bytes.Compare(k, from) <= 0; k, _ = c.Next() { if err := b.Delete(k); err != nil { return err } } return nil }
func deleteChanCapacity(openChanBucket *bolt.Bucket, chanID []byte) error { keyPrefix := make([]byte, 3+len(chanID)) copy(keyPrefix[3:], chanID) copy(keyPrefix[:3], chanCapacityPrefix) if err := openChanBucket.Delete(keyPrefix); err != nil { return err } copy(keyPrefix[:3], selfBalancePrefix) if err := openChanBucket.Delete(keyPrefix); err != nil { return err } copy(keyPrefix[:3], theirBalancePrefix) return openChanBucket.Delete(keyPrefix) }
func DepersistOneBoltTx(bucket *bolt.Bucket, key string) error { return bucket.Delete([]byte(key)) }
func deleteChannelIDs(nodeChanBucket *bolt.Bucket, chanID []byte) error { idKey := make([]byte, len(chanIDKey)+len(chanID)) copy(idKey[:3], chanIDKey) copy(idKey[3:], chanID) return nodeChanBucket.Delete(idKey) }
func deleteChanNetFee(openChanBucket *bolt.Bucket, chanID []byte) error { keyPrefix := make([]byte, 3+len(chanID)) copy(keyPrefix, netFeesPrefix) copy(keyPrefix[3:], chanID) return openChanBucket.Delete(keyPrefix) }
func deleteChanNumUpdates(openChanBucket *bolt.Bucket, chanID []byte) error { keyPrefix := make([]byte, 3+len(chanID)) copy(keyPrefix, updatePrefix) copy(keyPrefix[3:], chanID) return openChanBucket.Delete(keyPrefix) }
func deleteChanMinFeePerKb(openChanBucket *bolt.Bucket, chanID []byte) error { keyPrefix := make([]byte, 3+len(chanID)) copy(keyPrefix, minFeePerKbPrefix) copy(keyPrefix[3:], chanID) return openChanBucket.Delete(keyPrefix) }
func deleteChanDeliveryScripts(nodeChanBucket *bolt.Bucket, chanID []byte) error { deliveryKey := make([]byte, len(deliveryScriptsKey)+len(chanID)) copy(deliveryKey[:3], deliveryScriptsKey) copy(deliveryKey[3:], chanID) return nodeChanBucket.Delete(deliveryScriptsKey) }
func deleteChanElkremState(nodeChanBucket *bolt.Bucket, chanID []byte) error { elkremKey := make([]byte, len(elkremStateKey)+len(chanID)) copy(elkremKey[:3], elkremStateKey) copy(elkremKey[3:], chanID) return nodeChanBucket.Delete(elkremKey) }
func deleteChanFundingInfo(nodeChanBucket *bolt.Bucket, chanID []byte) error { fundTxnKey := make([]byte, len(fundingTxnKey)+len(chanID)) copy(fundTxnKey[:3], fundingTxnKey) copy(fundTxnKey[3:], chanID) return nodeChanBucket.Delete(fundTxnKey) }
func deleteChanCommitTxns(nodeChanBucket *bolt.Bucket, chanID []byte) error { txnsKey := make([]byte, len(commitTxnsKey)+len(chanID)) copy(txnsKey[:3], commitTxnsKey) copy(txnsKey[3:], chanID) return nodeChanBucket.Delete(txnsKey) }