Commit 7bf30e64 authored by Luke Champine's avatar Luke Champine Committed by GitHub

Merge pull request #1584 from NebulousLabs/hostdb-testing

Testing around dynamic ip addresses
parents 50dd615b 43be2972
This diff is collapsed.
......@@ -448,11 +448,6 @@ func createExplorerServerTester(name string) (*serverTester, error) {
return st, nil
}
// non2xx returns true for non-success HTTP status codes.
func non2xx(code int) bool {
return code < 200 || code > 299
}
// decodeError returns the api.Error from a API response. This method should
// only be called if the response's status code is non-2xx. The error returned
// may not be of type api.Error in the event of an error unmarshalling the
......@@ -466,6 +461,25 @@ func decodeError(resp *http.Response) error {
return apiErr
}
// non2xx returns true for non-success HTTP status codes.
func non2xx(code int) bool {
return code < 200 || code > 299
}
// retry will retry a function multiple times until it returns 'nil'. It will
// sleep the specified duration between tries. If success is not achieved in the
// specified number of attempts, the final error is returned.
func retry(tries int, durationBetweenAttempts time.Duration, fn func() error) (err error) {
for i := 0; i < tries-1; i++ {
err = fn()
if err == nil {
return nil
}
time.Sleep(durationBetweenAttempts)
}
return fn()
}
// reloadedServerTester creates a server tester where all of the persistent
// data has been copied to a new folder and all of the modules re-initialized
// on the new folder. This gives an opportunity to see how modules will behave
......@@ -521,7 +535,7 @@ func (st *serverTester) announceHost() error {
acceptingContractsValues.Set("acceptingcontracts", "true")
err := st.stdPostAPI("/host", acceptingContractsValues)
if err != nil {
return err
return build.ExtendErr("couldn't make an api call to the host:", err)
}
announceValues := url.Values{}
......
......@@ -136,6 +136,8 @@ func (c *Contractor) Downloader(id types.FileContractID) (_ Downloader, err erro
} else if host.DownloadBandwidthPrice.Cmp(maxDownloadPrice) > 0 {
return nil, errTooExpensive
}
// Update the contract to the most recent net address for the host.
contract.NetAddress = host.NetAddress
// acquire revising lock
c.mu.Lock()
......
......@@ -200,6 +200,7 @@ func (c *Contractor) Editor(id types.FileContractID) (_ Editor, err error) {
host.Collateral = maxUploadCollateral
}
}
contract.NetAddress = host.NetAddress
// acquire revising lock
c.mu.Lock()
......
......@@ -24,6 +24,9 @@ func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors ui
if host.MaxCollateral.Cmp(maxCollateral) > 0 {
host.MaxCollateral = maxCollateral
}
// Set the net address of the contract to the most recent net address for
// the host.
contract.NetAddress = host.NetAddress
// get an address to use for negotiation
uc, err := c.wallet.NextAddress()
......@@ -42,9 +45,8 @@ func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors ui
}
c.mu.RUnlock()
txnBuilder := c.wallet.StartTransaction()
// execute negotiation protocol
txnBuilder := c.wallet.StartTransaction()
newContract, err := proto.Renew(contract, params, txnBuilder, c.tpool)
if proto.IsRevisionMismatch(err) {
// return unused outputs to wallet
......
......@@ -30,8 +30,6 @@ type hdbTester struct {
// bareHostDB returns a HostDB with its fields initialized, but without any
// dependencies or scanning threads. It is only intended for use in unit tests.
//
// TODO: purge
func bareHostDB() *HostDB {
hdb := &HostDB{
log: persist.NewLogger(ioutil.Discard),
......
......@@ -25,10 +25,6 @@ func (quitAfterLoadDeps) disrupt(s string) bool {
}
// TestSaveLoad tests that the hostdb can save and load itself.
//
// TODO: By extending the hdbTester and adding some helper functions, we can
// eliminate the necessary disruption by adding real hosts + blocks instead of
// fake ones.
func TestSaveLoad(t *testing.T) {
if testing.Short() {
t.SkipNow()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment