diff --git a/Dockerfile b/Dockerfile index a5f450d19b..edf5a0602d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,5 @@ FROM alpine:latest RUN apk add --no-cache ca-certificates COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ -RUN addgroup -g 1000 geth && \ - adduser -h /root -D -u 1000 -G geth geth && \ - chown geth:geth /root - -USER geth - -EXPOSE 8545 8546 30303 30303/udp 30304/udp +EXPOSE 8545 8546 30303 30303/udp ENTRYPOINT ["geth"] diff --git a/Dockerfile.alltools b/Dockerfile.alltools index ec0ae92dd1..e54e107bf3 100644 --- a/Dockerfile.alltools +++ b/Dockerfile.alltools @@ -12,10 +12,4 @@ FROM alpine:latest RUN apk add --no-cache ca-certificates COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/ -RUN addgroup -g 1000 geth && \ - adduser -h /root -D -u 1000 -G geth geth && \ - chown geth:geth /root - -USER geth - -EXPOSE 8545 8546 30303 30303/udp 30304/udp +EXPOSE 8545 8546 30303 30303/udp diff --git a/Makefile b/Makefile index 3922d6015b..5cb9231a18 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,9 @@ ios: test: all build/env.sh go run build/ci.go test +lint: ## Run linters. + build/env.sh go run build/ci.go lint + clean: rm -fr build/_workspace/pkg/ $(GOBIN)/* diff --git a/VERSION b/VERSION index bfa363e76e..f263cd11b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.4 +1.8.6 diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go index 141952bfb3..3189e731c0 100644 --- a/accounts/usbwallet/ledger.go +++ b/accounts/usbwallet/ledger.go @@ -53,11 +53,9 @@ const ( ledgerOpGetConfiguration ledgerOpcode = 0x06 // Returns specific wallet application configuration ledgerP1DirectlyFetchAddress ledgerParam1 = 0x00 // Return address directly from the wallet - ledgerP1ConfirmFetchAddress ledgerParam1 = 0x01 // Require a user confirmation before returning the address ledgerP1InitTransactionData ledgerParam1 = 0x00 // First transaction data block for signing ledgerP1ContTransactionData ledgerParam1 = 0x80 // Subsequent transaction data block for signing ledgerP2DiscardAddressChainCode ledgerParam2 = 0x00 // Do not return the chain code along with the address - ledgerP2ReturnAddressChainCode ledgerParam2 = 0x01 // Require a user confirmation before returning the address ) // errLedgerReplyInvalidHeader is the error message returned by a Ledger data exchange diff --git a/build/ci.go b/build/ci.go index 3bb5395f94..303cf18421 100644 --- a/build/ci.go +++ b/build/ci.go @@ -329,7 +329,10 @@ func doLint(cmdline []string) { // Run fast linters batched together configs := []string{ "--vendor", + "--tests", "--disable-all", + "--enable=goimports", + "--enable=varcheck", "--enable=vet", "--enable=gofmt", "--enable=misspell", @@ -340,7 +343,7 @@ func doLint(cmdline []string) { // Run slow linters one by one for _, linter := range []string{"unconvert", "gosimple"} { - configs = []string{"--vendor", "--deadline=10m", "--disable-all", "--enable=" + linter} + configs = []string{"--vendor", "--tests", "--deadline=10m", "--disable-all", "--enable=" + linter} build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...) } } diff --git a/build/goimports.sh b/build/goimports.sh new file mode 100755 index 0000000000..6d67ef1f0f --- /dev/null +++ b/build/goimports.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +find_files() { + find . -not \( \ + \( \ + -wholename '.github' \ + -o -wholename './build/_workspace' \ + -o -wholename './build/bin' \ + -o -wholename './crypto/bn256' \ + -o -wholename '*/vendor/*' \ + \) -prune \ + \) -name '*.go' +} + +GOFMT="gofmt -s -w"; +GOIMPORTS="goimports -w"; +find_files | xargs $GOFMT; +find_files | xargs $GOIMPORTS; \ No newline at end of file diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 2f0188f2bf..6e4c1724aa 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -23,17 +23,18 @@ import ( "context" "crypto/rand" "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" "io" "io/ioutil" "os" + "os/signal" "os/user" "path/filepath" "runtime" "strings" - "encoding/hex" "github.com/EthereumCommonwealth/go-callisto/cmd/utils" "github.com/EthereumCommonwealth/go-callisto/common" "github.com/EthereumCommonwealth/go-callisto/crypto" @@ -44,7 +45,6 @@ import ( "github.com/EthereumCommonwealth/go-callisto/signer/rules" "github.com/EthereumCommonwealth/go-callisto/signer/storage" "gopkg.in/urfave/cli.v1" - "os/signal" ) // ExternalApiVersion -- see extapi_changelog.md @@ -54,13 +54,13 @@ const ExternalApiVersion = "2.0.0" const InternalApiVersion = "2.0.0" const legalWarning = ` -WARNING! +WARNING! Clef is alpha software, and not yet publically released. This software has _not_ been audited, and there are no guarantees about the workings of this software. It may contain severe flaws. You should not use this software -unless you agree to take full responsibility for doing so, and know what you are doing. +unless you agree to take full responsibility for doing so, and know what you are doing. -TLDR; THIS IS NOT PRODUCTION-READY SOFTWARE! +TLDR; THIS IS NOT PRODUCTION-READY SOFTWARE! ` @@ -130,7 +130,7 @@ var ( configdirFlag, }, Description: ` -The init command generates a master seed which Clef can use to store credentials and data needed for +The init command generates a master seed which Clef can use to store credentials and data needed for the rule-engine to work.`, } attestCommand = cli.Command{ @@ -144,10 +144,10 @@ the rule-engine to work.`, signerSecretFlag, }, Description: ` -The attest command stores the sha256 of the rule.js-file that you want to use for automatic processing of -incoming requests. +The attest command stores the sha256 of the rule.js-file that you want to use for automatic processing of +incoming requests. -Whenever you make an edit to the rule file, you need to use attestation to tell +Whenever you make an edit to the rule file, you need to use attestation to tell Clef that the file is 'safe' to execute.`, } @@ -162,7 +162,7 @@ Clef that the file is 'safe' to execute.`, signerSecretFlag, }, Description: ` -The addpw command stores a password for a given address (keyfile). If you invoke it with only one parameter, it will +The addpw command stores a password for a given address (keyfile). If you invoke it with only one parameter, it will remove any stored credential for that address (keyfile) `, } @@ -231,12 +231,12 @@ func initializeSecrets(c *cli.Context) error { } fmt.Printf("A master seed has been generated into %s\n", location) fmt.Printf(` -This is required to be able to store credentials, such as : +This is required to be able to store credentials, such as : * Passwords for keystores (used by rule engine) * Storage for javascript rules * Hash of rule-file -You should treat that file with utmost secrecy, and make a backup of it. +You should treat that file with utmost secrecy, and make a backup of it. NOTE: This file does not contain your accounts. Those need to be backed up separately! `) @@ -435,7 +435,7 @@ func signer(c *cli.Context) error { ipcApiUrl = filepath.Join(configDir, "clef.ipc") } - listener, _, err := rpc.StartIPCEndpoint(func() bool { return true }, ipcApiUrl, rpcApi) + listener, _, err := rpc.StartIPCEndpoint(ipcApiUrl, rpcApi) if err != nil { utils.Fatalf("Could not start IPC api: %v", err) } diff --git a/cmd/ethkey/main.go b/cmd/ethkey/main.go index 4293720956..7881bc2ae6 100644 --- a/cmd/ethkey/main.go +++ b/cmd/ethkey/main.go @@ -53,10 +53,6 @@ var ( Name: "json", Usage: "output JSON instead of human-readable format", } - messageFlag = cli.StringFlag{ - Name: "message", - Usage: "the file that contains the message to sign/verify", - } ) func main() { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index ff72f91cac..1ec262d208 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -146,7 +146,7 @@ func init() { // Initialize the CLI app and start Geth app.Action = geth app.HideVersion = true // we have a command to print the version - app.Copyright = "Copyright 2013-2017 The go-ethereum Authors" + app.Copyright = "Copyright 2013-2018 The go-ethereum Authors" app.Commands = []cli.Command{ // See chaincmd.go: initCommand, @@ -241,7 +241,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { stack.AccountManager().Subscribe(events) go func() { - // Create an chain state reader for self-derivation + // Create a chain state reader for self-derivation rpcClient, err := stack.Attach() if err != nil { utils.Fatalf("Failed to attach to self: %v", err) diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index a02bc46225..17aadf7909 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -33,7 +33,7 @@ import ( var AppHelpTemplate = `NAME: {{.App.Name}} - {{.App.Usage}} - Copyright 2013-2017 The go-ethereum Authors + Copyright 2013-2018 The go-ethereum Authors USAGE: {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}} diff --git a/cmd/puppeth/module_dashboard.go b/cmd/puppeth/module_dashboard.go index 64832c350c..0d80c772ed 100644 --- a/cmd/puppeth/module_dashboard.go +++ b/cmd/puppeth/module_dashboard.go @@ -683,7 +683,7 @@ func deployDashboard(client *sshClient, network string, conf *config, config *da return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s up -d --build --force-recreate", workdir, network)) } -// dashboardInfos is returned from an dashboard status check to allow reporting +// dashboardInfos is returned from a dashboard status check to allow reporting // various configuration parameters. type dashboardInfos struct { host string diff --git a/cmd/puppeth/module_explorer.go b/cmd/puppeth/module_explorer.go index ef90d84d8d..bd94d4ef55 100644 --- a/cmd/puppeth/module_explorer.go +++ b/cmd/puppeth/module_explorer.go @@ -168,7 +168,7 @@ func (info *explorerInfos) Report() map[string]string { return report } -// checkExplorer does a health-check against an block explorer server to verify +// checkExplorer does a health-check against a block explorer server to verify // whether it's running, and if yes, whether it's responsive. func checkExplorer(client *sshClient, network string) (*explorerInfos, error) { // Inspect a possible block explorer container on the host diff --git a/cmd/puppeth/module_faucet.go b/cmd/puppeth/module_faucet.go index a1147a1e3b..25a16016ad 100644 --- a/cmd/puppeth/module_faucet.go +++ b/cmd/puppeth/module_faucet.go @@ -30,7 +30,7 @@ import ( "github.com/EthereumCommonwealth/go-callisto/log" ) -// faucetDockerfile is the Dockerfile required to build an faucet container to +// faucetDockerfile is the Dockerfile required to build a faucet container to // grant crypto tokens based on GitHub authentications. var faucetDockerfile = ` FROM ethereum/client-go:alltools-latest @@ -138,7 +138,7 @@ func deployFaucet(client *sshClient, network string, bootnodes []string, config return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s up -d --build --force-recreate", workdir, network)) } -// faucetInfos is returned from an faucet status check to allow reporting various +// faucetInfos is returned from a faucet status check to allow reporting various // configuration parameters. type faucetInfos struct { node *nodeInfos @@ -181,7 +181,7 @@ func (info *faucetInfos) Report() map[string]string { return report } -// checkFaucet does a health-check against an faucet server to verify whether +// checkFaucet does a health-check against a faucet server to verify whether // it's running, and if yes, gathering a collection of useful infos about it. func checkFaucet(client *sshClient, network string) (*faucetInfos, error) { // Inspect a possible faucet container on the host diff --git a/cmd/puppeth/module_node.go b/cmd/puppeth/module_node.go index 82c425e5ee..5a966474d9 100644 --- a/cmd/puppeth/module_node.go +++ b/cmd/puppeth/module_node.go @@ -40,11 +40,11 @@ ADD genesis.json /genesis.json ADD signer.pass /signer.pass {{end}} RUN \ - echo 'geth --cache 512 init /genesis.json' > /root/geth.sh && \{{if .Unlock}} - echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> /root/geth.sh && \{{end}} - echo $'geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .Bootnodes}}--bootnodes {{.Bootnodes}}{{end}} {{if .Etherbase}}--etherbase {{.Etherbase}} --mine --minerthreads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> /root/geth.sh + echo 'geth --cache 512 init /genesis.json' > geth.sh && \{{if .Unlock}} + echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> geth.sh && \{{end}} + echo $'geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .Bootnodes}}--bootnodes {{.Bootnodes}}{{end}} {{if .Etherbase}}--etherbase {{.Etherbase}} --mine --minerthreads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> geth.sh -ENTRYPOINT ["/bin/sh", "/root/geth.sh"] +ENTRYPOINT ["/bin/sh", "geth.sh"] ` // nodeComposefile is the docker-compose.yml file required to deploy and maintain @@ -198,7 +198,7 @@ func (info *nodeInfos) Report() map[string]string { return report } -// checkNode does a health-check against an boot or seal node server to verify +// checkNode does a health-check against a boot or seal node server to verify // whether it's running, and if yes, whether it's responsive. func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error) { kind := "bootnode" diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8306a90794..8b08b37992 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -64,7 +64,7 @@ var ( {{if .cmd.Description}}{{.cmd.Description}} {{end}}{{if .cmd.Subcommands}} SUBCOMMANDS: - {{range .cmd.Subcommands}}{{.cmd.Name}}{{with .cmd.ShortName}}, {{.cmd}}{{end}}{{ "\t" }}{{.cmd.Usage}} + {{range .cmd.Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} {{end}}{{end}}{{if .categorizedFlags}} {{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS: {{range $categorized.Flags}}{{"\t"}}{{.}} diff --git a/common/types.go b/common/types.go index 3fb8b595f5..06cc9bbbda 100644 --- a/common/types.go +++ b/common/types.go @@ -18,12 +18,11 @@ package common import ( "encoding/hex" + "encoding/json" "fmt" "math/big" "math/rand" "reflect" - - "encoding/json" "strings" "github.com/EthereumCommonwealth/go-callisto/common/hexutil" diff --git a/console/bridge.go b/console/bridge.go index c5d85b24cd..263e81a003 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -87,7 +87,7 @@ func (b *bridge) NewAccount(call otto.FunctionCall) (response otto.Value) { // OpenWallet is a wrapper around personal.openWallet which can interpret and // react to certain error messages, such as the Trezor PIN matrix request. func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) { - // Make sure we have an wallet specified to open + // Make sure we have a wallet specified to open if !call.Argument(0).IsString() { throwJSException("first argument must be the wallet URL to open") } diff --git a/core/asm/compiler.go b/core/asm/compiler.go index 9875f0e695..2d1fabb813 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -17,7 +17,6 @@ package asm import ( - "errors" "fmt" "math/big" "os" @@ -237,19 +236,16 @@ func (c *Compiler) pushBin(v interface{}) { // isPush returns whether the string op is either any of // push(N). func isPush(op string) bool { - return op == "push" + return strings.ToUpper(op) == "PUSH" } // isJump returns whether the string op is jump(i) func isJump(op string) bool { - return op == "jumpi" || op == "jump" + return strings.ToUpper(op) == "JUMPI" || strings.ToUpper(op) == "JUMP" } // toBinary converts text to a vm.OpCode func toBinary(text string) vm.OpCode { - if isPush(text) { - text = "push1" - } return vm.StringToOp(strings.ToUpper(text)) } @@ -264,11 +260,6 @@ func (err compileError) Error() string { return fmt.Sprintf("%d syntax error: unexpected %v, expected %v", err.lineno, err.got, err.want) } -var ( - errExpBol = errors.New("expected beginning of line") - errExpElementOrLabel = errors.New("expected beginning of line") -) - func compileErr(c token, got, want string) error { return compileError{ got: got, diff --git a/core/bloombits/matcher.go b/core/bloombits/matcher.go index 9f6ee67cc4..b5cd27b233 100644 --- a/core/bloombits/matcher.go +++ b/core/bloombits/matcher.go @@ -392,7 +392,7 @@ func (m *Matcher) distributor(dist chan *request, session *MatcherSession) { shutdown = session.quit // Shutdown request channel, will gracefully wait for pending requests ) - // assign is a helper method fo try to assign a pending bit an an actively + // assign is a helper method fo try to assign a pending bit an actively // listening servicer, or schedule it up for later when one arrives. assign := func(bit uint) { select { diff --git a/core/tx_pool.go b/core/tx_pool.go index 31a0ae0195..fa28fca80c 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -38,8 +38,6 @@ import ( const ( // chainHeadChanSize is the size of channel listening to ChainHeadEvent. chainHeadChanSize = 10 - // rmTxChanSize is the size of channel listening to RemovedTransactionEvent. - rmTxChanSize = 10 ) var ( diff --git a/core/types/transaction.go b/core/types/transaction.go index 4ba314c1e4..9410526692 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -33,7 +33,6 @@ import ( var ( ErrInvalidSig = errors.New("invalid transaction v, r, s values") - errNoSigner = errors.New("missing signing methods") ) // deriveSigner makes a *best* guess about which signer to use. diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 63b8c909d5..7a901f2928 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -31,7 +31,6 @@ import ( var ( bigZero = new(big.Int) tt255 = math.BigPow(2, 255) - tt256 = math.BigPow(2, 256) errWriteProtection = errors.New("evm: write protection") errReturnDataOutOfBounds = errors.New("evm: return data out of bounds") errExecutionReverted = errors.New("evm: execution reverted") diff --git a/crypto/bn256/cloudflare/example_test.go b/crypto/bn256/cloudflare/example_test.go index b2d19807a2..6c285995cb 100644 --- a/crypto/bn256/cloudflare/example_test.go +++ b/crypto/bn256/cloudflare/example_test.go @@ -6,9 +6,12 @@ package bn256 import ( "crypto/rand" + "testing" + + "github.com/stretchr/testify/require" ) -func ExamplePair() { +func TestExamplePair(t *testing.T) { // This implements the tripartite Diffie-Hellman algorithm from "A One // Round Protocol for Tripartite Diffie-Hellman", A. Joux. // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf @@ -40,4 +43,9 @@ func ExamplePair() { k3.ScalarMult(k3, c) // k1, k2 and k3 will all be equal. + + require.Equal(t, k1, k2) + require.Equal(t, k1, k3) + + require.Equal(t, len(np), 4) //Avoid gometalinter varcheck err on np } diff --git a/eth/downloader/api.go b/eth/downloader/api.go index c394089f61..57b3e7c561 100644 --- a/eth/downloader/api.go +++ b/eth/downloader/api.go @@ -51,7 +51,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP return api } -// eventLoop runs an loop until the event mux closes. It will install and uninstall new +// eventLoop runs a loop until the event mux closes. It will install and uninstall new // sync subscriptions and broadcasts sync status updates to the installed sync subscriptions. func (api *PublicDownloaderAPI) eventLoop() { var ( diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 00deee75f9..b4fe3f95a4 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -306,7 +306,7 @@ func (d *Downloader) UnregisterPeer(id string) error { d.cancelLock.RUnlock() if master { - d.Cancel() + d.cancel() } return nil } @@ -501,8 +501,10 @@ func (d *Downloader) spawnSync(fetchers []func() error) error { return err } -// Cancel cancels all of the operations and resets the queue. -func (d *Downloader) Cancel() { +// cancel aborts all of the operations and resets the queue. However, cancel does +// not wait for the running download goroutines to finish. This method should be +// used when cancelling the downloads from inside the downloader. +func (d *Downloader) cancel() { // Close the current cancel channel d.cancelLock.Lock() if d.cancelCh != nil { @@ -514,6 +516,12 @@ func (d *Downloader) Cancel() { } } d.cancelLock.Unlock() +} + +// Cancel aborts all of the operations and waits for all download goroutines to +// finish before returning. +func (d *Downloader) Cancel() { + d.cancel() d.cancelWg.Wait() } diff --git a/eth/fetcher/fetcher_test.go b/eth/fetcher/fetcher_test.go index f7ad367b01..e43db4a3b3 100644 --- a/eth/fetcher/fetcher_test.go +++ b/eth/fetcher/fetcher_test.go @@ -198,7 +198,7 @@ func (f *fetcherTester) makeBodyFetcher(peer string, blocks map[common.Hash]*typ } } -// verifyFetchingEvent verifies that one single event arrive on an fetching channel. +// verifyFetchingEvent verifies that one single event arrive on a fetching channel. func verifyFetchingEvent(t *testing.T, fetching chan []common.Hash, arrive bool) { if arrive { select { diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 3b192633fc..fd657aed2e 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -39,7 +39,11 @@ type Client struct { // Dial connects a client to the given URL. func Dial(rawurl string) (*Client, error) { - c, err := rpc.Dial(rawurl) + return DialContext(context.Background(), rawurl) +} + +func DialContext(ctx context.Context, rawurl string) (*Client, error) { + c, err := rpc.DialContext(ctx, rawurl) if err != nil { return nil, err } @@ -51,6 +55,10 @@ func NewClient(c *rpc.Client) *Client { return &Client{c} } +func (ec *Client) Close() { + ec.c.Close() +} + // Blockchain Access // BlockByHash returns the given full block. diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 38e426baff..5cb527317e 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -2193,7 +2193,7 @@ var toWei = function(number, unit) { }; /** - * Takes an input and transforms it into an bignumber + * Takes an input and transforms it into a bignumber * * @method toBigNumber * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber diff --git a/les/bloombits.go b/les/bloombits.go index 1f9076b34b..869bceb38a 100644 --- a/les/bloombits.go +++ b/les/bloombits.go @@ -72,13 +72,3 @@ func (eth *LightEthereum) startBloomHandlers() { }() } } - -const ( - // bloomConfirms is the number of confirmation blocks before a bloom section is - // considered probably final and its rotated bits are calculated. - bloomConfirms = 256 - - // bloomThrottling is the time to wait between processing two consecutive index - // sections. It's useful during chain upgrades to prevent disk overload. - bloomThrottling = 100 * time.Millisecond -) diff --git a/les/serverpool.go b/les/serverpool.go index 545a250ceb..2954f44594 100644 --- a/les/serverpool.go +++ b/les/serverpool.go @@ -73,7 +73,6 @@ const ( // and a short term value which is adjusted exponentially with a factor of // pstatRecentAdjust with each dial/connection and also returned exponentially // to the average with the time constant pstatReturnToMeanTC - pstatRecentAdjust = 0.1 pstatReturnToMeanTC = time.Hour // node address selection weight is dropped by a factor of exp(-addrFailDropLn) after // each unsuccessful connection (restored after a successful one) @@ -83,9 +82,6 @@ const ( responseScoreTC = time.Millisecond * 100 delayScoreTC = time.Second * 5 timeoutPow = 10 - // peerSelectMinWeight is added to calculated weights at request peer selection - // to give poorly performing peers a little chance of coming back - peerSelectMinWeight = 0.005 // initStatsWeight is used to initialize previously unknown peers with good // statistics to give a chance to prove themselves initStatsWeight = 1 diff --git a/les/sync.go b/les/sync.go index 19875f7a06..1e13f3f90f 100644 --- a/les/sync.go +++ b/les/sync.go @@ -25,11 +25,6 @@ import ( "github.com/EthereumCommonwealth/go-callisto/light" ) -const ( - //forceSyncCycle = 10 * time.Second // Time interval to force syncs, even if few peers are available - minDesiredPeerCount = 5 // Amount of peers desired to start syncing -) - // syncer is responsible for periodically synchronising with the network, both // downloading hashes and blocks as well as handling the announcement handler. func (pm *ProtocolManager) syncer() { diff --git a/mobile/types.go b/mobile/types.go index 3bcb8615ca..f571f61048 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -80,7 +80,7 @@ func (h *Header) EncodeRLP() ([]byte, error) { return rlp.EncodeToBytes(h.header) } -// NewHeaderFromJSON parses a header from an JSON data dump. +// NewHeaderFromJSON parses a header from a JSON data dump. func NewHeaderFromJSON(data string) (*Header, error) { h := &Header{ header: new(types.Header), @@ -91,7 +91,7 @@ func NewHeaderFromJSON(data string) (*Header, error) { return h, nil } -// EncodeJSON encodes a header into an JSON data dump. +// EncodeJSON encodes a header into a JSON data dump. func (h *Header) EncodeJSON() (string, error) { data, err := json.Marshal(h.header) return string(data), err @@ -151,7 +151,7 @@ func (b *Block) EncodeRLP() ([]byte, error) { return rlp.EncodeToBytes(b.block) } -// NewBlockFromJSON parses a block from an JSON data dump. +// NewBlockFromJSON parses a block from a JSON data dump. func NewBlockFromJSON(data string) (*Block, error) { b := &Block{ block: new(types.Block), @@ -162,7 +162,7 @@ func NewBlockFromJSON(data string) (*Block, error) { return b, nil } -// EncodeJSON encodes a block into an JSON data dump. +// EncodeJSON encodes a block into a JSON data dump. func (b *Block) EncodeJSON() (string, error) { data, err := json.Marshal(b.block) return string(data), err @@ -220,7 +220,7 @@ func (tx *Transaction) EncodeRLP() ([]byte, error) { return rlp.EncodeToBytes(tx.tx) } -// NewTransactionFromJSON parses a transaction from an JSON data dump. +// NewTransactionFromJSON parses a transaction from a JSON data dump. func NewTransactionFromJSON(data string) (*Transaction, error) { tx := &Transaction{ tx: new(types.Transaction), @@ -231,7 +231,7 @@ func NewTransactionFromJSON(data string) (*Transaction, error) { return tx, nil } -// EncodeJSON encodes a transaction into an JSON data dump. +// EncodeJSON encodes a transaction into a JSON data dump. func (tx *Transaction) EncodeJSON() (string, error) { data, err := json.Marshal(tx.tx) return string(data), err @@ -312,7 +312,7 @@ func (r *Receipt) EncodeRLP() ([]byte, error) { return rlp.EncodeToBytes(r.receipt) } -// NewReceiptFromJSON parses a transaction receipt from an JSON data dump. +// NewReceiptFromJSON parses a transaction receipt from a JSON data dump. func NewReceiptFromJSON(data string) (*Receipt, error) { r := &Receipt{ receipt: new(types.Receipt), @@ -323,7 +323,7 @@ func NewReceiptFromJSON(data string) (*Receipt, error) { return r, nil } -// EncodeJSON encodes a transaction receipt into an JSON data dump. +// EncodeJSON encodes a transaction receipt into a JSON data dump. func (r *Receipt) EncodeJSON() (string, error) { data, err := rlp.EncodeToBytes(r.receipt) return string(data), err diff --git a/node/config.go b/node/config.go index 6f7ed6e150..0ed12b1ef6 100644 --- a/node/config.go +++ b/node/config.go @@ -209,7 +209,7 @@ func DefaultHTTPEndpoint() string { return config.HTTPEndpoint() } -// WSEndpoint resolves an websocket endpoint based on the configured host interface +// WSEndpoint resolves a websocket endpoint based on the configured host interface // and port parameters. func (c *Config) WSEndpoint() string { if c.WSHost == "" { diff --git a/node/node.go b/node/node.go index ea4450e883..f7c212c3f7 100644 --- a/node/node.go +++ b/node/node.go @@ -303,23 +303,13 @@ func (n *Node) stopInProc() { // startIPC initializes and starts the IPC RPC endpoint. func (n *Node) startIPC(apis []rpc.API) error { - // Short circuit if the IPC endpoint isn't being exposed if n.ipcEndpoint == "" { - return nil - + return nil // IPC disabled. } - isClosed := func() bool { - n.lock.RLock() - defer n.lock.RUnlock() - return n.ipcListener == nil - } - - listener, handler, err := rpc.StartIPCEndpoint(isClosed, n.ipcEndpoint, apis) + listener, handler, err := rpc.StartIPCEndpoint(n.ipcEndpoint, apis) if err != nil { return err } - - // All listeners booted successfully n.ipcListener = listener n.ipcHandler = handler n.log.Info("IPC endpoint opened", "url", n.ipcEndpoint) diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index cc95e6a006..d0028729e7 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -49,7 +49,6 @@ var ( // Timeouts const ( respTimeout = 500 * time.Millisecond - sendTimeout = 500 * time.Millisecond expiration = 20 * time.Second ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go index cc9a8cbe6e..eebcd8d673 100644 --- a/p2p/discv5/net.go +++ b/p2p/discv5/net.go @@ -36,7 +36,6 @@ import ( var ( errInvalidEvent = errors.New("invalid in current state") errNoQuery = errors.New("no pending query") - errWrongAddress = errors.New("unknown sender address") ) const ( @@ -828,11 +827,10 @@ type nodeEvent uint //go:generate stringer -type=nodeEvent const ( - invalidEvent nodeEvent = iota // zero is reserved // Packet type events. // These correspond to packet types in the UDP protocol. - pingPacket + pingPacket = iota + 1 pongPacket findnodePacket neighborsPacket diff --git a/p2p/discv5/nodeevent_string.go b/p2p/discv5/nodeevent_string.go index eb696fb8be..38c1993bac 100644 --- a/p2p/discv5/nodeevent_string.go +++ b/p2p/discv5/nodeevent_string.go @@ -4,24 +4,14 @@ package discv5 import "strconv" -const ( - _nodeEvent_name_0 = "invalidEventpingPacketpongPacketfindnodePacketneighborsPacketfindnodeHashPackettopicRegisterPackettopicQueryPackettopicNodesPacket" - _nodeEvent_name_1 = "pongTimeoutpingTimeoutneighboursTimeout" -) +const _nodeEvent_name = "pongTimeoutpingTimeoutneighboursTimeout" -var ( - _nodeEvent_index_0 = [...]uint8{0, 12, 22, 32, 46, 61, 79, 98, 114, 130} - _nodeEvent_index_1 = [...]uint8{0, 11, 22, 39} -) +var _nodeEvent_index = [...]uint8{0, 11, 22, 39} func (i nodeEvent) String() string { - switch { - case 0 <= i && i <= 8: - return _nodeEvent_name_0[_nodeEvent_index_0[i]:_nodeEvent_index_0[i+1]] - case 265 <= i && i <= 267: - i -= 265 - return _nodeEvent_name_1[_nodeEvent_index_1[i]:_nodeEvent_index_1[i+1]] - default: - return "nodeEvent(" + strconv.FormatInt(int64(i), 10) + ")" + i -= 264 + if i >= nodeEvent(len(_nodeEvent_index)-1) { + return "nodeEvent(" + strconv.FormatInt(int64(i+264), 10) + ")" } + return _nodeEvent_name[_nodeEvent_index[i]:_nodeEvent_index[i+1]] } diff --git a/p2p/discv5/table.go b/p2p/discv5/table.go index 0d25723536..be504f8258 100644 --- a/p2p/discv5/table.go +++ b/p2p/discv5/table.go @@ -38,7 +38,6 @@ const ( hashBits = len(common.Hash{}) * 8 nBuckets = hashBits + 1 // Number of buckets - maxBondingPingPongs = 16 maxFindnodeFailures = 5 ) diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go index 65650bca5a..017f28aceb 100644 --- a/p2p/discv5/udp.go +++ b/p2p/discv5/udp.go @@ -36,25 +36,17 @@ const Version = 4 // Errors var ( - errPacketTooSmall = errors.New("too small") - errBadPrefix = errors.New("bad prefix") - errExpired = errors.New("expired") - errUnsolicitedReply = errors.New("unsolicited reply") - errUnknownNode = errors.New("unknown node") - errTimeout = errors.New("RPC timeout") - errClockWarp = errors.New("reply deadline too far in the future") - errClosed = errors.New("socket closed") + errPacketTooSmall = errors.New("too small") + errBadPrefix = errors.New("bad prefix") + errTimeout = errors.New("RPC timeout") ) // Timeouts const ( respTimeout = 500 * time.Millisecond - queryDelay = 1000 * time.Millisecond expiration = 20 * time.Second - ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP - ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning - driftThreshold = 10 * time.Second // Allowed clock drift before warning user + driftThreshold = 10 * time.Second // Allowed clock drift before warning user ) // RPC request structures diff --git a/p2p/discv5/udp_test.go b/p2p/discv5/udp_test.go index 066ff489c0..0f87190a65 100644 --- a/p2p/discv5/udp_test.go +++ b/p2p/discv5/udp_test.go @@ -24,7 +24,6 @@ import ( "reflect" "sync" "testing" - "time" "github.com/davecgh/go-spew/spew" "github.com/EthereumCommonwealth/go-callisto/common" @@ -38,11 +37,7 @@ func init() { // shared test variables var ( - futureExp = uint64(time.Now().Add(10 * time.Hour).Unix()) - testTarget = NodeID{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1} - testRemote = rpcEndpoint{IP: net.ParseIP("1.1.1.1").To4(), UDP: 1, TCP: 2} - testLocalAnnounced = rpcEndpoint{IP: net.ParseIP("2.2.2.2").To4(), UDP: 3, TCP: 4} - testLocal = rpcEndpoint{IP: net.ParseIP("3.3.3.3").To4(), UDP: 5, TCP: 6} + testLocal = rpcEndpoint{IP: net.ParseIP("3.3.3.3").To4(), UDP: 5, TCP: 6} ) // type udpTest struct { diff --git a/p2p/enr/enr.go b/p2p/enr/enr.go index 391fcecd6b..b284b67ae2 100644 --- a/p2p/enr/enr.go +++ b/p2p/enr/enr.go @@ -46,7 +46,6 @@ const ID_SECP256k1_KECCAK = ID("secp256k1-keccak") // the default identity schem var ( errNoID = errors.New("unknown or unspecified identity scheme") - errInvalidSigsize = errors.New("invalid signature size") errInvalidSig = errors.New("invalid signature") errNotSorted = errors.New("record key/value pairs are not sorted by key") errDuplicateKey = errors.New("record contains duplicate key") diff --git a/p2p/peer.go b/p2p/peer.go index 477cd0fbea..81561e616c 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -47,8 +47,6 @@ const ( discMsg = 0x01 pingMsg = 0x02 pongMsg = 0x03 - getPeersMsg = 0x04 - peersMsg = 0x05 ) // protoHandshake is the RLP structure of the protocol handshake. diff --git a/params/version.go b/params/version.go index 4fc6ed22b0..689777b592 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 4 // Patch version component of the current release + VersionPatch = 6 // Patch version component of the current release VersionMeta = "CLO stable" // Version metadata to append to the version string ) diff --git a/rpc/client.go b/rpc/client.go index 1838fb8351..d9dcaae47f 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -25,6 +25,7 @@ import ( "fmt" "net" "net/url" + "os" "reflect" "strconv" "strings" @@ -32,8 +33,6 @@ import ( "sync/atomic" "time" - "os" - "github.com/EthereumCommonwealth/go-callisto/log" ) diff --git a/rpc/doc.go b/rpc/doc.go index 14b3780ade..78aa92f899 100644 --- a/rpc/doc.go +++ b/rpc/doc.go @@ -92,7 +92,7 @@ An example method: Subscriptions are deleted when: - the user sends an unsubscribe request - the connection which was used to create the subscription is closed. This can be initiated - by the client and server. The server will close the connection on an write error or when + by the client and server. The server will close the connection on a write error or when the queue of buffered notifications gets too big. */ package rpc diff --git a/rpc/endpoints.go b/rpc/endpoints.go index ec4ac6b0bd..195f88b474 100644 --- a/rpc/endpoints.go +++ b/rpc/endpoints.go @@ -17,8 +17,9 @@ package rpc import ( - "github.com/EthereumCommonwealth/go-callisto/log" "net" + + "github.com/EthereumCommonwealth/go-callisto/log" ) // StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules @@ -81,9 +82,9 @@ func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins [] } -// StartIPCEndpoint starts an IPC endpoint -func StartIPCEndpoint(isClosedFn func() bool, ipcEndpoint string, apis []API) (net.Listener, *Server, error) { - // Register all the APIs exposed by the services +// StartIPCEndpoint starts an IPC endpoint. +func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) { + // Register all the APIs exposed by the services. handler := NewServer() for _, api := range apis { if err := handler.RegisterName(api.Namespace, api.Service); err != nil { @@ -91,30 +92,11 @@ func StartIPCEndpoint(isClosedFn func() bool, ipcEndpoint string, apis []API) (n } log.Debug("IPC registered", "namespace", api.Namespace) } - // All APIs registered, start the IPC listener - var ( - listener net.Listener - err error - ) - if listener, err = CreateIPCListener(ipcEndpoint); err != nil { + // All APIs registered, start the IPC listener. + listener, err := ipcListen(ipcEndpoint) + if err != nil { return nil, nil, err } - go func() { - for { - conn, err := listener.Accept() - if err != nil { - // Terminate if the listener was closed - if isClosedFn() { - log.Info("IPC closed", "err", err) - } else { - // Not closed, just some error; report and continue - log.Error("IPC accept failed", "err", err) - } - continue - } - go handler.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) - } - }() - + go handler.ServeListener(listener) return listener, handler, nil } diff --git a/rpc/http.go b/rpc/http.go index 14b6c1ab42..0c2e060fb4 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -90,10 +90,19 @@ func DialHTTP(endpoint string) (*Client, error) { func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error { hc := c.writeConn.(*httpConn) respBody, err := hc.doRequest(ctx, msg) + if respBody != nil { + defer respBody.Close() + } + if err != nil { + if respBody != nil { + buf := new(bytes.Buffer) + if _, err2 := buf.ReadFrom(respBody); err2 == nil { + return fmt.Errorf("%v %v", err, buf.String()) + } + } return err } - defer respBody.Close() var respmsg jsonrpcMessage if err := json.NewDecoder(respBody).Decode(&respmsg); err != nil { return err @@ -132,6 +141,9 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos if err != nil { return nil, err } + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + return resp.Body, errors.New(resp.Status) + } return resp.Body, nil } diff --git a/rpc/ipc.go b/rpc/ipc.go index 2476a0743f..6b43f3bcc1 100644 --- a/rpc/ipc.go +++ b/rpc/ipc.go @@ -18,26 +18,23 @@ package rpc import ( "context" - "fmt" "net" "github.com/EthereumCommonwealth/go-callisto/log" + "github.com/EthereumCommonwealth/go-callisto/p2p/netutil" ) -// CreateIPCListener creates an listener, on Unix platforms this is a unix socket, on -// Windows this is a named pipe -func CreateIPCListener(endpoint string) (net.Listener, error) { - return ipcListen(endpoint) -} - // ServeListener accepts connections on l, serving JSON-RPC on them. func (srv *Server) ServeListener(l net.Listener) error { for { conn, err := l.Accept() - if err != nil { + if netutil.IsTemporaryError(err) { + log.Warn("RPC accept error", "err", err) + continue + } else if err != nil { return err } - log.Trace(fmt.Sprint("accepted conn", conn.RemoteAddr())) + log.Trace("Accepted connection", "addr", conn.RemoteAddr()) go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) } } diff --git a/swarm/fuse/fuse_dir.go b/swarm/fuse/fuse_dir.go index 91b236ae8a..a7701985eb 100644 --- a/swarm/fuse/fuse_dir.go +++ b/swarm/fuse/fuse_dir.go @@ -19,12 +19,13 @@ package fuse import ( - "bazil.org/fuse" - "bazil.org/fuse/fs" - "golang.org/x/net/context" "os" "path/filepath" "sync" + + "bazil.org/fuse" + "bazil.org/fuse/fs" + "golang.org/x/net/context" ) var ( diff --git a/swarm/fuse/swarmfs.go b/swarm/fuse/swarmfs.go index c6251accf0..84ad4f450c 100644 --- a/swarm/fuse/swarmfs.go +++ b/swarm/fuse/swarmfs.go @@ -17,9 +17,10 @@ package fuse import ( - "github.com/EthereumCommonwealth/go-callisto/swarm/api" "sync" "time" + + "github.com/EthereumCommonwealth/go-callisto/swarm/api" ) const ( diff --git a/swarm/network/kademlia/address.go b/swarm/network/kademlia/address.go index 86b9c380c3..5e029c7142 100644 --- a/swarm/network/kademlia/address.go +++ b/swarm/network/kademlia/address.go @@ -51,7 +51,7 @@ func (a Address) Bin() string { /* Proximity(x, y) returns the proximity order of the MSB distance between x and y -The distance metric MSB(x, y) of two equal length byte sequences x an y is the +The distance metric MSB(x, y) of two equal length byte sequences x and y is the value of the binary integer cast of the x^y, ie., x and y bitwise xor-ed. the binary cast is big endian: most significant bit first (=MSB). diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 0012982a10..bffbee0e3a 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -54,7 +54,6 @@ const ( // key prefixes for leveldb storage kpIndex = 0 - kpData = 1 ) var ( diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 6995e9e183..9564f8df45 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -83,11 +83,6 @@ func NewNetStore(hash SwarmHasher, lstore *LocalStore, cloud CloudStore, params } } -const ( - // maximum number of peers that a retrieved message is delivered to - requesterCount = 3 -) - var ( // timeout interval before retrieval is timed out searchTimeout = 3 * time.Second diff --git a/vendor/github.com/elastic/gosigar/CHANGELOG.md b/vendor/github.com/elastic/gosigar/CHANGELOG.md index 12695e10ef..45262e7b8d 100644 --- a/vendor/github.com/elastic/gosigar/CHANGELOG.md +++ b/vendor/github.com/elastic/gosigar/CHANGELOG.md @@ -8,10 +8,21 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Added missing runtime import for FreeBSD. #104 + ### Changed ### Deprecated +## [0.9.0] + +### Added +- Added support for huge TLB pages on Linux #97 +- Added support for big endian platform #100 + +### Fixed +- Add missing method for OpenBSD #99 + ## [0.8.0] ### Added diff --git a/vendor/github.com/elastic/gosigar/README.md b/vendor/github.com/elastic/gosigar/README.md index 2482620a83..ecdfc1c3c5 100644 --- a/vendor/github.com/elastic/gosigar/README.md +++ b/vendor/github.com/elastic/gosigar/README.md @@ -26,6 +26,7 @@ The features vary by operating system. | FDUsage | X | | | | X | | FileSystemList | X | X | X | X | X | | FileSystemUsage | X | X | X | X | X | +| HugeTLBPages | X | | | | | | LoadAverage | X | X | | X | X | | Mem | X | X | X | X | X | | ProcArgs | X | X | X | | X | diff --git a/vendor/github.com/elastic/gosigar/concrete_sigar.go b/vendor/github.com/elastic/gosigar/concrete_sigar.go index 685aa6dedd..e3ee80a980 100644 --- a/vendor/github.com/elastic/gosigar/concrete_sigar.go +++ b/vendor/github.com/elastic/gosigar/concrete_sigar.go @@ -62,6 +62,12 @@ func (c *ConcreteSigar) GetSwap() (Swap, error) { return s, err } +func (c *ConcreteSigar) GetHugeTLBPages() (HugeTLBPages, error) { + p := HugeTLBPages{} + err := p.Get() + return p, err +} + func (c *ConcreteSigar) GetFileSystemUsage(path string) (FileSystemUsage, error) { f := FileSystemUsage{} err := f.Get(path) diff --git a/vendor/github.com/elastic/gosigar/sigar_darwin.go b/vendor/github.com/elastic/gosigar/sigar_darwin.go index f989f51608..a90b998c2e 100644 --- a/vendor/github.com/elastic/gosigar/sigar_darwin.go +++ b/vendor/github.com/elastic/gosigar/sigar_darwin.go @@ -91,6 +91,10 @@ func (self *Swap) Get() error { return nil } +func (self *HugeTLBPages) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + func (self *Cpu) Get() error { var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT var cpuload C.host_cpu_load_info_data_t diff --git a/vendor/github.com/elastic/gosigar/sigar_freebsd.go b/vendor/github.com/elastic/gosigar/sigar_freebsd.go index 602b4a0aad..9b2af639b6 100644 --- a/vendor/github.com/elastic/gosigar/sigar_freebsd.go +++ b/vendor/github.com/elastic/gosigar/sigar_freebsd.go @@ -4,6 +4,7 @@ package gosigar import ( "io/ioutil" + "runtime" "strconv" "strings" "unsafe" @@ -97,6 +98,10 @@ func (self *ProcFDUsage) Get(pid int) error { return nil } +func (self *HugeTLBPages) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + func parseCpuStat(self *Cpu, line string) error { fields := strings.Fields(line) diff --git a/vendor/github.com/elastic/gosigar/sigar_interface.go b/vendor/github.com/elastic/gosigar/sigar_interface.go index a956af604a..df79ae08d2 100644 --- a/vendor/github.com/elastic/gosigar/sigar_interface.go +++ b/vendor/github.com/elastic/gosigar/sigar_interface.go @@ -26,6 +26,7 @@ type Sigar interface { GetLoadAverage() (LoadAverage, error) GetMem() (Mem, error) GetSwap() (Swap, error) + GetHugeTLBPages(HugeTLBPages, error) GetFileSystemUsage(string) (FileSystemUsage, error) GetFDUsage() (FDUsage, error) GetRusage(who int) (Rusage, error) @@ -82,6 +83,15 @@ type Swap struct { Free uint64 } +type HugeTLBPages struct { + Total uint64 + Free uint64 + Reserved uint64 + Surplus uint64 + DefaultSize uint64 + TotalAllocatedSize uint64 +} + type CpuList struct { List []Cpu } diff --git a/vendor/github.com/elastic/gosigar/sigar_linux.go b/vendor/github.com/elastic/gosigar/sigar_linux.go index cb1d3525b5..09f2e30b2f 100644 --- a/vendor/github.com/elastic/gosigar/sigar_linux.go +++ b/vendor/github.com/elastic/gosigar/sigar_linux.go @@ -45,6 +45,30 @@ func (self *FDUsage) Get() error { }) } +func (self *HugeTLBPages) Get() error { + table, err := parseMeminfo() + if err != nil { + return err + } + + self.Total, _ = table["HugePages_Total"] + self.Free, _ = table["HugePages_Free"] + self.Reserved, _ = table["HugePages_Rsvd"] + self.Surplus, _ = table["HugePages_Surp"] + self.DefaultSize, _ = table["Hugepagesize"] + + if totalSize, found := table["Hugetlb"]; found { + self.TotalAllocatedSize = totalSize + } else { + // If Hugetlb is not present, or huge pages of different sizes + // are used, this figure can be unaccurate. + // TODO (jsoriano): Extract information from /sys/kernel/mm/hugepages too + self.TotalAllocatedSize = (self.Total - self.Free + self.Reserved) * self.DefaultSize + } + + return nil +} + func (self *ProcFDUsage) Get(pid int) error { err := readFile(procFileName(pid, "limits"), func(line string) bool { if strings.HasPrefix(line, "Max open files") { diff --git a/vendor/github.com/elastic/gosigar/sigar_linux_common.go b/vendor/github.com/elastic/gosigar/sigar_linux_common.go index 8e5e7856f6..7ca6497622 100644 --- a/vendor/github.com/elastic/gosigar/sigar_linux_common.go +++ b/vendor/github.com/elastic/gosigar/sigar_linux_common.go @@ -379,12 +379,16 @@ func parseMeminfo() (map[string]uint64, error) { return true // skip on errors } - num := strings.TrimLeft(fields[1], " ") - val, err := strtoull(strings.Fields(num)[0]) + valueUnit := strings.Fields(fields[1]) + value, err := strtoull(valueUnit[0]) if err != nil { return true // skip on errors } - table[fields[0]] = val * 1024 //in bytes + + if len(valueUnit) > 1 && valueUnit[1] == "kB" { + value *= 1024 + } + table[fields[0]] = value return true }) @@ -420,8 +424,18 @@ func procFileName(pid int, name string) string { return Procd + "/" + strconv.Itoa(pid) + "/" + name } -func readProcFile(pid int, name string) ([]byte, error) { +func readProcFile(pid int, name string) (content []byte, err error) { path := procFileName(pid, name) + + // Panics have been reported when reading proc files, let's recover and + // report the path if this happens + // See https://github.com/elastic/beats/issues/6692 + defer func() { + if r := recover(); r != nil { + content = nil + err = fmt.Errorf("recovered panic when reading proc file '%s': %v", path, r) + } + }() contents, err := ioutil.ReadFile(path) if err != nil { diff --git a/vendor/github.com/elastic/gosigar/sigar_openbsd.go b/vendor/github.com/elastic/gosigar/sigar_openbsd.go index 4f1383a6ba..e4371b8b68 100644 --- a/vendor/github.com/elastic/gosigar/sigar_openbsd.go +++ b/vendor/github.com/elastic/gosigar/sigar_openbsd.go @@ -294,6 +294,10 @@ func (self *Swap) Get() error { return nil } +func (self *HugeTLBPages) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + func (self *Cpu) Get() error { load := [C.CPUSTATES]C.long{C.CP_USER, C.CP_NICE, C.CP_SYS, C.CP_INTR, C.CP_IDLE} @@ -381,6 +385,10 @@ func (self *ProcFDUsage) Get(pid int) error { return ErrNotImplemented{runtime.GOOS} } +func (self *Rusage) Get(pid int) error { + return ErrNotImplemented{runtime.GOOS} +} + func fillCpu(cpu *Cpu, load [C.CPUSTATES]C.long) { cpu.User = uint64(load[0]) cpu.Nice = uint64(load[1]) diff --git a/vendor/github.com/elastic/gosigar/sigar_stub.go b/vendor/github.com/elastic/gosigar/sigar_stub.go index 0b858f1c0c..de9565aec4 100644 --- a/vendor/github.com/elastic/gosigar/sigar_stub.go +++ b/vendor/github.com/elastic/gosigar/sigar_stub.go @@ -22,6 +22,10 @@ func (s *Swap) Get() error { return ErrNotImplemented{runtime.GOOS} } +func (s *HugeTLBPages) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + func (f *FDUsage) Get() error { return ErrNotImplemented{runtime.GOOS} } diff --git a/vendor/github.com/elastic/gosigar/sigar_windows.go b/vendor/github.com/elastic/gosigar/sigar_windows.go index 0cdf928d16..c2b54d8d7f 100644 --- a/vendor/github.com/elastic/gosigar/sigar_windows.go +++ b/vendor/github.com/elastic/gosigar/sigar_windows.go @@ -120,6 +120,10 @@ func (self *Swap) Get() error { return nil } +func (self *HugeTLBPages) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + func (self *Cpu) Get() error { idle, kernel, user, err := windows.GetSystemTimes() if err != nil { diff --git a/vendor/vendor.json b/vendor/vendor.json index 5ff50b285f..20d6b7715b 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -93,10 +93,10 @@ "revisionTime": "2016-05-12T03:30:02Z" }, { - "checksumSHA1": "Fc8BCxCoQ7ZmghDT6X1cASR10Ec=", + "checksumSHA1": "jElNoLEe7m/iaoF1vYIHyNaS2SE=", "path": "github.com/elastic/gosigar", - "revision": "a3814ce5008e612a0c6d027608b54e1d0d9a5613", - "revisionTime": "2018-01-22T22:25:45Z" + "revision": "37f05ff46ffa7a825d1b24cf2b62d4a4c1a9d2e8", + "revisionTime": "2018-03-30T10:04:40Z" }, { "checksumSHA1": "qDsgp2kAeI9nhj565HUScaUyjU4=", diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go index a7c531856a..32c0b469a6 100644 --- a/whisper/whisperv5/api.go +++ b/whisper/whisperv5/api.go @@ -32,10 +32,6 @@ import ( "github.com/EthereumCommonwealth/go-callisto/rpc" ) -const ( - filterTimeout = 300 // filters are considered timeout out after filterTimeout seconds -) - var ( ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key") ErrInvalidSymmetricKey = errors.New("invalid symmetric key") diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go index 3e97193daa..c99eaccd02 100644 --- a/whisper/whisperv6/api.go +++ b/whisper/whisperv6/api.go @@ -32,10 +32,6 @@ import ( "github.com/EthereumCommonwealth/go-callisto/rpc" ) -const ( - filterTimeout = 300 // filters are considered timeout out after filterTimeout seconds -) - // List of errors var ( ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key") @@ -231,8 +227,9 @@ type newMessageOverride struct { Padding hexutil.Bytes } -// Post a message on the Whisper network. -func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, error) { +// Post posts a message on the Whisper network. +// returns the hash of the message in case of success. +func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) { var ( symKeyGiven = len(req.SymKeyID) > 0 pubKeyGiven = len(req.PublicKey) > 0 @@ -241,7 +238,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er // user must specify either a symmetric or an asymmetric key if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) { - return false, ErrSymAsym + return nil, ErrSymAsym } params := &MessageParams{ @@ -256,20 +253,20 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er // Set key that is used to sign the message if len(req.Sig) > 0 { if params.Src, err = api.w.GetPrivateKey(req.Sig); err != nil { - return false, err + return nil, err } } // Set symmetric key that is used to encrypt the message if symKeyGiven { if params.Topic == (TopicType{}) { // topics are mandatory with symmetric encryption - return false, ErrNoTopics + return nil, ErrNoTopics } if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil { - return false, err + return nil, err } if !validateDataIntegrity(params.KeySym, aesKeyLength) { - return false, ErrInvalidSymmetricKey + return nil, ErrInvalidSymmetricKey } } @@ -277,36 +274,47 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er if pubKeyGiven { params.Dst = crypto.ToECDSAPub(req.PublicKey) if !ValidatePublicKey(params.Dst) { - return false, ErrInvalidPublicKey + return nil, ErrInvalidPublicKey } } // encrypt and sent message whisperMsg, err := NewSentMessage(params) if err != nil { - return false, err + return nil, err } + var result []byte env, err := whisperMsg.Wrap(params) if err != nil { - return false, err + return nil, err } // send to specific node (skip PoW check) if len(req.TargetPeer) > 0 { n, err := discover.ParseNode(req.TargetPeer) if err != nil { - return false, fmt.Errorf("failed to parse target peer: %s", err) + return nil, fmt.Errorf("failed to parse target peer: %s", err) } - return true, api.w.SendP2PMessage(n.ID[:], env) + err = api.w.SendP2PMessage(n.ID[:], env) + if err == nil { + hash := env.Hash() + result = hash[:] + } + return result, err } // ensure that the message PoW meets the node's minimum accepted PoW if req.PowTarget < api.w.MinPow() { - return false, ErrTooLowPoW + return nil, ErrTooLowPoW } - return true, api.w.Send(env) + err = api.w.Send(env) + if err == nil { + hash := env.Hash() + result = hash[:] + } + return result, err } //go:generate gencodec -type Criteria -field-override criteriaOverride -out gen_criteria_json.go