Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
fix host settings parsing reset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
avahowell committed Oct 26, 2017
1 parent 5b98e8e commit f8dd3b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
29 changes: 15 additions & 14 deletions Makefile
Expand Up @@ -17,13 +17,14 @@ dependencies:
go get -u github.com/NebulousLabs/errors
go get -u github.com/NebulousLabs/go-upnp
go get -u github.com/NebulousLabs/muxado
go get -u github.com/NebulousLabs/threadgroup
go get -u github.com/klauspost/reedsolomon
go get -u github.com/julienschmidt/httprouter
go get -u github.com/inconshreveable/go-update
go get -u github.com/kardianos/osext
go get -u github.com/inconshreveable/mousetrap
# Frontend Dependencies
go get -u github.com/bgentry/speakeasy
go get -u golang.org/x/crypto/ssh/terminal
go get -u github.com/spf13/cobra/...
# Developer Dependencies
go install -race std
Expand All @@ -37,8 +38,8 @@ run = .
pkgs = ./api ./build ./compatibility ./crypto ./encoding ./modules ./modules/consensus \
./modules/explorer ./modules/gateway ./modules/host ./modules/host/contractmanager \
./modules/renter ./modules/renter/contractor ./modules/renter/hostdb ./modules/renter/hostdb/hosttree \
./modules/renter/proto ./modules/miner ./modules/wallet ./modules/transactionpool ./persist ./cmd/siac \
./cmd/siad ./sync ./types
./modules/renter/proto ./modules/miner ./modules/wallet ./modules/transactionpool ./persist \
./cmd/siad ./cmd/siac ./sync ./types

# fmt calls go fmt on all packages.
fmt:
Expand All @@ -63,35 +64,35 @@ spellcheck:

# dev builds and installs developer binaries.
dev:
go install -race -tags='dev debug profile' $(pkgs)
go install -race -tags='dev debug profile netgo' $(pkgs)

# release builds and installs release binaries.
release:
go install -tags='debug profile' $(pkgs)
go install -tags='debug profile netgo' $(pkgs)
release-race:
go install -race -tags='debug profile' $(pkgs)
go install -race -tags='debug profile netgo' $(pkgs)
release-std:
go install -tags '' -ldflags='-s -w' $(pkgs)
go install -tags 'netgo' -a -ldflags='-s -w' $(pkgs)

# clean removes all directories that get automatically created during
# development.
clean:
rm -rf release doc/whitepaper.aux doc/whitepaper.log doc/whitepaper.pdf

