func (cs *ContractSet) SetRateLimits(readBPS int64, writeBPS int64, packetSize uint64) {
	cs.rl.SetLimits(readBPS, writeBPS, packetSize)
}
SetRateLimits sets the bandwidth limits for connections created by the
contractSet.
package proto
import (
	"os"
	"path/filepath"
	"sync"
	"github.com/NebulousLabs/Sia/build"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"
	"github.com/NebulousLabs/ratelimit"
	"github.com/NebulousLabs/errors"
	"github.com/NebulousLabs/writeaheadlog"
)
type ContractSet struct {
	contracts map[types.FileContractID]*SafeContract
	pubKeys   map[string]types.FileContractID
	deps      modules.Dependencies
	dir       string
	mu        sync.Mutex
	rl        *ratelimit.RateLimit
	wal       *writeaheadlog.WAL
}
func (cs *ContractSet) Acquire(id types.FileContractID) (*SafeContract, bool) {
	cs.mu.Lock()
	safeContract, ok := cs.contracts[id]
	cs.mu.Unlock()
	if !ok {
		return nil, false
	}
	safeContract.mu.Lock()
	cs.mu.Lock()
	_, ok = cs.contracts[id]
	cs.mu.Unlock()
	if !ok {
		safeContract.mu.Unlock()
		return nil, false
	}
	return safeContract, true
}
func (cs *ContractSet) Delete(c *SafeContract) {
	cs.mu.Lock()
	_, ok := cs.contracts[c.header.ID()]
	if !ok {
		cs.mu.Unlock()
		build.Critical("Delete called on already deleted contract")
		return
	}
	delete(cs.contracts, c.header.ID())
	delete(cs.pubKeys, string(c.header.HostPublicKey().Key))
	cs.mu.Unlock()
	c.mu.Unlock()
	path := filepath.Join(cs.dir, c.header.ID().String()+contractExtension)
	err := errors.Compose(c.headerFile.Close(), os.Remove(path))
	if err != nil {
		build.Critical("Failed to delete SafeContract from disk:", err)
	}
}
func (cs *ContractSet) IDs() []types.FileContractID {
	cs.mu.Lock()
	defer cs.mu.Unlock()
	pks := make([]types.FileContractID, 0, len(cs.contracts))
	for fcid := range cs.contracts {
		pks = append(pks, fcid)
	}
	return pks
}
func (cs *ContractSet) Len() int {
	cs.mu.Lock()
	defer cs.mu.Unlock()
	return len(cs.contracts)
}
func (cs *ContractSet) Return(c *SafeContract) {
	cs.mu.Lock()
	_, ok := cs.contracts[c.header.ID()]
	if !ok {
		cs.mu.Unlock()
		build.Critical("no contract with that key")
	}
	cs.mu.Unlock()
	c.mu.Unlock()
}
func (cs *ContractSet) RateLimits() (readBPS int64, writeBPS int64, packetSize uint64) {
	return cs.rl.Limits()
}