Merge 1.8.6

This commit is contained in:
Yohan Graterol 2018-04-23 17:34:51 -05:00
commit 362cdedca4
68 changed files with 277 additions and 239 deletions

View file

@ -12,11 +12,5 @@ FROM alpine:latest
RUN apk add --no-cache ca-certificates RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
RUN addgroup -g 1000 geth && \ EXPOSE 8545 8546 30303 30303/udp
adduser -h /root -D -u 1000 -G geth geth && \
chown geth:geth /root
USER geth
EXPOSE 8545 8546 30303 30303/udp 30304/udp
ENTRYPOINT ["geth"] ENTRYPOINT ["geth"]

View file

@ -12,10 +12,4 @@ FROM alpine:latest
RUN apk add --no-cache ca-certificates RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/ COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/
RUN addgroup -g 1000 geth && \ EXPOSE 8545 8546 30303 30303/udp
adduser -h /root -D -u 1000 -G geth geth && \
chown geth:geth /root
USER geth
EXPOSE 8545 8546 30303 30303/udp 30304/udp

View file

@ -37,6 +37,9 @@ ios:
test: all test: all
build/env.sh go run build/ci.go test build/env.sh go run build/ci.go test
lint: ## Run linters.
build/env.sh go run build/ci.go lint
clean: clean:
rm -fr build/_workspace/pkg/ $(GOBIN)/* rm -fr build/_workspace/pkg/ $(GOBIN)/*

View file

@ -1 +1 @@
1.8.4 1.8.6

View file

@ -53,11 +53,9 @@ const (
ledgerOpGetConfiguration ledgerOpcode = 0x06 // Returns specific wallet application configuration ledgerOpGetConfiguration ledgerOpcode = 0x06 // Returns specific wallet application configuration
ledgerP1DirectlyFetchAddress ledgerParam1 = 0x00 // Return address directly from the wallet 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 ledgerP1InitTransactionData ledgerParam1 = 0x00 // First transaction data block for signing
ledgerP1ContTransactionData ledgerParam1 = 0x80 // Subsequent 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 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 // errLedgerReplyInvalidHeader is the error message returned by a Ledger data exchange

View file

@ -329,7 +329,10 @@ func doLint(cmdline []string) {
// Run fast linters batched together // Run fast linters batched together
configs := []string{ configs := []string{
"--vendor", "--vendor",
"--tests",
"--disable-all", "--disable-all",
"--enable=goimports",
"--enable=varcheck",
"--enable=vet", "--enable=vet",
"--enable=gofmt", "--enable=gofmt",
"--enable=misspell", "--enable=misspell",
@ -340,7 +343,7 @@ func doLint(cmdline []string) {
// Run slow linters one by one // Run slow linters one by one
for _, linter := range []string{"unconvert", "gosimple"} { 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...)...) build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
} }
} }

18
build/goimports.sh Executable file
View file

@ -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;

View file

@ -23,17 +23,18 @@ import (
"context" "context"
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal"
"os/user" "os/user"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"encoding/hex"
"github.com/EthereumCommonwealth/go-callisto/cmd/utils" "github.com/EthereumCommonwealth/go-callisto/cmd/utils"
"github.com/EthereumCommonwealth/go-callisto/common" "github.com/EthereumCommonwealth/go-callisto/common"
"github.com/EthereumCommonwealth/go-callisto/crypto" "github.com/EthereumCommonwealth/go-callisto/crypto"
@ -44,7 +45,6 @@ import (
"github.com/EthereumCommonwealth/go-callisto/signer/rules" "github.com/EthereumCommonwealth/go-callisto/signer/rules"
"github.com/EthereumCommonwealth/go-callisto/signer/storage" "github.com/EthereumCommonwealth/go-callisto/signer/storage"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
"os/signal"
) )
// ExternalApiVersion -- see extapi_changelog.md // ExternalApiVersion -- see extapi_changelog.md
@ -435,7 +435,7 @@ func signer(c *cli.Context) error {
ipcApiUrl = filepath.Join(configDir, "clef.ipc") 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 { if err != nil {
utils.Fatalf("Could not start IPC api: %v", err) utils.Fatalf("Could not start IPC api: %v", err)
} }

View file

@ -53,10 +53,6 @@ var (
Name: "json", Name: "json",
Usage: "output JSON instead of human-readable format", 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() { func main() {

View file

@ -146,7 +146,7 @@ func init() {
// Initialize the CLI app and start Geth // Initialize the CLI app and start Geth
app.Action = geth app.Action = geth
app.HideVersion = true // we have a command to print the version 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{ app.Commands = []cli.Command{
// See chaincmd.go: // See chaincmd.go:
initCommand, initCommand,
@ -241,7 +241,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
stack.AccountManager().Subscribe(events) stack.AccountManager().Subscribe(events)
go func() { go func() {
// Create an chain state reader for self-derivation // Create a chain state reader for self-derivation
rpcClient, err := stack.Attach() rpcClient, err := stack.Attach()
if err != nil { if err != nil {
utils.Fatalf("Failed to attach to self: %v", err) utils.Fatalf("Failed to attach to self: %v", err)

View file

@ -33,7 +33,7 @@ import (
var AppHelpTemplate = `NAME: var AppHelpTemplate = `NAME:
{{.App.Name}} - {{.App.Usage}} {{.App.Name}} - {{.App.Usage}}
Copyright 2013-2017 The go-ethereum Authors Copyright 2013-2018 The go-ethereum Authors
USAGE: USAGE:
{{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}} {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}}

View file

@ -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)) 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. // various configuration parameters.
type dashboardInfos struct { type dashboardInfos struct {
host string host string

View file

@ -168,7 +168,7 @@ func (info *explorerInfos) Report() map[string]string {
return report 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. // whether it's running, and if yes, whether it's responsive.
func checkExplorer(client *sshClient, network string) (*explorerInfos, error) { func checkExplorer(client *sshClient, network string) (*explorerInfos, error) {
// Inspect a possible block explorer container on the host // Inspect a possible block explorer container on the host

View file

@ -30,7 +30,7 @@ import (
"github.com/EthereumCommonwealth/go-callisto/log" "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. // grant crypto tokens based on GitHub authentications.
var faucetDockerfile = ` var faucetDockerfile = `
FROM ethereum/client-go:alltools-latest 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)) 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. // configuration parameters.
type faucetInfos struct { type faucetInfos struct {
node *nodeInfos node *nodeInfos
@ -181,7 +181,7 @@ func (info *faucetInfos) Report() map[string]string {
return report 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. // it's running, and if yes, gathering a collection of useful infos about it.
func checkFaucet(client *sshClient, network string) (*faucetInfos, error) { func checkFaucet(client *sshClient, network string) (*faucetInfos, error) {
// Inspect a possible faucet container on the host // Inspect a possible faucet container on the host

View file

@ -40,11 +40,11 @@ ADD genesis.json /genesis.json
ADD signer.pass /signer.pass ADD signer.pass /signer.pass
{{end}} {{end}}
RUN \ RUN \
echo 'geth --cache 512 init /genesis.json' > /root/geth.sh && \{{if .Unlock}} echo 'geth --cache 512 init /genesis.json' > geth.sh && \{{if .Unlock}}
echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> /root/geth.sh && \{{end}} 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}}' >> /root/geth.sh 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 // 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 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. // whether it's running, and if yes, whether it's responsive.
func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error) { func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error) {
kind := "bootnode" kind := "bootnode"

View file

@ -64,7 +64,7 @@ var (
{{if .cmd.Description}}{{.cmd.Description}} {{if .cmd.Description}}{{.cmd.Description}}
{{end}}{{if .cmd.Subcommands}} {{end}}{{if .cmd.Subcommands}}
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}} {{end}}{{end}}{{if .categorizedFlags}}
{{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS: {{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS:
{{range $categorized.Flags}}{{"\t"}}{{.}} {{range $categorized.Flags}}{{"\t"}}{{.}}

View file

@ -18,12 +18,11 @@ package common
import ( import (
"encoding/hex" "encoding/hex"
"encoding/json"
"fmt" "fmt"
"math/big" "math/big"
"math/rand" "math/rand"
"reflect" "reflect"
"encoding/json"
"strings" "strings"
"github.com/EthereumCommonwealth/go-callisto/common/hexutil" "github.com/EthereumCommonwealth/go-callisto/common/hexutil"

View file

@ -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 // OpenWallet is a wrapper around personal.openWallet which can interpret and
// react to certain error messages, such as the Trezor PIN matrix request. // react to certain error messages, such as the Trezor PIN matrix request.
func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) { 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() { if !call.Argument(0).IsString() {
throwJSException("first argument must be the wallet URL to open") throwJSException("first argument must be the wallet URL to open")
} }

View file

@ -17,7 +17,6 @@
package asm package asm
import ( import (
"errors"
"fmt" "fmt"
"math/big" "math/big"
"os" "os"
@ -237,19 +236,16 @@ func (c *Compiler) pushBin(v interface{}) {
// isPush returns whether the string op is either any of // isPush returns whether the string op is either any of
// push(N). // push(N).
func isPush(op string) bool { func isPush(op string) bool {
return op == "push" return strings.ToUpper(op) == "PUSH"
} }
// isJump returns whether the string op is jump(i) // isJump returns whether the string op is jump(i)
func isJump(op string) bool { 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 // toBinary converts text to a vm.OpCode
func toBinary(text string) vm.OpCode { func toBinary(text string) vm.OpCode {
if isPush(text) {
text = "push1"
}
return vm.StringToOp(strings.ToUpper(text)) 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) 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 { func compileErr(c token, got, want string) error {
return compileError{ return compileError{
got: got, got: got,

View file

@ -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 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. // listening servicer, or schedule it up for later when one arrives.
assign := func(bit uint) { assign := func(bit uint) {
select { select {

View file

@ -38,8 +38,6 @@ import (
const ( const (
// chainHeadChanSize is the size of channel listening to ChainHeadEvent. // chainHeadChanSize is the size of channel listening to ChainHeadEvent.
chainHeadChanSize = 10 chainHeadChanSize = 10
// rmTxChanSize is the size of channel listening to RemovedTransactionEvent.
rmTxChanSize = 10
) )
var ( var (

View file

@ -33,7 +33,6 @@ import (
var ( var (
ErrInvalidSig = errors.New("invalid transaction v, r, s values") 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. // deriveSigner makes a *best* guess about which signer to use.

View file

@ -31,7 +31,6 @@ import (
var ( var (
bigZero = new(big.Int) bigZero = new(big.Int)
tt255 = math.BigPow(2, 255) tt255 = math.BigPow(2, 255)
tt256 = math.BigPow(2, 256)
errWriteProtection = errors.New("evm: write protection") errWriteProtection = errors.New("evm: write protection")
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds") errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
errExecutionReverted = errors.New("evm: execution reverted") errExecutionReverted = errors.New("evm: execution reverted")

View file

@ -6,9 +6,12 @@ package bn256
import ( import (
"crypto/rand" "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 // This implements the tripartite Diffie-Hellman algorithm from "A One
// Round Protocol for Tripartite Diffie-Hellman", A. Joux. // Round Protocol for Tripartite Diffie-Hellman", A. Joux.
// http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf
@ -40,4 +43,9 @@ func ExamplePair() {
k3.ScalarMult(k3, c) k3.ScalarMult(k3, c)
// k1, k2 and k3 will all be equal. // 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
} }

View file

@ -51,7 +51,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP
return api 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. // sync subscriptions and broadcasts sync status updates to the installed sync subscriptions.
func (api *PublicDownloaderAPI) eventLoop() { func (api *PublicDownloaderAPI) eventLoop() {
var ( var (

View file

@ -306,7 +306,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
d.cancelLock.RUnlock() d.cancelLock.RUnlock()
if master { if master {
d.Cancel() d.cancel()
} }
return nil return nil
} }
@ -501,8 +501,10 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
return err return err
} }
// Cancel cancels all of the operations and resets the queue. // cancel aborts all of the operations and resets the queue. However, cancel does
func (d *Downloader) Cancel() { // 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 // Close the current cancel channel
d.cancelLock.Lock() d.cancelLock.Lock()
if d.cancelCh != nil { if d.cancelCh != nil {
@ -514,6 +516,12 @@ func (d *Downloader) Cancel() {
} }
} }
d.cancelLock.Unlock() 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() d.cancelWg.Wait()
} }

View file

@ -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) { func verifyFetchingEvent(t *testing.T, fetching chan []common.Hash, arrive bool) {
if arrive { if arrive {
select { select {

View file

@ -39,7 +39,11 @@ type Client struct {
// Dial connects a client to the given URL. // Dial connects a client to the given URL.
func Dial(rawurl string) (*Client, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -51,6 +55,10 @@ func NewClient(c *rpc.Client) *Client {
return &Client{c} return &Client{c}
} }
func (ec *Client) Close() {
ec.c.Close()
}
// Blockchain Access // Blockchain Access
// BlockByHash returns the given full block. // BlockByHash returns the given full block.

View file

@ -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 * @method toBigNumber
* @param {Number|String|BigNumber} a number, string, HEX string or BigNumber * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber

View file

@ -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
)

View file

@ -73,7 +73,6 @@ const (
// and a short term value which is adjusted exponentially with a factor of // and a short term value which is adjusted exponentially with a factor of
// pstatRecentAdjust with each dial/connection and also returned exponentially // pstatRecentAdjust with each dial/connection and also returned exponentially
// to the average with the time constant pstatReturnToMeanTC // to the average with the time constant pstatReturnToMeanTC
pstatRecentAdjust = 0.1
pstatReturnToMeanTC = time.Hour pstatReturnToMeanTC = time.Hour
// node address selection weight is dropped by a factor of exp(-addrFailDropLn) after // node address selection weight is dropped by a factor of exp(-addrFailDropLn) after
// each unsuccessful connection (restored after a successful one) // each unsuccessful connection (restored after a successful one)
@ -83,9 +82,6 @@ const (
responseScoreTC = time.Millisecond * 100 responseScoreTC = time.Millisecond * 100
delayScoreTC = time.Second * 5 delayScoreTC = time.Second * 5
timeoutPow = 10 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 // initStatsWeight is used to initialize previously unknown peers with good
// statistics to give a chance to prove themselves // statistics to give a chance to prove themselves
initStatsWeight = 1 initStatsWeight = 1

View file

@ -25,11 +25,6 @@ import (
"github.com/EthereumCommonwealth/go-callisto/light" "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 // syncer is responsible for periodically synchronising with the network, both
// downloading hashes and blocks as well as handling the announcement handler. // downloading hashes and blocks as well as handling the announcement handler.
func (pm *ProtocolManager) syncer() { func (pm *ProtocolManager) syncer() {

View file

@ -80,7 +80,7 @@ func (h *Header) EncodeRLP() ([]byte, error) {
return rlp.EncodeToBytes(h.header) 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) { func NewHeaderFromJSON(data string) (*Header, error) {
h := &Header{ h := &Header{
header: new(types.Header), header: new(types.Header),
@ -91,7 +91,7 @@ func NewHeaderFromJSON(data string) (*Header, error) {
return h, nil 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) { func (h *Header) EncodeJSON() (string, error) {
data, err := json.Marshal(h.header) data, err := json.Marshal(h.header)
return string(data), err return string(data), err
@ -151,7 +151,7 @@ func (b *Block) EncodeRLP() ([]byte, error) {
return rlp.EncodeToBytes(b.block) 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) { func NewBlockFromJSON(data string) (*Block, error) {
b := &Block{ b := &Block{
block: new(types.Block), block: new(types.Block),
@ -162,7 +162,7 @@ func NewBlockFromJSON(data string) (*Block, error) {
return b, nil 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) { func (b *Block) EncodeJSON() (string, error) {
data, err := json.Marshal(b.block) data, err := json.Marshal(b.block)
return string(data), err return string(data), err
@ -220,7 +220,7 @@ func (tx *Transaction) EncodeRLP() ([]byte, error) {
return rlp.EncodeToBytes(tx.tx) 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) { func NewTransactionFromJSON(data string) (*Transaction, error) {
tx := &Transaction{ tx := &Transaction{
tx: new(types.Transaction), tx: new(types.Transaction),
@ -231,7 +231,7 @@ func NewTransactionFromJSON(data string) (*Transaction, error) {
return tx, nil 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) { func (tx *Transaction) EncodeJSON() (string, error) {
data, err := json.Marshal(tx.tx) data, err := json.Marshal(tx.tx)
return string(data), err return string(data), err
@ -312,7 +312,7 @@ func (r *Receipt) EncodeRLP() ([]byte, error) {
return rlp.EncodeToBytes(r.receipt) 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) { func NewReceiptFromJSON(data string) (*Receipt, error) {
r := &Receipt{ r := &Receipt{
receipt: new(types.Receipt), receipt: new(types.Receipt),
@ -323,7 +323,7 @@ func NewReceiptFromJSON(data string) (*Receipt, error) {
return r, nil 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) { func (r *Receipt) EncodeJSON() (string, error) {
data, err := rlp.EncodeToBytes(r.receipt) data, err := rlp.EncodeToBytes(r.receipt)
return string(data), err return string(data), err

View file

@ -209,7 +209,7 @@ func DefaultHTTPEndpoint() string {
return config.HTTPEndpoint() 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. // and port parameters.
func (c *Config) WSEndpoint() string { func (c *Config) WSEndpoint() string {
if c.WSHost == "" { if c.WSHost == "" {

View file

@ -303,23 +303,13 @@ func (n *Node) stopInProc() {
// startIPC initializes and starts the IPC RPC endpoint. // startIPC initializes and starts the IPC RPC endpoint.
func (n *Node) startIPC(apis []rpc.API) error { func (n *Node) startIPC(apis []rpc.API) error {
// Short circuit if the IPC endpoint isn't being exposed
if n.ipcEndpoint == "" { if n.ipcEndpoint == "" {
return nil return nil // IPC disabled.
} }
isClosed := func() bool { listener, handler, err := rpc.StartIPCEndpoint(n.ipcEndpoint, apis)
n.lock.RLock()
defer n.lock.RUnlock()
return n.ipcListener == nil
}
listener, handler, err := rpc.StartIPCEndpoint(isClosed, n.ipcEndpoint, apis)
if err != nil { if err != nil {
return err return err
} }
// All listeners booted successfully
n.ipcListener = listener n.ipcListener = listener
n.ipcHandler = handler n.ipcHandler = handler
n.log.Info("IPC endpoint opened", "url", n.ipcEndpoint) n.log.Info("IPC endpoint opened", "url", n.ipcEndpoint)

View file

@ -49,7 +49,6 @@ var (
// Timeouts // Timeouts
const ( const (
respTimeout = 500 * time.Millisecond respTimeout = 500 * time.Millisecond
sendTimeout = 500 * time.Millisecond
expiration = 20 * time.Second expiration = 20 * time.Second
ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP

View file

@ -36,7 +36,6 @@ import (
var ( var (
errInvalidEvent = errors.New("invalid in current state") errInvalidEvent = errors.New("invalid in current state")
errNoQuery = errors.New("no pending query") errNoQuery = errors.New("no pending query")
errWrongAddress = errors.New("unknown sender address")
) )
const ( const (
@ -828,11 +827,10 @@ type nodeEvent uint
//go:generate stringer -type=nodeEvent //go:generate stringer -type=nodeEvent
const ( const (
invalidEvent nodeEvent = iota // zero is reserved
// Packet type events. // Packet type events.
// These correspond to packet types in the UDP protocol. // These correspond to packet types in the UDP protocol.
pingPacket pingPacket = iota + 1
pongPacket pongPacket
findnodePacket findnodePacket
neighborsPacket neighborsPacket

View file

@ -4,24 +4,14 @@ package discv5
import "strconv" import "strconv"
const ( const _nodeEvent_name = "pongTimeoutpingTimeoutneighboursTimeout"
_nodeEvent_name_0 = "invalidEventpingPacketpongPacketfindnodePacketneighborsPacketfindnodeHashPackettopicRegisterPackettopicQueryPackettopicNodesPacket"
_nodeEvent_name_1 = "pongTimeoutpingTimeoutneighboursTimeout"
)
var ( var _nodeEvent_index = [...]uint8{0, 11, 22, 39}
_nodeEvent_index_0 = [...]uint8{0, 12, 22, 32, 46, 61, 79, 98, 114, 130}
_nodeEvent_index_1 = [...]uint8{0, 11, 22, 39}
)
func (i nodeEvent) String() string { func (i nodeEvent) String() string {
switch { i -= 264
case 0 <= i && i <= 8: if i >= nodeEvent(len(_nodeEvent_index)-1) {
return _nodeEvent_name_0[_nodeEvent_index_0[i]:_nodeEvent_index_0[i+1]] return "nodeEvent(" + strconv.FormatInt(int64(i+264), 10) + ")"
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) + ")"
} }
return _nodeEvent_name[_nodeEvent_index[i]:_nodeEvent_index[i+1]]
} }

View file

@ -38,7 +38,6 @@ const (
hashBits = len(common.Hash{}) * 8 hashBits = len(common.Hash{}) * 8
nBuckets = hashBits + 1 // Number of buckets nBuckets = hashBits + 1 // Number of buckets
maxBondingPingPongs = 16
maxFindnodeFailures = 5 maxFindnodeFailures = 5
) )

View file

@ -36,25 +36,17 @@ const Version = 4
// Errors // Errors
var ( var (
errPacketTooSmall = errors.New("too small") errPacketTooSmall = errors.New("too small")
errBadPrefix = errors.New("bad prefix") errBadPrefix = errors.New("bad prefix")
errExpired = errors.New("expired") errTimeout = errors.New("RPC timeout")
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")
) )
// Timeouts // Timeouts
const ( const (
respTimeout = 500 * time.Millisecond respTimeout = 500 * time.Millisecond
queryDelay = 1000 * time.Millisecond
expiration = 20 * time.Second expiration = 20 * time.Second
ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP driftThreshold = 10 * time.Second // Allowed clock drift before warning user
ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning
driftThreshold = 10 * time.Second // Allowed clock drift before warning user
) )
// RPC request structures // RPC request structures

View file

@ -24,7 +24,6 @@ import (
"reflect" "reflect"
"sync" "sync"
"testing" "testing"
"time"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/EthereumCommonwealth/go-callisto/common" "github.com/EthereumCommonwealth/go-callisto/common"
@ -38,11 +37,7 @@ func init() {
// shared test variables // shared test variables
var ( var (
futureExp = uint64(time.Now().Add(10 * time.Hour).Unix()) testLocal = rpcEndpoint{IP: net.ParseIP("3.3.3.3").To4(), UDP: 5, TCP: 6}
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}
) )
// type udpTest struct { // type udpTest struct {

View file

@ -46,7 +46,6 @@ const ID_SECP256k1_KECCAK = ID("secp256k1-keccak") // the default identity schem
var ( var (
errNoID = errors.New("unknown or unspecified identity scheme") errNoID = errors.New("unknown or unspecified identity scheme")
errInvalidSigsize = errors.New("invalid signature size")
errInvalidSig = errors.New("invalid signature") errInvalidSig = errors.New("invalid signature")
errNotSorted = errors.New("record key/value pairs are not sorted by key") errNotSorted = errors.New("record key/value pairs are not sorted by key")
errDuplicateKey = errors.New("record contains duplicate key") errDuplicateKey = errors.New("record contains duplicate key")

View file

@ -47,8 +47,6 @@ const (
discMsg = 0x01 discMsg = 0x01
pingMsg = 0x02 pingMsg = 0x02
pongMsg = 0x03 pongMsg = 0x03
getPeersMsg = 0x04
peersMsg = 0x05
) )
// protoHandshake is the RLP structure of the protocol handshake. // protoHandshake is the RLP structure of the protocol handshake.

View file

@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 8 // Minor 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 VersionMeta = "CLO stable" // Version metadata to append to the version string
) )

View file

@ -25,6 +25,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"os"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -32,8 +33,6 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"os"
"github.com/EthereumCommonwealth/go-callisto/log" "github.com/EthereumCommonwealth/go-callisto/log"
) )

View file

@ -92,7 +92,7 @@ An example method:
Subscriptions are deleted when: Subscriptions are deleted when:
- the user sends an unsubscribe request - the user sends an unsubscribe request
- the connection which was used to create the subscription is closed. This can be initiated - 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. the queue of buffered notifications gets too big.
*/ */
package rpc package rpc