test:
go test -short -tags='debug testing' -timeout=5s $(pkgs) -run=$(run)
go test -short -tags='debug testing netgo' -timeout=5s $(pkgs) -run=$(run)
test-v:
go test -race -v -short -tags='debug testing' -timeout=15s $(pkgs) -run=$(run)
go test -race -v -short -tags='debug testing netgo' -timeout=15s $(pkgs) -run=$(run)
test-long: clean fmt vet lint
go test -v -race -tags='testing debug' -timeout=500s $(pkgs) -run=$(run)
go test -v -race -tags='testing debug netgo' -timeout=500s $(pkgs) -run=$(run)
test-vlong: clean fmt vet lint
go test -v -race -tags='testing debug vlong' -timeout=5000s $(pkgs) -run=$(run)
go test -v -race -tags='testing debug vlong netgo' -timeout=5000s $(pkgs) -run=$(run)
test-cpu:
go test -v -tags='testing debug' -timeout=500s -cpuprofile cpu.prof $(pkgs) -run=$(run)
go test -v -tags='testing debug netgo' -timeout=500s -cpuprofile cpu.prof $(pkgs) -run=$(run)
test-mem:
go test -v -tags='testing debug' -timeout=500s -memprofile mem.prof $(pkgs) -run=$(run)
go test -v -tags='testing debug netgo' -timeout=500s -memprofile mem.prof $(pkgs) -run=$(run)
bench: clean fmt
go test -tags='debug testing' -timeout=500s -run=XXX -bench=$(run) $(pkgs)
go test -tags='debug testing netgo' -timeout=500s -run=XXX -bench=$(run) $(pkgs)
cover: clean
@mkdir -p cover/modules
@mkdir -p cover/modules/renter
Expand Down
26 changes: 13 additions & 13 deletions api/host.go
Expand Up @@ -91,47 +91,47 @@ func (api *API) parseHostSettings(req *http.Request) (modules.HostInternalSettin
var x bool
_, err := fmt.Sscan(req.FormValue("acceptingcontracts"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.AcceptingContracts = x
}
if req.FormValue("maxdownloadbatchsize") != "" {
var x uint64
_, err := fmt.Sscan(req.FormValue("maxdownloadbatchsize"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MaxDownloadBatchSize = x
}
if req.FormValue("maxduration") != "" {
var x types.BlockHeight
_, err := fmt.Sscan(req.FormValue("maxduration"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MaxDuration = x
}
if req.FormValue("maxrevisebatchsize") != "" {
var x uint64
_, err := fmt.Sscan(req.FormValue("maxrevisebatchsize"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MaxReviseBatchSize = x
}
if req.FormValue("netaddress") != "" {
var x modules.NetAddress
_, err := fmt.Sscan(req.FormValue("netaddress"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.NetAddress = x
}
if req.FormValue("windowsize") != "" {
var x types.BlockHeight
_, err := fmt.Sscan(req.FormValue("windowsize"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.WindowSize = x
}
Expand All @@ -140,23 +140,23 @@ func (api *API) parseHostSettings(req *http.Request) (modules.HostInternalSettin
var x types.Currency
_, err := fmt.Sscan(req.FormValue("collateral"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.Collateral = x
}
if req.FormValue("collateralbudget") != "" {
var x types.Currency
_, err := fmt.Sscan(req.FormValue("collateralbudget"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.CollateralBudget = x
}
if req.FormValue("maxcollateral") != "" {
var x types.Currency
_, err := fmt.Sscan(req.FormValue("maxcollateral"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MaxCollateral = x
}
Expand All @@ -165,31 +165,31 @@ func (api *API) parseHostSettings(req *http.Request) (modules.HostInternalSettin
var x types.Currency
_, err := fmt.Sscan(req.FormValue("mincontractprice"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MinContractPrice = x
}
if req.FormValue("mindownloadbandwidthprice") != "" {
var x types.Currency
_, err := fmt.Sscan(req.FormValue("mindownloadbandwidthprice"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MinDownloadBandwidthPrice = x
}
if req.FormValue("minstorageprice") != "" {
var x types.Currency
_, err := fmt.Sscan(req.FormValue("minstorageprice"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MinStoragePrice = x
}
if req.FormValue("minuploadbandwidthprice") != "" {
var x types.Currency
_, err := fmt.Sscan(req.FormValue("minuploadbandwidthprice"), &x)
if err != nil {
return modules.HostInternalSettings{}, nil
return modules.HostInternalSettings{}, err
}
settings.MinUploadBandwidthPrice = x
}
Expand Down
6 changes: 1 addition & 5 deletions api/host_test.go
Expand Up @@ -172,13 +172,9 @@ func TestHostSettingsHandlerParsing(t *testing.T) {
defer st.server.panicClose()

settings := st.host.InternalSettings()
t.Log(settings)
settingsValues := url.Values{}
settingsValues.Set("maxdownloadbatchsize", "foo")
err = st.stdPostAPI("/host", settingsValues)
if err != nil {
t.Fatal(err)
}
st.stdPostAPI("/host", settingsValues)
newSettings := st.host.InternalSettings()
if !reflect.DeepEqual(newSettings, settings) {
t.Fatal("invalid acceptingcontracts value changed host settings! got", newSettings, "wanted", settings)
Expand Down

0 comments on commit f8dd3b8

Please sign in to comment.