// New returns an empty renter. func New(cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*Renter, error) { hdb, err := hostdb.New(cs, wallet, tpool, persistDir) if err != nil { return nil, err } r := &Renter{ cs: cs, wallet: wallet, hostDB: hdb, files: make(map[string]*file), tracking: make(map[string]trackedFile), persistDir: persistDir, mu: sync.New(modules.SafeMutexDelay, 1), } err = r.initPersist() if err != nil { return nil, err } go r.threadedRepairLoop() return r, nil }
// newTestingContractor is a helper function that creates a ready-to-use // contractor. func newTestingContractor(testdir string, cs modules.ConsensusSet, tp modules.TransactionPool) (*Contractor, error) { w, err := newTestingWallet(testdir, cs, tp) if err != nil { return nil, err } hdb, err := hostdb.New(cs, filepath.Join(testdir, "hostdb")) if err != nil { return nil, err } return New(cs, w, tp, hdb, filepath.Join(testdir, "contractor")) }
// New returns an empty renter. func New(cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*Renter, error) { hdb, err := hostdb.New(cs, persistDir) if err != nil { return nil, err } hc, err := contractor.New(cs, wallet, tpool, hdb, persistDir) if err != nil { return nil, err } return newRenter(cs, tpool, hdb, hc, persistDir) }
// New returns an empty renter. func New(cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*Renter, error) { if cs == nil { return nil, ErrNilCS } if wallet == nil { return nil, ErrNilWallet } if tpool == nil { return nil, ErrNilTpool } hdb := hostdb.New() r := &Renter{ cs: cs, hostDB: hdb, wallet: wallet, tpool: tpool, files: make(map[string]*file), contracts: make(map[types.FileContractID]types.FileContract), tracking: make(map[string]trackedFile), persistDir: persistDir, mu: sync.New(modules.SafeMutexDelay, 1), } _, err := rand.Read(r.entropy[:]) if err != nil { return nil, err } err = r.initPersist() if err != nil { return nil, err } cs.ConsensusSetSubscribe(r) go r.threadedRepairUploads() return r, nil }
// newContractorTester creates a ready-to-use contractor tester with money in the // wallet. func newContractorTester(name string) (*contractorTester, error) { // Create the modules. testdir := build.TempDir("contractor", name) g, err := gateway.New("localhost:0", false, filepath.Join(testdir, modules.GatewayDir)) if err != nil { return nil, err } cs, err := consensus.New(g, false, filepath.Join(testdir, modules.ConsensusDir)) if err != nil { return nil, err } tp, err := transactionpool.New(cs, g, filepath.Join(testdir, modules.TransactionPoolDir)) if err != nil { return nil, err } w, err := modWallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir)) if err != nil { return nil, err } key, err := crypto.GenerateTwofishKey() if err != nil { return nil, err } _, err = w.Encrypt(key) if err != nil { return nil, err } err = w.Unlock(key) if err != nil { return nil, err } hdb, err := hostdb.New(cs, filepath.Join(testdir, modules.RenterDir)) if err != nil { return nil, err } m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir)) if err != nil { return nil, err } c, err := New(cs, w, tp, hdb, filepath.Join(testdir, modules.RenterDir)) if err != nil { return nil, err } // Assemble all pieces into a contractor tester. ct := &contractorTester{ cs: cs, gateway: g, miner: m, tpool: tp, wallet: w, hdb: hdb, contractor: c, } // Mine blocks until there is money in the wallet. for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ { _, err := ct.miner.AddBlock() if err != nil { return nil, err } } return ct, nil }