View file

@ -17,8 +17,9 @@
package rpc package rpc
import ( import (
"github.com/EthereumCommonwealth/go-callisto/log"
"net" "net"
"github.com/EthereumCommonwealth/go-callisto/log"
) )
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules // 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 // StartIPCEndpoint starts an IPC endpoint.
func StartIPCEndpoint(isClosedFn func() bool, ipcEndpoint string, apis []API) (net.Listener, *Server, error) { func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) {
// Register all the APIs exposed by the services // Register all the APIs exposed by the services.
handler := NewServer() handler := NewServer()
for _, api := range apis { for _, api := range apis {
if err := handler.RegisterName(api.Namespace, api.Service); err != nil { 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) log.Debug("IPC registered", "namespace", api.Namespace)
} }
// All APIs registered, start the IPC listener // All APIs registered, start the IPC listener.
var ( listener, err := ipcListen(ipcEndpoint)
listener net.Listener if err != nil {
err error
)
if listener, err = CreateIPCListener(ipcEndpoint); err != nil {
return nil, nil, err return nil, nil, err
} }
go func() { go handler.ServeListener(listener)
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)
}
}()
return listener, handler, nil return listener, handler, nil
} }

View file

@ -90,10 +90,19 @@ func DialHTTP(endpoint string) (*Client, error) {
func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error { func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error {
hc := c.writeConn.(*httpConn) hc := c.writeConn.(*httpConn)
respBody, err := hc.doRequest(ctx, msg) respBody, err := hc.doRequest(ctx, msg)
if respBody != nil {
defer respBody.Close()
}
if err != nil { 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 return err
} }
defer respBody.Close()
var respmsg jsonrpcMessage var respmsg jsonrpcMessage
if err := json.NewDecoder(respBody).Decode(&respmsg); err != nil { if err := json.NewDecoder(respBody).Decode(&respmsg); err != nil {
return err return err
@ -132,6 +141,9 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return resp.Body, errors.New(resp.Status)
}
return resp.Body, nil return resp.Body, nil
} }

View file

@ -18,26 +18,23 @@ package rpc
import ( import (
"context" "context"
"fmt"
"net" "net"
"github.com/EthereumCommonwealth/go-callisto/log" "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. // ServeListener accepts connections on l, serving JSON-RPC on them.
func (srv *Server) ServeListener(l net.Listener) error { func (srv *Server) ServeListener(l net.Listener) error {
for { for {
conn, err := l.Accept() 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 return err
} }
log.Trace(fmt.Sprint("accepted conn", conn.RemoteAddr())) log.Trace("Accepted connection", "addr", conn.RemoteAddr())
go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions)
} }
} }

