Exemplo n.º 1
1
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
}
Exemplo n.º 2
0
// 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[:])
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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)
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
// 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
}
Exemplo n.º 7
0
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)
}
Exemplo n.º 8
0
func DepersistOneBoltTx(bucket *bolt.Bucket, key string) error {
	return bucket.Delete([]byte(key))
}
Exemplo n.º 9
0
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)
}
Exemplo n.º 10
0
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)
}
Exemplo n.º 11
0
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)
}
Exemplo n.º 12
0
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)
}
Exemplo n.º 13
0
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)
}
Exemplo n.º 14
0
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)
}
Exemplo n.º 15
0
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)
}
Exemplo n.º 16
0
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)
}