View file

@ -19,12 +19,13 @@
package fuse package fuse
import ( import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
) )
var ( var (

View file

@ -17,9 +17,10 @@
package fuse package fuse
import ( import (
"github.com/EthereumCommonwealth/go-callisto/swarm/api"
"sync" "sync"
"time" "time"
"github.com/EthereumCommonwealth/go-callisto/swarm/api"
) )
const ( const (

View file

@ -51,7 +51,7 @@ func (a Address) Bin() string {
/* /*
Proximity(x, y) returns the proximity order of the MSB distance between x and y 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. 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). the binary cast is big endian: most significant bit first (=MSB).

View file

@ -54,7 +54,6 @@ const (
// key prefixes for leveldb storage // key prefixes for leveldb storage
kpIndex = 0 kpIndex = 0
kpData = 1
) )
var ( var (

View file

@ -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 ( var (
// timeout interval before retrieval is timed out // timeout interval before retrieval is timed out
searchTimeout = 3 * time.Second searchTimeout = 3 * time.Second

View file

@ -8,10 +8,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- Added missing runtime import for FreeBSD. #104
### Changed ### Changed
### Deprecated ### 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] ## [0.8.0]
### Added ### Added

View file

@ -26,6 +26,7 @@ The features vary by operating system.
| FDUsage | X | | | | X | | FDUsage | X | | | | X |
| FileSystemList | X | X | X | X | X | | FileSystemList | X | X | X | X | X |
| FileSystemUsage | X | X | X | X | X | | FileSystemUsage | X | X | X | X | X |
| HugeTLBPages | X | | | | |
| LoadAverage | X | X | | X | X | | LoadAverage | X | X | | X | X |
| Mem | X | X | X | X | X | | Mem | X | X | X | X | X |
| ProcArgs | X | X | X | | X | | ProcArgs | X | X | X | | X |

View file

@ -62,6 +62,12 @@ func (c *ConcreteSigar) GetSwap() (Swap, error) {
return s, err 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) { func (c *ConcreteSigar) GetFileSystemUsage(path string) (FileSystemUsage, error) {
f := FileSystemUsage{} f := FileSystemUsage{}
err := f.Get(path) err := f.Get(path)

View file

@ -91,6 +91,10 @@ func (self *Swap) Get() error {
return nil return nil
} }
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error { func (self *Cpu) Get() error {
var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT
var cpuload C.host_cpu_load_info_data_t var cpuload C.host_cpu_load_info_data_t

View file

@ -4,6 +4,7 @@ package gosigar
import ( import (
"io/ioutil" "io/ioutil"
"runtime"
"strconv" "strconv"
"strings" "strings"
"unsafe" "unsafe"
@ -97,6 +98,10 @@ func (self *ProcFDUsage) Get(pid int) error {
return nil return nil
} }
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func parseCpuStat(self *Cpu, line string) error { func parseCpuStat(self *Cpu, line string) error {
fields := strings.Fields(line) fields := strings.Fields(line)

View file

@ -26,6 +26,7 @@ type Sigar interface {
GetLoadAverage() (LoadAverage, error) GetLoadAverage() (LoadAverage, error)
GetMem() (Mem, error) GetMem() (Mem, error)
GetSwap() (Swap, error) GetSwap() (Swap, error)
GetHugeTLBPages(HugeTLBPages, error)
GetFileSystemUsage(string) (FileSystemUsage, error) GetFileSystemUsage(string) (FileSystemUsage, error)
GetFDUsage() (FDUsage, error) GetFDUsage() (FDUsage, error)
GetRusage(who int) (Rusage, error) GetRusage(who int) (Rusage, error)
@ -82,6 +83,15 @@ type Swap struct {
Free uint64 Free uint64
} }
type HugeTLBPages struct {
Total uint64
Free uint64
Reserved uint64
Surplus uint64
DefaultSize uint64
TotalAllocatedSize uint64
}
type CpuList struct { type CpuList struct {
List []Cpu List []Cpu
} }

View file

@ -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 { func (self *ProcFDUsage) Get(pid int) error {
err := readFile(procFileName(pid, "limits"), func(line string) bool { err := readFile(procFileName(pid, "limits"), func(line string) bool {
if strings.HasPrefix(line, "Max open files") { if strings.HasPrefix(line, "Max open files") {

View file

@ -379,12 +379,16 @@ func parseMeminfo() (map[string]uint64, error) {
return true // skip on errors return true // skip on errors
} }
num := strings.TrimLeft(fields[1], " ") valueUnit := strings.Fields(fields[1])
val, err := strtoull(strings.Fields(num)[0]) value, err := strtoull(valueUnit[0])
if err != nil { if err != nil {
return true // skip on errors 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 return true
}) })
@ -420,8 +424,18 @@ func procFileName(pid int, name string) string {
return Procd + "/" + strconv.Itoa(pid) + "/" + name 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) 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) contents, err := ioutil.ReadFile(path)
if err != nil { if err != nil {

View file

@ -294,6 +294,10 @@ func (self *Swap) Get() error {
return nil return nil
} }
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error { 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} 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} return ErrNotImplemented{runtime.GOOS}
} }
func (self *Rusage) Get(pid int) error {
return ErrNotImplemented{runtime.GOOS}
}
func fillCpu(cpu *Cpu, load [C.CPUSTATES]C.long) { func fillCpu(cpu *Cpu, load [C.CPUSTATES]C.long) {
cpu.User = uint64(load[0]) cpu.User = uint64(load[0])
cpu.Nice = uint64(load[1]) cpu.Nice = uint64(load[1])

View file

@ -22,6 +22,10 @@ func (s *Swap) Get() error {
return ErrNotImplemented{runtime.GOOS} return ErrNotImplemented{runtime.GOOS}
} }
func (s *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (f *FDUsage) Get() error { func (f *FDUsage) Get() error {
return ErrNotImplemented{runtime.GOOS} return ErrNotImplemented{runtime.GOOS}
} }

View file

@ -120,6 +120,10 @@ func (self *Swap) Get() error {
return nil return nil
} }
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error { func (self *Cpu) Get() error {
idle, kernel, user, err := windows.GetSystemTimes() idle, kernel, user, err := windows.GetSystemTimes()
if err != nil { if err != nil {

6
vendor/vendor.json vendored
View file

@ -93,10 +93,10 @@
"revisionTime": "2016-05-12T03:30:02Z" "revisionTime": "2016-05-12T03:30:02Z"
}, },
{ {
"checksumSHA1": "Fc8BCxCoQ7ZmghDT6X1cASR10Ec=", "checksumSHA1": "jElNoLEe7m/iaoF1vYIHyNaS2SE=",
"path": "github.com/elastic/gosigar", "path": "github.com/elastic/gosigar",
"revision": "a3814ce5008e612a0c6d027608b54e1d0d9a5613", "revision": "37f05ff46ffa7a825d1b24cf2b62d4a4c1a9d2e8",
"revisionTime": "2018-01-22T22:25:45Z" "revisionTime": "2018-03-30T10:04:40Z"
}, },
{ {
"checksumSHA1": "qDsgp2kAeI9nhj565HUScaUyjU4=", "checksumSHA1": "qDsgp2kAeI9nhj565HUScaUyjU4=",

View file

@ -32,10 +32,6 @@ import (
"github.com/EthereumCommonwealth/go-callisto/rpc" "github.com/EthereumCommonwealth/go-callisto/rpc"
) )
const (
filterTimeout = 300 // filters are considered timeout out after filterTimeout seconds
)
var ( var (
ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key") ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key")
ErrInvalidSymmetricKey = errors.New("invalid symmetric key") ErrInvalidSymmetricKey = errors.New("invalid symmetric key")

View file

@ -32,10 +32,6 @@ import (
"github.com/EthereumCommonwealth/go-callisto/rpc" "github.com/EthereumCommonwealth/go-callisto/rpc"
) )
const (
filterTimeout = 300 // filters are considered timeout out after filterTimeout seconds
)
// List of errors // List of errors
var ( var (
ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key") ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key")
@ -231,8 +227,9 @@ type newMessageOverride struct {
Padding hexutil.Bytes Padding hexutil.Bytes
} }
// Post a message on the Whisper network. // Post posts a message on the Whisper network.
func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, error) { // returns the hash of the message in case of success.
func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) {
var ( var (
symKeyGiven = len(req.SymKeyID) > 0 symKeyGiven = len(req.SymKeyID) > 0
pubKeyGiven = len(req.PublicKey) > 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 // user must specify either a symmetric or an asymmetric key
if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) { if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
return false, ErrSymAsym return nil, ErrSymAsym
} }
params := &MessageParams{ 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 // Set key that is used to sign the message
if len(req.Sig) > 0 { if len(req.Sig) > 0 {
if params.Src, err = api.w.GetPrivateKey(req.Sig); err != nil { 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 // Set symmetric key that is used to encrypt the message
if symKeyGiven { if symKeyGiven {
if params.Topic == (TopicType{}) { // topics are mandatory with symmetric encryption 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 { if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
return false, err return nil, err
} }
if !validateDataIntegrity(params.KeySym, aesKeyLength) { 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 { if pubKeyGiven {
params.Dst = crypto.ToECDSAPub(req.PublicKey) params.Dst = crypto.ToECDSAPub(req.PublicKey)
if !ValidatePublicKey(params.Dst) { if !ValidatePublicKey(params.Dst) {
return false, ErrInvalidPublicKey return nil, ErrInvalidPublicKey
} }
} }
// encrypt and sent message // encrypt and sent message
whisperMsg, err := NewSentMessage(params) whisperMsg, err := NewSentMessage(params)
if err != nil { if err != nil {
return false, err return nil, err
} }
var result []byte
env, err := whisperMsg.Wrap(params) env, err := whisperMsg.Wrap(params)
if err != nil { if err != nil {
return false, err return nil, err
} }
// send to specific node (skip PoW check) // send to specific node (skip PoW check)
if len(req.TargetPeer) > 0 { if len(req.TargetPeer) > 0 {
n, err := discover.ParseNode(req.TargetPeer) n, err := discover.ParseNode(req.TargetPeer)
if err != nil { 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 // ensure that the message PoW meets the node's minimum accepted PoW
if req.PowTarget < api.w.MinPow() { 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 //go:generate gencodec -type Criteria -field-override criteriaOverride -out gen_criteria_json.go