From 4671243b0d42a0f7710d1ab23c373e2f2bc2ebbb Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Mon, 15 Oct 2018 19:04:58 +0800 Subject: [PATCH 01/38] Refactor cql-utils and add adapterconfgen --- cmd/cql-explorer/main.go | 41 +++ cmd/cql-observer/main.go | 2 +- cmd/cql-utils/adapterconfgen.go | 180 +++++++++++ cmd/cql-utils/addrgen.go | 72 +++++ cmd/cql-utils/confgen.go | 167 ++++++++++ cmd/cql-utils/idminer.go | 125 ++++++++ cmd/cql-utils/keygen.go | 69 ++++ cmd/cql-utils/keytool.go | 41 +++ cmd/cql-utils/main.go | 537 +------------------------------- cmd/cql-utils/noncegen.go | 124 ++++++++ cmd/cql-utils/rpc.go | 148 +++++++++ 11 files changed, 974 insertions(+), 532 deletions(-) create mode 100644 cmd/cql-explorer/main.go create mode 100644 cmd/cql-utils/adapterconfgen.go create mode 100644 cmd/cql-utils/addrgen.go create mode 100644 cmd/cql-utils/confgen.go create mode 100644 cmd/cql-utils/idminer.go create mode 100644 cmd/cql-utils/keygen.go create mode 100644 cmd/cql-utils/keytool.go create mode 100644 cmd/cql-utils/noncegen.go create mode 100644 cmd/cql-utils/rpc.go diff --git a/cmd/cql-explorer/main.go b/cmd/cql-explorer/main.go new file mode 100644 index 000000000..e5fcf80f4 --- /dev/null +++ b/cmd/cql-explorer/main.go @@ -0,0 +1,41 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import "flag" + +var ( + version = "unknown" + commit = "unknown" + branch = "unknown" +) + +var ( + // config + configFile string + dbID string + listenAddr string +) + +func init() { + flag.StringVar(&configFile, "config", "./config.yaml", "config file path") + flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api") +} + +func main() { + +} diff --git a/cmd/cql-observer/main.go b/cmd/cql-observer/main.go index fdf3efdc2..9b71ccea1 100644 --- a/cmd/cql-observer/main.go +++ b/cmd/cql-observer/main.go @@ -48,7 +48,7 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "./config.yaml", "Config file path") + flag.StringVar(&configFile, "config", "./config.yaml", "config file path") flag.StringVar(&dbID, "database", "", "database to listen for observation") flag.BoolVar(&asymmetric.BypassSignature, "bypassSignature", false, "Disable signature sign and verify, for testing") diff --git a/cmd/cql-utils/adapterconfgen.go b/cmd/cql-utils/adapterconfgen.go new file mode 100644 index 000000000..535cf3ce0 --- /dev/null +++ b/cmd/cql-utils/adapterconfgen.go @@ -0,0 +1,180 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bufio" + "encoding/json" + "fmt" + "io/ioutil" + "os" + + "github.com/CovenantSQL/CovenantSQL/utils/log" + "gopkg.in/yaml.v2" +) + +type adapterConfig struct { + ListenAddr string + CertificatePath string + PrivateKeyPath string + VerifyCertificate bool + ClientCAPath string + AdminCerts []string + WriteCerts []string + StorageDriver string + StorageRoot string +} + +var ( + defaultAdapterConfig = &adapterConfig{ + ListenAddr: "0.0.0.0:4661", + CertificatePath: "server.pem", + PrivateKeyPath: "server-key.pem", + VerifyCertificate: false, + ClientCAPath: "", + AdminCerts: []string{}, + WriteCerts: []string{}, + StorageDriver: "covenantsql", + StorageRoot: "", + } +) + +func (c *adapterConfig) readListenAddr() { + +} + +func (c *adapterConfig) readCertificatePath() { + +} + +func (c *adapterConfig) readPrivateKeyPath() { + +} + +func (c *adapterConfig) readVerifyCertificate() { + +} + +func (c *adapterConfig) readClientCAPath() { + +} + +func (c *adapterConfig) readAdminCerts() { + +} + +func (c *adapterConfig) readWriteCerts() { + +} + +func (c *adapterConfig) readStorageDriver() { + +} + +func (c *adapterConfig) readStorageRoot() { + +} + +func (c *adapterConfig) loadFromExistingConfig(rawConfig map[string]interface{}) { + if rawConfig == nil || rawConfig["Adapter"] == nil { + return + } + + // fill values to config structure + var configBytes []byte + var err error + + if configBytes, err = json.Marshal(rawConfig["Adapter"]); err != nil { + log.Warningf("load previous adapter config failed: %v", err) + return + } + + if err = json.Unmarshal(configBytes, c); err != nil { + log.Warningf("load previous adapter config failed: %v", err) + return + } + + return +} + +func (c *adapterConfig) writeToRawConfig(rawConfig map[string]interface{}) { + if rawConfig != nil { + rawConfig["Adapter"] = c + } +} + +func (c *adapterConfig) readAllConfig() { + +} + +func readDataFromStdin(prompt string) (s string) { + reader := bufio.NewReader(os.Stdin) + fmt.Print(prompt) + s, _ = reader.ReadString('\n') + return +} + +func runAdapterConfGen() { + if configFile == "" { + log.Error("config file path is required for adapterconfgen tool") + os.Exit(1) + } + + var err error + var configBytes []byte + if configBytes, err = ioutil.ReadFile(configFile); err != nil { + log.Errorf("an existing config file is required for adapterconfggen: %v", err) + os.Exit(1) + } + + // load config + var rawConfig map[string]interface{} + if err = yaml.Unmarshal(configBytes, &rawConfig); err != nil { + log.Errorf("a valid config file is required for adapterconfgen: %v", err) + os.Exit(1) + } + + if rawConfig == nil { + log.Errorf("a confgen generated config is required for adapterconfgen: %v", err) + os.Exit(1) + } + + // backup config + bakConfigFile := configFile + ".bak" + if err = ioutil.WriteFile(bakConfigFile, configBytes, 0600); err != nil { + log.Errorf("backup config file failed: %v", err) + os.Exit(1) + } + + defaultAdapterConfig.loadFromExistingConfig(rawConfig) + defaultAdapterConfig.readAllConfig() + defaultAdapterConfig.writeToRawConfig(rawConfig) + + if configBytes, err = yaml.Marshal(rawConfig); err != nil { + log.Errorf("marshal config failed: %v", err) + os.Exit(1) + } + + if err = ioutil.WriteFile(configFile, configBytes, 0600); err != nil { + log.Errorf("write config to file failed: %v", err) + os.Exit(1) + } + + log.Infof("adapter config generated") + + return +} diff --git a/cmd/cql-utils/addrgen.go b/cmd/cql-utils/addrgen.go new file mode 100644 index 000000000..ca8d05a62 --- /dev/null +++ b/cmd/cql-utils/addrgen.go @@ -0,0 +1,72 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "encoding/hex" + "flag" + "fmt" + "github.com/CovenantSQL/CovenantSQL/crypto" + "os" + + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/kms" + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +var ( + isTestNetAddr bool +) + +func init() { + flag.BoolVar(&isTestNetAddr, "addrgen", false, "addrgen generates a testnet address from your key pair") +} + +func runAddrgen() { + var publicKey *asymmetric.PublicKey + + if publicKeyHex != "" { + publicKeyBytes, err := hex.DecodeString(publicKeyHex) + if err != nil { + log.Fatalf("error converting hex: %s\n", err) + } + publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) + if err != nil { + log.Fatalf("error converting public key: %s\n", err) + } + } else if privateKeyFile != "" { + masterKey, err := readMasterKey() + if err != nil { + fmt.Printf("read master key failed: %v\n", err) + os.Exit(1) + } + privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) + if err != nil { + log.Fatalf("load private key file fail: %v\n", err) + } + publicKey = privateKey.PubKey() + } else { + fmt.Println("privateKey path or publicKey hex is required for addrgen") + os.Exit(1) + } + + addr, err := crypto.PubKey2Addr(publicKey, crypto.TestNet) + if err != nil { + log.Fatalf("unexpected error: %v\n", err) + } + fmt.Printf("wallet address: %s\n", addr) +} diff --git a/cmd/cql-utils/confgen.go b/cmd/cql-utils/confgen.go new file mode 100644 index 000000000..bf1790287 --- /dev/null +++ b/cmd/cql-utils/confgen.go @@ -0,0 +1,167 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bufio" + "encoding/hex" + "flag" + "fmt" + "io/ioutil" + "os" + "path" + "strings" + + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +var ( + workingRoot string +) + +func init() { + flag.StringVar(&workingRoot, "root", "conf", "confgen root is the working root directory containing all auto-generating keys and certifications") +} + +func runConfgen() { + if workingRoot == "" { + log.Error("root directory is required for confgen") + os.Exit(1) + } + + privateKeyFileName := "private.key" + publicKeystoreFileName := "public.keystore" + + privateKeyFile = path.Join(workingRoot, privateKeyFileName) + + if _, err := os.Stat(workingRoot); err == nil { + reader := bufio.NewReader(os.Stdin) + fmt.Println("The directory has already existed. \nDo you want to delete it? (y or n, press Enter for default n):") + t, err := reader.ReadString('\n') + t = strings.Trim(t, "\n") + if err != nil { + log.Errorf("Unexpected error: %v\n", err) + os.Exit(1) + } + if strings.Compare(t, "y") == 0 || strings.Compare(t, "yes") == 0 { + os.RemoveAll(workingRoot) + } else { + os.Exit(0) + } + } + + err := os.Mkdir(workingRoot, 0755) + if err != nil { + log.Errorf("Unexpected error: %v", err) + os.Exit(1) + } + + fmt.Println("Generating key pair...") + publicKey := runKeygen() + fmt.Println("Generated key pair.") + + fmt.Println("Generating nonce...") + nonce := noncegen(publicKey) + fmt.Println("Generated nonce.") + + fmt.Println("Generating config file...") + + configContent := fmt.Sprintf(`IsTestMode: true +WorkingRoot: "./" +PrivateKeyFile: "%s" +PubKeyStoreFile: "%s" +DHTFileName: "dht.db" +ListenAddr: "0.0.0.0:4661" +ThisNodeID: %s +MinNodeIDDifficulty: 24 +BlockProducer: + PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 + NodeID: 0000011839f464418166658ef6dec09ea68da1619a7a9e0f247f16e0d6c6504d + Nonce: + a: 761802 + b: 0 + c: 0 + d: 4611686019290328603 + ChainFileName: "chain.db" + BPGenesisInfo: + Version: 1 + BlockHash: f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154 + Producer: 0000000000000000000000000000000000000000000000000000000000000001 + MerkleRoot: 0000000000000000000000000000000000000000000000000000000000000001 + ParentHash: 0000000000000000000000000000000000000000000000000000000000000001 + Timestamp: 2018-09-01T00:00:00Z + BaseAccounts: + - Address: d3dce44e0a4f1dae79b93f04ce13fb5ab719059f7409d7ca899d4c921da70129 + StableCoinBalance: 100000000 + CovenantCoinBalance: 100000000 +KnownNodes: +- ID: 0000011839f464418166658ef6dec09ea68da1619a7a9e0f247f16e0d6c6504d + Nonce: + a: 761802 + b: 0 + c: 0 + d: 4611686019290328603 + Addr: 120.79.254.36:11105 + PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 + Role: Leader +- ID: 00000177647ade3bd86a085510113ccae4b8e690424bb99b95b3545039ae8e8c + Nonce: + a: 197619 + b: 0 + c: 0 + d: 4611686019249700888 + Addr: 120.79.254.36:11106 + PublicKey: 02d6f3afcd26aa8de25f5d088c5f8d6b052b4ad1b27ce5b84939bc9f105556844e + Role: Miner +- ID: 000004b0267f959e645b0df5cd38ae0652c1160b960cdcb97b322caafe627e4f + Nonce: + a: 455820 + b: 0 + c: 0 + d: 3627017019 + Addr: 120.79.254.36:11107 + PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 + Role: Follower +- ID: 00000328ef30233890f61d7504b640b45e8ba33d5671157a0cee81745e46b963 + Nonce: + a: 333847 + b: 0 + c: 0 + d: 6917529031239958890 + Addr: 120.79.254.36:11108 + PublicKey: 0202361b87a087cd61137ba3b5bd83c48c180566c8d7f1a0b386c3277bf0dc6ebd + Role: Miner +- ID: %s + Nonce: + a: %d + b: %d + c: %d + d: %d + Addr: 127.0.0.1:11109 + PublicKey: %s + Role: Client +`, privateKeyFileName, publicKeystoreFileName, + nonce.Hash.String(), nonce.Hash.String(), + nonce.Nonce.A, nonce.Nonce.B, nonce.Nonce.C, nonce.Nonce.D, hex.EncodeToString(publicKey.Serialize())) + + err = ioutil.WriteFile(path.Join(workingRoot, "config.yaml"), []byte(configContent), 0755) + if err != nil { + log.Errorf("Unexpected error: %v\n", err) + os.Exit(1) + } + fmt.Println("Generated nonce.") +} diff --git a/cmd/cql-utils/idminer.go b/cmd/cql-utils/idminer.go new file mode 100644 index 000000000..639b7a98e --- /dev/null +++ b/cmd/cql-utils/idminer.go @@ -0,0 +1,125 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "encoding/hex" + "flag" + "fmt" + "math" + "math/rand" + "os" + "os/signal" + "runtime" + "syscall" + "time" + + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/kms" + mine "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +var ( + difficulty int +) + +func init() { + flag.IntVar(&difficulty, "difficulty", 24, "difficulty for miner to mine nodes and generating nonce") +} + +func runMiner() { + masterKey, err := readMasterKey() + if err != nil { + fmt.Printf("read master key failed: %v\n", err) + os.Exit(1) + } + + var publicKey *asymmetric.PublicKey + + if publicKeyHex != "" { + publicKeyBytes, err := hex.DecodeString(publicKeyHex) + if err != nil { + log.Fatalf("error converting hex: %s\n", err) + } + publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) + if err != nil { + log.Fatalf("error converting public key: %s\n", err) + } + } else if privateKeyFile != "" { + privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) + if err != nil { + log.Fatalf("load private key file faile: %v\n", err) + } + publicKey = privateKey.PubKey() + } + + signalCh := make(chan os.Signal, 1) + signal.Notify( + signalCh, + syscall.SIGINT, + syscall.SIGTERM, + ) + signal.Ignore(syscall.SIGHUP, syscall.SIGTTIN, syscall.SIGTTOU) + + cpuCount := runtime.NumCPU() + log.Infof("cpu: %d\n", cpuCount) + nonceChs := make([]chan mine.NonceInfo, cpuCount) + stopChs := make([]chan struct{}, cpuCount) + + rand.Seed(time.Now().UnixNano()) + step := math.MaxUint64 / uint64(cpuCount) + + for i := 0; i < cpuCount; i++ { + nonceChs[i] = make(chan mine.NonceInfo) + stopChs[i] = make(chan struct{}) + go func(i int) { + miner := mine.NewCPUMiner(stopChs[i]) + nonceCh := nonceChs[i] + block := mine.MiningBlock{ + Data: publicKey.Serialize(), + NonceChan: nonceCh, + Stop: nil, + } + start := mine.Uint256{D: step*uint64(i) + uint64(rand.Uint32())} + log.Infof("miner #%d start: %v\n", i, start) + miner.ComputeBlockNonce(block, start, difficulty) + }(i) + } + + sig := <-signalCh + log.Infof("received signal %s\n", sig) + for i := 0; i < cpuCount; i++ { + close(stopChs[i]) + } + + max := mine.NonceInfo{} + for i := 0; i < cpuCount; i++ { + newNonce := <-nonceChs[i] + if max.Difficulty < newNonce.Difficulty { + max = newNonce + } + } + + // verify result + log.Infof("verify result: %v\n", kms.IsIDPubNonceValid(&proto.RawNodeID{Hash: max.Hash}, &max.Nonce, publicKey)) + + // print result + fmt.Printf("nonce: %v\n", max) + fmt.Printf("node id: %v\n", max.Hash.String()) +} diff --git a/cmd/cql-utils/keygen.go b/cmd/cql-utils/keygen.go new file mode 100644 index 000000000..68ec398f1 --- /dev/null +++ b/cmd/cql-utils/keygen.go @@ -0,0 +1,69 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bufio" + "encoding/hex" + "fmt" + "os" + "strings" + + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/kms" + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +func runKeygen() *asymmetric.PublicKey { + if _, err := os.Stat(privateKeyFile); err == nil { + reader := bufio.NewReader(os.Stdin) + fmt.Println("Private key file has already existed. \nDo you want to delete it? (y or n, press Enter for default n):") + t, err := reader.ReadString('\n') + t = strings.Trim(t, "\n") + if err != nil { + log.Errorf("Unexpected error: %v\n", err) + os.Exit(1) + } + if strings.Compare(t, "y") == 0 || strings.Compare(t, "yes") == 0 { + err = os.Remove(privateKeyFile) + if err != nil { + log.Errorf("Unexpected error: %v\n", err) + os.Exit(1) + } + } else { + os.Exit(0) + } + } + + privateKey, _, err := asymmetric.GenSecp256k1KeyPair() + if err != nil { + log.Fatalf("generate key pair failed: %v\n", err) + } + + masterKey, err := readMasterKey() + if err != nil { + log.Fatalf("read master key failed: %v\n", err) + } + + if err = kms.SavePrivateKey(privateKeyFile, privateKey, []byte(masterKey)); err != nil { + log.Fatalf("save generated keypair failed: %v\n", err) + } + + fmt.Printf("Private key file: %s\n", privateKeyFile) + fmt.Printf("Public key's hex: %s\n", hex.EncodeToString(privateKey.PubKey().Serialize())) + return privateKey.PubKey() +} diff --git a/cmd/cql-utils/keytool.go b/cmd/cql-utils/keytool.go new file mode 100644 index 000000000..9343c440e --- /dev/null +++ b/cmd/cql-utils/keytool.go @@ -0,0 +1,41 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "encoding/hex" + "fmt" + "os" + + "github.com/CovenantSQL/CovenantSQL/crypto/kms" + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +func runKeytool() { + masterKey, err := readMasterKey() + if err != nil { + fmt.Printf("read master key failed: %v\n", err) + os.Exit(1) + } + + privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) + if err != nil { + log.Errorf("load private key failed: %v\n", err) + } + + fmt.Printf("Public key's hex: %s\n", hex.EncodeToString(privateKey.PubKey().Serialize())) +} diff --git a/cmd/cql-utils/main.go b/cmd/cql-utils/main.go index a769b1494..25931c350 100644 --- a/cmd/cql-utils/main.go +++ b/cmd/cql-utils/main.go @@ -17,36 +17,12 @@ package main import ( - "bufio" - "encoding/hex" - "encoding/json" "flag" "fmt" - "io/ioutil" - "math" - "math/rand" "os" - "os/signal" - "path" - "reflect" - "runtime" - "strings" "syscall" - "time" - "github.com/CovenantSQL/CovenantSQL/blockproducer" - "github.com/CovenantSQL/CovenantSQL/client" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" - "github.com/CovenantSQL/CovenantSQL/crypto/kms" - mine "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" - "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/CovenantSQL/CovenantSQL/route" - "github.com/CovenantSQL/CovenantSQL/rpc" - "github.com/CovenantSQL/CovenantSQL/sqlchain" "github.com/CovenantSQL/CovenantSQL/utils/log" - "github.com/CovenantSQL/CovenantSQL/worker" - - "github.com/CovenantSQL/CovenantSQL/crypto" "golang.org/x/crypto/ssh/terminal" ) @@ -55,38 +31,20 @@ var ( tool string publicKeyHex string privateKeyFile string - difficulty int - rpcName string - rpcEndpoint string - rpcReq string configFile string - workingRoot string - isTestNetAddr bool - rpcServiceMap = map[string]interface{}{ - "DHT": &route.DHTService{}, - "DBS": &worker.DBMSRPCService{}, - "BPDB": &blockproducer.DBService{}, - "SQLC": &sqlchain.MuxService{}, - } ) func init() { - log.SetLevel(log.ErrorLevel) + log.SetLevel(log.InfoLevel) - flag.StringVar(&tool, "tool", "", "tool type, miner, keygen, keytool, rpc, nonce, confgen, addrgen") + flag.StringVar(&tool, "tool", "", "tool type, miner, keygen, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") flag.StringVar(&publicKeyHex, "public", "", "public key hex string to mine node id/nonce") flag.StringVar(&privateKeyFile, "private", "private.key", "private key file to generate/show") - flag.IntVar(&difficulty, "difficulty", 24, "difficulty for miner to mine nodes and generating nonce") - flag.StringVar(&rpcName, "rpc", "", "rpc name to do test call") - flag.StringVar(&rpcEndpoint, "endpoint", "", "rpc endpoint to do test call") - flag.StringVar(&rpcReq, "req", "", "rpc request to do test call, in json format") - flag.StringVar(&configFile, "config", "", "rpc config file") - flag.StringVar(&workingRoot, "root", "conf", "confgen root is the working root directory containing all auto-generating keys and certifications") - flag.BoolVar(&isTestNetAddr, "addrgen", false, "addrgen generates a testnet address from your key pair") + flag.StringVar(&configFile, "config", "config.yaml", "config file to use") } func main() { - log.Infof("idminer build: %s\n", version) + log.Infof("cql-utils build: %s\n", version) flag.Parse() switch tool { @@ -112,25 +70,13 @@ func main() { } runKeytool() case "rpc": - if configFile == "" { - // error - log.Error("config file path is required for rpc tool") - os.Exit(1) - } - if rpcEndpoint == "" || rpcName == "" || rpcReq == "" { - // error - log.Error("rpc payload is required for rpc tool") - os.Exit(1) - } runRPC() case "nonce": runNonce() case "confgen": - if workingRoot == "" { - log.Error("root directory is required for confgen") - os.Exit(1) - } runConfgen() + case "adapterconfgen": + runAdapterConfGen() case "addrgen": if privateKeyFile == "" && publicKeyHex == "" { log.Error("privateKey path or publicKey hex is required for addrgen") @@ -143,477 +89,6 @@ func main() { } } -func runMiner() { - masterKey, err := readMasterKey() - if err != nil { - fmt.Printf("read master key failed: %v\n", err) - os.Exit(1) - } - - var publicKey *asymmetric.PublicKey - - if publicKeyHex != "" { - publicKeyBytes, err := hex.DecodeString(publicKeyHex) - if err != nil { - log.Fatalf("error converting hex: %s\n", err) - } - publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) - if err != nil { - log.Fatalf("error converting public key: %s\n", err) - } - } else if privateKeyFile != "" { - privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) - if err != nil { - log.Fatalf("load private key file faile: %v\n", err) - } - publicKey = privateKey.PubKey() - } - - signalCh := make(chan os.Signal, 1) - signal.Notify( - signalCh, - syscall.SIGINT, - syscall.SIGTERM, - ) - signal.Ignore(syscall.SIGHUP, syscall.SIGTTIN, syscall.SIGTTOU) - - cpuCount := runtime.NumCPU() - log.Infof("cpu: %d\n", cpuCount) - nonceChs := make([]chan mine.NonceInfo, cpuCount) - stopChs := make([]chan struct{}, cpuCount) - - rand.Seed(time.Now().UnixNano()) - step := math.MaxUint64 / uint64(cpuCount) - - for i := 0; i < cpuCount; i++ { - nonceChs[i] = make(chan mine.NonceInfo) - stopChs[i] = make(chan struct{}) - go func(i int) { - miner := mine.NewCPUMiner(stopChs[i]) - nonceCh := nonceChs[i] - block := mine.MiningBlock{ - Data: publicKey.Serialize(), - NonceChan: nonceCh, - Stop: nil, - } - start := mine.Uint256{D: step*uint64(i) + uint64(rand.Uint32())} - log.Infof("miner #%d start: %v\n", i, start) - miner.ComputeBlockNonce(block, start, difficulty) - }(i) - } - - sig := <-signalCh - log.Infof("received signal %s\n", sig) - for i := 0; i < cpuCount; i++ { - close(stopChs[i]) - } - - max := mine.NonceInfo{} - for i := 0; i < cpuCount; i++ { - newNonce := <-nonceChs[i] - if max.Difficulty < newNonce.Difficulty { - max = newNonce - } - } - - // verify result - log.Infof("verify result: %v\n", kms.IsIDPubNonceValid(&proto.RawNodeID{Hash: max.Hash}, &max.Nonce, publicKey)) - - // print result - fmt.Printf("nonce: %v\n", max) - fmt.Printf("node id: %v\n", max.Hash.String()) -} - -func runKeygen() *asymmetric.PublicKey { - if _, err := os.Stat(privateKeyFile); err == nil { - reader := bufio.NewReader(os.Stdin) - fmt.Println("Private key file has already existed. \nDo you want to delete it? (y or n, press Enter for default n):") - t, err := reader.ReadString('\n') - t = strings.Trim(t, "\n") - if err != nil { - log.Errorf("Unexpected error: %v\n", err) - os.Exit(1) - } - if strings.Compare(t, "y") == 0 || strings.Compare(t, "yes") == 0 { - err = os.Remove(privateKeyFile) - if err != nil { - log.Errorf("Unexpected error: %v\n", err) - os.Exit(1) - } - } else { - os.Exit(0) - } - } - - privateKey, _, err := asymmetric.GenSecp256k1KeyPair() - if err != nil { - log.Fatalf("generate key pair failed: %v\n", err) - } - - masterKey, err := readMasterKey() - if err != nil { - log.Fatalf("read master key failed: %v\n", err) - } - - if err = kms.SavePrivateKey(privateKeyFile, privateKey, []byte(masterKey)); err != nil { - log.Fatalf("save generated keypair failed: %v\n", err) - } - - fmt.Printf("Private key file: %s\n", privateKeyFile) - fmt.Printf("Public key's hex: %s\n", hex.EncodeToString(privateKey.PubKey().Serialize())) - return privateKey.PubKey() -} - -func runKeytool() { - masterKey, err := readMasterKey() - if err != nil { - fmt.Printf("read master key failed: %v\n", err) - os.Exit(1) - } - - privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) - if err != nil { - log.Errorf("load private key failed: %v\n", err) - } - - fmt.Printf("Public key's hex: %s\n", hex.EncodeToString(privateKey.PubKey().Serialize())) -} - -func runRPC() { - if err := client.Init(configFile, []byte("")); err != nil { - fmt.Printf("init rpc client failed: %v\n", err) - os.Exit(1) - return - } - - req, resp := resolveRPCEntities() - - // fill the req with request body - if err := json.Unmarshal([]byte(rpcReq), req); err != nil { - fmt.Printf("decode request body failed: %v\n", err) - os.Exit(1) - return - } - - if err := rpc.NewCaller().CallNode(proto.NodeID(rpcEndpoint), rpcName, req, resp); err != nil { - // send request failed - fmt.Printf("call rpc failed: %v\n", err) - os.Exit(1) - return - } - - // print the response - if resBytes, err := json.MarshalIndent(resp, "", " "); err != nil { - fmt.Printf("marshal response failed: %v\n", err) - os.Exit(1) - } else { - fmt.Println(string(resBytes)) - } -} - -func resolveRPCEntities() (req interface{}, resp interface{}) { - rpcParts := strings.SplitN(rpcName, ".", 2) - - if len(rpcParts) != 2 { - // error rpc name - fmt.Printf("%v is not a valid rpc name\n", rpcName) - os.Exit(1) - return - } - - rpcService := rpcParts[0] - - if s, supported := rpcServiceMap[rpcService]; supported { - typ := reflect.TypeOf(s) - - // traversing methods - for m := 0; m < typ.NumMethod(); m++ { - method := typ.Method(m) - mtype := method.Type - - if method.Name == rpcParts[1] { - // name matched - if mtype.PkgPath() != "" || mtype.NumIn() != 3 || mtype.NumOut() != 1 { - fmt.Printf("%v is not a valid rpc endpoint method\n", rpcName) - os.Exit(1) - return - } - - argType := mtype.In(1) - replyType := mtype.In(2) - - if argType.Kind() == reflect.Ptr { - req = reflect.New(argType.Elem()).Interface() - } else { - req = reflect.New(argType).Interface() - - } - - resp = reflect.New(replyType.Elem()).Interface() - - return - } - } - } - - // not found - fmt.Printf("rpc method %v not found\n", rpcName) - os.Exit(1) - - return -} - -func runNonce() { - var publicKey *asymmetric.PublicKey - - if publicKeyHex != "" { - publicKeyBytes, err := hex.DecodeString(publicKeyHex) - if err != nil { - log.Fatalf("error converting hex: %s\n", err) - } - publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) - if err != nil { - log.Fatalf("error converting public key: %s\n", err) - } - } else if privateKeyFile != "" { - masterKey, err := readMasterKey() - if err != nil { - fmt.Printf("read master key failed: %v\n", err) - os.Exit(1) - } - privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) - if err != nil { - log.Fatalf("load private key file fail: %v\n", err) - } - publicKey = privateKey.PubKey() - } else { - log.Fatalln("can neither convert public key nor load private key") - } - - noncegen(publicKey) -} - -func noncegen(publicKey *asymmetric.PublicKey) *mine.NonceInfo { - publicKeyBytes := publicKey.Serialize() - - cpuCount := runtime.NumCPU() - log.Infof("cpu: %d\n", cpuCount) - stopCh := make(chan struct{}) - nonceCh := make(chan mine.NonceInfo) - - rand.Seed(time.Now().UnixNano()) - step := 256 / cpuCount - for i := 0; i < cpuCount; i++ { - go func(i int) { - startBit := i * step - position := startBit / 64 - shift := uint(startBit % 64) - log.Infof("position: %d, shift: %d, i: %d", position, shift, i) - var start mine.Uint256 - if position == 0 { - start = mine.Uint256{A: uint64(1<= difficulty { - nonce := mine.NonceInfo{ - Nonce: j, - Difficulty: currentDifficulty, - Hash: currentHash, - } - nonceCh <- nonce - } - } - } - }(i) - } - - nonce := <-nonceCh - close(stopCh) - - // verify result - if !kms.IsIDPubNonceValid(&proto.RawNodeID{Hash: nonce.Hash}, &nonce.Nonce, publicKey) { - log.Fatalf("nonce: %v\nnode id: %s", nonce, nonce.Hash.String()) - } - - // print result - fmt.Printf("nonce: %v\n", nonce) - fmt.Printf("node id: %v\n", nonce.Hash.String()) - - return &nonce -} - -func runConfgen() { - privateKeyFileName := "private.key" - publicKeystoreFileName := "public.keystore" - - privateKeyFile = path.Join(workingRoot, privateKeyFileName) - - if _, err := os.Stat(workingRoot); err == nil { - reader := bufio.NewReader(os.Stdin) - fmt.Println("The directory has already existed. \nDo you want to delete it? (y or n, press Enter for default n):") - t, err := reader.ReadString('\n') - t = strings.Trim(t, "\n") - if err != nil { - log.Errorf("Unexpected error: %v\n", err) - os.Exit(1) - } - if strings.Compare(t, "y") == 0 || strings.Compare(t, "yes") == 0 { - os.RemoveAll(workingRoot) - } else { - os.Exit(0) - } - } - - err := os.Mkdir(workingRoot, 0755) - if err != nil { - log.Errorf("Unexpected error: %v", err) - os.Exit(1) - } - - fmt.Println("Generating key pair...") - publicKey := runKeygen() - fmt.Println("Generated key pair.") - - fmt.Println("Generating nonce...") - nonce := noncegen(publicKey) - fmt.Println("Generated nonce.") - - fmt.Println("Generating config file...") - - configContent := fmt.Sprintf(`IsTestMode: true -WorkingRoot: "./" -PrivateKeyFile: "%s" -PubKeyStoreFile: "%s" -DHTFileName: "dht.db" -ListenAddr: "0.0.0.0:4661" -ThisNodeID: %s -MinNodeIDDifficulty: 24 -BlockProducer: - PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 - NodeID: 0000011839f464418166658ef6dec09ea68da1619a7a9e0f247f16e0d6c6504d - Nonce: - a: 761802 - b: 0 - c: 0 - d: 4611686019290328603 - ChainFileName: "chain.db" - BPGenesisInfo: - Version: 1 - BlockHash: f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154 - Producer: 0000000000000000000000000000000000000000000000000000000000000001 - MerkleRoot: 0000000000000000000000000000000000000000000000000000000000000001 - ParentHash: 0000000000000000000000000000000000000000000000000000000000000001 - Timestamp: 2018-09-01T00:00:00Z - BaseAccounts: - - Address: d3dce44e0a4f1dae79b93f04ce13fb5ab719059f7409d7ca899d4c921da70129 - StableCoinBalance: 100000000 - CovenantCoinBalance: 100000000 -KnownNodes: -- ID: 0000011839f464418166658ef6dec09ea68da1619a7a9e0f247f16e0d6c6504d - Nonce: - a: 761802 - b: 0 - c: 0 - d: 4611686019290328603 - Addr: 120.79.254.36:11105 - PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 - Role: Leader -- ID: 00000177647ade3bd86a085510113ccae4b8e690424bb99b95b3545039ae8e8c - Nonce: - a: 197619 - b: 0 - c: 0 - d: 4611686019249700888 - Addr: 120.79.254.36:11106 - PublicKey: 02d6f3afcd26aa8de25f5d088c5f8d6b052b4ad1b27ce5b84939bc9f105556844e - Role: Miner -- ID: 000004b0267f959e645b0df5cd38ae0652c1160b960cdcb97b322caafe627e4f - Nonce: - a: 455820 - b: 0 - c: 0 - d: 3627017019 - Addr: 120.79.254.36:11107 - PublicKey: 034b4319f2e2a9d9f3fd55d1233ff7a2f2ea2e815e7227b3861b4a6a24a8d62697 - Role: Follower -- ID: 00000328ef30233890f61d7504b640b45e8ba33d5671157a0cee81745e46b963 - Nonce: - a: 333847 - b: 0 - c: 0 - d: 6917529031239958890 - Addr: 120.79.254.36:11108 - PublicKey: 0202361b87a087cd61137ba3b5bd83c48c180566c8d7f1a0b386c3277bf0dc6ebd - Role: Miner -- ID: %s - Nonce: - a: %d - b: %d - c: %d - d: %d - Addr: 127.0.0.1:11109 - PublicKey: %s - Role: Client -`, privateKeyFileName, publicKeystoreFileName, - nonce.Hash.String(), nonce.Hash.String(), - nonce.Nonce.A, nonce.Nonce.B, nonce.Nonce.C, nonce.Nonce.D, hex.EncodeToString(publicKey.Serialize())) - - err = ioutil.WriteFile(path.Join(workingRoot, "config.yaml"), []byte(configContent), 0755) - if err != nil { - log.Errorf("Unexpected error: %v\n", err) - os.Exit(1) - } - fmt.Println("Generated nonce.") -} - -func runAddrgen() { - var publicKey *asymmetric.PublicKey - - if publicKeyHex != "" { - publicKeyBytes, err := hex.DecodeString(publicKeyHex) - if err != nil { - log.Fatalf("error converting hex: %s\n", err) - } - publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) - if err != nil { - log.Fatalf("error converting public key: %s\n", err) - } - } else if privateKeyFile != "" { - masterKey, err := readMasterKey() - if err != nil { - fmt.Printf("read master key failed: %v\n", err) - os.Exit(1) - } - privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) - if err != nil { - log.Fatalf("load private key file fail: %v\n", err) - } - publicKey = privateKey.PubKey() - } else { - fmt.Println("privateKey path or publicKey hex is required for addrgen") - os.Exit(1) - } - - addr, err := crypto.PubKey2Addr(publicKey, crypto.TestNet) - if err != nil { - log.Fatalf("unexpected error: %v\n", err) - } - fmt.Printf("wallet address: %s\n", addr) -} - func readMasterKey() (string, error) { fmt.Println("Enter master key(press Enter for default: \"\"): ") bytePwd, err := terminal.ReadPassword(int(syscall.Stdin)) diff --git a/cmd/cql-utils/noncegen.go b/cmd/cql-utils/noncegen.go new file mode 100644 index 000000000..7d1453fa3 --- /dev/null +++ b/cmd/cql-utils/noncegen.go @@ -0,0 +1,124 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "encoding/hex" + "fmt" + "math/rand" + "os" + "runtime" + "time" + + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/kms" + mine "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils/log" +) + +func runNonce() { + var publicKey *asymmetric.PublicKey + + if publicKeyHex != "" { + publicKeyBytes, err := hex.DecodeString(publicKeyHex) + if err != nil { + log.Fatalf("error converting hex: %s\n", err) + } + publicKey, err = asymmetric.ParsePubKey(publicKeyBytes) + if err != nil { + log.Fatalf("error converting public key: %s\n", err) + } + } else if privateKeyFile != "" { + masterKey, err := readMasterKey() + if err != nil { + fmt.Printf("read master key failed: %v\n", err) + os.Exit(1) + } + privateKey, err := kms.LoadPrivateKey(privateKeyFile, []byte(masterKey)) + if err != nil { + log.Fatalf("load private key file fail: %v\n", err) + } + publicKey = privateKey.PubKey() + } else { + log.Fatalln("can neither convert public key nor load private key") + } + + noncegen(publicKey) +} + +func noncegen(publicKey *asymmetric.PublicKey) *mine.NonceInfo { + publicKeyBytes := publicKey.Serialize() + + cpuCount := runtime.NumCPU() + log.Infof("cpu: %d\n", cpuCount) + stopCh := make(chan struct{}) + nonceCh := make(chan mine.NonceInfo) + + rand.Seed(time.Now().UnixNano()) + step := 256 / cpuCount + for i := 0; i < cpuCount; i++ { + go func(i int) { + startBit := i * step + position := startBit / 64 + shift := uint(startBit % 64) + log.Infof("position: %d, shift: %d, i: %d", position, shift, i) + var start mine.Uint256 + if position == 0 { + start = mine.Uint256{A: uint64(1<= difficulty { + nonce := mine.NonceInfo{ + Nonce: j, + Difficulty: currentDifficulty, + Hash: currentHash, + } + nonceCh <- nonce + } + } + } + }(i) + } + + nonce := <-nonceCh + close(stopCh) + + // verify result + if !kms.IsIDPubNonceValid(&proto.RawNodeID{Hash: nonce.Hash}, &nonce.Nonce, publicKey) { + log.Fatalf("nonce: %v\nnode id: %s", nonce, nonce.Hash.String()) + } + + // print result + fmt.Printf("nonce: %v\n", nonce) + fmt.Printf("node id: %v\n", nonce.Hash.String()) + + return &nonce +} diff --git a/cmd/cql-utils/rpc.go b/cmd/cql-utils/rpc.go new file mode 100644 index 000000000..50808a914 --- /dev/null +++ b/cmd/cql-utils/rpc.go @@ -0,0 +1,148 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" + "reflect" + "strings" + + "github.com/CovenantSQL/CovenantSQL/blockproducer" + "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" + "github.com/CovenantSQL/CovenantSQL/rpc" + "github.com/CovenantSQL/CovenantSQL/sqlchain" + "github.com/CovenantSQL/CovenantSQL/utils/log" + "github.com/CovenantSQL/CovenantSQL/worker" +) + +var ( + rpcServiceMap = map[string]interface{}{ + "DHT": &route.DHTService{}, + "DBS": &worker.DBMSRPCService{}, + "BPDB": &blockproducer.DBService{}, + "SQLC": &sqlchain.MuxService{}, + } + rpcName string + rpcEndpoint string + rpcReq string +) + +func init() { + flag.StringVar(&rpcName, "rpc", "", "rpc name to do test call") + flag.StringVar(&rpcEndpoint, "rpc-endpoint", "", "rpc endpoint to do test call") + flag.StringVar(&rpcReq, "rpc-req", "", "rpc request to do test call, in json format") +} + +func runRPC() { + if configFile == "" { + // error + log.Error("config file path is required for rpc tool") + os.Exit(1) + } + if rpcEndpoint == "" || rpcName == "" || rpcReq == "" { + // error + log.Error("rpc payload is required for rpc tool") + os.Exit(1) + } + + if err := client.Init(configFile, []byte("")); err != nil { + fmt.Printf("init rpc client failed: %v\n", err) + os.Exit(1) + return + } + + req, resp := resolveRPCEntities() + + // fill the req with request body + if err := json.Unmarshal([]byte(rpcReq), req); err != nil { + fmt.Printf("decode request body failed: %v\n", err) + os.Exit(1) + return + } + + if err := rpc.NewCaller().CallNode(proto.NodeID(rpcEndpoint), rpcName, req, resp); err != nil { + // send request failed + fmt.Printf("call rpc failed: %v\n", err) + os.Exit(1) + return + } + + // print the response + if resBytes, err := json.MarshalIndent(resp, "", " "); err != nil { + fmt.Printf("marshal response failed: %v\n", err) + os.Exit(1) + } else { + fmt.Println(string(resBytes)) + } +} + +func resolveRPCEntities() (req interface{}, resp interface{}) { + rpcParts := strings.SplitN(rpcName, ".", 2) + + if len(rpcParts) != 2 { + // error rpc name + fmt.Printf("%v is not a valid rpc name\n", rpcName) + os.Exit(1) + return + } + + rpcService := rpcParts[0] + + if s, supported := rpcServiceMap[rpcService]; supported { + typ := reflect.TypeOf(s) + + // traversing methods + for m := 0; m < typ.NumMethod(); m++ { + method := typ.Method(m) + mtype := method.Type + + if method.Name == rpcParts[1] { + // name matched + if mtype.PkgPath() != "" || mtype.NumIn() != 3 || mtype.NumOut() != 1 { + fmt.Printf("%v is not a valid rpc endpoint method\n", rpcName) + os.Exit(1) + return + } + + argType := mtype.In(1) + replyType := mtype.In(2) + + if argType.Kind() == reflect.Ptr { + req = reflect.New(argType.Elem()).Interface() + } else { + req = reflect.New(argType).Interface() + + } + + resp = reflect.New(replyType.Elem()).Interface() + + return + } + } + } + + // not found + fmt.Printf("rpc method %v not found\n", rpcName) + os.Exit(1) + + return +} From 87bdbf7134e1f1beb21ad762de4b4bb3aa046f50 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 16 Oct 2018 08:46:30 +0800 Subject: [PATCH 02/38] Complete adapterconfgen --- cmd/cql-utils/adapterconfgen.go | 154 ++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 28 deletions(-) diff --git a/cmd/cql-utils/adapterconfgen.go b/cmd/cql-utils/adapterconfgen.go index 535cf3ce0..6f7a3b8bd 100644 --- a/cmd/cql-utils/adapterconfgen.go +++ b/cmd/cql-utils/adapterconfgen.go @@ -18,25 +18,25 @@ package main import ( "bufio" - "encoding/json" "fmt" "io/ioutil" "os" + "strings" "github.com/CovenantSQL/CovenantSQL/utils/log" "gopkg.in/yaml.v2" ) type adapterConfig struct { - ListenAddr string - CertificatePath string - PrivateKeyPath string - VerifyCertificate bool - ClientCAPath string - AdminCerts []string - WriteCerts []string - StorageDriver string - StorageRoot string + ListenAddr string `yaml:"ListenAddr"` + CertificatePath string `yaml:"CertificatePath"` + PrivateKeyPath string `yaml:"PrivateKeyPath"` + VerifyCertificate bool `yaml:"VerifyCertificate"` + ClientCAPath string `yaml:"ClientCAPath"` + AdminCerts []string `yaml:"AdminCerts"` + WriteCerts []string `yaml:"WriteCerts"` + StorageDriver string `yaml:"StorageDriver"` + StorageRoot string `yaml:"StorageRoot"` } var ( @@ -54,43 +54,113 @@ var ( ) func (c *adapterConfig) readListenAddr() { - + newAddr := readDataFromStdin("ListenAddr (default: %v): ", c.ListenAddr) + if newAddr != "" { + c.ListenAddr = newAddr + } } func (c *adapterConfig) readCertificatePath() { - + newCertPath := readDataFromStdin("CertificatePath (default: %v): ", c.CertificatePath) + if newCertPath != "" { + c.CertificatePath = newCertPath + } } func (c *adapterConfig) readPrivateKeyPath() { - + newPrivateKeyPath := readDataFromStdin("PrivateKeyPath (default: %v): ", c.PrivateKeyPath) + if newPrivateKeyPath != "" { + c.PrivateKeyPath = newPrivateKeyPath + } } -func (c *adapterConfig) readVerifyCertificate() { +func (c *adapterConfig) readVerifyCertificate() bool { + shouldVerifyCertificate := readDataFromStdin( + "VerifyCertificate (default: %v) (y/n): ", c.VerifyCertificate) + if shouldVerifyCertificate != "" { + switch shouldVerifyCertificate { + case "y": + fallthrough + case "Y": + c.VerifyCertificate = true + case "N": + fallthrough + case "n": + c.VerifyCertificate = false + } + } + return c.VerifyCertificate } func (c *adapterConfig) readClientCAPath() { - + newClientCAPath := readDataFromStdin("ClientCAPath (default: %v)", c.ClientCAPath) + if newClientCAPath != "" { + c.ClientCAPath = newClientCAPath + } } func (c *adapterConfig) readAdminCerts() { + var newCerts []string + for { + record := readDataFromStdin("AdminCerts: ") + + if record == "" { + break + } + + newCerts = append(newCerts, record) + } + + c.AdminCerts = newCerts } func (c *adapterConfig) readWriteCerts() { + var newCerts []string + + for { + record := readDataFromStdin("WriteCerts: ") + + if record == "" { + break + } + + newCerts = append(newCerts, record) + } + c.WriteCerts = newCerts } func (c *adapterConfig) readStorageDriver() { - + newStorageDriver := readDataFromStdin("StorageDriver (default: %v)", c.StorageDriver) + if newStorageDriver != "" { + c.StorageDriver = newStorageDriver + } } func (c *adapterConfig) readStorageRoot() { - + newStorageRoot := readDataFromStdin("StorageRoot (default: %v)", c.StorageRoot) + if newStorageRoot != "" { + c.StorageRoot = newStorageRoot + } } -func (c *adapterConfig) loadFromExistingConfig(rawConfig map[string]interface{}) { - if rawConfig == nil || rawConfig["Adapter"] == nil { +func (c *adapterConfig) loadFromExistingConfig(rawConfig yaml.MapSlice) { + if rawConfig == nil { + return + } + + // find adapter config in map slice + var originalConfig interface{} + + for _, item := range rawConfig { + if keyStr, ok := item.Key.(string); ok && keyStr == "Adapter" { + originalConfig = item.Value + } + } + + if originalConfig == nil { return } @@ -98,12 +168,12 @@ func (c *adapterConfig) loadFromExistingConfig(rawConfig map[string]interface{}) var configBytes []byte var err error - if configBytes, err = json.Marshal(rawConfig["Adapter"]); err != nil { + if configBytes, err = yaml.Marshal(originalConfig); err != nil { log.Warningf("load previous adapter config failed: %v", err) return } - if err = json.Unmarshal(configBytes, c); err != nil { + if err = yaml.Unmarshal(configBytes, c); err != nil { log.Warningf("load previous adapter config failed: %v", err) return } @@ -111,20 +181,48 @@ func (c *adapterConfig) loadFromExistingConfig(rawConfig map[string]interface{}) return } -func (c *adapterConfig) writeToRawConfig(rawConfig map[string]interface{}) { - if rawConfig != nil { - rawConfig["Adapter"] = c +func (c *adapterConfig) writeToRawConfig(rawConfig yaml.MapSlice) yaml.MapSlice { + if rawConfig == nil { + return rawConfig + } + + // find adapter config in map slice + for i, item := range rawConfig { + if keyStr, ok := item.Key.(string); ok && keyStr == "Adapter" { + rawConfig[i].Value = c + return rawConfig + } } + + // not found + rawConfig = append(rawConfig, yaml.MapItem{ + Key: "Adapter", + Value: c, + }) + + return rawConfig } func (c *adapterConfig) readAllConfig() { + c.readListenAddr() + c.readCertificatePath() + c.readPrivateKeyPath() + + if c.readVerifyCertificate() { + c.readClientCAPath() + c.readAdminCerts() + c.readWriteCerts() + } + c.readStorageDriver() + c.readStorageRoot() } -func readDataFromStdin(prompt string) (s string) { +func readDataFromStdin(prompt string, values ...interface{}) (s string) { reader := bufio.NewReader(os.Stdin) - fmt.Print(prompt) + fmt.Printf(prompt, values...) s, _ = reader.ReadString('\n') + s = strings.TrimSpace(s) return } @@ -142,7 +240,7 @@ func runAdapterConfGen() { } // load config - var rawConfig map[string]interface{} + var rawConfig yaml.MapSlice if err = yaml.Unmarshal(configBytes, &rawConfig); err != nil { log.Errorf("a valid config file is required for adapterconfgen: %v", err) os.Exit(1) @@ -162,7 +260,7 @@ func runAdapterConfGen() { defaultAdapterConfig.loadFromExistingConfig(rawConfig) defaultAdapterConfig.readAllConfig() - defaultAdapterConfig.writeToRawConfig(rawConfig) + rawConfig = defaultAdapterConfig.writeToRawConfig(rawConfig) if configBytes, err = yaml.Marshal(rawConfig); err != nil { log.Errorf("marshal config failed: %v", err) From ed941af5343e24c7238d5a5727784cc5e36c14e6 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 16 Oct 2018 08:47:48 +0800 Subject: [PATCH 03/38] Refine doc of adapter --- cmd/cql-adapter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cql-adapter/README.md b/cmd/cql-adapter/README.md index 38194e2a7..0a1e0b60d 100644 --- a/cmd/cql-adapter/README.md +++ b/cmd/cql-adapter/README.md @@ -51,7 +51,7 @@ $ cql-utils -tool adapterconfgen -config config.yaml ListenAddr (default: 0.0.0.0:4661): ⏎ CertificatePath (default: server.pem): ⏎ PrivateKeyPath (default: server-key.pem): ⏎ -VerifyCertificate (default: false): ⏎ +VerifyCertificate (default: true) (y/n): ⏎ ClientCAPath (default:): ⏎ AdminCerts (default:): ⏎ WriteCerts (default:): ⏎ From 5c2404348eb5cc7135ba9e0057c29cbdfa0ce775 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 16 Oct 2018 10:44:41 +0800 Subject: [PATCH 04/38] Fix mysql-adapter bug on initial use database statement --- cmd/cql-mysql-adapter/cursor.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/cql-mysql-adapter/cursor.go b/cmd/cql-mysql-adapter/cursor.go index 98ab3154c..c91185c5b 100644 --- a/cmd/cql-mysql-adapter/cursor.go +++ b/cmd/cql-mysql-adapter/cursor.go @@ -149,10 +149,6 @@ func (c *Cursor) UseDB(dbName string) (err error) { func (c *Cursor) HandleQuery(query string) (r *my.Result, err error) { var conn *sql.DB - if conn, err = c.ensureDatabase(); err != nil { - return - } - // send empty result for variables query/table listing if emptyResultQuery.MatchString(query) { // return empty result @@ -180,6 +176,10 @@ func (c *Cursor) HandleQuery(query string) (r *my.Result, err error) { return } + if conn, err = c.ensureDatabase(); err != nil { + return + } + // as normal query if readQuery.MatchString(query) { var rows *sql.Rows From 79657d3ab4715dfffd2123b2de7b33834d40140d Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 16 Oct 2018 11:16:20 +0800 Subject: [PATCH 05/38] Support database id quoted with backtick in mysql-adapter --- cmd/cql-mysql-adapter/cursor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cql-mysql-adapter/cursor.go b/cmd/cql-mysql-adapter/cursor.go index c91185c5b..1169364a7 100644 --- a/cmd/cql-mysql-adapter/cursor.go +++ b/cmd/cql-mysql-adapter/cursor.go @@ -31,7 +31,7 @@ import ( var ( dbIDRegex = regexp.MustCompile("^[a-zA-Z0-9_\\.]+$") emptyResultQuery = regexp.MustCompile("^(?i)\\s*(?:(?:SELECT\\s+)?@@(?:\\w+\\.)?|SHOW\\s+VARIABLES|SHOW\\s+DATABASES|SET|ROLLBACK).*$") - useDatabaseQuery = regexp.MustCompile("^(?i)\\s*USE\\s+(\\w+)\\s*$") + useDatabaseQuery = regexp.MustCompile("^(?i)\\s*USE\\s+`?(\\w+)`?\\s*$") readQuery = regexp.MustCompile("^(?i)\\s*(?:SELECT|SHOW|DESC)") ) From f6db8b58c53de871af0d0761a09f644b4dd2c0ca Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 16 Oct 2018 11:42:26 +0800 Subject: [PATCH 06/38] Update mysql-adapter to support libmysql trivial case --- cmd/cql-mysql-adapter/cursor.go | 51 +++++++++++++++++++++++++++------ cmd/cql-mysql-adapter/server.go | 2 +- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cmd/cql-mysql-adapter/cursor.go b/cmd/cql-mysql-adapter/cursor.go index 1169364a7..253a25e75 100644 --- a/cmd/cql-mysql-adapter/cursor.go +++ b/cmd/cql-mysql-adapter/cursor.go @@ -29,22 +29,24 @@ import ( ) var ( - dbIDRegex = regexp.MustCompile("^[a-zA-Z0-9_\\.]+$") - emptyResultQuery = regexp.MustCompile("^(?i)\\s*(?:(?:SELECT\\s+)?@@(?:\\w+\\.)?|SHOW\\s+VARIABLES|SHOW\\s+DATABASES|SET|ROLLBACK).*$") - useDatabaseQuery = regexp.MustCompile("^(?i)\\s*USE\\s+`?(\\w+)`?\\s*$") - readQuery = regexp.MustCompile("^(?i)\\s*(?:SELECT|SHOW|DESC)") + dbIDRegex = regexp.MustCompile("^[a-zA-Z0-9_\\.]+$") + specialSelectQuery = regexp.MustCompile("^(?i)SELECT\\s+(DATABASE|USER)\\(\\)\\s*;?\\s*$") + emptyResultQuery = regexp.MustCompile("^(?i)\\s*(?:(?:SELECT\\s+)?@@(?:\\w+\\.)?|SHOW\\s+VARIABLES|SHOW\\s+DATABASES|SET|ROLLBACK).*$") + useDatabaseQuery = regexp.MustCompile("^(?i)\\s*USE\\s+`?(\\w+)`?\\s*$") + readQuery = regexp.MustCompile("^(?i)\\s*(?:SELECT|SHOW|DESC)") ) // Cursor is a mysql connection handler, like a cursor of normal database. type Cursor struct { + server *Server curDBLock sync.Mutex curDB string curDBInstance *sql.DB } // NewCursor returns a new cursor. -func NewCursor() (c *Cursor) { - return &Cursor{} +func NewCursor(s *Server) (c *Cursor) { + return &Cursor{server: s} } func (c *Cursor) buildResultSet(rows *sql.Rows) (r *my.Result, err error) { @@ -152,12 +154,14 @@ func (c *Cursor) HandleQuery(query string) (r *my.Result, err error) { // send empty result for variables query/table listing if emptyResultQuery.MatchString(query) { // return empty result - return &my.Result{ + r = &my.Result{ Status: 0, InsertId: 0, AffectedRows: 0, Resultset: nil, - }, nil + } + + return } // use database query, same logic as COM_INIT_DB @@ -176,6 +180,37 @@ func (c *Cursor) HandleQuery(query string) (r *my.Result, err error) { return } + // special select database + // for libmysql trivial implementations + // https://github.com/mysql/mysql-server/blob/4f1d7cf5fcb11a3f84cff27e37100d7295e7d5ca/client/mysql.cc#L4266 + if matches := specialSelectQuery.FindStringSubmatch(query); len(matches) > 1 { + var resultSet *my.Resultset + + switch strings.ToUpper(matches[1]) { + case "DATABASE": + c.curDBLock.Lock() + resultSet, _ = my.BuildSimpleTextResultset( + []string{"DATABASE()"}, + [][]interface{}{{c.curDB}}, + ) + c.curDBLock.Unlock() + case "USER": + resultSet, _ = my.BuildSimpleTextResultset( + []string{"USER()"}, + [][]interface{}{{c.server.mysqlUser}}, + ) + } + + r = &my.Result{ + Status: 0, + InsertId: 0, + AffectedRows: 0, + Resultset: resultSet, + } + + return + } + if conn, err = c.ensureDatabase(); err != nil { return } diff --git a/cmd/cql-mysql-adapter/server.go b/cmd/cql-mysql-adapter/server.go index c6728f7c6..a355143d1 100644 --- a/cmd/cql-mysql-adapter/server.go +++ b/cmd/cql-mysql-adapter/server.go @@ -59,7 +59,7 @@ func (s *Server) Serve() { } func (s *Server) handleConn(conn net.Conn) { - h, err := mys.NewConn(conn, s.mysqlUser, s.mysqlPassword, NewCursor()) + h, err := mys.NewConn(conn, s.mysqlUser, s.mysqlPassword, NewCursor(s)) if err != nil { log.Errorf("process connection failed: %v", err) From 6a3605a7845f75a2f65294c6c57c1c447d8a7443 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 17 Oct 2018 11:13:35 +0800 Subject: [PATCH 07/38] Add blockproducer rpc to cql-utils and refactor msgpack utils to use single msgpack handler --- cmd/cql-utils/rpc.go | 2 ++ utils/msgpack.go | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/cql-utils/rpc.go b/cmd/cql-utils/rpc.go index 50808a914..855e86d47 100644 --- a/cmd/cql-utils/rpc.go +++ b/cmd/cql-utils/rpc.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/CovenantSQL/CovenantSQL/blockproducer" + bp "github.com/CovenantSQL/CovenantSQL/blockproducer" "github.com/CovenantSQL/CovenantSQL/client" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/route" @@ -40,6 +41,7 @@ var ( "DBS": &worker.DBMSRPCService{}, "BPDB": &blockproducer.DBService{}, "SQLC": &sqlchain.MuxService{}, + "MCC": &bp.ChainRPCService{}, } rpcName string rpcEndpoint string diff --git a/utils/msgpack.go b/utils/msgpack.go index fdaa89b64..927d86ac1 100644 --- a/utils/msgpack.go +++ b/utils/msgpack.go @@ -22,35 +22,33 @@ import ( "github.com/ugorji/go/codec" ) -// DecodeMsgPack reverses the encode operation on a byte slice input. -func DecodeMsgPack(buf []byte, out interface{}) error { - r := bytes.NewBuffer(buf) - hd := codec.MsgpackHandle{ +var ( + msgpackHandle = &codec.MsgpackHandle{ WriteExt: true, RawToString: true, } - dec := codec.NewDecoder(r, &hd) +) +// DecodeMsgPack reverses the encode operation on a byte slice input. +func DecodeMsgPack(buf []byte, out interface{}) error { + r := bytes.NewBuffer(buf) + dec := codec.NewDecoder(r, msgpackHandle) return dec.Decode(out) } // DecodeMsgPackPlain reverses the encode operation on a byte slice input without RawToString setting. func DecodeMsgPackPlain(buf []byte, out interface{}) error { r := bytes.NewBuffer(buf) - hd := codec.MsgpackHandle{ + hd := &codec.MsgpackHandle{ WriteExt: true, } - dec := codec.NewDecoder(r, &hd) + dec := codec.NewDecoder(r, hd) return dec.Decode(out) } // EncodeMsgPack writes an encoded object to a new bytes buffer. func EncodeMsgPack(in interface{}) (*bytes.Buffer, error) { buf := bytes.NewBuffer(nil) - hd := codec.MsgpackHandle{ - WriteExt: true, - RawToString: true, - } - enc := codec.NewEncoder(buf, &hd) + enc := codec.NewEncoder(buf, msgpackHandle) err := enc.Encode(in) return buf, err } From 5ae7b353d6dd1b0a48b7ff6f328e4b5e8b99b278 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 17 Oct 2018 11:14:26 +0800 Subject: [PATCH 08/38] Add check interval argument for explorer --- cmd/cql-explorer/main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/cql-explorer/main.go b/cmd/cql-explorer/main.go index e5fcf80f4..4e37f4699 100644 --- a/cmd/cql-explorer/main.go +++ b/cmd/cql-explorer/main.go @@ -16,7 +16,10 @@ package main -import "flag" +import ( + "flag" + "time" +) var ( version = "unknown" @@ -26,16 +29,17 @@ var ( var ( // config - configFile string - dbID string - listenAddr string + configFile string + listenAddr string + checkInterval time.Duration ) func init() { flag.StringVar(&configFile, "config", "./config.yaml", "config file path") flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api") + flag.DurationVar(&checkInterval, "interval", time.Second*2, "new block check interval for explorer") } func main() { - + } From 8106512b70061247c5040e45d77f79119d694978 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 17 Oct 2018 11:15:19 +0800 Subject: [PATCH 09/38] Refactor observer use cas in stopped condition test --- cmd/cql-observer/service.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/cql-observer/service.go b/cmd/cql-observer/service.go index e143c4305..1834c2bdc 100644 --- a/cmd/cql-observer/service.go +++ b/cmd/cql-observer/service.go @@ -434,7 +434,7 @@ func (s *Service) addBlock(dbID proto.DatabaseID, count int32, b *ct.Block) (err } func (s *Service) stop() (err error) { - if atomic.LoadInt32(&s.stopped) == 1 { + if !atomic.CompareAndSwapInt32(&s.stopped, 0, 1) { // stopped return ErrStopped } @@ -442,8 +442,6 @@ func (s *Service) stop() (err error) { s.lock.Lock() defer s.lock.Unlock() - atomic.StoreInt32(&s.stopped, 1) - // send cancel subscription to all databases log.Infof("stop subscribing all databases") From 3b7dd7a0f6665b02724b7fc9e95012446b86f4c7 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 17 Oct 2018 17:41:30 +0800 Subject: [PATCH 10/38] Add TransactionWrapper for transaction to decode/encode using msgpack --- blockproducer/interfaces/transaction.go | 2 + .../interfaces/transaction_wrapper.go | 176 ++++++++++++++++++ blockproducer/types/baseaccount.go | 4 + blockproducer/types/createdb.go | 4 + blockproducer/types/msgpack_test.go | 42 +++++ blockproducer/types/transfer.go | 4 + blockproducer/types/txsqlchainbilling.go | 4 + utils/big.go | 2 +- utils/msgpack.go | 7 + 9 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 blockproducer/interfaces/transaction_wrapper.go create mode 100644 blockproducer/types/msgpack_test.go diff --git a/blockproducer/interfaces/transaction.go b/blockproducer/interfaces/transaction.go index df2497378..608b7bffd 100644 --- a/blockproducer/interfaces/transaction.go +++ b/blockproducer/interfaces/transaction.go @@ -89,4 +89,6 @@ type Transaction interface { GetTransactionType() TransactionType Sign(signer *asymmetric.PrivateKey) error Verify() error + MarshalHash() ([]byte, error) + Msgsize() int } diff --git a/blockproducer/interfaces/transaction_wrapper.go b/blockproducer/interfaces/transaction_wrapper.go new file mode 100644 index 000000000..1a311be07 --- /dev/null +++ b/blockproducer/interfaces/transaction_wrapper.go @@ -0,0 +1,176 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package interfaces + +import ( + "reflect" + "sync" + + "github.com/CovenantSQL/CovenantSQL/utils" + "github.com/pkg/errors" + "github.com/ugorji/go/codec" +) + +const ( + // msgpack constants, copied from go/codec/msgpack.go + valueTypeArray = 10 +) + +var ( + txTypeMapping sync.Map + txType = reflect.TypeOf((*Transaction)(nil)).Elem() + txWrapperType = reflect.TypeOf((*TransactionWrapper)(nil)) + + // ErrInvalidContainerType represents invalid container type read from msgpack bytes. + ErrInvalidContainerType = errors.New("invalid container type for TransactionWrapper") + // ErrInvalidTransactionType represents invalid transaction type read from msgpack bytes. + ErrInvalidTransactionType = errors.New("invalid transaction type, can not instantiate transaction") + // ErrTransactionRegistration represents invalid transaction object type being registered. + ErrTransactionRegistration = errors.New("transaction register failed") + // ErrMsgPackVersionMismatch represents the msgpack library abi has changed. + ErrMsgPackVersionMismatch = errors.New("msgpack library version mismatch") +) + +func init() { + // detect msgpack version + if codec.GenVersion != 8 { + panic(ErrMsgPackVersionMismatch) + } + + // register transaction wrapper to msgpack handler + if err := utils.RegisterInterfaceToMsgPack(txType, txWrapperType); err != nil { + panic(err) + } +} + +// TransactionWrapper is the wrapper for Transaction interface for serialization/deserialization purpose. +type TransactionWrapper struct { + Transaction +} + +// CodecEncodeSelf implements codec.Selfer interface. +func (w *TransactionWrapper) CodecEncodeSelf(e *codec.Encoder) { + helperEncoder, encDriver := codec.GenHelperEncoder(e) + + if w == nil || w.Transaction == nil { + encDriver.EncodeNil() + return + } + + // translate wrapper to two fields array wrapped by map + encDriver.WriteArrayStart(2) + encDriver.WriteArrayElem() + encDriver.EncodeUint(uint64(w.GetTransactionType())) + encDriver.WriteArrayElem() + helperEncoder.EncFallback(w.Transaction) + encDriver.WriteArrayEnd() +} + +// CodecDecodeSelf implements codec.Selfer interface. +func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder) { + helperDecoder, decodeDriver := codec.GenHelperDecoder(d) + + // clear fields + w.Transaction = nil + + if ct := decodeDriver.ContainerType(); ct != valueTypeArray { + panic(errors.Wrapf(ErrInvalidContainerType, "type %v applied", ct)) + } + + containerLen := decodeDriver.ReadArrayStart() + + for i := 0; i < containerLen; i++ { + if decodeDriver.CheckBreak() { + break + } + + decodeDriver.ReadArrayElem() + + if i == 0 { + if decodeDriver.TryDecodeAsNil() { + // invalid type, can not instantiate transaction + panic(ErrInvalidTransactionType) + } else { + txType := (TransactionType)(helperDecoder.C.UintV(decodeDriver.DecodeUint64(), 32)) + + var err error + if w.Transaction, err = NewTransaction(txType); err != nil { + panic(err) + } + } + } else if i == 1 { + if !decodeDriver.TryDecodeAsNil() { + helperDecoder.DecFallback(&w.Transaction, true) + } + } else { + helperDecoder.DecStructFieldNotFound(i, "") + } + } + + decodeDriver.ReadArrayEnd() +} + +// RegisterTransaction registers transaction type to wrapper. +func RegisterTransaction(t TransactionType, tx Transaction) { + if tx == nil { + panic(ErrTransactionRegistration) + } + rt := reflect.TypeOf(tx) + + if rt == txWrapperType { + panic(ErrTransactionRegistration) + } + + txTypeMapping.Store(t, rt) +} + +// NewTransaction instantiates new transaction object. +func NewTransaction(t TransactionType) (tx Transaction, err error) { + var d interface{} + var ok bool + var rt reflect.Type + + if d, ok = txTypeMapping.Load(t); !ok { + err = errors.Wrapf(ErrInvalidTransactionType, "transaction not registered") + return + } + rt = d.(reflect.Type) + + if !rt.Implements(txType) || rt == txWrapperType { + err = errors.Wrap(ErrInvalidTransactionType, "invalid transaction registered") + return + } + + var rv reflect.Value + + if rt.Kind() == reflect.Ptr { + rv = reflect.New(rt.Elem()) + } else { + rv = reflect.New(rt).Elem() + } + + tx = rv.Interface().(Transaction) + + return +} + +// WrapTransaction wraps transaction in wrapper. +func WrapTransaction(tx Transaction) *TransactionWrapper { + return &TransactionWrapper{ + Transaction: tx, + } +} diff --git a/blockproducer/types/baseaccount.go b/blockproducer/types/baseaccount.go index af93be2ec..612146e93 100644 --- a/blockproducer/types/baseaccount.go +++ b/blockproducer/types/baseaccount.go @@ -79,3 +79,7 @@ func (b *BaseAccount) Sign(signer *asymmetric.PrivateKey) (err error) { func (b *BaseAccount) Verify() (err error) { return } + +func init() { + pi.RegisterTransaction(pi.TransactionTypeBaseAccount, (*BaseAccount)(nil)) +} diff --git a/blockproducer/types/createdb.go b/blockproducer/types/createdb.go index 41e105421..11befccb5 100644 --- a/blockproducer/types/createdb.go +++ b/blockproducer/types/createdb.go @@ -70,3 +70,7 @@ func (cd *CreateDatabase) Sign(signer *asymmetric.PrivateKey) (err error) { func (cd *CreateDatabase) Verify() error { return cd.DefaultHashSignVerifierImpl.Verify(&cd.CreateDatabaseHeader) } + +func init() { + pi.RegisterTransaction(pi.TransactionTypeCreataDatabase, (*CreateDatabase)(nil)) +} diff --git a/blockproducer/types/msgpack_test.go b/blockproducer/types/msgpack_test.go new file mode 100644 index 000000000..26083c6e9 --- /dev/null +++ b/blockproducer/types/msgpack_test.go @@ -0,0 +1,42 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package types + +import ( + "reflect" + "testing" + + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" + "github.com/CovenantSQL/CovenantSQL/utils" + . "github.com/smartystreets/goconvey/convey" +) + +func TestEncodeSingleTransaction(t *testing.T) { + Convey("test encode/decode single transaction", t, func() { + var t pi.Transaction + t = pi.WrapTransaction(&BaseAccount{}) + buf, err := utils.EncodeMsgPack(t) + So(err, ShouldBeNil) + + var out pi.Transaction + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldBeNil) + So(out, ShouldNotBeNil) + So(reflect.TypeOf(out).String(), ShouldContainSubstring, "TransactionWrapper") + So(out.GetTransactionType(), ShouldEqual, t.GetTransactionType()) + }) +} diff --git a/blockproducer/types/transfer.go b/blockproducer/types/transfer.go index 62f84b5e9..342b6d945 100644 --- a/blockproducer/types/transfer.go +++ b/blockproducer/types/transfer.go @@ -107,3 +107,7 @@ func (t *Transfer) Verify() (err error) { } return } + +func init() { + pi.RegisterTransaction(pi.TransactionTypeTransfer, (*Transfer)(nil)) +} diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/txsqlchainbilling.go index fcb680ded..df8e26cef 100644 --- a/blockproducer/types/txsqlchainbilling.go +++ b/blockproducer/types/txsqlchainbilling.go @@ -191,3 +191,7 @@ func (tb *TxBilling) GetSignedBlock() *hash.Hash { defer tb.mutex.Unlock() return tb.SignedBlock } + +func init() { + pi.RegisterTransaction(pi.TransactionTypeBilling, (*TxBilling)(nil)) +} diff --git a/utils/big.go b/utils/big.go index 0c7e75930..6568671f5 100644 --- a/utils/big.go +++ b/utils/big.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// Package math provides integer math utilities. +// Package utils provides integer math utilities. package utils import ( diff --git a/utils/msgpack.go b/utils/msgpack.go index 927d86ac1..cd924b682 100644 --- a/utils/msgpack.go +++ b/utils/msgpack.go @@ -18,6 +18,7 @@ package utils import ( "bytes" + "reflect" "github.com/ugorji/go/codec" ) @@ -28,6 +29,12 @@ var ( RawToString: true, } ) + +// RegisterInterfaceToMsgPack binds interface decode/encode to specified implementation. +func RegisterInterfaceToMsgPack(intf, impl reflect.Type) (err error) { + return msgpackHandle.Intf2Impl(intf, impl) +} + // DecodeMsgPack reverses the encode operation on a byte slice input. func DecodeMsgPack(buf []byte, out interface{}) error { r := bytes.NewBuffer(buf) From b5b964f65bfad280673c9d2f18f64a72acde286f Mon Sep 17 00:00:00 2001 From: Levente Liu Date: Thu, 18 Oct 2018 10:43:50 +0800 Subject: [PATCH 11/38] Add txs from pool --- blockproducer/chain.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index 330cdb187..1b6a4d0c0 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -501,7 +501,8 @@ func (c *Chain) produceBlock(now time.Time) error { Timestamp: now, }, }, - TxBillings: c.ti.fetchUnpackedTxBillings(), + TxBillings: c.ti.fetchUnpackedTxBillings(), + Transactions: c.ms.pullTxs(), } err = b.PackAndSignBlock(priv) From 7aa9b58abbe122491a549bbe473d688a8ace8ad8 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 12:15:09 +0800 Subject: [PATCH 12/38] Add missing rpc method declarations --- route/acl.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/route/acl.go b/route/acl.go index 5c6b073d3..01c25f98d 100644 --- a/route/acl.go +++ b/route/acl.go @@ -101,6 +101,10 @@ const ( SQLCFetchBlock // SQLCFetchAckedQuery is used by sqlchain to fetch response ack from adjacent nodes SQLCFetchAckedQuery + // SQLCSignBilling is used by sqlchain to response billing signature for periodic billing request + SQLCSignBilling + // SQLCLaunchBilling is used by blockproducer to trigger the billing process in sqlchain + SQLCLaunchBilling // SQLCSubscribeTransactions is used by sqlchain to handle observer subscription request SQLCSubscribeTransactions // SQLCCancelSubscription is used by sqlchain to handle observer subscription cancellation request @@ -109,6 +113,16 @@ const ( OBSAdviseAckedQuery // OBSAdviseNewBlock is used by sqlchain to push new block to observers OBSAdviseNewBlock + // MCCAdviseNewBlock is used by block producer to push block to adjacent nodes + MCCAdviseNewBlock + // MCCAdviseTxBilling is used by block producer to push billing transaction to adjacent nodes + MCCAdviseTxBilling + // MCCAdviseBillingRequest is used by block producer to push billing request to adjacent nodes + MCCAdviseBillingRequest + // MCCFetchBlock is used by nodes to fetch block from block producer + MCCFetchBlock + // MCCFetchTxBilling is used by nodes to fetch billing transaction from block producer + MCCFetchTxBilling // MCCNextAccountNonce is used by block producer main chain to allocate next nonce for transactions MCCNextAccountNonce // MCCAddTx is used by block producer main chain to upload transaction @@ -164,6 +178,10 @@ func (s RemoteFunc) String() string { return "SQLC.FetchBlock" case SQLCFetchAckedQuery: return "SQLC.FetchAckedQuery" + case SQLCSignBilling: + return "SQLC.SignBilling" + case SQLCLaunchBilling: + return "SQLC.LaunchBilling" case SQLCSubscribeTransactions: return "SQLC.SubscribeTransactions" case SQLCCancelSubscription: @@ -172,6 +190,16 @@ func (s RemoteFunc) String() string { return "OBS.AdviseAckedQuery" case OBSAdviseNewBlock: return "OBS.AdviseNewBlock" + case MCCAdviseNewBlock: + return "MCC.AdviseNewBlock" + case MCCAdviseTxBilling: + return "MCC.AdviseTxBilling" + case MCCAdviseBillingRequest: + return "MCC.AdviseBillingRequest" + case MCCFetchBlock: + return "MCC.FetchBlock" + case MCCFetchTxBilling: + return "MCC.FetchTxBilling" case MCCNextAccountNonce: return "MCC.NextAccountNonce" case MCCAddTx: From 991a979885174a733000b4f6ab24b4e27e1c8b7c Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 12:28:49 +0800 Subject: [PATCH 13/38] Refactor existing rpc call --- blockproducer/chain.go | 10 ++++------ blockproducer/chain_test.go | 5 ++--- sqlchain/chain.go | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index 1b6a4d0c0..e2daeaf3c 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -27,6 +27,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/merkle" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" @@ -528,7 +529,6 @@ func (c *Chain) produceBlock(now time.Time) error { wg.Add(1) go func(id proto.NodeID) { defer wg.Done() - method := fmt.Sprintf("%s.%s", MainChainRPCName, "AdviseNewBlock") blockReq := &AdviseNewBlockReq{ Envelope: proto.Envelope{ // TODO(lambda): Add fields. @@ -536,7 +536,7 @@ func (c *Chain) produceBlock(now time.Time) error { Block: b, } blockResp := &AdviseNewBlockResp{} - if err := c.cl.CallNode(id, method, blockReq, blockResp); err != nil { + if err := c.cl.CallNode(id, route.MCCAdviseNewBlock.String(), blockReq, blockResp); err != nil { log.WithFields(log.Fields{ "peer": c.rt.getPeerInfoString(), "curr_turn": c.rt.getNextTurn(), @@ -621,7 +621,6 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp }, TxBilling: tb, } - method := fmt.Sprintf("%s.%s", MainChainRPCName, "AdviseTxBilling") peers := c.rt.getPeers() wg := &sync.WaitGroup{} for _, s := range peers.Servers { @@ -630,7 +629,7 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp go func(id proto.NodeID) { defer wg.Done() tbResp := &AdviseTxBillingResp{} - if err := c.cl.CallNode(id, method, tbReq, tbResp); err != nil { + if err := c.cl.CallNode(id, route.MCCAdviseTxBilling.String(), tbReq, tbResp); err != nil { log.WithFields(log.Fields{ "peer": c.rt.getPeerInfoString(), "curr_turn": c.rt.getNextTurn(), @@ -901,13 +900,12 @@ func (c *Chain) syncHead() { Height: h, } resp := &FetchBlockResp{} - method := fmt.Sprintf("%s.%s", MainChainRPCName, "FetchBlock") peers := c.rt.getPeers() succ := false for i, s := range peers.Servers { if !s.ID.IsEqual(&c.rt.nodeID) { - err = c.cl.CallNode(s.ID, method, req, resp) + err = c.cl.CallNode(s.ID, route.MCCFetchBlock.String(), req, resp) if err != nil || resp.Block == nil { log.WithFields(log.Fields{ "peer": c.rt.getPeerInfoString(), diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index 307518889..11a7653dd 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -17,7 +17,6 @@ package blockproducer import ( - "fmt" "io/ioutil" "sync" "testing" @@ -29,6 +28,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/kayak" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/utils/log" . "github.com/smartystreets/goconvey/convey" ) @@ -271,9 +271,8 @@ func TestMultiNode(t *testing.T) { Req: br, } bResp := &AdviseBillingResp{} - method := fmt.Sprintf("%s.%s", MainChainRPCName, "AdviseBillingRequest") log.Debugf("CallNode %d hash is %s", val, br.RequestHash) - err = chains[i].cl.CallNode(chains[i].rt.nodeID, method, bReq, bResp) + err = chains[i].cl.CallNode(chains[i].rt.nodeID, route.MCCAdviseBillingRequest.String(), bReq, bResp) if err != nil { log.WithFields(log.Fields{ "peer": chains[i].rt.getPeerInfoString(), diff --git a/sqlchain/chain.go b/sqlchain/chain.go index 8817ed6e4..4a8d8f617 100644 --- a/sqlchain/chain.go +++ b/sqlchain/chain.go @@ -1246,7 +1246,7 @@ func (c *Chain) collectBillingSignatures(billings *pt.BillingRequest) { resp := &pt.BillingResponse{} - if err = c.cl.CallNode(bp, "MCC.AdviseBillingRequest", req, resp); err != nil { + if err = c.cl.CallNode(bp, route.MCCAdviseBillingRequest.String(), req, resp); err != nil { return } }() @@ -1266,7 +1266,7 @@ func (c *Chain) collectBillingSignatures(billings *pt.BillingRequest) { defer rpcWG.Done() resp := &MuxSignBillingResp{} - if err := c.cl.CallNode(id, "SQLC.SignBilling", req, resp); err != nil { + if err := c.cl.CallNode(id, route.SQLCSignBilling.String(), req, resp); err != nil { log.WithFields(log.Fields{ "peer": c.rt.getPeerInfoString(), "time": c.rt.getChainTimeString(), From d13de30a5e9720e5edc3ca193d062437ae84dc8c Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 12:52:39 +0800 Subject: [PATCH 14/38] Unify all rpc service name to route package --- blockproducer/db_service.go | 2 -- blockproducer/db_service_test.go | 2 +- blockproducer/helper_test.go | 2 +- blockproducer/rpc.go | 5 ----- blockproducer/runtime.go | 3 ++- client/helper_test.go | 6 +++--- cmd/cql-observer/observer.go | 4 ++-- cmd/cql-utils/rpc.go | 10 +++++----- cmd/cqld/bootstrap.go | 5 ++--- route/acl.go | 13 +++++++++++++ route/service_test.go | 4 ++-- rpc/README.md | 2 +- rpc/_example/tracker/main.go | 2 +- rpc/rpcutil_test.go | 8 ++++---- rpc/server_test.go | 2 +- sqlchain/chain_test.go | 5 ++--- sqlchain/types/observer.go | 2 -- worker/db_test.go | 4 ++-- worker/dbms.go | 10 ++-------- 19 files changed, 44 insertions(+), 47 deletions(-) diff --git a/blockproducer/db_service.go b/blockproducer/db_service.go index feadfc058..75a3c80e7 100644 --- a/blockproducer/db_service.go +++ b/blockproducer/db_service.go @@ -40,8 +40,6 @@ import ( const ( // DefaultAllocationRounds defines max rounds to try allocate peers for database creation. DefaultAllocationRounds = 3 - // DBServiceName for block producer to provide database management related logic. - DBServiceName = "BPDB" ) var ( diff --git a/blockproducer/db_service_test.go b/blockproducer/db_service_test.go index a06ed73bc..66d33c8fb 100644 --- a/blockproducer/db_service_test.go +++ b/blockproducer/db_service_test.go @@ -66,7 +66,7 @@ func TestService(t *testing.T) { } // register BPDB service to rpc - err = server.RegisterService(DBServiceName, dbService) + err = server.RegisterService(route.BPDBRPCName, dbService) So(err, ShouldBeNil) // get database diff --git a/blockproducer/helper_test.go b/blockproducer/helper_test.go index 2a8d42fb8..169152add 100644 --- a/blockproducer/helper_test.go +++ b/blockproducer/helper_test.go @@ -215,7 +215,7 @@ func initNode(confRP, privateKeyRP string) (cleanupFunc func(), dht *route.DHTSe } // init rpc - if server, err = rpc.NewServerWithService(rpc.ServiceMap{"DHT": dht}); err != nil { + if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil { return } diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 22322558d..852679c11 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -22,11 +22,6 @@ import ( "github.com/CovenantSQL/CovenantSQL/proto" ) -const ( - // MainChainRPCName defines rpc service name of main chain internal consensus. - MainChainRPCName = "MCC" -) - // ChainRPCService defines a main chain RPC server. type ChainRPCService struct { chain *Chain diff --git a/blockproducer/runtime.go b/blockproducer/runtime.go index f282a6cda..b1e376f0d 100644 --- a/blockproducer/runtime.go +++ b/blockproducer/runtime.go @@ -23,6 +23,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/kayak" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" ) @@ -99,7 +100,7 @@ func newRuntime(cfg *Config, accountAddress proto.AccountAddress) *rt { } func (r *rt) startService(chain *Chain) { - r.server.RegisterService(MainChainRPCName, &ChainRPCService{chain: chain}) + r.server.RegisterService(route.BlockProducerRPCName, &ChainRPCService{chain: chain}) } // nextTick returns the current clock reading and the duration till the next turn. If duration diff --git a/client/helper_test.go b/client/helper_test.go index 59aafa303..0a2118e09 100644 --- a/client/helper_test.go +++ b/client/helper_test.go @@ -276,17 +276,17 @@ func initNode() (cleanupFunc func(), tempDir string, server *rpc.Server, err err } // init rpc - if server, err = rpc.NewServerWithService(rpc.ServiceMap{"DHT": dht}); err != nil { + if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil { return } // register bpdb service - if err = server.RegisterService(bp.DBServiceName, &stubBPDBService{}); err != nil { + if err = server.RegisterService(route.BPDBRPCName, &stubBPDBService{}); err != nil { return } // register fake chain service - if err = server.RegisterService(bp.MainChainRPCName, &stubBPDBService{}); err != nil { + if err = server.RegisterService(route.BlockProducerRPCName, &stubBPDBService{}); err != nil { return } diff --git a/cmd/cql-observer/observer.go b/cmd/cql-observer/observer.go index a6913fb8a..ff7ed1b22 100644 --- a/cmd/cql-observer/observer.go +++ b/cmd/cql-observer/observer.go @@ -20,8 +20,8 @@ import ( "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" - ct "github.com/CovenantSQL/CovenantSQL/sqlchain/types" ) func registerNode() (err error) { @@ -48,7 +48,7 @@ func startService(server *rpc.Server) (service *Service, err error) { return } - if err = server.RegisterService(ct.ObserverService, service); err != nil { + if err = server.RegisterService(route.ObserverRPCName, service); err != nil { return } diff --git a/cmd/cql-utils/rpc.go b/cmd/cql-utils/rpc.go index 855e86d47..a2e62a702 100644 --- a/cmd/cql-utils/rpc.go +++ b/cmd/cql-utils/rpc.go @@ -37,11 +37,11 @@ import ( var ( rpcServiceMap = map[string]interface{}{ - "DHT": &route.DHTService{}, - "DBS": &worker.DBMSRPCService{}, - "BPDB": &blockproducer.DBService{}, - "SQLC": &sqlchain.MuxService{}, - "MCC": &bp.ChainRPCService{}, + route.DHTRPCName: &route.DHTService{}, + route.DBRPCName: &worker.DBMSRPCService{}, + route.BPDBRPCName: &blockproducer.DBService{}, + route.SQLChainRPCName: &sqlchain.MuxService{}, + route.BlockProducerRPCName: &bp.ChainRPCService{}, } rpcName string rpcEndpoint string diff --git a/cmd/cqld/bootstrap.go b/cmd/cqld/bootstrap.go index d12681193..cde81f434 100644 --- a/cmd/cqld/bootstrap.go +++ b/cmd/cqld/bootstrap.go @@ -46,7 +46,6 @@ const ( //privateKeyFile = "private.key" //dhtFileName = "dht.db" kayakServiceName = "Kayak" - dhtServiceName = "DHT" ) func runNode(nodeID proto.NodeID, listenAddr string) (err error) { @@ -123,7 +122,7 @@ func runNode(nodeID proto.NodeID, listenAddr string) (err error) { // register service rpc log.Infof("register dht service rpc") - err = server.RegisterService(dhtServiceName, dht) + err = server.RegisterService(route.DHTRPCName, dht) if err != nil { log.Errorf("register dht service failed: %s", err) return @@ -144,7 +143,7 @@ func runNode(nodeID proto.NodeID, listenAddr string) (err error) { log.Errorf("init block producer db service failed: %v", err) return } - if err = server.RegisterService(bp.DBServiceName, dbService); err != nil { + if err = server.RegisterService(route.BPDBRPCName, dbService); err != nil { log.Errorf("init block producer db service failed: %v", err) return } diff --git a/route/acl.go b/route/acl.go index 01c25f98d..6762f19b8 100644 --- a/route/acl.go +++ b/route/acl.go @@ -133,6 +133,19 @@ const ( MCCQueryAccountStableBalance // MCCQueryAccountCovenantBalance is used by block producer to provide account covenant coin balance MCCQueryAccountCovenantBalance + + // DHTRPCName defines the block producer dh-rpc service name + DHTRPCName = "DHT" + // BlockProducerRPCName defines main chain rpc name + BlockProducerRPCName = "MCC" + // SQLChainRPCName defines the sql chain rpc name + SQLChainRPCName = "SQLC" + // DBRPCName defines the sql chain db service rpc name + DBRPCName = "DBS" + // BPDBRPCName defines the block producer db service rpc name + BPDBRPCName = "BPDB" + // ObserverRPCName defines the observer node service rpc name + ObserverRPCName = "OBS" ) // String returns the RemoteFunc string diff --git a/route/service_test.go b/route/service_test.go index 620c56e75..16f6354c0 100644 --- a/route/service_test.go +++ b/route/service_test.go @@ -43,7 +43,7 @@ func TestDHTService_FindNeighbor_FindNode(t *testing.T) { addr := "127.0.0.1:0" dht, _ := NewDHTService(DHTStorePath+"1", new(consistent.KMSStorage), false) kms.ResetBucket() - rpc.RegisterName("DHT", dht) + rpc.RegisterName(DHTRPCName, dht) ln, err := net.Listen("tcp", addr) if err != nil { fmt.Println(err) @@ -207,7 +207,7 @@ func TestDHTService_Ping(t *testing.T) { addr := "127.0.0.1:0" dht, _ := NewDHTService(DHTStorePath, new(consistent.KMSStorage), false) - rpc.RegisterName("DHT", dht) + rpc.RegisterName(DHTRPCName, dht) ln, err := net.Listen("tcp", addr) if err != nil { fmt.Println(err) diff --git a/rpc/README.md b/rpc/README.md index 4aafc248d..3bbe39543 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -164,7 +164,7 @@ func main() { } // Register DHT service - server, err := rpc.NewServerWithService(rpc.ServiceMap{"DHT": dht}) + server, err := rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}) if err != nil { log.Fatal(err) } diff --git a/rpc/_example/tracker/main.go b/rpc/_example/tracker/main.go index 1b00d67d7..706d35afa 100644 --- a/rpc/_example/tracker/main.go +++ b/rpc/_example/tracker/main.go @@ -25,7 +25,7 @@ func main() { } // Register DHT service - server, err := rpc.NewServerWithService(rpc.ServiceMap{"DHT": dht}) + server, err := rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}) if err != nil { log.Fatal(err) } diff --git a/rpc/rpcutil_test.go b/rpc/rpcutil_test.go index e10da5c6d..dc437343e 100644 --- a/rpc/rpcutil_test.go +++ b/rpc/rpcutil_test.go @@ -64,7 +64,7 @@ func TestCaller_CallNode(t *testing.T) { masterKey := []byte("") dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true) - server, err := NewServerWithService(ServiceMap{"DHT": dht}) + server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht}) if err != nil { t.Fatal(err) } @@ -90,7 +90,7 @@ func TestCaller_CallNode(t *testing.T) { } respA := new(proto.PingResp) - err = client.CallNode(conf.GConf.BP.NodeID, "DHT.Ping", reqA, respA) + err = client.CallNode(conf.GConf.BP.NodeID, route.DHTPing.String(), reqA, respA) if err != nil { t.Fatal(err) } @@ -193,7 +193,7 @@ func TestNewPersistentCaller(t *testing.T) { masterKey := []byte("") dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true) - server, err := NewServerWithService(ServiceMap{"DHT": dht}) + server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht}) if err != nil { t.Fatal(err) } @@ -288,7 +288,7 @@ func BenchmarkPersistentCaller_Call(b *testing.B) { masterKey := []byte("") dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true) - server, err := NewServerWithService(ServiceMap{"DHT": dht}) + server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht}) if err != nil { b.Fatal(err) } diff --git a/rpc/server_test.go b/rpc/server_test.go index ba901f804..d1674c9f9 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -187,7 +187,7 @@ func TestEncPingFindNeighbor(t *testing.T) { masterKey := []byte("abc") dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true) - server, err := NewServerWithService(ServiceMap{"DHT": dht}) + server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht}) if err != nil { log.Fatal(err) } diff --git a/sqlchain/chain_test.go b/sqlchain/chain_test.go index fd69cdb59..37500a3a3 100644 --- a/sqlchain/chain_test.go +++ b/sqlchain/chain_test.go @@ -41,7 +41,6 @@ var ( testTick = 100 * time.Millisecond testQueryTTL int32 = 10 testDatabaseID proto.DatabaseID = "tdb-test" - testChainService = "SQLC" testPeriodNumber int32 = 10 testClientNumberPerChain = 3 ) @@ -155,7 +154,7 @@ func TestMultiChain(t *testing.T) { defer server.Stop() // Create multiplexing service from RPC server - mux := NewMuxService(testChainService, server) + mux := NewMuxService(route.SQLChainRPCName, server) // Create chain instance config := &Config{ @@ -232,7 +231,7 @@ func TestMultiChain(t *testing.T) { // Start BP if dht, err := route.NewDHTService(testDHTStoreFile, new(consistent.KMSStorage), true); err != nil { t.Fatalf("Error occurred: %v", err) - } else if err = bpsvr.RegisterService("DHT", dht); err != nil { + } else if err = bpsvr.RegisterService(route.DHTRPCName, dht); err != nil { t.Fatalf("Error occurred: %v", err) } diff --git a/sqlchain/types/observer.go b/sqlchain/types/observer.go index 9e0aa35cc..112e99257 100644 --- a/sqlchain/types/observer.go +++ b/sqlchain/types/observer.go @@ -17,8 +17,6 @@ package types const ( - // ObserverService is the service name for observer to receive. - ObserverService = "OBS" // ReplicateFromBeginning is the replication offset observes from genesis block. ReplicateFromBeginning = int32(0) // ReplicateFromNewest is the replication offset observes from block head of current node. diff --git a/worker/db_test.go b/worker/db_test.go index 31e4afe0b..3d7071686 100644 --- a/worker/db_test.go +++ b/worker/db_test.go @@ -693,12 +693,12 @@ func initNode() (cleanupFunc func(), server *rpc.Server, err error) { } // init rpc - if server, err = rpc.NewServerWithService(rpc.ServiceMap{"DHT": dht}); err != nil { + if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil { return } // register bpdb service - if err = server.RegisterService(bp.DBServiceName, &stubBPDBService{}); err != nil { + if err = server.RegisterService(route.BPDBRPCName, &stubBPDBService{}); err != nil { return } diff --git a/worker/dbms.go b/worker/dbms.go index e945d5b88..a3632de1f 100644 --- a/worker/dbms.go +++ b/worker/dbms.go @@ -38,12 +38,6 @@ const ( // DBKayakRPCName defines rpc service name of database internal consensus. DBKayakRPCName = "DBC" // aka. database consensus - // SQLChainRPCName defines rpc service name of sql-chain internal consensus. - SQLChainRPCName = "SQLC" - - // DBServiceRPCName defines rpc service name of database external query api. - DBServiceRPCName = "DBS" // aka. database service - // DBMetaFileName defines dbms meta file name. DBMetaFileName = "db.meta" ) @@ -67,10 +61,10 @@ func NewDBMS(cfg *DBMSConfig) (dbms *DBMS, err error) { dbms.kayakMux = ka.NewMuxService(DBKayakRPCName, cfg.Server) // init sql-chain rpc mux - dbms.chainMux = sqlchain.NewMuxService(SQLChainRPCName, cfg.Server) + dbms.chainMux = sqlchain.NewMuxService(route.SQLChainRPCName, cfg.Server) // init service - dbms.rpc = NewDBMSRPCService(DBServiceRPCName, cfg.Server, dbms) + dbms.rpc = NewDBMSRPCService(route.DBRPCName, cfg.Server, dbms) return } From 890753d334b1a879b2e84aed7165c7280e485848 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 13:23:05 +0800 Subject: [PATCH 15/38] Swallow data on unknown fields during msgpack decode --- blockproducer/interfaces/transaction_wrapper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/blockproducer/interfaces/transaction_wrapper.go b/blockproducer/interfaces/transaction_wrapper.go index 1a311be07..96c75886e 100644 --- a/blockproducer/interfaces/transaction_wrapper.go +++ b/blockproducer/interfaces/transaction_wrapper.go @@ -117,6 +117,7 @@ func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder) { helperDecoder.DecFallback(&w.Transaction, true) } } else { + helperDecoder.DecSwallow() helperDecoder.DecStructFieldNotFound(i, "") } } From 67889d183200fcad4d77828b2e3b7881b9750aa8 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 13:28:13 +0800 Subject: [PATCH 16/38] Remove unused TxType of TxBilling structure --- blockproducer/chain.go | 2 +- blockproducer/types/block_test.go | 15 --------- blockproducer/types/tx.go | 42 ------------------------ blockproducer/types/tx_gen.go | 21 ------------ blockproducer/types/tx_gen_test.go | 3 -- blockproducer/types/txsqlchainbilling.go | 3 +- blockproducer/types/xxx_test.go | 2 +- 7 files changed, 3 insertions(+), 85 deletions(-) delete mode 100644 blockproducer/types/tx.go delete mode 100644 blockproducer/types/tx_gen.go delete mode 100644 blockproducer/types/tx_gen_test.go diff --git a/blockproducer/chain.go b/blockproducer/chain.go index e2daeaf3c..c0ea56a0f 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -606,7 +606,7 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp } var ( tc = types.NewTxContent(uint32(nc), br, receivers, fees, rewards, resp) - tb = types.NewTxBilling(tc, types.TxTypeBilling, &c.rt.accountAddress) + tb = types.NewTxBilling(tc, &c.rt.accountAddress) ) if err = tb.Sign(privKey); err != nil { return diff --git a/blockproducer/types/block_test.go b/blockproducer/types/block_test.go index e2c42bf0d..10f2f712d 100644 --- a/blockproducer/types/block_test.go +++ b/blockproducer/types/block_test.go @@ -24,7 +24,6 @@ import ( "bytes" "github.com/CovenantSQL/CovenantSQL/utils" - . "github.com/smartystreets/goconvey/convey" ) func TestHeader_MarshalUnmarshalBinary(t *testing.T) { @@ -142,17 +141,3 @@ func TestBlock_PackAndSignBlock(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } } - -func TestOther_MarshalHash(t *testing.T) { - Convey("marshal hash", t, func() { - tm := TxType(1) - s, err := tm.MarshalHash() - So(err, ShouldBeNil) - So(s, ShouldNotBeEmpty) - - So(tm.String(), ShouldResemble, "TxUnknown") - - tm = TxType(0) - So(tm.String(), ShouldResemble, "TxBilling") - }) -} diff --git a/blockproducer/types/tx.go b/blockproducer/types/tx.go deleted file mode 100644 index 3e102d338..000000000 --- a/blockproducer/types/tx.go +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2018 The CovenantSQL Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package types - -//go:generate hsp - -// TxType represents the type of tx. -type TxType byte - -const ( - // TxTypeBilling defines TxType for database service billing. - TxTypeBilling TxType = 0 -) - -// String returns the TxType name. -func (tt *TxType) String() string { - switch *tt { - case TxTypeBilling: - return "TxBilling" - default: - return "TxUnknown" - } -} - -// ToByte returns the the that represents the TxType. -func (tt *TxType) ToByte() byte { - return byte(*tt) -} diff --git a/blockproducer/types/tx_gen.go b/blockproducer/types/tx_gen.go deleted file mode 100644 index 46dfae05c..000000000 --- a/blockproducer/types/tx_gen.go +++ /dev/null @@ -1,21 +0,0 @@ -package types - -// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. - -import ( - hsp "github.com/CovenantSQL/HashStablePack/marshalhash" -) - -// MarshalHash marshals for hash -func (z TxType) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - o = hsp.AppendByte(o, byte(z)) - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z TxType) Msgsize() (s int) { - s = hsp.ByteSize - return -} diff --git a/blockproducer/types/tx_gen_test.go b/blockproducer/types/tx_gen_test.go deleted file mode 100644 index 76e7feeed..000000000 --- a/blockproducer/types/tx_gen_test.go +++ /dev/null @@ -1,3 +0,0 @@ -package types - -// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/txsqlchainbilling.go index df8e26cef..6050aec43 100644 --- a/blockproducer/types/txsqlchainbilling.go +++ b/blockproducer/types/txsqlchainbilling.go @@ -82,10 +82,9 @@ type TxBilling struct { } // NewTxBilling generates a new TxBilling. -func NewTxBilling(txContent *TxContent, txType TxType, addr *proto.AccountAddress) *TxBilling { +func NewTxBilling(txContent *TxContent, addr *proto.AccountAddress) *TxBilling { return &TxBilling{ TxContent: *txContent, - TxType: txType.ToByte(), AccountAddress: addr, } } diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index f5a0efe10..2622424b2 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -267,7 +267,7 @@ func generateRandomTxBilling() (*TxBilling, error) { } blockHash := generateRandomHash() - txBilling := NewTxBilling(txContent, TxTypeBilling, &accountAddress) + txBilling := NewTxBilling(txContent, &accountAddress) txBilling.TxHash = &txHash txBilling.Signee = pub txBilling.Signature = sign From 5b2fe885bf510b7d08fc71df097577ef60927944 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 13:28:52 +0800 Subject: [PATCH 17/38] Remove accountAddress field in BillingResponse structure --- blockproducer/chain.go | 7 ++--- blockproducer/types/billing.go | 44 ++---------------------------- blockproducer/types/billing_gen.go | 16 ++++------- blockproducer/types/xxx_test.go | 14 ++++------ blockproducer/xxx_test.go | 14 ++++------ 5 files changed, 23 insertions(+), 72 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index c0ea56a0f..b884438d1 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -592,10 +592,9 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp return } resp := &types.BillingResponse{ - AccountAddress: accountAddress, - RequestHash: h, - Signee: privKey.PubKey(), - Signature: sign, + RequestHash: h, + Signee: privKey.PubKey(), + Signature: sign, } // generate and push the txbilling diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing.go index 3e4f80502..11274fafb 100644 --- a/blockproducer/types/billing.go +++ b/blockproducer/types/billing.go @@ -36,26 +36,6 @@ type BillingRequestHeader struct { GasAmounts []*proto.AddrAndGas } -// -//// MarshalHash marshals for hash -//func (bh *BillingRequestHeader) MarshalHash() ([]byte, error) { -// buffer := bytes.NewBuffer(nil) -// -// err := utils.WriteElements(buffer, binary.BigEndian, -// &bh.DatabaseID, -// &bh.LowBlock, -// &bh.LowHeight, -// &bh.HighBlock, -// &bh.HighHeight, -// &bh.GasAmounts, -// ) -// -// if err != nil { -// return nil, err -// } -// return buffer.Bytes(), nil -//} - // BillingRequest defines periodically Billing sync. type BillingRequest struct { Header BillingRequestHeader @@ -64,23 +44,6 @@ type BillingRequest struct { Signatures []*asymmetric.Signature } -//// MarshalHash marshals for hash -//func (br *BillingRequest) MarshalHash() ([]byte, error) { -// buffer := bytes.NewBuffer(nil) -// -// err := utils.WriteElements(buffer, binary.BigEndian, -// &br.Header, -// &br.RequestHash, -// &br.Signees, -// &br.Signatures, -// ) -// -// if err != nil { -// return nil, err -// } -// return buffer.Bytes(), nil -//} - // PackRequestHeader computes the hash of header. func (br *BillingRequest) PackRequestHeader() (*hash.Hash, error) { b, err := br.Header.MarshalHash() @@ -103,8 +66,7 @@ func (br *BillingRequest) SignRequestHeader(signee *asymmetric.PrivateKey) (*asy // BillingResponse defines the the response for BillingRequest. type BillingResponse struct { - AccountAddress proto.AccountAddress - RequestHash hash.Hash - Signee *asymmetric.PublicKey - Signature *asymmetric.Signature + RequestHash hash.Hash + Signee *asymmetric.PublicKey + Signature *asymmetric.Signature } diff --git a/blockproducer/types/billing_gen.go b/blockproducer/types/billing_gen.go index 6e2efb4ab..bd6cd1f2f 100644 --- a/blockproducer/types/billing_gen.go +++ b/blockproducer/types/billing_gen.go @@ -135,8 +135,8 @@ func (z *BillingRequestHeader) Msgsize() (s int) { func (z *BillingResponse) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 4 - o = append(o, 0x84, 0x84) + // map header, size 3 + o = append(o, 0x83, 0x83) if z.Signee == nil { o = hsp.AppendNil(o) } else { @@ -146,7 +146,7 @@ func (z *BillingResponse) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } } - o = append(o, 0x84) + o = append(o, 0x83) if z.Signature == nil { o = hsp.AppendNil(o) } else { @@ -156,18 +156,12 @@ func (z *BillingResponse) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } } - o = append(o, 0x84) + o = append(o, 0x83) if oTemp, err := z.RequestHash.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x84) - if oTemp, err := z.AccountAddress.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } return } @@ -185,6 +179,6 @@ func (z *BillingResponse) Msgsize() (s int) { } else { s += z.Signature.Msgsize() } - s += 12 + z.RequestHash.Msgsize() + 15 + z.AccountAddress.Msgsize() + s += 12 + z.RequestHash.Msgsize() return } diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index 2622424b2..9b867f83c 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -213,10 +213,9 @@ func generateRandomBillingResponse() (*BillingResponse, error) { return nil, err } resp := BillingResponse{ - AccountAddress: proto.AccountAddress(generateRandomHash()), - RequestHash: h, - Signee: pub, - Signature: sign, + RequestHash: h, + Signee: pub, + Signature: sign, } return &resp, nil } @@ -232,10 +231,9 @@ func generateRandomTxContent() (*TxContent, error) { return nil, err } resp := &BillingResponse{ - AccountAddress: proto.AccountAddress(generateRandomHash()), - RequestHash: req.RequestHash, - Signee: pub, - Signature: sign, + RequestHash: req.RequestHash, + Signee: pub, + Signature: sign, } receivers := make([]*proto.AccountAddress, peerNum) diff --git a/blockproducer/xxx_test.go b/blockproducer/xxx_test.go index 4429f206b..fc9d9c262 100644 --- a/blockproducer/xxx_test.go +++ b/blockproducer/xxx_test.go @@ -251,10 +251,9 @@ func generateRandomBillingResponse() (*types.BillingResponse, error) { return nil, err } resp := types.BillingResponse{ - AccountAddress: proto.AccountAddress(generateRandomHash()), - RequestHash: h, - Signee: pub, - Signature: sign, + RequestHash: h, + Signee: pub, + Signature: sign, } return &resp, nil } @@ -270,10 +269,9 @@ func generateRandomTxContent() (*types.TxContent, error) { return nil, err } resp := &types.BillingResponse{ - AccountAddress: proto.AccountAddress(generateRandomHash()), - RequestHash: req.RequestHash, - Signee: pub, - Signature: sign, + RequestHash: req.RequestHash, + Signee: pub, + Signature: sign, } receivers := make([]*proto.AccountAddress, peerNum) From 2a74c792bdce0b637919ea89660bf2be1b604300 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 13:30:51 +0800 Subject: [PATCH 18/38] Add TransactionTypeMixin for Transaction type heuristic --- blockproducer/interfaces/mixins.go | 34 +++++++++++++++ blockproducer/interfaces/mixins_gen.go | 27 ++++++++++++ blockproducer/interfaces/mixins_gen_test.go | 47 +++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 blockproducer/interfaces/mixins.go create mode 100644 blockproducer/interfaces/mixins_gen.go create mode 100644 blockproducer/interfaces/mixins_gen_test.go diff --git a/blockproducer/interfaces/mixins.go b/blockproducer/interfaces/mixins.go new file mode 100644 index 000000000..edf2965fb --- /dev/null +++ b/blockproducer/interfaces/mixins.go @@ -0,0 +1,34 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package interfaces + +//go:generate hsp + +// TransactionTypeMixin provide type heuristic features to transaction wrapper. +type TransactionTypeMixin struct { + TxType TransactionType +} + +// GetTransactionType implements Transaction.GetTransactionType. +func (m *TransactionTypeMixin) GetTransactionType() TransactionType { + return m.TxType +} + +// SetTransactionType is a helper function for derived types. +func (m *TransactionTypeMixin) SetTransactionType(t TransactionType) { + m.TxType = t +} diff --git a/blockproducer/interfaces/mixins_gen.go b/blockproducer/interfaces/mixins_gen.go new file mode 100644 index 000000000..a3fb205a9 --- /dev/null +++ b/blockproducer/interfaces/mixins_gen.go @@ -0,0 +1,27 @@ +package interfaces + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + hsp "github.com/CovenantSQL/HashStablePack/marshalhash" +) + +// MarshalHash marshals for hash +func (z *TransactionTypeMixin) MarshalHash() (o []byte, err error) { + var b []byte + o = hsp.Require(b, z.Msgsize()) + // map header, size 1 + o = append(o, 0x81, 0x81) + if oTemp, err := z.TxType.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *TransactionTypeMixin) Msgsize() (s int) { + s = 1 + 7 + z.TxType.Msgsize() + return +} diff --git a/blockproducer/interfaces/mixins_gen_test.go b/blockproducer/interfaces/mixins_gen_test.go new file mode 100644 index 000000000..eb3a35968 --- /dev/null +++ b/blockproducer/interfaces/mixins_gen_test.go @@ -0,0 +1,47 @@ +package interfaces + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + "bytes" + "crypto/rand" + "encoding/binary" + "testing" +) + +func TestMarshalHashTransactionTypeMixin(t *testing.T) { + v := TransactionTypeMixin{} + binary.Read(rand.Reader, binary.BigEndian, &v) + bts1, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + bts2, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} + +func BenchmarkMarshalHashTransactionTypeMixin(b *testing.B) { + v := TransactionTypeMixin{} + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.MarshalHash() + } +} + +func BenchmarkAppendMsgTransactionTypeMixin(b *testing.B) { + v := TransactionTypeMixin{} + bts := make([]byte, 0, v.Msgsize()) + bts, _ = v.MarshalHash() + b.SetBytes(int64(len(bts))) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + bts, _ = v.MarshalHash() + } +} From c0d38b74802f48735ee96aec829528e0c8d054d2 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 13:36:24 +0800 Subject: [PATCH 19/38] Fix typo of transactions --- blockproducer/chain_test.go | 2 +- blockproducer/metastate.go | 4 ++-- blockproducer/metastate_test.go | 18 +++++++++--------- blockproducer/txpool.go | 32 ++++++++++++++++---------------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index 11a7653dd..74f62b6d7 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -77,7 +77,7 @@ func TestChain(t *testing.T) { ao, ok := chain.ms.readonly.accounts[testAddress1] So(ok, ShouldBeTrue) So(ao, ShouldNotBeNil) - So(chain.ms.pool.entries[testAddress1].transacions, ShouldBeEmpty) + So(chain.ms.pool.entries[testAddress1].transactions, ShouldBeEmpty) So(chain.ms.pool.entries[testAddress1].baseNonce, ShouldEqual, 1) var ( bl uint64 diff --git a/blockproducer/metastate.go b/blockproducer/metastate.go index b1bbe6a7d..a38479004 100644 --- a/blockproducer/metastate.go +++ b/blockproducer/metastate.go @@ -310,7 +310,7 @@ func (s *metaState) partialCommitProcedure(txs []pi.Transaction) (_ func(*bolt.T // Rebuild dirty map cm.dirty = newMetaIndex() for _, v := range cp.entries { - for _, tx := range v.transacions { + for _, tx := range v.transactions { if err = cm.applyTransaction(tx); err != nil { return } @@ -758,7 +758,7 @@ func (s *metaState) pullTxs() (txs []pi.Transaction) { defer s.Unlock() for _, v := range s.pool.entries { // TODO(leventeliu): check race condition. - txs = append(txs, v.transacions...) + txs = append(txs, v.transactions...) } return } diff --git a/blockproducer/metastate_test.go b/blockproducer/metastate_test.go index f8296b45a..1d1095489 100644 --- a/blockproducer/metastate_test.go +++ b/blockproducer/metastate_test.go @@ -568,7 +568,7 @@ func TestMetaState(t *testing.T) { }) }) }) - Convey("When transacions are added", func() { + Convey("When transactions are added", func() { var ( n pi.AccountNonce t0 = &pt.BaseAccount{ @@ -600,20 +600,20 @@ func TestMetaState(t *testing.T) { So(err, ShouldBeNil) err = db.Update(ms.applyTransactionProcedure(t0)) So(err, ShouldBeNil) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 1) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 1) err = db.Update(ms.applyTransactionProcedure(t1)) So(err, ShouldBeNil) _, loaded = ms.pool.entries[t1.GetAccountAddress()] So(loaded, ShouldBeTrue) So(ms.pool.hasTx(t0), ShouldBeTrue) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 2) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 2) _, loaded = ms.pool.entries[t1.GetAccountAddress()] So(loaded, ShouldBeTrue) So(ms.pool.hasTx(t0), ShouldBeTrue) So(ms.pool.hasTx(t1), ShouldBeTrue) err = db.Update(ms.applyTransactionProcedure(t2)) So(err, ShouldBeNil) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 3) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 3) _, loaded = ms.pool.entries[t1.GetAccountAddress()] So(loaded, ShouldBeTrue) _, loaded = ms.pool.entries[t2.GetAccountAddress()] @@ -658,25 +658,25 @@ func TestMetaState(t *testing.T) { err = db.Update(ms.partialCommitProcedure([]pi.Transaction{})) So(err, ShouldBeNil) So(ms.pool.entries[addr1].baseNonce, ShouldEqual, 0) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 3) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 3) }) Convey("The partial commit procedure should be appliable for tx0", func() { err = db.Update(ms.partialCommitProcedure([]pi.Transaction{t0})) So(err, ShouldBeNil) So(ms.pool.entries[addr1].baseNonce, ShouldEqual, 1) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 2) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 2) }) Convey("The partial commit procedure should be appliable for tx0-1", func() { err = db.Update(ms.partialCommitProcedure([]pi.Transaction{t0, t1})) So(err, ShouldBeNil) So(ms.pool.entries[addr1].baseNonce, ShouldEqual, 2) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 1) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 1) }) Convey("The partial commit procedure should be appliable for all tx", func() { err = db.Update(ms.partialCommitProcedure([]pi.Transaction{t0, t1, t2})) So(err, ShouldBeNil) So(ms.pool.entries[addr1].baseNonce, ShouldEqual, 3) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 0) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 0) }) Convey( "The partial commit procedure should not be appliable for modified tx", @@ -686,7 +686,7 @@ func TestMetaState(t *testing.T) { So(err, ShouldBeNil) err = db.Update(ms.partialCommitProcedure([]pi.Transaction{t0, t1, t2})) So(err, ShouldEqual, ErrTransactionMismatch) - So(len(ms.pool.entries[addr1].transacions), ShouldEqual, 3) + So(len(ms.pool.entries[addr1].transactions), ShouldEqual, 3) }, ) }) diff --git a/blockproducer/txpool.go b/blockproducer/txpool.go index 8a17156c8..4fd46f683 100644 --- a/blockproducer/txpool.go +++ b/blockproducer/txpool.go @@ -23,34 +23,34 @@ import ( ) type accountTxEntries struct { - account proto.AccountAddress - baseNonce pi.AccountNonce - transacions []pi.Transaction + account proto.AccountAddress + baseNonce pi.AccountNonce + transactions []pi.Transaction } func newAccountTxEntries( addr proto.AccountAddress, baseNonce pi.AccountNonce) (_ *accountTxEntries, ) { return &accountTxEntries{ - account: addr, - baseNonce: baseNonce, - transacions: nil, + account: addr, + baseNonce: baseNonce, + transactions: nil, } } func (e *accountTxEntries) nextNonce() pi.AccountNonce { - return e.baseNonce + pi.AccountNonce(len(e.transacions)) + return e.baseNonce + pi.AccountNonce(len(e.transactions)) } func (e *accountTxEntries) addTx(tx pi.Transaction) { - e.transacions = append(e.transacions, tx) + e.transactions = append(e.transactions, tx) } func (e *accountTxEntries) halfDeepCopy() (cpy *accountTxEntries) { return &accountTxEntries{ - account: e.account, - baseNonce: e.baseNonce, - transacions: e.transacions[:], + account: e.account, + baseNonce: e.baseNonce, + transactions: e.transactions[:], } } @@ -89,12 +89,12 @@ func (p *txPool) hasTx(tx pi.Transaction) (ok bool) { nonce = tx.GetAccountNonce() index = int(nonce - te.baseNonce) ) - if ok = (nonce >= te.baseNonce && index < len(te.transacions)); !ok { + if ok = (nonce >= te.baseNonce && index < len(te.transactions)); !ok { log.Debug("transaction nonce or index already exists") return } // Check transaction hash - if ok = (tx.GetHash() == te.transacions[index].GetHash()); !ok { + if ok = (tx.GetHash() == te.transactions[index].GetHash()); !ok { log.Debug("transaction hash already exists") return } @@ -108,15 +108,15 @@ func (p *txPool) cmpAndMoveNextTx(tx pi.Transaction) (ok bool) { return } // Out of range - if ok = (tx.GetAccountNonce() == te.baseNonce && len(te.transacions) > 0); !ok { + if ok = (tx.GetAccountNonce() == te.baseNonce && len(te.transactions) > 0); !ok { return } // Check transaction hash - if ok = (tx.GetHash() == te.transacions[0].GetHash()); !ok { + if ok = (tx.GetHash() == te.transactions[0].GetHash()); !ok { return } // Move forward - te.transacions = te.transacions[1:] + te.transactions = te.transactions[1:] te.baseNonce++ return } From b895f144b68fd4b7bdeb5d0fad2b10666cbe4f20 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Thu, 18 Oct 2018 21:39:02 +0800 Subject: [PATCH 20/38] Move AdviseBillingReq/Resp to sqlchain/types package --- blockproducer/chain_test.go | 5 +++-- blockproducer/rpc.go | 15 ++------------- sqlchain/types/billing_req.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 sqlchain/types/billing_req.go diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index 74f62b6d7..a99c6bb11 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -29,6 +29,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/route" + ct "github.com/CovenantSQL/CovenantSQL/sqlchain/types" "github.com/CovenantSQL/CovenantSQL/utils/log" . "github.com/smartystreets/goconvey/convey" ) @@ -264,13 +265,13 @@ func TestMultiNode(t *testing.T) { br, err := generateRandomBillingRequest() c.So(err, ShouldBeNil) - bReq := &AdviseBillingReq{ + bReq := &ct.AdviseBillingReq{ Envelope: proto.Envelope{ // TODO(lambda): Add fields. }, Req: br, } - bResp := &AdviseBillingResp{} + bResp := &ct.AdviseBillingResp{} log.Debugf("CallNode %d hash is %s", val, br.RequestHash) err = chains[i].cl.CallNode(chains[i].rt.nodeID, route.MCCAdviseBillingRequest.String(), bReq, bResp) if err != nil { diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 852679c11..38cb43187 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -20,6 +20,7 @@ import ( pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/blockproducer/types" "github.com/CovenantSQL/CovenantSQL/proto" + ct "github.com/CovenantSQL/CovenantSQL/sqlchain/types" ) // ChainRPCService defines a main chain RPC server. @@ -49,18 +50,6 @@ type AdviseTxBillingResp struct { proto.Envelope } -// AdviseBillingReq defines a request of the AdviseBillingRequest RPC method. -type AdviseBillingReq struct { - proto.Envelope - Req *types.BillingRequest -} - -// AdviseBillingResp defines a request of the AdviseBillingRequest RPC method. -type AdviseBillingResp struct { - proto.Envelope - Resp *types.BillingResponse -} - // FetchBlockReq defines a request of the FetchBlock RPC method. type FetchBlockReq struct { proto.Envelope @@ -154,7 +143,7 @@ func (s *ChainRPCService) AdviseTxBilling(req *AdviseTxBillingReq, resp *AdviseT } // AdviseBillingRequest is the RPC method to advise a new billing request to main chain. -func (s *ChainRPCService) AdviseBillingRequest(req *AdviseBillingReq, resp *AdviseBillingResp) error { +func (s *ChainRPCService) AdviseBillingRequest(req *ct.AdviseBillingReq, resp *ct.AdviseBillingResp) error { response, err := s.chain.produceTxBilling(req.Req) if err != nil { return err diff --git a/sqlchain/types/billing_req.go b/sqlchain/types/billing_req.go new file mode 100644 index 000000000..00ee3cde2 --- /dev/null +++ b/sqlchain/types/billing_req.go @@ -0,0 +1,34 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package types + +import ( + pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/proto" +) + +// AdviseBillingReq defines a request of the AdviseBillingRequest RPC method. +type AdviseBillingReq struct { + proto.Envelope + Req *pt.BillingRequest +} + +// AdviseBillingResp defines a request of the AdviseBillingRequest RPC method. +type AdviseBillingResp struct { + proto.Envelope + Resp *pt.BillingRequest +} From ee46afd6165ca479aaae6e6d069d466b6ba0bcf9 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 00:02:17 +0800 Subject: [PATCH 21/38] Fix race condition in dht consistent ring --- consistent/consistent.go | 99 +++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/consistent/consistent.go b/consistent/consistent.go index 5f8fbe6bb..0b1da8053 100644 --- a/consistent/consistent.go +++ b/consistent/consistent.go @@ -73,6 +73,7 @@ type Consistent struct { NumberOfReplicas int count int64 persist Persistence + cacheLock sync.RWMutex sync.RWMutex } @@ -111,7 +112,7 @@ func InitConsistent(storePath string, persistImpl Persistence, initBP bool) (c * _, isKMSStorage := c.persist.(*KMSStorage) if isKMSStorage { for _, n := range nodes[:] { - c.add(n) + c.Add(n) } } else { // currently just for KayakKVServer @@ -137,6 +138,41 @@ func (c *Consistent) Add(node proto.Node) (err error) { return c.add(node) } +// Remove removes an node from the hash. +func (c *Consistent) Remove(nodeID proto.NodeID) (err error) { + c.Lock() + defer c.Unlock() + err = c.persist.DelNode(nodeID) + if err != nil { + log.Errorf("del node failed: %s", err) + return + } + + c.RemoveCache(nodeID) + return +} + +// Set sets all the nodes in the hash. If there are existing nodes not +// present in nodes, they will be removed. +func (c *Consistent) Set(nodes []proto.Node) (err error) { + c.Lock() + defer c.Unlock() + + err = c.persist.Reset() + if err != nil { + log.Errorf("reset bucket failed: %s", err) + return + } + + c.ResetCache() + + for _, v := range nodes { + c.add(v) + } + + return +} + // need c.Lock() before calling func (c *Consistent) add(node proto.Node) (err error) { err = c.persist.SetNode(&node) @@ -145,11 +181,15 @@ func (c *Consistent) add(node proto.Node) (err error) { return } - return c.AddCache(node) + c.AddCache(node) + return } -// AddCache only adds c.circle skips persist -func (c *Consistent) AddCache(node proto.Node) (err error) { +// AddCache only adds c.circle skips persist. +func (c *Consistent) AddCache(node proto.Node) { + c.cacheLock.Lock() + defer c.cacheLock.Unlock() + for i := 0; i < c.NumberOfReplicas; i++ { c.circle[hashKey(c.nodeKey(node.ID, i))] = &node } @@ -158,56 +198,35 @@ func (c *Consistent) AddCache(node proto.Node) (err error) { return } -// Remove removes an node from the hash. -func (c *Consistent) Remove(node proto.NodeID) (err error) { - c.Lock() - defer c.Unlock() - return c.remove(node) -} - -// need c.Lock() before calling -func (c *Consistent) remove(nodeID proto.NodeID) (err error) { - err = c.persist.DelNode(nodeID) - if err != nil { - log.Errorf("del node failed: %s", err) - return - } +// RemoveCache removes an node from the hash cache. +func (c *Consistent) RemoveCache(nodeID proto.NodeID) { + c.cacheLock.Lock() + defer c.cacheLock.Unlock() for i := 0; i < c.NumberOfReplicas; i++ { delete(c.circle, hashKey(c.nodeKey(nodeID, i))) } c.updateSortedHashes() c.count-- - - return } -// Set sets all the nodes in the hash. If there are existing nodes not -// present in nodes, they will be removed. -func (c *Consistent) Set(nodes []proto.Node) (err error) { - c.Lock() - defer c.Unlock() - err = c.persist.Reset() - if err != nil { - log.Errorf("reset bucket failed: %s", err) - return - } +// ResetCache removes all node from the hash cache. +func (c *Consistent) ResetCache() { + c.cacheLock.Lock() + defer c.cacheLock.Unlock() c.circle = make(map[proto.NodeKey]*proto.Node) c.count = 0 c.sortedHashes = NodeKeys{} - - for _, v := range nodes { - c.add(v) - } - - return } // GetNeighbor returns an node close to where name hashes to in the circle. func (c *Consistent) GetNeighbor(name string) (proto.Node, error) { c.RLock() defer c.RUnlock() + c.cacheLock.RLock() + defer c.cacheLock.RUnlock() + if len(c.circle) == 0 { return proto.Node{}, ErrEmptyCircle } @@ -220,6 +239,9 @@ func (c *Consistent) GetNeighbor(name string) (proto.Node, error) { func (c *Consistent) GetNode(name string) (*proto.Node, error) { c.RLock() defer c.RUnlock() + c.cacheLock.RLock() + defer c.cacheLock.RUnlock() + n, ok := c.circle[hashKey(c.nodeKey(proto.NodeID(name), 0))] if ok { return n, nil @@ -243,6 +265,9 @@ func (c *Consistent) search(key proto.NodeKey) (i int) { func (c *Consistent) GetTwoNeighbors(name string) (proto.Node, proto.Node, error) { c.RLock() defer c.RUnlock() + c.cacheLock.RLock() + defer c.cacheLock.RUnlock() + if len(c.circle) == 0 { return proto.Node{}, proto.Node{}, ErrEmptyCircle } @@ -272,6 +297,8 @@ func (c *Consistent) GetTwoNeighbors(name string) (proto.Node, proto.Node, error func (c *Consistent) GetNeighborsEx(name string, n int, roles proto.ServerRoles) ([]proto.Node, error) { c.RLock() defer c.RUnlock() + c.cacheLock.RLock() + defer c.cacheLock.RUnlock() if len(c.circle) == 0 { return nil, ErrEmptyCircle From a96fb52ab183a4dd985608320f852b7f10d1bdf2 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 09:22:45 +0800 Subject: [PATCH 22/38] Refactor billing/signature, support sending request requires entity signing --- blockproducer/chain.go | 55 +--- blockproducer/db_service.go | 17 -- blockproducer/db_service_test.go | 15 +- blockproducer/db_service_types.go | 5 + blockproducer/helper_test.go | 2 - blockproducer/types/billing.go | 115 +++++++-- blockproducer/types/billing_gen.go | 52 ---- blockproducer/types/billing_gen_test.go | 37 --- blockproducer/types/billing_test.go | 234 ++++++++++++++++-- blockproducer/types/errors.go | 3 + blockproducer/types/txsqlchainbilling.go | 21 +- blockproducer/types/txsqlchainbilling_gen.go | 20 +- blockproducer/types/txsqlchainbilling_test.go | 3 - blockproducer/types/xxx_test.go | 77 ++---- blockproducer/xxx_test.go | 54 +--- client/conn.go | 3 - client/helper_test.go | 2 - cmd/cql-faucet/verifier.go | 1 - cmd/cql-minerd/dbms.go | 2 - cmd/cql-observer/service.go | 6 - cmd/cql-utils/addrgen.go | 2 +- cmd/cql-utils/rpc.go | 35 ++- cmd/cqld/adapter.go | 6 +- kayak/types.go | 1 + sqlchain/chain.go | 67 ++--- sqlchain/errors.go | 3 - sqlchain/types/xxx_test.go | 2 - sqlchain/xxx_test.go | 16 +- worker/db.go | 3 - worker/db_test.go | 10 +- worker/dbms_test.go | 6 - worker/types/ack_type.go | 1 + worker/types/init_service_type.go | 1 + worker/types/no_ack_report_type.go | 2 + worker/types/request_type.go | 3 +- worker/types/response_type.go | 1 + worker/types/types_test.go | 36 +-- worker/types/update_service_type.go | 1 + 38 files changed, 465 insertions(+), 455 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index b884438d1..aaf5070f6 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -23,6 +23,7 @@ import ( pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/merkle" @@ -554,7 +555,7 @@ func (c *Chain) produceBlock(now time.Time) error { return err } -func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResponse, err error) { +func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequest, err error) { // TODO(lambda): simplify the function if err = c.checkBillingRequest(br); err != nil { return @@ -564,7 +565,6 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp // TODO(lambda): because there is no token distribution, // we only increase miners' balance but not decrease customer's balance var ( - enc []byte accountNumber = len(br.Header.GasAmounts) receivers = make([]*proto.AccountAddress, accountNumber) fees = make([]uint64, accountNumber) @@ -577,25 +577,16 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp rewards[i] = 0 } - if enc, err = br.MarshalHash(); err != nil { - return - } - h := hash.THashH(enc) - - // generate response - privKey, err := kms.GetLocalPrivateKey() + // add block producer signature + var privKey *asymmetric.PrivateKey + privKey, err = kms.GetLocalPrivateKey() if err != nil { return } - sign, err := privKey.Sign(h[:]) - if err != nil { + + if _, _, err = br.SignRequestHeader(privKey, false); err != nil { return } - resp := &types.BillingResponse{ - RequestHash: h, - Signee: privKey.PubKey(), - Signature: sign, - } // generate and push the txbilling // 1. generate txbilling @@ -604,13 +595,13 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp return } var ( - tc = types.NewTxContent(uint32(nc), br, receivers, fees, rewards, resp) + tc = types.NewTxContent(uint32(nc), br, receivers, fees, rewards) tb = types.NewTxBilling(tc, &c.rt.accountAddress) ) if err = tb.Sign(privKey); err != nil { return } - log.Debugf("response is %s", resp.RequestHash) + log.Debugf("response is %s", br.RequestHash) // 2. push tx c.pendingTxs <- tb @@ -642,39 +633,19 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingResp } wg.Wait() - return resp, nil + return br, nil } // checkBillingRequest checks followings by order: // 1. period of sqlchain; // 2. request's hash // 3. miners' signatures. -func (c *Chain) checkBillingRequest(br *types.BillingRequest) error { +func (c *Chain) checkBillingRequest(br *types.BillingRequest) (err error) { // period of sqlchain; // TODO(lambda): get and check period and miner list of specific sqlchain - // request's hash - enc, err := br.Header.MarshalHash() - if err != nil { - return err - } - h := hash.THashH(enc[:]) - if !h.IsEqual(&br.RequestHash) { - return ErrInvalidHash - } - - // miners' signatures - sLen := len(br.Signees) - if sLen != len(br.Signatures) { - return ErrInvalidBillingRequest - } - for i := range br.Signees { - if !br.Signatures[i].Verify(h[:], br.Signees[i]) { - return ErrSignVerification - } - } - - return nil + err = br.VerifySignatures() + return } func (c *Chain) fetchBlockByHeight(h uint32) (*types.Block, error) { diff --git a/blockproducer/db_service.go b/blockproducer/db_service.go index 75a3c80e7..ef946a66b 100644 --- a/blockproducer/db_service.go +++ b/blockproducer/db_service.go @@ -102,11 +102,6 @@ func (s *DBService) CreateDatabase(req *CreateDatabaseRequest, resp *CreateDatab // call miner nodes to provide service var privateKey *asymmetric.PrivateKey - var pubKey *asymmetric.PublicKey - - if pubKey, err = kms.GetLocalPublicKey(); err != nil { - return - } if privateKey, err = kms.GetLocalPrivateKey(); err != nil { return } @@ -118,7 +113,6 @@ func (s *DBService) CreateDatabase(req *CreateDatabaseRequest, resp *CreateDatab Peers: peers, GenesisBlock: genesisBlock, } - initSvcReq.Header.Signee = pubKey if err = initSvcReq.Sign(privateKey); err != nil { return } @@ -128,7 +122,6 @@ func (s *DBService) CreateDatabase(req *CreateDatabaseRequest, resp *CreateDatab rollbackReq.Header.Instance = wt.ServiceInstance{ DatabaseID: dbID, } - rollbackReq.Header.Signee = pubKey if err = rollbackReq.Sign(privateKey); err != nil { return } @@ -155,7 +148,6 @@ func (s *DBService) CreateDatabase(req *CreateDatabaseRequest, resp *CreateDatab // send response to client resp.Header.InstanceMeta = instanceMeta - resp.Header.Signee = pubKey // sign the response err = resp.Sign(privateKey) @@ -261,9 +253,6 @@ func (s *DBService) GetNodeDatabases(req *wt.InitService, resp *wt.InitServiceRe // send response to client resp.Header.Instances = instances - if resp.Header.Signee, err = kms.GetLocalPublicKey(); err != nil { - return - } var privateKey *asymmetric.PrivateKey if privateKey, err = kms.GetLocalPrivateKey(); err != nil { return @@ -496,10 +485,6 @@ func (s *DBService) generateGenesisBlock(dbID proto.DatabaseID, resourceMeta wt. // TODO(xq262144): following is stub code, real logic should be implemented in the future emptyHash := hash.Hash{} - var pubKey *asymmetric.PublicKey - if pubKey, err = kms.GetLocalPublicKey(); err != nil { - return - } var privKey *asymmetric.PrivateKey if privKey, err = kms.GetLocalPrivateKey(); err != nil { return @@ -518,8 +503,6 @@ func (s *DBService) generateGenesisBlock(dbID proto.DatabaseID, resourceMeta wt. ParentHash: emptyHash, Timestamp: time.Now().UTC(), }, - Signee: pubKey, - Signature: nil, }, } err = genesisBlock.PackAndSignBlock(privKey) diff --git a/blockproducer/db_service_test.go b/blockproducer/db_service_test.go index 66d33c8fb..da00e68ba 100644 --- a/blockproducer/db_service_test.go +++ b/blockproducer/db_service_test.go @@ -46,10 +46,6 @@ func TestService(t *testing.T) { defer cleanup() // get keys - var pubKey *asymmetric.PublicKey - pubKey, err = kms.GetLocalPublicKey() - So(err, ShouldBeNil) - var privateKey *asymmetric.PrivateKey privateKey, err = kms.GetLocalPrivateKey() So(err, ShouldBeNil) @@ -77,7 +73,6 @@ func TestService(t *testing.T) { // test get database getReq := new(GetDatabaseRequest) getReq.Header.DatabaseID = proto.DatabaseID("db") - getReq.Header.Signee = pubKey err = getReq.Sign(privateKey) So(err, ShouldBeNil) @@ -101,7 +96,6 @@ func TestService(t *testing.T) { createDBReq.Header.ResourceMeta = wt.ResourceMeta{ Node: 1, } - createDBReq.Header.Signee = pubKey err = createDBReq.Sign(privateKey) So(err, ShouldBeNil) createDBRes := new(CreateDatabaseResponse) @@ -166,7 +160,6 @@ func TestService(t *testing.T) { // drop database dropDBReq := new(DropDatabaseRequest) dropDBReq.Header.DatabaseID = createDBRes.Header.InstanceMeta.DatabaseID - dropDBReq.Header.Signee = pubKey err = dropDBReq.Sign(privateKey) So(err, ShouldBeNil) dropDBRes := new(DropDatabaseResponse) @@ -176,7 +169,6 @@ func TestService(t *testing.T) { // get this database again to test if it is dropped getReq = new(GetDatabaseRequest) getReq.Header.DatabaseID = createDBRes.Header.InstanceMeta.DatabaseID - getReq.Header.Signee = pubKey err = getReq.Sign(privateKey) So(err, ShouldBeNil) err = rpc.NewCaller().CallNode(nodeID, route.BPDBGetDatabase.String(), getReq, getRes) @@ -191,12 +183,8 @@ func buildQuery(queryType wt.QueryType, connID uint64, seqNo uint64, databaseID return } - // get private/public key - var pubKey *asymmetric.PublicKey + // get private key var privateKey *asymmetric.PrivateKey - if pubKey, err = kms.GetLocalPublicKey(); err != nil { - return - } if privateKey, err = kms.GetLocalPrivateKey(); err != nil { return } @@ -220,7 +208,6 @@ func buildQuery(queryType wt.QueryType, connID uint64, seqNo uint64, databaseID SeqNo: seqNo, Timestamp: tm, }, - Signee: pubKey, }, Payload: wt.RequestPayload{ Queries: realQueries, diff --git a/blockproducer/db_service_types.go b/blockproducer/db_service_types.go index 7797dff6c..6edac9581 100644 --- a/blockproducer/db_service_types.go +++ b/blockproducer/db_service_types.go @@ -65,6 +65,7 @@ func (sh *SignedCreateDatabaseRequestHeader) Sign(signer *asymmetric.PrivateKey) // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } @@ -128,6 +129,7 @@ func (sh *SignedCreateDatabaseResponseHeader) Sign(signer *asymmetric.PrivateKey // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } @@ -191,6 +193,7 @@ func (sh *SignedDropDatabaseRequestHeader) Sign(signer *asymmetric.PrivateKey) ( // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } @@ -256,6 +259,7 @@ func (sh *SignedGetDatabaseRequestHeader) Sign(signer *asymmetric.PrivateKey) (e // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } @@ -318,6 +322,7 @@ func (sh *SignedGetDatabaseResponseHeader) Sign(signer *asymmetric.PrivateKey) ( // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/blockproducer/helper_test.go b/blockproducer/helper_test.go index 169152add..121c5fd8e 100644 --- a/blockproducer/helper_test.go +++ b/blockproducer/helper_test.go @@ -76,8 +76,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *ct.Block, err error ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, Queries: make([]*hash.Hash, rand.Intn(10)+10), } diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing.go index 11274fafb..14d96c1b9 100644 --- a/blockproducer/types/billing.go +++ b/blockproducer/types/billing.go @@ -17,6 +17,8 @@ package types import ( + "reflect" + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" @@ -45,28 +47,109 @@ type BillingRequest struct { } // PackRequestHeader computes the hash of header. -func (br *BillingRequest) PackRequestHeader() (*hash.Hash, error) { - b, err := br.Header.MarshalHash() - if err != nil { - return nil, err +func (br *BillingRequest) PackRequestHeader() (h *hash.Hash, err error) { + var enc []byte + if enc, err = br.Header.MarshalHash(); err != nil { + return } - h := hash.THashH(b) - return &h, nil + br.RequestHash = hash.THashH(enc) + h = &br.RequestHash + return } // SignRequestHeader first computes the hash of BillingRequestHeader, then signs the request. -func (br *BillingRequest) SignRequestHeader(signee *asymmetric.PrivateKey) (*asymmetric.Signature, error) { - signature, err := signee.Sign(br.RequestHash[:]) - if err != nil { - return nil, err +func (br *BillingRequest) SignRequestHeader(signer *asymmetric.PrivateKey, calcHash bool) ( + signee *asymmetric.PublicKey, signature *asymmetric.Signature, err error) { + if calcHash { + if _, err = br.PackRequestHeader(); err != nil { + return + } + } + + if signature, err = signer.Sign(br.RequestHash[:]); err == nil { + // append to current signatures + signee = signer.PubKey() + br.Signees = append(br.Signees, signee) + br.Signatures = append(br.Signatures, signature) } - return signature, nil + + return } -// BillingResponse defines the the response for BillingRequest. -type BillingResponse struct { - RequestHash hash.Hash - Signee *asymmetric.PublicKey - Signature *asymmetric.Signature +// AddSignature add existing signature to BillingRequest, requires the structure to be packed first. +func (br *BillingRequest) AddSignature( + signee *asymmetric.PublicKey, signature *asymmetric.Signature, calcHash bool) (err error) { + if calcHash { + if _, err = br.PackRequestHeader(); err != nil { + return + } + } + + if !signature.Verify(br.RequestHash[:], signee) { + err = ErrSignVerification + return + } + + // append + br.Signees = append(br.Signees, signee) + br.Signatures = append(br.Signatures, signature) + + return +} + +// VerifySignatures verify existing signatures. +func (br *BillingRequest) VerifySignatures() (err error) { + if len(br.Signees) != len(br.Signatures) { + return ErrSignVerification + } + + var enc []byte + if enc, err = br.Header.MarshalHash(); err != nil { + return + } + + h := hash.THashH(enc) + if !br.RequestHash.IsEqual(&h) { + return ErrSignVerification + } + + if len(br.Signees) == 0 { + return + } + + for idx, signee := range br.Signees { + if !br.Signatures[idx].Verify(br.RequestHash[:], signee) { + return ErrSignVerification + } + } + + return +} + +// Compare returns if two billing records are identical. +func (br *BillingRequest) Compare(r *BillingRequest) (err error) { + if !br.Header.LowBlock.IsEqual(&r.Header.LowBlock) || + !br.Header.HighBlock.IsEqual(&br.Header.HighBlock) { + err = ErrBillingNotMatch + return + } + + reqMap := make(map[proto.AccountAddress]*proto.AddrAndGas) + locMap := make(map[proto.AccountAddress]*proto.AddrAndGas) + + for _, v := range br.Header.GasAmounts { + reqMap[v.AccountAddress] = v + } + + for _, v := range r.Header.GasAmounts { + locMap[v.AccountAddress] = v + } + + if !reflect.DeepEqual(reqMap, locMap) { + err = ErrBillingNotMatch + return + } + + return } diff --git a/blockproducer/types/billing_gen.go b/blockproducer/types/billing_gen.go index bd6cd1f2f..48da8b034 100644 --- a/blockproducer/types/billing_gen.go +++ b/blockproducer/types/billing_gen.go @@ -130,55 +130,3 @@ func (z *BillingRequestHeader) Msgsize() (s int) { s += 9 + z.LowBlock.Msgsize() + 10 + z.HighBlock.Msgsize() + 10 + hsp.Int32Size + 11 + hsp.Int32Size + 11 + z.DatabaseID.Msgsize() return } - -// MarshalHash marshals for hash -func (z *BillingResponse) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 3 - o = append(o, 0x83, 0x83) - if z.Signee == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signee.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x83) - if z.Signature == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signature.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x83) - if oTemp, err := z.RequestHash.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *BillingResponse) Msgsize() (s int) { - s = 1 + 7 - if z.Signee == nil { - s += hsp.NilSize - } else { - s += z.Signee.Msgsize() - } - s += 10 - if z.Signature == nil { - s += hsp.NilSize - } else { - s += z.Signature.Msgsize() - } - s += 12 + z.RequestHash.Msgsize() - return -} diff --git a/blockproducer/types/billing_gen_test.go b/blockproducer/types/billing_gen_test.go index 1ad0c1426..d46613c46 100644 --- a/blockproducer/types/billing_gen_test.go +++ b/blockproducer/types/billing_gen_test.go @@ -82,40 +82,3 @@ func BenchmarkAppendMsgBillingRequestHeader(b *testing.B) { bts, _ = v.MarshalHash() } } - -func TestMarshalHashBillingResponse(t *testing.T) { - v := BillingResponse{} - binary.Read(rand.Reader, binary.BigEndian, &v) - bts1, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } -} - -func BenchmarkMarshalHashBillingResponse(b *testing.B) { - v := BillingResponse{} - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - v.MarshalHash() - } -} - -func BenchmarkAppendMsgBillingResponse(b *testing.B) { - v := BillingResponse{} - bts := make([]byte, 0, v.Msgsize()) - bts, _ = v.MarshalHash() - b.SetBytes(int64(len(bts))) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - bts, _ = v.MarshalHash() - } -} diff --git a/blockproducer/types/billing_test.go b/blockproducer/types/billing_test.go index 9f3f49446..c6d7ee998 100644 --- a/blockproducer/types/billing_test.go +++ b/blockproducer/types/billing_test.go @@ -20,15 +20,15 @@ import ( "reflect" "testing" - "github.com/CovenantSQL/CovenantSQL/utils" - "github.com/CovenantSQL/CovenantSQL/utils/log" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" + "github.com/CovenantSQL/CovenantSQL/utils/log" ) var ( - peerNum uint32 = 32 + peerNum = 32 ) func TestBillingRequestHeader_MarshalUnmarshalBinary(t *testing.T) { @@ -114,30 +114,226 @@ func TestBillingRequest_SignRequestHeader(t *testing.T) { } priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := req.SignRequestHeader(priv) - if !sign.Verify(req.RequestHash[:], pub) { + _, sign, err := req.SignRequestHeader(priv, false) + if err != nil || !sign.Verify(req.RequestHash[:], pub) { t.Fatalf("signature cannot match the hash and public key: %v", req) } - sign, err = req.SignRequestHeader(priv) - if !sign.Verify(req.RequestHash[:], pub) { +} + +func TestBillingRequest_SignRequestHeader2(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + priv, _, err := asymmetric.GenSecp256k1KeyPair() + signee, sign, err := req.SignRequestHeader(priv, true) + if err != nil || !sign.Verify(req.RequestHash[:], signee) { t.Fatalf("signature cannot match the hash and public key: %v", req) } } -func TestBillingResponse_MarshalUnmarshalBinary(t *testing.T) { - resp, err := generateRandomBillingResponse() - if err != nil { - t.Fatalf("unexpected error: %v", err) +func TestBillingRequest_AddSignature(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, } - enc, err := utils.EncodeMsgPack(resp) - if err != nil { - t.Fatalf("unexpected error: %v", err) + priv, _, err := asymmetric.GenSecp256k1KeyPair() + signee, sign, err := req.SignRequestHeader(priv, true) + if err != nil || !sign.Verify(req.RequestHash[:], signee) { + t.Fatalf("signature cannot match the hash and public key, req: %v, err: %v", req, err) } - dec := &BillingResponse{} - err = utils.DecodeMsgPack(enc.Bytes(), dec) - if err != nil { - t.Fatalf("unexpected error: %v", err) + // clear previous signees and signatures + req.Signees = req.Signees[:0] + req.Signatures = req.Signatures[:0] + + if err := req.AddSignature(signee, sign, false); err != nil { + t.Fatalf("add signature failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_AddSignature2(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + priv, _, err := asymmetric.GenSecp256k1KeyPair() + signee, sign, err := req.SignRequestHeader(priv, true) + if err != nil || !sign.Verify(req.RequestHash[:], signee) { + t.Fatalf("signature cannot match the hash and public key, req: %v, err: %v", req, err) + } + + // clear previous signees and signatures + req.RequestHash = hash.Hash{} + req.Signees = req.Signees[:0] + req.Signatures = req.Signatures[:0] + + if err := req.AddSignature(signee, sign, true); err != nil { + t.Fatalf("add signature failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_AddSignature3(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + priv, _, err := asymmetric.GenSecp256k1KeyPair() + signee, sign, err := req.SignRequestHeader(priv, true) + if err != nil || !sign.Verify(req.RequestHash[:], signee) { + t.Fatalf("signature cannot match the hash and public key, req: %v, err: %v", req, err) + } + + // clear previous signees and signatures + req.RequestHash = hash.Hash{} + req.Signees = req.Signees[:0] + req.Signatures = req.Signatures[:0] + + _, signee, _ = asymmetric.GenSecp256k1KeyPair() + if err := req.AddSignature(signee, sign, true); err != ErrSignVerification { + t.Fatalf("add signature should failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_VerifySignatures(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + addSignature := func(calcHash bool) { + priv, _, err := asymmetric.GenSecp256k1KeyPair() + _, _, err = req.SignRequestHeader(priv, calcHash) + if err != nil { + t.Fatalf("sign request failed, req: %v, err: %v", req, err) + } + } + + // add 3 signatures + addSignature(true) + addSignature(false) + addSignature(false) + + if err := req.VerifySignatures(); err != nil { + t.Fatalf("verify signature failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_VerifySignatures2(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + addSignature := func(calcHash bool) { + priv, _, err := asymmetric.GenSecp256k1KeyPair() + _, _, err = req.SignRequestHeader(priv, calcHash) + if err != nil { + t.Fatalf("sign request failed, req: %v, err: %v", req, err) + } + } + + // add 3 signatures + addSignature(true) + addSignature(false) + addSignature(false) + + // length invalidation + req.Signees = req.Signees[:0] + + if err := req.VerifySignatures(); err != ErrSignVerification { + t.Fatalf("verify should be failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_VerifySignatures3(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + addSignature := func(calcHash bool) { + priv, _, err := asymmetric.GenSecp256k1KeyPair() + _, _, err = req.SignRequestHeader(priv, calcHash) + if err != nil { + t.Fatalf("sign request failed, req: %v, err: %v", req, err) + } + } + + // add 3 signatures + addSignature(true) + addSignature(false) + addSignature(false) + + // length invalidation + req.RequestHash = hash.Hash{} + + if err := req.VerifySignatures(); err != ErrSignVerification { + t.Fatalf("verify should be failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_VerifySignatures4(t *testing.T) { + header := generateRandomBillingRequestHeader() + req := &BillingRequest{ + Header: *header, + } + + addSignature := func(calcHash bool) { + priv, _, err := asymmetric.GenSecp256k1KeyPair() + _, _, err = req.SignRequestHeader(priv, calcHash) + if err != nil { + t.Fatalf("sign request failed, req: %v, err: %v", req, err) + } + } + + // add 3 signatures + addSignature(true) + addSignature(false) + addSignature(false) + + // length invalidation + _, req.Signees[0], _ = asymmetric.GenSecp256k1KeyPair() + + if err := req.VerifySignatures(); err == nil || err != ErrSignVerification { + t.Fatalf("verify should be failed, req: %v, err: %v", req, err) + } +} + +func TestBillingRequest_Compare(t *testing.T) { + req, _ := generateRandomBillingRequest() + + if err := req.Compare(req); err != nil { + t.Fatalf("compare failed, req: %v, err: %v", req, err) + } + + var req2 BillingRequest + req2 = *req + + req2.Header.LowBlock = hash.Hash{} + + if err := req.Compare(&req2); err != ErrBillingNotMatch { + t.Fatalf("compare should be failed, req: %v, req2: %v, err: %v", req, req2, err) + } +} + +func TestBillingRequest_Compare2(t *testing.T) { + req, _ := generateRandomBillingRequest() + var req2 BillingRequest + req2 = *req + + var gasAmount proto.AddrAndGas + gasAmount = *req.Header.GasAmounts[0] + gasAmount.GasAmount += 10 + req2.Header.GasAmounts = nil + req2.Header.GasAmounts = append(req2.Header.GasAmounts, &gasAmount) + req2.Header.GasAmounts = append(req2.Header.GasAmounts, req.Header.GasAmounts[1:]...) + + if err := req.Compare(&req2); err != ErrBillingNotMatch { + t.Fatalf("compare should be failed, req: %v, req2: %v, err: %v", req, req2, err) } } diff --git a/blockproducer/types/errors.go b/blockproducer/types/errors.go index 7d856cb81..13d135db1 100644 --- a/blockproducer/types/errors.go +++ b/blockproducer/types/errors.go @@ -33,4 +33,7 @@ var ( // ErrNodePublicKeyNotMatch indicates that the public key given with a node does not match the // one in the key store. ErrNodePublicKeyNotMatch = errors.New("node publick key doesn't match") + + // ErrBillingNotMatch indicates that the billing request doesn't match the local result. + ErrBillingNotMatch = errors.New("billing request doesn't match") ) diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/txsqlchainbilling.go index 6050aec43..0feb00018 100644 --- a/blockproducer/types/txsqlchainbilling.go +++ b/blockproducer/types/txsqlchainbilling.go @@ -38,8 +38,7 @@ type TxContent struct { // Fee paid by stable coin Fees []uint64 // Reward is share coin - Rewards []uint64 - BillingResponse BillingResponse + Rewards []uint64 } // NewTxContent generates new TxContent. @@ -47,15 +46,13 @@ func NewTxContent(seqID uint32, bReq *BillingRequest, receivers []*proto.AccountAddress, fees []uint64, - rewards []uint64, - bResp *BillingResponse) *TxContent { + rewards []uint64) *TxContent { return &TxContent{ - SequenceID: seqID, - BillingRequest: *bReq, - Receivers: receivers, - Fees: fees, - Rewards: rewards, - BillingResponse: *bResp, + SequenceID: seqID, + BillingRequest: *bReq, + Receivers: receivers, + Fees: fees, + Rewards: rewards, } } @@ -132,9 +129,7 @@ func (tb *TxBilling) Sign(signer *asymmetric.PrivateKey) error { } h := hash.THashH(enc) tb.TxHash = &h - - pub := asymmetric.PublicKey(signer.PublicKey) - tb.Signee = &pub + tb.Signee = signer.PubKey() signature, err := signer.Sign(h[:]) if err != nil { diff --git a/blockproducer/types/txsqlchainbilling_gen.go b/blockproducer/types/txsqlchainbilling_gen.go index 3cdd961e8..169f0436a 100644 --- a/blockproducer/types/txsqlchainbilling_gen.go +++ b/blockproducer/types/txsqlchainbilling_gen.go @@ -112,20 +112,14 @@ func (z *TxBilling) Msgsize() (s int) { func (z *TxContent) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 6 - o = append(o, 0x86, 0x86) + // map header, size 5 + o = append(o, 0x85, 0x85) if oTemp, err := z.BillingRequest.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x86) - if oTemp, err := z.BillingResponse.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = append(o, 0x86) + o = append(o, 0x85) o = hsp.AppendArrayHeader(o, uint32(len(z.Receivers))) for za0001 := range z.Receivers { if z.Receivers[za0001] == nil { @@ -138,24 +132,24 @@ func (z *TxContent) MarshalHash() (o []byte, err error) { } } } - o = append(o, 0x86) + o = append(o, 0x85) o = hsp.AppendArrayHeader(o, uint32(len(z.Fees))) for za0002 := range z.Fees { o = hsp.AppendUint64(o, z.Fees[za0002]) } - o = append(o, 0x86) + o = append(o, 0x85) o = hsp.AppendArrayHeader(o, uint32(len(z.Rewards))) for za0003 := range z.Rewards { o = hsp.AppendUint64(o, z.Rewards[za0003]) } - o = append(o, 0x86) + o = append(o, 0x85) o = hsp.AppendUint32(o, z.SequenceID) return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *TxContent) Msgsize() (s int) { - s = 1 + 15 + z.BillingRequest.Msgsize() + 16 + z.BillingResponse.Msgsize() + 10 + hsp.ArrayHeaderSize + s = 1 + 15 + z.BillingRequest.Msgsize() + 10 + hsp.ArrayHeaderSize for za0001 := range z.Receivers { if z.Receivers[za0001] == nil { s += hsp.NilSize diff --git a/blockproducer/types/txsqlchainbilling_test.go b/blockproducer/types/txsqlchainbilling_test.go index dc004a11b..b992fc881 100644 --- a/blockproducer/types/txsqlchainbilling_test.go +++ b/blockproducer/types/txsqlchainbilling_test.go @@ -111,9 +111,6 @@ func TestTxBilling_SerializeDeserialize(t *testing.T) { if !tb.TxHash.IsEqual(dec.TxHash) { t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.TxHash, tb.TxHash) } - if !reflect.DeepEqual(tb.TxContent.BillingResponse, dec.TxContent.BillingResponse) { - t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.TxContent.BillingResponse, tb.TxContent.BillingResponse) - } } func TestTxBilling_GetSet(t *testing.T) { diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index 9b867f83c..7ad157b34 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -126,7 +126,7 @@ func generateRandomUint32s(n int32) []uint32 { func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) { // Generate key pair - priv, pub, err := asymmetric.GenSecp256k1KeyPair() + priv, _, err := asymmetric.GenSecp256k1KeyPair() if err != nil { return @@ -143,7 +143,6 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, }, } @@ -170,70 +169,44 @@ func generateRandomBillingRequestHeader() *BillingRequestHeader { } } -func generateRandomBillingRequest() (*BillingRequest, error) { +func generateRandomBillingRequest() (req *BillingRequest, err error) { reqHeader := generateRandomBillingRequestHeader() - req := BillingRequest{ + req = &BillingRequest{ Header: *reqHeader, } - h, err := req.PackRequestHeader() - if err != nil { + if _, err = req.PackRequestHeader(); err != nil { return nil, err } - signees := make([]*asymmetric.PublicKey, peerNum) - signatures := make([]*asymmetric.Signature, peerNum) - - for i := range signees { + for i := 0; i < peerNum; i++ { // Generate key pair - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - if err != nil { - return nil, err + var priv *asymmetric.PrivateKey + + if priv, _, err = asymmetric.GenSecp256k1KeyPair(); err != nil { + return } - signees[i] = pub - signatures[i], err = priv.Sign(h[:]) - if err != nil { - return nil, err + + if _, _, err = req.SignRequestHeader(priv, false); err != nil { + return } } - req.RequestHash = *h - req.Signatures = signatures - req.Signees = signees - return &req, nil + return } -func generateRandomBillingResponse() (*BillingResponse, error) { - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - if err != nil { - return nil, err - } - h := generateRandomHash() - sign, err := priv.Sign(h[:]) - if err != nil { - return nil, err - } - resp := BillingResponse{ - RequestHash: h, - Signee: pub, - Signature: sign, +func generateRandomTxContent() (tc *TxContent, err error) { + var req *BillingRequest + if req, err = generateRandomBillingRequest(); err != nil { + return } - return &resp, nil -} -func generateRandomTxContent() (*TxContent, error) { - req, err := generateRandomBillingRequest() - if err != nil { - return nil, err - } - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := priv.Sign(req.RequestHash[:]) - if err != nil { - return nil, err + var priv *asymmetric.PrivateKey + if priv, _, err = asymmetric.GenSecp256k1KeyPair(); err != nil { + return } - resp := &BillingResponse{ - RequestHash: req.RequestHash, - Signee: pub, - Signature: sign, + + if _, _, err = req.SignRequestHeader(priv, false); err != nil { + return } receivers := make([]*proto.AccountAddress, peerNum) @@ -247,7 +220,7 @@ func generateRandomTxContent() (*TxContent, error) { rewards[i] = rand.Uint64() } - tc := NewTxContent(rand.Uint32(), req, receivers, fees, rewards, resp) + tc = NewTxContent(rand.Uint32(), req, receivers, fees, rewards) return tc, nil } @@ -273,7 +246,7 @@ func generateRandomTxBilling() (*TxBilling, error) { return txBilling, nil } -func generateRandomGasAmount(n uint32) []*proto.AddrAndGas { +func generateRandomGasAmount(n int) []*proto.AddrAndGas { gasAmount := make([]*proto.AddrAndGas, n) for i := range gasAmount { diff --git a/blockproducer/xxx_test.go b/blockproducer/xxx_test.go index fc9d9c262..849690014 100644 --- a/blockproducer/xxx_test.go +++ b/blockproducer/xxx_test.go @@ -89,7 +89,7 @@ func randStringBytes(n int) string { func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err error) { // Generate key pair - priv, pub, err := asymmetric.GenSecp256k1KeyPair() + priv, _, err := asymmetric.GenSecp256k1KeyPair() if err != nil { return @@ -106,7 +106,6 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, }, } @@ -152,7 +151,7 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) (b *types.Block, err error) { // Generate key pair - priv, pub, err := asymmetric.GenSecp256k1KeyPair() + priv, _, err := asymmetric.GenSecp256k1KeyPair() if err != nil { return @@ -169,7 +168,6 @@ func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, }, } @@ -240,38 +238,19 @@ func generateRandomBillingRequest() (*types.BillingRequest, error) { return &req, nil } -func generateRandomBillingResponse() (*types.BillingResponse, error) { - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - if err != nil { - return nil, err - } - h := generateRandomHash() - sign, err := priv.Sign(h[:]) - if err != nil { - return nil, err - } - resp := types.BillingResponse{ - RequestHash: h, - Signee: pub, - Signature: sign, +func generateRandomTxContent() (tc *types.TxContent, err error) { + var req *types.BillingRequest + if req, err = generateRandomBillingRequest(); err != nil { + return } - return &resp, nil -} -func generateRandomTxContent() (*types.TxContent, error) { - req, err := generateRandomBillingRequest() - if err != nil { - return nil, err - } - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := priv.Sign(req.RequestHash[:]) - if err != nil { - return nil, err + var priv *asymmetric.PrivateKey + if priv, _, err = asymmetric.GenSecp256k1KeyPair(); err != nil { + return } - resp := &types.BillingResponse{ - RequestHash: req.RequestHash, - Signee: pub, - Signature: sign, + + if _, _, err = req.SignRequestHeader(priv, false); err != nil { + return } receivers := make([]*proto.AccountAddress, peerNum) @@ -285,14 +264,7 @@ func generateRandomTxContent() (*types.TxContent, error) { rewards[i] = rand.Uint64() } - tc := &types.TxContent{ - SequenceID: rand.Uint32(), - BillingRequest: *req, - BillingResponse: *resp, - Receivers: receivers, - Fees: fees, - Rewards: rewards, - } + tc = types.NewTxContent(rand.Uint32(), req, receivers, fees, rewards) return tc, nil } diff --git a/client/conn.go b/client/conn.go index 60c8371ed..35c4756d0 100644 --- a/client/conn.go +++ b/client/conn.go @@ -292,7 +292,6 @@ func (c *conn) sendQuery(queryType wt.QueryType, queries []wt.Query) (rows drive SeqNo: seqNo, Timestamp: getLocalTime(), }, - Signee: c.pubKey, }, Payload: wt.RequestPayload{ Queries: queries, @@ -339,7 +338,6 @@ func (c *conn) sendQuery(queryType wt.QueryType, queries []wt.Query) (rows drive NodeID: c.nodeID, Timestamp: getLocalTime(), }, - Signee: c.pubKey, }, } @@ -366,7 +364,6 @@ func (c *conn) getPeers() (err error) { req := new(bp.GetDatabaseRequest) req.Header.DatabaseID = c.dbID - req.Header.Signee = c.pubKey if err = req.Sign(c.privKey); err != nil { return diff --git a/client/helper_test.go b/client/helper_test.go index 0a2118e09..67422f93f 100644 --- a/client/helper_test.go +++ b/client/helper_test.go @@ -329,8 +329,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *ct.Block, err error ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, Queries: make([]*hash.Hash, rand.Intn(10)+10), } diff --git a/cmd/cql-faucet/verifier.go b/cmd/cql-faucet/verifier.go index e3d53503e..c1b95aed8 100644 --- a/cmd/cql-faucet/verifier.go +++ b/cmd/cql-faucet/verifier.go @@ -268,7 +268,6 @@ func (v *Verifier) dispenseOne(r *applicationRecord) (err error) { Nonce: nonceResp.Nonce, Amount: uint64(r.tokenAmount), }, - Signee: v.publicKey, } if err = req.Tx.Sign(v.privateKey); err != nil { // sign failed? diff --git a/cmd/cql-minerd/dbms.go b/cmd/cql-minerd/dbms.go index 8616cf3d6..013aa7840 100644 --- a/cmd/cql-minerd/dbms.go +++ b/cmd/cql-minerd/dbms.go @@ -181,8 +181,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *ct.Block, err error ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, Queries: make([]*hash.Hash, rand.Intn(10)+10), } diff --git a/cmd/cql-observer/service.go b/cmd/cql-observer/service.go index 1834c2bdc..34eda57ea 100644 --- a/cmd/cql-observer/service.go +++ b/cmd/cql-observer/service.go @@ -490,14 +490,8 @@ func (s *Service) getUpstream(dbID proto.DatabaseID) (instance *wt.ServiceInstan return } - pubKey, err := kms.GetLocalPublicKey() - if err != nil { - return - } - req := &bp.GetDatabaseRequest{} req.Header.DatabaseID = dbID - req.Header.Signee = pubKey if err = req.Sign(privateKey); err != nil { return } diff --git a/cmd/cql-utils/addrgen.go b/cmd/cql-utils/addrgen.go index ca8d05a62..fb2cfea47 100644 --- a/cmd/cql-utils/addrgen.go +++ b/cmd/cql-utils/addrgen.go @@ -20,9 +20,9 @@ import ( "encoding/hex" "flag" "fmt" - "github.com/CovenantSQL/CovenantSQL/crypto" "os" + "github.com/CovenantSQL/CovenantSQL/crypto" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/utils/log" diff --git a/cmd/cql-utils/rpc.go b/cmd/cql-utils/rpc.go index a2e62a702..f3663fceb 100644 --- a/cmd/cql-utils/rpc.go +++ b/cmd/cql-utils/rpc.go @@ -27,12 +27,15 @@ import ( "github.com/CovenantSQL/CovenantSQL/blockproducer" bp "github.com/CovenantSQL/CovenantSQL/blockproducer" "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" "github.com/CovenantSQL/CovenantSQL/sqlchain" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/CovenantSQL/CovenantSQL/worker" + "gopkg.in/yaml.v2" ) var ( @@ -48,6 +51,10 @@ var ( rpcReq string ) +type canSign interface { + Sign(signer *asymmetric.PrivateKey) error +} + func init() { flag.StringVar(&rpcName, "rpc", "", "rpc name to do test call") flag.StringVar(&rpcEndpoint, "rpc-endpoint", "", "rpc endpoint to do test call") @@ -81,6 +88,13 @@ func runRPC() { return } + // requires signature? + if err := checkAndSign(req); err != nil { + fmt.Printf("sign request failed: %v\n", err) + os.Exit(1) + return + } + if err := rpc.NewCaller().CallNode(proto.NodeID(rpcEndpoint), rpcName, req, resp); err != nil { // send request failed fmt.Printf("call rpc failed: %v\n", err) @@ -89,7 +103,7 @@ func runRPC() { } // print the response - if resBytes, err := json.MarshalIndent(resp, "", " "); err != nil { + if resBytes, err := yaml.Marshal(resp); err != nil { fmt.Printf("marshal response failed: %v\n", err) os.Exit(1) } else { @@ -97,6 +111,24 @@ func runRPC() { } } +func checkAndSign(req interface{}) (err error) { + if reflect.ValueOf(req).Kind() != reflect.Ptr { + return checkAndSign(&req) + } + + if canSignObj, ok := req.(canSign); ok { + var privKey *asymmetric.PrivateKey + if privKey, err = kms.GetLocalPrivateKey(); err != nil { + return + } + if err = canSignObj.Sign(privKey); err != nil { + return + } + } + + return +} + func resolveRPCEntities() (req interface{}, resp interface{}) { rpcParts := strings.SplitN(rpcName, ".", 2) @@ -132,7 +164,6 @@ func resolveRPCEntities() (req interface{}, resp interface{}) { req = reflect.New(argType.Elem()).Interface() } else { req = reflect.New(argType).Interface() - } resp = reflect.New(replyType.Elem()).Interface() diff --git a/cmd/cqld/adapter.go b/cmd/cqld/adapter.go index ba63f5224..d044493e5 100644 --- a/cmd/cqld/adapter.go +++ b/cmd/cqld/adapter.go @@ -126,11 +126,7 @@ func (s *LocalStorage) commit(ctx context.Context, payload *KayakPayload) (err e // if s.consistent == nil, it is called during Init. and AddCache will be called by consistent.InitConsistent if s.consistent != nil { - err = s.consistent.AddCache(nodeToSet) - if err != nil { - //TODO(auxten) even no error will be returned, there may be some inconsistency and needs sync periodically - log.Errorf("add consistent cache failed: %s", err) - } + s.consistent.AddCache(nodeToSet) } return s.Storage.Commit(ctx, execLog) diff --git a/kayak/types.go b/kayak/types.go index 15d9c4749..8b64adc93 100644 --- a/kayak/types.go +++ b/kayak/types.go @@ -229,6 +229,7 @@ func (c *Peers) Sign(signer *asymmetric.PrivateKey) error { } c.Signature = sig + c.PubKey = signer.PubKey() return nil } diff --git a/sqlchain/chain.go b/sqlchain/chain.go index 4a8d8f617..e65b433f7 100644 --- a/sqlchain/chain.go +++ b/sqlchain/chain.go @@ -21,7 +21,6 @@ import ( "encoding/binary" "fmt" "os" - "reflect" "sync" "time" @@ -1221,32 +1220,41 @@ func (c *Chain) collectBillingSignatures(billings *pt.BillingRequest) { proWG.Add(1) go func() { defer proWG.Done() - for resp := range respC { - req.Signees = append(req.Signees, resp.Signee) - req.Signatures = append(req.Signatures, resp.Signature) + + bpReq := &ct.AdviseBillingReq{ + Req: billings, } var ( - bp proto.NodeID - err error + bpNodeID proto.NodeID + err error ) + for resp := range respC { + if err = bpReq.Req.AddSignature(resp.Signee, resp.Signature, false); err != nil { + // consume all rpc result + for range respC { + } + + return + } + } + defer log.WithFields(log.Fields{ "peer": c.rt.getPeerInfoString(), "time": c.rt.getChainTimeString(), "signees_count": len(req.Signees), "signatures_count": len(req.Signatures), - "bp": bp, + "bp": bpNodeID, }).WithError(err).Debug( "Sent billing request") - if bp, err = rpc.GetCurrentBP(); err != nil { + if bpNodeID, err = rpc.GetCurrentBP(); err != nil { return } - resp := &pt.BillingResponse{} - - if err = c.cl.CallNode(bp, route.MCCAdviseBillingRequest.String(), req, resp); err != nil { + var resp interface{} + if err = c.cl.CallNode(bpNodeID, route.MCCAdviseBillingRequest.String(), bpReq, resp); err != nil { return } }() @@ -1285,7 +1293,6 @@ func (c *Chain) collectBillingSignatures(billings *pt.BillingRequest) { func (c *Chain) LaunchBilling(low, high int32) (err error) { var ( req *pt.BillingRequest - h *hash.Hash ) defer log.WithFields(log.Fields{ @@ -1299,11 +1306,10 @@ func (c *Chain) LaunchBilling(low, high int32) (err error) { return } - if h, err = req.PackRequestHeader(); err != nil { + if _, err = req.PackRequestHeader(); err != nil { return } - req.RequestHash = *h c.rt.wg.Add(1) go c.collectBillingSignatures(req) return @@ -1314,7 +1320,6 @@ func (c *Chain) SignBilling(req *pt.BillingRequest) ( pub *asymmetric.PublicKey, sig *asymmetric.Signature, err error, ) { var ( - h *hash.Hash loc *pt.BillingRequest ) defer log.WithFields(log.Fields{ @@ -1325,12 +1330,7 @@ func (c *Chain) SignBilling(req *pt.BillingRequest) ( }).WithError(err).Debug("Processing sign billing request") // Verify billing results - if h, err = req.PackRequestHeader(); err != nil { - return - } - - if !req.RequestHash.IsEqual(h) { - err = ErrBillingNotMatch + if err = req.VerifySignatures(); err != nil { return } @@ -1338,25 +1338,7 @@ func (c *Chain) SignBilling(req *pt.BillingRequest) ( return } - if !req.Header.LowBlock.IsEqual(&loc.Header.LowBlock) || - !req.Header.HighBlock.IsEqual(&loc.Header.HighBlock) { - err = ErrBillingNotMatch - return - } - - reqMap := make(map[proto.AccountAddress]*proto.AddrAndGas) - locMap := make(map[proto.AccountAddress]*proto.AddrAndGas) - - for _, v := range req.Header.GasAmounts { - reqMap[v.AccountAddress] = v - } - - for _, v := range loc.Header.GasAmounts { - locMap[v.AccountAddress] = v - } - - if !reflect.DeepEqual(reqMap, locMap) { - err = ErrBillingNotMatch + if err = req.Compare(loc); err != nil { return } @@ -1367,11 +1349,8 @@ func (c *Chain) SignBilling(req *pt.BillingRequest) ( return } - if sig, err = req.SignRequestHeader(priv); err != nil { - return - } + pub, sig, err = req.SignRequestHeader(priv, false) - pub = priv.PubKey() return } diff --git a/sqlchain/errors.go b/sqlchain/errors.go index 707ef6fcb..0cbf1c682 100644 --- a/sqlchain/errors.go +++ b/sqlchain/errors.go @@ -84,9 +84,6 @@ var ( // given in its hash field. ErrHashNotMatch = errors.New("hash value doesn't match") - // ErrBillingNotMatch indicates that the billing request doesn't match the local result. - ErrBillingNotMatch = errors.New("billing request doesn't match") - // ErrMetaStateNotFound indicates that meta state not found in db. ErrMetaStateNotFound = errors.New("meta state not found in db") diff --git a/sqlchain/types/xxx_test.go b/sqlchain/types/xxx_test.go index 1a21a213c..d6545d79d 100644 --- a/sqlchain/types/xxx_test.go +++ b/sqlchain/types/xxx_test.go @@ -98,8 +98,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) { ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, } diff --git a/sqlchain/xxx_test.go b/sqlchain/xxx_test.go index 1aea3d25d..9f3da9360 100644 --- a/sqlchain/xxx_test.go +++ b/sqlchain/xxx_test.go @@ -131,8 +131,6 @@ func createRandomQueryRequest(cli *nodeProfile) (r *wt.SignedRequestHeader, err Timestamp: time.Now().UTC(), // BatchCount and QueriesHash will be set by req.Sign() }, - Signee: cli.PublicKey, - Signature: nil, }, Payload: wt.RequestPayload{ Queries: createRandomStorageQueries(10, 10, 10, 10), @@ -165,8 +163,6 @@ func createRandomQueryResponse(cli, worker *nodeProfile) ( NodeID: worker.NodeID, Timestamp: createRandomTimeAfter(req.Timestamp, 100), }, - Signee: worker.PublicKey, - Signature: nil, }, Payload: wt.ResponsePayload{ Columns: createRandomStrings(10, 10, 10, 10), @@ -201,8 +197,6 @@ func createRandomQueryResponseWithRequest(req *wt.SignedRequestHeader, worker *n NodeID: worker.NodeID, Timestamp: createRandomTimeAfter(req.Timestamp, 100), }, - Signee: worker.PublicKey, - Signature: nil, }, Payload: wt.ResponsePayload{ Columns: createRandomStrings(10, 10, 10, 10), @@ -237,8 +231,6 @@ func createRandomQueryAckWithResponse(resp *wt.SignedResponseHeader, cli *nodePr NodeID: cli.NodeID, Timestamp: createRandomTimeAfter(resp.Timestamp, 100), }, - Signee: cli.PublicKey, - Signature: nil, }, } @@ -264,8 +256,6 @@ func createRandomQueryAck(cli, worker *nodeProfile) (r *wt.SignedAckHeader, err NodeID: cli.NodeID, Timestamp: createRandomTimeAfter(resp.Timestamp, 100), }, - Signee: cli.PublicKey, - Signature: nil, }, } @@ -351,8 +341,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *ct.Block, err error ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, } @@ -397,7 +385,7 @@ func createRandomBlockWithQueries(genesis, parent hash.Hash, acks []*wt.SignedAc b *ct.Block, err error, ) { // Generate key pair - priv, pub, err := asymmetric.GenSecp256k1KeyPair() + priv, _, err := asymmetric.GenSecp256k1KeyPair() if err != nil { return @@ -415,8 +403,6 @@ func createRandomBlockWithQueries(genesis, parent hash.Hash, acks []*wt.SignedAc ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, } diff --git a/worker/db.go b/worker/db.go index dd2478eb4..9f303538d 100644 --- a/worker/db.go +++ b/worker/db.go @@ -319,9 +319,6 @@ func (db *Database) buildQueryResponse(request *wt.Request, offset uint64, response.Header.LogOffset = offset response.Header.Timestamp = getLocalTime() response.Header.RowCount = uint64(len(data)) - if response.Header.Signee, err = getLocalPubKey(); err != nil { - return - } // set payload response.Payload.Columns = columns diff --git a/worker/db_test.go b/worker/db_test.go index 3d7071686..e78462fc1 100644 --- a/worker/db_test.go +++ b/worker/db_test.go @@ -533,10 +533,9 @@ func buildAck(res *wt.Response) (ack *wt.Ack, err error) { } // get private/public key - var pubKey *asymmetric.PublicKey var privateKey *asymmetric.PrivateKey - if privateKey, pubKey, err = getKeys(); err != nil { + if privateKey, _, err = getKeys(); err != nil { return } @@ -547,7 +546,6 @@ func buildAck(res *wt.Response) (ack *wt.Ack, err error) { NodeID: nodeID, Timestamp: getLocalTime(), }, - Signee: pubKey, }, } @@ -576,10 +574,9 @@ func buildQueryEx(queryType wt.QueryType, connID uint64, seqNo uint64, timeShift } // get private/public key - var pubKey *asymmetric.PublicKey var privateKey *asymmetric.PrivateKey - if privateKey, pubKey, err = getKeys(); err != nil { + if privateKey, _, err = getKeys(); err != nil { return } @@ -603,7 +600,6 @@ func buildQueryEx(queryType wt.QueryType, connID uint64, seqNo uint64, timeShift SeqNo: seqNo, Timestamp: tm, }, - Signee: pubKey, }, Payload: wt.RequestPayload{ Queries: realQueries, @@ -743,8 +739,6 @@ func createRandomBlock(parent hash.Hash, isGenesis bool) (b *ct.Block, err error ParentHash: parent, Timestamp: time.Now().UTC(), }, - Signee: pub, - Signature: nil, }, Queries: make([]*hash.Hash, rand.Intn(10)+10), } diff --git a/worker/dbms_test.go b/worker/dbms_test.go index f04d48554..a0f2875ae 100644 --- a/worker/dbms_test.go +++ b/worker/dbms_test.go @@ -41,9 +41,6 @@ func TestDBMS(t *testing.T) { cleanup, server, err = initNode() So(err, ShouldBeNil) - var pubKey *asymmetric.PublicKey - pubKey, err = kms.GetLocalPublicKey() - So(err, ShouldBeNil) var privateKey *asymmetric.PrivateKey privateKey, err = kms.GetLocalPrivateKey() So(err, ShouldBeNil) @@ -90,7 +87,6 @@ func TestDBMS(t *testing.T) { Peers: peers, GenesisBlock: block, } - req.Header.Signee = pubKey err = req.Sign(privateKey) So(err, ShouldBeNil) @@ -179,7 +175,6 @@ func TestDBMS(t *testing.T) { DatabaseID: dbID, Peers: peers, } - req.Header.Signee = pubKey err = req.Sign(privateKey) So(err, ShouldBeNil) @@ -194,7 +189,6 @@ func TestDBMS(t *testing.T) { req.Header.Instance = wt.ServiceInstance{ DatabaseID: dbID, } - req.Header.Signee = pubKey err = req.Sign(privateKey) So(err, ShouldBeNil) diff --git a/worker/types/ack_type.go b/worker/types/ack_type.go index a5deb68b7..2c6a38da1 100644 --- a/worker/types/ack_type.go +++ b/worker/types/ack_type.go @@ -120,6 +120,7 @@ func (sh *SignedAckHeader) Sign(signer *asymmetric.PrivateKey) (err error) { // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/worker/types/init_service_type.go b/worker/types/init_service_type.go index cc87a6c51..8c97f1c5e 100644 --- a/worker/types/init_service_type.go +++ b/worker/types/init_service_type.go @@ -166,6 +166,7 @@ func (sh *SignedInitServiceResponseHeader) Sign(signer *asymmetric.PrivateKey) ( // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/worker/types/no_ack_report_type.go b/worker/types/no_ack_report_type.go index 5d67eece1..aa163176e 100644 --- a/worker/types/no_ack_report_type.go +++ b/worker/types/no_ack_report_type.go @@ -141,6 +141,7 @@ func (sh *SignedNoAckReportHeader) Sign(signer *asymmetric.PrivateKey) (err erro // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } @@ -240,6 +241,7 @@ func (sh *SignedAggrNoAckReportHeader) Sign(signer *asymmetric.PrivateKey) (err // verify signature sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/worker/types/request_type.go b/worker/types/request_type.go index c58095973..c6815a02d 100644 --- a/worker/types/request_type.go +++ b/worker/types/request_type.go @@ -168,12 +168,13 @@ func (sh *SignedRequestHeader) Sign(signer *asymmetric.PrivateKey) (err error) { // compute hash buildHash(&sh.RequestHeader, &sh.HeaderHash) - if sh.Signee == nil || signer == nil { + if signer == nil { return ErrSignRequest } // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/worker/types/response_type.go b/worker/types/response_type.go index e2a28abac..94d0d9dab 100644 --- a/worker/types/response_type.go +++ b/worker/types/response_type.go @@ -174,6 +174,7 @@ func (sh *SignedResponseHeader) Sign(signer *asymmetric.PrivateKey) (err error) // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } diff --git a/worker/types/types_test.go b/worker/types/types_test.go index 67316cb43..a3449731a 100644 --- a/worker/types/types_test.go +++ b/worker/types/types_test.go @@ -71,7 +71,7 @@ func Test_buildHash(t *testing.T) { } func TestSignedRequestHeader_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { req := &SignedRequestHeader{ @@ -87,11 +87,6 @@ func TestSignedRequestHeader_Sign(t *testing.T) { var err error - // without signee - err = req.Sign(privKey) - So(err, ShouldNotBeNil) - - req.Signee = pubKey err = req.Sign(privKey) So(err, ShouldBeNil) @@ -113,7 +108,7 @@ func TestSignedRequestHeader_Sign(t *testing.T) { } func TestRequest_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { req := &Request{ @@ -126,7 +121,6 @@ func TestRequest_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, Payload: RequestPayload{ Queries: []Query{ @@ -218,7 +212,7 @@ func TestRequest_Sign(t *testing.T) { } func TestResponse_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { res := &Response{ @@ -233,13 +227,11 @@ func TestResponse_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, NodeID: proto.NodeID("node2"), Timestamp: time.Now().UTC(), RowCount: uint64(1), }, - Signee: pubKey, }, Payload: ResponsePayload{ Columns: []string{ @@ -364,7 +356,7 @@ func TestResponse_Sign(t *testing.T) { } func TestAck_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { ack := &Ack{ @@ -381,18 +373,15 @@ func TestAck_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, NodeID: proto.NodeID("node2"), Timestamp: time.Now().UTC(), RowCount: uint64(1), }, - Signee: pubKey, }, NodeID: proto.NodeID("node1"), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, } @@ -487,7 +476,7 @@ func TestAck_Sign(t *testing.T) { } func TestNoAckReport_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { noAck := &NoAckReport{ @@ -506,16 +495,13 @@ func TestNoAckReport_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, NodeID: proto.NodeID("node2"), Timestamp: time.Now().UTC(), RowCount: uint64(1), }, - Signee: pubKey, }, }, - Signee: pubKey, }, } @@ -596,7 +582,7 @@ func TestNoAckReport_Sign(t *testing.T) { } func TestAggrNoAckReport_Sign(t *testing.T) { - privKey, pubKey := getCommKeys() + privKey, _ := getCommKeys() Convey("sign", t, func() { aggrNoAck := &AggrNoAckReport{ @@ -620,16 +606,13 @@ func TestAggrNoAckReport_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, NodeID: proto.NodeID("node2"), Timestamp: time.Now().UTC(), RowCount: uint64(1), }, - Signee: pubKey, }, }, - Signee: pubKey, }, { NoAckReportHeader: NoAckReportHeader{ @@ -646,16 +629,13 @@ func TestAggrNoAckReport_Sign(t *testing.T) { SeqNo: uint64(2), Timestamp: time.Now().UTC(), }, - Signee: pubKey, }, NodeID: proto.NodeID("node3"), Timestamp: time.Now().UTC(), RowCount: uint64(1), }, - Signee: pubKey, }, }, - Signee: pubKey, }, }, Peers: &kayak.Peers{ @@ -676,7 +656,6 @@ func TestAggrNoAckReport_Sign(t *testing.T) { }, }, }, - Signee: pubKey, }, } @@ -807,7 +786,6 @@ func TestInitServiceResponse_Sign(t *testing.T) { }, }, }, - Signee: pubKey, }, } @@ -898,8 +876,6 @@ func TestUpdateService_Sign(t *testing.T) { GenesisBlock: nil, }, }, - - Signee: pubKey, }, } diff --git a/worker/types/update_service_type.go b/worker/types/update_service_type.go index 470e39f24..ccea45e27 100644 --- a/worker/types/update_service_type.go +++ b/worker/types/update_service_type.go @@ -120,6 +120,7 @@ func (sh *SignedUpdateServiceHeader) Sign(signer *asymmetric.PrivateKey) (err er // sign sh.Signature, err = signer.Sign(sh.HeaderHash[:]) + sh.Signee = signer.PubKey() return } From d5739a47819db1c1c8967b273d688423bd18baa0 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 15:42:24 +0800 Subject: [PATCH 23/38] Refactor TxBilling and re-generate MarshalHash functions --- blockproducer/chain.go | 217 ++---------------- blockproducer/chain_test.go | 50 ++-- blockproducer/metastate_test.go | 30 +-- blockproducer/rpc.go | 5 - blockproducer/txindex.go | 111 --------- blockproducer/txindex_test.go | 66 ------ blockproducer/types/account_gen.go | 6 +- blockproducer/types/block.go | 20 +- blockproducer/types/block_gen.go | 24 +- blockproducer/types/block_test.go | 84 ++++--- blockproducer/types/txsqlchainbilling.go | 67 ++---- blockproducer/types/txsqlchainbilling_gen.go | 72 ++---- blockproducer/types/txsqlchainbilling_test.go | 28 +-- blockproducer/types/xxx_test.go | 19 +- blockproducer/xxx_test.go | 164 ++++++------- worker/types/response_type_gen.go | 16 +- 16 files changed, 238 insertions(+), 741 deletions(-) delete mode 100644 blockproducer/txindex.go delete mode 100644 blockproducer/txindex_test.go diff --git a/blockproducer/chain.go b/blockproducer/chain.go index aaf5070f6..0d7121dec 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -18,6 +18,7 @@ package blockproducer import ( "fmt" + "os" "sync" "time" @@ -30,22 +31,19 @@ import ( "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" - "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/coreos/bbolt" ) var ( - metaBucket = [4]byte{0x0, 0x0, 0x0, 0x0} - metaStateKey = []byte("covenantsql-state") - metaBlockIndexBucket = []byte("covenantsql-block-index-bucket") - metaTransactionBucket = []byte("covenantsql-tx-index-bucket") - metaTxBillingIndexBucket = []byte("covenantsql-tx-billing-index-bucket") - metaLastTxBillingIndexBucket = []byte("covenantsql-last-tx-billing-index-bucket") - metaAccountIndexBucket = []byte("covenantsql-account-index-bucket") - metaSQLChainIndexBucket = []byte("covenantsql-sqlchain-index-bucket") - gasprice uint32 = 1 - accountAddress proto.AccountAddress + metaBucket = [4]byte{0x0, 0x0, 0x0, 0x0} + metaStateKey = []byte("covenantsql-state") + metaBlockIndexBucket = []byte("covenantsql-block-index-bucket") + metaTransactionBucket = []byte("covenantsql-tx-index-bucket") + metaAccountIndexBucket = []byte("covenantsql-account-index-bucket") + metaSQLChainIndexBucket = []byte("covenantsql-sqlchain-index-bucket") + gasPrice uint32 = 1 + accountAddress proto.AccountAddress ) // Chain defines the main chain. @@ -53,7 +51,6 @@ type Chain struct { db *bolt.DB ms *metaState bi *blockIndex - ti *txIndex rt *rt cl *rpc.Caller @@ -65,6 +62,10 @@ type Chain struct { // NewChain creates a new blockchain. func NewChain(cfg *Config) (*Chain, error) { + if fi, err := os.Stat(cfg.DataFile); err == nil && fi.Mode().IsRegular() { + return LoadChain(cfg) + } + // open db file db, err := bolt.Open(cfg.DataFile, 0600, nil) if err != nil { @@ -105,16 +106,6 @@ func NewChain(cfg *Config) (*Chain, error) { } } - _, err = bucket.CreateBucketIfNotExists(metaTxBillingIndexBucket) - if err != nil { - return - } - - _, err = bucket.CreateBucketIfNotExists(metaLastTxBillingIndexBucket) - if err != nil { - return - } - _, err = bucket.CreateBucketIfNotExists(metaAccountIndexBucket) if err != nil { return @@ -132,7 +123,6 @@ func NewChain(cfg *Config) (*Chain, error) { db: db, ms: newMetaState(), bi: newBlockIndex(), - ti: newTxIndex(), rt: newRuntime(cfg, accountAddress), cl: rpc.NewCaller(), blocksFromSelf: make(chan *types.Block), @@ -182,7 +172,6 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { db: db, ms: newMetaState(), bi: newBlockIndex(), - ti: newTxIndex(), rt: newRuntime(cfg, accountAddress), cl: rpc.NewCaller(), blocksFromSelf: make(chan *types.Block), @@ -194,6 +183,7 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { err = chain.db.View(func(tx *bolt.Tx) (err error) { meta := tx.Bucket(metaBucket[:]) state := &State{} + // TODO(), should test if fetch metaState failed if err = state.deserialize(meta.Get(metaStateKey)); err != nil { return } @@ -238,39 +228,6 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { return err } - txbillings := meta.Bucket(metaTxBillingIndexBucket) - if err = txbillings.ForEach(func(k, v []byte) (err error) { - txbilling := types.TxBilling{} - err = txbilling.Deserialize(v) - if err != nil { - return - } - chain.ti.addTxBilling(&txbilling) - return - }); err != nil { - return - } - - lastTxBillings := meta.Bucket(metaLastTxBillingIndexBucket) - if err = lastTxBillings.ForEach(func(k, v []byte) (err error) { - var databaseID proto.DatabaseID - err = utils.DecodeMsgPack(k, &databaseID) - if err != nil { - return - } - - var sequenceID uint32 - err = utils.DecodeMsgPack(v, &sequenceID) - if err != nil { - return - } - - chain.ti.updateLastTxBilling(&databaseID, sequenceID) - return - }); err != nil { - return - } - // Reload state if err = chain.ms.reloadProcedure()(tx); err != nil { return @@ -285,51 +242,6 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { return chain, nil } -// checkTxBilling has two steps: 1. Hash 2. Signature 3. existed tx 4. SequenceID. -func (c *Chain) checkTxBilling(tb *types.TxBilling) (err error) { - err = tb.Verify() - if err != nil { - return err - } - - if val := c.ti.getTxBilling(tb.TxHash); val == nil { - err = c.db.View(func(tx *bolt.Tx) error { - meta := tx.Bucket(metaBucket[:]) - dec := meta.Bucket(metaTxBillingIndexBucket).Get(tb.TxHash[:]) - if len(dec) != 0 { - decTx := &types.TxBilling{} - err = decTx.Deserialize(dec) - if err != nil { - return err - } - - if decTx != nil && (!decTx.SignedBlock.IsEqual(tb.SignedBlock)) { - return ErrExistedTx - } - } - return nil - }) - if err != nil { - return err - } - } else { - if val.SignedBlock != nil && (!val.SignedBlock.IsEqual(tb.SignedBlock)) { - return ErrExistedTx - } - } - - // check sequence ID to avoid double rewards and fees - databaseID := tb.GetDatabaseID() - sequenceID, err := c.ti.lastSequenceID(databaseID) - if err == nil { - if sequenceID >= tb.GetSequenceID() { - return ErrSmallerSequenceID - } - } - - return nil -} - // checkBlock has following steps: 1. check parent block 2. checkTx 2. merkle tree 3. Hash 4. Signature. func (c *Chain) checkBlock(b *types.Block) (err error) { // TODO(lambda): process block fork @@ -342,13 +254,6 @@ func (c *Chain) checkBlock(b *types.Block) (err error) { return ErrParentNotMatch } - // TODO(leventeliu): merge transactions checking. - for i := range b.TxBillings { - if err = c.checkTxBilling(b.TxBillings[i]); err != nil { - return err - } - } - rootHash := merkle.NewMerkle(b.GetTxHashes()).GetRoot() if !b.SignedHeader.MerkleRoot.IsEqual(rootHash) { return ErrInvalidMerkleTreeRoot @@ -429,65 +334,9 @@ func (c *Chain) pushBlock(b *types.Block) error { return err } - for i := range b.TxBillings { - err = c.pushTxBillingWithoutCheck(b.TxBillings[i]) - if err != nil { - return err - } - } - - return nil -} - -func (c *Chain) pushTxBillingWithoutCheck(tb *types.TxBilling) error { - encTx, err := tb.Serialize() - if err != nil { - return err - } - - err = c.db.Update(func(tx *bolt.Tx) error { - meta := tx.Bucket(metaBucket[:]) - err = meta.Bucket(metaTxBillingIndexBucket).Put(tb.TxHash[:], encTx) - if err != nil { - return err - } - - // if the tx is packed in some block, its nonce should be stored to ensure nonce is monotone increasing - if tb.SignedBlock != nil { - databaseID, err := utils.EncodeMsgPack(tb.GetDatabaseID()) - if err != nil { - return err - } - - sequenceID, err := utils.EncodeMsgPack(tb.GetSequenceID()) - if err != nil { - return err - } - err = meta.Bucket(metaLastTxBillingIndexBucket).Put(databaseID.Bytes(), sequenceID.Bytes()) - return err - } - return nil - }) - if err != nil { - return err - } - c.ti.addTxBilling(tb) - if tb.IsSigned() { - c.ti.updateLastTxBilling(tb.GetDatabaseID(), tb.GetSequenceID()) - } return nil } -func (c *Chain) pushTxBilling(tb *types.TxBilling) error { - err := c.checkTxBilling(tb) - if err != nil { - return err - } - - err = c.pushTxBillingWithoutCheck(tb) - return err -} - func (c *Chain) produceBlock(now time.Time) error { priv, err := kms.GetLocalPrivateKey() if err != nil { @@ -503,7 +352,6 @@ func (c *Chain) produceBlock(now time.Time) error { Timestamp: now, }, }, - TxBillings: c.ti.fetchUnpackedTxBillings(), Transactions: c.ms.pullTxs(), } @@ -512,10 +360,6 @@ func (c *Chain) produceBlock(now time.Time) error { return err } - for i := range b.TxBillings { - b.TxBillings[i].SetSignedBlock(&b.SignedHeader.BlockHash) - } - log.Debugf("generate new block: %v", b) err = c.pushBlockWithoutCheck(b) @@ -573,7 +417,7 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequ for i, addrAndGas := range br.Header.GasAmounts { receivers[i] = &addrAndGas.AccountAddress - fees[i] = addrAndGas.GasAmount * uint64(gasprice) + fees[i] = addrAndGas.GasAmount * uint64(gasPrice) rewards[i] = 0 } @@ -595,8 +439,8 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequ return } var ( - tc = types.NewTxContent(uint32(nc), br, receivers, fees, rewards) - tb = types.NewTxBilling(tc, &c.rt.accountAddress) + tc = types.NewTxContent(nc, br, accountAddress, receivers, fees, rewards) + tb = types.NewTxBilling(tc) ) if err = tb.Sign(privKey); err != nil { return @@ -605,33 +449,6 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequ // 2. push tx c.pendingTxs <- tb - tbReq := &AdviseTxBillingReq{ - Envelope: proto.Envelope{ - // TODO(lambda): Add fields. - }, - TxBilling: tb, - } - peers := c.rt.getPeers() - wg := &sync.WaitGroup{} - for _, s := range peers.Servers { - if !s.ID.IsEqual(&c.rt.nodeID) { - wg.Add(1) - go func(id proto.NodeID) { - defer wg.Done() - tbResp := &AdviseTxBillingResp{} - if err := c.cl.CallNode(id, route.MCCAdviseTxBilling.String(), tbReq, tbResp); err != nil { - log.WithFields(log.Fields{ - "peer": c.rt.getPeerInfoString(), - "curr_turn": c.rt.getNextTurn(), - "now_time": time.Now().UTC().Format(time.RFC3339Nano), - "tx_hash": tb.TxHash, - }).WithError(err).Error( - "Failed to advise new block") - } - }(s.ID) - } - } - wg.Wait() return br, nil } diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index a99c6bb11..08ce6426e 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -18,12 +18,13 @@ package blockproducer import ( "io/ioutil" + "os" "sync" "testing" "time" - "github.com/CovenantSQL/CovenantSQL/blockproducer/types" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" + pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/kayak" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" @@ -42,12 +43,6 @@ var ( testClientNumberPerChain = 10 ) -type nodeProfile struct { - NodeID proto.NodeID - PrivateKey *asymmetric.PrivateKey - PublicKey *asymmetric.PublicKey -} - func TestChain(t *testing.T) { Convey("test main chain", t, func() { confDir := "../test/mainchain/node_standalone/config.yaml" @@ -63,6 +58,7 @@ func TestChain(t *testing.T) { So(err, ShouldBeNil) fl.Close() + os.Remove(fl.Name()) // create genesis block genesis, err := generateRandomBlock(genesisHash, true) @@ -97,7 +93,7 @@ func TestChain(t *testing.T) { So(loaded, ShouldBeTrue) So(bl, ShouldEqual, testInitBalance) - // Hack for signle instance test + // Hack for single instance test chain.rt.bpNum = 5 for { @@ -109,23 +105,29 @@ func TestChain(t *testing.T) { chain.rt.isMyTurn()) // chain will receive blocks and tx - // receive block // generate valid txbillings - tbs := make([]*types.TxBilling, 10) - for i := range tbs { - tb, err := generateRandomTxBillingWithSeqID(0) + tbs := make([]pi.Transaction, 0, 20) + + // pull previous processed transactions + tbs = append(tbs, chain.ms.pullTxs()...) + + for i := 0; i != 10; i++ { + tb, err := generateRandomAccountTxBilling() So(err, ShouldBeNil) - tbs[i] = tb + tbs = append(tbs, tb) } // generate block - block, err := generateRandomBlockWithTxBillings(*chain.rt.getHead().getHeader(), tbs) + block, err := generateRandomBlockWithTransactions(*chain.rt.getHead().getHeader(), tbs) So(err, ShouldBeNil) err = chain.pushBlock(block) So(err, ShouldBeNil) + nextNonce, err := chain.ms.nextNonce(testAddress1) + So(err, ShouldBeNil) for _, val := range tbs { - So(chain.ti.hasTxBilling(val.TxHash), ShouldBeTrue) + // should be packed + So(nextNonce >= val.GetAccountNonce(), ShouldBeTrue) } So(chain.bi.hasBlock(block.SignedHeader.BlockHash), ShouldBeTrue) // So(chain.rt.getHead().Height, ShouldEqual, height) @@ -138,17 +140,21 @@ func TestChain(t *testing.T) { So(specificHeightBlock2, ShouldBeNil) So(err, ShouldNotBeNil) - // receive txes - receivedTbs := make([]*types.TxBilling, 9) + // receive txs + receivedTbs := make([]*pt.TxBilling, 9) for i := range receivedTbs { - tb, err := generateRandomTxBillingWithSeqID(0) + tb, err := generateRandomAccountTxBilling() So(err, ShouldBeNil) receivedTbs[i] = tb - chain.pushTxBilling(tb) + err = chain.processTx(tb) + So(err, ShouldBeNil) } + nextNonce, err = chain.ms.nextNonce(testAddress1) + for _, val := range receivedTbs { - So(chain.ti.hasTxBilling(val.TxHash), ShouldBeTrue) + // should be packed or unpacked + So(chain.ms.pool.hasTx(val), ShouldBeTrue) } // So(height, ShouldEqual, chain.rt.getHead().Height) @@ -198,6 +204,8 @@ func TestMultiNode(t *testing.T) { // create tmp file fl, err := ioutil.TempFile("", "mainchain") So(err, ShouldBeNil) + fl.Close() + os.Remove(fl.Name()) // init config cleanup, dht, _, server, err := initNode(configs[i], privateKeys[i]) diff --git a/blockproducer/metastate_test.go b/blockproducer/metastate_test.go index 1d1095489..5533befef 100644 --- a/blockproducer/metastate_test.go +++ b/blockproducer/metastate_test.go @@ -586,12 +586,12 @@ func TestMetaState(t *testing.T) { } t2 = &pt.TxBilling{ TxContent: pt.TxContent{ - SequenceID: 2, - Receivers: []*proto.AccountAddress{&addr2}, - Fees: []uint64{1}, - Rewards: []uint64{1}, + Nonce: 2, + Producer: addr1, + Receivers: []*proto.AccountAddress{&addr2}, + Fees: []uint64{1}, + Rewards: []uint64{1}, }, - AccountAddress: &addr1, } ) err = t1.Sign(testPrivKey) @@ -718,21 +718,21 @@ func TestMetaState(t *testing.T) { }, &pt.TxBilling{ TxContent: pt.TxContent{ - SequenceID: 2, - Receivers: []*proto.AccountAddress{&addr2}, - Fees: []uint64{1}, - Rewards: []uint64{1}, + Nonce: 2, + Producer: addr1, + Receivers: []*proto.AccountAddress{&addr2}, + Fees: []uint64{1}, + Rewards: []uint64{1}, }, - AccountAddress: &addr1, }, &pt.TxBilling{ TxContent: pt.TxContent{ - SequenceID: 1, - Receivers: []*proto.AccountAddress{&addr1}, - Fees: []uint64{1}, - Rewards: []uint64{1}, + Nonce: 1, + Producer: addr2, + Receivers: []*proto.AccountAddress{&addr1}, + Fees: []uint64{1}, + Rewards: []uint64{1}, }, - AccountAddress: &addr2, }, &pt.Transfer{ TransferHeader: pt.TransferHeader{ diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 38cb43187..642e6b961 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -137,11 +137,6 @@ func (s *ChainRPCService) AdviseNewBlock(req *AdviseNewBlockReq, resp *AdviseNew return s.chain.pushBlock(req.Block) } -// AdviseTxBilling is the RPC method to advise a new billing tx to target server. -func (s *ChainRPCService) AdviseTxBilling(req *AdviseTxBillingReq, resp *AdviseTxBillingResp) error { - return s.chain.pushTxBilling(req.TxBilling) -} - // AdviseBillingRequest is the RPC method to advise a new billing request to main chain. func (s *ChainRPCService) AdviseBillingRequest(req *ct.AdviseBillingReq, resp *ct.AdviseBillingResp) error { response, err := s.chain.produceTxBilling(req.Req) diff --git a/blockproducer/txindex.go b/blockproducer/txindex.go deleted file mode 100644 index d17eebd21..000000000 --- a/blockproducer/txindex.go +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2018 The CovenantSQL Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package blockproducer - -import ( - "sync" - - "github.com/CovenantSQL/CovenantSQL/blockproducer/types" - "github.com/CovenantSQL/CovenantSQL/crypto/hash" - "github.com/CovenantSQL/CovenantSQL/proto" -) - -// txIndex indexes the tx blockchain receive. -type txIndex struct { - mu sync.Mutex - - billingHashIndex map[hash.Hash]*types.TxBilling - // lastBillingIndex indexes last appearing txBilling of DatabaseID - // to ensure the nonce of txbilling monotone increasing - lastBillingIndex map[*proto.DatabaseID]uint32 -} - -// newTxIndex creates a new TxIndex. -func newTxIndex() *txIndex { - ti := txIndex{ - billingHashIndex: make(map[hash.Hash]*types.TxBilling), - lastBillingIndex: make(map[*proto.DatabaseID]uint32), - } - return &ti -} - -// addTxBilling adds a checked TxBilling in the TxIndex. -func (ti *txIndex) addTxBilling(tb *types.TxBilling) error { - ti.mu.Lock() - defer ti.mu.Unlock() - - if v, ok := ti.billingHashIndex[*tb.TxHash]; ok { - // TODO(lambda): ensure whether the situation will happen - if v == nil { - return ErrCorruptedIndex - } - } - - ti.billingHashIndex[*tb.TxHash] = tb - - return nil -} - -// updateLatTxBilling updates the last billing index of specific databaseID. -func (ti *txIndex) updateLastTxBilling(databaseID *proto.DatabaseID, sequenceID uint32) (err error) { - ti.mu.Lock() - defer ti.mu.Unlock() - - if v, ok := ti.lastBillingIndex[databaseID]; ok { - if v >= sequenceID { - return ErrSmallerSequenceID - } - ti.lastBillingIndex[databaseID] = sequenceID - } - ti.lastBillingIndex[databaseID] = sequenceID - return -} - -// fetchUnpackedTxBillings fetch all txbillings in index. -func (ti *txIndex) fetchUnpackedTxBillings() []*types.TxBilling { - ti.mu.Lock() - defer ti.mu.Unlock() - - txes := make([]*types.TxBilling, 0, 1024) - - for _, t := range ti.billingHashIndex { - if t != nil && t.SignedBlock == nil { - txes = append(txes, t) - } - } - return txes -} - -// hasTxBilling look up the specific txbilling in index. -func (ti *txIndex) hasTxBilling(h *hash.Hash) bool { - _, ok := ti.billingHashIndex[*h] - return ok -} - -// getTxBilling look up the specific txbilling in index. -func (ti *txIndex) getTxBilling(h *hash.Hash) *types.TxBilling { - val := ti.billingHashIndex[*h] - return val -} - -// lastSequenceID look up the last sequenceID of specific databaseID. -func (ti *txIndex) lastSequenceID(databaseID *proto.DatabaseID) (uint32, error) { - if seqID, ok := ti.lastBillingIndex[databaseID]; ok { - return seqID, nil - } - return 0, ErrNoSuchTxBilling -} diff --git a/blockproducer/txindex_test.go b/blockproducer/txindex_test.go deleted file mode 100644 index 784c7808f..000000000 --- a/blockproducer/txindex_test.go +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2018 The CovenantSQL Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package blockproducer - -import ( - "math/rand" - "reflect" - "testing" - - "github.com/CovenantSQL/CovenantSQL/blockproducer/types" -) - -func Test_AddAndHasTxBilling(t *testing.T) { - ti := newTxIndex() - maxLen := 100 - mlen := rand.Intn(maxLen) - tbs := make([]*types.TxBilling, mlen) - for i := range tbs { - tb, err := generateRandomTxBilling() - if err != nil { - t.Fatalf("unexpect error: %v", err) - } - tbs[i] = tb - err = ti.addTxBilling(tb) - if err != nil { - t.Fatalf("unexpect error: %v", err) - } - } - - for i := range tbs { - if !ti.hasTxBilling(tbs[i].TxHash) { - t.Fatalf("tx (%v) should be included in tx index", tbs[i]) - } - if val := ti.getTxBilling(tbs[i].TxHash); !reflect.DeepEqual(tbs[i], val) { - t.Fatalf("tx (%v) should be included in tx index", tbs[i]) - } - tb, err := generateRandomTxBilling() - if err != nil { - t.Fatalf("unexpect error: %v", err) - } - if ti.hasTxBilling(tb.TxHash) { - t.Fatalf("tx (%v) should be excluded in tx index", tb) - } - } - - fetchedTbs := ti.fetchUnpackedTxBillings() - for i := range fetchedTbs { - if !reflect.DeepEqual(tbs[i], fetchedTbs[i]) { - t.Fatalf("two values should be equal: \n\tv1=%v\n\tv2=%v", tbs[i], fetchedTbs[i]) - } - } -} diff --git a/blockproducer/types/account_gen.go b/blockproducer/types/account_gen.go index 1b7ea56b4..031082942 100644 --- a/blockproducer/types/account_gen.go +++ b/blockproducer/types/account_gen.go @@ -12,14 +12,14 @@ func (z *Account) MarshalHash() (o []byte, err error) { o = hsp.Require(b, z.Msgsize()) // map header, size 5 o = append(o, 0x85, 0x85) + o = hsp.AppendFloat64(o, z.Rating) + o = append(o, 0x85) if oTemp, err := z.NextNonce.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } o = append(o, 0x85) - o = hsp.AppendFloat64(o, z.Rating) - o = append(o, 0x85) if oTemp, err := z.Address.MarshalHash(); err != nil { return nil, err } else { @@ -34,7 +34,7 @@ func (z *Account) MarshalHash() (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Account) Msgsize() (s int) { - s = 1 + 10 + z.NextNonce.Msgsize() + 7 + hsp.Float64Size + 8 + z.Address.Msgsize() + 18 + hsp.Uint64Size + 20 + hsp.Uint64Size + s = 1 + 7 + hsp.Float64Size + 10 + z.NextNonce.Msgsize() + 8 + z.Address.Msgsize() + 18 + hsp.Uint64Size + 20 + hsp.Uint64Size return } diff --git a/blockproducer/types/block.go b/blockproducer/types/block.go index 515f6c595..41c09501c 100644 --- a/blockproducer/types/block.go +++ b/blockproducer/types/block.go @@ -60,7 +60,6 @@ func (s *SignedHeader) Verify() error { // Block defines the main chain block. type Block struct { SignedHeader SignedHeader - TxBillings []*TxBilling Transactions []pi.Transaction } @@ -68,14 +67,11 @@ type Block struct { func (b *Block) GetTxHashes() []*hash.Hash { // TODO(lambda): when you add new tx type, you need to put new tx's hash in the slice // get hashes in block.TxBillings - bl := len(b.TxBillings) - hs := make([]*hash.Hash, len(b.TxBillings)+len(b.Transactions)) - for i, v := range b.TxBillings { - hs[i] = v.TxHash - } + hs := make([]*hash.Hash, len(b.Transactions)) + for i, v := range b.Transactions { h := v.GetHash() - hs[bl+i] = &h + hs[i] = &h } return hs } @@ -150,16 +146,6 @@ func (b *Block) Deserialize(buf []byte) error { return dec.Decode(b) } -// PushTx pushes txes into block. -func (b *Block) PushTx(tx *TxBilling) { - if b.TxBillings != nil { - // TODO(lambda): set appropriate capacity. - b.TxBillings = make([]*TxBilling, 0, 100) - } - - b.TxBillings = append(b.TxBillings, tx) -} - // Verify verifies whether the block is valid. func (b *Block) Verify() error { hs := b.GetTxHashes() diff --git a/blockproducer/types/block_gen.go b/blockproducer/types/block_gen.go index 5398974ce..1a0814c1c 100644 --- a/blockproducer/types/block_gen.go +++ b/blockproducer/types/block_gen.go @@ -18,16 +18,12 @@ func (z *Block) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } o = append(o, 0x82) - o = hsp.AppendArrayHeader(o, uint32(len(z.TxBillings))) - for za0001 := range z.TxBillings { - if z.TxBillings[za0001] == nil { - o = hsp.AppendNil(o) + o = hsp.AppendArrayHeader(o, uint32(len(z.Transactions))) + for za0001 := range z.Transactions { + if oTemp, err := z.Transactions[za0001].MarshalHash(); err != nil { + return nil, err } else { - if oTemp, err := z.TxBillings[za0001].MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } + o = hsp.AppendBytes(o, oTemp) } } return @@ -35,13 +31,9 @@ func (z *Block) MarshalHash() (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Block) Msgsize() (s int) { - s = 1 + 13 + z.SignedHeader.Msgsize() + 11 + hsp.ArrayHeaderSize - for za0001 := range z.TxBillings { - if z.TxBillings[za0001] == nil { - s += hsp.NilSize - } else { - s += z.TxBillings[za0001].Msgsize() - } + s = 1 + 13 + z.SignedHeader.Msgsize() + 13 + hsp.ArrayHeaderSize + for za0001 := range z.Transactions { + s += z.Transactions[za0001].Msgsize() } return } diff --git a/blockproducer/types/block_test.go b/blockproducer/types/block_test.go index 10f2f712d..701698bd3 100644 --- a/blockproducer/types/block_test.go +++ b/blockproducer/types/block_test.go @@ -17,12 +17,9 @@ package types import ( - "encoding" "reflect" "testing" - "bytes" - "github.com/CovenantSQL/CovenantSQL/utils" ) @@ -74,45 +71,46 @@ func TestSignedHeader_MarshalUnmashalBinary(t *testing.T) { } -func TestBlock_MarshalUnmarshalBinary(t *testing.T) { - block, err := generateRandomBlock(genesisHash, false) - if err != nil { - t.Fatalf("Failed to generate block: %v", err) - } - h := reflect.TypeOf(block) - _, ok := h.(encoding.BinaryMarshaler) - if ok { - t.Log("dec hash BinaryMashaler interface") - } - - enc, err := block.Serialize() - if err != nil { - t.Fatalf("Failed to mashal binary: %v", err) - } - - dec := &Block{} - - err = dec.Deserialize(enc) - if err != nil { - t.Fatalf("Failed to unmashal binary: %v", err) - } - - bts1, err := block.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := dec.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } - - if !reflect.DeepEqual(block, dec) { - t.Fatalf("value not match") - } -} +// +//func TestBlock_MarshalUnmarshalBinary(t *testing.T) { +// block, err := generateRandomBlock(genesisHash, false) +// if err != nil { +// t.Fatalf("Failed to generate block: %v", err) +// } +// h := reflect.TypeOf(block) +// _, ok := h.(encoding.BinaryMarshaler) +// if ok { +// t.Log("dec hash BinaryMashaler interface") +// } +// +// enc, err := block.Serialize() +// if err != nil { +// t.Fatalf("Failed to mashal binary: %v", err) +// } +// +// dec := &Block{} +// +// err = dec.Deserialize(enc) +// if err != nil { +// t.Fatalf("Failed to unmashal binary: %v", err) +// } +// +// bts1, err := block.MarshalHash() +// if err != nil { +// t.Fatal(err) +// } +// bts2, err := dec.MarshalHash() +// if err != nil { +// t.Fatal(err) +// } +// if !bytes.Equal(bts1, bts2) { +// t.Fatal("hash not stable") +// } +// +// if !reflect.DeepEqual(block, dec) { +// t.Fatalf("value not match") +// } +//} func TestBlock_PackAndSignBlock(t *testing.T) { block, err := generateRandomBlock(genesisHash, false) @@ -135,7 +133,7 @@ func TestBlock_PackAndSignBlock(t *testing.T) { if err != nil { t.Fatalf("Unexpected error: %v", err) } - block.PushTx(tb) + block.Transactions = append(block.Transactions, tb) err = block.Verify() if err != ErrMerkleRootVerification { t.Fatalf("Unexpected error: %v", err) diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/txsqlchainbilling.go index 0feb00018..4366d5602 100644 --- a/blockproducer/types/txsqlchainbilling.go +++ b/blockproducer/types/txsqlchainbilling.go @@ -18,7 +18,6 @@ package types import ( "bytes" - "sync" pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" @@ -28,13 +27,16 @@ import ( ) //go:generate hsp -//hsp:ignore sync.Mutex Mutex // TxContent defines the customer's billing and block rewards in transaction. type TxContent struct { - SequenceID uint32 + // Transaction nonce + Nonce pi.AccountNonce BillingRequest BillingRequest - Receivers []*proto.AccountAddress + // Bill producer + Producer proto.AccountAddress + // Bill receivers + Receivers []*proto.AccountAddress // Fee paid by stable coin Fees []uint64 // Reward is share coin @@ -42,14 +44,12 @@ type TxContent struct { } // NewTxContent generates new TxContent. -func NewTxContent(seqID uint32, - bReq *BillingRequest, - receivers []*proto.AccountAddress, - fees []uint64, - rewards []uint64) *TxContent { +func NewTxContent(seqID pi.AccountNonce, bReq *BillingRequest, producer proto.AccountAddress, receivers []*proto.AccountAddress, + fees []uint64, rewards []uint64) *TxContent { return &TxContent{ - SequenceID: seqID, + Nonce: seqID, BillingRequest: *bReq, + Producer: producer, Receivers: receivers, Fees: fees, Rewards: rewards, @@ -68,21 +68,16 @@ func (tb *TxContent) GetHash() (*hash.Hash, error) { // TxBilling is a type of tx, that is used to record sql chain billing and block rewards. type TxBilling struct { - mutex sync.Mutex - TxContent TxContent - TxType byte - AccountAddress *proto.AccountAddress - TxHash *hash.Hash - Signee *asymmetric.PublicKey - Signature *asymmetric.Signature - SignedBlock *hash.Hash + TxContent TxContent + TxHash *hash.Hash + Signee *asymmetric.PublicKey + Signature *asymmetric.Signature } // NewTxBilling generates a new TxBilling. -func NewTxBilling(txContent *TxContent, addr *proto.AccountAddress) *TxBilling { +func NewTxBilling(txContent *TxContent) *TxBilling { return &TxBilling{ - TxContent: *txContent, - AccountAddress: addr, + TxContent: *txContent, } } @@ -103,12 +98,12 @@ func (tb *TxBilling) Deserialize(enc []byte) error { // GetAccountAddress implements interfaces/Transaction.GetAccountAddress. func (tb *TxBilling) GetAccountAddress() proto.AccountAddress { - return *tb.AccountAddress + return tb.TxContent.Producer } // GetAccountNonce implements interfaces/Transaction.GetAccountNonce. func (tb *TxBilling) GetAccountNonce() pi.AccountNonce { - return pi.AccountNonce(tb.TxContent.SequenceID) + return tb.TxContent.Nonce } // GetHash implements interfaces/Transaction.GetHash. @@ -160,32 +155,6 @@ func (tb *TxBilling) GetDatabaseID() *proto.DatabaseID { return &tb.TxContent.BillingRequest.Header.DatabaseID } -// GetSequenceID gets the sequence ID. -func (tb *TxBilling) GetSequenceID() uint32 { - return tb.TxContent.SequenceID -} - -// IsSigned shows whether the tx billing is signed. -func (tb *TxBilling) IsSigned() bool { - tb.mutex.Lock() - defer tb.mutex.Unlock() - return tb.SignedBlock != nil -} - -// SetSignedBlock sets the tx billing with block hash. -func (tb *TxBilling) SetSignedBlock(h *hash.Hash) { - tb.mutex.Lock() - defer tb.mutex.Unlock() - tb.SignedBlock = h -} - -// GetSignedBlock gets the block hash. -func (tb *TxBilling) GetSignedBlock() *hash.Hash { - tb.mutex.Lock() - defer tb.mutex.Unlock() - return tb.SignedBlock -} - func init() { pi.RegisterTransaction(pi.TransactionTypeBilling, (*TxBilling)(nil)) } diff --git a/blockproducer/types/txsqlchainbilling_gen.go b/blockproducer/types/txsqlchainbilling_gen.go index 169f0436a..3fc03f635 100644 --- a/blockproducer/types/txsqlchainbilling_gen.go +++ b/blockproducer/types/txsqlchainbilling_gen.go @@ -10,8 +10,8 @@ import ( func (z *TxBilling) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 7 - o = append(o, 0x87, 0x87) + // map header, size 4 + o = append(o, 0x84, 0x84) if z.Signee == nil { o = hsp.AppendNil(o) } else { @@ -21,7 +21,7 @@ func (z *TxBilling) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } } - o = append(o, 0x87) + o = append(o, 0x84) if z.Signature == nil { o = hsp.AppendNil(o) } else { @@ -31,17 +31,7 @@ func (z *TxBilling) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } } - o = append(o, 0x87) - if z.SignedBlock == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.SignedBlock.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x87) + o = append(o, 0x84) if z.TxHash == nil { o = hsp.AppendNil(o) } else { @@ -51,24 +41,12 @@ func (z *TxBilling) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } } - o = append(o, 0x87) - if z.AccountAddress == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.AccountAddress.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x87) + o = append(o, 0x84) if oTemp, err := z.TxContent.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x87) - o = hsp.AppendByte(o, z.TxType) return } @@ -86,25 +64,13 @@ func (z *TxBilling) Msgsize() (s int) { } else { s += z.Signature.Msgsize() } - s += 12 - if z.SignedBlock == nil { - s += hsp.NilSize - } else { - s += z.SignedBlock.Msgsize() - } s += 7 if z.TxHash == nil { s += hsp.NilSize } else { s += z.TxHash.Msgsize() } - s += 15 - if z.AccountAddress == nil { - s += hsp.NilSize - } else { - s += z.AccountAddress.Msgsize() - } - s += 10 + z.TxContent.Msgsize() + 7 + hsp.ByteSize + s += 10 + z.TxContent.Msgsize() return } @@ -112,14 +78,14 @@ func (z *TxBilling) Msgsize() (s int) { func (z *TxContent) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 5 - o = append(o, 0x85, 0x85) + // map header, size 6 + o = append(o, 0x86, 0x86) if oTemp, err := z.BillingRequest.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x85) + o = append(o, 0x86) o = hsp.AppendArrayHeader(o, uint32(len(z.Receivers))) for za0001 := range z.Receivers { if z.Receivers[za0001] == nil { @@ -132,18 +98,28 @@ func (z *TxContent) MarshalHash() (o []byte, err error) { } } } - o = append(o, 0x85) + o = append(o, 0x86) o = hsp.AppendArrayHeader(o, uint32(len(z.Fees))) for za0002 := range z.Fees { o = hsp.AppendUint64(o, z.Fees[za0002]) } - o = append(o, 0x85) + o = append(o, 0x86) o = hsp.AppendArrayHeader(o, uint32(len(z.Rewards))) for za0003 := range z.Rewards { o = hsp.AppendUint64(o, z.Rewards[za0003]) } - o = append(o, 0x85) - o = hsp.AppendUint32(o, z.SequenceID) + o = append(o, 0x86) + if oTemp, err := z.Nonce.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + o = append(o, 0x86) + if oTemp, err := z.Producer.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } return } @@ -157,6 +133,6 @@ func (z *TxContent) Msgsize() (s int) { s += z.Receivers[za0001].Msgsize() } } - s += 5 + hsp.ArrayHeaderSize + (len(z.Fees) * (hsp.Uint64Size)) + 8 + hsp.ArrayHeaderSize + (len(z.Rewards) * (hsp.Uint64Size)) + 11 + hsp.Uint32Size + s += 5 + hsp.ArrayHeaderSize + (len(z.Fees) * (hsp.Uint64Size)) + 8 + hsp.ArrayHeaderSize + (len(z.Rewards) * (hsp.Uint64Size)) + 6 + z.Nonce.Msgsize() + 9 + z.Producer.Msgsize() return } diff --git a/blockproducer/types/txsqlchainbilling_test.go b/blockproducer/types/txsqlchainbilling_test.go index b992fc881..6b1ef34ff 100644 --- a/blockproducer/types/txsqlchainbilling_test.go +++ b/blockproducer/types/txsqlchainbilling_test.go @@ -60,8 +60,8 @@ func TestTxContent_MarshalUnmarshalBinary(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } - if tc.SequenceID != dec.SequenceID { - t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tc.SequenceID, tc.SequenceID) + if tc.Nonce != dec.Nonce { + t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tc.Nonce, tc.Nonce) } if tc.BillingRequest.RequestHash != dec.BillingRequest.RequestHash { t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tc.BillingRequest.RequestHash, tc.BillingRequest.RequestHash) @@ -99,9 +99,6 @@ func TestTxBilling_SerializeDeserialize(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } - if !tb.SignedBlock.IsEqual(dec.SignedBlock) { - t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.SignedBlock, tb.SignedBlock) - } if !tb.Signature.IsEqual(dec.Signature) { t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.Signature, tb.Signature) } @@ -113,27 +110,6 @@ func TestTxBilling_SerializeDeserialize(t *testing.T) { } } -func TestTxBilling_GetSet(t *testing.T) { - tb, err := generateRandomTxBilling() - if err != nil { - t.Fatalf("Unexpeted error: %v", err) - } - - tb.GetSequenceID() - if tb.GetDatabaseID() == nil { - t.Fatalf("String should not be nil: %v", tb) - } - - if !tb.IsSigned() { - t.Fatalf("BlockHash should not be nil: %v", tb) - } - h := generateRandomHash() - tb.SetSignedBlock(&h) - if !h.IsEqual(tb.GetSignedBlock()) { - t.Fatalf("BlockHash should be the same: v1=%s, v2=%s", h.String(), tb.GetSignedBlock().String()) - } -} - func TestTxBilling_PackAndSignTx(t *testing.T) { tb, err := generateRandomTxBilling() if err != nil { diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index 7ad157b34..9431b394b 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/crypto/kms" @@ -116,14 +117,6 @@ func randStringBytes(n int) string { return string(b) } -func generateRandomUint32s(n int32) []uint32 { - s := make([]uint32, n) - for i := range s { - s[i] = (uint32)(rand.Int31()) - } - return s -} - func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) { // Generate key pair priv, _, err := asymmetric.GenSecp256k1KeyPair() @@ -151,7 +144,7 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) if err != nil { return nil, err } - b.PushTx(tb) + b.Transactions = append(b.Transactions, tb) } err = b.PackAndSignBlock(priv) @@ -220,7 +213,8 @@ func generateRandomTxContent() (tc *TxContent, err error) { rewards[i] = rand.Uint64() } - tc = NewTxContent(rand.Uint32(), req, receivers, fees, rewards) + producer := proto.AccountAddress(generateRandomHash()) + tc = NewTxContent(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) return tc, nil } @@ -229,20 +223,17 @@ func generateRandomTxBilling() (*TxBilling, error) { if err != nil { return nil, err } - accountAddress := proto.AccountAddress(generateRandomHash()) txHash := generateRandomHash() priv, pub, err := asymmetric.GenSecp256k1KeyPair() sign, err := priv.Sign(txHash[:]) if err != nil { return nil, err } - blockHash := generateRandomHash() - txBilling := NewTxBilling(txContent, &accountAddress) + txBilling := NewTxBilling(txContent) txBilling.TxHash = &txHash txBilling.Signee = pub txBilling.Signature = sign - txBilling.SignedBlock = &blockHash return txBilling, nil } diff --git a/blockproducer/xxx_test.go b/blockproducer/xxx_test.go index 849690014..96ae8c16b 100644 --- a/blockproducer/xxx_test.go +++ b/blockproducer/xxx_test.go @@ -25,8 +25,8 @@ import ( "time" pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" - "github.com/CovenantSQL/CovenantSQL/blockproducer/types" pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/crypto" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/crypto/kms" @@ -41,17 +41,13 @@ var ( uuidLen = 32 peerNum uint32 = 32 - testAddress1 = proto.AccountAddress{0x0, 0x0, 0x0, 0x1} - testAddress2 = proto.AccountAddress{0x0, 0x0, 0x0, 0x2} - testInitBalance = uint64(10000) - testMasterKey = []byte(".9K.sgch!3;C>w0v") - testDifficulty = 4 - testDataDir string - testPrivKeyFile string - testPubKeysFile string - testNonce pi.AccountNonce - testPrivKey *asymmetric.PrivateKey - testPubKey *asymmetric.PublicKey + testAddress1 = proto.AccountAddress{0x0, 0x0, 0x0, 0x1} + testAddress2 = proto.AccountAddress{0x0, 0x0, 0x0, 0x2} + testInitBalance = uint64(10000) + testDifficulty = 4 + testDataDir string + testAddress1Nonce pi.AccountNonce + testPrivKey *asymmetric.PrivateKey ) const ( @@ -87,7 +83,7 @@ func randStringBytes(n int) string { return string(b) } -func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err error) { +func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *pt.Block, err error) { // Generate key pair priv, _, err := asymmetric.GenSecp256k1KeyPair() @@ -98,9 +94,9 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err h := hash.Hash{} rand.Read(h[:]) - b = &types.Block{ - SignedHeader: types.SignedHeader{ - Header: types.Header{ + b = &pt.Block{ + SignedHeader: pt.SignedHeader{ + Header: pt.Header{ Version: 0x01000000, Producer: proto.AccountAddress(h), ParentHash: parent, @@ -111,11 +107,11 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err if !isGenesis { for i, n := 0, rand.Intn(10)+10; i < n; i++ { - tb, err := generateRandomTxBilling() + ba, tb, err := generateRandomTxBillingAndBaseAccount() if err != nil { return nil, err } - b.PushTx(tb) + b.Transactions = append(b.Transactions, ba, tb) } } else { // Create base accounts @@ -141,15 +137,14 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err if err = ba2.Sign(testPrivKey); err != nil { return } - b.Transactions = append(b.Transactions, ba1) - b.Transactions = append(b.Transactions, ba2) + b.Transactions = append(b.Transactions, ba1, ba2) } err = b.PackAndSignBlock(priv) return } -func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) (b *types.Block, err error) { +func generateRandomBlockWithTransactions(parent hash.Hash, tbs []pi.Transaction) (b *pt.Block, err error) { // Generate key pair priv, _, err := asymmetric.GenSecp256k1KeyPair() @@ -160,9 +155,9 @@ func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) h := hash.Hash{} rand.Read(h[:]) - b = &types.Block{ - SignedHeader: types.SignedHeader{ - Header: types.Header{ + b = &pt.Block{ + SignedHeader: pt.SignedHeader{ + Header: pt.Header{ Version: 0x01000000, Producer: proto.AccountAddress(h), ParentHash: parent, @@ -171,14 +166,16 @@ func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) }, } - b.TxBillings = tbs + for _, tb := range tbs { + b.Transactions = append(b.Transactions, tb) + } - testNonce++ + testAddress1Nonce++ var tr = &pt.Transfer{ TransferHeader: pt.TransferHeader{ Sender: testAddress1, Receiver: testAddress2, - Nonce: testNonce, + Nonce: testAddress1Nonce, Amount: 1, }, } @@ -188,15 +185,12 @@ func generateRandomBlockWithTxBillings(parent hash.Hash, tbs []*types.TxBilling) b.Transactions = append(b.Transactions, tr) err = b.PackAndSignBlock(priv) - for i := range b.TxBillings { - b.TxBillings[i].SignedBlock = &b.SignedHeader.BlockHash - } return } -func generateRandomBillingRequestHeader() *types.BillingRequestHeader { - return &types.BillingRequestHeader{ +func generateRandomBillingRequestHeader() *pt.BillingRequestHeader { + return &pt.BillingRequestHeader{ DatabaseID: *generateRandomDatabaseID(), LowBlock: generateRandomHash(), LowHeight: rand.Int31(), @@ -206,9 +200,9 @@ func generateRandomBillingRequestHeader() *types.BillingRequestHeader { } } -func generateRandomBillingRequest() (*types.BillingRequest, error) { +func generateRandomBillingRequest() (*pt.BillingRequest, error) { reqHeader := generateRandomBillingRequestHeader() - req := types.BillingRequest{ + req := pt.BillingRequest{ Header: *reqHeader, } h, err := req.PackRequestHeader() @@ -238,8 +232,8 @@ func generateRandomBillingRequest() (*types.BillingRequest, error) { return &req, nil } -func generateRandomTxContent() (tc *types.TxContent, err error) { - var req *types.BillingRequest +func generateRandomTxContent() (tc *pt.TxContent, err error) { + var req *pt.BillingRequest if req, err = generateRandomBillingRequest(); err != nil { return } @@ -263,62 +257,59 @@ func generateRandomTxContent() (tc *types.TxContent, err error) { fees[i] = rand.Uint64() rewards[i] = rand.Uint64() } + producer := proto.AccountAddress(generateRandomHash()) - tc = types.NewTxContent(rand.Uint32(), req, receivers, fees, rewards) + tc = pt.NewTxContent(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) return tc, nil } -func generateRandomTxBilling() (*types.TxBilling, error) { +func generateRandomTxBillingAndBaseAccount() (*pt.BaseAccount, *pt.TxBilling, error) { txContent, err := generateRandomTxContent() if err != nil { - return nil, err + return nil, nil, err } - accountAddress := proto.AccountAddress(generateRandomHash()) - txHash := generateRandomHash() - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := priv.Sign(txHash[:]) - if err != nil { - return nil, err + priv, _, err := asymmetric.GenSecp256k1KeyPair() + txContent.Producer, _ = crypto.PubKeyHash(priv.PubKey()) + + txBilling := &pt.TxBilling{ + TxContent: *txContent, } - blockHash := generateRandomHash() - txBilling := &types.TxBilling{ - TxContent: *txContent, - AccountAddress: &accountAddress, - TxHash: &txHash, - Signee: pub, - Signature: sign, - SignedBlock: &blockHash, + if err := txBilling.Sign(priv); err != nil { + return nil, nil, err } - return txBilling, nil + + txBaseAccount := &pt.BaseAccount{ + Account: pt.Account{ + Address: txContent.Producer, + StableCoinBalance: testInitBalance, + CovenantCoinBalance: testInitBalance, + }, + } + + if err := txBaseAccount.Sign(priv); err != nil { + return nil, nil, err + } + + return txBaseAccount, txBilling, nil } -func generateRandomTxBillingWithSeqID(seqID uint32) (*types.TxBilling, error) { +func generateRandomAccountTxBilling() (*pt.TxBilling, error) { txContent, err := generateRandomTxContent() - txContent.SequenceID = seqID if err != nil { return nil, err } - accountAddress := testAddress1 - enc, err := txContent.MarshalHash() - if err != nil { - return nil, err + txContent.Producer = testAddress1 + testAddress1Nonce++ + txContent.Nonce = testAddress1Nonce + txBilling := &pt.TxBilling{ + TxContent: *txContent, } - txHash := hash.THashH(enc) - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := priv.Sign(txHash[:]) - if err != nil { + + if err := txBilling.Sign(testPrivKey); err != nil { return nil, err } - txBilling := &types.TxBilling{ - TxContent: *txContent, - AccountAddress: &accountAddress, - TxHash: &txHash, - Signee: pub, - Signature: sign, - SignedBlock: nil, - } return txBilling, nil } @@ -342,22 +333,6 @@ func generateRandomHash() hash.Hash { return h } -func generateRandomNode() (node *nodeProfile, err error) { - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - - if err != nil { - return - } - - node = &nodeProfile{ - PrivateKey: priv, - PublicKey: pub, - } - - createRandomString(10, 10, (*string)(&node.NodeID)) - return -} - func registerNodesWithPublicKey(pub *asymmetric.PublicKey, diff int, num int) ( nis []cpuminer.NonceInfo, err error) { nis = make([]cpuminer.NonceInfo, num) @@ -402,17 +377,6 @@ func createRandomString(offset, length int, s *string) { *s = string(buff) } -// createNodes assign Node asymmetric key pair and generate Node.NonceInfo -// Node.ID = Node.NonceInfo.Hash. -func createNodes(pubKey *asymmetric.PublicKey, timeThreshold time.Duration) *proto.Node { - node := proto.NewNode() - nonce := asymmetric.GetPubKeyNonce(pubKey, proto.NewNodeIDDifficulty, timeThreshold, nil) - node.ID = proto.NodeID(nonce.Hash.String()) - node.Nonce = nonce.Nonce - log.Debugf("Node: %v", node) - return node -} - func createTestPeersWithPrivKeys(priv *asymmetric.PrivateKey, num int) (nis []cpuminer.NonceInfo, p *kayak.Peers, err error) { if num <= 0 { return @@ -522,7 +486,7 @@ func setup() { rand.Read(genesisHash[:]) // Create key paire for test - if testPrivKey, testPubKey, err = asymmetric.GenSecp256k1KeyPair(); err != nil { + if testPrivKey, _, err = asymmetric.GenSecp256k1KeyPair(); err != nil { panic(err) } diff --git a/worker/types/response_type_gen.go b/worker/types/response_type_gen.go index 3126d6e1c..8ce0f4c36 100644 --- a/worker/types/response_type_gen.go +++ b/worker/types/response_type_gen.go @@ -36,35 +36,37 @@ func (z *Response) Msgsize() (s int) { func (z *ResponseHeader) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 5 - o = append(o, 0x85, 0x85) + // map header, size 6 + o = append(o, 0x86, 0x86) if oTemp, err := z.Request.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x85) + o = append(o, 0x86) if oTemp, err := z.DataHash.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x85) + o = append(o, 0x86) if oTemp, err := z.NodeID.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x85) + o = append(o, 0x86) o = hsp.AppendTime(o, z.Timestamp) - o = append(o, 0x85) + o = append(o, 0x86) o = hsp.AppendUint64(o, z.RowCount) + o = append(o, 0x86) + o = hsp.AppendUint64(o, z.LogOffset) return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *ResponseHeader) Msgsize() (s int) { - s = 1 + 8 + z.Request.Msgsize() + 9 + z.DataHash.Msgsize() + 7 + z.NodeID.Msgsize() + 10 + hsp.TimeSize + 9 + hsp.Uint64Size + s = 1 + 8 + z.Request.Msgsize() + 9 + z.DataHash.Msgsize() + 7 + z.NodeID.Msgsize() + 10 + hsp.TimeSize + 9 + hsp.Uint64Size + 10 + hsp.Uint64Size return } From 31e94bb4dbd4779fa408a6c7ab2f6f5fcc355255 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 15:56:16 +0800 Subject: [PATCH 24/38] Rename BillingRequest filename --- blockproducer/types/{billing.go => billing_request.go} | 0 blockproducer/types/{billing_gen.go => billing_request_gen.go} | 0 .../types/{billing_gen_test.go => billing_request_gen_test.go} | 0 blockproducer/types/{billing_test.go => billing_request_test.go} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename blockproducer/types/{billing.go => billing_request.go} (100%) rename blockproducer/types/{billing_gen.go => billing_request_gen.go} (100%) rename blockproducer/types/{billing_gen_test.go => billing_request_gen_test.go} (100%) rename blockproducer/types/{billing_test.go => billing_request_test.go} (100%) diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing_request.go similarity index 100% rename from blockproducer/types/billing.go rename to blockproducer/types/billing_request.go diff --git a/blockproducer/types/billing_gen.go b/blockproducer/types/billing_request_gen.go similarity index 100% rename from blockproducer/types/billing_gen.go rename to blockproducer/types/billing_request_gen.go diff --git a/blockproducer/types/billing_gen_test.go b/blockproducer/types/billing_request_gen_test.go similarity index 100% rename from blockproducer/types/billing_gen_test.go rename to blockproducer/types/billing_request_gen_test.go diff --git a/blockproducer/types/billing_test.go b/blockproducer/types/billing_request_test.go similarity index 100% rename from blockproducer/types/billing_test.go rename to blockproducer/types/billing_request_test.go From 47eb5ebe0175694f33fdff75c8bcc3241ec5dc19 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 16:23:18 +0800 Subject: [PATCH 25/38] Rename TxBilling to Billing type transaction --- blockproducer/chain.go | 6 +- blockproducer/chain_test.go | 8 +- blockproducer/metastate.go | 10 +-- blockproducer/metastate_test.go | 12 +-- blockproducer/rpc.go | 4 +- blockproducer/types/block.go | 6 +- blockproducer/types/block_test.go | 2 +- blockproducer/types/transfer.go | 4 +- blockproducer/types/txsqlchainbilling.go | 76 ++++++++----------- blockproducer/types/txsqlchainbilling_gen.go | 12 +-- .../types/txsqlchainbilling_gen_test.go | 24 +++--- blockproducer/types/txsqlchainbilling_test.go | 36 +++------ blockproducer/types/xxx_test.go | 12 +-- blockproducer/xxx_test.go | 30 ++++---- 14 files changed, 107 insertions(+), 135 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index 0d7121dec..7ad63c93c 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -399,7 +399,7 @@ func (c *Chain) produceBlock(now time.Time) error { return err } -func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequest, err error) { +func (c *Chain) produceBilling(br *types.BillingRequest) (_ *types.BillingRequest, err error) { // TODO(lambda): simplify the function if err = c.checkBillingRequest(br); err != nil { return @@ -439,8 +439,8 @@ func (c *Chain) produceTxBilling(br *types.BillingRequest) (_ *types.BillingRequ return } var ( - tc = types.NewTxContent(nc, br, accountAddress, receivers, fees, rewards) - tb = types.NewTxBilling(tc) + tc = types.NewBillingHeader(nc, br, accountAddress, receivers, fees, rewards) + tb = types.NewBilling(tc) ) if err = tb.Sign(privKey); err != nil { return diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index 08ce6426e..f24863b4b 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -101,7 +101,7 @@ func TestChain(t *testing.T) { t.Logf("Chain state: head = %s, height = %d, turn = %d, nextturnstart = %s, ismyturn = %t", chain.rt.getHead().getHeader(), chain.rt.getHead().getHeight(), chain.rt.nextTurn, chain.rt.chainInitTime.Add( - chain.rt.period*time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), + chain.rt.period * time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), chain.rt.isMyTurn()) // chain will receive blocks and tx @@ -113,7 +113,7 @@ func TestChain(t *testing.T) { tbs = append(tbs, chain.ms.pullTxs()...) for i := 0; i != 10; i++ { - tb, err := generateRandomAccountTxBilling() + tb, err := generateRandomAccountBilling() So(err, ShouldBeNil) tbs = append(tbs, tb) } @@ -141,9 +141,9 @@ func TestChain(t *testing.T) { So(err, ShouldNotBeNil) // receive txs - receivedTbs := make([]*pt.TxBilling, 9) + receivedTbs := make([]*pt.Billing, 9) for i := range receivedTbs { - tb, err := generateRandomAccountTxBilling() + tb, err := generateRandomAccountBilling() So(err, ShouldBeNil) receivedTbs[i] = tb err = chain.processTx(tb) diff --git a/blockproducer/metastate.go b/blockproducer/metastate.go index a38479004..33d9d9395 100644 --- a/blockproducer/metastate.go +++ b/blockproducer/metastate.go @@ -649,15 +649,15 @@ func (s *metaState) increaseNonce(addr proto.AccountAddress) (err error) { return } -func (s *metaState) applyBilling(tx *pt.TxBilling) (err error) { - for i, v := range tx.TxContent.Receivers { +func (s *metaState) applyBilling(tx *pt.Billing) (err error) { + for i, v := range tx.Receivers { // Create empty receiver account if not found s.loadOrStoreAccountObject(*v, &accountObject{Account: pt.Account{Address: *v}}) - if err = s.increaseAccountCovenantBalance(*v, tx.TxContent.Fees[i]); err != nil { + if err = s.increaseAccountCovenantBalance(*v, tx.Fees[i]); err != nil { return } - if err = s.increaseAccountStableBalance(*v, tx.TxContent.Rewards[i]); err != nil { + if err = s.increaseAccountStableBalance(*v, tx.Rewards[i]); err != nil { return } } @@ -668,7 +668,7 @@ func (s *metaState) applyTransaction(tx pi.Transaction) (err error) { switch t := tx.(type) { case *pt.Transfer: err = s.transferAccountStableBalance(t.Sender, t.Receiver, t.Amount) - case *pt.TxBilling: + case *pt.Billing: err = s.applyBilling(t) case *pt.BaseAccount: err = s.storeBaseAccount(t.Address, &accountObject{Account: t.Account}) diff --git a/blockproducer/metastate_test.go b/blockproducer/metastate_test.go index 5533befef..d98854c26 100644 --- a/blockproducer/metastate_test.go +++ b/blockproducer/metastate_test.go @@ -584,8 +584,8 @@ func TestMetaState(t *testing.T) { Amount: 0, }, } - t2 = &pt.TxBilling{ - TxContent: pt.TxContent{ + t2 = &pt.Billing{ + BillingHeader: pt.BillingHeader{ Nonce: 2, Producer: addr1, Receivers: []*proto.AccountAddress{&addr2}, @@ -716,8 +716,8 @@ func TestMetaState(t *testing.T) { Amount: 10, }, }, - &pt.TxBilling{ - TxContent: pt.TxContent{ + &pt.Billing{ + BillingHeader: pt.BillingHeader{ Nonce: 2, Producer: addr1, Receivers: []*proto.AccountAddress{&addr2}, @@ -725,8 +725,8 @@ func TestMetaState(t *testing.T) { Rewards: []uint64{1}, }, }, - &pt.TxBilling{ - TxContent: pt.TxContent{ + &pt.Billing{ + BillingHeader: pt.BillingHeader{ Nonce: 1, Producer: addr2, Receivers: []*proto.AccountAddress{&addr1}, diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 642e6b961..8f20c204a 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -42,7 +42,7 @@ type AdviseNewBlockResp struct { // AdviseTxBillingReq defines a request of the AdviseTxBilling RPC method. type AdviseTxBillingReq struct { proto.Envelope - TxBilling *types.TxBilling + TxBilling *types.Billing } // AdviseTxBillingResp defines a response of the AdviseTxBilling RPC method. @@ -139,7 +139,7 @@ func (s *ChainRPCService) AdviseNewBlock(req *AdviseNewBlockReq, resp *AdviseNew // AdviseBillingRequest is the RPC method to advise a new billing request to main chain. func (s *ChainRPCService) AdviseBillingRequest(req *ct.AdviseBillingReq, resp *ct.AdviseBillingResp) error { - response, err := s.chain.produceTxBilling(req.Req) + response, err := s.chain.produceBilling(req.Req) if err != nil { return err } diff --git a/blockproducer/types/block.go b/blockproducer/types/block.go index 41c09501c..6b0c9dcd4 100644 --- a/blockproducer/types/block.go +++ b/blockproducer/types/block.go @@ -63,10 +63,10 @@ type Block struct { Transactions []pi.Transaction } -// GetTxHashes returns all hashes of tx in block.{TxBillings, ...} +// GetTxHashes returns all hashes of tx in block.{Billings, ...} func (b *Block) GetTxHashes() []*hash.Hash { // TODO(lambda): when you add new tx type, you need to put new tx's hash in the slice - // get hashes in block.TxBillings + // get hashes in block.Transactions hs := make([]*hash.Hash, len(b.Transactions)) for i, v := range b.Transactions { @@ -101,7 +101,7 @@ func (b *Block) PackAndSignBlock(signer *asymmetric.PrivateKey) error { func enumType(t pi.TransactionType) (i pi.Transaction) { switch t { case pi.TransactionTypeBilling: - i = (*TxBilling)(nil) + i = (*Billing)(nil) case pi.TransactionTypeTransfer: i = (*Transfer)(nil) case pi.TransactionTypeBaseAccount: diff --git a/blockproducer/types/block_test.go b/blockproducer/types/block_test.go index 701698bd3..7c79d93cd 100644 --- a/blockproducer/types/block_test.go +++ b/blockproducer/types/block_test.go @@ -129,7 +129,7 @@ func TestBlock_PackAndSignBlock(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - tb, err := generateRandomTxBilling() + tb, err := generateRandomBilling() if err != nil { t.Fatalf("Unexpected error: %v", err) } diff --git a/blockproducer/types/transfer.go b/blockproducer/types/transfer.go index 342b6d945..ecb0e5e2f 100644 --- a/blockproducer/types/transfer.go +++ b/blockproducer/types/transfer.go @@ -43,7 +43,7 @@ type Transfer struct { Signature *asymmetric.Signature } -// Serialize serializes TxBilling using msgpack. +// Serialize serializes Billing using msgpack. func (t *Transfer) Serialize() (b []byte, err error) { var enc *bytes.Buffer if enc, err = utils.EncodeMsgPack(t); err != nil { @@ -53,7 +53,7 @@ func (t *Transfer) Serialize() (b []byte, err error) { return } -// Deserialize desrializes TxBilling using msgpack. +// Deserialize desrializes Billing using msgpack. func (t *Transfer) Deserialize(enc []byte) error { return utils.DecodeMsgPack(enc, t) } diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/txsqlchainbilling.go index 4366d5602..ab8251e2a 100644 --- a/blockproducer/types/txsqlchainbilling.go +++ b/blockproducer/types/txsqlchainbilling.go @@ -28,8 +28,8 @@ import ( //go:generate hsp -// TxContent defines the customer's billing and block rewards in transaction. -type TxContent struct { +// BillingHeader defines the customer's billing and block rewards in transaction. +type BillingHeader struct { // Transaction nonce Nonce pi.AccountNonce BillingRequest BillingRequest @@ -43,11 +43,11 @@ type TxContent struct { Rewards []uint64 } -// NewTxContent generates new TxContent. -func NewTxContent(seqID pi.AccountNonce, bReq *BillingRequest, producer proto.AccountAddress, receivers []*proto.AccountAddress, - fees []uint64, rewards []uint64) *TxContent { - return &TxContent{ - Nonce: seqID, +// NewBillingHeader generates new BillingHeader. +func NewBillingHeader(nonce pi.AccountNonce, bReq *BillingRequest, producer proto.AccountAddress, receivers []*proto.AccountAddress, + fees []uint64, rewards []uint64) *BillingHeader { + return &BillingHeader{ + Nonce: nonce, BillingRequest: *bReq, Producer: producer, Receivers: receivers, @@ -56,33 +56,23 @@ func NewTxContent(seqID pi.AccountNonce, bReq *BillingRequest, producer proto.Ac } } -// GetHash returns the hash of transaction. -func (tb *TxContent) GetHash() (*hash.Hash, error) { - b, err := tb.MarshalHash() - if err != nil { - return nil, err - } - h := hash.THashH(b) - return &h, nil -} - -// TxBilling is a type of tx, that is used to record sql chain billing and block rewards. -type TxBilling struct { - TxContent TxContent +// Billing is a type of tx, that is used to record sql chain billing and block rewards. +type Billing struct { + BillingHeader TxHash *hash.Hash Signee *asymmetric.PublicKey Signature *asymmetric.Signature } -// NewTxBilling generates a new TxBilling. -func NewTxBilling(txContent *TxContent) *TxBilling { - return &TxBilling{ - TxContent: *txContent, +// NewBilling generates a new Billing. +func NewBilling(header *BillingHeader) *Billing { + return &Billing{ + BillingHeader: *header, } } -// Serialize serializes TxBilling using msgpack. -func (tb *TxBilling) Serialize() (b []byte, err error) { +// Serialize serializes Billing using msgpack. +func (tb *Billing) Serialize() (b []byte, err error) { var enc *bytes.Buffer if enc, err = utils.EncodeMsgPack(tb); err != nil { return @@ -91,34 +81,34 @@ func (tb *TxBilling) Serialize() (b []byte, err error) { return } -// Deserialize desrializes TxBilling using msgpack. -func (tb *TxBilling) Deserialize(enc []byte) error { +// Deserialize desrializes Billing using msgpack. +func (tb *Billing) Deserialize(enc []byte) error { return utils.DecodeMsgPack(enc, tb) } // GetAccountAddress implements interfaces/Transaction.GetAccountAddress. -func (tb *TxBilling) GetAccountAddress() proto.AccountAddress { - return tb.TxContent.Producer +func (tb *Billing) GetAccountAddress() proto.AccountAddress { + return tb.Producer } // GetAccountNonce implements interfaces/Transaction.GetAccountNonce. -func (tb *TxBilling) GetAccountNonce() pi.AccountNonce { - return tb.TxContent.Nonce +func (tb *Billing) GetAccountNonce() pi.AccountNonce { + return tb.Nonce } // GetHash implements interfaces/Transaction.GetHash. -func (tb *TxBilling) GetHash() hash.Hash { +func (tb *Billing) GetHash() hash.Hash { return *tb.TxHash } // GetTransactionType implements interfaces/Transaction.GetTransactionType. -func (tb *TxBilling) GetTransactionType() pi.TransactionType { +func (tb *Billing) GetTransactionType() pi.TransactionType { return pi.TransactionTypeBilling } -// Sign computes tx of TxContent and signs it. -func (tb *TxBilling) Sign(signer *asymmetric.PrivateKey) error { - enc, err := tb.TxContent.MarshalHash() +// Sign computes tx of BillingHeader and signs it. +func (tb *Billing) Sign(signer *asymmetric.PrivateKey) error { + enc, err := tb.BillingHeader.MarshalHash() if err != nil { return err } @@ -135,10 +125,10 @@ func (tb *TxBilling) Sign(signer *asymmetric.PrivateKey) error { return nil } -// Verify verifies the signature of TxBilling. -func (tb *TxBilling) Verify() (err error) { +// Verify verifies the signature of Billing. +func (tb *Billing) Verify() (err error) { var enc []byte - if enc, err = tb.TxContent.MarshalHash(); err != nil { + if enc, err = tb.BillingHeader.MarshalHash(); err != nil { return } else if h := hash.THashH(enc); !tb.TxHash.IsEqual(&h) { err = ErrSignVerification @@ -151,10 +141,10 @@ func (tb *TxBilling) Verify() (err error) { } // GetDatabaseID gets the database ID. -func (tb *TxBilling) GetDatabaseID() *proto.DatabaseID { - return &tb.TxContent.BillingRequest.Header.DatabaseID +func (tb *Billing) GetDatabaseID() *proto.DatabaseID { + return &tb.BillingRequest.Header.DatabaseID } func init() { - pi.RegisterTransaction(pi.TransactionTypeBilling, (*TxBilling)(nil)) + pi.RegisterTransaction(pi.TransactionTypeBilling, (*Billing)(nil)) } diff --git a/blockproducer/types/txsqlchainbilling_gen.go b/blockproducer/types/txsqlchainbilling_gen.go index 3fc03f635..1fefcee9c 100644 --- a/blockproducer/types/txsqlchainbilling_gen.go +++ b/blockproducer/types/txsqlchainbilling_gen.go @@ -7,7 +7,7 @@ import ( ) // MarshalHash marshals for hash -func (z *TxBilling) MarshalHash() (o []byte, err error) { +func (z *Billing) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) // map header, size 4 @@ -42,7 +42,7 @@ func (z *TxBilling) MarshalHash() (o []byte, err error) { } } o = append(o, 0x84) - if oTemp, err := z.TxContent.MarshalHash(); err != nil { + if oTemp, err := z.BillingHeader.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) @@ -51,7 +51,7 @@ func (z *TxBilling) MarshalHash() (o []byte, err error) { } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *TxBilling) Msgsize() (s int) { +func (z *Billing) Msgsize() (s int) { s = 1 + 7 if z.Signee == nil { s += hsp.NilSize @@ -70,12 +70,12 @@ func (z *TxBilling) Msgsize() (s int) { } else { s += z.TxHash.Msgsize() } - s += 10 + z.TxContent.Msgsize() + s += 14 + z.BillingHeader.Msgsize() return } // MarshalHash marshals for hash -func (z *TxContent) MarshalHash() (o []byte, err error) { +func (z *BillingHeader) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) // map header, size 6 @@ -124,7 +124,7 @@ func (z *TxContent) MarshalHash() (o []byte, err error) { } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *TxContent) Msgsize() (s int) { +func (z *BillingHeader) Msgsize() (s int) { s = 1 + 15 + z.BillingRequest.Msgsize() + 10 + hsp.ArrayHeaderSize for za0001 := range z.Receivers { if z.Receivers[za0001] == nil { diff --git a/blockproducer/types/txsqlchainbilling_gen_test.go b/blockproducer/types/txsqlchainbilling_gen_test.go index add50d6f9..845a15213 100644 --- a/blockproducer/types/txsqlchainbilling_gen_test.go +++ b/blockproducer/types/txsqlchainbilling_gen_test.go @@ -9,8 +9,8 @@ import ( "testing" ) -func TestMarshalHashTxBilling(t *testing.T) { - v := TxBilling{} +func TestMarshalHashBilling(t *testing.T) { + v := Billing{} binary.Read(rand.Reader, binary.BigEndian, &v) bts1, err := v.MarshalHash() if err != nil { @@ -25,8 +25,8 @@ func TestMarshalHashTxBilling(t *testing.T) { } } -func BenchmarkMarshalHashTxBilling(b *testing.B) { - v := TxBilling{} +func BenchmarkMarshalHashBilling(b *testing.B) { + v := Billing{} b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { @@ -34,8 +34,8 @@ func BenchmarkMarshalHashTxBilling(b *testing.B) { } } -func BenchmarkAppendMsgTxBilling(b *testing.B) { - v := TxBilling{} +func BenchmarkAppendMsgBilling(b *testing.B) { + v := Billing{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalHash() b.SetBytes(int64(len(bts))) @@ -46,8 +46,8 @@ func BenchmarkAppendMsgTxBilling(b *testing.B) { } } -func TestMarshalHashTxContent(t *testing.T) { - v := TxContent{} +func TestMarshalHashBillingHeader(t *testing.T) { + v := BillingHeader{} binary.Read(rand.Reader, binary.BigEndian, &v) bts1, err := v.MarshalHash() if err != nil { @@ -62,8 +62,8 @@ func TestMarshalHashTxContent(t *testing.T) { } } -func BenchmarkMarshalHashTxContent(b *testing.B) { - v := TxContent{} +func BenchmarkMarshalHashBillingHeader(b *testing.B) { + v := BillingHeader{} b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { @@ -71,8 +71,8 @@ func BenchmarkMarshalHashTxContent(b *testing.B) { } } -func BenchmarkAppendMsgTxContent(b *testing.B) { - v := TxContent{} +func BenchmarkAppendMsgBillingHeader(b *testing.B) { + v := BillingHeader{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalHash() b.SetBytes(int64(len(bts))) diff --git a/blockproducer/types/txsqlchainbilling_test.go b/blockproducer/types/txsqlchainbilling_test.go index 6b1ef34ff..3d1dda2d3 100644 --- a/blockproducer/types/txsqlchainbilling_test.go +++ b/blockproducer/types/txsqlchainbilling_test.go @@ -25,26 +25,8 @@ import ( "github.com/CovenantSQL/CovenantSQL/utils" ) -func TestTxContent_GetHashAndGetType(t *testing.T) { - tc, err := generateRandomTxContent() - if err != nil { - t.Fatalf("Unexpeted error: %v", err) - } - - h, err := tc.GetHash() - if err != nil { - t.Fatalf("Unexpeted error: %v", err) - } - - enc, err := tc.MarshalHash() - encHash := hash.THashH(enc) - if !h.IsEqual(&encHash) { - t.Fatalf("Hash not match: \n\tv1=%v,\n\tv2=%v", h, encHash) - } -} - -func TestTxContent_MarshalUnmarshalBinary(t *testing.T) { - tc, err := generateRandomTxContent() +func TestBillingHeader_MarshalUnmarshalBinary(t *testing.T) { + tc, err := generateRandomBillingHeader() if err != nil { t.Fatalf("Unexpeted error: %v", err) } @@ -54,7 +36,7 @@ func TestTxContent_MarshalUnmarshalBinary(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } - dec := &TxContent{} + dec := &BillingHeader{} err = utils.DecodeMsgPack(enc.Bytes(), dec) if err != nil { t.Fatalf("Unexpeted error: %v", err) @@ -82,8 +64,8 @@ func TestTxContent_MarshalUnmarshalBinary(t *testing.T) { } } -func TestTxBilling_SerializeDeserialize(t *testing.T) { - tb, err := generateRandomTxBilling() +func TestBilling_SerializeDeserialize(t *testing.T) { + tb, err := generateRandomBilling() if err != nil { t.Fatalf("Unexpeted error: %v", err) } @@ -93,7 +75,7 @@ func TestTxBilling_SerializeDeserialize(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } - dec := TxBilling{} + dec := Billing{} err = dec.Deserialize(enc) if err != nil { t.Fatalf("Unexpeted error: %v", err) @@ -110,8 +92,8 @@ func TestTxBilling_SerializeDeserialize(t *testing.T) { } } -func TestTxBilling_PackAndSignTx(t *testing.T) { - tb, err := generateRandomTxBilling() +func TestBilling_PackAndSignTx(t *testing.T) { + tb, err := generateRandomBilling() if err != nil { t.Fatalf("Unexpeted error: %v", err) } @@ -121,7 +103,7 @@ func TestTxBilling_PackAndSignTx(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } tb.Sign(priv) - enc, err := tb.TxContent.MarshalHash() + enc, err := tb.BillingHeader.MarshalHash() if err != nil { t.Fatalf("Unexpeted error: %v", err) } diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index 9431b394b..86d1ae063 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -140,7 +140,7 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) } for i, n := 0, rand.Intn(10)+10; i < n; i++ { - tb, err := generateRandomTxBilling() + tb, err := generateRandomBilling() if err != nil { return nil, err } @@ -187,7 +187,7 @@ func generateRandomBillingRequest() (req *BillingRequest, err error) { return } -func generateRandomTxContent() (tc *TxContent, err error) { +func generateRandomBillingHeader() (tc *BillingHeader, err error) { var req *BillingRequest if req, err = generateRandomBillingRequest(); err != nil { return @@ -214,12 +214,12 @@ func generateRandomTxContent() (tc *TxContent, err error) { } producer := proto.AccountAddress(generateRandomHash()) - tc = NewTxContent(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) + tc = NewBillingHeader(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) return tc, nil } -func generateRandomTxBilling() (*TxBilling, error) { - txContent, err := generateRandomTxContent() +func generateRandomBilling() (*Billing, error) { + header, err := generateRandomBillingHeader() if err != nil { return nil, err } @@ -230,7 +230,7 @@ func generateRandomTxBilling() (*TxBilling, error) { return nil, err } - txBilling := NewTxBilling(txContent) + txBilling := NewBilling(header) txBilling.TxHash = &txHash txBilling.Signee = pub txBilling.Signature = sign diff --git a/blockproducer/xxx_test.go b/blockproducer/xxx_test.go index 96ae8c16b..d7702db46 100644 --- a/blockproducer/xxx_test.go +++ b/blockproducer/xxx_test.go @@ -107,7 +107,7 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *pt.Block, err err if !isGenesis { for i, n := 0, rand.Intn(10)+10; i < n; i++ { - ba, tb, err := generateRandomTxBillingAndBaseAccount() + ba, tb, err := generateRandomBillingAndBaseAccount() if err != nil { return nil, err } @@ -232,7 +232,7 @@ func generateRandomBillingRequest() (*pt.BillingRequest, error) { return &req, nil } -func generateRandomTxContent() (tc *pt.TxContent, err error) { +func generateRandomBillingHeader() (tc *pt.BillingHeader, err error) { var req *pt.BillingRequest if req, err = generateRandomBillingRequest(); err != nil { return @@ -259,20 +259,20 @@ func generateRandomTxContent() (tc *pt.TxContent, err error) { } producer := proto.AccountAddress(generateRandomHash()) - tc = pt.NewTxContent(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) + tc = pt.NewBillingHeader(pi.AccountNonce(rand.Uint32()), req, producer, receivers, fees, rewards) return tc, nil } -func generateRandomTxBillingAndBaseAccount() (*pt.BaseAccount, *pt.TxBilling, error) { - txContent, err := generateRandomTxContent() +func generateRandomBillingAndBaseAccount() (*pt.BaseAccount, *pt.Billing, error) { + header, err := generateRandomBillingHeader() if err != nil { return nil, nil, err } priv, _, err := asymmetric.GenSecp256k1KeyPair() - txContent.Producer, _ = crypto.PubKeyHash(priv.PubKey()) + header.Producer, _ = crypto.PubKeyHash(priv.PubKey()) - txBilling := &pt.TxBilling{ - TxContent: *txContent, + txBilling := &pt.Billing{ + BillingHeader: *header, } if err := txBilling.Sign(priv); err != nil { @@ -281,7 +281,7 @@ func generateRandomTxBillingAndBaseAccount() (*pt.BaseAccount, *pt.TxBilling, er txBaseAccount := &pt.BaseAccount{ Account: pt.Account{ - Address: txContent.Producer, + Address: header.Producer, StableCoinBalance: testInitBalance, CovenantCoinBalance: testInitBalance, }, @@ -294,16 +294,16 @@ func generateRandomTxBillingAndBaseAccount() (*pt.BaseAccount, *pt.TxBilling, er return txBaseAccount, txBilling, nil } -func generateRandomAccountTxBilling() (*pt.TxBilling, error) { - txContent, err := generateRandomTxContent() +func generateRandomAccountBilling() (*pt.Billing, error) { + header, err := generateRandomBillingHeader() if err != nil { return nil, err } - txContent.Producer = testAddress1 + header.Producer = testAddress1 testAddress1Nonce++ - txContent.Nonce = testAddress1Nonce - txBilling := &pt.TxBilling{ - TxContent: *txContent, + header.Nonce = testAddress1Nonce + txBilling := &pt.Billing{ + BillingHeader: *header, } if err := txBilling.Sign(testPrivKey); err != nil { From 4663499999351e440aec18f6f9e63d7b87d27f2f Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 16:24:20 +0800 Subject: [PATCH 26/38] Rename txsqlchainbilling to billing filename --- blockproducer/types/{txsqlchainbilling.go => billing.go} | 0 blockproducer/types/{txsqlchainbilling_gen.go => billing_gen.go} | 0 .../types/{txsqlchainbilling_gen_test.go => billing_gen_test.go} | 0 .../types/{txsqlchainbilling_test.go => billing_test.go} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename blockproducer/types/{txsqlchainbilling.go => billing.go} (100%) rename blockproducer/types/{txsqlchainbilling_gen.go => billing_gen.go} (100%) rename blockproducer/types/{txsqlchainbilling_gen_test.go => billing_gen_test.go} (100%) rename blockproducer/types/{txsqlchainbilling_test.go => billing_test.go} (100%) diff --git a/blockproducer/types/txsqlchainbilling.go b/blockproducer/types/billing.go similarity index 100% rename from blockproducer/types/txsqlchainbilling.go rename to blockproducer/types/billing.go diff --git a/blockproducer/types/txsqlchainbilling_gen.go b/blockproducer/types/billing_gen.go similarity index 100% rename from blockproducer/types/txsqlchainbilling_gen.go rename to blockproducer/types/billing_gen.go diff --git a/blockproducer/types/txsqlchainbilling_gen_test.go b/blockproducer/types/billing_gen_test.go similarity index 100% rename from blockproducer/types/txsqlchainbilling_gen_test.go rename to blockproducer/types/billing_gen_test.go diff --git a/blockproducer/types/txsqlchainbilling_test.go b/blockproducer/types/billing_test.go similarity index 100% rename from blockproducer/types/txsqlchainbilling_test.go rename to blockproducer/types/billing_test.go From 14e99e805252544b6ca9bb217517b0a6eb289c1e Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 16:53:02 +0800 Subject: [PATCH 27/38] Refactor transaction using DefaultHashSignVerifierImpl --- blockproducer/chain_test.go | 2 +- blockproducer/types/billing.go | 56 ++++++---------------------- blockproducer/types/billing_gen.go | 58 ++++------------------------- blockproducer/types/billing_test.go | 4 +- blockproducer/types/transfer.go | 34 ++--------------- blockproducer/types/transfer_gen.go | 44 +++------------------- blockproducer/types/xxx_test.go | 11 ++---- 7 files changed, 36 insertions(+), 173 deletions(-) diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index f24863b4b..b4207f347 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -101,7 +101,7 @@ func TestChain(t *testing.T) { t.Logf("Chain state: head = %s, height = %d, turn = %d, nextturnstart = %s, ismyturn = %t", chain.rt.getHead().getHeader(), chain.rt.getHead().getHeight(), chain.rt.nextTurn, chain.rt.chainInitTime.Add( - chain.rt.period * time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), + chain.rt.period*time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), chain.rt.isMyTurn()) // chain will receive blocks and tx diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing.go index ab8251e2a..77923e736 100644 --- a/blockproducer/types/billing.go +++ b/blockproducer/types/billing.go @@ -21,7 +21,6 @@ import ( pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" - "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/utils" ) @@ -59,9 +58,7 @@ func NewBillingHeader(nonce pi.AccountNonce, bReq *BillingRequest, producer prot // Billing is a type of tx, that is used to record sql chain billing and block rewards. type Billing struct { BillingHeader - TxHash *hash.Hash - Signee *asymmetric.PublicKey - Signature *asymmetric.Signature + DefaultHashSignVerifierImpl } // NewBilling generates a new Billing. @@ -81,11 +78,21 @@ func (tb *Billing) Serialize() (b []byte, err error) { return } -// Deserialize desrializes Billing using msgpack. +// Deserialize deserialize Billing using msgpack. func (tb *Billing) Deserialize(enc []byte) error { return utils.DecodeMsgPack(enc, tb) } +// Sign implements interfaces/Transaction.Sign. +func (tb *Billing) Sign(signer *asymmetric.PrivateKey) (err error) { + return tb.DefaultHashSignVerifierImpl.Sign(&tb.BillingHeader, signer) +} + +// Verify implements interfaces/Transaction.Verify. +func (tb *Billing) Verify() error { + return tb.DefaultHashSignVerifierImpl.Verify(&tb.BillingHeader) +} + // GetAccountAddress implements interfaces/Transaction.GetAccountAddress. func (tb *Billing) GetAccountAddress() proto.AccountAddress { return tb.Producer @@ -96,50 +103,11 @@ func (tb *Billing) GetAccountNonce() pi.AccountNonce { return tb.Nonce } -// GetHash implements interfaces/Transaction.GetHash. -func (tb *Billing) GetHash() hash.Hash { - return *tb.TxHash -} - // GetTransactionType implements interfaces/Transaction.GetTransactionType. func (tb *Billing) GetTransactionType() pi.TransactionType { return pi.TransactionTypeBilling } -// Sign computes tx of BillingHeader and signs it. -func (tb *Billing) Sign(signer *asymmetric.PrivateKey) error { - enc, err := tb.BillingHeader.MarshalHash() - if err != nil { - return err - } - h := hash.THashH(enc) - tb.TxHash = &h - tb.Signee = signer.PubKey() - - signature, err := signer.Sign(h[:]) - if err != nil { - return err - } - tb.Signature = signature - - return nil -} - -// Verify verifies the signature of Billing. -func (tb *Billing) Verify() (err error) { - var enc []byte - if enc, err = tb.BillingHeader.MarshalHash(); err != nil { - return - } else if h := hash.THashH(enc); !tb.TxHash.IsEqual(&h) { - err = ErrSignVerification - return - } else if !tb.Signature.Verify(h[:], tb.Signee) { - err = ErrSignVerification - return - } - return -} - // GetDatabaseID gets the database ID. func (tb *Billing) GetDatabaseID() *proto.DatabaseID { return &tb.BillingRequest.Header.DatabaseID diff --git a/blockproducer/types/billing_gen.go b/blockproducer/types/billing_gen.go index 1fefcee9c..0e45c16d9 100644 --- a/blockproducer/types/billing_gen.go +++ b/blockproducer/types/billing_gen.go @@ -10,39 +10,15 @@ import ( func (z *Billing) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 4 - o = append(o, 0x84, 0x84) - if z.Signee == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signee.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x84) - if z.Signature == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signature.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x84) - if z.TxHash == nil { - o = hsp.AppendNil(o) + // map header, size 2 + o = append(o, 0x82, 0x82) + if oTemp, err := z.BillingHeader.MarshalHash(); err != nil { + return nil, err } else { - if oTemp, err := z.TxHash.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } + o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x84) - if oTemp, err := z.BillingHeader.MarshalHash(); err != nil { + o = append(o, 0x82) + if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) @@ -52,25 +28,7 @@ func (z *Billing) MarshalHash() (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Billing) Msgsize() (s int) { - s = 1 + 7 - if z.Signee == nil { - s += hsp.NilSize - } else { - s += z.Signee.Msgsize() - } - s += 10 - if z.Signature == nil { - s += hsp.NilSize - } else { - s += z.Signature.Msgsize() - } - s += 7 - if z.TxHash == nil { - s += hsp.NilSize - } else { - s += z.TxHash.Msgsize() - } - s += 14 + z.BillingHeader.Msgsize() + s = 1 + 14 + z.BillingHeader.Msgsize() + 28 + z.DefaultHashSignVerifierImpl.Msgsize() return } diff --git a/blockproducer/types/billing_test.go b/blockproducer/types/billing_test.go index 3d1dda2d3..011035bef 100644 --- a/blockproducer/types/billing_test.go +++ b/blockproducer/types/billing_test.go @@ -87,8 +87,8 @@ func TestBilling_SerializeDeserialize(t *testing.T) { if !tb.Signee.IsEqual(dec.Signee) { t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.Signee, tb.Signee) } - if !tb.TxHash.IsEqual(dec.TxHash) { - t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.TxHash, tb.TxHash) + if !tb.Hash.IsEqual(&dec.Hash) { + t.Fatalf("Value not match: \n\tv1=%v\n\tv2=%v", tb.Hash, tb.Hash) } } diff --git a/blockproducer/types/transfer.go b/blockproducer/types/transfer.go index ecb0e5e2f..6ea90abb7 100644 --- a/blockproducer/types/transfer.go +++ b/blockproducer/types/transfer.go @@ -21,7 +21,6 @@ import ( pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" - "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/utils" ) @@ -38,9 +37,7 @@ type TransferHeader struct { // Transfer defines the transfer transaction. type Transfer struct { TransferHeader - HeaderHash hash.Hash - Signee *asymmetric.PublicKey - Signature *asymmetric.Signature + DefaultHashSignVerifierImpl } // Serialize serializes Billing using msgpack. @@ -68,11 +65,6 @@ func (t *Transfer) GetAccountNonce() pi.AccountNonce { return t.Nonce } -// GetHash implements interfaces/Transaction.GetHash. -func (t *Transfer) GetHash() hash.Hash { - return t.HeaderHash -} - // GetTransactionType implements interfaces/Transaction.GetTransactionType. func (t *Transfer) GetTransactionType() pi.TransactionType { return pi.TransactionTypeTransfer @@ -80,32 +72,12 @@ func (t *Transfer) GetTransactionType() pi.TransactionType { // Sign implements interfaces/Transaction.Sign. func (t *Transfer) Sign(signer *asymmetric.PrivateKey) (err error) { - var enc []byte - if enc, err = t.TransferHeader.MarshalHash(); err != nil { - return - } - var h = hash.THashH(enc) - if t.Signature, err = signer.Sign(h[:]); err != nil { - return - } - t.HeaderHash = h - t.Signee = signer.PubKey() - return + return t.DefaultHashSignVerifierImpl.Sign(&t.TransferHeader, signer) } // Verify implements interfaces/Transaction.Verify. func (t *Transfer) Verify() (err error) { - var enc []byte - if enc, err = t.TransferHeader.MarshalHash(); err != nil { - return - } else if h := hash.THashH(enc); !t.HeaderHash.IsEqual(&h) { - err = ErrSignVerification - return - } else if !t.Signature.Verify(h[:], t.Signee) { - err = ErrSignVerification - return - } - return + return t.DefaultHashSignVerifierImpl.Verify(&t.TransferHeader) } func init() { diff --git a/blockproducer/types/transfer_gen.go b/blockproducer/types/transfer_gen.go index 9091a1e62..87c282d1d 100644 --- a/blockproducer/types/transfer_gen.go +++ b/blockproducer/types/transfer_gen.go @@ -10,35 +10,15 @@ import ( func (z *Transfer) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 4 - o = append(o, 0x84, 0x84) - if z.Signee == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signee.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x84) - if z.Signature == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Signature.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - o = append(o, 0x84) - if oTemp, err := z.TransferHeader.MarshalHash(); err != nil { + // map header, size 2 + o = append(o, 0x82, 0x82) + if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x84) - if oTemp, err := z.HeaderHash.MarshalHash(); err != nil { + o = append(o, 0x82) + if oTemp, err := z.TransferHeader.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) @@ -48,19 +28,7 @@ func (z *Transfer) MarshalHash() (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Transfer) Msgsize() (s int) { - s = 1 + 7 - if z.Signee == nil { - s += hsp.NilSize - } else { - s += z.Signee.Msgsize() - } - s += 10 - if z.Signature == nil { - s += hsp.NilSize - } else { - s += z.Signature.Msgsize() - } - s += 15 + z.TransferHeader.Msgsize() + 11 + z.HeaderHash.Msgsize() + s = 1 + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 15 + z.TransferHeader.Msgsize() return } diff --git a/blockproducer/types/xxx_test.go b/blockproducer/types/xxx_test.go index 86d1ae063..31bd5a7ae 100644 --- a/blockproducer/types/xxx_test.go +++ b/blockproducer/types/xxx_test.go @@ -223,17 +223,14 @@ func generateRandomBilling() (*Billing, error) { if err != nil { return nil, err } - txHash := generateRandomHash() - priv, pub, err := asymmetric.GenSecp256k1KeyPair() - sign, err := priv.Sign(txHash[:]) + priv, _, err := asymmetric.GenSecp256k1KeyPair() if err != nil { return nil, err } - txBilling := NewBilling(header) - txBilling.TxHash = &txHash - txBilling.Signee = pub - txBilling.Signature = sign + if err := txBilling.Sign(priv); err != nil { + return nil, err + } return txBilling, nil } From a6f1da98880fbe3145ba9ef0c1d6da7986b93f99 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 19:43:23 +0800 Subject: [PATCH 28/38] Complete transaction type awareness encode/decoder --- blockproducer/interfaces/mixins.go | 12 +++ blockproducer/interfaces/nil_tx.go | 83 +++++++++++++++++++ blockproducer/interfaces/transaction.go | 4 +- .../interfaces/transaction_wrapper.go | 70 +++++++++++++++- blockproducer/metastate.go | 3 + blockproducer/metastate_test.go | 74 ++++++++--------- blockproducer/types/baseaccount.go | 19 +++-- blockproducer/types/baseaccount_gen.go | 4 +- blockproducer/types/billing.go | 9 +- blockproducer/types/billing_gen.go | 14 +++- blockproducer/types/block.go | 49 ++--------- blockproducer/types/block_test.go | 77 +++++++++-------- blockproducer/types/createdb.go | 16 ++-- blockproducer/types/createdb_gen.go | 14 +++- blockproducer/types/msgpack_test.go | 24 +++++- blockproducer/types/transfer.go | 18 ++-- blockproducer/types/transfer_gen.go | 14 +++- blockproducer/xxx_test.go | 32 ++++--- cmd/cql-faucet/verifier.go | 6 +- cmd/cql/util.go | 1 - cmd/cqld/bootstrap.go | 7 +- 21 files changed, 356 insertions(+), 194 deletions(-) create mode 100644 blockproducer/interfaces/nil_tx.go diff --git a/blockproducer/interfaces/mixins.go b/blockproducer/interfaces/mixins.go index edf2965fb..26cce6346 100644 --- a/blockproducer/interfaces/mixins.go +++ b/blockproducer/interfaces/mixins.go @@ -23,6 +23,11 @@ type TransactionTypeMixin struct { TxType TransactionType } +// ContainsTransactionTypeMixin interface defines interface to detect transaction type mixin. +type ContainsTransactionTypeMixin interface { + SetTransactionType(TransactionType) +} + // GetTransactionType implements Transaction.GetTransactionType. func (m *TransactionTypeMixin) GetTransactionType() TransactionType { return m.TxType @@ -32,3 +37,10 @@ func (m *TransactionTypeMixin) GetTransactionType() TransactionType { func (m *TransactionTypeMixin) SetTransactionType(t TransactionType) { m.TxType = t } + +// NewTransactionTypeMixin returns new instance. +func NewTransactionTypeMixin(txType TransactionType) *TransactionTypeMixin { + return &TransactionTypeMixin{ + TxType: txType, + } +} diff --git a/blockproducer/interfaces/nil_tx.go b/blockproducer/interfaces/nil_tx.go new file mode 100644 index 000000000..85d19fec1 --- /dev/null +++ b/blockproducer/interfaces/nil_tx.go @@ -0,0 +1,83 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package interfaces + +import ( + "bytes" + + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" +) + +// NilTx defines empty transaction for transaction decode failure +type NilTx struct { + TransactionTypeMixin +} + +// NewNilTx returns new instance. +func NewNilTx() *NilTx { + return &NilTx{ + TransactionTypeMixin: *NewTransactionTypeMixin(TransactionTypeNumber), + } +} + +// Serialize serializes NilTx using msgpack. +func (t *NilTx) Serialize() (b []byte, err error) { + var enc *bytes.Buffer + if enc, err = utils.EncodeMsgPack(t); err != nil { + return + } + b = enc.Bytes() + return +} + +// Deserialize desrializes NilTx using msgpack. +func (t *NilTx) Deserialize(enc []byte) error { + return utils.DecodeMsgPack(enc, t) +} + +// GetAccountAddress implements Transaction.GetAccountAddress. +func (t *NilTx) GetAccountAddress() (addr proto.AccountAddress) { + return +} + +// GetAccountNonce implements Transaction.GetAccountNonce. +func (t *NilTx) GetAccountNonce() (nonce AccountNonce) { + // BaseAccount nonce is not counted, always return 0. + return +} + +// GetHash implements Transaction.GetHash. +func (t *NilTx) GetHash() (h hash.Hash) { + return +} + +// Sign implements interfaces/Transaction.Sign. +func (t *NilTx) Sign(signer *asymmetric.PrivateKey) (err error) { + return +} + +// Verify implements interfaces/Transaction.Verify. +func (t *NilTx) Verify() (err error) { + return +} + +func init() { + RegisterTransaction(TransactionTypeNumber, (*NilTx)(nil)) +} diff --git a/blockproducer/interfaces/transaction.go b/blockproducer/interfaces/transaction.go index 608b7bffd..2a1e9ca49 100644 --- a/blockproducer/interfaces/transaction.go +++ b/blockproducer/interfaces/transaction.go @@ -61,8 +61,8 @@ const ( TransactionTypeDeleteDatabaseUser // TransactionTypeBaseAccount defines base account transaction type. TransactionTypeBaseAccount - // TransactionTypeCreataDatabase defines database creation transaction type. - TransactionTypeCreataDatabase + // TransactionTypeCreateDatabase defines database creation transaction type. + TransactionTypeCreateDatabase // TransactionTypeNumber defines transaction types number. TransactionTypeNumber ) diff --git a/blockproducer/interfaces/transaction_wrapper.go b/blockproducer/interfaces/transaction_wrapper.go index 96c75886e..6c7d3748d 100644 --- a/blockproducer/interfaces/transaction_wrapper.go +++ b/blockproducer/interfaces/transaction_wrapper.go @@ -27,6 +27,7 @@ import ( const ( // msgpack constants, copied from go/codec/msgpack.go + valueTypeMap = 9 valueTypeArray = 10 ) @@ -62,6 +63,11 @@ type TransactionWrapper struct { Transaction } +// Unwrap returns transaction within wrapper. +func (w *TransactionWrapper) Unwrap() Transaction { + return w.Transaction +} + // CodecEncodeSelf implements codec.Selfer interface. func (w *TransactionWrapper) CodecEncodeSelf(e *codec.Encoder) { helperEncoder, encDriver := codec.GenHelperEncoder(e) @@ -71,6 +77,14 @@ func (w *TransactionWrapper) CodecEncodeSelf(e *codec.Encoder) { return } + // if the transaction is supports type transaction mixin + var rawTx interface{} = w.Transaction + if _, ok := rawTx.(ContainsTransactionTypeMixin); ok { + // encode directly + helperEncoder.EncFallback(w.Transaction) + return + } + // translate wrapper to two fields array wrapped by map encDriver.WriteArrayStart(2) encDriver.WriteArrayElem() @@ -82,15 +96,29 @@ func (w *TransactionWrapper) CodecEncodeSelf(e *codec.Encoder) { // CodecDecodeSelf implements codec.Selfer interface. func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder) { - helperDecoder, decodeDriver := codec.GenHelperDecoder(d) + _, decodeDriver := codec.GenHelperDecoder(d) // clear fields w.Transaction = nil - - if ct := decodeDriver.ContainerType(); ct != valueTypeArray { + ct := decodeDriver.ContainerType() + + switch ct { + case valueTypeArray: + w.decodeFromWrapper(d) + case valueTypeMap: + w.decodeFromRaw(d) + default: panic(errors.Wrapf(ErrInvalidContainerType, "type %v applied", ct)) } + if w.Transaction == nil { + // set nil transaction as placeholder to avoid nil pointer call + w.Transaction = NewNilTx() + } +} + +func (w *TransactionWrapper) decodeFromWrapper(d *codec.Decoder) { + helperDecoder, decodeDriver := codec.GenHelperDecoder(d) containerLen := decodeDriver.ReadArrayStart() for i := 0; i < containerLen; i++ { @@ -125,6 +153,35 @@ func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder) { decodeDriver.ReadArrayEnd() } +func (w *TransactionWrapper) decodeFromRaw(d *codec.Decoder) { + helperDecoder, _ := codec.GenHelperDecoder(d) + + // read all container as raw + rawBytes := helperDecoder.DecRaw() + + var typeDetector TransactionTypeMixin + typeDetector.SetTransactionType(TransactionTypeNumber) + + var err error + if err = utils.DecodeMsgPack(rawBytes, &typeDetector); err != nil { + panic(err) + } + + txType := typeDetector.GetTransactionType() + + if txType == TransactionTypeNumber { + panic(ErrInvalidTransactionType) + } + + if w.Transaction, err = NewTransaction(txType); err != nil { + panic(err) + } + + if err = utils.DecodeMsgPack(rawBytes, w.Transaction); err != nil { + panic(err) + } +} + // RegisterTransaction registers transaction type to wrapper. func RegisterTransaction(t TransactionType, tx Transaction) { if tx == nil { @@ -164,7 +221,12 @@ func NewTransaction(t TransactionType) (tx Transaction, err error) { rv = reflect.New(rt).Elem() } - tx = rv.Interface().(Transaction) + rawTx := rv.Interface() + tx = rawTx.(Transaction) + + if txTypeAwareness, ok := rawTx.(ContainsTransactionTypeMixin); ok { + txTypeAwareness.SetTransactionType(t) + } return } diff --git a/blockproducer/metastate.go b/blockproducer/metastate.go index 33d9d9395..cdeb5fdaa 100644 --- a/blockproducer/metastate.go +++ b/blockproducer/metastate.go @@ -672,6 +672,9 @@ func (s *metaState) applyTransaction(tx pi.Transaction) (err error) { err = s.applyBilling(t) case *pt.BaseAccount: err = s.storeBaseAccount(t.Address, &accountObject{Account: t.Account}) + case *pi.TransactionWrapper: + // call again using unwrapped transaction + err = s.applyTransaction(t.Unwrap()) default: err = ErrUnknownTransactionType } diff --git a/blockproducer/metastate_test.go b/blockproducer/metastate_test.go index d98854c26..e27cc13af 100644 --- a/blockproducer/metastate_test.go +++ b/blockproducer/metastate_test.go @@ -571,28 +571,26 @@ func TestMetaState(t *testing.T) { Convey("When transactions are added", func() { var ( n pi.AccountNonce - t0 = &pt.BaseAccount{ - Account: pt.Account{ - Address: addr1, - }, - } - t1 = &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + t0 = pt.NewBaseAccount(&pt.Account{ + Address: addr1, + }) + t1 = pt.NewTransfer( + &pt.TransferHeader{ Sender: addr1, Receiver: addr2, Nonce: 1, Amount: 0, }, - } - t2 = &pt.Billing{ - BillingHeader: pt.BillingHeader{ + ) + t2 = pt.NewBilling( + &pt.BillingHeader{ Nonce: 2, Producer: addr1, Receivers: []*proto.AccountAddress{&addr2}, Fees: []uint64{1}, Rewards: []uint64{1}, }, - } + ) ) err = t1.Sign(testPrivKey) So(err, ShouldBeNil) @@ -694,78 +692,78 @@ func TestMetaState(t *testing.T) { Convey("When base account txs are added", func() { var ( txs = []pi.Transaction{ - &pt.BaseAccount{ - Account: pt.Account{ + pt.NewBaseAccount( + &pt.Account{ Address: addr1, StableCoinBalance: 100, CovenantCoinBalance: 100, }, - }, - &pt.BaseAccount{ - Account: pt.Account{ + ), + pt.NewBaseAccount( + &pt.Account{ Address: addr2, StableCoinBalance: 100, CovenantCoinBalance: 100, }, - }, - &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + ), + pt.NewTransfer( + &pt.TransferHeader{ Sender: addr1, Receiver: addr2, Nonce: 1, Amount: 10, }, - }, - &pt.Billing{ - BillingHeader: pt.BillingHeader{ + ), + pt.NewBilling( + &pt.BillingHeader{ Nonce: 2, Producer: addr1, Receivers: []*proto.AccountAddress{&addr2}, Fees: []uint64{1}, Rewards: []uint64{1}, }, - }, - &pt.Billing{ - BillingHeader: pt.BillingHeader{ + ), + pt.NewBilling( + &pt.BillingHeader{ Nonce: 1, Producer: addr2, Receivers: []*proto.AccountAddress{&addr1}, Fees: []uint64{1}, Rewards: []uint64{1}, }, - }, - &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + ), + pt.NewTransfer( + &pt.TransferHeader{ Sender: addr2, Receiver: addr1, Nonce: 2, Amount: 1, }, - }, - &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + ), + pt.NewTransfer( + &pt.TransferHeader{ Sender: addr1, Receiver: addr2, Nonce: 3, Amount: 10, }, - }, - &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + ), + pt.NewTransfer( + &pt.TransferHeader{ Sender: addr2, Receiver: addr1, Nonce: 3, Amount: 1, }, - }, - &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + ), + pt.NewTransfer( + &pt.TransferHeader{ Sender: addr2, Receiver: addr1, Nonce: 4, Amount: 1, }, - }, + ), } ) for _, tx := range txs { diff --git a/blockproducer/types/baseaccount.go b/blockproducer/types/baseaccount.go index 612146e93..4aff39d50 100644 --- a/blockproducer/types/baseaccount.go +++ b/blockproducer/types/baseaccount.go @@ -31,7 +31,15 @@ import ( // BaseAccount defines the base account type header. type BaseAccount struct { Account - AccountHash hash.Hash + pi.TransactionTypeMixin +} + +// NewBaseAccount returns new instance. +func NewBaseAccount(account *Account) *BaseAccount { + return &BaseAccount{ + Account: *account, + TransactionTypeMixin: *pi.NewTransactionTypeMixin(pi.TransactionTypeBaseAccount), + } } // Serialize implements interfaces/Transaction.Serialize. @@ -61,13 +69,8 @@ func (b *BaseAccount) GetAccountNonce() pi.AccountNonce { } // GetHash implements interfaces/Transaction.GetHash. -func (b *BaseAccount) GetHash() hash.Hash { - return b.AccountHash -} - -// GetTransactionType implements interfaces/Transaction.GetTransactionType. -func (b *BaseAccount) GetTransactionType() pi.TransactionType { - return pi.TransactionTypeBaseAccount +func (b *BaseAccount) GetHash() (h hash.Hash) { + return } // Sign implements interfaces/Transaction.Sign. diff --git a/blockproducer/types/baseaccount_gen.go b/blockproducer/types/baseaccount_gen.go index 6f8c8f40f..857c98fd1 100644 --- a/blockproducer/types/baseaccount_gen.go +++ b/blockproducer/types/baseaccount_gen.go @@ -18,7 +18,7 @@ func (z *BaseAccount) MarshalHash() (o []byte, err error) { o = hsp.AppendBytes(o, oTemp) } o = append(o, 0x82) - if oTemp, err := z.AccountHash.MarshalHash(); err != nil { + if oTemp, err := z.TransactionTypeMixin.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) @@ -28,6 +28,6 @@ func (z *BaseAccount) MarshalHash() (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *BaseAccount) Msgsize() (s int) { - s = 1 + 8 + z.Account.Msgsize() + 12 + z.AccountHash.Msgsize() + s = 1 + 8 + z.Account.Msgsize() + 21 + z.TransactionTypeMixin.Msgsize() return } diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing.go index 77923e736..4569ae507 100644 --- a/blockproducer/types/billing.go +++ b/blockproducer/types/billing.go @@ -58,13 +58,15 @@ func NewBillingHeader(nonce pi.AccountNonce, bReq *BillingRequest, producer prot // Billing is a type of tx, that is used to record sql chain billing and block rewards. type Billing struct { BillingHeader + pi.TransactionTypeMixin DefaultHashSignVerifierImpl } // NewBilling generates a new Billing. func NewBilling(header *BillingHeader) *Billing { return &Billing{ - BillingHeader: *header, + BillingHeader: *header, + TransactionTypeMixin: *pi.NewTransactionTypeMixin(pi.TransactionTypeBilling), } } @@ -103,11 +105,6 @@ func (tb *Billing) GetAccountNonce() pi.AccountNonce { return tb.Nonce } -// GetTransactionType implements interfaces/Transaction.GetTransactionType. -func (tb *Billing) GetTransactionType() pi.TransactionType { - return pi.TransactionTypeBilling -} - // GetDatabaseID gets the database ID. func (tb *Billing) GetDatabaseID() *proto.DatabaseID { return &tb.BillingRequest.Header.DatabaseID diff --git a/blockproducer/types/billing_gen.go b/blockproducer/types/billing_gen.go index 0e45c16d9..5260f1a35 100644 --- a/blockproducer/types/billing_gen.go +++ b/blockproducer/types/billing_gen.go @@ -10,25 +10,31 @@ import ( func (z *Billing) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 2 - o = append(o, 0x82, 0x82) + // map header, size 3 + o = append(o, 0x83, 0x83) if oTemp, err := z.BillingHeader.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x82) + o = append(o, 0x83) if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } + o = append(o, 0x83) + if oTemp, err := z.TransactionTypeMixin.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Billing) Msgsize() (s int) { - s = 1 + 14 + z.BillingHeader.Msgsize() + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + s = 1 + 14 + z.BillingHeader.Msgsize() + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 21 + z.TransactionTypeMixin.Msgsize() return } diff --git a/blockproducer/types/block.go b/blockproducer/types/block.go index 6b0c9dcd4..15721da23 100644 --- a/blockproducer/types/block.go +++ b/blockproducer/types/block.go @@ -17,8 +17,7 @@ package types import ( - "bytes" - "reflect" + "github.com/CovenantSQL/CovenantSQL/utils" "time" pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" @@ -26,7 +25,6 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/merkle" "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/ugorji/go/codec" ) //go:generate hsp @@ -98,52 +96,19 @@ func (b *Block) PackAndSignBlock(signer *asymmetric.PrivateKey) error { return nil } -func enumType(t pi.TransactionType) (i pi.Transaction) { - switch t { - case pi.TransactionTypeBilling: - i = (*Billing)(nil) - case pi.TransactionTypeTransfer: - i = (*Transfer)(nil) - case pi.TransactionTypeBaseAccount: - i = (*BaseAccount)(nil) - case pi.TransactionTypeCreataDatabase: - i = (*CreateDatabase)(nil) - } - return -} - // Serialize converts block to bytes. func (b *Block) Serialize() ([]byte, error) { - buf := bytes.NewBuffer(nil) - hd := codec.MsgpackHandle{ - WriteExt: true, - RawToString: true, + buf, err := utils.EncodeMsgPack(b) + if err != nil { + return nil, err } - enc := codec.NewEncoder(buf, &hd) - err := enc.Encode(b) - return buf.Bytes(), err + + return buf.Bytes(), nil } // Deserialize converts bytes to block. func (b *Block) Deserialize(buf []byte) error { - r := bytes.NewBuffer(buf) - hd := codec.MsgpackHandle{ - WriteExt: true, - RawToString: true, - } - - for i := pi.TransactionType(0); i < pi.TransactionTypeNumber; i++ { - err := hd.Intf2Impl( - reflect.TypeOf((*pi.Transaction)(nil)).Elem(), - reflect.TypeOf(enumType(i)), - ) - if err != nil { - return err - } - } - - dec := codec.NewDecoder(r, &hd) - return dec.Decode(b) + return utils.DecodeMsgPack(buf, b) } // Verify verifies whether the block is valid. diff --git a/blockproducer/types/block_test.go b/blockproducer/types/block_test.go index 7c79d93cd..12785b4d6 100644 --- a/blockproducer/types/block_test.go +++ b/blockproducer/types/block_test.go @@ -17,6 +17,8 @@ package types import ( + "bytes" + "encoding" "reflect" "testing" @@ -71,46 +73,41 @@ func TestSignedHeader_MarshalUnmashalBinary(t *testing.T) { } -// -//func TestBlock_MarshalUnmarshalBinary(t *testing.T) { -// block, err := generateRandomBlock(genesisHash, false) -// if err != nil { -// t.Fatalf("Failed to generate block: %v", err) -// } -// h := reflect.TypeOf(block) -// _, ok := h.(encoding.BinaryMarshaler) -// if ok { -// t.Log("dec hash BinaryMashaler interface") -// } -// -// enc, err := block.Serialize() -// if err != nil { -// t.Fatalf("Failed to mashal binary: %v", err) -// } -// -// dec := &Block{} -// -// err = dec.Deserialize(enc) -// if err != nil { -// t.Fatalf("Failed to unmashal binary: %v", err) -// } -// -// bts1, err := block.MarshalHash() -// if err != nil { -// t.Fatal(err) -// } -// bts2, err := dec.MarshalHash() -// if err != nil { -// t.Fatal(err) -// } -// if !bytes.Equal(bts1, bts2) { -// t.Fatal("hash not stable") -// } -// -// if !reflect.DeepEqual(block, dec) { -// t.Fatalf("value not match") -// } -//} +func TestBlock_MarshalUnmarshalBinary(t *testing.T) { + block, err := generateRandomBlock(genesisHash, false) + if err != nil { + t.Fatalf("Failed to generate block: %v", err) + } + h := reflect.TypeOf(block) + _, ok := h.(encoding.BinaryMarshaler) + if ok { + t.Log("dec hash BinaryMashaler interface") + } + + enc, err := block.Serialize() + if err != nil { + t.Fatalf("Failed to mashal binary: %v", err) + } + + dec := &Block{} + + err = dec.Deserialize(enc) + if err != nil { + t.Fatalf("Failed to unmashal binary: %v", err) + } + + bts1, err := block.MarshalHash() + if err != nil { + t.Fatal(err) + } + bts2, err := dec.MarshalHash() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} func TestBlock_PackAndSignBlock(t *testing.T) { block, err := generateRandomBlock(genesisHash, false) diff --git a/blockproducer/types/createdb.go b/blockproducer/types/createdb.go index 11befccb5..c12471d95 100644 --- a/blockproducer/types/createdb.go +++ b/blockproducer/types/createdb.go @@ -43,9 +43,18 @@ func (h *CreateDatabaseHeader) GetAccountNonce() pi.AccountNonce { // CreateDatabase defines the database creation transaction. type CreateDatabase struct { CreateDatabaseHeader + pi.TransactionTypeMixin DefaultHashSignVerifierImpl } +// NewCreateDatabase returns new instance. +func NewCreateDatabase(header *CreateDatabaseHeader) *CreateDatabase { + return &CreateDatabase{ + CreateDatabaseHeader: *header, + TransactionTypeMixin: *pi.NewTransactionTypeMixin(pi.TransactionTypeCreateDatabase), + } +} + // Serialize implements interfaces/Transaction.Serialize. func (cd *CreateDatabase) Serialize() ([]byte, error) { return serialize(cd) @@ -56,11 +65,6 @@ func (cd *CreateDatabase) Deserialize(enc []byte) error { return deserialize(enc, cd) } -// GetTransactionType implements interfaces/Transaction.GetTransactionType. -func (cd *CreateDatabase) GetTransactionType() pi.TransactionType { - return pi.TransactionTypeCreataDatabase -} - // Sign implements interfaces/Transaction.Sign. func (cd *CreateDatabase) Sign(signer *asymmetric.PrivateKey) (err error) { return cd.DefaultHashSignVerifierImpl.Sign(&cd.CreateDatabaseHeader, signer) @@ -72,5 +76,5 @@ func (cd *CreateDatabase) Verify() error { } func init() { - pi.RegisterTransaction(pi.TransactionTypeCreataDatabase, (*CreateDatabase)(nil)) + pi.RegisterTransaction(pi.TransactionTypeCreateDatabase, (*CreateDatabase)(nil)) } diff --git a/blockproducer/types/createdb_gen.go b/blockproducer/types/createdb_gen.go index 368a8c99a..0b3e6b862 100644 --- a/blockproducer/types/createdb_gen.go +++ b/blockproducer/types/createdb_gen.go @@ -10,9 +10,9 @@ import ( func (z *CreateDatabase) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) + // map header, size 3 // map header, size 2 - // map header, size 2 - o = append(o, 0x82, 0x82, 0x82, 0x82) + o = append(o, 0x83, 0x83, 0x82, 0x82) if oTemp, err := z.CreateDatabaseHeader.Owner.MarshalHash(); err != nil { return nil, err } else { @@ -24,18 +24,24 @@ func (z *CreateDatabase) MarshalHash() (o []byte, err error) { } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x82) + o = append(o, 0x83) if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } + o = append(o, 0x83) + if oTemp, err := z.TransactionTypeMixin.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *CreateDatabase) Msgsize() (s int) { - s = 1 + 21 + 1 + 6 + z.CreateDatabaseHeader.Owner.Msgsize() + 6 + z.CreateDatabaseHeader.Nonce.Msgsize() + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + s = 1 + 21 + 1 + 6 + z.CreateDatabaseHeader.Owner.Msgsize() + 6 + z.CreateDatabaseHeader.Nonce.Msgsize() + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 21 + z.TransactionTypeMixin.Msgsize() return } diff --git a/blockproducer/types/msgpack_test.go b/blockproducer/types/msgpack_test.go index 26083c6e9..93eb487d3 100644 --- a/blockproducer/types/msgpack_test.go +++ b/blockproducer/types/msgpack_test.go @@ -28,7 +28,7 @@ import ( func TestEncodeSingleTransaction(t *testing.T) { Convey("test encode/decode single transaction", t, func() { var t pi.Transaction - t = pi.WrapTransaction(&BaseAccount{}) + t = NewBaseAccount(&Account{}) buf, err := utils.EncodeMsgPack(t) So(err, ShouldBeNil) @@ -39,4 +39,26 @@ func TestEncodeSingleTransaction(t *testing.T) { So(reflect.TypeOf(out).String(), ShouldContainSubstring, "TransactionWrapper") So(out.GetTransactionType(), ShouldEqual, t.GetTransactionType()) }) + + Convey("test encode/decode series of transactions", t, func() { + var t []pi.Transaction + t = append(t, NewBaseAccount(&Account{})) + t = append(t, NewTransfer(&TransferHeader{})) + t = append(t, NewBilling(&BillingHeader{})) + t = append(t, NewCreateDatabase(&CreateDatabaseHeader{})) + + buf, err := utils.EncodeMsgPack(t) + So(err, ShouldBeNil) + + var out []pi.Transaction + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldBeNil) + So(out, ShouldNotBeNil) + So(out, ShouldHaveLength, len(t)) + + for i := range t { + So(out[i].GetTransactionType(), ShouldEqual, t[i].GetTransactionType()) + So(reflect.TypeOf(out[i]).String(), ShouldContainSubstring, "TransactionWrapper") + } + }) } diff --git a/blockproducer/types/transfer.go b/blockproducer/types/transfer.go index 6ea90abb7..38be7c601 100644 --- a/blockproducer/types/transfer.go +++ b/blockproducer/types/transfer.go @@ -37,10 +37,19 @@ type TransferHeader struct { // Transfer defines the transfer transaction. type Transfer struct { TransferHeader + pi.TransactionTypeMixin DefaultHashSignVerifierImpl } -// Serialize serializes Billing using msgpack. +// NewTransfer returns new instance. +func NewTransfer(header *TransferHeader) *Transfer { + return &Transfer{ + TransferHeader: *header, + TransactionTypeMixin: *pi.NewTransactionTypeMixin(pi.TransactionTypeTransfer), + } +} + +// Serialize serializes Transfer using msgpack. func (t *Transfer) Serialize() (b []byte, err error) { var enc *bytes.Buffer if enc, err = utils.EncodeMsgPack(t); err != nil { @@ -50,7 +59,7 @@ func (t *Transfer) Serialize() (b []byte, err error) { return } -// Deserialize desrializes Billing using msgpack. +// Deserialize desrializes Transfer using msgpack. func (t *Transfer) Deserialize(enc []byte) error { return utils.DecodeMsgPack(enc, t) } @@ -65,11 +74,6 @@ func (t *Transfer) GetAccountNonce() pi.AccountNonce { return t.Nonce } -// GetTransactionType implements interfaces/Transaction.GetTransactionType. -func (t *Transfer) GetTransactionType() pi.TransactionType { - return pi.TransactionTypeTransfer -} - // Sign implements interfaces/Transaction.Sign. func (t *Transfer) Sign(signer *asymmetric.PrivateKey) (err error) { return t.DefaultHashSignVerifierImpl.Sign(&t.TransferHeader, signer) diff --git a/blockproducer/types/transfer_gen.go b/blockproducer/types/transfer_gen.go index 87c282d1d..6d910fa70 100644 --- a/blockproducer/types/transfer_gen.go +++ b/blockproducer/types/transfer_gen.go @@ -10,25 +10,31 @@ import ( func (z *Transfer) MarshalHash() (o []byte, err error) { var b []byte o = hsp.Require(b, z.Msgsize()) - // map header, size 2 - o = append(o, 0x82, 0x82) + // map header, size 3 + o = append(o, 0x83, 0x83) if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } - o = append(o, 0x82) + o = append(o, 0x83) if oTemp, err := z.TransferHeader.MarshalHash(); err != nil { return nil, err } else { o = hsp.AppendBytes(o, oTemp) } + o = append(o, 0x83) + if oTemp, err := z.TransactionTypeMixin.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *Transfer) Msgsize() (s int) { - s = 1 + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 15 + z.TransferHeader.Msgsize() + s = 1 + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 15 + z.TransferHeader.Msgsize() + 21 + z.TransactionTypeMixin.Msgsize() return } diff --git a/blockproducer/xxx_test.go b/blockproducer/xxx_test.go index d7702db46..8361b0eeb 100644 --- a/blockproducer/xxx_test.go +++ b/blockproducer/xxx_test.go @@ -116,20 +116,20 @@ func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *pt.Block, err err } else { // Create base accounts var ( - ba1 = &pt.BaseAccount{ - Account: pt.Account{ + ba1 = pt.NewBaseAccount( + &pt.Account{ Address: testAddress1, StableCoinBalance: testInitBalance, CovenantCoinBalance: testInitBalance, }, - } - ba2 = &pt.BaseAccount{ - Account: pt.Account{ + ) + ba2 = pt.NewBaseAccount( + &pt.Account{ Address: testAddress2, StableCoinBalance: testInitBalance, CovenantCoinBalance: testInitBalance, }, - } + ) ) if err = ba1.Sign(testPrivKey); err != nil { return @@ -171,14 +171,14 @@ func generateRandomBlockWithTransactions(parent hash.Hash, tbs []pi.Transaction) } testAddress1Nonce++ - var tr = &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + var tr = pt.NewTransfer( + &pt.TransferHeader{ Sender: testAddress1, Receiver: testAddress2, Nonce: testAddress1Nonce, Amount: 1, }, - } + ) if err = tr.Sign(priv); err != nil { return } @@ -271,21 +271,19 @@ func generateRandomBillingAndBaseAccount() (*pt.BaseAccount, *pt.Billing, error) priv, _, err := asymmetric.GenSecp256k1KeyPair() header.Producer, _ = crypto.PubKeyHash(priv.PubKey()) - txBilling := &pt.Billing{ - BillingHeader: *header, - } + txBilling := pt.NewBilling(header) if err := txBilling.Sign(priv); err != nil { return nil, nil, err } - txBaseAccount := &pt.BaseAccount{ - Account: pt.Account{ + txBaseAccount := pt.NewBaseAccount( + &pt.Account{ Address: header.Producer, StableCoinBalance: testInitBalance, CovenantCoinBalance: testInitBalance, }, - } + ) if err := txBaseAccount.Sign(priv); err != nil { return nil, nil, err @@ -302,9 +300,7 @@ func generateRandomAccountBilling() (*pt.Billing, error) { header.Producer = testAddress1 testAddress1Nonce++ header.Nonce = testAddress1Nonce - txBilling := &pt.Billing{ - BillingHeader: *header, - } + txBilling := pt.NewBilling(header) if err := txBilling.Sign(testPrivKey); err != nil { return nil, err diff --git a/cmd/cql-faucet/verifier.go b/cmd/cql-faucet/verifier.go index c1b95aed8..07c41929b 100644 --- a/cmd/cql-faucet/verifier.go +++ b/cmd/cql-faucet/verifier.go @@ -261,14 +261,14 @@ func (v *Verifier) dispenseOne(r *applicationRecord) (err error) { req := &bp.AddTxTransferReq{} resp := &bp.AddTxResp{} - req.Tx = &pt.Transfer{ - TransferHeader: pt.TransferHeader{ + req.Tx = pt.NewTransfer( + &pt.TransferHeader{ Sender: v.vaultAddress, Receiver: targetAddress, Nonce: nonceResp.Nonce, Amount: uint64(r.tokenAmount), }, - } + ) if err = req.Tx.Sign(v.privateKey); err != nil { // sign failed? return diff --git a/cmd/cql/util.go b/cmd/cql/util.go index af29b3bc3..8622c372b 100644 --- a/cmd/cql/util.go +++ b/cmd/cql/util.go @@ -47,7 +47,6 @@ func (t *SqTime) Scan(v interface{}) error { return nil case []byte: return t.parse(string(x)) - case string: return t.parse(x) } diff --git a/cmd/cqld/bootstrap.go b/cmd/cqld/bootstrap.go index cde81f434..7f8898e49 100644 --- a/cmd/cqld/bootstrap.go +++ b/cmd/cqld/bootstrap.go @@ -297,13 +297,12 @@ func loadGenesis() *types.Block { "stableCoinBalance": ba.StableCoinBalance, "covenantCoinBalance": ba.CovenantCoinBalance, }).Debugf("setting one balance fixture in genesis block") - genesis.Transactions = append(genesis.Transactions, &pt.BaseAccount{ - Account: pt.Account{ + genesis.Transactions = append(genesis.Transactions, pt.NewBaseAccount( + &pt.Account{ Address: proto.AccountAddress(ba.Address), StableCoinBalance: ba.StableCoinBalance, CovenantCoinBalance: ba.CovenantCoinBalance, - }, - }) + })) } return genesis From f88a7343f589e1ad9d8229c45d628f814d673b3e Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 19 Oct 2018 23:11:01 +0800 Subject: [PATCH 29/38] Add more test case for serialize and deserialize of transaction --- blockproducer/interfaces/nil_tx.go | 83 ---------------- .../interfaces/transaction_wrapper.go | 17 ++-- blockproducer/types/msgpack_test.go | 98 ++++++++++++++++++- 3 files changed, 107 insertions(+), 91 deletions(-) delete mode 100644 blockproducer/interfaces/nil_tx.go diff --git a/blockproducer/interfaces/nil_tx.go b/blockproducer/interfaces/nil_tx.go deleted file mode 100644 index 85d19fec1..000000000 --- a/blockproducer/interfaces/nil_tx.go +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2018 The CovenantSQL Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package interfaces - -import ( - "bytes" - - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" - "github.com/CovenantSQL/CovenantSQL/crypto/hash" - "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/CovenantSQL/CovenantSQL/utils" -) - -// NilTx defines empty transaction for transaction decode failure -type NilTx struct { - TransactionTypeMixin -} - -// NewNilTx returns new instance. -func NewNilTx() *NilTx { - return &NilTx{ - TransactionTypeMixin: *NewTransactionTypeMixin(TransactionTypeNumber), - } -} - -// Serialize serializes NilTx using msgpack. -func (t *NilTx) Serialize() (b []byte, err error) { - var enc *bytes.Buffer - if enc, err = utils.EncodeMsgPack(t); err != nil { - return - } - b = enc.Bytes() - return -} - -// Deserialize desrializes NilTx using msgpack. -func (t *NilTx) Deserialize(enc []byte) error { - return utils.DecodeMsgPack(enc, t) -} - -// GetAccountAddress implements Transaction.GetAccountAddress. -func (t *NilTx) GetAccountAddress() (addr proto.AccountAddress) { - return -} - -// GetAccountNonce implements Transaction.GetAccountNonce. -func (t *NilTx) GetAccountNonce() (nonce AccountNonce) { - // BaseAccount nonce is not counted, always return 0. - return -} - -// GetHash implements Transaction.GetHash. -func (t *NilTx) GetHash() (h hash.Hash) { - return -} - -// Sign implements interfaces/Transaction.Sign. -func (t *NilTx) Sign(signer *asymmetric.PrivateKey) (err error) { - return -} - -// Verify implements interfaces/Transaction.Verify. -func (t *NilTx) Verify() (err error) { - return -} - -func init() { - RegisterTransaction(TransactionTypeNumber, (*NilTx)(nil)) -} diff --git a/blockproducer/interfaces/transaction_wrapper.go b/blockproducer/interfaces/transaction_wrapper.go index 6c7d3748d..37948aa38 100644 --- a/blockproducer/interfaces/transaction_wrapper.go +++ b/blockproducer/interfaces/transaction_wrapper.go @@ -110,11 +110,6 @@ func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder) { default: panic(errors.Wrapf(ErrInvalidContainerType, "type %v applied", ct)) } - - if w.Transaction == nil { - // set nil transaction as placeholder to avoid nil pointer call - w.Transaction = NewNilTx() - } } func (w *TransactionWrapper) decodeFromWrapper(d *codec.Decoder) { @@ -133,7 +128,8 @@ func (w *TransactionWrapper) decodeFromWrapper(d *codec.Decoder) { // invalid type, can not instantiate transaction panic(ErrInvalidTransactionType) } else { - txType := (TransactionType)(helperDecoder.C.UintV(decodeDriver.DecodeUint64(), 32)) + var txType TransactionType + helperDecoder.DecFallback(&txType, true) var err error if w.Transaction, err = NewTransaction(txType); err != nil { @@ -141,7 +137,12 @@ func (w *TransactionWrapper) decodeFromWrapper(d *codec.Decoder) { } } } else if i == 1 { + if ct := decodeDriver.ContainerType(); ct != valueTypeMap { + panic(errors.Wrapf(ErrInvalidContainerType, "type %v applied", ct)) + } + if !decodeDriver.TryDecodeAsNil() { + // the container type should be struct helperDecoder.DecFallback(&w.Transaction, true) } } else { @@ -151,6 +152,10 @@ func (w *TransactionWrapper) decodeFromWrapper(d *codec.Decoder) { } decodeDriver.ReadArrayEnd() + + if containerLen < 2 { + panic(ErrInvalidTransactionType) + } } func (w *TransactionWrapper) decodeFromRaw(d *codec.Decoder) { diff --git a/blockproducer/types/msgpack_test.go b/blockproducer/types/msgpack_test.go index 93eb487d3..c448c3af6 100644 --- a/blockproducer/types/msgpack_test.go +++ b/blockproducer/types/msgpack_test.go @@ -25,7 +25,13 @@ import ( . "github.com/smartystreets/goconvey/convey" ) -func TestEncodeSingleTransaction(t *testing.T) { +type complexStructure struct { + Tx pi.Transaction + Txs []pi.Transaction + Maps map[string]pi.Transaction +} + +func TestEncodeDecodeTransactions(t *testing.T) { Convey("test encode/decode single transaction", t, func() { var t pi.Transaction t = NewBaseAccount(&Account{}) @@ -39,7 +45,6 @@ func TestEncodeSingleTransaction(t *testing.T) { So(reflect.TypeOf(out).String(), ShouldContainSubstring, "TransactionWrapper") So(out.GetTransactionType(), ShouldEqual, t.GetTransactionType()) }) - Convey("test encode/decode series of transactions", t, func() { var t []pi.Transaction t = append(t, NewBaseAccount(&Account{})) @@ -57,8 +62,97 @@ func TestEncodeSingleTransaction(t *testing.T) { So(out, ShouldHaveLength, len(t)) for i := range t { + So(out[i], ShouldNotBeNil) So(out[i].GetTransactionType(), ShouldEqual, t[i].GetTransactionType()) So(reflect.TypeOf(out[i]).String(), ShouldContainSubstring, "TransactionWrapper") } }) + Convey("test encode/decode complex structure containing transactions", t, func() { + var t complexStructure + t.Tx = NewBaseAccount(&Account{}) + t.Txs = append(t.Txs, NewBaseAccount(&Account{})) + t.Txs = append(t.Txs, NewTransfer(&TransferHeader{})) + t.Txs = append(t.Txs, NewBilling(&BillingHeader{})) + t.Txs = append(t.Txs, NewCreateDatabase(&CreateDatabaseHeader{})) + t.Maps = make(map[string]pi.Transaction) + t.Maps["BaseAccount"] = NewBaseAccount(&Account{}) + t.Maps["Transfer"] = NewTransfer(&TransferHeader{}) + t.Maps["Billing"] = NewBilling(&BillingHeader{}) + t.Maps["CreateDatabase"] = NewCreateDatabase(&CreateDatabaseHeader{}) + buf, err := utils.EncodeMsgPack(t) + So(err, ShouldBeNil) + + var out complexStructure + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldBeNil) + So(out.Tx, ShouldNotBeNil) + So(out.Txs, ShouldNotBeNil) + So(out.Txs, ShouldHaveLength, len(t.Txs)) + So(out.Maps, ShouldNotBeNil) + So(out.Maps, ShouldHaveLength, len(t.Maps)) + + So(out.Tx.GetTransactionType(), ShouldEqual, pi.TransactionTypeBaseAccount) + So(reflect.TypeOf(out.Tx).String(), ShouldContainSubstring, "TransactionWrapper") + + for i := range out.Txs { + So(out.Txs[i], ShouldNotBeNil) + So(out.Txs[i].GetTransactionType(), ShouldEqual, t.Txs[i].GetTransactionType()) + So(reflect.TypeOf(out.Txs[i]).String(), ShouldContainSubstring, "TransactionWrapper") + } + + for k, v := range out.Maps { + So(v, ShouldNotBeNil) + So(out.Maps[k].GetTransactionType(), ShouldEqual, t.Maps[k].GetTransactionType()) + So(reflect.TypeOf(out.Maps[k]).String(), ShouldContainSubstring, "TransactionWrapper") + } + }) + Convey("test encode wrapper, decode using real type", t, func() { + var t pi.Transaction + t = pi.WrapTransaction(NewBaseAccount(&Account{})) + So(reflect.TypeOf(t).String(), ShouldContainSubstring, "TransactionWrapper") + So(t.GetTransactionType(), ShouldEqual, pi.TransactionTypeBaseAccount) + buf, err := utils.EncodeMsgPack(t) + So(err, ShouldBeNil) + + var out *BaseAccount + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldBeNil) + So(out, ShouldNotBeNil) + So(out.GetTransactionType(), ShouldEqual, pi.TransactionTypeBaseAccount) + So(reflect.TypeOf(out).String(), ShouldContainSubstring, "BaseAccount") + }) + Convey("decode invalid data", t, func() { + var testTypes = []interface{}{ + "1", + 1, + 0.1, + []int{}, + []int{1, 2}, + []int{1, 2, 3}, + struct{ A int }{A: 1}, + struct{ TxType int }{TxType: int(pi.TransactionTypeNumber) + 1}, + struct{ TxType struct{} }{}, + struct{}{}, + } + + for _, val := range testTypes { + buf, err := utils.EncodeMsgPack(val) + So(err, ShouldBeNil) + + var out pi.Transaction + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldNotBeNil) + } + }) + Convey("decode wrapper with nil transaction", t, func() { + var t pi.Transaction + t = pi.WrapTransaction(nil) + buf, err := utils.EncodeMsgPack(t) + So(err, ShouldBeNil) + + var out pi.Transaction + err = utils.DecodeMsgPack(buf.Bytes(), &out) + So(err, ShouldBeNil) + So(out, ShouldBeNil) + }) } From b7a8bd4050df9f25ba2dee1c4a3e21a865c7df07 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Sat, 20 Oct 2018 00:04:30 +0800 Subject: [PATCH 30/38] Unify msgpack encode/decode --- blockproducer/chain.go | 22 +++++++++++++--------- blockproducer/errors.go | 2 ++ blockproducer/helper_test.go | 1 - blockproducer/interfaces/transaction.go | 13 ------------- blockproducer/metastate.go | 6 +++--- blockproducer/state.go | 17 ----------------- blockproducer/types/baseaccount.go | 18 ------------------ blockproducer/types/billing.go | 18 ------------------ blockproducer/types/billing_test.go | 4 ++-- blockproducer/types/block.go | 16 ---------------- blockproducer/types/block_test.go | 5 ++--- blockproducer/types/common.go | 16 ---------------- blockproducer/types/createdb.go | 10 ---------- blockproducer/types/transfer.go | 18 ------------------ client/_example/simple.go | 2 -- cmd/cql-faucet/persistence.go | 1 - cmd/cql-minerd/integration_test.go | 3 +-- cmd/cql-observer/main.go | 3 +-- conf/config_test.go | 3 +-- crypto/asymmetric/keypair_test.go | 1 - crypto/asymmetric/signature.go | 1 - crypto/etls/encrypt_test.go | 3 +-- crypto/hash/hashfuncs.go | 2 -- crypto/kms/privatekeystore_test.go | 9 +++------ crypto/kms/pubkeystore.go | 17 ++++------------- crypto/kms/pubkeystore_test.go | 12 +++--------- crypto/symmetric/aes.go | 3 +-- merkle/merkletrie_test.go | 5 +---- merkle/patriciatrie_test.go | 4 +--- pow/cpuminer/miner_test.go | 4 +--- pow/cpuminer/uint256_test.go | 4 +--- proto/nodeinfo_test.go | 1 - proto/proto_test.go | 1 - route/service_test.go | 15 +++++---------- rpc/client.go | 12 +++--------- rpc/rpcutil_test.go | 3 +-- rpc/server.go | 8 ++------ sqlchain/storage/storage.go | 1 - sqlchain/types/block_test.go | 3 +-- twopc/twopc_test.go | 6 ++---- utils/msgpack.go | 20 ++++++++++++++++---- utils/net_test.go | 6 ++---- utils/path_test.go | 4 +--- utils/profiler_test.go | 3 +-- 44 files changed, 75 insertions(+), 251 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index 7ad63c93c..dafb8fd46 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -31,6 +31,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/coreos/bbolt" ) @@ -182,9 +183,13 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { err = chain.db.View(func(tx *bolt.Tx) (err error) { meta := tx.Bucket(metaBucket[:]) + metaEnc := meta.Get(metaStateKey) + if metaEnc == nil { + return ErrMetaStateNotFound + } + state := &State{} - // TODO(), should test if fetch metaState failed - if err = state.deserialize(meta.Get(metaStateKey)); err != nil { + if err = utils.DecodeMsgPack(metaEnc, state); err != nil { return } chain.rt.setHead(state) @@ -196,8 +201,7 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { if err = blocks.ForEach(func(k, v []byte) (err error) { block := &types.Block{} - - if err = block.Deserialize(v); err != nil { + if err = utils.DecodeMsgPack(v, block); err != nil { log.Errorf("loadeing block: %v", err) return err } @@ -280,22 +284,22 @@ func (c *Chain) pushBlockWithoutCheck(b *types.Block) error { Height: node.height, } - encBlock, err := b.Serialize() + encBlock, err := utils.EncodeMsgPack(b) if err != nil { return err } - encState, err := c.rt.getHead().serialize() + encState, err := utils.EncodeMsgPack(c.rt.getHead()) if err != nil { return err } err = c.db.Update(func(tx *bolt.Tx) (err error) { - err = tx.Bucket(metaBucket[:]).Put(metaStateKey, encState) + err = tx.Bucket(metaBucket[:]).Put(metaStateKey, encState.Bytes()) if err != nil { return err } - err = tx.Bucket(metaBucket[:]).Bucket(metaBlockIndexBucket).Put(node.indexKey(), encBlock) + err = tx.Bucket(metaBucket[:]).Bucket(metaBlockIndexBucket).Put(node.indexKey(), encBlock.Bytes()) if err != nil { return err } @@ -476,7 +480,7 @@ func (c *Chain) fetchBlockByHeight(h uint32) (*types.Block, error) { err := c.db.View(func(tx *bolt.Tx) error { v := tx.Bucket(metaBucket[:]).Bucket(metaBlockIndexBucket).Get(k) - return b.Deserialize(v) + return utils.DecodeMsgPack(v, b) }) if err != nil { return nil, err diff --git a/blockproducer/errors.go b/blockproducer/errors.go index 507ebf263..53e845bab 100644 --- a/blockproducer/errors.go +++ b/blockproducer/errors.go @@ -74,4 +74,6 @@ var ( ErrUnknownTransactionType = errors.New("unknown transaction type") // ErrTransactionMismatch indicates that transactions to be committed mismatch the pool. ErrTransactionMismatch = errors.New("transaction mismatch") + // ErrMetaStateNotFound indicates that meta state not found in db. + ErrMetaStateNotFound = errors.New("meta state not found in db") ) diff --git a/blockproducer/helper_test.go b/blockproducer/helper_test.go index 121c5fd8e..b74061eb5 100644 --- a/blockproducer/helper_test.go +++ b/blockproducer/helper_test.go @@ -29,7 +29,6 @@ import ( "time" "github.com/CovenantSQL/CovenantSQL/conf" - "github.com/CovenantSQL/CovenantSQL/consistent" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" diff --git a/blockproducer/interfaces/transaction.go b/blockproducer/interfaces/transaction.go index 2a1e9ca49..7aec5aabd 100644 --- a/blockproducer/interfaces/transaction.go +++ b/blockproducer/interfaces/transaction.go @@ -67,22 +67,9 @@ const ( TransactionTypeNumber ) -// Serializer is the interface implemented by an object that can serialize itself into binary form. -type Serializer interface { - Serialize() ([]byte, error) -} - -// Deserializer is the interface implemented by an object that can deserialize a binary -// representation of itself. -type Deserializer interface { - Deserialize(enc []byte) error -} - // Transaction is the interface implemented by an object that can be verified and processed by // block producers. type Transaction interface { - Serializer - Deserializer GetAccountAddress() proto.AccountAddress GetAccountNonce() AccountNonce GetHash() hash.Hash diff --git a/blockproducer/metastate.go b/blockproducer/metastate.go index cdeb5fdaa..571a34764 100644 --- a/blockproducer/metastate.go +++ b/blockproducer/metastate.go @@ -699,13 +699,13 @@ func (s *metaState) applyTransactionProcedure(t pi.Transaction) (_ func(*bolt.Tx } var ( - enc []byte + enc *bytes.Buffer hash = t.GetHash() addr = t.GetAccountAddress() nonce = t.GetAccountNonce() ttype = t.GetTransactionType() ) - if enc, err = t.Serialize(); err != nil { + if enc, err = utils.EncodeMsgPack(t); err != nil { log.Debugf("encode failed on applying transaction: %v", err) return errPass } @@ -737,7 +737,7 @@ func (s *metaState) applyTransactionProcedure(t pi.Transaction) (_ func(*bolt.Tx // Try to put transaction before any state change, will be rolled back later // if transaction doesn't apply tb := tx.Bucket(metaBucket[:]).Bucket(metaTransactionBucket).Bucket(ttype.Bytes()) - if err = tb.Put(hash[:], enc); err != nil { + if err = tb.Put(hash[:], enc.Bytes()); err != nil { log.Debugf("store transaction to bucket failed: %v", err) return } diff --git a/blockproducer/state.go b/blockproducer/state.go index 3875c9004..c82fc3618 100644 --- a/blockproducer/state.go +++ b/blockproducer/state.go @@ -20,7 +20,6 @@ import ( "sync" "github.com/CovenantSQL/CovenantSQL/crypto/hash" - "github.com/CovenantSQL/CovenantSQL/utils" ) // State store the node info of chain. @@ -31,22 +30,6 @@ type State struct { Height uint32 } -// serialize serializes the state. -func (s *State) serialize() ([]byte, error) { - buffer, err := utils.EncodeMsgPack(s) - if err != nil { - return nil, err - } - - return buffer.Bytes(), nil -} - -// deserialize deserializes the state. -func (s *State) deserialize(b []byte) error { - err := utils.DecodeMsgPack(b, s) - return err -} - func (s *State) getNode() *blockNode { s.Lock() defer s.Unlock() diff --git a/blockproducer/types/baseaccount.go b/blockproducer/types/baseaccount.go index 4aff39d50..ce4facda1 100644 --- a/blockproducer/types/baseaccount.go +++ b/blockproducer/types/baseaccount.go @@ -17,13 +17,10 @@ package types import ( - "bytes" - pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/CovenantSQL/CovenantSQL/utils" ) //go:generate hsp @@ -42,21 +39,6 @@ func NewBaseAccount(account *Account) *BaseAccount { } } -// Serialize implements interfaces/Transaction.Serialize. -func (b *BaseAccount) Serialize() (s []byte, err error) { - var enc *bytes.Buffer - if enc, err = utils.EncodeMsgPack(b); err != nil { - return - } - s = enc.Bytes() - return -} - -// Deserialize implements interfaces/Transaction.Deserialize. -func (b *BaseAccount) Deserialize(enc []byte) error { - return utils.DecodeMsgPack(enc, b) -} - // GetAccountAddress implements interfaces/Transaction.GetAccountAddress. func (b *BaseAccount) GetAccountAddress() proto.AccountAddress { return b.Address diff --git a/blockproducer/types/billing.go b/blockproducer/types/billing.go index 4569ae507..0beeb86f7 100644 --- a/blockproducer/types/billing.go +++ b/blockproducer/types/billing.go @@ -17,12 +17,9 @@ package types import ( - "bytes" - pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/CovenantSQL/CovenantSQL/utils" ) //go:generate hsp @@ -70,21 +67,6 @@ func NewBilling(header *BillingHeader) *Billing { } } -// Serialize serializes Billing using msgpack. -func (tb *Billing) Serialize() (b []byte, err error) { - var enc *bytes.Buffer - if enc, err = utils.EncodeMsgPack(tb); err != nil { - return - } - b = enc.Bytes() - return -} - -// Deserialize deserialize Billing using msgpack. -func (tb *Billing) Deserialize(enc []byte) error { - return utils.DecodeMsgPack(enc, tb) -} - // Sign implements interfaces/Transaction.Sign. func (tb *Billing) Sign(signer *asymmetric.PrivateKey) (err error) { return tb.DefaultHashSignVerifierImpl.Sign(&tb.BillingHeader, signer) diff --git a/blockproducer/types/billing_test.go b/blockproducer/types/billing_test.go index 011035bef..bafa32c10 100644 --- a/blockproducer/types/billing_test.go +++ b/blockproducer/types/billing_test.go @@ -70,13 +70,13 @@ func TestBilling_SerializeDeserialize(t *testing.T) { t.Fatalf("Unexpeted error: %v", err) } - enc, err := tb.Serialize() + enc, err := utils.EncodeMsgPack(tb) if err != nil { t.Fatalf("Unexpeted error: %v", err) } dec := Billing{} - err = dec.Deserialize(enc) + err = utils.DecodeMsgPack(enc.Bytes(), &dec) if err != nil { t.Fatalf("Unexpeted error: %v", err) } diff --git a/blockproducer/types/block.go b/blockproducer/types/block.go index 15721da23..2feb2ec6b 100644 --- a/blockproducer/types/block.go +++ b/blockproducer/types/block.go @@ -17,7 +17,6 @@ package types import ( - "github.com/CovenantSQL/CovenantSQL/utils" "time" pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" @@ -96,21 +95,6 @@ func (b *Block) PackAndSignBlock(signer *asymmetric.PrivateKey) error { return nil } -// Serialize converts block to bytes. -func (b *Block) Serialize() ([]byte, error) { - buf, err := utils.EncodeMsgPack(b) - if err != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -// Deserialize converts bytes to block. -func (b *Block) Deserialize(buf []byte) error { - return utils.DecodeMsgPack(buf, b) -} - // Verify verifies whether the block is valid. func (b *Block) Verify() error { hs := b.GetTxHashes() diff --git a/blockproducer/types/block_test.go b/blockproducer/types/block_test.go index 12785b4d6..403123ea6 100644 --- a/blockproducer/types/block_test.go +++ b/blockproducer/types/block_test.go @@ -84,14 +84,13 @@ func TestBlock_MarshalUnmarshalBinary(t *testing.T) { t.Log("dec hash BinaryMashaler interface") } - enc, err := block.Serialize() + enc, err := utils.EncodeMsgPack(block) if err != nil { t.Fatalf("Failed to mashal binary: %v", err) } dec := &Block{} - - err = dec.Deserialize(enc) + err = utils.DecodeMsgPack(enc.Bytes(), dec) if err != nil { t.Fatalf("Failed to unmashal binary: %v", err) } diff --git a/blockproducer/types/common.go b/blockproducer/types/common.go index c865cd63f..024cc9646 100644 --- a/blockproducer/types/common.go +++ b/blockproducer/types/common.go @@ -17,26 +17,10 @@ package types import ( - "bytes" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" - "github.com/CovenantSQL/CovenantSQL/utils" ) -func serialize(i interface{}) (s []byte, err error) { - var enc *bytes.Buffer - if enc, err = utils.EncodeMsgPack(i); err != nil { - return - } - s = enc.Bytes() - return -} - -func deserialize(enc []byte, o interface{}) error { - return utils.DecodeMsgPack(enc, o) -} - type marshalHasher interface { MarshalHash() ([]byte, error) } diff --git a/blockproducer/types/createdb.go b/blockproducer/types/createdb.go index c12471d95..2d5aa00fa 100644 --- a/blockproducer/types/createdb.go +++ b/blockproducer/types/createdb.go @@ -55,16 +55,6 @@ func NewCreateDatabase(header *CreateDatabaseHeader) *CreateDatabase { } } -// Serialize implements interfaces/Transaction.Serialize. -func (cd *CreateDatabase) Serialize() ([]byte, error) { - return serialize(cd) -} - -// Deserialize implements interfaces/Transaction.Deserialize. -func (cd *CreateDatabase) Deserialize(enc []byte) error { - return deserialize(enc, cd) -} - // Sign implements interfaces/Transaction.Sign. func (cd *CreateDatabase) Sign(signer *asymmetric.PrivateKey) (err error) { return cd.DefaultHashSignVerifierImpl.Sign(&cd.CreateDatabaseHeader, signer) diff --git a/blockproducer/types/transfer.go b/blockproducer/types/transfer.go index 38be7c601..e9a170fa0 100644 --- a/blockproducer/types/transfer.go +++ b/blockproducer/types/transfer.go @@ -17,12 +17,9 @@ package types import ( - "bytes" - pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/proto" - "github.com/CovenantSQL/CovenantSQL/utils" ) //go:generate hsp @@ -49,21 +46,6 @@ func NewTransfer(header *TransferHeader) *Transfer { } } -// Serialize serializes Transfer using msgpack. -func (t *Transfer) Serialize() (b []byte, err error) { - var enc *bytes.Buffer - if enc, err = utils.EncodeMsgPack(t); err != nil { - return - } - b = enc.Bytes() - return -} - -// Deserialize desrializes Transfer using msgpack. -func (t *Transfer) Deserialize(enc []byte) error { - return utils.DecodeMsgPack(enc, t) -} - // GetAccountAddress implements interfaces/Transaction.GetAccountAddress. func (t *Transfer) GetAccountAddress() proto.AccountAddress { return t.Sender diff --git a/client/_example/simple.go b/client/_example/simple.go index 1bbd2e420..c3bc6cad4 100644 --- a/client/_example/simple.go +++ b/client/_example/simple.go @@ -19,9 +19,7 @@ package main import ( "database/sql" "flag" - "fmt" - "github.com/CovenantSQL/CovenantSQL/client" log "github.com/sirupsen/logrus" ) diff --git a/cmd/cql-faucet/persistence.go b/cmd/cql-faucet/persistence.go index 961ece8e2..411b6289c 100644 --- a/cmd/cql-faucet/persistence.go +++ b/cmd/cql-faucet/persistence.go @@ -26,7 +26,6 @@ import ( "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/satori/go.uuid" - // Load sqlite3 database driver. _ "github.com/CovenantSQL/go-sqlite3-encrypt" ) diff --git a/cmd/cql-minerd/integration_test.go b/cmd/cql-minerd/integration_test.go index 86b2a068c..068055516 100644 --- a/cmd/cql-minerd/integration_test.go +++ b/cmd/cql-minerd/integration_test.go @@ -22,14 +22,13 @@ import ( "context" "database/sql" "os" + "os/exec" "path/filepath" "sync" "syscall" "testing" "time" - "os/exec" - "github.com/CovenantSQL/CovenantSQL/client" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/utils" diff --git a/cmd/cql-observer/main.go b/cmd/cql-observer/main.go index 9b71ccea1..975c6966f 100644 --- a/cmd/cql-observer/main.go +++ b/cmd/cql-observer/main.go @@ -19,11 +19,10 @@ package main import ( "flag" "math/rand" - "time" - "os" "os/signal" "syscall" + "time" "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" diff --git a/conf/config_test.go b/conf/config_test.go index c2b56571b..84d5d0103 100644 --- a/conf/config_test.go +++ b/conf/config_test.go @@ -23,9 +23,8 @@ import ( "testing" "time" - "github.com/CovenantSQL/CovenantSQL/crypto/hash" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/utils/log" diff --git a/crypto/asymmetric/keypair_test.go b/crypto/asymmetric/keypair_test.go index ead4e40bf..d5b4e7f8c 100644 --- a/crypto/asymmetric/keypair_test.go +++ b/crypto/asymmetric/keypair_test.go @@ -20,7 +20,6 @@ import ( "bytes" "strings" "testing" - "time" "github.com/CovenantSQL/CovenantSQL/utils/log" diff --git a/crypto/asymmetric/signature.go b/crypto/asymmetric/signature.go index 19d9b310a..77ac14580 100644 --- a/crypto/asymmetric/signature.go +++ b/crypto/asymmetric/signature.go @@ -20,7 +20,6 @@ import ( "crypto/elliptic" "errors" "math/big" - "sync" "github.com/CovenantSQL/CovenantSQL/crypto/secp256k1" diff --git a/crypto/etls/encrypt_test.go b/crypto/etls/encrypt_test.go index 9c98b47c2..129ccf94c 100644 --- a/crypto/etls/encrypt_test.go +++ b/crypto/etls/encrypt_test.go @@ -17,9 +17,8 @@ package etls import ( - "testing" - "bytes" + "testing" "github.com/CovenantSQL/CovenantSQL/crypto/hash" . "github.com/smartystreets/goconvey/convey" diff --git a/crypto/hash/hashfuncs.go b/crypto/hash/hashfuncs.go index ba3d16caf..6235c4964 100644 --- a/crypto/hash/hashfuncs.go +++ b/crypto/hash/hashfuncs.go @@ -19,11 +19,9 @@ package hash import ( "encoding/binary" "hash/fnv" - // "crypto/sha256" benchmark is at least 10% faster on // i7-4870HQ CPU @ 2.50GHz than "github.com/minio/sha256-simd" "crypto/sha256" - // "minio/blake2b-simd" benchmark is at least 3% faster on // i7-4870HQ CPU @ 2.50GHz than "golang.org/x/crypto/blake2b" // and supports more CPU instructions diff --git a/crypto/kms/privatekeystore_test.go b/crypto/kms/privatekeystore_test.go index 44682c76f..0485552af 100644 --- a/crypto/kms/privatekeystore_test.go +++ b/crypto/kms/privatekeystore_test.go @@ -17,14 +17,11 @@ package kms import ( + "bytes" "encoding/hex" - "testing" - - "os" - "io/ioutil" - - "bytes" + "os" + "testing" "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" diff --git a/crypto/kms/pubkeystore.go b/crypto/kms/pubkeystore.go index 7a952605a..f9ff5062b 100644 --- a/crypto/kms/pubkeystore.go +++ b/crypto/kms/pubkeystore.go @@ -17,7 +17,6 @@ package kms import ( - "bytes" "errors" "os" "path/filepath" @@ -26,14 +25,13 @@ import ( "sync" "github.com/CovenantSQL/CovenantSQL/conf" - "github.com/CovenantSQL/CovenantSQL/utils/log" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" mine "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" + "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/coreos/bbolt" - "github.com/ugorji/go/codec" ) // PublicKeyStore holds db and bucket name @@ -185,11 +183,7 @@ func GetNodeInfo(id proto.NodeID) (nodeInfo *proto.Node, err error) { if byteVal == nil { return ErrKeyNotFound } - reader := bytes.NewReader(byteVal) - mh := &codec.MsgpackHandle{} - dec := codec.NewDecoder(reader, mh) - nodeInfo = proto.NewNode() - err = dec.Decode(nodeInfo) + err = utils.DecodeMsgPack(byteVal, &nodeInfo) log.Debugf("get node info: %v", nodeInfo) return err // return from View func }) @@ -266,10 +260,7 @@ func setNode(nodeInfo *proto.Node) (err error) { return ErrPKSNotInitialized } - nodeBuf := new(bytes.Buffer) - mh := &codec.MsgpackHandle{} - enc := codec.NewEncoder(nodeBuf, mh) - err = enc.Encode(*nodeInfo) + nodeBuf, err := utils.EncodeMsgPack(nodeInfo) if err != nil { log.Errorf("marshal node info failed: %s", err) return diff --git a/crypto/kms/pubkeystore_test.go b/crypto/kms/pubkeystore_test.go index de6c6fba7..07d9cf568 100644 --- a/crypto/kms/pubkeystore_test.go +++ b/crypto/kms/pubkeystore_test.go @@ -17,7 +17,6 @@ package kms import ( - "bytes" "os" "reflect" "testing" @@ -25,9 +24,9 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" . "github.com/smartystreets/goconvey/convey" - "github.com/ugorji/go/codec" "gopkg.in/yaml.v2" ) @@ -171,18 +170,13 @@ func TestMarshalNode(t *testing.T) { D: 4, }, } - nodeBuf := new(bytes.Buffer) - mh := &codec.MsgpackHandle{} - enc := codec.NewEncoder(nodeBuf, mh) - err := enc.Encode(nodeInfo) + nodeBuf, err := utils.EncodeMsgPack(nodeInfo) if err != nil { log.Errorf("encode error: %s", err) } nodeDec := proto.NewNode() - reader := bytes.NewReader(nodeBuf.Bytes()) - dec := codec.NewDecoder(reader, mh) - err = dec.Decode(nodeDec) + err = utils.DecodeMsgPack(nodeBuf.Bytes(), nodeDec) So(reflect.DeepEqual(nodeDec, nodeInfo), ShouldBeTrue) }) diff --git a/crypto/symmetric/aes.go b/crypto/symmetric/aes.go index f04414dc7..41c7a0f1d 100644 --- a/crypto/symmetric/aes.go +++ b/crypto/symmetric/aes.go @@ -21,9 +21,8 @@ import ( "crypto/aes" "crypto/cipher" "crypto/rand" - "io" - "errors" + "io" "github.com/CovenantSQL/CovenantSQL/crypto" "github.com/CovenantSQL/CovenantSQL/crypto/hash" diff --git a/merkle/merkletrie_test.go b/merkle/merkletrie_test.go index 973ae4650..58a94cbe0 100644 --- a/merkle/merkletrie_test.go +++ b/merkle/merkletrie_test.go @@ -1,13 +1,10 @@ package merkle import ( - "testing" - "bytes" - "crypto/rand" - "math" + "testing" "github.com/CovenantSQL/CovenantSQL/crypto/hash" . "github.com/smartystreets/goconvey/convey" diff --git a/merkle/patriciatrie_test.go b/merkle/patriciatrie_test.go index 375d2c8bb..c5cf5ce62 100644 --- a/merkle/patriciatrie_test.go +++ b/merkle/patriciatrie_test.go @@ -1,12 +1,10 @@ package merkle import ( - "testing" - "bytes" "encoding/gob" - "strings" + "testing" "github.com/CovenantSQL/CovenantSQL/crypto/hash" . "github.com/smartystreets/goconvey/convey" diff --git a/pow/cpuminer/miner_test.go b/pow/cpuminer/miner_test.go index 814204f33..24e81380d 100644 --- a/pow/cpuminer/miner_test.go +++ b/pow/cpuminer/miner_test.go @@ -17,11 +17,9 @@ package cpuminer import ( + "sync" "testing" - "time" - - "sync" ) func TestCPUMiner_HashBlock(t *testing.T) { diff --git a/pow/cpuminer/uint256_test.go b/pow/cpuminer/uint256_test.go index 53204f680..d6d87ee81 100644 --- a/pow/cpuminer/uint256_test.go +++ b/pow/cpuminer/uint256_test.go @@ -19,11 +19,9 @@ package cpuminer import ( "math" "testing" - - "github.com/CovenantSQL/CovenantSQL/utils/log" - "unsafe" + "github.com/CovenantSQL/CovenantSQL/utils/log" . "github.com/smartystreets/goconvey/convey" ) diff --git a/proto/nodeinfo_test.go b/proto/nodeinfo_test.go index d66f4f3bf..7f9f07c92 100644 --- a/proto/nodeinfo_test.go +++ b/proto/nodeinfo_test.go @@ -19,7 +19,6 @@ package proto import ( "strings" "testing" - "time" "github.com/CovenantSQL/CovenantSQL/crypto/hash" diff --git a/proto/proto_test.go b/proto/proto_test.go index fdca927f6..82428d995 100644 --- a/proto/proto_test.go +++ b/proto/proto_test.go @@ -18,7 +18,6 @@ package proto import ( "testing" - "time" "github.com/CovenantSQL/CovenantSQL/crypto/hash" diff --git a/route/service_test.go b/route/service_test.go index 16f6354c0..499f73e74 100644 --- a/route/service_test.go +++ b/route/service_test.go @@ -29,9 +29,9 @@ import ( "github.com/CovenantSQL/CovenantSQL/consistent" "github.com/CovenantSQL/CovenantSQL/crypto/kms" . "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" . "github.com/smartystreets/goconvey/convey" - "github.com/ugorji/go/codec" ) const DHTStorePath = "./DHTStore" @@ -213,7 +213,6 @@ func TestDHTService_Ping(t *testing.T) { fmt.Println(err) return } - mh := &codec.MsgpackHandle{} go func() { for { @@ -221,8 +220,7 @@ func TestDHTService_Ping(t *testing.T) { if err != nil { continue } - msgpackCodec := codec.MsgpackSpecRpc.ServerCodec(c, mh) - go rpc.ServeCodec(msgpackCodec) + go rpc.ServeCodec(utils.GetMsgPackServerCodec(c)) } }() @@ -239,8 +237,7 @@ func TestDHTService_Ping(t *testing.T) { Node: *node1, } respA := new(PingResp) - msgpackCodec := codec.MsgpackSpecRpc.ClientCodec(client, mh) - rc := rpc.NewClientWithCodec(msgpackCodec) + rc := rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client)) err = rc.Call("DHT.Ping", reqA, respA) if err != nil { t.Error(err) @@ -251,8 +248,7 @@ func TestDHTService_Ping(t *testing.T) { respA3 := new(PingResp) conf.GConf.MinNodeIDDifficulty = 256 client, _ = net.Dial("tcp", ln.Addr().String()) - msgpackCodec = codec.MsgpackSpecRpc.ClientCodec(client, mh) - rc = rpc.NewClientWithCodec(msgpackCodec) + rc = rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client)) err = rc.Call("DHT.Ping", reqA, respA3) if err == nil || !strings.Contains(err.Error(), "difficulty too low") { t.Error(err) @@ -263,8 +259,7 @@ func TestDHTService_Ping(t *testing.T) { respA2 := new(PingResp) reqA.Node.Nonce.A = ^uint64(0) client, _ = net.Dial("tcp", ln.Addr().String()) - msgpackCodec = codec.MsgpackSpecRpc.ClientCodec(client, mh) - rc = rpc.NewClientWithCodec(msgpackCodec) + rc = rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client)) err = rc.Call("DHT.Ping", reqA, respA2) if err == nil || !strings.Contains(err.Error(), "nonce public key not match") { t.Error(err) diff --git a/rpc/client.go b/rpc/client.go index b918e1b5e..6c6e2d500 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -18,18 +18,17 @@ package rpc import ( + "io/ioutil" "net" "net/rpc" - "io/ioutil" - "github.com/CovenantSQL/CovenantSQL/crypto/etls" "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/hashicorp/yamux" - "github.com/ugorji/go/codec" ) // Client is RPC client @@ -194,12 +193,7 @@ func InitClientConn(conn net.Conn) (client *Client, err error) { } } client.Conn = muxConn - mh := &codec.MsgpackHandle{ - WriteExt: true, - RawToString: true, - } - msgpackCodec := codec.MsgpackSpecRpc.ClientCodec(muxConn, mh) - client.Client = rpc.NewClientWithCodec(msgpackCodec) + client.Client = rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(muxConn)) client.RemoteAddr = conn.RemoteAddr().String() return client, nil diff --git a/rpc/rpcutil_test.go b/rpc/rpcutil_test.go index dc437343e..96c3242b3 100644 --- a/rpc/rpcutil_test.go +++ b/rpc/rpcutil_test.go @@ -21,12 +21,11 @@ import ( "os" "path/filepath" "runtime" + "strings" "sync" "testing" "time" - "strings" - "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/consistent" "github.com/CovenantSQL/CovenantSQL/crypto/kms" diff --git a/rpc/server.go b/rpc/server.go index 321d9169c..d2477c26e 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -26,9 +26,9 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/pow/cpuminer" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/hashicorp/yamux" - "github.com/ugorji/go/codec" ) // ServiceMap maps service name to service instance @@ -152,11 +152,7 @@ sessionLoop: break sessionLoop } log.Debugf("session accepted %d for %v", muxConn.StreamID(), remoteNodeID) - msgpackCodec := codec.MsgpackSpecRpc.ServerCodec(muxConn, &codec.MsgpackHandle{ - WriteExt: true, - RawToString: true, - }) - nodeAwareCodec := NewNodeAwareServerCodec(msgpackCodec, remoteNodeID) + nodeAwareCodec := NewNodeAwareServerCodec(utils.GetMsgPackServerCodec(muxConn), remoteNodeID) go s.rpcServer.ServeCodec(nodeAwareCodec) } } diff --git a/sqlchain/storage/storage.go b/sqlchain/storage/storage.go index d0190ba94..073343406 100644 --- a/sqlchain/storage/storage.go +++ b/sqlchain/storage/storage.go @@ -26,7 +26,6 @@ import ( "github.com/CovenantSQL/CovenantSQL/twopc" "github.com/CovenantSQL/CovenantSQL/utils/log" - // Register CovenantSQL/go-sqlite3-encrypt engine. _ "github.com/CovenantSQL/go-sqlite3-encrypt" ) diff --git a/sqlchain/types/block_test.go b/sqlchain/types/block_test.go index cfb40b505..2a0f74dee 100644 --- a/sqlchain/types/block_test.go +++ b/sqlchain/types/block_test.go @@ -17,12 +17,11 @@ package types import ( + "bytes" "math/big" "reflect" "testing" - "bytes" - "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/utils" diff --git a/twopc/twopc_test.go b/twopc/twopc_test.go index 6525d3b87..5e5975b42 100644 --- a/twopc/twopc_test.go +++ b/twopc/twopc_test.go @@ -18,16 +18,14 @@ package twopc import ( "context" + "errors" "fmt" + "net" "os" "sync" "testing" "time" - "net" - - "errors" - "github.com/CovenantSQL/CovenantSQL/crypto/etls" "github.com/CovenantSQL/CovenantSQL/rpc" "github.com/CovenantSQL/CovenantSQL/utils/log" diff --git a/utils/msgpack.go b/utils/msgpack.go index cd924b682..f443c9184 100644 --- a/utils/msgpack.go +++ b/utils/msgpack.go @@ -18,13 +18,15 @@ package utils import ( "bytes" + "net" + "net/rpc" "reflect" "github.com/ugorji/go/codec" ) var ( - msgpackHandle = &codec.MsgpackHandle{ + msgPackHandle = &codec.MsgpackHandle{ WriteExt: true, RawToString: true, } @@ -32,13 +34,13 @@ var ( // RegisterInterfaceToMsgPack binds interface decode/encode to specified implementation. func RegisterInterfaceToMsgPack(intf, impl reflect.Type) (err error) { - return msgpackHandle.Intf2Impl(intf, impl) + return msgPackHandle.Intf2Impl(intf, impl) } // DecodeMsgPack reverses the encode operation on a byte slice input. func DecodeMsgPack(buf []byte, out interface{}) error { r := bytes.NewBuffer(buf) - dec := codec.NewDecoder(r, msgpackHandle) + dec := codec.NewDecoder(r, msgPackHandle) return dec.Decode(out) } @@ -55,7 +57,17 @@ func DecodeMsgPackPlain(buf []byte, out interface{}) error { // EncodeMsgPack writes an encoded object to a new bytes buffer. func EncodeMsgPack(in interface{}) (*bytes.Buffer, error) { buf := bytes.NewBuffer(nil) - enc := codec.NewEncoder(buf, msgpackHandle) + enc := codec.NewEncoder(buf, msgPackHandle) err := enc.Encode(in) return buf, err } + +// GetMsgPackServerCodec returns msgpack server codec for connection. +func GetMsgPackServerCodec(c net.Conn) rpc.ServerCodec { + return codec.MsgpackSpecRpc.ServerCodec(c, msgPackHandle) +} + +// GetMsgPackClientCodec returns msgpack client codec for connection. +func GetMsgPackClientCodec(c net.Conn) rpc.ClientCodec { + return codec.MsgpackSpecRpc.ClientCodec(c, msgPackHandle) +} diff --git a/utils/net_test.go b/utils/net_test.go index cf458f123..d72bdd98c 100644 --- a/utils/net_test.go +++ b/utils/net_test.go @@ -17,12 +17,10 @@ package utils import ( - "testing" - - "net" - "context" "fmt" + "net" + "testing" "time" . "github.com/smartystreets/goconvey/convey" diff --git a/utils/path_test.go b/utils/path_test.go index c2363a593..b0c4fa8b3 100644 --- a/utils/path_test.go +++ b/utils/path_test.go @@ -17,11 +17,9 @@ package utils import ( - "testing" - "io/ioutil" - "os" + "testing" . "github.com/smartystreets/goconvey/convey" ) diff --git a/utils/profiler_test.go b/utils/profiler_test.go index aeba66718..80bc8b9ee 100644 --- a/utils/profiler_test.go +++ b/utils/profiler_test.go @@ -17,9 +17,8 @@ package utils import ( - "testing" - "os" + "testing" . "github.com/smartystreets/goconvey/convey" ) From e19e172afe2faa0da9766041306f4eca03bee980 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Sat, 20 Oct 2018 10:30:13 +0800 Subject: [PATCH 31/38] Fix some bugs in blockproducer chain --- blockproducer/chain.go | 61 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/blockproducer/chain.go b/blockproducer/chain.go index dafb8fd46..d369eb5d5 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -23,7 +23,8 @@ import ( "time" pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" - "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/crypto" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/crypto/kms" @@ -55,8 +56,8 @@ type Chain struct { rt *rt cl *rpc.Caller - blocksFromSelf chan *types.Block - blocksFromRPC chan *types.Block + blocksFromSelf chan *pt.Block + blocksFromRPC chan *pt.Block pendingTxs chan pi.Transaction stopCh chan struct{} } @@ -78,11 +79,10 @@ func NewChain(cfg *Config) (*Chain, error) { if err != nil { return nil, err } - enc, err := pubKey.MarshalHash() + accountAddress, err := crypto.PubKeyHash(pubKey) if err != nil { return nil, err } - accountAddress = proto.AccountAddress(hash.THashH(enc[:])) // create bucket for meta data err = db.Update(func(tx *bolt.Tx) (err error) { @@ -126,8 +126,8 @@ func NewChain(cfg *Config) (*Chain, error) { bi: newBlockIndex(), rt: newRuntime(cfg, accountAddress), cl: rpc.NewCaller(), - blocksFromSelf: make(chan *types.Block), - blocksFromRPC: make(chan *types.Block), + blocksFromSelf: make(chan *pt.Block), + blocksFromRPC: make(chan *pt.Block), pendingTxs: make(chan pi.Transaction), stopCh: make(chan struct{}), } @@ -163,11 +163,10 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { if err != nil { return nil, err } - enc, err := pubKey.MarshalHash() + accountAddress, err = crypto.PubKeyHash(pubKey) if err != nil { return nil, err } - accountAddress = proto.AccountAddress(hash.THashH(enc[:])) chain = &Chain{ db: db, @@ -175,8 +174,8 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { bi: newBlockIndex(), rt: newRuntime(cfg, accountAddress), cl: rpc.NewCaller(), - blocksFromSelf: make(chan *types.Block), - blocksFromRPC: make(chan *types.Block), + blocksFromSelf: make(chan *pt.Block), + blocksFromRPC: make(chan *pt.Block), pendingTxs: make(chan pi.Transaction), stopCh: make(chan struct{}), } @@ -200,9 +199,9 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { nodes := make([]blockNode, blocks.Stats().KeyN) if err = blocks.ForEach(func(k, v []byte) (err error) { - block := &types.Block{} + block := &pt.Block{} if err = utils.DecodeMsgPack(v, block); err != nil { - log.Errorf("loadeing block: %v", err) + log.Errorf("loading block: %v", err) return err } @@ -217,7 +216,7 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { parent = last } else { - parent = chain.bi.lookupBlock(block.SignedHeader.BlockHash) + parent = chain.bi.lookupBlock(block.SignedHeader.ParentHash) if parent == nil { return ErrParentNotFound @@ -225,6 +224,7 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { } nodes[index].initBlockNode(block, parent) + chain.bi.addBlock(&nodes[index]) last = &nodes[index] index++ return err @@ -247,7 +247,7 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { } // checkBlock has following steps: 1. check parent block 2. checkTx 2. merkle tree 3. Hash 4. Signature. -func (c *Chain) checkBlock(b *types.Block) (err error) { +func (c *Chain) checkBlock(b *pt.Block) (err error) { // TODO(lambda): process block fork if !b.SignedHeader.ParentHash.IsEqual(c.rt.getHead().getHeader()) { log.WithFields(log.Fields{ @@ -275,7 +275,7 @@ func (c *Chain) checkBlock(b *types.Block) (err error) { return nil } -func (c *Chain) pushBlockWithoutCheck(b *types.Block) error { +func (c *Chain) pushBlockWithoutCheck(b *pt.Block) error { h := c.rt.getHeightFromTime(b.Timestamp()) node := newBlockNode(h, b, c.rt.getHead().getNode()) state := &State{ @@ -319,7 +319,7 @@ func (c *Chain) pushBlockWithoutCheck(b *types.Block) error { return nil } -func (c *Chain) pushGenesisBlock(b *types.Block) (err error) { +func (c *Chain) pushGenesisBlock(b *pt.Block) (err error) { err = c.pushBlockWithoutCheck(b) if err != nil { log.Errorf("push genesis block failed: %v", err) @@ -327,7 +327,7 @@ func (c *Chain) pushGenesisBlock(b *types.Block) (err error) { return } -func (c *Chain) pushBlock(b *types.Block) error { +func (c *Chain) pushBlock(b *pt.Block) error { err := c.checkBlock(b) if err != nil { return err @@ -347,9 +347,9 @@ func (c *Chain) produceBlock(now time.Time) error { return err } - b := &types.Block{ - SignedHeader: types.SignedHeader{ - Header: types.Header{ + b := &pt.Block{ + SignedHeader: pt.SignedHeader{ + Header: pt.Header{ Version: blockVersion, Producer: c.rt.accountAddress, ParentHash: *c.rt.getHead().getHeader(), @@ -403,7 +403,7 @@ func (c *Chain) produceBlock(now time.Time) error { return err } -func (c *Chain) produceBilling(br *types.BillingRequest) (_ *types.BillingRequest, err error) { +func (c *Chain) produceBilling(br *pt.BillingRequest) (_ *pt.BillingRequest, err error) { // TODO(lambda): simplify the function if err = c.checkBillingRequest(br); err != nil { return @@ -443,8 +443,8 @@ func (c *Chain) produceBilling(br *types.BillingRequest) (_ *types.BillingReques return } var ( - tc = types.NewBillingHeader(nc, br, accountAddress, receivers, fees, rewards) - tb = types.NewBilling(tc) + tc = pt.NewBillingHeader(nc, br, accountAddress, receivers, fees, rewards) + tb = pt.NewBilling(tc) ) if err = tb.Sign(privKey); err != nil { return @@ -461,7 +461,7 @@ func (c *Chain) produceBilling(br *types.BillingRequest) (_ *types.BillingReques // 1. period of sqlchain; // 2. request's hash // 3. miners' signatures. -func (c *Chain) checkBillingRequest(br *types.BillingRequest) (err error) { +func (c *Chain) checkBillingRequest(br *pt.BillingRequest) (err error) { // period of sqlchain; // TODO(lambda): get and check period and miner list of specific sqlchain @@ -469,13 +469,13 @@ func (c *Chain) checkBillingRequest(br *types.BillingRequest) (err error) { return } -func (c *Chain) fetchBlockByHeight(h uint32) (*types.Block, error) { +func (c *Chain) fetchBlockByHeight(h uint32) (*pt.Block, error) { node := c.rt.getHead().getNode().ancestor(h) if node == nil { return nil, ErrNoSuchBlock } - b := &types.Block{} + b := &pt.Block{} k := node.indexKey() err := c.db.View(func(tx *bolt.Tx) error { @@ -560,7 +560,7 @@ func (c *Chain) Start() error { func (c *Chain) processBlocks() { rsCh := make(chan struct{}) rsWG := &sync.WaitGroup{} - returnStash := func(stash []*types.Block) { + returnStash := func(stash []*pt.Block) { defer rsWG.Done() for _, block := range stash { select { @@ -577,7 +577,7 @@ func (c *Chain) processBlocks() { c.rt.wg.Done() }() - var stash []*types.Block + var stash []*pt.Block for { select { case block := <-c.blocksFromSelf: @@ -592,7 +592,7 @@ func (c *Chain) processBlocks() { if h := c.rt.getHeightFromTime(block.Timestamp()); h > c.rt.getNextTurn()-1 { // Stash newer blocks for later check if stash == nil { - stash = make([]*types.Block, 0) + stash = make([]*pt.Block, 0) } stash = append(stash, block) } else { @@ -680,7 +680,6 @@ func (c *Chain) syncHead() { "index": c.rt.index, "next_turn": c.rt.getNextTurn(), "height": c.rt.getHead().getHeight(), - "count": c.rt.getHead().getNode().count, }).Debugf("sync header") if h := c.rt.getNextTurn() - 1; c.rt.getHead().getHeight() < h { var err error From 6e06b841ef3a58d135104af3903e16bff1a25289 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Mon, 22 Oct 2018 10:02:49 +0800 Subject: [PATCH 32/38] Remove AddTxTransfer rpc, use unified AddTx instead --- blockproducer/rpc.go | 17 ----------------- cmd/cql-faucet/verifier.go | 4 ++-- route/acl.go | 4 ---- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 8f20c204a..897971523 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -97,12 +97,6 @@ type AddTxResp struct { proto.Envelope } -// AddTxTransferReq defines a request of AddTxTransfer RPC method. -type AddTxTransferReq struct { - proto.Envelope - Tx *types.Transfer -} - // QueryAccountStableBalanceReq defines a request of the QueryAccountStableBalance RPC method. type QueryAccountStableBalanceReq struct { proto.Envelope @@ -182,17 +176,6 @@ func (s *ChainRPCService) AddTx(req *AddTxReq, resp *AddTxResp) (err error) { return } -// AddTxTransfer is the RPC method to add a transfer transaction. -func (s *ChainRPCService) AddTxTransfer(req *AddTxTransferReq, resp *AddTxResp) (err error) { - if req.Tx == nil { - return ErrUnknownTransactionType - } - - s.chain.pendingTxs <- req.Tx - - return -} - // QueryAccountStableBalance is the RPC method to query acccount stable coin balance. func (s *ChainRPCService) QueryAccountStableBalance( req *QueryAccountStableBalanceReq, resp *QueryAccountStableBalanceResp) (err error, diff --git a/cmd/cql-faucet/verifier.go b/cmd/cql-faucet/verifier.go index 07c41929b..d79f82286 100644 --- a/cmd/cql-faucet/verifier.go +++ b/cmd/cql-faucet/verifier.go @@ -259,7 +259,7 @@ func (v *Verifier) dispenseOne(r *applicationRecord) (err error) { return } - req := &bp.AddTxTransferReq{} + req := &bp.AddTxReq{} resp := &bp.AddTxResp{} req.Tx = pt.NewTransfer( &pt.TransferHeader{ @@ -274,7 +274,7 @@ func (v *Verifier) dispenseOne(r *applicationRecord) (err error) { return } - if err = requestBP(route.MCCAddTxTransfer.String(), req, resp); err != nil { + if err = requestBP(route.MCCAddTx.String(), req, resp); err != nil { // add transaction failed, try again log.Warningf("send transaction failed: %v", err) diff --git a/route/acl.go b/route/acl.go index 6762f19b8..c1f054239 100644 --- a/route/acl.go +++ b/route/acl.go @@ -127,8 +127,6 @@ const ( MCCNextAccountNonce // MCCAddTx is used by block producer main chain to upload transaction MCCAddTx - // MCCAddTxTransfer is used by block producer main chain to upload transfer transaction - MCCAddTxTransfer // MCCQueryAccountStableBalance is used by block producer to provide account stable coin balance MCCQueryAccountStableBalance // MCCQueryAccountCovenantBalance is used by block producer to provide account covenant coin balance @@ -217,8 +215,6 @@ func (s RemoteFunc) String() string { return "MCC.NextAccountNonce" case MCCAddTx: return "MCC.AddTx" - case MCCAddTxTransfer: - return "MCC.AddTxTransfer" case MCCQueryAccountStableBalance: return "MCC.QueryAccountStableBalance" case MCCQueryAccountCovenantBalance: From 14a9363c57e56424016957cbdaf862df276af051 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Mon, 22 Oct 2018 13:58:53 +0800 Subject: [PATCH 33/38] Refactor chain functions in blockproducer chain --- blockproducer/blockindex.go | 4 ++-- blockproducer/blockindex_test.go | 2 +- blockproducer/chain.go | 12 ++++++------ blockproducer/chain_test.go | 6 +++--- blockproducer/types/block.go | 10 ++++++++++ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/blockproducer/blockindex.go b/blockproducer/blockindex.go index 02891bcae..40347ad15 100644 --- a/blockproducer/blockindex.go +++ b/blockproducer/blockindex.go @@ -107,9 +107,9 @@ func (bi *blockIndex) hasBlock(h hash.Hash) bool { return has } -func (bi *blockIndex) lookupBlock(h hash.Hash) *blockNode { +func (bi *blockIndex) lookupNode(h *hash.Hash) *blockNode { bi.mu.RLock() defer bi.mu.RUnlock() - return bi.index[h] + return bi.index[*h] } diff --git a/blockproducer/blockindex_test.go b/blockproducer/blockindex_test.go index 4a244e993..d185cbfb7 100644 --- a/blockproducer/blockindex_test.go +++ b/blockproducer/blockindex_test.go @@ -138,7 +138,7 @@ func TestIndexBlock(t *testing.T) { t.Fatalf("lack of block index: %v", bn1) } - bn3 := bi.lookupBlock(bn0.hash) + bn3 := bi.lookupNode(&bn0.hash) if !reflect.DeepEqual(bn0, bn3) { t.Fatalf("two values should be equal: \n\tv0=%+v\n\tv1=%+v", bn0, bn3) } diff --git a/blockproducer/chain.go b/blockproducer/chain.go index d369eb5d5..09f2e3d14 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -209,14 +209,14 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { if last == nil { // TODO(lambda): check genesis block - } else if block.SignedHeader.ParentHash.IsEqual(&last.hash) { + } else if block.ParentHash().IsEqual(&last.hash) { if err = block.SignedHeader.Verify(); err != nil { return err } parent = last } else { - parent = chain.bi.lookupBlock(block.SignedHeader.ParentHash) + parent = chain.bi.lookupNode(block.ParentHash()) if parent == nil { return ErrParentNotFound @@ -249,11 +249,11 @@ func LoadChain(cfg *Config) (chain *Chain, err error) { // checkBlock has following steps: 1. check parent block 2. checkTx 2. merkle tree 3. Hash 4. Signature. func (c *Chain) checkBlock(b *pt.Block) (err error) { // TODO(lambda): process block fork - if !b.SignedHeader.ParentHash.IsEqual(c.rt.getHead().getHeader()) { + if !b.ParentHash().IsEqual(c.rt.getHead().getHeader()) { log.WithFields(log.Fields{ "head": c.rt.getHead().getHeader().String(), "height": c.rt.getHead().getHeight(), - "received_parent": b.SignedHeader.ParentHash, + "received_parent": b.ParentHash(), }).Debug("invalid parent") return ErrParentNotMatch } @@ -268,7 +268,7 @@ func (c *Chain) checkBlock(b *pt.Block) (err error) { return err } h := hash.THashH(enc) - if !b.SignedHeader.BlockHash.IsEqual(&h) { + if !b.BlockHash().IsEqual(&h) { return ErrInvalidHash } @@ -390,7 +390,7 @@ func (c *Chain) produceBlock(now time.Time) error { "peer": c.rt.getPeerInfoString(), "curr_turn": c.rt.getNextTurn(), "now_time": time.Now().UTC().Format(time.RFC3339Nano), - "block_hash": b.SignedHeader.BlockHash, + "block_hash": b.BlockHash(), }).WithError(err).Error( "Failed to advise new block") } else { diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index b4207f347..1b41531d5 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -101,7 +101,7 @@ func TestChain(t *testing.T) { t.Logf("Chain state: head = %s, height = %d, turn = %d, nextturnstart = %s, ismyturn = %t", chain.rt.getHead().getHeader(), chain.rt.getHead().getHeight(), chain.rt.nextTurn, chain.rt.chainInitTime.Add( - chain.rt.period*time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), + chain.rt.period * time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), chain.rt.isMyTurn()) // chain will receive blocks and tx @@ -162,8 +162,8 @@ func TestChain(t *testing.T) { t.Logf("Pushed new block: height = %d, %s <- %s", chain.rt.getHead().getHeight(), - block.SignedHeader.ParentHash, - block.SignedHeader.BlockHash) + block.ParentHash(), + block.BlockHash()) if chain.rt.getHead().getHeight() >= testPeriodNumber { break diff --git a/blockproducer/types/block.go b/blockproducer/types/block.go index 2feb2ec6b..a2f88d642 100644 --- a/blockproducer/types/block.go +++ b/blockproducer/types/block.go @@ -125,3 +125,13 @@ func (b *Block) Timestamp() time.Time { func (b *Block) Producer() proto.AccountAddress { return b.SignedHeader.Producer } + +// ParentHash returns the parent hash field of the block header. +func (b *Block) ParentHash() *hash.Hash { + return &b.SignedHeader.ParentHash +} + +// BlockHash returns the parent hash field of the block header. +func (b *Block) BlockHash() *hash.Hash { + return &b.SignedHeader.BlockHash +} From 93f64d958cb58ee6236844a0b5c35d6a4110a1f2 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Mon, 22 Oct 2018 18:14:14 +0800 Subject: [PATCH 34/38] Count block nodes using count field in blockNode --- blockproducer/blockindex.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockproducer/blockindex.go b/blockproducer/blockindex.go index 40347ad15..ec3b9327d 100644 --- a/blockproducer/blockindex.go +++ b/blockproducer/blockindex.go @@ -35,12 +35,12 @@ func newBlockNode(h uint32, block *types.Block, parent *blockNode) *blockNode { var count uint32 if parent != nil { - count = parent.height + 1 + count = parent.count + 1 } else { count = 0 } bn := &blockNode{ - hash: block.SignedHeader.BlockHash, + hash: *block.BlockHash(), parent: parent, height: h, count: count, From 275ca6902e8b597aa0f17080a64d38fd83ee69a9 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Mon, 22 Oct 2018 22:05:45 +0800 Subject: [PATCH 35/38] Update go-mysql dep to github.com/CovenantSQL/go-mysql --- Gopkg.lock | 37 +- Gopkg.toml | 5 + vendor/github.com/miekg/dns/README.md | 1 + vendor/github.com/miekg/dns/dnssec_keyscan.go | 168 ++- vendor/github.com/miekg/dns/generate.go | 299 +++-- vendor/github.com/miekg/dns/privaterr.go | 4 +- vendor/github.com/miekg/dns/scan.go | 1003 +++++++++----- vendor/github.com/miekg/dns/scan_rr.go | 730 ++++++----- vendor/github.com/miekg/dns/scanner.go | 56 - vendor/github.com/miekg/dns/version.go | 2 +- .../client_golang/prometheus/http.go | 105 +- .../prometheus/common/expfmt/text_create.go | 36 +- .../prometheus/common/model/time.go | 2 +- vendor/github.com/satori/go.uuid/README.md | 3 +- vendor/github.com/satori/go.uuid/generator.go | 6 +- .../siddontang/go-mysql/server/auth.go | 68 +- vendor/github.com/xo/tblfmt/go.mod | 5 +- vendor/github.com/xo/tblfmt/go.sum | 2 + vendor/golang.org/x/sys/unix/asm_aix_ppc64.s | 17 + vendor/golang.org/x/sys/unix/mkall.sh | 14 +- ...{mksyscall_aix.pl => mksyscall_aix_ppc.pl} | 5 +- .../x/sys/unix/mksyscall_aix_ppc64.pl | 579 ++++++++ .../golang.org/x/sys/unix/openbsd_pledge.go | 6 +- vendor/golang.org/x/sys/unix/syscall_aix.go | 31 +- .../golang.org/x/sys/unix/syscall_freebsd.go | 310 ++++- .../x/sys/unix/syscall_openbsd_386.go | 4 + .../x/sys/unix/syscall_openbsd_arm.go | 4 + vendor/golang.org/x/sys/unix/types_freebsd.go | 65 +- .../x/sys/unix/zerrors_linux_386.go | 13 +- .../x/sys/unix/zerrors_linux_amd64.go | 13 +- .../x/sys/unix/zerrors_linux_arm.go | 13 +- .../x/sys/unix/zerrors_linux_arm64.go | 13 +- .../x/sys/unix/zerrors_linux_mips.go | 13 +- .../x/sys/unix/zerrors_linux_mips64.go | 13 +- .../x/sys/unix/zerrors_linux_mips64le.go | 13 +- .../x/sys/unix/zerrors_linux_mipsle.go | 13 +- .../x/sys/unix/zerrors_linux_ppc64.go | 13 +- .../x/sys/unix/zerrors_linux_ppc64le.go | 13 +- .../x/sys/unix/zerrors_linux_riscv64.go | 13 +- .../x/sys/unix/zerrors_linux_s390x.go | 13 +- .../golang.org/x/sys/unix/zsyscall_aix_ppc.go | 97 +- .../x/sys/unix/zsyscall_aix_ppc64.go | 1073 +++++++-------- .../x/sys/unix/zsyscall_aix_ppc64_gc.go | 1162 +++++++++++++++++ .../x/sys/unix/zsyscall_aix_ppc64_gccgo.go | 1042 +++++++++++++++ .../x/sys/unix/zsyscall_freebsd_386.go | 102 +- .../x/sys/unix/zsyscall_freebsd_amd64.go | 102 +- .../x/sys/unix/zsyscall_freebsd_arm.go | 102 +- .../x/sys/unix/zsysnum_linux_arm.go | 1 + .../x/sys/unix/zsysnum_linux_arm64.go | 1 + .../x/sys/unix/zsysnum_linux_riscv64.go | 1 + .../x/sys/unix/zsysnum_openbsd_386.go | 25 +- .../x/sys/unix/zsysnum_openbsd_arm.go | 13 +- .../x/sys/unix/ztypes_freebsd_386.go | 255 ++-- .../x/sys/unix/ztypes_freebsd_amd64.go | 273 ++-- .../x/sys/unix/ztypes_freebsd_arm.go | 277 ++-- .../golang.org/x/sys/unix/ztypes_linux_386.go | 23 +- .../x/sys/unix/ztypes_linux_amd64.go | 23 +- .../golang.org/x/sys/unix/ztypes_linux_arm.go | 23 +- .../x/sys/unix/ztypes_linux_arm64.go | 23 +- .../x/sys/unix/ztypes_linux_mips.go | 23 +- .../x/sys/unix/ztypes_linux_mips64.go | 23 +- .../x/sys/unix/ztypes_linux_mips64le.go | 23 +- .../x/sys/unix/ztypes_linux_mipsle.go | 23 +- .../x/sys/unix/ztypes_linux_ppc64.go | 23 +- .../x/sys/unix/ztypes_linux_ppc64le.go | 23 +- .../x/sys/unix/ztypes_linux_riscv64.go | 23 +- .../x/sys/unix/ztypes_linux_s390x.go | 23 +- 67 files changed, 6322 insertions(+), 2203 deletions(-) delete mode 100644 vendor/github.com/miekg/dns/scanner.go create mode 100644 vendor/golang.org/x/sys/unix/asm_aix_ppc64.s rename vendor/golang.org/x/sys/unix/{mksyscall_aix.pl => mksyscall_aix_ppc.pl} (98%) mode change 100644 => 100755 create mode 100755 vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl create mode 100644 vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go create mode 100644 vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go diff --git a/Gopkg.lock b/Gopkg.lock index 4fdec7120..c11cf6ec9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -192,7 +192,7 @@ name = "github.com/gopherjs/gopherjs" packages = ["js"] pruneopts = "UT" - revision = "1babbf986f6fcb1156d0646cdba5c4f81bc32849" + revision = "0766667cb4d1cfb8d5fde1fe210ae41ead3cf589" [[projects]] digest = "1:c79fb010be38a59d657c48c6ba1d003a8aa651fa56b579d959d74573b7dff8e1" @@ -307,12 +307,12 @@ version = "v1.0.1" [[projects]] - digest = "1:57689550840d285f2da9e85356a66e626592a8b6f1170d7f2482438e64fe82e3" + digest = "1:c22d250c583ec1136ecad8b74a43f408c08ddbbcbae715341ec4a49f332628e0" name = "github.com/miekg/dns" packages = ["."] pruneopts = "UT" - revision = "d74956db7b5b20451796774572d0f5a0222e377a" - version = "v1.0.13" + revision = "915ca3d5ffd945235828a097c917311a9d86ebb4" + version = "v1.0.14" [[projects]] branch = "master" @@ -348,14 +348,14 @@ [[projects]] branch = "master" - digest = "1:f43f7e80e273179b98af510dd453d184c7860920d6f9aa5c89e06aed0494a7a8" + digest = "1:f696f304d2a14745859a153f1041b66e0e2cf150eff731beb6431e93e27ddc5c" name = "github.com/prometheus/client_golang" packages = [ "prometheus", "prometheus/internal", ] pruneopts = "UT" - revision = "1cafe34db7fdec6022e17e00e1c1ea501022f3e4" + revision = "16f375c74db6ccf880e1cd9c6c6087a6d58e5d12" [[projects]] branch = "master" @@ -367,7 +367,7 @@ [[projects]] branch = "master" - digest = "1:95ed48ec01b571d453b17ed631c7b65be39ced2b5082f1426a2fa6991799846f" + digest = "1:6366b518dc6e520027f67ad03792b99e370468aac47c4102bddd56ae6ce780e5" name = "github.com/prometheus/common" packages = [ "expfmt", @@ -376,7 +376,7 @@ "version", ] pruneopts = "UT" - revision = "bcb74de08d37a417cb6789eec1d6c810040f0470" + revision = "7e9e6cabbd393fc208072eedef99188d0ce788b6" [[projects]] branch = "master" @@ -393,11 +393,11 @@ [[projects]] branch = "master" - digest = "1:ff6b0586c0621a76832cf783eee58cbb9d9795d2ce8acbc199a4131db11c42a9" + digest = "1:dd6ba1917df517806c9dcee5c87f15643c9b1ca6260d5b3f25eb863c6fe092ce" name = "github.com/satori/go.uuid" packages = ["."] pruneopts = "UT" - revision = "36e9d2ebbde5e3f13ab2e25625fd453271d6522e" + revision = "8ccf5352a842c034b1a69f28c863aff9b1cdb116" [[projects]] branch = "master" @@ -423,7 +423,7 @@ [[projects]] branch = "master" - digest = "1:a730590f80ebe31a7c88a072500766c6094a14b03e0c6931e4a63a13f227edc4" + digest = "1:a2781c62eecc87e942c9e9e84e5aeeba9957b6cd2f9b78f536d6f2a795577950" name = "github.com/siddontang/go-mysql" packages = [ "mysql", @@ -431,7 +431,8 @@ "server", ] pruneopts = "UT" - revision = "c8bed9e1e90b2121165ad80fe85a34ceff169999" + revision = "a2685e59bda4b33ae8a7c95ace99cf2ea7804db3" + source = "github.com/CovenantSQL/go-mysql" [[projects]] digest = "1:3f53e9e4dfbb664cd62940c9c4b65a2171c66acd0b7621a1a6b8e78513525a52" @@ -539,11 +540,11 @@ [[projects]] branch = "master" - digest = "1:8a6b9b1c86f610eb347e6e5e42af0fc9aff52427c619dd70e9e61a79c6114106" + digest = "1:3863946ace74cbd518a33a2e8dd145a13aba1fc37a0e89788154083f183fca11" name = "github.com/xo/tblfmt" packages = ["."] pruneopts = "UT" - revision = "3ae3311c5ac954b9ec8a89eed14e395abbb069e4" + revision = "e82d5611beb24993cc6afc59cdacf6e598891d12" [[projects]] branch = "master" @@ -568,7 +569,7 @@ "text", ] pruneopts = "UT" - revision = "ee0ef60c5b0883dcb5caa67d5317c56d6389e779" + revision = "f0d1f2ffcfd924cccb45128a0fd7bdc06cad72b4" [[projects]] digest = "1:4619abe2e9ceabced45ff40a4826866c48f264bb58384efe799a8fb83c2256e0" @@ -604,18 +605,18 @@ "ipv6", ] pruneopts = "UT" - revision = "49bb7cea24b1df9410e1712aa6433dae904ff66a" + revision = "04a2e542c03f1d053ab3e4d6e5abcd4b66e2be8e" [[projects]] branch = "master" - digest = "1:f5aa274a0377f85735edc7fedfb0811d3cbc20af91633797cb359e29c3272271" + digest = "1:eb2ed765d17a2cedfc307cf8beda6f0857ad378431a4d8f2726c419f3d7105de" name = "golang.org/x/sys" packages = [ "unix", "windows", ] pruneopts = "UT" - revision = "fa43e7bc11baaae89f3f902b2b4d832b68234844" + revision = "8a28ead16f52c8aaeffbf79239b251dfdf6c4f96" [[projects]] digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" diff --git a/Gopkg.toml b/Gopkg.toml index 6c483cb82..e3328ec22 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -60,6 +60,11 @@ name = "github.com/CovenantSQL/xurls" branch = "master" +[[override]] + name = "github.com/siddontang/go-mysql" + source = "github.com/CovenantSQL/go-mysql" + branch = "master" + [prune] go-tests = true unused-packages = true diff --git a/vendor/github.com/miekg/dns/README.md b/vendor/github.com/miekg/dns/README.md index 77874642b..7f1aaa5de 100644 --- a/vendor/github.com/miekg/dns/README.md +++ b/vendor/github.com/miekg/dns/README.md @@ -67,6 +67,7 @@ A not-so-up-to-date-list-that-may-be-actually-current: * https://github.com/xor-gate/sshfp * https://github.com/rs/dnstrace * https://blitiri.com.ar/p/dnss ([github mirror](https://github.com/albertito/dnss)) +* https://github.com/semihalev/sdns Send pull request if you want to be listed here. diff --git a/vendor/github.com/miekg/dns/dnssec_keyscan.go b/vendor/github.com/miekg/dns/dnssec_keyscan.go index 719198659..5e6542230 100644 --- a/vendor/github.com/miekg/dns/dnssec_keyscan.go +++ b/vendor/github.com/miekg/dns/dnssec_keyscan.go @@ -1,6 +1,7 @@ package dns import ( + "bufio" "crypto" "crypto/dsa" "crypto/ecdsa" @@ -194,23 +195,12 @@ func readPrivateKeyED25519(m map[string]string) (ed25519.PrivateKey, error) { // parseKey reads a private key from r. It returns a map[string]string, // with the key-value pairs, or an error when the file is not correct. func parseKey(r io.Reader, file string) (map[string]string, error) { - s, cancel := scanInit(r) m := make(map[string]string) - c := make(chan lex) - k := "" - defer func() { - cancel() - // zlexer can send up to two tokens, the next one and possibly 1 remainders. - // Do a non-blocking read. - _, ok := <-c - _, ok = <-c - if !ok { - // too bad - } - }() - // Start the lexer - go klexer(s, c) - for l := range c { + var k string + + c := newKLexer(r) + + for l, ok := c.Next(); ok; l, ok = c.Next() { // It should alternate switch l.value { case zKey: @@ -219,41 +209,111 @@ func parseKey(r io.Reader, file string) (map[string]string, error) { if k == "" { return nil, &ParseError{file, "no private key seen", l} } - //println("Setting", strings.ToLower(k), "to", l.token, "b") + m[strings.ToLower(k)] = l.token k = "" } } + + // Surface any read errors from r. + if err := c.Err(); err != nil { + return nil, &ParseError{file: file, err: err.Error()} + } + return m, nil } -// klexer scans the sourcefile and returns tokens on the channel c. -func klexer(s *scan, c chan lex) { - var l lex - str := "" // Hold the current read text - commt := false - key := true - x, err := s.tokenText() - defer close(c) - for err == nil { - l.column = s.position.Column - l.line = s.position.Line +type klexer struct { + br io.ByteReader + + readErr error + + line int + column int + + key bool + + eol bool // end-of-line +} + +func newKLexer(r io.Reader) *klexer { + br, ok := r.(io.ByteReader) + if !ok { + br = bufio.NewReaderSize(r, 1024) + } + + return &klexer{ + br: br, + + line: 1, + + key: true, + } +} + +func (kl *klexer) Err() error { + if kl.readErr == io.EOF { + return nil + } + + return kl.readErr +} + +// readByte returns the next byte from the input +func (kl *klexer) readByte() (byte, bool) { + if kl.readErr != nil { + return 0, false + } + + c, err := kl.br.ReadByte() + if err != nil { + kl.readErr = err + return 0, false + } + + // delay the newline handling until the next token is delivered, + // fixes off-by-one errors when reporting a parse error. + if kl.eol { + kl.line++ + kl.column = 0 + kl.eol = false + } + + if c == '\n' { + kl.eol = true + } else { + kl.column++ + } + + return c, true +} + +func (kl *klexer) Next() (lex, bool) { + var ( + l lex + + str strings.Builder + + commt bool + ) + + for x, ok := kl.readByte(); ok; x, ok = kl.readByte() { + l.line, l.column = kl.line, kl.column + switch x { case ':': - if commt { + if commt || !kl.key { break } - l.token = str - if key { - l.value = zKey - c <- l - // Next token is a space, eat it - s.tokenText() - key = false - str = "" - } else { - l.value = zValue - } + + kl.key = false + + // Next token is a space, eat it + kl.readByte() + + l.value = zKey + l.token = str.String() + return l, true case ';': commt = true case '\n': @@ -261,24 +321,32 @@ func klexer(s *scan, c chan lex) { // Reset a comment commt = false } + + kl.key = true + l.value = zValue - l.token = str - c <- l - str = "" - commt = false - key = true + l.token = str.String() + return l, true default: if commt { break } - str += string(x) + + str.WriteByte(x) } - x, err = s.tokenText() } - if len(str) > 0 { + + if kl.readErr != nil && kl.readErr != io.EOF { + // Don't return any tokens after a read error occurs. + return lex{value: zEOF}, false + } + + if str.Len() > 0 { // Send remainder - l.token = str l.value = zValue - c <- l + l.token = str.String() + return l, true } + + return lex{value: zEOF}, false } diff --git a/vendor/github.com/miekg/dns/generate.go b/vendor/github.com/miekg/dns/generate.go index 91d928c83..97bc39f58 100644 --- a/vendor/github.com/miekg/dns/generate.go +++ b/vendor/github.com/miekg/dns/generate.go @@ -2,8 +2,8 @@ package dns import ( "bytes" - "errors" "fmt" + "io" "strconv" "strings" ) @@ -18,154 +18,225 @@ import ( // * rhs (rdata) // But we are lazy here, only the range is parsed *all* occurrences // of $ after that are interpreted. -// Any error are returned as a string value, the empty string signals -// "no error". -func generate(l lex, c chan lex, t chan *Token, o string) string { +func (zp *ZoneParser) generate(l lex) (RR, bool) { + token := l.token step := 1 - if i := strings.IndexAny(l.token, "/"); i != -1 { - if i+1 == len(l.token) { - return "bad step in $GENERATE range" + if i := strings.IndexByte(token, '/'); i >= 0 { + if i+1 == len(token) { + return zp.setParseError("bad step in $GENERATE range", l) } - if s, err := strconv.Atoi(l.token[i+1:]); err == nil { - if s < 0 { - return "bad step in $GENERATE range" - } - step = s - } else { - return "bad step in $GENERATE range" + + s, err := strconv.Atoi(token[i+1:]) + if err != nil || s <= 0 { + return zp.setParseError("bad step in $GENERATE range", l) } - l.token = l.token[:i] + + step = s + token = token[:i] } - sx := strings.SplitN(l.token, "-", 2) + + sx := strings.SplitN(token, "-", 2) if len(sx) != 2 { - return "bad start-stop in $GENERATE range" + return zp.setParseError("bad start-stop in $GENERATE range", l) } + start, err := strconv.Atoi(sx[0]) if err != nil { - return "bad start in $GENERATE range" + return zp.setParseError("bad start in $GENERATE range", l) } + end, err := strconv.Atoi(sx[1]) if err != nil { - return "bad stop in $GENERATE range" + return zp.setParseError("bad stop in $GENERATE range", l) } if end < 0 || start < 0 || end < start { - return "bad range in $GENERATE range" + return zp.setParseError("bad range in $GENERATE range", l) } - <-c // _BLANK + zp.c.Next() // _BLANK + // Create a complete new string, which we then parse again. - s := "" -BuildRR: - l = <-c - if l.value != zNewline && l.value != zEOF { + var s string + for l, ok := zp.c.Next(); ok; l, ok = zp.c.Next() { + if l.err { + return zp.setParseError("bad data in $GENERATE directive", l) + } + if l.value == zNewline { + break + } + s += l.token - goto BuildRR - } - for i := start; i <= end; i += step { - var ( - escape bool - dom bytes.Buffer - mod string - err error - offset int - ) - - for j := 0; j < len(s); j++ { // No 'range' because we need to jump around - switch s[j] { - case '\\': - if escape { - dom.WriteByte('\\') - escape = false - continue - } - escape = true - case '$': - mod = "%d" - offset = 0 - if escape { - dom.WriteByte('$') - escape = false - continue - } - escape = false - if j+1 >= len(s) { // End of the string - dom.WriteString(fmt.Sprintf(mod, i+offset)) - continue - } else { - if s[j+1] == '$' { - dom.WriteByte('$') - j++ - continue - } - } - // Search for { and } - if s[j+1] == '{' { // Modifier block - sep := strings.Index(s[j+2:], "}") - if sep == -1 { - return "bad modifier in $GENERATE" - } - mod, offset, err = modToPrintf(s[j+2 : j+2+sep]) - if err != nil { - return err.Error() - } else if start + offset < 0 || end + offset > 1<<31-1 { - return "bad offset in $GENERATE" - } - j += 2 + sep // Jump to it - } - dom.WriteString(fmt.Sprintf(mod, i+offset)) - default: - if escape { // Pretty useless here - escape = false - continue - } - dom.WriteByte(s[j]) + } + + r := &generateReader{ + s: s, + + cur: start, + start: start, + end: end, + step: step, + + file: zp.file, + lex: &l, + } + zp.sub = NewZoneParser(r, zp.origin, zp.file) + zp.sub.includeDepth, zp.sub.includeAllowed = zp.includeDepth, zp.includeAllowed + zp.sub.SetDefaultTTL(defaultTtl) + return zp.subNext() +} + +type generateReader struct { + s string + si int + + cur int + start int + end int + step int + + mod bytes.Buffer + + escape bool + + eof bool + + file string + lex *lex +} + +func (r *generateReader) parseError(msg string, end int) *ParseError { + r.eof = true // Make errors sticky. + + l := *r.lex + l.token = r.s[r.si-1 : end] + l.column += r.si // l.column starts one zBLANK before r.s + + return &ParseError{r.file, msg, l} +} + +func (r *generateReader) Read(p []byte) (int, error) { + // NewZLexer, through NewZoneParser, should use ReadByte and + // not end up here. + + panic("not implemented") +} + +func (r *generateReader) ReadByte() (byte, error) { + if r.eof { + return 0, io.EOF + } + if r.mod.Len() > 0 { + return r.mod.ReadByte() + } + + if r.si >= len(r.s) { + r.si = 0 + r.cur += r.step + + r.eof = r.cur > r.end || r.cur < 0 + return '\n', nil + } + + si := r.si + r.si++ + + switch r.s[si] { + case '\\': + if r.escape { + r.escape = false + return '\\', nil + } + + r.escape = true + return r.ReadByte() + case '$': + if r.escape { + r.escape = false + return '$', nil + } + + mod := "%d" + + if si >= len(r.s)-1 { + // End of the string + fmt.Fprintf(&r.mod, mod, r.cur) + return r.mod.ReadByte() + } + + if r.s[si+1] == '$' { + r.si++ + return '$', nil + } + + var offset int + + // Search for { and } + if r.s[si+1] == '{' { + // Modifier block + sep := strings.Index(r.s[si+2:], "}") + if sep < 0 { + return 0, r.parseError("bad modifier in $GENERATE", len(r.s)) + } + + var errMsg string + mod, offset, errMsg = modToPrintf(r.s[si+2 : si+2+sep]) + if errMsg != "" { + return 0, r.parseError(errMsg, si+3+sep) } + if r.start+offset < 0 || r.end+offset > 1<<31-1 { + return 0, r.parseError("bad offset in $GENERATE", si+3+sep) + } + + r.si += 2 + sep // Jump to it } - // Re-parse the RR and send it on the current channel t - rx, err := NewRR("$ORIGIN " + o + "\n" + dom.String()) - if err != nil { - return err.Error() + + fmt.Fprintf(&r.mod, mod, r.cur+offset) + return r.mod.ReadByte() + default: + if r.escape { // Pretty useless here + r.escape = false + return r.ReadByte() } - t <- &Token{RR: rx} - // Its more efficient to first built the rrlist and then parse it in - // one go! But is this a problem? + + return r.s[si], nil } - return "" } // Convert a $GENERATE modifier 0,0,d to something Printf can deal with. -func modToPrintf(s string) (string, int, error) { - xs := strings.Split(s, ",") - +func modToPrintf(s string) (string, int, string) { // Modifier is { offset [ ,width [ ,base ] ] } - provide default // values for optional width and type, if necessary. - switch len(xs) { + var offStr, widthStr, base string + switch xs := strings.Split(s, ","); len(xs) { case 1: - xs = append(xs, "0", "d") + offStr, widthStr, base = xs[0], "0", "d" case 2: - xs = append(xs, "d") + offStr, widthStr, base = xs[0], xs[1], "d" case 3: + offStr, widthStr, base = xs[0], xs[1], xs[2] default: - return "", 0, errors.New("bad modifier in $GENERATE") + return "", 0, "bad modifier in $GENERATE" } - // xs[0] is offset, xs[1] is width, xs[2] is base - if xs[2] != "o" && xs[2] != "d" && xs[2] != "x" && xs[2] != "X" { - return "", 0, errors.New("bad base in $GENERATE") + switch base { + case "o", "d", "x", "X": + default: + return "", 0, "bad base in $GENERATE" } - offset, err := strconv.Atoi(xs[0]) + + offset, err := strconv.Atoi(offStr) if err != nil { - return "", 0, errors.New("bad offset in $GENERATE") + return "", 0, "bad offset in $GENERATE" } - width, err := strconv.Atoi(xs[1]) - if err != nil || width > 255 { - return "", offset, errors.New("bad width in $GENERATE") + + width, err := strconv.Atoi(widthStr) + if err != nil || width < 0 || width > 255 { + return "", 0, "bad width in $GENERATE" } - switch { - case width < 0: - return "", offset, errors.New("bad width in $GENERATE") - case width == 0: - return "%" + xs[1] + xs[2], offset, nil + + if width == 0 { + return "%" + base, offset, "" } - return "%0" + xs[1] + xs[2], offset, nil + + return "%0" + widthStr + base, offset, "" } diff --git a/vendor/github.com/miekg/dns/privaterr.go b/vendor/github.com/miekg/dns/privaterr.go index d931da7ef..74544a74e 100644 --- a/vendor/github.com/miekg/dns/privaterr.go +++ b/vendor/github.com/miekg/dns/privaterr.go @@ -105,7 +105,7 @@ func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata) return rr, off, err } - setPrivateRR := func(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { + setPrivateRR := func(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := mkPrivateRR(h.Rrtype) rr.Hdr = h @@ -115,7 +115,7 @@ func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata) for { // TODO(miek): we could also be returning _QUOTE, this might or might not // be an issue (basically parsing TXT becomes hard) - switch l = <-c; l.value { + switch l, _ = c.Next(); l.value { case zNewline, zEOF: break Fetch case zString: diff --git a/vendor/github.com/miekg/dns/scan.go b/vendor/github.com/miekg/dns/scan.go index a752dbd01..61ace121e 100644 --- a/vendor/github.com/miekg/dns/scan.go +++ b/vendor/github.com/miekg/dns/scan.go @@ -1,6 +1,7 @@ package dns import ( + "bufio" "fmt" "io" "os" @@ -11,6 +12,10 @@ import ( const maxTok = 2048 // Largest token we can return. +// The maximum depth of $INCLUDE directives supported by the +// ZoneParser API. +const maxIncludeDepth = 7 + // Tokinize a RFC 1035 zone file. The tokenizer will normalize it: // * Add ownernames if they are left blank; // * Suppress sequences of spaces; @@ -74,15 +79,13 @@ func (e *ParseError) Error() (s string) { } type lex struct { - token string // text of the token - tokenUpper string // uppercase text of the token - length int // length of the token - err bool // when true, token text has lexer error - value uint8 // value: zString, _BLANK, etc. - torc uint16 // type or class as parsed in the lexer, we only need to look this up in the grammar - line int // line in the file - column int // column in the file - comment string // any comment text seen + token string // text of the token + err bool // when true, token text has lexer error + value uint8 // value: zString, _BLANK, etc. + torc uint16 // type or class as parsed in the lexer, we only need to look this up in the grammar + line int // line in the file + column int // column in the file + comment string // any comment text seen } // Token holds the token that are returned when a zone file is parsed. @@ -102,10 +105,14 @@ type ttlState struct { } // NewRR reads the RR contained in the string s. Only the first RR is -// returned. If s contains no RR, return nil with no error. The class -// defaults to IN and TTL defaults to 3600. The full zone file syntax -// like $TTL, $ORIGIN, etc. is supported. All fields of the returned -// RR are set, except RR.Header().Rdlength which is set to 0. +// returned. If s contains no records, NewRR will return nil with no +// error. +// +// The class defaults to IN and TTL defaults to 3600. The full zone +// file syntax like $TTL, $ORIGIN, etc. is supported. +// +// All fields of the returned RR are set, except RR.Header().Rdlength +// which is set to 0. func NewRR(s string) (RR, error) { if len(s) > 0 && s[len(s)-1] != '\n' { // We need a closing newline return ReadRR(strings.NewReader(s+"\n"), "") @@ -113,28 +120,31 @@ func NewRR(s string) (RR, error) { return ReadRR(strings.NewReader(s), "") } -// ReadRR reads the RR contained in q. +// ReadRR reads the RR contained in r. +// +// The string file is used in error reporting and to resolve relative +// $INCLUDE directives. +// // See NewRR for more documentation. -func ReadRR(q io.Reader, filename string) (RR, error) { - defttl := &ttlState{defaultTtl, false} - r := <-parseZoneHelper(q, ".", filename, defttl, 1) - if r == nil { - return nil, nil - } - - if r.Error != nil { - return nil, r.Error - } - return r.RR, nil +func ReadRR(r io.Reader, file string) (RR, error) { + zp := NewZoneParser(r, ".", file) + zp.SetDefaultTTL(defaultTtl) + zp.SetIncludeAllowed(true) + rr, _ := zp.Next() + return rr, zp.Err() } -// ParseZone reads a RFC 1035 style zonefile from r. It returns *Tokens on the -// returned channel, each consisting of either a parsed RR and optional comment -// or a nil RR and an error. The string file is only used -// in error reporting. The string origin is used as the initial origin, as -// if the file would start with an $ORIGIN directive. -// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are supported. -// The channel t is closed by ParseZone when the end of r is reached. +// ParseZone reads a RFC 1035 style zonefile from r. It returns +// *Tokens on the returned channel, each consisting of either a +// parsed RR and optional comment or a nil RR and an error. The +// channel is closed by ParseZone when the end of r is reached. +// +// The string file is used in error reporting and to resolve relative +// $INCLUDE directives. The string origin is used as the initial +// origin, as if the file would start with an $ORIGIN directive. +// +// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all +// supported. // // Basic usage pattern when reading from a string (z) containing the // zone data: @@ -147,90 +157,246 @@ func ReadRR(q io.Reader, filename string) (RR, error) { // } // } // -// Comments specified after an RR (and on the same line!) are returned too: +// Comments specified after an RR (and on the same line!) are +// returned too: // // foo. IN A 10.0.0.1 ; this is a comment // -// The text "; this is comment" is returned in Token.Comment. Comments inside the -// RR are discarded. Comments on a line by themselves are discarded too. +// The text "; this is comment" is returned in Token.Comment. +// Comments inside the RR are returned concatenated along with the +// RR. Comments on a line by themselves are discarded. +// +// To prevent memory leaks it is important to always fully drain the +// returned channel. If an error occurs, it will always be the last +// Token sent on the channel. +// +// Deprecated: New users should prefer the ZoneParser API. func ParseZone(r io.Reader, origin, file string) chan *Token { - return parseZoneHelper(r, origin, file, nil, 10000) -} - -func parseZoneHelper(r io.Reader, origin, file string, defttl *ttlState, chansize int) chan *Token { - t := make(chan *Token, chansize) - go parseZone(r, origin, file, defttl, t, 0) + t := make(chan *Token, 10000) + go parseZone(r, origin, file, t) return t } -func parseZone(r io.Reader, origin, f string, defttl *ttlState, t chan *Token, include int) { - defer func() { - if include == 0 { - close(t) - } - }() - s, cancel := scanInit(r) - c := make(chan lex) - // Start the lexer - go zlexer(s, c) - - defer func() { - cancel() - // zlexer can send up to three tokens, the next one and possibly 2 remainders. - // Do a non-blocking read. - _, ok := <-c - _, ok = <-c - _, ok = <-c +func parseZone(r io.Reader, origin, file string, t chan *Token) { + defer close(t) + + zp := NewZoneParser(r, origin, file) + zp.SetIncludeAllowed(true) + + for rr, ok := zp.Next(); ok; rr, ok = zp.Next() { + t <- &Token{RR: rr, Comment: zp.Comment()} + } + + if err := zp.Err(); err != nil { + pe, ok := err.(*ParseError) if !ok { - // too bad + pe = &ParseError{file: file, err: err.Error()} } - }() - // 6 possible beginnings of a line, _ is a space - // 0. zRRTYPE -> all omitted until the rrtype - // 1. zOwner _ zRrtype -> class/ttl omitted - // 2. zOwner _ zString _ zRrtype -> class omitted - // 3. zOwner _ zString _ zClass _ zRrtype -> ttl/class - // 4. zOwner _ zClass _ zRrtype -> ttl omitted - // 5. zOwner _ zClass _ zString _ zRrtype -> class/ttl (reversed) - // After detecting these, we know the zRrtype so we can jump to functions - // handling the rdata for each of these types. + t <- &Token{Error: pe} + } +} + +// ZoneParser is a parser for an RFC 1035 style zonefile. +// +// Each parsed RR in the zone is returned sequentially from Next. An +// optional comment can be retrieved with Comment. +// +// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all +// supported. Although $INCLUDE is disabled by default. +// +// Basic usage pattern when reading from a string (z) containing the +// zone data: +// +// zp := NewZoneParser(strings.NewReader(z), "", "") +// +// for rr, ok := zp.Next(); ok; rr, ok = zp.Next() { +// // Do something with rr +// } +// +// if err := zp.Err(); err != nil { +// // log.Println(err) +// } +// +// Comments specified after an RR (and on the same line!) are +// returned too: +// +// foo. IN A 10.0.0.1 ; this is a comment +// +// The text "; this is comment" is returned from Comment. Comments inside +// the RR are returned concatenated along with the RR. Comments on a line +// by themselves are discarded. +type ZoneParser struct { + c *zlexer + + parseErr *ParseError + + origin string + file string + + defttl *ttlState + + h RR_Header + + // sub is used to parse $INCLUDE files and $GENERATE directives. + // Next, by calling subNext, forwards the resulting RRs from this + // sub parser to the calling code. + sub *ZoneParser + osFile *os.File + + com string + + includeDepth uint8 + + includeAllowed bool +} + +// NewZoneParser returns an RFC 1035 style zonefile parser that reads +// from r. +// +// The string file is used in error reporting and to resolve relative +// $INCLUDE directives. The string origin is used as the initial +// origin, as if the file would start with an $ORIGIN directive. +func NewZoneParser(r io.Reader, origin, file string) *ZoneParser { + var pe *ParseError if origin != "" { origin = Fqdn(origin) if _, ok := IsDomainName(origin); !ok { - t <- &Token{Error: &ParseError{f, "bad initial origin name", lex{}}} - return + pe = &ParseError{file, "bad initial origin name", lex{}} } } + return &ZoneParser{ + c: newZLexer(r), + + parseErr: pe, + + origin: origin, + file: file, + } +} + +// SetDefaultTTL sets the parsers default TTL to ttl. +func (zp *ZoneParser) SetDefaultTTL(ttl uint32) { + zp.defttl = &ttlState{ttl, false} +} + +// SetIncludeAllowed controls whether $INCLUDE directives are +// allowed. $INCLUDE directives are not supported by default. +// +// The $INCLUDE directive will open and read from a user controlled +// file on the system. Even if the file is not a valid zonefile, the +// contents of the file may be revealed in error messages, such as: +// +// /etc/passwd: dns: not a TTL: "root:x:0:0:root:/root:/bin/bash" at line: 1:31 +// /etc/shadow: dns: not a TTL: "root:$6$::0:99999:7:::" at line: 1:125 +func (zp *ZoneParser) SetIncludeAllowed(v bool) { + zp.includeAllowed = v +} + +// Err returns the first non-EOF error that was encountered by the +// ZoneParser. +func (zp *ZoneParser) Err() error { + if zp.parseErr != nil { + return zp.parseErr + } + + if zp.sub != nil { + if err := zp.sub.Err(); err != nil { + return err + } + } + + return zp.c.Err() +} + +func (zp *ZoneParser) setParseError(err string, l lex) (RR, bool) { + zp.parseErr = &ParseError{zp.file, err, l} + return nil, false +} + +// Comment returns an optional text comment that occurred alongside +// the RR. +func (zp *ZoneParser) Comment() string { + return zp.com +} + +func (zp *ZoneParser) subNext() (RR, bool) { + if rr, ok := zp.sub.Next(); ok { + zp.com = zp.sub.com + return rr, true + } + + if zp.sub.osFile != nil { + zp.sub.osFile.Close() + zp.sub.osFile = nil + } + + if zp.sub.Err() != nil { + // We have errors to surface. + return nil, false + } + + zp.sub = nil + return zp.Next() +} + +// Next advances the parser to the next RR in the zonefile and +// returns the (RR, true). It will return (nil, false) when the +// parsing stops, either by reaching the end of the input or an +// error. After Next returns (nil, false), the Err method will return +// any error that occurred during parsing. +func (zp *ZoneParser) Next() (RR, bool) { + zp.com = "" + + if zp.parseErr != nil { + return nil, false + } + if zp.sub != nil { + return zp.subNext() + } + + // 6 possible beginnings of a line (_ is a space): + // + // 0. zRRTYPE -> all omitted until the rrtype + // 1. zOwner _ zRrtype -> class/ttl omitted + // 2. zOwner _ zString _ zRrtype -> class omitted + // 3. zOwner _ zString _ zClass _ zRrtype -> ttl/class + // 4. zOwner _ zClass _ zRrtype -> ttl omitted + // 5. zOwner _ zClass _ zString _ zRrtype -> class/ttl (reversed) + // + // After detecting these, we know the zRrtype so we can jump to functions + // handling the rdata for each of these types. + st := zExpectOwnerDir // initial state - var h RR_Header - var prevName string - for l := range c { - // Lexer spotted an error already + h := &zp.h + + for l, ok := zp.c.Next(); ok; l, ok = zp.c.Next() { + // zlexer spotted an error already if l.err { - t <- &Token{Error: &ParseError{f, l.token, l}} - return + return zp.setParseError(l.token, l) } + switch st { case zExpectOwnerDir: // We can also expect a directive, like $TTL or $ORIGIN - if defttl != nil { - h.Ttl = defttl.ttl + if zp.defttl != nil { + h.Ttl = zp.defttl.ttl } + h.Class = ClassINET + switch l.value { case zNewline: st = zExpectOwnerDir case zOwner: - h.Name = l.token - name, ok := toAbsoluteName(l.token, origin) + name, ok := toAbsoluteName(l.token, zp.origin) if !ok { - t <- &Token{Error: &ParseError{f, "bad owner name", l}} - return + return zp.setParseError("bad owner name", l) } + h.Name = name - prevName = h.Name + st = zExpectOwnerBl case zDirTTL: st = zExpectDirTTLBl @@ -241,12 +407,12 @@ func parseZone(r io.Reader, origin, f string, defttl *ttlState, t chan *Token, i case zDirGenerate: st = zExpectDirGenerateBl case zRrtpe: - h.Name = prevName h.Rrtype = l.torc + st = zExpectRdata case zClass: - h.Name = prevName h.Class = l.torc + st = zExpectAnyNoClassBl case zBlank: // Discard, can happen when there is nothing on the @@ -254,297 +420,400 @@ func parseZone(r io.Reader, origin, f string, defttl *ttlState, t chan *Token, i case zString: ttl, ok := stringToTTL(l.token) if !ok { - t <- &Token{Error: &ParseError{f, "not a TTL", l}} - return + return zp.setParseError("not a TTL", l) } + h.Ttl = ttl - if defttl == nil || !defttl.isByDirective { - defttl = &ttlState{ttl, false} + + if zp.defttl == nil || !zp.defttl.isByDirective { + zp.defttl = &ttlState{ttl, false} } - st = zExpectAnyNoTTLBl + st = zExpectAnyNoTTLBl default: - t <- &Token{Error: &ParseError{f, "syntax error at beginning", l}} - return + return zp.setParseError("syntax error at beginning", l) } case zExpectDirIncludeBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank after $INCLUDE-directive", l}} - return + return zp.setParseError("no blank after $INCLUDE-directive", l) } + st = zExpectDirInclude case zExpectDirInclude: if l.value != zString { - t <- &Token{Error: &ParseError{f, "expecting $INCLUDE value, not this...", l}} - return + return zp.setParseError("expecting $INCLUDE value, not this...", l) } - neworigin := origin // There may be optionally a new origin set after the filename, if not use current one - switch l := <-c; l.value { + + neworigin := zp.origin // There may be optionally a new origin set after the filename, if not use current one + switch l, _ := zp.c.Next(); l.value { case zBlank: - l := <-c + l, _ := zp.c.Next() if l.value == zString { - name, ok := toAbsoluteName(l.token, origin) + name, ok := toAbsoluteName(l.token, zp.origin) if !ok { - t <- &Token{Error: &ParseError{f, "bad origin name", l}} - return + return zp.setParseError("bad origin name", l) } + neworigin = name } case zNewline, zEOF: // Ok default: - t <- &Token{Error: &ParseError{f, "garbage after $INCLUDE", l}} - return + return zp.setParseError("garbage after $INCLUDE", l) } + + if !zp.includeAllowed { + return zp.setParseError("$INCLUDE directive not allowed", l) + } + if zp.includeDepth >= maxIncludeDepth { + return zp.setParseError("too deeply nested $INCLUDE", l) + } + // Start with the new file includePath := l.token if !filepath.IsAbs(includePath) { - includePath = filepath.Join(filepath.Dir(f), includePath) + includePath = filepath.Join(filepath.Dir(zp.file), includePath) } + r1, e1 := os.Open(includePath) if e1 != nil { - msg := fmt.Sprintf("failed to open `%s'", l.token) + var as string if !filepath.IsAbs(l.token) { - msg += fmt.Sprintf(" as `%s'", includePath) + as = fmt.Sprintf(" as `%s'", includePath) } - t <- &Token{Error: &ParseError{f, msg, l}} - return - } - if include+1 > 7 { - t <- &Token{Error: &ParseError{f, "too deeply nested $INCLUDE", l}} - return + + msg := fmt.Sprintf("failed to open `%s'%s: %v", l.token, as, e1) + return zp.setParseError(msg, l) } - parseZone(r1, neworigin, includePath, defttl, t, include+1) - st = zExpectOwnerDir + + zp.sub = NewZoneParser(r1, neworigin, includePath) + zp.sub.defttl, zp.sub.includeDepth, zp.sub.osFile = zp.defttl, zp.includeDepth+1, r1 + zp.sub.SetIncludeAllowed(true) + return zp.subNext() case zExpectDirTTLBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank after $TTL-directive", l}} - return + return zp.setParseError("no blank after $TTL-directive", l) } + st = zExpectDirTTL case zExpectDirTTL: if l.value != zString { - t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}} - return + return zp.setParseError("expecting $TTL value, not this...", l) } - if e, _ := slurpRemainder(c, f); e != nil { - t <- &Token{Error: e} - return + + if e, _ := slurpRemainder(zp.c, zp.file); e != nil { + zp.parseErr = e + return nil, false } + ttl, ok := stringToTTL(l.token) if !ok { - t <- &Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}} - return + return zp.setParseError("expecting $TTL value, not this...", l) } - defttl = &ttlState{ttl, true} + + zp.defttl = &ttlState{ttl, true} + st = zExpectOwnerDir case zExpectDirOriginBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank after $ORIGIN-directive", l}} - return + return zp.setParseError("no blank after $ORIGIN-directive", l) } + st = zExpectDirOrigin case zExpectDirOrigin: if l.value != zString { - t <- &Token{Error: &ParseError{f, "expecting $ORIGIN value, not this...", l}} - return + return zp.setParseError("expecting $ORIGIN value, not this...", l) } - if e, _ := slurpRemainder(c, f); e != nil { - t <- &Token{Error: e} + + if e, _ := slurpRemainder(zp.c, zp.file); e != nil { + zp.parseErr = e + return nil, false } - name, ok := toAbsoluteName(l.token, origin) + + name, ok := toAbsoluteName(l.token, zp.origin) if !ok { - t <- &Token{Error: &ParseError{f, "bad origin name", l}} - return + return zp.setParseError("bad origin name", l) } - origin = name + + zp.origin = name + st = zExpectOwnerDir case zExpectDirGenerateBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank after $GENERATE-directive", l}} - return + return zp.setParseError("no blank after $GENERATE-directive", l) } + st = zExpectDirGenerate case zExpectDirGenerate: if l.value != zString { - t <- &Token{Error: &ParseError{f, "expecting $GENERATE value, not this...", l}} - return - } - if errMsg := generate(l, c, t, origin); errMsg != "" { - t <- &Token{Error: &ParseError{f, errMsg, l}} - return + return zp.setParseError("expecting $GENERATE value, not this...", l) } - st = zExpectOwnerDir + + return zp.generate(l) case zExpectOwnerBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank after owner", l}} - return + return zp.setParseError("no blank after owner", l) } + st = zExpectAny case zExpectAny: switch l.value { case zRrtpe: - if defttl == nil { - t <- &Token{Error: &ParseError{f, "missing TTL with no previous value", l}} - return + if zp.defttl == nil { + return zp.setParseError("missing TTL with no previous value", l) } + h.Rrtype = l.torc + st = zExpectRdata case zClass: h.Class = l.torc + st = zExpectAnyNoClassBl case zString: ttl, ok := stringToTTL(l.token) if !ok { - t <- &Token{Error: &ParseError{f, "not a TTL", l}} - return + return zp.setParseError("not a TTL", l) } + h.Ttl = ttl - if defttl == nil || !defttl.isByDirective { - defttl = &ttlState{ttl, false} + + if zp.defttl == nil || !zp.defttl.isByDirective { + zp.defttl = &ttlState{ttl, false} } + st = zExpectAnyNoTTLBl default: - t <- &Token{Error: &ParseError{f, "expecting RR type, TTL or class, not this...", l}} - return + return zp.setParseError("expecting RR type, TTL or class, not this...", l) } case zExpectAnyNoClassBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank before class", l}} - return + return zp.setParseError("no blank before class", l) } + st = zExpectAnyNoClass case zExpectAnyNoTTLBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank before TTL", l}} - return + return zp.setParseError("no blank before TTL", l) } + st = zExpectAnyNoTTL case zExpectAnyNoTTL: switch l.value { case zClass: h.Class = l.torc + st = zExpectRrtypeBl case zRrtpe: h.Rrtype = l.torc + st = zExpectRdata default: - t <- &Token{Error: &ParseError{f, "expecting RR type or class, not this...", l}} - return + return zp.setParseError("expecting RR type or class, not this...", l) } case zExpectAnyNoClass: switch l.value { case zString: ttl, ok := stringToTTL(l.token) if !ok { - t <- &Token{Error: &ParseError{f, "not a TTL", l}} - return + return zp.setParseError("not a TTL", l) } + h.Ttl = ttl - if defttl == nil || !defttl.isByDirective { - defttl = &ttlState{ttl, false} + + if zp.defttl == nil || !zp.defttl.isByDirective { + zp.defttl = &ttlState{ttl, false} } + st = zExpectRrtypeBl case zRrtpe: h.Rrtype = l.torc + st = zExpectRdata default: - t <- &Token{Error: &ParseError{f, "expecting RR type or TTL, not this...", l}} - return + return zp.setParseError("expecting RR type or TTL, not this...", l) } case zExpectRrtypeBl: if l.value != zBlank { - t <- &Token{Error: &ParseError{f, "no blank before RR type", l}} - return + return zp.setParseError("no blank before RR type", l) } + st = zExpectRrtype case zExpectRrtype: if l.value != zRrtpe { - t <- &Token{Error: &ParseError{f, "unknown RR type", l}} - return + return zp.setParseError("unknown RR type", l) } + h.Rrtype = l.torc + st = zExpectRdata case zExpectRdata: - r, e, c1 := setRR(h, c, origin, f) + r, e, c1 := setRR(*h, zp.c, zp.origin, zp.file) if e != nil { // If e.lex is nil than we have encounter a unknown RR type // in that case we substitute our current lex token if e.lex.token == "" && e.lex.value == 0 { e.lex = l // Uh, dirty } - t <- &Token{Error: e} - return + + zp.parseErr = e + return nil, false } - t <- &Token{RR: r, Comment: c1} - st = zExpectOwnerDir + + zp.com = c1 + return r, true } } + // If we get here, we and the h.Rrtype is still zero, we haven't parsed anything, this // is not an error, because an empty zone file is still a zone file. + return nil, false +} + +type zlexer struct { + br io.ByteReader + + readErr error + + line int + column int + + com string + + l lex + + brace int + quote bool + space bool + commt bool + rrtype bool + owner bool + + nextL bool + + eol bool // end-of-line +} + +func newZLexer(r io.Reader) *zlexer { + br, ok := r.(io.ByteReader) + if !ok { + br = bufio.NewReaderSize(r, 1024) + } + + return &zlexer{ + br: br, + + line: 1, + + owner: true, + } +} + +func (zl *zlexer) Err() error { + if zl.readErr == io.EOF { + return nil + } + + return zl.readErr } -// zlexer scans the sourcefile and returns tokens on the channel c. -func zlexer(s *scan, c chan lex) { - var l lex - str := make([]byte, maxTok) // Should be enough for any token - stri := 0 // Offset in str (0 means empty) - com := make([]byte, maxTok) // Hold comment text - comi := 0 - quote := false - escape := false - space := false - commt := false - rrtype := false - owner := true - brace := 0 - x, err := s.tokenText() - defer close(c) - for err == nil { - l.column = s.position.Column - l.line = s.position.Line - if stri >= maxTok { +// readByte returns the next byte from the input +func (zl *zlexer) readByte() (byte, bool) { + if zl.readErr != nil { + return 0, false + } + + c, err := zl.br.ReadByte() + if err != nil { + zl.readErr = err + return 0, false + } + + // delay the newline handling until the next token is delivered, + // fixes off-by-one errors when reporting a parse error. + if zl.eol { + zl.line++ + zl.column = 0 + zl.eol = false + } + + if c == '\n' { + zl.eol = true + } else { + zl.column++ + } + + return c, true +} + +func (zl *zlexer) Next() (lex, bool) { + l := &zl.l + if zl.nextL { + zl.nextL = false + return *l, true + } + if l.err { + // Parsing errors should be sticky. + return lex{value: zEOF}, false + } + + var ( + str [maxTok]byte // Hold string text + com [maxTok]byte // Hold comment text + + stri int // Offset in str (0 means empty) + comi int // Offset in com (0 means empty) + + escape bool + ) + + if zl.com != "" { + comi = copy(com[:], zl.com) + zl.com = "" + } + + for x, ok := zl.readByte(); ok; x, ok = zl.readByte() { + l.line, l.column = zl.line, zl.column + l.comment = "" + + if stri >= len(str) { l.token = "token length insufficient for parsing" l.err = true - c <- l - return + return *l, true } - if comi >= maxTok { + if comi >= len(com) { l.token = "comment length insufficient for parsing" l.err = true - c <- l - return + return *l, true } switch x { case ' ', '\t': - if escape { - escape = false - str[stri] = x - stri++ - break - } - if quote { - // Inside quotes this is legal + if escape || zl.quote { + // Inside quotes or escaped this is legal. str[stri] = x stri++ + + escape = false break } - if commt { + + if zl.commt { com[comi] = x comi++ break } + + var retL lex if stri == 0 { // Space directly in the beginning, handled in the grammar - } else if owner { + } else if zl.owner { // If we have a string and its the first, make it an owner l.value = zOwner l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri + // escape $... start with a \ not a $, so this will work - switch l.tokenUpper { + switch strings.ToUpper(l.token) { case "$TTL": l.value = zDirTTL case "$ORIGIN": @@ -554,258 +823,316 @@ func zlexer(s *scan, c chan lex) { case "$GENERATE": l.value = zDirGenerate } - c <- l + + retL = *l } else { l.value = zString l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri - if !rrtype { - if t, ok := StringToType[l.tokenUpper]; ok { + + if !zl.rrtype { + tokenUpper := strings.ToUpper(l.token) + if t, ok := StringToType[tokenUpper]; ok { l.value = zRrtpe l.torc = t - rrtype = true - } else { - if strings.HasPrefix(l.tokenUpper, "TYPE") { - t, ok := typeToInt(l.token) - if !ok { - l.token = "unknown RR type" - l.err = true - c <- l - return - } - l.value = zRrtpe - rrtype = true - l.torc = t + + zl.rrtype = true + } else if strings.HasPrefix(tokenUpper, "TYPE") { + t, ok := typeToInt(l.token) + if !ok { + l.token = "unknown RR type" + l.err = true + return *l, true } + + l.value = zRrtpe + l.torc = t + + zl.rrtype = true } - if t, ok := StringToClass[l.tokenUpper]; ok { + + if t, ok := StringToClass[tokenUpper]; ok { l.value = zClass l.torc = t - } else { - if strings.HasPrefix(l.tokenUpper, "CLASS") { - t, ok := classToInt(l.token) - if !ok { - l.token = "unknown class" - l.err = true - c <- l - return - } - l.value = zClass - l.torc = t + } else if strings.HasPrefix(tokenUpper, "CLASS") { + t, ok := classToInt(l.token) + if !ok { + l.token = "unknown class" + l.err = true + return *l, true } + + l.value = zClass + l.torc = t } } - c <- l + + retL = *l } - stri = 0 - if !space && !commt { + zl.owner = false + + if !zl.space { + zl.space = true + l.value = zBlank l.token = " " - l.length = 1 - c <- l + + if retL == (lex{}) { + return *l, true + } + + zl.nextL = true + } + + if retL != (lex{}) { + return retL, true } - owner = false - space = true case ';': - if escape { - escape = false + if escape || zl.quote { + // Inside quotes or escaped this is legal. str[stri] = x stri++ + + escape = false break } - if quote { - // Inside quotes this is legal - str[stri] = x - stri++ - break + + zl.commt = true + zl.com = "" + + if comi > 1 { + // A newline was previously seen inside a comment that + // was inside braces and we delayed adding it until now. + com[comi] = ' ' // convert newline to space + comi++ } + + com[comi] = ';' + comi++ + if stri > 0 { + zl.com = string(com[:comi]) + l.value = zString l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri - c <- l - stri = 0 + return *l, true } - commt = true - com[comi] = ';' - comi++ case '\r': escape = false - if quote { + + if zl.quote { str[stri] = x stri++ } + // discard if outside of quotes case '\n': escape = false + // Escaped newline - if quote { + if zl.quote { str[stri] = x stri++ break } - // inside quotes this is legal - if commt { + + if zl.commt { // Reset a comment - commt = false - rrtype = false - stri = 0 + zl.commt = false + zl.rrtype = false + // If not in a brace this ends the comment AND the RR - if brace == 0 { - owner = true - owner = true + if zl.brace == 0 { + zl.owner = true + l.value = zNewline l.token = "\n" - l.tokenUpper = l.token - l.length = 1 l.comment = string(com[:comi]) - c <- l - l.comment = "" - comi = 0 - break + return *l, true } - com[comi] = ' ' // convert newline to space - comi++ + + zl.com = string(com[:comi]) break } - if brace == 0 { + if zl.brace == 0 { // If there is previous text, we should output it here + var retL lex if stri != 0 { l.value = zString l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri - if !rrtype { - if t, ok := StringToType[l.tokenUpper]; ok { + if !zl.rrtype { + tokenUpper := strings.ToUpper(l.token) + if t, ok := StringToType[tokenUpper]; ok { + zl.rrtype = true + l.value = zRrtpe l.torc = t - rrtype = true } } - c <- l + + retL = *l } + l.value = zNewline l.token = "\n" - l.tokenUpper = l.token - l.length = 1 - c <- l - stri = 0 - commt = false - rrtype = false - owner = true - comi = 0 + l.comment = zl.com + + zl.com = "" + zl.rrtype = false + zl.owner = true + + if retL != (lex{}) { + zl.nextL = true + return retL, true + } + + return *l, true } case '\\': // comments do not get escaped chars, everything is copied - if commt { + if zl.commt { com[comi] = x comi++ break } + // something already escaped must be in string if escape { str[stri] = x stri++ + escape = false break } + // something escaped outside of string gets added to string str[stri] = x stri++ + escape = true case '"': - if commt { + if zl.commt { com[comi] = x comi++ break } + if escape { str[stri] = x stri++ + escape = false break } - space = false + + zl.space = false + // send previous gathered text and the quote + var retL lex if stri != 0 { l.value = zString l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri - c <- l - stri = 0 + retL = *l } // send quote itself as separate token l.value = zQuote l.token = "\"" - l.tokenUpper = l.token - l.length = 1 - c <- l - quote = !quote + + zl.quote = !zl.quote + + if retL != (lex{}) { + zl.nextL = true + return retL, true + } + + return *l, true case '(', ')': - if commt { + if zl.commt { com[comi] = x comi++ break } - if escape { + + if escape || zl.quote { + // Inside quotes or escaped this is legal. str[stri] = x stri++ + escape = false break } - if quote { - str[stri] = x - stri++ - break - } + switch x { case ')': - brace-- - if brace < 0 { + zl.brace-- + + if zl.brace < 0 { l.token = "extra closing brace" - l.tokenUpper = l.token l.err = true - c <- l - return + return *l, true } case '(': - brace++ + zl.brace++ } default: escape = false - if commt { + + if zl.commt { com[comi] = x comi++ break } + str[stri] = x stri++ - space = false + + zl.space = false } - x, err = s.tokenText() } + + if zl.readErr != nil && zl.readErr != io.EOF { + // Don't return any tokens after a read error occurs. + return lex{value: zEOF}, false + } + + var retL lex if stri > 0 { - // Send remainder - l.token = string(str[:stri]) - l.tokenUpper = strings.ToUpper(l.token) - l.length = stri + // Send remainder of str l.value = zString - c <- l + l.token = string(str[:stri]) + retL = *l + + if comi <= 0 { + return retL, true + } } - if brace != 0 { + + if comi > 0 { + // Send remainder of com + l.value = zNewline + l.token = "\n" + l.comment = string(com[:comi]) + + if retL != (lex{}) { + zl.nextL = true + return retL, true + } + + return *l, true + } + + if zl.brace != 0 { + l.comment = "" // in case there was left over string and comment l.token = "unbalanced brace" - l.tokenUpper = l.token l.err = true - c <- l + return *l, true } + + return lex{value: zEOF}, false } // Extract the class number from CLASSxx @@ -966,12 +1293,12 @@ func locCheckEast(token string, longitude uint32) (uint32, bool) { } // "Eat" the rest of the "line". Return potential comments -func slurpRemainder(c chan lex, f string) (*ParseError, string) { - l := <-c +func slurpRemainder(c *zlexer, f string) (*ParseError, string) { + l, _ := c.Next() com := "" switch l.value { case zBlank: - l = <-c + l, _ = c.Next() com = l.comment if l.value != zNewline && l.value != zEOF { return &ParseError{f, "garbage after rdata", l}, "" diff --git a/vendor/github.com/miekg/dns/scan_rr.go b/vendor/github.com/miekg/dns/scan_rr.go index 67f884b0d..935d22c3f 100644 --- a/vendor/github.com/miekg/dns/scan_rr.go +++ b/vendor/github.com/miekg/dns/scan_rr.go @@ -11,7 +11,7 @@ type parserFunc struct { // Func defines the function that parses the tokens and returns the RR // or an error. The last string contains any comments in the line as // they returned by the lexer as well. - Func func(h RR_Header, c chan lex, origin string, file string) (RR, *ParseError, string) + Func func(h RR_Header, c *zlexer, origin string, file string) (RR, *ParseError, string) // Signals if the RR ending is of variable length, like TXT or records // that have Hexadecimal or Base64 as their last element in the Rdata. Records // that have a fixed ending or for instance A, AAAA, SOA and etc. @@ -23,7 +23,7 @@ type parserFunc struct { // After the rdata there may come a zBlank and then a zNewline // or immediately a zNewline. If this is not the case we flag // an *ParseError: garbage after rdata. -func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { parserfunc, ok := typeToparserFunc[h.Rrtype] if ok { r, e, cm := parserfunc.Func(h, c, o, f) @@ -45,9 +45,9 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { // A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces) // or an error -func endingToString(c chan lex, errstr, f string) (string, *ParseError, string) { +func endingToString(c *zlexer, errstr, f string) (string, *ParseError, string) { s := "" - l := <-c // zString + l, _ := c.Next() // zString for l.value != zNewline && l.value != zEOF { if l.err { return s, &ParseError{f, errstr, l}, "" @@ -59,16 +59,16 @@ func endingToString(c chan lex, errstr, f string) (string, *ParseError, string) default: return "", &ParseError{f, errstr, l}, "" } - l = <-c + l, _ = c.Next() } return s, nil, l.comment } // A remainder of the rdata with embedded spaces, split on unquoted whitespace // and return the parsed string slice or an error -func endingToTxtSlice(c chan lex, errstr, f string) ([]string, *ParseError, string) { +func endingToTxtSlice(c *zlexer, errstr, f string) ([]string, *ParseError, string) { // Get the remaining data until we see a zNewline - l := <-c + l, _ := c.Next() if l.err { return nil, &ParseError{f, errstr, l}, "" } @@ -117,7 +117,7 @@ func endingToTxtSlice(c chan lex, errstr, f string) ([]string, *ParseError, stri default: return nil, &ParseError{f, errstr, l}, "" } - l = <-c + l, _ = c.Next() } if quote { return nil, &ParseError{f, errstr, l}, "" @@ -125,12 +125,12 @@ func endingToTxtSlice(c chan lex, errstr, f string) ([]string, *ParseError, stri return s, nil, l.comment } -func setA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(A) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -141,12 +141,12 @@ func setA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setAAAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setAAAA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(AAAA) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -157,13 +157,13 @@ func setAAAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setNS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNS(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NS) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Ns = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -175,13 +175,13 @@ func setNS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setPTR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(PTR) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Ptr = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -193,13 +193,13 @@ func setPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setNSAPPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNSAPPTR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NSAPPTR) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Ptr = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -211,13 +211,13 @@ func setNSAPPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) return rr, nil, "" } -func setRP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRP(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(RP) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Mbox = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -227,8 +227,8 @@ func setRP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Mbox = mbox - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rr.Txt = l.token txt, txtOk := toAbsoluteName(l.token, o) @@ -240,13 +240,13 @@ func setRP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MR) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Mr = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -258,13 +258,13 @@ func setMR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMB(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MB) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Mb = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -276,13 +276,13 @@ func setMB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMG(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MG) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Mg = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -294,7 +294,7 @@ func setMG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setHINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setHINFO(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(HINFO) rr.Hdr = h @@ -320,13 +320,13 @@ func setHINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMINFO(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MINFO) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Rmail = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -336,8 +336,8 @@ func setMINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Rmail = rmail - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rr.Email = l.token email, emailOk := toAbsoluteName(l.token, o) @@ -349,13 +349,13 @@ func setMINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMF(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMF(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MF) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Mf = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -367,13 +367,13 @@ func setMF(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMD(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMD(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MD) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Md = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -385,12 +385,12 @@ func setMD(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setMX(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(MX) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -400,8 +400,8 @@ func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Mx = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -413,12 +413,12 @@ func setMX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setRT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRT(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(RT) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -428,8 +428,8 @@ func setRT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Host = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -441,12 +441,12 @@ func setRT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setAFSDB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setAFSDB(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(AFSDB) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -456,8 +456,8 @@ func setAFSDB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Subtype = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Hostname = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -468,12 +468,12 @@ func setAFSDB(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setX25(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setX25(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(X25) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -484,12 +484,12 @@ func setX25(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setKX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setKX(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(KX) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -499,8 +499,8 @@ func setKX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Exchanger = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -511,13 +511,13 @@ func setKX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setCNAME(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCNAME(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(CNAME) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Target = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -529,13 +529,13 @@ func setCNAME(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setDNAME(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setDNAME(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(DNAME) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Target = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -547,13 +547,13 @@ func setDNAME(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSOA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(SOA) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.Ns = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -563,8 +563,8 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Ns = ns - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rr.Mbox = l.token mbox, mboxOk := toAbsoluteName(l.token, o) @@ -573,14 +573,14 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Mbox = mbox - <-c // zBlank + c.Next() // zBlank var ( v uint32 ok bool ) for i := 0; i < 5; i++ { - l = <-c + l, _ = c.Next() if l.err { return nil, &ParseError{f, "bad SOA zone parameter", l}, "" } @@ -600,16 +600,16 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { switch i { case 0: rr.Serial = v - <-c // zBlank + c.Next() // zBlank case 1: rr.Refresh = v - <-c // zBlank + c.Next() // zBlank case 2: rr.Retry = v - <-c // zBlank + c.Next() // zBlank case 3: rr.Expire = v - <-c // zBlank + c.Next() // zBlank case 4: rr.Minttl = v } @@ -617,12 +617,12 @@ func setSOA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSRV(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(SRV) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -632,24 +632,24 @@ func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Priority = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad SRV Weight", l}, "" } rr.Weight = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad SRV Port", l}, "" } rr.Port = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Target = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -660,12 +660,12 @@ func setSRV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNAPTR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NAPTR) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -675,8 +675,8 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Order = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NAPTR Preference", l}, "" @@ -684,15 +684,15 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Preference = uint16(i) // Flags - <-c // zBlank - l = <-c // _QUOTE + c.Next() // zBlank + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Flags", l}, "" } - l = <-c // Either String or Quote + l, _ = c.Next() // Either String or Quote if l.value == zString { rr.Flags = l.token - l = <-c // _QUOTE + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Flags", l}, "" } @@ -703,15 +703,15 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } // Service - <-c // zBlank - l = <-c // _QUOTE + c.Next() // zBlank + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Service", l}, "" } - l = <-c // Either String or Quote + l, _ = c.Next() // Either String or Quote if l.value == zString { rr.Service = l.token - l = <-c // _QUOTE + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Service", l}, "" } @@ -722,15 +722,15 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } // Regexp - <-c // zBlank - l = <-c // _QUOTE + c.Next() // zBlank + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Regexp", l}, "" } - l = <-c // Either String or Quote + l, _ = c.Next() // Either String or Quote if l.value == zString { rr.Regexp = l.token - l = <-c // _QUOTE + l, _ = c.Next() // _QUOTE if l.value != zQuote { return nil, &ParseError{f, "bad NAPTR Regexp", l}, "" } @@ -741,8 +741,8 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } // After quote no space?? - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Replacement = l.token name, nameOk := toAbsoluteName(l.token, o) @@ -753,13 +753,13 @@ func setNAPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setTALINK(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setTALINK(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(TALINK) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.PreviousName = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -769,8 +769,8 @@ func setTALINK(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.PreviousName = previousName - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rr.NextName = l.token nextName, nextNameOk := toAbsoluteName(l.token, o) @@ -782,7 +782,7 @@ func setTALINK(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setLOC(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(LOC) rr.Hdr = h // Non zero defaults for LOC record, see RFC 1876, Section 3. @@ -792,8 +792,8 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { ok := false // North - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } i, e := strconv.ParseUint(l.token, 10, 32) @@ -802,9 +802,9 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Latitude = 1000 * 60 * 60 * uint32(i) - <-c // zBlank + c.Next() // zBlank // Either number, 'N' or 'S' - l = <-c + l, _ = c.Next() if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok { goto East } @@ -814,16 +814,16 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Latitude += 1000 * 60 * uint32(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, e := strconv.ParseFloat(l.token, 32); e != nil || l.err { return nil, &ParseError{f, "bad LOC Latitude seconds", l}, "" } else { rr.Latitude += uint32(1000 * i) } - <-c // zBlank + c.Next() // zBlank // Either number, 'N' or 'S' - l = <-c + l, _ = c.Next() if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok { goto East } @@ -832,16 +832,16 @@ func setLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { East: // East - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, e := strconv.ParseUint(l.token, 10, 32); e != nil || l.err { return nil, &ParseError{f, "bad LOC Longitude", l}, "" } else { rr.Longitude = 1000 * 60 * 60 * uint32(i) } - <-c // zBlank + c.Next() // zBlank // Either number, 'E' or 'W' - l = <-c + l, _ = c.Next() if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok { goto Altitude } @@ -850,16 +850,16 @@ East: } else { rr.Longitude += 1000 * 60 * uint32(i) } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, e := strconv.ParseFloat(l.token, 32); e != nil || l.err { return nil, &ParseError{f, "bad LOC Longitude seconds", l}, "" } else { rr.Longitude += uint32(1000 * i) } - <-c // zBlank + c.Next() // zBlank // Either number, 'E' or 'W' - l = <-c + l, _ = c.Next() if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok { goto Altitude } @@ -867,9 +867,9 @@ East: return nil, &ParseError{f, "bad LOC Longitude East/West", l}, "" Altitude: - <-c // zBlank - l = <-c - if l.length == 0 || l.err { + c.Next() // zBlank + l, _ = c.Next() + if len(l.token) == 0 || l.err { return nil, &ParseError{f, "bad LOC Altitude", l}, "" } if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' { @@ -882,7 +882,7 @@ Altitude: } // And now optionally the other values - l = <-c + l, _ = c.Next() count := 0 for l.value != zNewline && l.value != zEOF { switch l.value { @@ -913,18 +913,18 @@ Altitude: default: return nil, &ParseError{f, "bad LOC Size, HorizPre or VertPre", l}, "" } - l = <-c + l, _ = c.Next() } return rr, nil, "" } -func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setHIP(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(HIP) rr.Hdr = h // HitLength is not represented - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -934,24 +934,24 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.PublicKeyAlgorithm = uint8(i) - <-c // zBlank - l = <-c // zString - if l.length == 0 || l.err { + c.Next() // zBlank + l, _ = c.Next() // zString + if len(l.token) == 0 || l.err { return nil, &ParseError{f, "bad HIP Hit", l}, "" } rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6. rr.HitLength = uint8(len(rr.Hit)) / 2 - <-c // zBlank - l = <-c // zString - if l.length == 0 || l.err { + c.Next() // zBlank + l, _ = c.Next() // zString + if len(l.token) == 0 || l.err { return nil, &ParseError{f, "bad HIP PublicKey", l}, "" } rr.PublicKey = l.token // This cannot contain spaces rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey))) // RendezvousServers (if any) - l = <-c + l, _ = c.Next() var xs []string for l.value != zNewline && l.value != zEOF { switch l.value { @@ -966,18 +966,18 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { default: return nil, &ParseError{f, "bad HIP RendezvousServers", l}, "" } - l = <-c + l, _ = c.Next() } rr.RendezvousServers = xs return rr, nil, l.comment } -func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCERT(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(CERT) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -988,15 +988,15 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } else { rr.Type = uint16(i) } - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e := strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad CERT KeyTag", l}, "" } rr.KeyTag = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString if v, ok := StringToAlgorithm[l.token]; ok { rr.Algorithm = v } else if i, e := strconv.ParseUint(l.token, 10, 8); e != nil { @@ -1012,7 +1012,7 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setOPENPGPKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setOPENPGPKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(OPENPGPKEY) rr.Hdr = h @@ -1024,12 +1024,12 @@ func setOPENPGPKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, strin return rr, nil, c1 } -func setCSYNC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCSYNC(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(CSYNC) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } j, e := strconv.ParseUint(l.token, 10, 32) @@ -1039,9 +1039,9 @@ func setCSYNC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Serial = uint32(j) - <-c // zBlank + c.Next() // zBlank - l = <-c + l, _ = c.Next() j, e = strconv.ParseUint(l.token, 10, 16) if e != nil { // Serial must be a number @@ -1054,14 +1054,15 @@ func setCSYNC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { k uint16 ok bool ) - l = <-c + l, _ = c.Next() for l.value != zNewline && l.value != zEOF { switch l.value { case zBlank: // Ok case zString: - if k, ok = StringToType[l.tokenUpper]; !ok { - if k, ok = typeToInt(l.tokenUpper); !ok { + tokenUpper := strings.ToUpper(l.token) + if k, ok = StringToType[tokenUpper]; !ok { + if k, ok = typeToInt(l.token); !ok { return nil, &ParseError{f, "bad CSYNC TypeBitMap", l}, "" } } @@ -1069,12 +1070,12 @@ func setCSYNC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { default: return nil, &ParseError{f, "bad CSYNC TypeBitMap", l}, "" } - l = <-c + l, _ = c.Next() } return rr, nil, l.comment } -func setSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSIG(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setRRSIG(h, c, o, f) if r != nil { return &SIG{*r.(*RRSIG)}, e, s @@ -1082,18 +1083,19 @@ func setSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, e, s } -func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRRSIG(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(RRSIG) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } - if t, ok := StringToType[l.tokenUpper]; !ok { - if strings.HasPrefix(l.tokenUpper, "TYPE") { - t, ok = typeToInt(l.tokenUpper) + tokenUpper := strings.ToUpper(l.token) + if t, ok := StringToType[tokenUpper]; !ok { + if strings.HasPrefix(tokenUpper, "TYPE") { + t, ok = typeToInt(l.token) if !ok { return nil, &ParseError{f, "bad RRSIG Typecovered", l}, "" } @@ -1105,32 +1107,32 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.TypeCovered = t } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, err := strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG Algorithm", l}, "" } rr.Algorithm = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, err = strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG Labels", l}, "" } rr.Labels = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, err = strconv.ParseUint(l.token, 10, 32) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG OrigTtl", l}, "" } rr.OrigTtl = uint32(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, err := StringToTime(l.token); err != nil { // Try to see if all numeric and use it as epoch if i, err := strconv.ParseInt(l.token, 10, 64); err == nil { @@ -1143,8 +1145,8 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Expiration = i } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, err := StringToTime(l.token); err != nil { if i, err := strconv.ParseInt(l.token, 10, 64); err == nil { rr.Inception = uint32(i) @@ -1155,16 +1157,16 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Inception = i } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, err = strconv.ParseUint(l.token, 10, 16) if err != nil || l.err { return nil, &ParseError{f, "bad RRSIG KeyTag", l}, "" } rr.KeyTag = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rr.SignerName = l.token name, nameOk := toAbsoluteName(l.token, o) if l.err || !nameOk { @@ -1181,13 +1183,13 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setNSEC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNSEC(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NSEC) rr.Hdr = h - l := <-c + l, _ := c.Next() rr.NextDomain = l.token - if l.length == 0 { // dynamic update rr. + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1202,14 +1204,15 @@ func setNSEC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { k uint16 ok bool ) - l = <-c + l, _ = c.Next() for l.value != zNewline && l.value != zEOF { switch l.value { case zBlank: // Ok case zString: - if k, ok = StringToType[l.tokenUpper]; !ok { - if k, ok = typeToInt(l.tokenUpper); !ok { + tokenUpper := strings.ToUpper(l.token) + if k, ok = StringToType[tokenUpper]; !ok { + if k, ok = typeToInt(l.token); !ok { return nil, &ParseError{f, "bad NSEC TypeBitMap", l}, "" } } @@ -1217,17 +1220,17 @@ func setNSEC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { default: return nil, &ParseError{f, "bad NSEC TypeBitMap", l}, "" } - l = <-c + l, _ = c.Next() } return rr, nil, l.comment } -func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNSEC3(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NSEC3) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1236,22 +1239,22 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad NSEC3 Hash", l}, "" } rr.Hash = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3 Flags", l}, "" } rr.Flags = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3 Iterations", l}, "" } rr.Iterations = uint16(i) - <-c - l = <-c + c.Next() + l, _ = c.Next() if len(l.token) == 0 || l.err { return nil, &ParseError{f, "bad NSEC3 Salt", l}, "" } @@ -1260,8 +1263,8 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Salt = l.token } - <-c - l = <-c + c.Next() + l, _ = c.Next() if len(l.token) == 0 || l.err { return nil, &ParseError{f, "bad NSEC3 NextDomain", l}, "" } @@ -1273,14 +1276,15 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { k uint16 ok bool ) - l = <-c + l, _ = c.Next() for l.value != zNewline && l.value != zEOF { switch l.value { case zBlank: // Ok case zString: - if k, ok = StringToType[l.tokenUpper]; !ok { - if k, ok = typeToInt(l.tokenUpper); !ok { + tokenUpper := strings.ToUpper(l.token) + if k, ok = StringToType[tokenUpper]; !ok { + if k, ok = typeToInt(l.token); !ok { return nil, &ParseError{f, "bad NSEC3 TypeBitMap", l}, "" } } @@ -1288,17 +1292,17 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { default: return nil, &ParseError{f, "bad NSEC3 TypeBitMap", l}, "" } - l = <-c + l, _ = c.Next() } return rr, nil, l.comment } -func setNSEC3PARAM(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNSEC3PARAM(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NSEC3PARAM) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1307,22 +1311,22 @@ func setNSEC3PARAM(h RR_Header, c chan lex, o, f string) (RR, *ParseError, strin return nil, &ParseError{f, "bad NSEC3PARAM Hash", l}, "" } rr.Hash = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3PARAM Flags", l}, "" } rr.Flags = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad NSEC3PARAM Iterations", l}, "" } rr.Iterations = uint16(i) - <-c - l = <-c + c.Next() + l, _ = c.Next() if l.token != "-" { rr.SaltLength = uint8(len(l.token)) rr.Salt = l.token @@ -1330,16 +1334,16 @@ func setNSEC3PARAM(h RR_Header, c chan lex, o, f string) (RR, *ParseError, strin return rr, nil, "" } -func setEUI48(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setEUI48(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(EUI48) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } - if l.length != 17 || l.err { + if len(l.token) != 17 || l.err { return nil, &ParseError{f, "bad EUI48 Address", l}, "" } addr := make([]byte, 12) @@ -1363,16 +1367,16 @@ func setEUI48(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setEUI64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setEUI64(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(EUI64) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } - if l.length != 23 || l.err { + if len(l.token) != 23 || l.err { return nil, &ParseError{f, "bad EUI64 Address", l}, "" } addr := make([]byte, 16) @@ -1396,12 +1400,12 @@ func setEUI64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSSHFP(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(SSHFP) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1410,14 +1414,14 @@ func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad SSHFP Algorithm", l}, "" } rr.Algorithm = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SSHFP Type", l}, "" } rr.Type = uint8(i) - <-c // zBlank + c.Next() // zBlank s, e1, c1 := endingToString(c, "bad SSHFP Fingerprint", f) if e1 != nil { return nil, e1, c1 @@ -1426,12 +1430,12 @@ func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setDNSKEYs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) { +func setDNSKEYs(h RR_Header, c *zlexer, o, f, typ string) (RR, *ParseError, string) { rr := new(DNSKEY) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1440,15 +1444,15 @@ func setDNSKEYs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, str return nil, &ParseError{f, "bad " + typ + " Flags", l}, "" } rr.Flags = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " Protocol", l}, "" } rr.Protocol = uint8(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, "" @@ -1462,7 +1466,7 @@ func setDNSKEYs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, str return rr, nil, c1 } -func setKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDNSKEYs(h, c, o, f, "KEY") if r != nil { return &KEY{*r.(*DNSKEY)}, e, s @@ -1470,12 +1474,12 @@ func setKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, e, s } -func setDNSKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setDNSKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDNSKEYs(h, c, o, f, "DNSKEY") return r, e, s } -func setCDNSKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCDNSKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDNSKEYs(h, c, o, f, "CDNSKEY") if r != nil { return &CDNSKEY{*r.(*DNSKEY)}, e, s @@ -1483,12 +1487,12 @@ func setCDNSKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) return nil, e, s } -func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(RKEY) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1497,15 +1501,15 @@ func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad RKEY Flags", l}, "" } rr.Flags = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad RKEY Protocol", l}, "" } rr.Protocol = uint8(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad RKEY Algorithm", l}, "" @@ -1519,7 +1523,7 @@ func setRKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setEID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setEID(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(EID) rr.Hdr = h s, e, c1 := endingToString(c, "bad EID Endpoint", f) @@ -1530,7 +1534,7 @@ func setEID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setNIMLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNIMLOC(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NIMLOC) rr.Hdr = h s, e, c1 := endingToString(c, "bad NIMLOC Locator", f) @@ -1541,12 +1545,12 @@ func setNIMLOC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setGPOS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setGPOS(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(GPOS) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1555,15 +1559,15 @@ func setGPOS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad GPOS Longitude", l}, "" } rr.Longitude = l.token - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() _, e = strconv.ParseFloat(l.token, 64) if e != nil || l.err { return nil, &ParseError{f, "bad GPOS Latitude", l}, "" } rr.Latitude = l.token - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() _, e = strconv.ParseFloat(l.token, 64) if e != nil || l.err { return nil, &ParseError{f, "bad GPOS Altitude", l}, "" @@ -1572,12 +1576,12 @@ func setGPOS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) { +func setDSs(h RR_Header, c *zlexer, o, f, typ string) (RR, *ParseError, string) { rr := new(DS) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1586,10 +1590,11 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) return nil, &ParseError{f, "bad " + typ + " KeyTag", l}, "" } rr.KeyTag = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, e = strconv.ParseUint(l.token, 10, 8); e != nil { - i, ok := StringToAlgorithm[l.tokenUpper] + tokenUpper := strings.ToUpper(l.token) + i, ok := StringToAlgorithm[tokenUpper] if !ok || l.err { return nil, &ParseError{f, "bad " + typ + " Algorithm", l}, "" } @@ -1597,8 +1602,8 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) } else { rr.Algorithm = uint8(i) } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad " + typ + " DigestType", l}, "" @@ -1612,12 +1617,12 @@ func setDSs(h RR_Header, c chan lex, o, f, typ string) (RR, *ParseError, string) return rr, nil, c1 } -func setDS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setDS(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDSs(h, c, o, f, "DS") return r, e, s } -func setDLV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setDLV(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDSs(h, c, o, f, "DLV") if r != nil { return &DLV{*r.(*DS)}, e, s @@ -1625,7 +1630,7 @@ func setDLV(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, e, s } -func setCDS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCDS(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { r, e, s := setDSs(h, c, o, f, "CDS") if r != nil { return &CDS{*r.(*DS)}, e, s @@ -1633,12 +1638,12 @@ func setCDS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, e, s } -func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setTA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(TA) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1647,10 +1652,11 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad TA KeyTag", l}, "" } rr.KeyTag = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if i, e := strconv.ParseUint(l.token, 10, 8); e != nil { - i, ok := StringToAlgorithm[l.tokenUpper] + tokenUpper := strings.ToUpper(l.token) + i, ok := StringToAlgorithm[tokenUpper] if !ok || l.err { return nil, &ParseError{f, "bad TA Algorithm", l}, "" } @@ -1658,8 +1664,8 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } else { rr.Algorithm = uint8(i) } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TA DigestType", l}, "" @@ -1673,12 +1679,12 @@ func setTA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setTLSA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setTLSA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(TLSA) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1687,15 +1693,15 @@ func setTLSA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad TLSA Usage", l}, "" } rr.Usage = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TLSA Selector", l}, "" } rr.Selector = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad TLSA MatchingType", l}, "" @@ -1710,12 +1716,12 @@ func setTLSA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setSMIMEA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSMIMEA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(SMIMEA) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -1724,15 +1730,15 @@ func setSMIMEA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad SMIMEA Usage", l}, "" } rr.Usage = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SMIMEA Selector", l}, "" } rr.Selector = uint8(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 8) if e != nil || l.err { return nil, &ParseError{f, "bad SMIMEA MatchingType", l}, "" @@ -1747,17 +1753,17 @@ func setSMIMEA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setRFC3597(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setRFC3597(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(RFC3597) rr.Hdr = h - l := <-c + l, _ := c.Next() if l.token != "\\#" { return nil, &ParseError{f, "bad RFC3597 Rdata", l}, "" } - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() rdlength, e := strconv.Atoi(l.token) if e != nil || l.err { return nil, &ParseError{f, "bad RFC3597 Rdata ", l}, "" @@ -1774,7 +1780,7 @@ func setRFC3597(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) return rr, nil, c1 } -func setSPF(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setSPF(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(SPF) rr.Hdr = h @@ -1786,7 +1792,7 @@ func setSPF(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setAVC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setAVC(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(AVC) rr.Hdr = h @@ -1798,7 +1804,7 @@ func setAVC(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setTXT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setTXT(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(TXT) rr.Hdr = h @@ -1812,7 +1818,7 @@ func setTXT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } // identical to setTXT -func setNINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNINFO(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NINFO) rr.Hdr = h @@ -1824,12 +1830,12 @@ func setNINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setURI(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(URI) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1838,15 +1844,15 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad URI Priority", l}, "" } rr.Priority = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() i, e = strconv.ParseUint(l.token, 10, 16) if e != nil || l.err { return nil, &ParseError{f, "bad URI Weight", l}, "" } rr.Weight = uint16(i) - <-c // zBlank + c.Next() // zBlank s, err, c1 := endingToTxtSlice(c, "bad URI Target", f) if err != nil { return nil, err, "" @@ -1858,7 +1864,7 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setDHCID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setDHCID(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { // awesome record to parse! rr := new(DHCID) rr.Hdr = h @@ -1871,12 +1877,12 @@ func setDHCID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setNID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setNID(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(NID) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1885,8 +1891,8 @@ func setNID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad NID Preference", l}, "" } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString u, err := stringToNodeID(l) if err != nil || l.err { return nil, err, "" @@ -1895,12 +1901,12 @@ func setNID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setL32(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setL32(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(L32) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1909,8 +1915,8 @@ func setL32(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad L32 Preference", l}, "" } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Locator32 = net.ParseIP(l.token) if rr.Locator32 == nil || l.err { return nil, &ParseError{f, "bad L32 Locator", l}, "" @@ -1918,12 +1924,12 @@ func setL32(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setLP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setLP(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(LP) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1933,8 +1939,8 @@ func setLP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Fqdn = l.token name, nameOk := toAbsoluteName(l.token, o) if l.err || !nameOk { @@ -1945,12 +1951,12 @@ func setLP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setL64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setL64(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(L64) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1959,8 +1965,8 @@ func setL64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return nil, &ParseError{f, "bad L64 Preference", l}, "" } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString u, err := stringToNodeID(l) if err != nil || l.err { return nil, err, "" @@ -1969,12 +1975,12 @@ func setL64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setUID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setUID(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(UID) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -1986,12 +1992,12 @@ func setUID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setGID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setGID(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(GID) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -2003,7 +2009,7 @@ func setGID(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setUINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setUINFO(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(UINFO) rr.Hdr = h @@ -2018,12 +2024,12 @@ func setUINFO(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setPX(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(PX) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, "" } @@ -2033,8 +2039,8 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Preference = uint16(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Map822 = l.token map822, map822Ok := toAbsoluteName(l.token, o) if l.err || !map822Ok { @@ -2042,8 +2048,8 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Map822 = map822 - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString rr.Mapx400 = l.token mapx400, mapx400Ok := toAbsoluteName(l.token, o) if l.err || !mapx400Ok { @@ -2054,12 +2060,12 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, "" } -func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setCAA(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(CAA) rr.Hdr = h - l := <-c - if l.length == 0 { // dynamic update rr. + l, _ := c.Next() + if len(l.token) == 0 { // dynamic update rr. return rr, nil, l.comment } @@ -2069,14 +2075,14 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Flag = uint8(i) - <-c // zBlank - l = <-c // zString + c.Next() // zBlank + l, _ = c.Next() // zString if l.value != zString { return nil, &ParseError{f, "bad CAA Tag", l}, "" } rr.Tag = l.token - <-c // zBlank + c.Next() // zBlank s, e, c1 := endingToTxtSlice(c, "bad CAA Value", f) if e != nil { return nil, e, "" @@ -2088,43 +2094,43 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { return rr, nil, c1 } -func setTKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { +func setTKEY(h RR_Header, c *zlexer, o, f string) (RR, *ParseError, string) { rr := new(TKEY) rr.Hdr = h - l := <-c + l, _ := c.Next() // Algorithm if l.value != zString { return nil, &ParseError{f, "bad TKEY algorithm", l}, "" } rr.Algorithm = l.token - <-c // zBlank + c.Next() // zBlank // Get the key length and key values - l = <-c + l, _ = c.Next() i, err := strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad TKEY key length", l}, "" } rr.KeySize = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if l.value != zString { return nil, &ParseError{f, "bad TKEY key", l}, "" } rr.Key = l.token - <-c // zBlank + c.Next() // zBlank // Get the otherdata length and string data - l = <-c + l, _ = c.Next() i, err = strconv.ParseUint(l.token, 10, 8) if err != nil || l.err { return nil, &ParseError{f, "bad TKEY otherdata length", l}, "" } rr.OtherLen = uint16(i) - <-c // zBlank - l = <-c + c.Next() // zBlank + l, _ = c.Next() if l.value != zString { return nil, &ParseError{f, "bad TKEY otherday", l}, "" } diff --git a/vendor/github.com/miekg/dns/scanner.go b/vendor/github.com/miekg/dns/scanner.go deleted file mode 100644 index 5b124ec59..000000000 --- a/vendor/github.com/miekg/dns/scanner.go +++ /dev/null @@ -1,56 +0,0 @@ -package dns - -// Implement a simple scanner, return a byte stream from an io reader. - -import ( - "bufio" - "context" - "io" - "text/scanner" -) - -type scan struct { - src *bufio.Reader - position scanner.Position - eof bool // Have we just seen a eof - ctx context.Context -} - -func scanInit(r io.Reader) (*scan, context.CancelFunc) { - s := new(scan) - s.src = bufio.NewReader(r) - s.position.Line = 1 - - ctx, cancel := context.WithCancel(context.Background()) - s.ctx = ctx - - return s, cancel -} - -// tokenText returns the next byte from the input -func (s *scan) tokenText() (byte, error) { - c, err := s.src.ReadByte() - if err != nil { - return c, err - } - select { - case <-s.ctx.Done(): - return c, context.Canceled - default: - break - } - - // delay the newline handling until the next token is delivered, - // fixes off-by-one errors when reporting a parse error. - if s.eof { - s.position.Line++ - s.position.Column = 0 - s.eof = false - } - if c == '\n' { - s.eof = true - return c, nil - } - s.position.Column++ - return c, nil -} diff --git a/vendor/github.com/miekg/dns/version.go b/vendor/github.com/miekg/dns/version.go index 403b9ef97..0b0e9b6d8 100644 --- a/vendor/github.com/miekg/dns/version.go +++ b/vendor/github.com/miekg/dns/version.go @@ -3,7 +3,7 @@ package dns import "fmt" // Version is current version of this library. -var Version = V{1, 0, 13} +var Version = V{1, 0, 14} // V holds the version of this library. type V struct { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/http.go b/vendor/github.com/prometheus/client_golang/prometheus/http.go index 4b8e60273..9f0875bfc 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/http.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/http.go @@ -15,9 +15,7 @@ package prometheus import ( "bufio" - "bytes" "compress/gzip" - "fmt" "io" "net" "net/http" @@ -41,19 +39,10 @@ const ( acceptEncodingHeader = "Accept-Encoding" ) -var bufPool sync.Pool - -func getBuf() *bytes.Buffer { - buf := bufPool.Get() - if buf == nil { - return &bytes.Buffer{} - } - return buf.(*bytes.Buffer) -} - -func giveBuf(buf *bytes.Buffer) { - buf.Reset() - bufPool.Put(buf) +var gzipPool = sync.Pool{ + New: func() interface{} { + return gzip.NewWriter(nil) + }, } // Handler returns an HTTP handler for the DefaultGatherer. It is @@ -71,58 +60,40 @@ func Handler() http.Handler { // Deprecated: Use promhttp.HandlerFor(DefaultGatherer, promhttp.HandlerOpts{}) // instead. See there for further documentation. func UninstrumentedHandler() http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + return http.HandlerFunc(func(rsp http.ResponseWriter, req *http.Request) { mfs, err := DefaultGatherer.Gather() if err != nil { - http.Error(w, "An error has occurred during metrics collection:\n\n"+err.Error(), http.StatusInternalServerError) + httpError(rsp, err) return } contentType := expfmt.Negotiate(req.Header) - buf := getBuf() - defer giveBuf(buf) - writer, encoding := decorateWriter(req, buf) - enc := expfmt.NewEncoder(writer, contentType) - var lastErr error + header := rsp.Header() + header.Set(contentTypeHeader, string(contentType)) + + w := io.Writer(rsp) + if gzipAccepted(req.Header) { + header.Set(contentEncodingHeader, "gzip") + gz := gzipPool.Get().(*gzip.Writer) + defer gzipPool.Put(gz) + + gz.Reset(w) + defer gz.Close() + + w = gz + } + + enc := expfmt.NewEncoder(w, contentType) + for _, mf := range mfs { if err := enc.Encode(mf); err != nil { - lastErr = err - http.Error(w, "An error has occurred during metrics encoding:\n\n"+err.Error(), http.StatusInternalServerError) + httpError(rsp, err) return } } - if closer, ok := writer.(io.Closer); ok { - closer.Close() - } - if lastErr != nil && buf.Len() == 0 { - http.Error(w, "No metrics encoded, last error:\n\n"+lastErr.Error(), http.StatusInternalServerError) - return - } - header := w.Header() - header.Set(contentTypeHeader, string(contentType)) - header.Set(contentLengthHeader, fmt.Sprint(buf.Len())) - if encoding != "" { - header.Set(contentEncodingHeader, encoding) - } - w.Write(buf.Bytes()) }) } -// decorateWriter wraps a writer to handle gzip compression if requested. It -// returns the decorated writer and the appropriate "Content-Encoding" header -// (which is empty if no compression is enabled). -func decorateWriter(request *http.Request, writer io.Writer) (io.Writer, string) { - header := request.Header.Get(acceptEncodingHeader) - parts := strings.Split(header, ",") - for _, part := range parts { - part = strings.TrimSpace(part) - if part == "gzip" || strings.HasPrefix(part, "gzip;") { - return gzip.NewWriter(writer), "gzip" - } - } - return writer, "" -} - var instLabels = []string{"method", "code"} type nower interface { @@ -503,3 +474,31 @@ func sanitizeCode(s int) string { return strconv.Itoa(s) } } + +// gzipAccepted returns whether the client will accept gzip-encoded content. +func gzipAccepted(header http.Header) bool { + a := header.Get(acceptEncodingHeader) + parts := strings.Split(a, ",") + for _, part := range parts { + part = strings.TrimSpace(part) + if part == "gzip" || strings.HasPrefix(part, "gzip;") { + return true + } + } + return false +} + +// httpError removes any content-encoding header and then calls http.Error with +// the provided error and http.StatusInternalServerErrer. Error contents is +// supposed to be uncompressed plain text. However, same as with a plain +// http.Error, any header settings will be void if the header has already been +// sent. The error message will still be written to the writer, but it will +// probably be of limited use. +func httpError(rsp http.ResponseWriter, err error) { + rsp.Header().Del(contentEncodingHeader) + http.Error( + rsp, + "An error has occurred while serving metrics:\n\n"+err.Error(), + http.StatusInternalServerError, + ) +} diff --git a/vendor/github.com/prometheus/common/expfmt/text_create.go b/vendor/github.com/prometheus/common/expfmt/text_create.go index 46b74364e..8e473d0fe 100644 --- a/vendor/github.com/prometheus/common/expfmt/text_create.go +++ b/vendor/github.com/prometheus/common/expfmt/text_create.go @@ -19,6 +19,7 @@ import ( "io" "math" "strconv" + "strings" "sync" "github.com/prometheus/common/model" @@ -43,7 +44,7 @@ const ( var ( bufPool = sync.Pool{ New: func() interface{} { - return bytes.NewBuffer(make([]byte, 0, initialNumBufSize)) + return bytes.NewBuffer(make([]byte, 0, initialBufSize)) }, } numBufPool = sync.Pool{ @@ -416,32 +417,17 @@ func writeLabelPairs( // writeEscapedString replaces '\' by '\\', new line character by '\n', and - if // includeDoubleQuote is true - '"' by '\"'. +var ( + escaper = strings.NewReplacer("\\", `\\`, "\n", `\n`) + quotedEscaper = strings.NewReplacer("\\", `\\`, "\n", `\n`, "\"", `\"`) +) + func writeEscapedString(w enhancedWriter, v string, includeDoubleQuote bool) (int, error) { - var ( - written, n int - err error - ) - for _, r := range v { - switch r { - case '\\': - n, err = w.WriteString(`\\`) - case '\n': - n, err = w.WriteString(`\n`) - case '"': - if includeDoubleQuote { - n, err = w.WriteString(`\"`) - } else { - n, err = w.WriteRune(r) - } - default: - n, err = w.WriteRune(r) - } - written += n - if err != nil { - return written, err - } + if includeDoubleQuote { + return quotedEscaper.WriteString(w, v) + } else { + return escaper.WriteString(w, v) } - return written, nil } // writeFloat is equivalent to fmt.Fprint with a float64 argument but hardcodes diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go index 74ed5a9f7..46259b1f1 100644 --- a/vendor/github.com/prometheus/common/model/time.go +++ b/vendor/github.com/prometheus/common/model/time.go @@ -43,7 +43,7 @@ const ( // (1970-01-01 00:00 UTC) excluding leap seconds. type Time int64 -// Interval describes and interval between two timestamps. +// Interval describes an interval between two timestamps. type Interval struct { Start, End Time } diff --git a/vendor/github.com/satori/go.uuid/README.md b/vendor/github.com/satori/go.uuid/README.md index 770284969..362b27067 100644 --- a/vendor/github.com/satori/go.uuid/README.md +++ b/vendor/github.com/satori/go.uuid/README.md @@ -23,7 +23,7 @@ Use the `go` command: ## Requirements -UUID package requires Go >= 1.2. +UUID package tested against Go >= 1.6. ## Example @@ -53,6 +53,7 @@ func main() { u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8") if err != nil { fmt.Printf("Something went wrong: %s", err) + return } fmt.Printf("Successfully parsed: %s", u2) } diff --git a/vendor/github.com/satori/go.uuid/generator.go b/vendor/github.com/satori/go.uuid/generator.go index 499dc35fb..c50d33cab 100644 --- a/vendor/github.com/satori/go.uuid/generator.go +++ b/vendor/github.com/satori/go.uuid/generator.go @@ -165,7 +165,7 @@ func (g *rfc4122Generator) NewV3(ns UUID, name string) UUID { // NewV4 returns random generated UUID. func (g *rfc4122Generator) NewV4() (UUID, error) { u := UUID{} - if _, err := g.rand.Read(u[:]); err != nil { + if _, err := io.ReadFull(g.rand, u[:]); err != nil { return Nil, err } u.SetVersion(V4) @@ -188,7 +188,7 @@ func (g *rfc4122Generator) getClockSequence() (uint64, uint16, error) { var err error g.clockSequenceOnce.Do(func() { buf := make([]byte, 2) - if _, err = g.rand.Read(buf); err != nil { + if _, err = io.ReadFull(g.rand, buf); err != nil { return } g.clockSequence = binary.BigEndian.Uint16(buf) @@ -222,7 +222,7 @@ func (g *rfc4122Generator) getHardwareAddr() ([]byte, error) { // Initialize hardwareAddr randomly in case // of real network interfaces absence. - if _, err = g.rand.Read(g.hardwareAddr[:]); err != nil { + if _, err = io.ReadFull(g.rand, g.hardwareAddr[:]); err != nil { return } // Set multicast bit as recommended by RFC 4122 diff --git a/vendor/github.com/siddontang/go-mysql/server/auth.go b/vendor/github.com/siddontang/go-mysql/server/auth.go index b66ea4e0c..0a098e69c 100644 --- a/vendor/github.com/siddontang/go-mysql/server/auth.go +++ b/vendor/github.com/siddontang/go-mysql/server/auth.go @@ -89,20 +89,37 @@ func (c *Conn) readHandshakeResponse(password string) error { return NewDefaultError(ER_NO_SUCH_USER, user, c.RemoteAddr().String()) } - //auth length and auth - authLen := int(data[pos]) - pos++ - auth := data[pos : pos+authLen] + var auth []byte + + if c.capability&CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA > 0 { + // Fix from github.com/pingcap/tidb + // MySQL client sets the wrong capability, it will set this bit even server doesn't + // support ClientPluginAuthLenencClientData. + // https://github.com/mysql/mysql-server/blob/5.7/sql-common/client.c#L3478 + num, null, off := parseLengthEncodedInt(data[pos:]) + pos += off + if !null { + auth = data[pos : pos+int(num)] + pos += int(num) + } + } else if c.capability&CLIENT_SECURE_CONNECTION > 0 { + //auth length and auth + authLen := int(data[pos]) + pos++ + auth = data[pos : pos+authLen] + pos += authLen + } else { + auth = data[pos : pos+bytes.IndexByte(data[pos:], 0)] + pos += len(auth) + 1 + } checkAuth := CalcPassword(c.salt, []byte(password)) if !bytes.Equal(auth, checkAuth) { - return NewDefaultError(ER_ACCESS_DENIED_ERROR, c.RemoteAddr().String(), c.user, "Yes") + return NewDefaultError(ER_ACCESS_DENIED_ERROR, c.user, c.RemoteAddr().String(), "Yes") } - pos += authLen - - if c.capability|CLIENT_CONNECT_WITH_DB > 0 { + if c.capability&CLIENT_CONNECT_WITH_DB > 0 { if len(data[pos:]) == 0 { return nil } @@ -117,3 +134,38 @@ func (c *Conn) readHandshakeResponse(password string) error { return nil } + +func parseLengthEncodedInt(b []byte) (num uint64, isNull bool, n int) { + switch b[0] { + // 251: NULL + case 0xfb: + n = 1 + isNull = true + return + + // 252: value of following 2 + case 0xfc: + num = uint64(b[1]) | uint64(b[2])<<8 + n = 3 + return + + // 253: value of following 3 + case 0xfd: + num = uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 + n = 4 + return + + // 254: value of following 8 + case 0xfe: + num = uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 | + uint64(b[4])<<24 | uint64(b[5])<<32 | uint64(b[6])<<40 | + uint64(b[7])<<48 | uint64(b[8])<<56 + n = 9 + return + } + + // 0-250: value of first byte + num = uint64(b[0]) + n = 1 + return +} diff --git a/vendor/github.com/xo/tblfmt/go.mod b/vendor/github.com/xo/tblfmt/go.mod index b8dc613f2..f66af95c8 100644 --- a/vendor/github.com/xo/tblfmt/go.mod +++ b/vendor/github.com/xo/tblfmt/go.mod @@ -1,3 +1,6 @@ module github.com/xo/tblfmt -require github.com/mattn/go-runewidth v0.0.3 +require ( + github.com/mattn/go-runewidth v0.0.3 + github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132 +) diff --git a/vendor/github.com/xo/tblfmt/go.sum b/vendor/github.com/xo/tblfmt/go.sum index 1c1891604..977b1d669 100644 --- a/vendor/github.com/xo/tblfmt/go.sum +++ b/vendor/github.com/xo/tblfmt/go.sum @@ -1,2 +1,4 @@ github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132 h1:cRKJ4yZeCZbCEXJmjZMa9s2z+3eavo2a4qu/usvVopI= +github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132/go.mod h1:g6rdekR8vgfVZrkLWfobLTm0kVez7GAN23mWtkGCJ14= diff --git a/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s b/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s new file mode 100644 index 000000000..06f84b855 --- /dev/null +++ b/vendor/golang.org/x/sys/unix/asm_aix_ppc64.s @@ -0,0 +1,17 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !gccgo + +#include "textflag.h" + +// +// System calls for ppc64, AIX are implemented in runtime/syscall_aix.go +// + +TEXT ·syscall6(SB),NOSPLIT,$0-88 + JMP syscall·syscall6(SB) + +TEXT ·rawSyscall6(SB),NOSPLIT,$0-88 + JMP syscall·rawSyscall6(SB) diff --git a/vendor/golang.org/x/sys/unix/mkall.sh b/vendor/golang.org/x/sys/unix/mkall.sh index edb176f16..9b76ad669 100755 --- a/vendor/golang.org/x/sys/unix/mkall.sh +++ b/vendor/golang.org/x/sys/unix/mkall.sh @@ -61,12 +61,12 @@ _* | *_ | _) ;; aix_ppc) mkerrors="$mkerrors -maix32" - mksyscall="perl mksyscall_aix.pl -aix" + mksyscall="./mksyscall_aix_ppc.pl -aix" mktypes="GOARCH=$GOARCH go tool cgo -godefs" ;; aix_ppc64) mkerrors="$mkerrors -maix64" - mksyscall="perl mksyscall_aix.pl -aix" + mksyscall="./mksyscall_aix_ppc64.pl -aix" mktypes="GOARCH=$GOARCH go tool cgo -godefs" ;; darwin_386) @@ -187,8 +187,14 @@ esac syscall_goos="syscall_bsd.go $syscall_goos" ;; esac - if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi - ;; + if [ -n "$mksyscall" ]; then + if [ "$GOOSARCH" == "aix_ppc64" ]; then + # aix/ppc64 script generates files instead of writing to stdin. + echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in && gofmt -w zsyscall_$GOOSARCH.go && gofmt -w zsyscall_"$GOOSARCH"_gccgo.go && gofmt -w zsyscall_"$GOOSARCH"_gc.go " ; + else + echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; + fi + fi esac if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi diff --git a/vendor/golang.org/x/sys/unix/mksyscall_aix.pl b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl old mode 100644 new mode 100755 similarity index 98% rename from vendor/golang.org/x/sys/unix/mksyscall_aix.pl rename to vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl index c9b3954ba..c44de8d31 --- a/vendor/golang.org/x/sys/unix/mksyscall_aix.pl +++ b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.pl @@ -19,7 +19,7 @@ use strict; -my $cmdline = "mksyscall_aix.pl " . join(' ', @ARGV); +my $cmdline = "mksyscall_aix_ppc.pl " . join(' ', @ARGV); my $errors = 0; my $_32bit = ""; my $tags = ""; # build tags @@ -72,7 +72,7 @@ ($) my $package = ""; my $text = ""; -my $c_extern = "/*\n#include \n"; +my $c_extern = "/*\n#include \n#include \n"; my @vars = (); while(<>) { chomp; @@ -369,7 +369,6 @@ package $package import "C" import ( "unsafe" - "syscall" ) diff --git a/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl new file mode 100755 index 000000000..53df26bb9 --- /dev/null +++ b/vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.pl @@ -0,0 +1,579 @@ +#!/usr/bin/env perl +# Copyright 2018 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# This program reads a file containing function prototypes +# (like syscall_aix.go) and generates system call bodies. +# The prototypes are marked by lines beginning with "//sys" +# and read like func declarations if //sys is replaced by func, but: +# * The parameter lists must give a name for each argument. +# This includes return parameters. +# * The parameter lists must give a type for each argument: +# the (x, y, z int) shorthand is not allowed. +# * If the return parameter is an error number, it must be named err. +# * If go func name needs to be different than its libc name, +# * or the function is not in libc, name could be specified +# * at the end, after "=" sign, like +# //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt + +# This program will generate three files and handle both gc and gccgo implementation: +# - zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation) +# - zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6 +# - zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type. + +# The generated code looks like this +# +# zsyscall_aix_ppc64.go +# func asyscall(...) (n int, err error) { +# // Pointer Creation +# r1, e1 := callasyscall(...) +# // Type Conversion +# // Error Handler +# return +# } +# +# zsyscall_aix_ppc64_gc.go +# //go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o" +# //go:linkname libc_asyscall libc_asyscall +# var asyscall syscallFunc +# +# func callasyscall(...) (r1 uintptr, e1 Errno) { +# r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... ) +# return +# } +# +# zsyscall_aix_ppc64_ggcgo.go +# /* +# int asyscall(...) +# +# */ +# import "C" +# +# func callasyscall(...) (r1 uintptr, e1 Errno) { +# r1 = uintptr(C.asyscall(...)) +# e1 = syscall.GetErrno() +# return +# } + + + +use strict; + +my $cmdline = "mksyscall_aix_ppc64.pl " . join(' ', @ARGV); +my $errors = 0; +my $_32bit = ""; +my $tags = ""; # build tags +my $aix = 0; +my $solaris = 0; + +binmode STDOUT; + +if($ARGV[0] eq "-b32") { + $_32bit = "big-endian"; + shift; +} elsif($ARGV[0] eq "-l32") { + $_32bit = "little-endian"; + shift; +} +if($ARGV[0] eq "-aix") { + $aix = 1; + shift; +} +if($ARGV[0] eq "-tags") { + shift; + $tags = $ARGV[0]; + shift; +} + +if($ARGV[0] =~ /^-/) { + print STDERR "usage: mksyscall_aix.pl [-b32 | -l32] [-tags x,y] [file ...]\n"; + exit 1; +} + +sub parseparamlist($) { + my ($list) = @_; + $list =~ s/^\s*//; + $list =~ s/\s*$//; + if($list eq "") { + return (); + } + return split(/\s*,\s*/, $list); +} + +sub parseparam($) { + my ($p) = @_; + if($p !~ /^(\S*) (\S*)$/) { + print STDERR "$ARGV:$.: malformed parameter: $p\n"; + $errors = 1; + return ("xx", "int"); + } + return ($1, $2); +} + +my $package = ""; +# GCCGO +my $textgccgo = ""; +my $c_extern = "/*\n#include \n"; +# GC +my $textgc = ""; +my $dynimports = ""; +my $linknames = ""; +my @vars = (); +# COMMUN +my $textcommon = ""; + +while(<>) { + chomp; + s/\s+/ /g; + s/^\s+//; + s/\s+$//; + $package = $1 if !$package && /^package (\S+)$/; + my $nonblock = /^\/\/sysnb /; + next if !/^\/\/sys / && !$nonblock; + + # Line must be of the form + # func Open(path string, mode int, perm int) (fd int, err error) + # Split into name, in params, out params. + if(!/^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$/) { + print STDERR "$ARGV:$.: malformed //sys declaration\n"; + $errors = 1; + next; + } + my ($nb, $func, $in, $out, $modname, $sysname) = ($1, $2, $3, $4, $5, $6); + + # Split argument lists on comma. + my @in = parseparamlist($in); + my @out = parseparamlist($out); + + $in = join(', ', @in); + $out = join(', ', @out); + + if($sysname eq "") { + $sysname = "$func"; + } + + my $onlyCommon = 0; + if ($func eq "readlen" || $func eq "writelen" || $func eq "FcntlInt" || $func eq "FcntlFlock") { + # This function call another syscall which is already implemented. + # Therefore, the gc and gccgo part must not be generated. + $onlyCommon = 1 + } + + # Try in vain to keep people from editing this file. + # The theory is that they jump into the middle of the file + # without reading the header. + + $textcommon .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"; + if (!$onlyCommon) { + $textgccgo .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"; + $textgc .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"; + } + + + # Check if value return, err return available + my $errvar = ""; + my $retvar = ""; + my $rettype = ""; + foreach my $p (@out) { + my ($name, $type) = parseparam($p); + if($type eq "error") { + $errvar = $name; + } else { + $retvar = $name; + $rettype = $type; + } + } + + + $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; + $sysname =~ y/A-Z/a-z/; # All libc functions are lowercase. + + # GCCGO Prototype return type + my $C_rettype = ""; + if($rettype eq "unsafe.Pointer") { + $C_rettype = "uintptr_t"; + } elsif($rettype eq "uintptr") { + $C_rettype = "uintptr_t"; + } elsif($rettype =~ /^_/) { + $C_rettype = "uintptr_t"; + } elsif($rettype eq "int") { + $C_rettype = "int"; + } elsif($rettype eq "int32") { + $C_rettype = "int"; + } elsif($rettype eq "int64") { + $C_rettype = "long long"; + } elsif($rettype eq "uint32") { + $C_rettype = "unsigned int"; + } elsif($rettype eq "uint64") { + $C_rettype = "unsigned long long"; + } else { + $C_rettype = "int"; + } + if($sysname eq "exit") { + $C_rettype = "void"; + } + + # GCCGO Prototype arguments type + my @c_in = (); + foreach my $i (0 .. $#in) { + my ($name, $type) = parseparam($in[$i]); + if($type =~ /^\*/) { + push @c_in, "uintptr_t"; + } elsif($type eq "string") { + push @c_in, "uintptr_t"; + } elsif($type =~ /^\[\](.*)/) { + push @c_in, "uintptr_t", "size_t"; + } elsif($type eq "unsafe.Pointer") { + push @c_in, "uintptr_t"; + } elsif($type eq "uintptr") { + push @c_in, "uintptr_t"; + } elsif($type =~ /^_/) { + push @c_in, "uintptr_t"; + } elsif($type eq "int") { + if (($i == 0 || $i == 2) && $func eq "fcntl"){ + # These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock + push @c_in, "uintptr_t"; + } else { + push @c_in, "int"; + } + } elsif($type eq "int32") { + push @c_in, "int"; + } elsif($type eq "int64") { + push @c_in, "long long"; + } elsif($type eq "uint32") { + push @c_in, "unsigned int"; + } elsif($type eq "uint64") { + push @c_in, "unsigned long long"; + } else { + push @c_in, "int"; + } + } + + if (!$onlyCommon){ + # GCCGO Prototype Generation + # Imports of system calls from libc + $c_extern .= "$C_rettype $sysname"; + my $c_in = join(', ', @c_in); + $c_extern .= "($c_in);\n"; + } + + # GC Library name + if($modname eq "") { + $modname = "libc.a/shr_64.o"; + } else { + print STDERR "$func: only syscall using libc are available\n"; + $errors = 1; + next; + } + my $sysvarname = "libc_${sysname}"; + + if (!$onlyCommon){ + # GC Runtime import of function to allow cross-platform builds. + $dynimports .= "//go:cgo_import_dynamic ${sysvarname} ${sysname} \"$modname\"\n"; + # GC Link symbol to proc address variable. + $linknames .= "//go:linkname ${sysvarname} ${sysvarname}\n"; + # GC Library proc address variable. + push @vars, $sysvarname; + } + + my $strconvfunc ="BytePtrFromString"; + my $strconvtype = "*byte"; + + # Go function header. + if($out ne "") { + $out = " ($out)"; + } + if($textcommon ne "") { + $textcommon .= "\n" + } + + $textcommon .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out ; + + # Prepare arguments to call. + my @argscommun = (); # Arguments in the commun part + my @argscall = (); # Arguments for call prototype + my @argsgc = (); # Arguments for gc call (with syscall6) + my @argsgccgo = (); # Arguments for gccgo call (with C.name_of_syscall) + my $n = 0; + my $arg_n = 0; + foreach my $p (@in) { + my ($name, $type) = parseparam($p); + if($type =~ /^\*/) { + push @argscommun, "uintptr(unsafe.Pointer($name))"; + push @argscall, "$name uintptr"; + push @argsgc, "$name"; + push @argsgccgo, "C.uintptr_t($name)"; + } elsif($type eq "string" && $errvar ne "") { + $textcommon .= "\tvar _p$n $strconvtype\n"; + $textcommon .= "\t_p$n, $errvar = $strconvfunc($name)\n"; + $textcommon .= "\tif $errvar != nil {\n\t\treturn\n\t}\n"; + + push @argscommun, "uintptr(unsafe.Pointer(_p$n))"; + push @argscall, "_p$n uintptr "; + push @argsgc, "_p$n"; + push @argsgccgo, "C.uintptr_t(_p$n)"; + $n++; + } elsif($type eq "string") { + print STDERR "$ARGV:$.: $func uses string arguments, but has no error return\n"; + $textcommon .= "\tvar _p$n $strconvtype\n"; + $textcommon .= "\t_p$n, $errvar = $strconvfunc($name)\n"; + $textcommon .= "\tif $errvar != nil {\n\t\treturn\n\t}\n"; + + push @argscommun, "uintptr(unsafe.Pointer(_p$n))"; + push @argscall, "_p$n uintptr"; + push @argsgc, "_p$n"; + push @argsgccgo, "C.uintptr_t(_p$n)"; + $n++; + } elsif($type =~ /^\[\](.*)/) { + # Convert slice into pointer, length. + # Have to be careful not to take address of &a[0] if len == 0: + # pass nil in that case. + $textcommon .= "\tvar _p$n *$1\n"; + $textcommon .= "\tif len($name) > 0 {\n\t\t_p$n = \&$name\[0]\n\t}\n"; + push @argscommun, "uintptr(unsafe.Pointer(_p$n))", "len($name)"; + push @argscall, "_p$n uintptr", "_lenp$n int"; + push @argsgc, "_p$n", "uintptr(_lenp$n)"; + push @argsgccgo, "C.uintptr_t(_p$n)", "C.size_t(_lenp$n)"; + $n++; + } elsif($type eq "int64" && $_32bit ne "") { + print STDERR "$ARGV:$.: $func uses int64 with 32 bits mode. Case not yet implemented\n"; + # if($_32bit eq "big-endian") { + # push @args, "uintptr($name >> 32)", "uintptr($name)"; + # } else { + # push @args, "uintptr($name)", "uintptr($name >> 32)"; + # } + # $n++; + } elsif($type eq "bool") { + print STDERR "$ARGV:$.: $func uses bool. Case not yet implemented\n"; + # $text .= "\tvar _p$n uint32\n"; + # $text .= "\tif $name {\n\t\t_p$n = 1\n\t} else {\n\t\t_p$n = 0\n\t}\n"; + # push @args, "_p$n"; + # $n++; + } elsif($type =~ /^_/ ||$type eq "unsafe.Pointer") { + push @argscommun, "uintptr($name)"; + push @argscall, "$name uintptr"; + push @argsgc, "$name"; + push @argsgccgo, "C.uintptr_t($name)"; + } elsif($type eq "int") { + if (($arg_n == 0 || $arg_n == 2) && ($func eq "fcntl" || $func eq "FcntlInt" || $func eq "FcntlFlock")) { + # These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock + push @argscommun, "uintptr($name)"; + push @argscall, "$name uintptr"; + push @argsgc, "$name"; + push @argsgccgo, "C.uintptr_t($name)"; + } else { + push @argscommun, "$name"; + push @argscall, "$name int"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.int($name)"; + } + } elsif($type eq "int32") { + push @argscommun, "$name"; + push @argscall, "$name int32"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.int($name)"; + } elsif($type eq "int64") { + push @argscommun, "$name"; + push @argscall, "$name int64"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.longlong($name)"; + } elsif($type eq "uint32") { + push @argscommun, "$name"; + push @argscall, "$name uint32"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.uint($name)"; + } elsif($type eq "uint64") { + push @argscommun, "$name"; + push @argscall, "$name uint64"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.ulonglong($name)"; + } elsif($type eq "uintptr") { + push @argscommun, "$name"; + push @argscall, "$name uintptr"; + push @argsgc, "$name"; + push @argsgccgo, "C.uintptr_t($name)"; + } else { + push @argscommun, "int($name)"; + push @argscall, "$name int"; + push @argsgc, "uintptr($name)"; + push @argsgccgo, "C.int($name)"; + } + $arg_n++; + } + my $nargs = @argsgc; + + # COMMUN function generation + my $argscommun = join(', ', @argscommun); + my $callcommun = "call$sysname($argscommun)"; + my @ret = ("_", "_"); + my $body = ""; + my $do_errno = 0; + for(my $i=0; $i<@out; $i++) { + my $p = $out[$i]; + my ($name, $type) = parseparam($p); + my $reg = ""; + if($name eq "err") { + $reg = "e1"; + $ret[1] = $reg; + $do_errno = 1; + } else { + $reg = "r0"; + $ret[0] = $reg; + } + if($type eq "bool") { + $reg = "$reg != 0"; + } + if($reg ne "e1") { + $body .= "\t$name = $type($reg)\n"; + } + } + if ($ret[0] eq "_" && $ret[1] eq "_") { + $textcommon .= "\t$callcommun\n"; + } else { + $textcommon .= "\t$ret[0], $ret[1] := $callcommun\n"; + } + $textcommon .= $body; + + if ($do_errno) { + $textcommon .= "\tif e1 != 0 {\n"; + $textcommon .= "\t\terr = errnoErr(e1)\n"; + $textcommon .= "\t}\n"; + } + $textcommon .= "\treturn\n"; + $textcommon .= "}\n"; + + if ($onlyCommon){ + next + } + # CALL Prototype + my $callProto = sprintf "func call%s(%s) (r1 uintptr, e1 Errno) {\n", $sysname, join(', ', @argscall); + + # GC function generation + my $asm = "syscall6"; + if ($nonblock) { + $asm = "rawSyscall6"; + } + + if(@argsgc <= 6) { + while(@argsgc < 6) { + push @argsgc, "0"; + } + } else { + print STDERR "$ARGV:$.: too many arguments to system call\n"; + } + my $argsgc = join(', ', @argsgc); + my $callgc = "$asm(uintptr(unsafe.Pointer(&$sysvarname)), $nargs, $argsgc)"; + + $textgc .= $callProto; + $textgc .= "\tr1, _, e1 = $callgc\n"; + $textgc .= "\treturn\n}\n"; + + # GCCGO function generation + my $argsgccgo = join(', ', @argsgccgo); + my $callgccgo = "C.$sysname($argsgccgo)"; + $textgccgo .= $callProto; + $textgccgo .= "\tr1 = uintptr($callgccgo)\n"; + $textgccgo .= "\te1 = syscall.GetErrno()\n"; + $textgccgo .= "\treturn\n}\n"; +} + +if($errors) { + exit 1; +} + +# Print zsyscall_aix_ppc64.go +open(my $fcommun, '>', 'zsyscall_aix_ppc64.go'); +my $tofcommun = <', 'zsyscall_aix_ppc64_gc.go'); +my $tofgc = <', 'zsyscall_aix_ppc64_gccgo.go'); +my $tofgccgo = <>8) & 0xFF + return Signal(w>>8) & 0xFF } func (w WaitStatus) Exited() bool { return w&0xFF == 0 } @@ -321,11 +321,11 @@ func (w WaitStatus) ExitStatus() int { } func (w WaitStatus) Signaled() bool { return w&0x40 == 0 && w&0xFF != 0 } -func (w WaitStatus) Signal() syscall.Signal { +func (w WaitStatus) Signal() Signal { if !w.Signaled() { return -1 } - return syscall.Signal(w>>16) & 0xFF + return Signal(w>>16) & 0xFF } func (w WaitStatus) Continued() bool { return w&0x01000000 != 0 } @@ -383,6 +383,8 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) { // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command. //sys FcntlFlock(fd uintptr, cmd int, lk *Flock_t) (err error) = fcntl +//sys fcntl(fd int, cmd int, arg int) (val int, err error) + func Flock(fd int, how int) (err error) { return syscall.Flock(fd, how) } @@ -396,15 +398,12 @@ func Flock(fd int, how int) (err error) { //sys Chroot(path string) (err error) //sys Close(fd int) (err error) //sys Dup(oldfd int) (fd int, err error) -//sys Dup3(oldfd int, newfd int, flags int) (err error) //sys Exit(code int) //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) -//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error) //sys Fchdir(fd int) (err error) //sys Fchmod(fd int, mode uint32) (err error) //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) -//sys fcntl(fd int, cmd int, arg int) (val int, err error) //sys Fdatasync(fd int) (err error) //sys Fsync(fd int) (err error) // readdir_r @@ -417,7 +416,7 @@ func Flock(fd int, how int) (err error) { //sys Getpriority(which int, who int) (prio int, err error) //sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Getsid(pid int) (sid int, err error) -//sysnb Kill(pid int, sig syscall.Signal) (err error) +//sysnb Kill(pid int, sig Signal) (err error) //sys Klogctl(typ int, buf []byte) (n int, err error) = syslog //sys Mkdir(dirfd int, path string, mode uint32) (err error) //sys Mkdirat(dirfd int, path string, mode uint32) (err error) @@ -429,7 +428,6 @@ func Flock(fd int, how int) (err error) { //sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Readlink(path string, buf []byte) (n int, err error) -//sys Removexattr(path string, attr string) (err error) //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) //sys Setdomainname(p []byte) (err error) //sys Sethostname(p []byte) (err error) @@ -443,7 +441,6 @@ func Flock(fd int, how int) (err error) { //sys Setpriority(which int, who int, prio int) (err error) //sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error) //sys Sync() -//sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error) //sysnb Times(tms *Tms) (ticks uintptr, err error) //sysnb Umask(mask int) (oldmask int) //sysnb Uname(buf *Utsname) (err error) @@ -451,7 +448,6 @@ func Flock(fd int, how int) (err error) { // //sys Unmount(target string, flags int) (err error) = umount //sys Unlink(path string) (err error) //sys Unlinkat(dirfd int, path string, flags int) (err error) -//sys Unshare(flags int) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys write(fd int, p []byte) (n int, err error) //sys readlen(fd int, p *byte, np int) (n int, err error) = read @@ -537,19 +533,6 @@ func Pipe(p []int) (err error) { return } -//sysnb pipe2(p *[2]_C_int, flags int) (err error) - -func Pipe2(p []int, flags int) (err error) { - if len(p) != 2 { - return EINVAL - } - var pp [2]_C_int - err = pipe2(&pp, flags) - p[0] = int(pp[0]) - p[1] = int(pp[1]) - return -} - //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) func Poll(fds []PollFd, timeout int) (n int, err error) { diff --git a/vendor/golang.org/x/sys/unix/syscall_freebsd.go b/vendor/golang.org/x/sys/unix/syscall_freebsd.go index 77a634c76..085a808cc 100644 --- a/vendor/golang.org/x/sys/unix/syscall_freebsd.go +++ b/vendor/golang.org/x/sys/unix/syscall_freebsd.go @@ -13,9 +13,34 @@ package unix import ( + "sync" "unsafe" ) +const ( + SYS_FSTAT_FREEBSD12 = 551 // { int fstat(int fd, _Out_ struct stat *sb); } + SYS_FSTATAT_FREEBSD12 = 552 // { int fstatat(int fd, _In_z_ char *path, \ + SYS_GETDIRENTRIES_FREEBSD12 = 554 // { ssize_t getdirentries(int fd, \ + SYS_STATFS_FREEBSD12 = 555 // { int statfs(_In_z_ char *path, \ + SYS_FSTATFS_FREEBSD12 = 556 // { int fstatfs(int fd, \ + SYS_GETFSSTAT_FREEBSD12 = 557 // { int getfsstat( \ + SYS_MKNODAT_FREEBSD12 = 559 // { int mknodat(int fd, _In_z_ char *path, \ +) + +// See https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html. +var ( + osreldateOnce sync.Once + osreldate uint32 +) + +// INO64_FIRST from /usr/src/lib/libc/sys/compat-ino64.h +const _ino64First = 1200031 + +func supportsABI(ver uint32) bool { + osreldateOnce.Do(func() { osreldate, _ = SysctlUint32("kern.osreldate") }) + return osreldate >= ver +} + // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. type SockaddrDatalink struct { Len uint8 @@ -121,17 +146,39 @@ func Getwd() (string, error) { } func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { - var _p0 unsafe.Pointer - var bufsize uintptr + var ( + _p0 unsafe.Pointer + bufsize uintptr + oldBuf []statfs_freebsd11_t + needsConvert bool + ) + if len(buf) > 0 { - _p0 = unsafe.Pointer(&buf[0]) - bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + if supportsABI(_ino64First) { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) + } else { + n := len(buf) + oldBuf = make([]statfs_freebsd11_t, n) + _p0 = unsafe.Pointer(&oldBuf[0]) + bufsize = unsafe.Sizeof(statfs_freebsd11_t{}) * uintptr(n) + needsConvert = true + } } - r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + var sysno uintptr = SYS_GETFSSTAT + if supportsABI(_ino64First) { + sysno = SYS_GETFSSTAT_FREEBSD12 + } + r0, _, e1 := Syscall(sysno, uintptr(_p0), bufsize, uintptr(flags)) n = int(r0) if e1 != 0 { err = e1 } + if e1 == 0 && needsConvert { + for i := range oldBuf { + buf[i].convertFrom(&oldBuf[i]) + } + } return } @@ -225,6 +272,234 @@ func Uname(uname *Utsname) error { return nil } +func Stat(path string, st *Stat_t) (err error) { + var oldStat stat_freebsd11_t + if supportsABI(_ino64First) { + return fstatat_freebsd12(AT_FDCWD, path, st, 0) + } + err = stat(path, &oldStat) + if err != nil { + return err + } + + st.convertFrom(&oldStat) + return nil +} + +func Lstat(path string, st *Stat_t) (err error) { + var oldStat stat_freebsd11_t + if supportsABI(_ino64First) { + return fstatat_freebsd12(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW) + } + err = lstat(path, &oldStat) + if err != nil { + return err + } + + st.convertFrom(&oldStat) + return nil +} + +func Fstat(fd int, st *Stat_t) (err error) { + var oldStat stat_freebsd11_t + if supportsABI(_ino64First) { + return fstat_freebsd12(fd, st) + } + err = fstat(fd, &oldStat) + if err != nil { + return err + } + + st.convertFrom(&oldStat) + return nil +} + +func Fstatat(fd int, path string, st *Stat_t, flags int) (err error) { + var oldStat stat_freebsd11_t + if supportsABI(_ino64First) { + return fstatat_freebsd12(fd, path, st, flags) + } + err = fstatat(fd, path, &oldStat, flags) + if err != nil { + return err + } + + st.convertFrom(&oldStat) + return nil +} + +func Statfs(path string, st *Statfs_t) (err error) { + var oldStatfs statfs_freebsd11_t + if supportsABI(_ino64First) { + return statfs_freebsd12(path, st) + } + err = statfs(path, &oldStatfs) + if err != nil { + return err + } + + st.convertFrom(&oldStatfs) + return nil +} + +func Fstatfs(fd int, st *Statfs_t) (err error) { + var oldStatfs statfs_freebsd11_t + if supportsABI(_ino64First) { + return fstatfs_freebsd12(fd, st) + } + err = fstatfs(fd, &oldStatfs) + if err != nil { + return err + } + + st.convertFrom(&oldStatfs) + return nil +} + +func Getdents(fd int, buf []byte) (n int, err error) { + return Getdirentries(fd, buf, nil) +} + +func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { + if supportsABI(_ino64First) { + return getdirentries_freebsd12(fd, buf, basep) + } + + // The old syscall entries are smaller than the new. Use 1/4 of the original + // buffer size rounded up to DIRBLKSIZ (see /usr/src/lib/libc/sys/getdirentries.c). + oldBufLen := roundup(len(buf)/4, _dirblksiz) + oldBuf := make([]byte, oldBufLen) + n, err = getdirentries(fd, oldBuf, basep) + if err == nil && n > 0 { + n = convertFromDirents11(buf, oldBuf[:n]) + } + return +} + +func Mknod(path string, mode uint32, dev uint64) (err error) { + var oldDev int + if supportsABI(_ino64First) { + return mknodat_freebsd12(AT_FDCWD, path, mode, dev) + } + oldDev = int(dev) + return mknod(path, mode, oldDev) +} + +func Mknodat(fd int, path string, mode uint32, dev uint64) (err error) { + var oldDev int + if supportsABI(_ino64First) { + return mknodat_freebsd12(fd, path, mode, dev) + } + oldDev = int(dev) + return mknodat(fd, path, mode, oldDev) +} + +// round x to the nearest multiple of y, larger or equal to x. +// +// from /usr/include/sys/param.h Macros for counting and rounding. +// #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +func roundup(x, y int) int { + return ((x + y - 1) / y) * y +} + +func (s *Stat_t) convertFrom(old *stat_freebsd11_t) { + *s = Stat_t{ + Dev: uint64(old.Dev), + Ino: uint64(old.Ino), + Nlink: uint64(old.Nlink), + Mode: old.Mode, + Uid: old.Uid, + Gid: old.Gid, + Rdev: uint64(old.Rdev), + Atim: old.Atim, + Mtim: old.Mtim, + Ctim: old.Ctim, + Birthtim: old.Birthtim, + Size: old.Size, + Blocks: old.Blocks, + Blksize: old.Blksize, + Flags: old.Flags, + Gen: uint64(old.Gen), + } +} + +func (s *Statfs_t) convertFrom(old *statfs_freebsd11_t) { + *s = Statfs_t{ + Version: _statfsVersion, + Type: old.Type, + Flags: old.Flags, + Bsize: old.Bsize, + Iosize: old.Iosize, + Blocks: old.Blocks, + Bfree: old.Bfree, + Bavail: old.Bavail, + Files: old.Files, + Ffree: old.Ffree, + Syncwrites: old.Syncwrites, + Asyncwrites: old.Asyncwrites, + Syncreads: old.Syncreads, + Asyncreads: old.Asyncreads, + // Spare + Namemax: old.Namemax, + Owner: old.Owner, + Fsid: old.Fsid, + // Charspare + // Fstypename + // Mntfromname + // Mntonname + } + + sl := old.Fstypename[:] + n := clen(*(*[]byte)(unsafe.Pointer(&sl))) + copy(s.Fstypename[:], old.Fstypename[:n]) + + sl = old.Mntfromname[:] + n = clen(*(*[]byte)(unsafe.Pointer(&sl))) + copy(s.Mntfromname[:], old.Mntfromname[:n]) + + sl = old.Mntonname[:] + n = clen(*(*[]byte)(unsafe.Pointer(&sl))) + copy(s.Mntonname[:], old.Mntonname[:n]) +} + +func convertFromDirents11(buf []byte, old []byte) int { + const ( + fixedSize = int(unsafe.Offsetof(Dirent{}.Name)) + oldFixedSize = int(unsafe.Offsetof(dirent_freebsd11{}.Name)) + ) + + dstPos := 0 + srcPos := 0 + for dstPos+fixedSize < len(buf) && srcPos+oldFixedSize < len(old) { + dstDirent := (*Dirent)(unsafe.Pointer(&buf[dstPos])) + srcDirent := (*dirent_freebsd11)(unsafe.Pointer(&old[srcPos])) + + reclen := roundup(fixedSize+int(srcDirent.Namlen)+1, 8) + if dstPos+reclen > len(buf) { + break + } + + dstDirent.Fileno = uint64(srcDirent.Fileno) + dstDirent.Off = 0 + dstDirent.Reclen = uint16(reclen) + dstDirent.Type = srcDirent.Type + dstDirent.Pad0 = 0 + dstDirent.Namlen = uint16(srcDirent.Namlen) + dstDirent.Pad1 = 0 + + copy(dstDirent.Name[:], srcDirent.Name[:srcDirent.Namlen]) + padding := buf[dstPos+fixedSize+int(dstDirent.Namlen) : dstPos+reclen] + for i := range padding { + padding[i] = 0 + } + + dstPos += int(dstDirent.Reclen) + srcPos += int(srcDirent.Reclen) + } + + return dstPos +} + /* * Exposed directly */ @@ -264,13 +539,16 @@ func Uname(uname *Utsname) error { //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) //sys Flock(fd int, how int) (err error) //sys Fpathconf(fd int, name int) (val int, err error) -//sys Fstat(fd int, stat *Stat_t) (err error) -//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) -//sys Fstatfs(fd int, stat *Statfs_t) (err error) +//sys fstat(fd int, stat *stat_freebsd11_t) (err error) +//sys fstat_freebsd12(fd int, stat *Stat_t) (err error) +//sys fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) +//sys fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) +//sys fstatfs(fd int, stat *statfs_freebsd11_t) (err error) +//sys fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) //sys Fsync(fd int) (err error) //sys Ftruncate(fd int, length int64) (err error) -//sys Getdents(fd int, buf []byte) (n int, err error) -//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) +//sys getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) +//sys getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error) //sys Getdtablesize() (size int) //sysnb Getegid() (egid int) //sysnb Geteuid() (uid int) @@ -292,11 +570,13 @@ func Uname(uname *Utsname) error { //sys Link(path string, link string) (err error) //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) //sys Listen(s int, backlog int) (err error) -//sys Lstat(path string, stat *Stat_t) (err error) +//sys lstat(path string, stat *stat_freebsd11_t) (err error) //sys Mkdir(path string, mode uint32) (err error) //sys Mkdirat(dirfd int, path string, mode uint32) (err error) //sys Mkfifo(path string, mode uint32) (err error) -//sys Mknod(path string, mode uint32, dev int) (err error) +//sys mknod(path string, mode uint32, dev int) (err error) +//sys mknodat(fd int, path string, mode uint32, dev int) (err error) +//sys mknodat_freebsd12(fd int, path string, mode uint32, dev uint64) (err error) //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys Open(path string, mode int, perm uint32) (fd int, err error) //sys Openat(fdat int, path string, mode int, perm uint32) (fd int, err error) @@ -326,8 +606,9 @@ func Uname(uname *Utsname) error { //sysnb Setsid() (pid int, err error) //sysnb Settimeofday(tp *Timeval) (err error) //sysnb Setuid(uid int) (err error) -//sys Stat(path string, stat *Stat_t) (err error) -//sys Statfs(path string, stat *Statfs_t) (err error) +//sys stat(path string, stat *stat_freebsd11_t) (err error) +//sys statfs(path string, stat *statfs_freebsd11_t) (err error) +//sys statfs_freebsd12(path string, stat *Statfs_t) (err error) //sys Symlink(path string, link string) (err error) //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) //sys Sync() (err error) @@ -382,6 +663,7 @@ func Uname(uname *Utsname) error { // Kqueue_portset // Getattrlist // Setattrlist +// Getdents // Getdirentriesattr // Searchfs // Delete diff --git a/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go b/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go index 994964a91..d62da60d1 100644 --- a/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go +++ b/vendor/golang.org/x/sys/unix/syscall_openbsd_386.go @@ -31,3 +31,7 @@ func (msghdr *Msghdr) SetControllen(length int) { func (cmsg *Cmsghdr) SetLen(length int) { cmsg.Len = uint32(length) } + +// SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions +// of openbsd/386 the syscall is called sysctl instead of __sysctl. +const SYS___SYSCTL = SYS_SYSCTL diff --git a/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go b/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go index 59844f504..5d812aaea 100644 --- a/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go +++ b/vendor/golang.org/x/sys/unix/syscall_openbsd_arm.go @@ -31,3 +31,7 @@ func (msghdr *Msghdr) SetControllen(length int) { func (cmsg *Cmsghdr) SetLen(length int) { cmsg.Len = uint32(length) } + +// SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions +// of openbsd/arm the syscall is called sysctl instead of __sysctl. +const SYS___SYSCTL = SYS_SYSCTL diff --git a/vendor/golang.org/x/sys/unix/types_freebsd.go b/vendor/golang.org/x/sys/unix/types_freebsd.go index a0a5843b9..8421ccf1c 100644 --- a/vendor/golang.org/x/sys/unix/types_freebsd.go +++ b/vendor/golang.org/x/sys/unix/types_freebsd.go @@ -14,7 +14,11 @@ Input to cgo -godefs. See README.md package unix /* -#define KERNEL +#define _WANT_FREEBSD11_STAT 1 +#define _WANT_FREEBSD11_STATFS 1 +#define _WANT_FREEBSD11_DIRENT 1 +#define _WANT_FREEBSD11_KEVENT 1 + #include #include #include @@ -63,50 +67,6 @@ struct sockaddr_any { char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; }; -// This structure is a duplicate of stat on FreeBSD 8-STABLE. -// See /usr/include/sys/stat.h. -struct stat8 { -#undef st_atimespec st_atim -#undef st_mtimespec st_mtim -#undef st_ctimespec st_ctim -#undef st_birthtimespec st_birthtim - __dev_t st_dev; - ino_t st_ino; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - __dev_t st_rdev; -#if __BSD_VISIBLE - struct timespec st_atimespec; - struct timespec st_mtimespec; - struct timespec st_ctimespec; -#else - time_t st_atime; - long __st_atimensec; - time_t st_mtime; - long __st_mtimensec; - time_t st_ctime; - long __st_ctimensec; -#endif - off_t st_size; - blkcnt_t st_blocks; - blksize_t st_blksize; - fflags_t st_flags; - __uint32_t st_gen; - __int32_t st_lspare; -#if __BSD_VISIBLE - struct timespec st_birthtimespec; - unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); - unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); -#else - time_t st_birthtime; - long st_birthtimensec; - unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); - unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); -#endif -}; - // This structure is a duplicate of if_data on FreeBSD 8-STABLE. // See /usr/include/net/if.h. struct if_data8 { @@ -189,14 +149,25 @@ type _Gid_t C.gid_t // Files -type Stat_t C.struct_stat8 +const ( + _statfsVersion = C.STATFS_VERSION + _dirblksiz = C.DIRBLKSIZ +) + +type Stat_t C.struct_stat + +type stat_freebsd11_t C.struct_freebsd11_stat type Statfs_t C.struct_statfs +type statfs_freebsd11_t C.struct_freebsd11_statfs + type Flock_t C.struct_flock type Dirent C.struct_dirent +type dirent_freebsd11 C.struct_freebsd11_dirent + type Fsid C.struct_fsid // File system limits @@ -279,7 +250,7 @@ const ( // Events (kqueue, kevent) -type Kevent_t C.struct_kevent +type Kevent_t C.struct_kevent_freebsd11 // Select diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index 86b980a5a..7d93bdf02 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -1008,7 +1008,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1584,6 +1586,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1604,6 +1607,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1618,11 +1622,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1637,8 +1642,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1687,6 +1692,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1891,6 +1897,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index 286311572..bd57833ba 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -1008,7 +1008,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1585,6 +1587,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1605,6 +1608,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1619,11 +1623,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1638,8 +1643,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1688,6 +1693,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1892,6 +1898,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index 1b58da1e7..b059c2878 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1591,6 +1593,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1611,6 +1614,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1625,11 +1629,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1644,8 +1649,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1694,6 +1699,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1898,6 +1904,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index 08377eb4f..97d5e2248 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -1009,7 +1009,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1575,6 +1577,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1595,6 +1598,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1609,11 +1613,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1628,8 +1633,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1678,6 +1683,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1882,6 +1888,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index 5de2c7aa4..059d1fc18 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1584,6 +1586,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1604,6 +1607,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1618,11 +1622,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1637,8 +1642,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1687,6 +1692,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1892,6 +1898,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x1008 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index 51015f354..355f749bc 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1584,6 +1586,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1604,6 +1607,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1618,11 +1622,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1637,8 +1642,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1687,6 +1692,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1892,6 +1898,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x1008 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index fdd388deb..5218cf5ae 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1584,6 +1586,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1604,6 +1607,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1618,11 +1622,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1637,8 +1642,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1687,6 +1692,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1892,6 +1898,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x1008 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index 2d1504612..73e35b9ed 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1584,6 +1586,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1604,6 +1607,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1618,11 +1622,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1637,8 +1642,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1687,6 +1692,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1892,6 +1898,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x1008 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index cd8fcd35c..82f44ce3e 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -1005,7 +1005,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1640,6 +1642,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1660,6 +1663,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1674,11 +1678,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1693,8 +1698,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1743,6 +1748,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1947,6 +1953,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index cdb608876..8734df99a 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -1005,7 +1005,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1640,6 +1642,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1660,6 +1663,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1674,11 +1678,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1693,8 +1698,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1743,6 +1748,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1947,6 +1953,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go index 9e9472bec..0954f4722 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1572,6 +1574,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1592,6 +1595,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1606,11 +1610,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1625,8 +1630,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1675,6 +1680,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1879,6 +1885,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index f33d031ad..61a96aba7 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -1006,7 +1006,9 @@ const ( MFD_HUGE_256MB = 0x70000000 MFD_HUGE_2GB = 0x7c000000 MFD_HUGE_2MB = 0x54000000 + MFD_HUGE_32MB = 0x64000000 MFD_HUGE_512KB = 0x4c000000 + MFD_HUGE_512MB = 0x74000000 MFD_HUGE_64KB = 0x40000000 MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f @@ -1645,6 +1647,7 @@ const ( RTM_DELACTION = 0x31 RTM_DELADDR = 0x15 RTM_DELADDRLABEL = 0x49 + RTM_DELCHAIN = 0x65 RTM_DELLINK = 0x11 RTM_DELMDB = 0x55 RTM_DELNEIGH = 0x1d @@ -1665,6 +1668,7 @@ const ( RTM_GETADDR = 0x16 RTM_GETADDRLABEL = 0x4a RTM_GETANYCAST = 0x3e + RTM_GETCHAIN = 0x66 RTM_GETDCB = 0x4e RTM_GETLINK = 0x12 RTM_GETMDB = 0x56 @@ -1679,11 +1683,12 @@ const ( RTM_GETSTATS = 0x5e RTM_GETTCLASS = 0x2a RTM_GETTFILTER = 0x2e - RTM_MAX = 0x63 + RTM_MAX = 0x67 RTM_NEWACTION = 0x30 RTM_NEWADDR = 0x14 RTM_NEWADDRLABEL = 0x48 RTM_NEWCACHEREPORT = 0x60 + RTM_NEWCHAIN = 0x64 RTM_NEWLINK = 0x10 RTM_NEWMDB = 0x54 RTM_NEWNDUSEROPT = 0x44 @@ -1698,8 +1703,8 @@ const ( RTM_NEWSTATS = 0x5c RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c - RTM_NR_FAMILIES = 0x15 - RTM_NR_MSGTYPES = 0x54 + RTM_NR_FAMILIES = 0x16 + RTM_NR_MSGTYPES = 0x58 RTM_SETDCB = 0x4f RTM_SETLINK = 0x13 RTM_SETNEIGHTBL = 0x43 @@ -1748,6 +1753,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 @@ -1952,6 +1958,7 @@ const ( SO_TIMESTAMP = 0x1d SO_TIMESTAMPING = 0x25 SO_TIMESTAMPNS = 0x23 + SO_TXTIME = 0x3d SO_TYPE = 0x3 SO_VM_SOCKETS_BUFFER_MAX_SIZE = 0x2 SO_VM_SOCKETS_BUFFER_MIN_SIZE = 0x1 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go index ab2f76122..6bae21e5d 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go @@ -1,4 +1,4 @@ -// mksyscall_aix.pl -aix -tags aix,ppc syscall_aix.go syscall_aix_ppc.go +// mksyscall_aix_ppc.pl -aix -tags aix,ppc syscall_aix.go syscall_aix_ppc.go // Code generated by the command above; see README.md. DO NOT EDIT. // +build aix,ppc @@ -7,6 +7,7 @@ package unix /* #include +#include int utimes(uintptr_t, uintptr_t); int utimensat(int, uintptr_t, uintptr_t, int); int getcwd(uintptr_t, size_t); @@ -20,10 +21,8 @@ int chdir(uintptr_t); int chroot(uintptr_t); int close(int); int dup(int); -int dup3(int, int, int); void exit(int); int faccessat(int, uintptr_t, unsigned int, int); -int fallocate(int, unsigned int, long long, long long); int fchdir(int); int fchmod(int, unsigned int); int fchmodat(int, uintptr_t, unsigned int, int); @@ -49,7 +48,6 @@ int open64(uintptr_t, int, unsigned int); int openat(int, uintptr_t, int, unsigned int); int read(int, uintptr_t, size_t); int readlink(uintptr_t, uintptr_t, size_t); -int removexattr(uintptr_t, uintptr_t); int renameat(int, uintptr_t, int, uintptr_t); int setdomainname(uintptr_t, size_t); int sethostname(uintptr_t, size_t); @@ -61,13 +59,11 @@ int setgid(int); int setpriority(int, int, int); int statx(int, uintptr_t, int, int, uintptr_t); int sync(); -long long tee(int, int, int, int); uintptr_t times(uintptr_t); int umask(int); int uname(uintptr_t); int unlink(uintptr_t); int unlinkat(int, uintptr_t, int); -int unshare(int); int ustat(int, uintptr_t); int write(int, uintptr_t, size_t); int dup2(int, int); @@ -118,7 +114,6 @@ int msync(uintptr_t, size_t, int); int munlock(uintptr_t, size_t); int munlockall(); int pipe(uintptr_t); -int pipe2(uintptr_t, int); int poll(uintptr_t, int, int); int gettimeofday(uintptr_t, uintptr_t); int time(uintptr_t); @@ -131,7 +126,6 @@ uintptr_t mmap(uintptr_t, uintptr_t, int, int, int, long long); */ import "C" import ( - "syscall" "unsafe" ) @@ -245,6 +239,17 @@ func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, er := C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(arg)) + val = int(r0) + if r0 == -1 && er != nil { + err = er + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Acct(path string) (err error) { _p0 := uintptr(unsafe.Pointer(C.CString(path))) r0, er := C.acct(C.uintptr_t(_p0)) @@ -299,16 +304,6 @@ func Dup(oldfd int) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Dup3(oldfd int, newfd int, flags int) (err error) { - r0, er := C.dup3(C.int(oldfd), C.int(newfd), C.int(flags)) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Exit(code int) { C.exit(C.int(code)) return @@ -327,16 +322,6 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fallocate(fd int, mode uint32, off int64, len int64) (err error) { - r0, er := C.fallocate(C.int(fd), C.uint(mode), C.longlong(off), C.longlong(len)) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fchdir(fd int) (err error) { r0, er := C.fchdir(C.int(fd)) if r0 == -1 && er != nil { @@ -379,17 +364,6 @@ func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func fcntl(fd int, cmd int, arg int) (val int, err error) { - r0, er := C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(arg)) - val = int(r0) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fdatasync(fd int) (err error) { r0, er := C.fdatasync(C.int(fd)) if r0 == -1 && er != nil { @@ -477,7 +451,7 @@ func Getsid(pid int) (sid int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Kill(pid int, sig syscall.Signal) (err error) { +func Kill(pid int, sig Signal) (err error) { r0, er := C.kill(C.int(pid), C.int(sig)) if r0 == -1 && er != nil { err = er @@ -628,18 +602,6 @@ func Readlink(path string, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Removexattr(path string, attr string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - _p1 := uintptr(unsafe.Pointer(C.CString(attr))) - r0, er := C.removexattr(C.uintptr_t(_p0), C.uintptr_t(_p1)) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { _p0 := uintptr(unsafe.Pointer(C.CString(oldpath))) _p1 := uintptr(unsafe.Pointer(C.CString(newpath))) @@ -763,17 +725,6 @@ func Sync() { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { - r0, er := C.tee(C.int(rfd), C.int(wfd), C.int(len), C.int(flags)) - n = int64(r0) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Times(tms *Tms) (ticks uintptr, err error) { r0, er := C.times(C.uintptr_t(uintptr(unsafe.Pointer(tms)))) ticks = uintptr(r0) @@ -825,16 +776,6 @@ func Unlinkat(dirfd int, path string, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Unshare(flags int) (err error) { - r0, er := C.unshare(C.int(flags)) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Ustat(dev int, ubuf *Ustat_t) (err error) { r0, er := C.ustat(C.int(dev), C.uintptr_t(uintptr(unsafe.Pointer(ubuf)))) if r0 == -1 && er != nil { @@ -1425,16 +1366,6 @@ func pipe(p *[2]_C_int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe2(p *[2]_C_int, flags int) (err error) { - r0, er := C.pipe2(C.uintptr_t(uintptr(unsafe.Pointer(p))), C.int(flags)) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { r0, er := C.poll(C.uintptr_t(uintptr(unsafe.Pointer(fds))), C.int(nfds), C.int(timeout)) n = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go index 2e4f93fb1..3e929e520 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go @@ -1,147 +1,25 @@ -// mksyscall_aix.pl -aix -tags aix,ppc64 syscall_aix.go syscall_aix_ppc64.go +// mksyscall_aix_ppc64.pl -aix -tags aix,ppc64 syscall_aix.go syscall_aix_ppc64.go // Code generated by the command above; see README.md. DO NOT EDIT. // +build aix,ppc64 package unix -/* -#include -int utimes(uintptr_t, uintptr_t); -int utimensat(int, uintptr_t, uintptr_t, int); -int getcwd(uintptr_t, size_t); -int accept(int, uintptr_t, uintptr_t); -int getdirent(int, uintptr_t, size_t); -int wait4(int, uintptr_t, int, uintptr_t); -int ioctl(int, int, uintptr_t); -int fcntl(uintptr_t, int, uintptr_t); -int acct(uintptr_t); -int chdir(uintptr_t); -int chroot(uintptr_t); -int close(int); -int dup(int); -int dup3(int, int, int); -void exit(int); -int faccessat(int, uintptr_t, unsigned int, int); -int fallocate(int, unsigned int, long long, long long); -int fchdir(int); -int fchmod(int, unsigned int); -int fchmodat(int, uintptr_t, unsigned int, int); -int fchownat(int, uintptr_t, int, int, int); -int fdatasync(int); -int fsync(int); -int getpgid(int); -int getpgrp(); -int getpid(); -int getppid(); -int getpriority(int, int); -int getrusage(int, uintptr_t); -int getsid(int); -int kill(int, int); -int syslog(int, uintptr_t, size_t); -int mkdir(int, uintptr_t, unsigned int); -int mkdirat(int, uintptr_t, unsigned int); -int mkfifo(uintptr_t, unsigned int); -int mknod(uintptr_t, unsigned int, int); -int mknodat(int, uintptr_t, unsigned int, int); -int nanosleep(uintptr_t, uintptr_t); -int open64(uintptr_t, int, unsigned int); -int openat(int, uintptr_t, int, unsigned int); -int read(int, uintptr_t, size_t); -int readlink(uintptr_t, uintptr_t, size_t); -int removexattr(uintptr_t, uintptr_t); -int renameat(int, uintptr_t, int, uintptr_t); -int setdomainname(uintptr_t, size_t); -int sethostname(uintptr_t, size_t); -int setpgid(int, int); -int setsid(); -int settimeofday(uintptr_t); -int setuid(int); -int setgid(int); -int setpriority(int, int, int); -int statx(int, uintptr_t, int, int, uintptr_t); -int sync(); -long long tee(int, int, int, int); -uintptr_t times(uintptr_t); -int umask(int); -int uname(uintptr_t); -int unlink(uintptr_t); -int unlinkat(int, uintptr_t, int); -int unshare(int); -int ustat(int, uintptr_t); -int write(int, uintptr_t, size_t); -int dup2(int, int); -int posix_fadvise64(int, long long, long long, int); -int fchown(int, int, int); -int fstat(int, uintptr_t); -int fstatat(int, uintptr_t, uintptr_t, int); -int fstatfs(int, uintptr_t); -int ftruncate(int, long long); -int getegid(); -int geteuid(); -int getgid(); -int getuid(); -int lchown(uintptr_t, int, int); -int listen(int, int); -int lstat(uintptr_t, uintptr_t); -int pause(); -int pread64(int, uintptr_t, size_t, long long); -int pwrite64(int, uintptr_t, size_t, long long); -int pselect(int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t); -int setregid(int, int); -int setreuid(int, int); -int shutdown(int, int); -long long splice(int, uintptr_t, int, uintptr_t, int, int); -int stat(uintptr_t, uintptr_t); -int statfs(uintptr_t, uintptr_t); -int truncate(uintptr_t, long long); -int bind(int, uintptr_t, uintptr_t); -int connect(int, uintptr_t, uintptr_t); -int getgroups(int, uintptr_t); -int setgroups(int, uintptr_t); -int getsockopt(int, int, int, uintptr_t, uintptr_t); -int setsockopt(int, int, int, uintptr_t, uintptr_t); -int socket(int, int, int); -int socketpair(int, int, int, uintptr_t); -int getpeername(int, uintptr_t, uintptr_t); -int getsockname(int, uintptr_t, uintptr_t); -int recvfrom(int, uintptr_t, size_t, int, uintptr_t, uintptr_t); -int sendto(int, uintptr_t, size_t, int, uintptr_t, uintptr_t); -int recvmsg(int, uintptr_t, int); -int sendmsg(int, uintptr_t, int); -int munmap(uintptr_t, uintptr_t); -int madvise(uintptr_t, size_t, int); -int mprotect(uintptr_t, size_t, int); -int mlock(uintptr_t, size_t); -int mlockall(int); -int msync(uintptr_t, size_t, int); -int munlock(uintptr_t, size_t); -int munlockall(); -int pipe(uintptr_t); -int pipe2(uintptr_t, int); -int poll(uintptr_t, int, int); -int gettimeofday(uintptr_t, uintptr_t); -int time(uintptr_t); -int utime(uintptr_t, uintptr_t); -int getrlimit(int, uintptr_t); -int setrlimit(int, uintptr_t); -long long lseek(int, long long, int); -uintptr_t mmap64(uintptr_t, uintptr_t, int, int, int, long long); - -*/ -import "C" import ( - "syscall" "unsafe" ) // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func utimes(path string, times *[2]Timeval) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.utimes(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(times)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callutimes(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -149,10 +27,14 @@ func utimes(path string, times *[2]Timeval) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.utimensat(C.int(dirfd), C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(times))), C.int(flag)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callutimensat(dirfd, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), flag) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -164,11 +46,9 @@ func getcwd(buf []byte) (err error) { if len(buf) > 0 { _p0 = &buf[0] } - var _p1 int - _p1 = len(buf) - r0, er := C.getcwd(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetcwd(uintptr(unsafe.Pointer(_p0)), len(buf)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -176,10 +56,10 @@ func getcwd(buf []byte) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) { - r0, er := C.accept(C.int(s), C.uintptr_t(uintptr(unsafe.Pointer(rsa))), C.uintptr_t(uintptr(unsafe.Pointer(addrlen)))) + r0, e1 := callaccept(s, uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) fd = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -191,12 +71,10 @@ func getdirent(fd int, buf []byte) (n int, err error) { if len(buf) > 0 { _p0 = &buf[0] } - var _p1 int - _p1 = len(buf) - r0, er := C.getdirent(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) + r0, e1 := callgetdirent(fd, uintptr(unsafe.Pointer(_p0)), len(buf)) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -204,10 +82,10 @@ func getdirent(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func wait4(pid Pid_t, status *_C_int, options int, rusage *Rusage) (wpid Pid_t, err error) { - r0, er := C.wait4(C.int(pid), C.uintptr_t(uintptr(unsafe.Pointer(status))), C.int(options), C.uintptr_t(uintptr(unsafe.Pointer(rusage)))) + r0, e1 := callwait4(int(pid), uintptr(unsafe.Pointer(status)), options, uintptr(unsafe.Pointer(rusage))) wpid = Pid_t(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -215,9 +93,9 @@ func wait4(pid Pid_t, status *_C_int, options int, rusage *Rusage) (wpid Pid_t, // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func ioctl(fd int, req uint, arg uintptr) (err error) { - r0, er := C.ioctl(C.int(fd), C.int(req), C.uintptr_t(arg)) - if r0 == -1 && er != nil { - err = er + _, e1 := callioctl(fd, int(req), arg) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -225,10 +103,10 @@ func ioctl(fd int, req uint, arg uintptr) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func FcntlInt(fd uintptr, cmd int, arg int) (r int, err error) { - r0, er := C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(arg)) + r0, e1 := callfcntl(fd, cmd, uintptr(arg)) r = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -236,73 +114,86 @@ func FcntlInt(fd uintptr, cmd int, arg int) (r int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) (err error) { - r0, er := C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(uintptr(unsafe.Pointer(lk)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callfcntl(fd, cmd, uintptr(unsafe.Pointer(lk))) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Acct(path string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.acct(C.uintptr_t(_p0)) - if r0 == -1 && er != nil { - err = er +func fcntl(fd int, cmd int, arg int) (val int, err error) { + r0, e1 := callfcntl(uintptr(fd), cmd, uintptr(arg)) + val = int(r0) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Chdir(path string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.chdir(C.uintptr_t(_p0)) - if r0 == -1 && er != nil { - err = er +func Acct(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callacct(uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Chroot(path string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.chroot(C.uintptr_t(_p0)) - if r0 == -1 && er != nil { - err = er +func Chdir(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callchdir(uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Close(fd int) (err error) { - r0, er := C.close(C.int(fd)) - if r0 == -1 && er != nil { - err = er +func Chroot(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callchroot(uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Dup(oldfd int) (fd int, err error) { - r0, er := C.dup(C.int(oldfd)) - fd = int(r0) - if r0 == -1 && er != nil { - err = er +func Close(fd int) (err error) { + _, e1 := callclose(fd) + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Dup3(oldfd int, newfd int, flags int) (err error) { - r0, er := C.dup3(C.int(oldfd), C.int(newfd), C.int(flags)) - if r0 == -1 && er != nil { - err = er +func Dup(oldfd int) (fd int, err error) { + r0, e1 := calldup(oldfd) + fd = int(r0) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -310,27 +201,21 @@ func Dup3(oldfd int, newfd int, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Exit(code int) { - C.exit(C.int(code)) + callexit(code) return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.faccessat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(flags)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Fallocate(fd int, mode uint32, off int64, len int64) (err error) { - r0, er := C.fallocate(C.int(fd), C.uint(mode), C.longlong(off), C.longlong(len)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfaccessat(dirfd, uintptr(unsafe.Pointer(_p0)), mode, flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -338,9 +223,9 @@ func Fallocate(fd int, mode uint32, off int64, len int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fchdir(fd int) (err error) { - r0, er := C.fchdir(C.int(fd)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfchdir(fd) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -348,9 +233,9 @@ func Fchdir(fd int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fchmod(fd int, mode uint32) (err error) { - r0, er := C.fchmod(C.int(fd), C.uint(mode)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfchmod(fd, mode) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -358,10 +243,14 @@ func Fchmod(fd int, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.fchmodat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(flags)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callfchmodat(dirfd, uintptr(unsafe.Pointer(_p0)), mode, flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -369,21 +258,14 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.fchownat(C.int(dirfd), C.uintptr_t(_p0), C.int(uid), C.int(gid), C.int(flags)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func fcntl(fd int, cmd int, arg int) (val int, err error) { - r0, er := C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(arg)) - val = int(r0) - if r0 == -1 && er != nil { - err = er + _, e1 := callfchownat(dirfd, uintptr(unsafe.Pointer(_p0)), uid, gid, flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -391,9 +273,9 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fdatasync(fd int) (err error) { - r0, er := C.fdatasync(C.int(fd)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfdatasync(fd) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -401,9 +283,9 @@ func Fdatasync(fd int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fsync(fd int) (err error) { - r0, er := C.fsync(C.int(fd)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfsync(fd) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -411,10 +293,10 @@ func Fsync(fd int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getpgid(pid int) (pgid int, err error) { - r0, er := C.getpgid(C.int(pid)) + r0, e1 := callgetpgid(pid) pgid = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -422,7 +304,7 @@ func Getpgid(pid int) (pgid int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getpgrp() (pid int) { - r0, _ := C.getpgrp() + r0, _ := callgetpgrp() pid = int(r0) return } @@ -430,7 +312,7 @@ func Getpgrp() (pid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getpid() (pid int) { - r0, _ := C.getpid() + r0, _ := callgetpid() pid = int(r0) return } @@ -438,7 +320,7 @@ func Getpid() (pid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getppid() (ppid int) { - r0, _ := C.getppid() + r0, _ := callgetppid() ppid = int(r0) return } @@ -446,10 +328,10 @@ func Getppid() (ppid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getpriority(which int, who int) (prio int, err error) { - r0, er := C.getpriority(C.int(which), C.int(who)) + r0, e1 := callgetpriority(which, who) prio = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -457,9 +339,9 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getrusage(who int, rusage *Rusage) (err error) { - r0, er := C.getrusage(C.int(who), C.uintptr_t(uintptr(unsafe.Pointer(rusage)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetrusage(who, uintptr(unsafe.Pointer(rusage))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -467,20 +349,20 @@ func Getrusage(who int, rusage *Rusage) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getsid(pid int) (sid int, err error) { - r0, er := C.getsid(C.int(pid)) + r0, e1 := callgetsid(pid) sid = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Kill(pid int, sig syscall.Signal) (err error) { - r0, er := C.kill(C.int(pid), C.int(sig)) - if r0 == -1 && er != nil { - err = er +func Kill(pid int, sig Signal) (err error) { + _, e1 := callkill(pid, int(sig)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -492,12 +374,10 @@ func Klogctl(typ int, buf []byte) (n int, err error) { if len(buf) > 0 { _p0 = &buf[0] } - var _p1 int - _p1 = len(buf) - r0, er := C.syslog(C.int(typ), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) + r0, e1 := callsyslog(typ, uintptr(unsafe.Pointer(_p0)), len(buf)) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -505,10 +385,14 @@ func Klogctl(typ int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mkdir(dirfd int, path string, mode uint32) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.mkdir(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callmkdir(dirfd, uintptr(unsafe.Pointer(_p0)), mode) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -516,10 +400,14 @@ func Mkdir(dirfd int, path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mkdirat(dirfd int, path string, mode uint32) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.mkdirat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callmkdirat(dirfd, uintptr(unsafe.Pointer(_p0)), mode) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -527,10 +415,14 @@ func Mkdirat(dirfd int, path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mkfifo(path string, mode uint32) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.mkfifo(C.uintptr_t(_p0), C.uint(mode)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callmkfifo(uintptr(unsafe.Pointer(_p0)), mode) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -538,10 +430,14 @@ func Mkfifo(path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mknod(path string, mode uint32, dev int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.mknod(C.uintptr_t(_p0), C.uint(mode), C.int(dev)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callmknod(uintptr(unsafe.Pointer(_p0)), mode, dev) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -549,10 +445,14 @@ func Mknod(path string, mode uint32, dev int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.mknodat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(dev)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callmknodat(dirfd, uintptr(unsafe.Pointer(_p0)), mode, dev) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -560,9 +460,9 @@ func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Nanosleep(time *Timespec, leftover *Timespec) (err error) { - r0, er := C.nanosleep(C.uintptr_t(uintptr(unsafe.Pointer(time))), C.uintptr_t(uintptr(unsafe.Pointer(leftover)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callnanosleep(uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -570,11 +470,15 @@ func Nanosleep(time *Timespec, leftover *Timespec) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Open(path string, mode int, perm uint32) (fd int, err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.open64(C.uintptr_t(_p0), C.int(mode), C.uint(perm)) + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, e1 := callopen64(uintptr(unsafe.Pointer(_p0)), mode, perm) fd = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -582,11 +486,15 @@ func Open(path string, mode int, perm uint32) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.openat(C.int(dirfd), C.uintptr_t(_p0), C.int(flags), C.uint(mode)) + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + r0, e1 := callopenat(dirfd, uintptr(unsafe.Pointer(_p0)), flags, mode) fd = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -598,12 +506,10 @@ func read(fd int, p []byte) (n int, err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.read(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) + r0, e1 := callread(fd, uintptr(unsafe.Pointer(_p0)), len(p)) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -611,29 +517,19 @@ func read(fd int, p []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Readlink(path string, buf []byte) (n int, err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } var _p1 *byte if len(buf) > 0 { _p1 = &buf[0] } - var _p2 int - _p2 = len(buf) - r0, er := C.readlink(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(_p1))), C.size_t(_p2)) + r0, e1 := callreadlink(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), len(buf)) n = int(r0) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Removexattr(path string, attr string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - _p1 := uintptr(unsafe.Pointer(C.CString(attr))) - r0, er := C.removexattr(C.uintptr_t(_p0), C.uintptr_t(_p1)) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -641,11 +537,19 @@ func Removexattr(path string, attr string) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(oldpath))) - _p1 := uintptr(unsafe.Pointer(C.CString(newpath))) - r0, er := C.renameat(C.int(olddirfd), C.uintptr_t(_p0), C.int(newdirfd), C.uintptr_t(_p1)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(oldpath) + if err != nil { + return + } + var _p1 *byte + _p1, err = BytePtrFromString(newpath) + if err != nil { + return + } + _, e1 := callrenameat(olddirfd, uintptr(unsafe.Pointer(_p0)), newdirfd, uintptr(unsafe.Pointer(_p1))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -657,11 +561,9 @@ func Setdomainname(p []byte) (err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.setdomainname(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetdomainname(uintptr(unsafe.Pointer(_p0)), len(p)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -673,11 +575,9 @@ func Sethostname(p []byte) (err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.sethostname(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsethostname(uintptr(unsafe.Pointer(_p0)), len(p)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -685,9 +585,9 @@ func Sethostname(p []byte) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setpgid(pid int, pgid int) (err error) { - r0, er := C.setpgid(C.int(pid), C.int(pgid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetpgid(pid, pgid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -695,10 +595,10 @@ func Setpgid(pid int, pgid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setsid() (pid int, err error) { - r0, er := C.setsid() + r0, e1 := callsetsid() pid = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -706,9 +606,9 @@ func Setsid() (pid int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Settimeofday(tv *Timeval) (err error) { - r0, er := C.settimeofday(C.uintptr_t(uintptr(unsafe.Pointer(tv)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callsettimeofday(uintptr(unsafe.Pointer(tv))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -716,9 +616,9 @@ func Settimeofday(tv *Timeval) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setuid(uid int) (err error) { - r0, er := C.setuid(C.int(uid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetuid(uid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -726,9 +626,9 @@ func Setuid(uid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setgid(uid int) (err error) { - r0, er := C.setgid(C.int(uid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetgid(uid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -736,9 +636,9 @@ func Setgid(uid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setpriority(which int, who int, prio int) (err error) { - r0, er := C.setpriority(C.int(which), C.int(who), C.int(prio)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetpriority(which, who, prio) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -746,10 +646,14 @@ func Setpriority(which int, who int, prio int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.statx(C.int(dirfd), C.uintptr_t(_p0), C.int(flags), C.int(mask), C.uintptr_t(uintptr(unsafe.Pointer(stat)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callstatx(dirfd, uintptr(unsafe.Pointer(_p0)), flags, mask, uintptr(unsafe.Pointer(stat))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -757,28 +661,17 @@ func Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err erro // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Sync() { - C.sync() - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { - r0, er := C.tee(C.int(rfd), C.int(wfd), C.int(len), C.int(flags)) - n = int64(r0) - if r0 == -1 && er != nil { - err = er - } + callsync() return } // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Times(tms *Tms) (ticks uintptr, err error) { - r0, er := C.times(C.uintptr_t(uintptr(unsafe.Pointer(tms)))) + r0, e1 := calltimes(uintptr(unsafe.Pointer(tms))) ticks = uintptr(r0) - if uintptr(r0) == ^uintptr(0) && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -786,7 +679,7 @@ func Times(tms *Tms) (ticks uintptr, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Umask(mask int) (oldmask int) { - r0, _ := C.umask(C.int(mask)) + r0, _ := callumask(mask) oldmask = int(r0) return } @@ -794,9 +687,9 @@ func Umask(mask int) (oldmask int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Uname(buf *Utsname) (err error) { - r0, er := C.uname(C.uintptr_t(uintptr(unsafe.Pointer(buf)))) - if r0 == -1 && er != nil { - err = er + _, e1 := calluname(uintptr(unsafe.Pointer(buf))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -804,10 +697,14 @@ func Uname(buf *Utsname) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Unlink(path string) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.unlink(C.uintptr_t(_p0)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callunlink(uintptr(unsafe.Pointer(_p0))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -815,20 +712,14 @@ func Unlink(path string) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Unlinkat(dirfd int, path string, flags int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.unlinkat(C.int(dirfd), C.uintptr_t(_p0), C.int(flags)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Unshare(flags int) (err error) { - r0, er := C.unshare(C.int(flags)) - if r0 == -1 && er != nil { - err = er + _, e1 := callunlinkat(dirfd, uintptr(unsafe.Pointer(_p0)), flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -836,9 +727,9 @@ func Unshare(flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Ustat(dev int, ubuf *Ustat_t) (err error) { - r0, er := C.ustat(C.int(dev), C.uintptr_t(uintptr(unsafe.Pointer(ubuf)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callustat(dev, uintptr(unsafe.Pointer(ubuf))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -850,12 +741,10 @@ func write(fd int, p []byte) (n int, err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.write(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) + r0, e1 := callwrite(fd, uintptr(unsafe.Pointer(_p0)), len(p)) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -863,10 +752,10 @@ func write(fd int, p []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func readlen(fd int, p *byte, np int) (n int, err error) { - r0, er := C.read(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(p))), C.size_t(np)) + r0, e1 := callread(fd, uintptr(unsafe.Pointer(p)), np) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -874,10 +763,10 @@ func readlen(fd int, p *byte, np int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func writelen(fd int, p *byte, np int) (n int, err error) { - r0, er := C.write(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(p))), C.size_t(np)) + r0, e1 := callwrite(fd, uintptr(unsafe.Pointer(p)), np) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -885,9 +774,9 @@ func writelen(fd int, p *byte, np int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Dup2(oldfd int, newfd int) (err error) { - r0, er := C.dup2(C.int(oldfd), C.int(newfd)) - if r0 == -1 && er != nil { - err = er + _, e1 := calldup2(oldfd, newfd) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -895,9 +784,9 @@ func Dup2(oldfd int, newfd int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fadvise(fd int, offset int64, length int64, advice int) (err error) { - r0, er := C.posix_fadvise64(C.int(fd), C.longlong(offset), C.longlong(length), C.int(advice)) - if r0 == -1 && er != nil { - err = er + _, e1 := callposix_fadvise64(fd, offset, length, advice) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -905,9 +794,9 @@ func Fadvise(fd int, offset int64, length int64, advice int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fchown(fd int, uid int, gid int) (err error) { - r0, er := C.fchown(C.int(fd), C.int(uid), C.int(gid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callfchown(fd, uid, gid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -915,9 +804,9 @@ func Fchown(fd int, uid int, gid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fstat(fd int, stat *Stat_t) (err error) { - r0, er := C.fstat(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(stat)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callfstat(fd, uintptr(unsafe.Pointer(stat))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -925,10 +814,14 @@ func Fstat(fd int, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.fstatat(C.int(dirfd), C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(stat))), C.int(flags)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callfstatat(dirfd, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -936,9 +829,9 @@ func Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Fstatfs(fd int, buf *Statfs_t) (err error) { - r0, er := C.fstatfs(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(buf)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callfstatfs(fd, uintptr(unsafe.Pointer(buf))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -946,9 +839,9 @@ func Fstatfs(fd int, buf *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Ftruncate(fd int, length int64) (err error) { - r0, er := C.ftruncate(C.int(fd), C.longlong(length)) - if r0 == -1 && er != nil { - err = er + _, e1 := callftruncate(fd, length) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -956,7 +849,7 @@ func Ftruncate(fd int, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getegid() (egid int) { - r0, _ := C.getegid() + r0, _ := callgetegid() egid = int(r0) return } @@ -964,7 +857,7 @@ func Getegid() (egid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Geteuid() (euid int) { - r0, _ := C.geteuid() + r0, _ := callgeteuid() euid = int(r0) return } @@ -972,7 +865,7 @@ func Geteuid() (euid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getgid() (gid int) { - r0, _ := C.getgid() + r0, _ := callgetgid() gid = int(r0) return } @@ -980,7 +873,7 @@ func Getgid() (gid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getuid() (uid int) { - r0, _ := C.getuid() + r0, _ := callgetuid() uid = int(r0) return } @@ -988,10 +881,14 @@ func Getuid() (uid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Lchown(path string, uid int, gid int) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.lchown(C.uintptr_t(_p0), C.int(uid), C.int(gid)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := calllchown(uintptr(unsafe.Pointer(_p0)), uid, gid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -999,9 +896,9 @@ func Lchown(path string, uid int, gid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Listen(s int, n int) (err error) { - r0, er := C.listen(C.int(s), C.int(n)) - if r0 == -1 && er != nil { - err = er + _, e1 := calllisten(s, n) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1009,10 +906,14 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Lstat(path string, stat *Stat_t) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.lstat(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(stat)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := calllstat(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1020,9 +921,9 @@ func Lstat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Pause() (err error) { - r0, er := C.pause() - if r0 == -1 && er != nil { - err = er + _, e1 := callpause() + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1034,12 +935,10 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.pread64(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.longlong(offset)) + r0, e1 := callpread64(fd, uintptr(unsafe.Pointer(_p0)), len(p), offset) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1051,12 +950,10 @@ func Pwrite(fd int, p []byte, offset int64) (n int, err error) { if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.pwrite64(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.longlong(offset)) + r0, e1 := callpwrite64(fd, uintptr(unsafe.Pointer(_p0)), len(p), offset) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1064,10 +961,10 @@ func Pwrite(fd int, p []byte, offset int64) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { - r0, er := C.pselect(C.int(nfd), C.uintptr_t(uintptr(unsafe.Pointer(r))), C.uintptr_t(uintptr(unsafe.Pointer(w))), C.uintptr_t(uintptr(unsafe.Pointer(e))), C.uintptr_t(uintptr(unsafe.Pointer(timeout))), C.uintptr_t(uintptr(unsafe.Pointer(sigmask)))) + r0, e1 := callpselect(nfd, uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask))) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1075,9 +972,9 @@ func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask * // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setregid(rgid int, egid int) (err error) { - r0, er := C.setregid(C.int(rgid), C.int(egid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetregid(rgid, egid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1085,9 +982,9 @@ func Setregid(rgid int, egid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setreuid(ruid int, euid int) (err error) { - r0, er := C.setreuid(C.int(ruid), C.int(euid)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetreuid(ruid, euid) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1095,9 +992,9 @@ func Setreuid(ruid int, euid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Shutdown(fd int, how int) (err error) { - r0, er := C.shutdown(C.int(fd), C.int(how)) - if r0 == -1 && er != nil { - err = er + _, e1 := callshutdown(fd, how) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1105,10 +1002,10 @@ func Shutdown(fd int, how int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) { - r0, er := C.splice(C.int(rfd), C.uintptr_t(uintptr(unsafe.Pointer(roff))), C.int(wfd), C.uintptr_t(uintptr(unsafe.Pointer(woff))), C.int(len), C.int(flags)) + r0, e1 := callsplice(rfd, uintptr(unsafe.Pointer(roff)), wfd, uintptr(unsafe.Pointer(woff)), len, flags) n = int64(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1116,10 +1013,14 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Stat(path string, stat *Stat_t) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.stat(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(stat)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callstat(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1127,10 +1028,14 @@ func Stat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Statfs(path string, buf *Statfs_t) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.statfs(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(buf)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callstatfs(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1138,10 +1043,14 @@ func Statfs(path string, buf *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Truncate(path string, length int64) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.truncate(C.uintptr_t(_p0), C.longlong(length)) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := calltruncate(uintptr(unsafe.Pointer(_p0)), length) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1149,9 +1058,9 @@ func Truncate(path string, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { - r0, er := C.bind(C.int(s), C.uintptr_t(uintptr(addr)), C.uintptr_t(uintptr(addrlen))) - if r0 == -1 && er != nil { - err = er + _, e1 := callbind(s, uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1159,9 +1068,9 @@ func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { - r0, er := C.connect(C.int(s), C.uintptr_t(uintptr(addr)), C.uintptr_t(uintptr(addrlen))) - if r0 == -1 && er != nil { - err = er + _, e1 := callconnect(s, uintptr(addr), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1169,10 +1078,10 @@ func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func getgroups(n int, list *_Gid_t) (nn int, err error) { - r0, er := C.getgroups(C.int(n), C.uintptr_t(uintptr(unsafe.Pointer(list)))) + r0, e1 := callgetgroups(n, uintptr(unsafe.Pointer(list))) nn = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1180,9 +1089,9 @@ func getgroups(n int, list *_Gid_t) (nn int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func setgroups(n int, list *_Gid_t) (err error) { - r0, er := C.setgroups(C.int(n), C.uintptr_t(uintptr(unsafe.Pointer(list)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetgroups(n, uintptr(unsafe.Pointer(list))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1190,9 +1099,9 @@ func setgroups(n int, list *_Gid_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) { - r0, er := C.getsockopt(C.int(s), C.int(level), C.int(name), C.uintptr_t(uintptr(val)), C.uintptr_t(uintptr(unsafe.Pointer(vallen)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetsockopt(s, level, name, uintptr(val), uintptr(unsafe.Pointer(vallen))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1200,9 +1109,9 @@ func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) { - r0, er := C.setsockopt(C.int(s), C.int(level), C.int(name), C.uintptr_t(uintptr(val)), C.uintptr_t(vallen)) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetsockopt(s, level, name, uintptr(val), vallen) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1210,10 +1119,10 @@ func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func socket(domain int, typ int, proto int) (fd int, err error) { - r0, er := C.socket(C.int(domain), C.int(typ), C.int(proto)) + r0, e1 := callsocket(domain, typ, proto) fd = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1221,9 +1130,9 @@ func socket(domain int, typ int, proto int) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { - r0, er := C.socketpair(C.int(domain), C.int(typ), C.int(proto), C.uintptr_t(uintptr(unsafe.Pointer(fd)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callsocketpair(domain, typ, proto, uintptr(unsafe.Pointer(fd))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1231,9 +1140,9 @@ func socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { - r0, er := C.getpeername(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(rsa))), C.uintptr_t(uintptr(unsafe.Pointer(addrlen)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetpeername(fd, uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1241,9 +1150,9 @@ func getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) { - r0, er := C.getsockname(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(rsa))), C.uintptr_t(uintptr(unsafe.Pointer(addrlen)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetsockname(fd, uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1255,12 +1164,10 @@ func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Sockl if len(p) > 0 { _p0 = &p[0] } - var _p1 int - _p1 = len(p) - r0, er := C.recvfrom(C.int(fd), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.int(flags), C.uintptr_t(uintptr(unsafe.Pointer(from))), C.uintptr_t(uintptr(unsafe.Pointer(fromlen)))) + r0, e1 := callrecvfrom(fd, uintptr(unsafe.Pointer(_p0)), len(p), flags, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1272,11 +1179,9 @@ func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) ( if len(buf) > 0 { _p0 = &buf[0] } - var _p1 int - _p1 = len(buf) - r0, er := C.sendto(C.int(s), C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.int(flags), C.uintptr_t(uintptr(to)), C.uintptr_t(uintptr(addrlen))) - if r0 == -1 && er != nil { - err = er + _, e1 := callsendto(s, uintptr(unsafe.Pointer(_p0)), len(buf), flags, uintptr(to), uintptr(addrlen)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1284,10 +1189,10 @@ func sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) ( // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { - r0, er := C.recvmsg(C.int(s), C.uintptr_t(uintptr(unsafe.Pointer(msg))), C.int(flags)) + r0, e1 := callrecvmsg(s, uintptr(unsafe.Pointer(msg)), flags) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1295,10 +1200,10 @@ func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { - r0, er := C.sendmsg(C.int(s), C.uintptr_t(uintptr(unsafe.Pointer(msg))), C.int(flags)) + r0, e1 := callsendmsg(s, uintptr(unsafe.Pointer(msg)), flags) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1306,9 +1211,9 @@ func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func munmap(addr uintptr, length uintptr) (err error) { - r0, er := C.munmap(C.uintptr_t(addr), C.uintptr_t(length)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmunmap(addr, length) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1320,11 +1225,9 @@ func Madvise(b []byte, advice int) (err error) { if len(b) > 0 { _p0 = &b[0] } - var _p1 int - _p1 = len(b) - r0, er := C.madvise(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.int(advice)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmadvise(uintptr(unsafe.Pointer(_p0)), len(b), advice) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1336,11 +1239,9 @@ func Mprotect(b []byte, prot int) (err error) { if len(b) > 0 { _p0 = &b[0] } - var _p1 int - _p1 = len(b) - r0, er := C.mprotect(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.int(prot)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmprotect(uintptr(unsafe.Pointer(_p0)), len(b), prot) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1352,11 +1253,9 @@ func Mlock(b []byte) (err error) { if len(b) > 0 { _p0 = &b[0] } - var _p1 int - _p1 = len(b) - r0, er := C.mlock(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmlock(uintptr(unsafe.Pointer(_p0)), len(b)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1364,9 +1263,9 @@ func Mlock(b []byte) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Mlockall(flags int) (err error) { - r0, er := C.mlockall(C.int(flags)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmlockall(flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1378,11 +1277,9 @@ func Msync(b []byte, flags int) (err error) { if len(b) > 0 { _p0 = &b[0] } - var _p1 int - _p1 = len(b) - r0, er := C.msync(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1), C.int(flags)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmsync(uintptr(unsafe.Pointer(_p0)), len(b), flags) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1394,11 +1291,9 @@ func Munlock(b []byte) (err error) { if len(b) > 0 { _p0 = &b[0] } - var _p1 int - _p1 = len(b) - r0, er := C.munlock(C.uintptr_t(uintptr(unsafe.Pointer(_p0))), C.size_t(_p1)) - if r0 == -1 && er != nil { - err = er + _, e1 := callmunlock(uintptr(unsafe.Pointer(_p0)), len(b)) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1406,9 +1301,9 @@ func Munlock(b []byte) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Munlockall() (err error) { - r0, er := C.munlockall() - if r0 == -1 && er != nil { - err = er + _, e1 := callmunlockall() + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1416,19 +1311,9 @@ func Munlockall() (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func pipe(p *[2]_C_int) (err error) { - r0, er := C.pipe(C.uintptr_t(uintptr(unsafe.Pointer(p)))) - if r0 == -1 && er != nil { - err = er - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func pipe2(p *[2]_C_int, flags int) (err error) { - r0, er := C.pipe2(C.uintptr_t(uintptr(unsafe.Pointer(p))), C.int(flags)) - if r0 == -1 && er != nil { - err = er + _, e1 := callpipe(uintptr(unsafe.Pointer(p))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1436,10 +1321,10 @@ func pipe2(p *[2]_C_int, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { - r0, er := C.poll(C.uintptr_t(uintptr(unsafe.Pointer(fds))), C.int(nfds), C.int(timeout)) + r0, e1 := callpoll(uintptr(unsafe.Pointer(fds)), nfds, timeout) n = int(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1447,9 +1332,9 @@ func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func gettimeofday(tv *Timeval, tzp *Timezone) (err error) { - r0, er := C.gettimeofday(C.uintptr_t(uintptr(unsafe.Pointer(tv))), C.uintptr_t(uintptr(unsafe.Pointer(tzp)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgettimeofday(uintptr(unsafe.Pointer(tv)), uintptr(unsafe.Pointer(tzp))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1457,10 +1342,10 @@ func gettimeofday(tv *Timeval, tzp *Timezone) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Time(t *Time_t) (tt Time_t, err error) { - r0, er := C.time(C.uintptr_t(uintptr(unsafe.Pointer(t)))) + r0, e1 := calltime(uintptr(unsafe.Pointer(t))) tt = Time_t(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1468,10 +1353,14 @@ func Time(t *Time_t) (tt Time_t, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Utime(path string, buf *Utimbuf) (err error) { - _p0 := uintptr(unsafe.Pointer(C.CString(path))) - r0, er := C.utime(C.uintptr_t(_p0), C.uintptr_t(uintptr(unsafe.Pointer(buf)))) - if r0 == -1 && er != nil { - err = er + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, e1 := callutime(uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1479,9 +1368,9 @@ func Utime(path string, buf *Utimbuf) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Getrlimit(resource int, rlim *Rlimit) (err error) { - r0, er := C.getrlimit(C.int(resource), C.uintptr_t(uintptr(unsafe.Pointer(rlim)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callgetrlimit(resource, uintptr(unsafe.Pointer(rlim))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1489,9 +1378,9 @@ func Getrlimit(resource int, rlim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Setrlimit(resource int, rlim *Rlimit) (err error) { - r0, er := C.setrlimit(C.int(resource), C.uintptr_t(uintptr(unsafe.Pointer(rlim)))) - if r0 == -1 && er != nil { - err = er + _, e1 := callsetrlimit(resource, uintptr(unsafe.Pointer(rlim))) + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1499,10 +1388,10 @@ func Setrlimit(resource int, rlim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Seek(fd int, offset int64, whence int) (off int64, err error) { - r0, er := C.lseek(C.int(fd), C.longlong(offset), C.int(whence)) + r0, e1 := calllseek(fd, offset, whence) off = int64(r0) - if r0 == -1 && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } @@ -1510,10 +1399,10 @@ func Seek(fd int, offset int64, whence int) (off int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { - r0, er := C.mmap64(C.uintptr_t(addr), C.uintptr_t(length), C.int(prot), C.int(flags), C.int(fd), C.longlong(offset)) + r0, e1 := callmmap64(addr, length, prot, flags, fd, offset) xaddr = uintptr(r0) - if uintptr(r0) == ^uintptr(0) && er != nil { - err = er + if e1 != 0 { + err = errnoErr(e1) } return } diff --git a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go new file mode 100644 index 000000000..a185ee842 --- /dev/null +++ b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go @@ -0,0 +1,1162 @@ +// mksyscall_aix_ppc64.pl -aix -tags aix,ppc64 syscall_aix.go syscall_aix_ppc64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build aix,ppc64 +// +build !gccgo + +package unix + +import ( + "unsafe" +) + +//go:cgo_import_dynamic libc_utimes utimes "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_utimensat utimensat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getcwd getcwd "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_accept accept "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getdirent getdirent "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_wait4 wait4 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_ioctl ioctl "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fcntl fcntl "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_acct acct "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_chdir chdir "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_chroot chroot "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_close close "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_dup dup "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_exit exit "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_faccessat faccessat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fchdir fchdir "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fchmod fchmod "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fchmodat fchmodat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fchownat fchownat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fdatasync fdatasync "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fsync fsync "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getpgid getpgid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getpgrp getpgrp "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getpid getpid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getppid getppid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getpriority getpriority "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getrusage getrusage "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getsid getsid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_kill kill "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_syslog syslog "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mkdir mkdir "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mkdirat mkdirat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mkfifo mkfifo "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mknod mknod "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mknodat mknodat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_nanosleep nanosleep "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_open64 open64 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_openat openat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_read read "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_readlink readlink "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_renameat renameat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setdomainname setdomainname "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_sethostname sethostname "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setpgid setpgid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setsid setsid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_settimeofday settimeofday "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setuid setuid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setgid setgid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setpriority setpriority "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_statx statx "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_sync sync "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_times times "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_umask umask "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_uname uname "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_unlink unlink "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_ustat ustat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_write write "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_dup2 dup2 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_posix_fadvise64 posix_fadvise64 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fchown fchown "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fstat fstat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fstatat fstatat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_fstatfs fstatfs "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_ftruncate ftruncate "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getegid getegid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_geteuid geteuid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getgid getgid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getuid getuid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_lchown lchown "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_listen listen "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_lstat lstat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pause pause "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pread64 pread64 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pwrite64 pwrite64 "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pselect pselect "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setregid setregid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setreuid setreuid "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_shutdown shutdown "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_splice splice "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_stat stat "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_statfs statfs "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_truncate truncate "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_bind bind "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_connect connect "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getgroups getgroups "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setgroups setgroups "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getsockopt getsockopt "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setsockopt setsockopt "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_socket socket "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_socketpair socketpair "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getpeername getpeername "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getsockname getsockname "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_recvfrom recvfrom "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_sendto sendto "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_recvmsg recvmsg "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_sendmsg sendmsg "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_munmap munmap "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_madvise madvise "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mprotect mprotect "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mlock mlock "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mlockall mlockall "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_msync msync "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_munlock munlock "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_munlockall munlockall "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_pipe pipe "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_poll poll "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_gettimeofday gettimeofday "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_time time "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_utime utime "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_getrlimit getrlimit "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_setrlimit setrlimit "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_lseek lseek "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_mmap64 mmap64 "libc.a/shr_64.o" + +//go:linkname libc_utimes libc_utimes +//go:linkname libc_utimensat libc_utimensat +//go:linkname libc_getcwd libc_getcwd +//go:linkname libc_accept libc_accept +//go:linkname libc_getdirent libc_getdirent +//go:linkname libc_wait4 libc_wait4 +//go:linkname libc_ioctl libc_ioctl +//go:linkname libc_fcntl libc_fcntl +//go:linkname libc_acct libc_acct +//go:linkname libc_chdir libc_chdir +//go:linkname libc_chroot libc_chroot +//go:linkname libc_close libc_close +//go:linkname libc_dup libc_dup +//go:linkname libc_exit libc_exit +//go:linkname libc_faccessat libc_faccessat +//go:linkname libc_fchdir libc_fchdir +//go:linkname libc_fchmod libc_fchmod +//go:linkname libc_fchmodat libc_fchmodat +//go:linkname libc_fchownat libc_fchownat +//go:linkname libc_fdatasync libc_fdatasync +//go:linkname libc_fsync libc_fsync +//go:linkname libc_getpgid libc_getpgid +//go:linkname libc_getpgrp libc_getpgrp +//go:linkname libc_getpid libc_getpid +//go:linkname libc_getppid libc_getppid +//go:linkname libc_getpriority libc_getpriority +//go:linkname libc_getrusage libc_getrusage +//go:linkname libc_getsid libc_getsid +//go:linkname libc_kill libc_kill +//go:linkname libc_syslog libc_syslog +//go:linkname libc_mkdir libc_mkdir +//go:linkname libc_mkdirat libc_mkdirat +//go:linkname libc_mkfifo libc_mkfifo +//go:linkname libc_mknod libc_mknod +//go:linkname libc_mknodat libc_mknodat +//go:linkname libc_nanosleep libc_nanosleep +//go:linkname libc_open64 libc_open64 +//go:linkname libc_openat libc_openat +//go:linkname libc_read libc_read +//go:linkname libc_readlink libc_readlink +//go:linkname libc_renameat libc_renameat +//go:linkname libc_setdomainname libc_setdomainname +//go:linkname libc_sethostname libc_sethostname +//go:linkname libc_setpgid libc_setpgid +//go:linkname libc_setsid libc_setsid +//go:linkname libc_settimeofday libc_settimeofday +//go:linkname libc_setuid libc_setuid +//go:linkname libc_setgid libc_setgid +//go:linkname libc_setpriority libc_setpriority +//go:linkname libc_statx libc_statx +//go:linkname libc_sync libc_sync +//go:linkname libc_times libc_times +//go:linkname libc_umask libc_umask +//go:linkname libc_uname libc_uname +//go:linkname libc_unlink libc_unlink +//go:linkname libc_unlinkat libc_unlinkat +//go:linkname libc_ustat libc_ustat +//go:linkname libc_write libc_write +//go:linkname libc_dup2 libc_dup2 +//go:linkname libc_posix_fadvise64 libc_posix_fadvise64 +//go:linkname libc_fchown libc_fchown +//go:linkname libc_fstat libc_fstat +//go:linkname libc_fstatat libc_fstatat +//go:linkname libc_fstatfs libc_fstatfs +//go:linkname libc_ftruncate libc_ftruncate +//go:linkname libc_getegid libc_getegid +//go:linkname libc_geteuid libc_geteuid +//go:linkname libc_getgid libc_getgid +//go:linkname libc_getuid libc_getuid +//go:linkname libc_lchown libc_lchown +//go:linkname libc_listen libc_listen +//go:linkname libc_lstat libc_lstat +//go:linkname libc_pause libc_pause +//go:linkname libc_pread64 libc_pread64 +//go:linkname libc_pwrite64 libc_pwrite64 +//go:linkname libc_pselect libc_pselect +//go:linkname libc_setregid libc_setregid +//go:linkname libc_setreuid libc_setreuid +//go:linkname libc_shutdown libc_shutdown +//go:linkname libc_splice libc_splice +//go:linkname libc_stat libc_stat +//go:linkname libc_statfs libc_statfs +//go:linkname libc_truncate libc_truncate +//go:linkname libc_bind libc_bind +//go:linkname libc_connect libc_connect +//go:linkname libc_getgroups libc_getgroups +//go:linkname libc_setgroups libc_setgroups +//go:linkname libc_getsockopt libc_getsockopt +//go:linkname libc_setsockopt libc_setsockopt +//go:linkname libc_socket libc_socket +//go:linkname libc_socketpair libc_socketpair +//go:linkname libc_getpeername libc_getpeername +//go:linkname libc_getsockname libc_getsockname +//go:linkname libc_recvfrom libc_recvfrom +//go:linkname libc_sendto libc_sendto +//go:linkname libc_recvmsg libc_recvmsg +//go:linkname libc_sendmsg libc_sendmsg +//go:linkname libc_munmap libc_munmap +//go:linkname libc_madvise libc_madvise +//go:linkname libc_mprotect libc_mprotect +//go:linkname libc_mlock libc_mlock +//go:linkname libc_mlockall libc_mlockall +//go:linkname libc_msync libc_msync +//go:linkname libc_munlock libc_munlock +//go:linkname libc_munlockall libc_munlockall +//go:linkname libc_pipe libc_pipe +//go:linkname libc_poll libc_poll +//go:linkname libc_gettimeofday libc_gettimeofday +//go:linkname libc_time libc_time +//go:linkname libc_utime libc_utime +//go:linkname libc_getrlimit libc_getrlimit +//go:linkname libc_setrlimit libc_setrlimit +//go:linkname libc_lseek libc_lseek +//go:linkname libc_mmap64 libc_mmap64 + +type syscallFunc uintptr + +var ( + libc_utimes, + libc_utimensat, + libc_getcwd, + libc_accept, + libc_getdirent, + libc_wait4, + libc_ioctl, + libc_fcntl, + libc_acct, + libc_chdir, + libc_chroot, + libc_close, + libc_dup, + libc_exit, + libc_faccessat, + libc_fchdir, + libc_fchmod, + libc_fchmodat, + libc_fchownat, + libc_fdatasync, + libc_fsync, + libc_getpgid, + libc_getpgrp, + libc_getpid, + libc_getppid, + libc_getpriority, + libc_getrusage, + libc_getsid, + libc_kill, + libc_syslog, + libc_mkdir, + libc_mkdirat, + libc_mkfifo, + libc_mknod, + libc_mknodat, + libc_nanosleep, + libc_open64, + libc_openat, + libc_read, + libc_readlink, + libc_renameat, + libc_setdomainname, + libc_sethostname, + libc_setpgid, + libc_setsid, + libc_settimeofday, + libc_setuid, + libc_setgid, + libc_setpriority, + libc_statx, + libc_sync, + libc_times, + libc_umask, + libc_uname, + libc_unlink, + libc_unlinkat, + libc_ustat, + libc_write, + libc_dup2, + libc_posix_fadvise64, + libc_fchown, + libc_fstat, + libc_fstatat, + libc_fstatfs, + libc_ftruncate, + libc_getegid, + libc_geteuid, + libc_getgid, + libc_getuid, + libc_lchown, + libc_listen, + libc_lstat, + libc_pause, + libc_pread64, + libc_pwrite64, + libc_pselect, + libc_setregid, + libc_setreuid, + libc_shutdown, + libc_splice, + libc_stat, + libc_statfs, + libc_truncate, + libc_bind, + libc_connect, + libc_getgroups, + libc_setgroups, + libc_getsockopt, + libc_setsockopt, + libc_socket, + libc_socketpair, + libc_getpeername, + libc_getsockname, + libc_recvfrom, + libc_sendto, + libc_recvmsg, + libc_sendmsg, + libc_munmap, + libc_madvise, + libc_mprotect, + libc_mlock, + libc_mlockall, + libc_msync, + libc_munlock, + libc_munlockall, + libc_pipe, + libc_poll, + libc_gettimeofday, + libc_time, + libc_utime, + libc_getrlimit, + libc_setrlimit, + libc_lseek, + libc_mmap64 syscallFunc +) + +// Implemented in runtime/syscall_aix.go. +func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) +func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutimes(_p0 uintptr, times uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_utimes)), 2, _p0, times, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutimensat(dirfd int, _p0 uintptr, times uintptr, flag int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_utimensat)), 4, uintptr(dirfd), _p0, times, uintptr(flag), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetcwd(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getcwd)), 2, _p0, uintptr(_lenp0), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callaccept(s int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_accept)), 3, uintptr(s), rsa, addrlen, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetdirent(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getdirent)), 3, uintptr(fd), _p0, uintptr(_lenp0), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callwait4(pid int, status uintptr, options int, rusage uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_wait4)), 4, uintptr(pid), status, uintptr(options), rusage, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callioctl(fd int, req int, arg uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_ioctl)), 3, uintptr(fd), uintptr(req), arg, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfcntl(fd uintptr, cmd int, arg uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fcntl)), 3, fd, uintptr(cmd), arg, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callacct(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_acct)), 1, _p0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callchdir(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_chdir)), 1, _p0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callchroot(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_chroot)), 1, _p0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callclose(fd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_close)), 1, uintptr(fd), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calldup(oldfd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_dup)), 1, uintptr(oldfd), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callexit(code int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_exit)), 1, uintptr(code), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfaccessat(dirfd int, _p0 uintptr, mode uint32, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_faccessat)), 4, uintptr(dirfd), _p0, uintptr(mode), uintptr(flags), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchdir(fd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fchdir)), 1, uintptr(fd), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchmod(fd int, mode uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fchmod)), 2, uintptr(fd), uintptr(mode), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchmodat(dirfd int, _p0 uintptr, mode uint32, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fchmodat)), 4, uintptr(dirfd), _p0, uintptr(mode), uintptr(flags), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchownat(dirfd int, _p0 uintptr, uid int, gid int, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fchownat)), 5, uintptr(dirfd), _p0, uintptr(uid), uintptr(gid), uintptr(flags), 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfdatasync(fd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fdatasync)), 1, uintptr(fd), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfsync(fd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fsync)), 1, uintptr(fd), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpgid(pid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getpgid)), 1, uintptr(pid), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpgrp() (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getpgrp)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getpid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetppid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getppid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpriority(which int, who int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getpriority)), 2, uintptr(which), uintptr(who), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetrusage(who int, rusage uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getrusage)), 2, uintptr(who), rusage, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsid(pid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getsid)), 1, uintptr(pid), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callkill(pid int, sig int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_kill)), 2, uintptr(pid), uintptr(sig), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsyslog(typ int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_syslog)), 3, uintptr(typ), _p0, uintptr(_lenp0), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkdir(dirfd int, _p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mkdir)), 3, uintptr(dirfd), _p0, uintptr(mode), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkdirat(dirfd int, _p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mkdirat)), 3, uintptr(dirfd), _p0, uintptr(mode), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkfifo(_p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mkfifo)), 2, _p0, uintptr(mode), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmknod(_p0 uintptr, mode uint32, dev int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mknod)), 3, _p0, uintptr(mode), uintptr(dev), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmknodat(dirfd int, _p0 uintptr, mode uint32, dev int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mknodat)), 4, uintptr(dirfd), _p0, uintptr(mode), uintptr(dev), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callnanosleep(time uintptr, leftover uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_nanosleep)), 2, time, leftover, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callopen64(_p0 uintptr, mode int, perm uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_open64)), 3, _p0, uintptr(mode), uintptr(perm), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callopenat(dirfd int, _p0 uintptr, flags int, mode uint32) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_openat)), 4, uintptr(dirfd), _p0, uintptr(flags), uintptr(mode), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callread(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_read)), 3, uintptr(fd), _p0, uintptr(_lenp0), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callreadlink(_p0 uintptr, _p1 uintptr, _lenp1 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_readlink)), 3, _p0, _p1, uintptr(_lenp1), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrenameat(olddirfd int, _p0 uintptr, newdirfd int, _p1 uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_renameat)), 4, uintptr(olddirfd), _p0, uintptr(newdirfd), _p1, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetdomainname(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_setdomainname)), 2, _p0, uintptr(_lenp0), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsethostname(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_sethostname)), 2, _p0, uintptr(_lenp0), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetpgid(pid int, pgid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setpgid)), 2, uintptr(pid), uintptr(pgid), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetsid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setsid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsettimeofday(tv uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_settimeofday)), 1, tv, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetuid(uid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_setuid)), 1, uintptr(uid), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetgid(uid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_setgid)), 1, uintptr(uid), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetpriority(which int, who int, prio int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_setpriority)), 3, uintptr(which), uintptr(who), uintptr(prio), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstatx(dirfd int, _p0 uintptr, flags int, mask int, stat uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_statx)), 5, uintptr(dirfd), _p0, uintptr(flags), uintptr(mask), stat, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsync() (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_sync)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltimes(tms uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_times)), 1, tms, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callumask(mask int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_umask)), 1, uintptr(mask), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calluname(buf uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_uname)), 1, buf, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callunlink(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_unlink)), 1, _p0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callunlinkat(dirfd int, _p0 uintptr, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_unlinkat)), 3, uintptr(dirfd), _p0, uintptr(flags), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callustat(dev int, ubuf uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_ustat)), 2, uintptr(dev), ubuf, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callwrite(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_write)), 3, uintptr(fd), _p0, uintptr(_lenp0), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calldup2(oldfd int, newfd int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_dup2)), 2, uintptr(oldfd), uintptr(newfd), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callposix_fadvise64(fd int, offset int64, length int64, advice int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_posix_fadvise64)), 4, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchown(fd int, uid int, gid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fchown)), 3, uintptr(fd), uintptr(uid), uintptr(gid), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstat(fd int, stat uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fstat)), 2, uintptr(fd), stat, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstatat(dirfd int, _p0 uintptr, stat uintptr, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fstatat)), 4, uintptr(dirfd), _p0, stat, uintptr(flags), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstatfs(fd int, buf uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_fstatfs)), 2, uintptr(fd), buf, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callftruncate(fd int, length int64) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_ftruncate)), 2, uintptr(fd), uintptr(length), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetegid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getegid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgeteuid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_geteuid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetgid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getgid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetuid() (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getuid)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllchown(_p0 uintptr, uid int, gid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_lchown)), 3, _p0, uintptr(uid), uintptr(gid), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllisten(s int, n int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_listen)), 2, uintptr(s), uintptr(n), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllstat(_p0 uintptr, stat uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_lstat)), 2, _p0, stat, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpause() (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_pause)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpread64(fd int, _p0 uintptr, _lenp0 int, offset int64) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_pread64)), 4, uintptr(fd), _p0, uintptr(_lenp0), uintptr(offset), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpwrite64(fd int, _p0 uintptr, _lenp0 int, offset int64) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_pwrite64)), 4, uintptr(fd), _p0, uintptr(_lenp0), uintptr(offset), 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpselect(nfd int, r uintptr, w uintptr, e uintptr, timeout uintptr, sigmask uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_pselect)), 6, uintptr(nfd), r, w, e, timeout, sigmask) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetregid(rgid int, egid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setregid)), 2, uintptr(rgid), uintptr(egid), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetreuid(ruid int, euid int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setreuid)), 2, uintptr(ruid), uintptr(euid), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callshutdown(fd int, how int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_shutdown)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsplice(rfd int, roff uintptr, wfd int, woff uintptr, len int, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_splice)), 6, uintptr(rfd), roff, uintptr(wfd), woff, uintptr(len), uintptr(flags)) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstat(_p0 uintptr, stat uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_stat)), 2, _p0, stat, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstatfs(_p0 uintptr, buf uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_statfs)), 2, _p0, buf, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltruncate(_p0 uintptr, length int64) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_truncate)), 2, _p0, uintptr(length), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callbind(s int, addr uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_bind)), 3, uintptr(s), addr, addrlen, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callconnect(s int, addr uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_connect)), 3, uintptr(s), addr, addrlen, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetgroups(n int, list uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getgroups)), 2, uintptr(n), list, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetgroups(n int, list uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setgroups)), 2, uintptr(n), list, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsockopt(s int, level int, name int, val uintptr, vallen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getsockopt)), 5, uintptr(s), uintptr(level), uintptr(name), val, vallen, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetsockopt(s int, level int, name int, val uintptr, vallen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_setsockopt)), 5, uintptr(s), uintptr(level), uintptr(name), val, vallen, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsocket(domain int, typ int, proto int) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_socket)), 3, uintptr(domain), uintptr(typ), uintptr(proto), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsocketpair(domain int, typ int, proto int, fd uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_socketpair)), 4, uintptr(domain), uintptr(typ), uintptr(proto), fd, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpeername(fd int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getpeername)), 3, uintptr(fd), rsa, addrlen, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsockname(fd int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getsockname)), 3, uintptr(fd), rsa, addrlen, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrecvfrom(fd int, _p0 uintptr, _lenp0 int, flags int, from uintptr, fromlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_recvfrom)), 6, uintptr(fd), _p0, uintptr(_lenp0), uintptr(flags), from, fromlen) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsendto(s int, _p0 uintptr, _lenp0 int, flags int, to uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_sendto)), 6, uintptr(s), _p0, uintptr(_lenp0), uintptr(flags), to, addrlen) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrecvmsg(s int, msg uintptr, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_recvmsg)), 3, uintptr(s), msg, uintptr(flags), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsendmsg(s int, msg uintptr, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_sendmsg)), 3, uintptr(s), msg, uintptr(flags), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunmap(addr uintptr, length uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_munmap)), 2, addr, length, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmadvise(_p0 uintptr, _lenp0 int, advice int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_madvise)), 3, _p0, uintptr(_lenp0), uintptr(advice), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmprotect(_p0 uintptr, _lenp0 int, prot int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mprotect)), 3, _p0, uintptr(_lenp0), uintptr(prot), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmlock(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mlock)), 2, _p0, uintptr(_lenp0), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmlockall(flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mlockall)), 1, uintptr(flags), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmsync(_p0 uintptr, _lenp0 int, flags int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_msync)), 3, _p0, uintptr(_lenp0), uintptr(flags), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunlock(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_munlock)), 2, _p0, uintptr(_lenp0), 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunlockall() (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_munlockall)), 0, 0, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpipe(p uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_pipe)), 1, p, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpoll(fds uintptr, nfds int, timeout int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_poll)), 3, fds, uintptr(nfds), uintptr(timeout), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgettimeofday(tv uintptr, tzp uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_gettimeofday)), 2, tv, tzp, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltime(t uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_time)), 1, t, 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutime(_p0 uintptr, buf uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_utime)), 2, _p0, buf, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetrlimit(resource int, rlim uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_getrlimit)), 2, uintptr(resource), rlim, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetrlimit(resource int, rlim uintptr) (r1 uintptr, e1 Errno) { + r1, _, e1 = rawSyscall6(uintptr(unsafe.Pointer(&libc_setrlimit)), 2, uintptr(resource), rlim, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllseek(fd int, offset int64, whence int) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_lseek)), 3, uintptr(fd), uintptr(offset), uintptr(whence), 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmmap64(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (r1 uintptr, e1 Errno) { + r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_mmap64)), 6, addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)) + return +} diff --git a/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go new file mode 100644 index 000000000..aef7c0e78 --- /dev/null +++ b/vendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go @@ -0,0 +1,1042 @@ +// mksyscall_aix_ppc64.pl -aix -tags aix,ppc64 syscall_aix.go syscall_aix_ppc64.go +// Code generated by the command above; see README.md. DO NOT EDIT. + +// +build aix,ppc64 +// +build gccgo + +package unix + +/* +#include +int utimes(uintptr_t, uintptr_t); +int utimensat(int, uintptr_t, uintptr_t, int); +int getcwd(uintptr_t, size_t); +int accept(int, uintptr_t, uintptr_t); +int getdirent(int, uintptr_t, size_t); +int wait4(int, uintptr_t, int, uintptr_t); +int ioctl(int, int, uintptr_t); +int fcntl(uintptr_t, int, uintptr_t); +int acct(uintptr_t); +int chdir(uintptr_t); +int chroot(uintptr_t); +int close(int); +int dup(int); +void exit(int); +int faccessat(int, uintptr_t, unsigned int, int); +int fchdir(int); +int fchmod(int, unsigned int); +int fchmodat(int, uintptr_t, unsigned int, int); +int fchownat(int, uintptr_t, int, int, int); +int fdatasync(int); +int fsync(int); +int getpgid(int); +int getpgrp(); +int getpid(); +int getppid(); +int getpriority(int, int); +int getrusage(int, uintptr_t); +int getsid(int); +int kill(int, int); +int syslog(int, uintptr_t, size_t); +int mkdir(int, uintptr_t, unsigned int); +int mkdirat(int, uintptr_t, unsigned int); +int mkfifo(uintptr_t, unsigned int); +int mknod(uintptr_t, unsigned int, int); +int mknodat(int, uintptr_t, unsigned int, int); +int nanosleep(uintptr_t, uintptr_t); +int open64(uintptr_t, int, unsigned int); +int openat(int, uintptr_t, int, unsigned int); +int read(int, uintptr_t, size_t); +int readlink(uintptr_t, uintptr_t, size_t); +int renameat(int, uintptr_t, int, uintptr_t); +int setdomainname(uintptr_t, size_t); +int sethostname(uintptr_t, size_t); +int setpgid(int, int); +int setsid(); +int settimeofday(uintptr_t); +int setuid(int); +int setgid(int); +int setpriority(int, int, int); +int statx(int, uintptr_t, int, int, uintptr_t); +int sync(); +uintptr_t times(uintptr_t); +int umask(int); +int uname(uintptr_t); +int unlink(uintptr_t); +int unlinkat(int, uintptr_t, int); +int ustat(int, uintptr_t); +int write(int, uintptr_t, size_t); +int dup2(int, int); +int posix_fadvise64(int, long long, long long, int); +int fchown(int, int, int); +int fstat(int, uintptr_t); +int fstatat(int, uintptr_t, uintptr_t, int); +int fstatfs(int, uintptr_t); +int ftruncate(int, long long); +int getegid(); +int geteuid(); +int getgid(); +int getuid(); +int lchown(uintptr_t, int, int); +int listen(int, int); +int lstat(uintptr_t, uintptr_t); +int pause(); +int pread64(int, uintptr_t, size_t, long long); +int pwrite64(int, uintptr_t, size_t, long long); +int pselect(int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t); +int setregid(int, int); +int setreuid(int, int); +int shutdown(int, int); +long long splice(int, uintptr_t, int, uintptr_t, int, int); +int stat(uintptr_t, uintptr_t); +int statfs(uintptr_t, uintptr_t); +int truncate(uintptr_t, long long); +int bind(int, uintptr_t, uintptr_t); +int connect(int, uintptr_t, uintptr_t); +int getgroups(int, uintptr_t); +int setgroups(int, uintptr_t); +int getsockopt(int, int, int, uintptr_t, uintptr_t); +int setsockopt(int, int, int, uintptr_t, uintptr_t); +int socket(int, int, int); +int socketpair(int, int, int, uintptr_t); +int getpeername(int, uintptr_t, uintptr_t); +int getsockname(int, uintptr_t, uintptr_t); +int recvfrom(int, uintptr_t, size_t, int, uintptr_t, uintptr_t); +int sendto(int, uintptr_t, size_t, int, uintptr_t, uintptr_t); +int recvmsg(int, uintptr_t, int); +int sendmsg(int, uintptr_t, int); +int munmap(uintptr_t, uintptr_t); +int madvise(uintptr_t, size_t, int); +int mprotect(uintptr_t, size_t, int); +int mlock(uintptr_t, size_t); +int mlockall(int); +int msync(uintptr_t, size_t, int); +int munlock(uintptr_t, size_t); +int munlockall(); +int pipe(uintptr_t); +int poll(uintptr_t, int, int); +int gettimeofday(uintptr_t, uintptr_t); +int time(uintptr_t); +int utime(uintptr_t, uintptr_t); +int getrlimit(int, uintptr_t); +int setrlimit(int, uintptr_t); +long long lseek(int, long long, int); +uintptr_t mmap64(uintptr_t, uintptr_t, int, int, int, long long); + +*/ +import "C" +import ( + "syscall" +) + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutimes(_p0 uintptr, times uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.utimes(C.uintptr_t(_p0), C.uintptr_t(times))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutimensat(dirfd int, _p0 uintptr, times uintptr, flag int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.utimensat(C.int(dirfd), C.uintptr_t(_p0), C.uintptr_t(times), C.int(flag))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetcwd(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getcwd(C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callaccept(s int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.accept(C.int(s), C.uintptr_t(rsa), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetdirent(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getdirent(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callwait4(pid int, status uintptr, options int, rusage uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.wait4(C.int(pid), C.uintptr_t(status), C.int(options), C.uintptr_t(rusage))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callioctl(fd int, req int, arg uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.ioctl(C.int(fd), C.int(req), C.uintptr_t(arg))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfcntl(fd uintptr, cmd int, arg uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fcntl(C.uintptr_t(fd), C.int(cmd), C.uintptr_t(arg))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callacct(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.acct(C.uintptr_t(_p0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callchdir(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.chdir(C.uintptr_t(_p0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callchroot(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.chroot(C.uintptr_t(_p0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callclose(fd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.close(C.int(fd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calldup(oldfd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.dup(C.int(oldfd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callexit(code int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.exit(C.int(code))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfaccessat(dirfd int, _p0 uintptr, mode uint32, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.faccessat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchdir(fd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fchdir(C.int(fd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchmod(fd int, mode uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fchmod(C.int(fd), C.uint(mode))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchmodat(dirfd int, _p0 uintptr, mode uint32, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fchmodat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchownat(dirfd int, _p0 uintptr, uid int, gid int, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fchownat(C.int(dirfd), C.uintptr_t(_p0), C.int(uid), C.int(gid), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfdatasync(fd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fdatasync(C.int(fd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfsync(fd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fsync(C.int(fd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpgid(pid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getpgid(C.int(pid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpgrp() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getpgrp()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getpid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetppid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getppid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpriority(which int, who int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getpriority(C.int(which), C.int(who))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetrusage(who int, rusage uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getrusage(C.int(who), C.uintptr_t(rusage))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsid(pid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getsid(C.int(pid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callkill(pid int, sig int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.kill(C.int(pid), C.int(sig))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsyslog(typ int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.syslog(C.int(typ), C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkdir(dirfd int, _p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mkdir(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkdirat(dirfd int, _p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mkdirat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmkfifo(_p0 uintptr, mode uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mkfifo(C.uintptr_t(_p0), C.uint(mode))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmknod(_p0 uintptr, mode uint32, dev int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mknod(C.uintptr_t(_p0), C.uint(mode), C.int(dev))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmknodat(dirfd int, _p0 uintptr, mode uint32, dev int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mknodat(C.int(dirfd), C.uintptr_t(_p0), C.uint(mode), C.int(dev))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callnanosleep(time uintptr, leftover uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.nanosleep(C.uintptr_t(time), C.uintptr_t(leftover))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callopen64(_p0 uintptr, mode int, perm uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.open64(C.uintptr_t(_p0), C.int(mode), C.uint(perm))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callopenat(dirfd int, _p0 uintptr, flags int, mode uint32) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.openat(C.int(dirfd), C.uintptr_t(_p0), C.int(flags), C.uint(mode))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callread(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.read(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callreadlink(_p0 uintptr, _p1 uintptr, _lenp1 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.readlink(C.uintptr_t(_p0), C.uintptr_t(_p1), C.size_t(_lenp1))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrenameat(olddirfd int, _p0 uintptr, newdirfd int, _p1 uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.renameat(C.int(olddirfd), C.uintptr_t(_p0), C.int(newdirfd), C.uintptr_t(_p1))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetdomainname(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setdomainname(C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsethostname(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.sethostname(C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetpgid(pid int, pgid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setpgid(C.int(pid), C.int(pgid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetsid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setsid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsettimeofday(tv uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.settimeofday(C.uintptr_t(tv))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetuid(uid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setuid(C.int(uid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetgid(uid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setgid(C.int(uid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetpriority(which int, who int, prio int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setpriority(C.int(which), C.int(who), C.int(prio))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstatx(dirfd int, _p0 uintptr, flags int, mask int, stat uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.statx(C.int(dirfd), C.uintptr_t(_p0), C.int(flags), C.int(mask), C.uintptr_t(stat))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsync() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.sync()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltimes(tms uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.times(C.uintptr_t(tms))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callumask(mask int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.umask(C.int(mask))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calluname(buf uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.uname(C.uintptr_t(buf))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callunlink(_p0 uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.unlink(C.uintptr_t(_p0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callunlinkat(dirfd int, _p0 uintptr, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.unlinkat(C.int(dirfd), C.uintptr_t(_p0), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callustat(dev int, ubuf uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.ustat(C.int(dev), C.uintptr_t(ubuf))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callwrite(fd int, _p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.write(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calldup2(oldfd int, newfd int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.dup2(C.int(oldfd), C.int(newfd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callposix_fadvise64(fd int, offset int64, length int64, advice int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.posix_fadvise64(C.int(fd), C.longlong(offset), C.longlong(length), C.int(advice))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfchown(fd int, uid int, gid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fchown(C.int(fd), C.int(uid), C.int(gid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstat(fd int, stat uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fstat(C.int(fd), C.uintptr_t(stat))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstatat(dirfd int, _p0 uintptr, stat uintptr, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fstatat(C.int(dirfd), C.uintptr_t(_p0), C.uintptr_t(stat), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callfstatfs(fd int, buf uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.fstatfs(C.int(fd), C.uintptr_t(buf))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callftruncate(fd int, length int64) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.ftruncate(C.int(fd), C.longlong(length))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetegid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getegid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgeteuid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.geteuid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetgid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getgid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetuid() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getuid()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllchown(_p0 uintptr, uid int, gid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.lchown(C.uintptr_t(_p0), C.int(uid), C.int(gid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllisten(s int, n int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.listen(C.int(s), C.int(n))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllstat(_p0 uintptr, stat uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.lstat(C.uintptr_t(_p0), C.uintptr_t(stat))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpause() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.pause()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpread64(fd int, _p0 uintptr, _lenp0 int, offset int64) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.pread64(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0), C.longlong(offset))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpwrite64(fd int, _p0 uintptr, _lenp0 int, offset int64) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.pwrite64(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0), C.longlong(offset))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpselect(nfd int, r uintptr, w uintptr, e uintptr, timeout uintptr, sigmask uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.pselect(C.int(nfd), C.uintptr_t(r), C.uintptr_t(w), C.uintptr_t(e), C.uintptr_t(timeout), C.uintptr_t(sigmask))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetregid(rgid int, egid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setregid(C.int(rgid), C.int(egid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetreuid(ruid int, euid int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setreuid(C.int(ruid), C.int(euid))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callshutdown(fd int, how int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.shutdown(C.int(fd), C.int(how))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsplice(rfd int, roff uintptr, wfd int, woff uintptr, len int, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.splice(C.int(rfd), C.uintptr_t(roff), C.int(wfd), C.uintptr_t(woff), C.int(len), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstat(_p0 uintptr, stat uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.stat(C.uintptr_t(_p0), C.uintptr_t(stat))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callstatfs(_p0 uintptr, buf uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.statfs(C.uintptr_t(_p0), C.uintptr_t(buf))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltruncate(_p0 uintptr, length int64) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.truncate(C.uintptr_t(_p0), C.longlong(length))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callbind(s int, addr uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.bind(C.int(s), C.uintptr_t(addr), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callconnect(s int, addr uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.connect(C.int(s), C.uintptr_t(addr), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetgroups(n int, list uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getgroups(C.int(n), C.uintptr_t(list))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetgroups(n int, list uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setgroups(C.int(n), C.uintptr_t(list))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsockopt(s int, level int, name int, val uintptr, vallen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getsockopt(C.int(s), C.int(level), C.int(name), C.uintptr_t(val), C.uintptr_t(vallen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetsockopt(s int, level int, name int, val uintptr, vallen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setsockopt(C.int(s), C.int(level), C.int(name), C.uintptr_t(val), C.uintptr_t(vallen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsocket(domain int, typ int, proto int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.socket(C.int(domain), C.int(typ), C.int(proto))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsocketpair(domain int, typ int, proto int, fd uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.socketpair(C.int(domain), C.int(typ), C.int(proto), C.uintptr_t(fd))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetpeername(fd int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getpeername(C.int(fd), C.uintptr_t(rsa), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetsockname(fd int, rsa uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getsockname(C.int(fd), C.uintptr_t(rsa), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrecvfrom(fd int, _p0 uintptr, _lenp0 int, flags int, from uintptr, fromlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.recvfrom(C.int(fd), C.uintptr_t(_p0), C.size_t(_lenp0), C.int(flags), C.uintptr_t(from), C.uintptr_t(fromlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsendto(s int, _p0 uintptr, _lenp0 int, flags int, to uintptr, addrlen uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.sendto(C.int(s), C.uintptr_t(_p0), C.size_t(_lenp0), C.int(flags), C.uintptr_t(to), C.uintptr_t(addrlen))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callrecvmsg(s int, msg uintptr, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.recvmsg(C.int(s), C.uintptr_t(msg), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsendmsg(s int, msg uintptr, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.sendmsg(C.int(s), C.uintptr_t(msg), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunmap(addr uintptr, length uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.munmap(C.uintptr_t(addr), C.uintptr_t(length))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmadvise(_p0 uintptr, _lenp0 int, advice int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.madvise(C.uintptr_t(_p0), C.size_t(_lenp0), C.int(advice))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmprotect(_p0 uintptr, _lenp0 int, prot int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mprotect(C.uintptr_t(_p0), C.size_t(_lenp0), C.int(prot))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmlock(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mlock(C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmlockall(flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mlockall(C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmsync(_p0 uintptr, _lenp0 int, flags int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.msync(C.uintptr_t(_p0), C.size_t(_lenp0), C.int(flags))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunlock(_p0 uintptr, _lenp0 int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.munlock(C.uintptr_t(_p0), C.size_t(_lenp0))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmunlockall() (r1 uintptr, e1 Errno) { + r1 = uintptr(C.munlockall()) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpipe(p uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.pipe(C.uintptr_t(p))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callpoll(fds uintptr, nfds int, timeout int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.poll(C.uintptr_t(fds), C.int(nfds), C.int(timeout))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgettimeofday(tv uintptr, tzp uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.gettimeofday(C.uintptr_t(tv), C.uintptr_t(tzp))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calltime(t uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.time(C.uintptr_t(t))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callutime(_p0 uintptr, buf uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.utime(C.uintptr_t(_p0), C.uintptr_t(buf))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callgetrlimit(resource int, rlim uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.getrlimit(C.int(resource), C.uintptr_t(rlim))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callsetrlimit(resource int, rlim uintptr) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.setrlimit(C.int(resource), C.uintptr_t(rlim))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func calllseek(fd int, offset int64, whence int) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.lseek(C.int(fd), C.longlong(offset), C.int(whence))) + e1 = syscall.GetErrno() + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func callmmap64(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (r1 uintptr, e1 Errno) { + r1 = uintptr(C.mmap64(C.uintptr_t(addr), C.uintptr_t(length), C.int(prot), C.int(flags), C.int(fd), C.longlong(offset))) + e1 = syscall.GetErrno() + return +} diff --git a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go index ad77882b8..9bbbf9662 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go @@ -912,7 +912,7 @@ func Fpathconf(fd int, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstat(fd int, stat *Stat_t) (err error) { +func fstat(fd int, stat *stat_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -922,7 +922,17 @@ func Fstat(fd int, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { +func fstat_freebsd12(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -937,7 +947,22 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatfs(fd int, stat *Statfs_t) (err error) { +func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatfs(fd int, stat *statfs_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -947,6 +972,16 @@ func Fstatfs(fd int, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fsync(fd int) (err error) { _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) if e1 != 0 { @@ -967,14 +1002,14 @@ func Ftruncate(fd int, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdents(fd int, buf []byte) (n int, err error) { +func getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -984,14 +1019,14 @@ func Getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { +func getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES_FREEBSD12, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -1222,7 +1257,7 @@ func Listen(s int, backlog int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lstat(path string, stat *Stat_t) (err error) { +func lstat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1282,7 +1317,7 @@ func Mkfifo(path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Mknod(path string, mode uint32, dev int) (err error) { +func mknod(path string, mode uint32, dev int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1297,6 +1332,36 @@ func Mknod(path string, mode uint32, dev int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func mknodat(fd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mknodat_freebsd12(fd int, path string, mode uint32, dev uint64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Nanosleep(time *Timespec, leftover *Timespec) (err error) { _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) if e1 != 0 { @@ -1687,7 +1752,7 @@ func Setuid(uid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { +func stat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1702,7 +1767,7 @@ func Stat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Statfs(path string, stat *Statfs_t) (err error) { +func statfs(path string, stat *statfs_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1717,6 +1782,21 @@ func Statfs(path string, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func statfs_freebsd12(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS_FREEBSD12, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Symlink(path string, link string) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go index d3ba6c46f..ee7090ff4 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go @@ -912,7 +912,7 @@ func Fpathconf(fd int, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstat(fd int, stat *Stat_t) (err error) { +func fstat(fd int, stat *stat_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -922,7 +922,17 @@ func Fstat(fd int, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { +func fstat_freebsd12(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -937,7 +947,22 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatfs(fd int, stat *Statfs_t) (err error) { +func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatfs(fd int, stat *statfs_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -947,6 +972,16 @@ func Fstatfs(fd int, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fsync(fd int) (err error) { _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) if e1 != 0 { @@ -967,14 +1002,14 @@ func Ftruncate(fd int, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdents(fd int, buf []byte) (n int, err error) { +func getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -984,14 +1019,14 @@ func Getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { +func getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES_FREEBSD12, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -1222,7 +1257,7 @@ func Listen(s int, backlog int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lstat(path string, stat *Stat_t) (err error) { +func lstat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1282,7 +1317,7 @@ func Mkfifo(path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Mknod(path string, mode uint32, dev int) (err error) { +func mknod(path string, mode uint32, dev int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1297,6 +1332,36 @@ func Mknod(path string, mode uint32, dev int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func mknodat(fd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mknodat_freebsd12(fd int, path string, mode uint32, dev uint64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Nanosleep(time *Timespec, leftover *Timespec) (err error) { _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) if e1 != 0 { @@ -1687,7 +1752,7 @@ func Setuid(uid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { +func stat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1702,7 +1767,7 @@ func Stat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Statfs(path string, stat *Statfs_t) (err error) { +func statfs(path string, stat *statfs_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1717,6 +1782,21 @@ func Statfs(path string, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func statfs_freebsd12(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS_FREEBSD12, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Symlink(path string, link string) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go index 9dfd77b62..9aeff5131 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go @@ -912,7 +912,7 @@ func Fpathconf(fd int, name int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstat(fd int, stat *Stat_t) (err error) { +func fstat(fd int, stat *stat_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -922,7 +922,17 @@ func Fstat(fd int, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { +func fstat_freebsd12(fd int, stat *Stat_t) (err error) { + _, _, e1 := Syscall(SYS_FSTAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatat(fd int, path string, stat *stat_freebsd11_t, flags int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -937,7 +947,22 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Fstatfs(fd int, stat *Statfs_t) (err error) { +func fstatat_freebsd12(fd int, path string, stat *Stat_t, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FSTATAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func fstatfs(fd int, stat *statfs_freebsd11_t) (err error) { _, _, e1 := Syscall(SYS_FSTATFS, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { err = errnoErr(e1) @@ -947,6 +972,16 @@ func Fstatfs(fd int, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func fstatfs_freebsd12(fd int, stat *Statfs_t) (err error) { + _, _, e1 := Syscall(SYS_FSTATFS_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fsync(fd int) (err error) { _, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0) if e1 != 0 { @@ -967,14 +1002,14 @@ func Ftruncate(fd int, length int64) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdents(fd int, buf []byte) (n int, err error) { +func getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -984,14 +1019,14 @@ func Getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { +func getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error) { var _p0 unsafe.Pointer if len(buf) > 0 { _p0 = unsafe.Pointer(&buf[0]) } else { _p0 = unsafe.Pointer(&_zero) } - r0, _, e1 := Syscall6(SYS_GETDIRENTRIES, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) + r0, _, e1 := Syscall6(SYS_GETDIRENTRIES_FREEBSD12, uintptr(fd), uintptr(_p0), uintptr(len(buf)), uintptr(unsafe.Pointer(basep)), 0, 0) n = int(r0) if e1 != 0 { err = errnoErr(e1) @@ -1222,7 +1257,7 @@ func Listen(s int, backlog int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lstat(path string, stat *Stat_t) (err error) { +func lstat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1282,7 +1317,7 @@ func Mkfifo(path string, mode uint32) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Mknod(path string, mode uint32, dev int) (err error) { +func mknod(path string, mode uint32, dev int) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1297,6 +1332,36 @@ func Mknod(path string, mode uint32, dev int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func mknodat(fd int, path string, mode uint32, dev int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mknodat_freebsd12(fd int, path string, mode uint32, dev uint64) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_MKNODAT_FREEBSD12, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Nanosleep(time *Timespec, leftover *Timespec) (err error) { _, _, e1 := Syscall(SYS_NANOSLEEP, uintptr(unsafe.Pointer(time)), uintptr(unsafe.Pointer(leftover)), 0) if e1 != 0 { @@ -1687,7 +1752,7 @@ func Setuid(uid int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { +func stat(path string, stat *stat_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1702,7 +1767,7 @@ func Stat(path string, stat *Stat_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Statfs(path string, stat *Statfs_t) (err error) { +func statfs(path string, stat *statfs_freebsd11_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) if err != nil { @@ -1717,6 +1782,21 @@ func Statfs(path string, stat *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func statfs_freebsd12(path string, stat *Statfs_t) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall(SYS_STATFS_FREEBSD12, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Symlink(path string, link string) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go b/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go index a1db143f8..6e281d6b3 100644 --- a/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go @@ -360,4 +360,5 @@ const ( SYS_PKEY_FREE = 396 SYS_STATX = 397 SYS_RSEQ = 398 + SYS_IO_PGETEVENTS = 399 ) diff --git a/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go b/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go index 2e4cee70d..f9157e192 100644 --- a/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go @@ -284,4 +284,5 @@ const ( SYS_PKEY_FREE = 290 SYS_STATX = 291 SYS_IO_PGETEVENTS = 292 + SYS_RSEQ = 293 ) diff --git a/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go b/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go index 41e4fd1d3..a5d991915 100644 --- a/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go @@ -283,4 +283,5 @@ const ( SYS_PKEY_FREE = 290 SYS_STATX = 291 SYS_IO_PGETEVENTS = 292 + SYS_RSEQ = 293 ) diff --git a/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go b/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go index 07787301f..f93f391d2 100644 --- a/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go +++ b/vendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go @@ -1,5 +1,5 @@ // mksysnum_openbsd.pl -// Code generated by the command above; DO NOT EDIT. +// Code generated by the command above; see README.md. DO NOT EDIT. // +build 386,openbsd @@ -12,6 +12,7 @@ const ( SYS_WRITE = 4 // { ssize_t sys_write(int fd, const void *buf, \ SYS_OPEN = 5 // { int sys_open(const char *path, \ SYS_CLOSE = 6 // { int sys_close(int fd); } + SYS_GETENTROPY = 7 // { int sys_getentropy(void *buf, size_t nbyte); } SYS___TFORK = 8 // { int sys___tfork(const struct __tfork *param, \ SYS_LINK = 9 // { int sys_link(const char *path, const char *link); } SYS_UNLINK = 10 // { int sys_unlink(const char *path); } @@ -37,11 +38,10 @@ const ( SYS_ACCEPT = 30 // { int sys_accept(int s, struct sockaddr *name, \ SYS_GETPEERNAME = 31 // { int sys_getpeername(int fdes, struct sockaddr *asa, \ SYS_GETSOCKNAME = 32 // { int sys_getsockname(int fdes, struct sockaddr *asa, \ - SYS_ACCESS = 33 // { int sys_access(const char *path, int flags); } + SYS_ACCESS = 33 // { int sys_access(const char *path, int amode); } SYS_CHFLAGS = 34 // { int sys_chflags(const char *path, u_int flags); } SYS_FCHFLAGS = 35 // { int sys_fchflags(int fd, u_int flags); } SYS_SYNC = 36 // { void sys_sync(void); } - SYS_KILL = 37 // { int sys_kill(int pid, int signum); } SYS_STAT = 38 // { int sys_stat(const char *path, struct stat *ub); } SYS_GETPPID = 39 // { pid_t sys_getppid(void); } SYS_LSTAT = 40 // { int sys_lstat(const char *path, struct stat *ub); } @@ -53,7 +53,6 @@ const ( SYS_SIGACTION = 46 // { int sys_sigaction(int signum, \ SYS_GETGID = 47 // { gid_t sys_getgid(void); } SYS_SIGPROCMASK = 48 // { int sys_sigprocmask(int how, sigset_t mask); } - SYS_GETLOGIN = 49 // { int sys_getlogin(char *namebuf, u_int namelen); } SYS_SETLOGIN = 50 // { int sys_setlogin(const char *namebuf); } SYS_ACCT = 51 // { int sys_acct(const char *path); } SYS_SIGPENDING = 52 // { int sys_sigpending(void); } @@ -62,7 +61,7 @@ const ( SYS_REBOOT = 55 // { int sys_reboot(int opt); } SYS_REVOKE = 56 // { int sys_revoke(const char *path); } SYS_SYMLINK = 57 // { int sys_symlink(const char *path, \ - SYS_READLINK = 58 // { int sys_readlink(const char *path, char *buf, \ + SYS_READLINK = 58 // { ssize_t sys_readlink(const char *path, \ SYS_EXECVE = 59 // { int sys_execve(const char *path, \ SYS_UMASK = 60 // { mode_t sys_umask(mode_t newmask); } SYS_CHROOT = 61 // { int sys_chroot(const char *path); } @@ -86,15 +85,18 @@ const ( SYS_GETGROUPS = 79 // { int sys_getgroups(int gidsetsize, \ SYS_SETGROUPS = 80 // { int sys_setgroups(int gidsetsize, \ SYS_GETPGRP = 81 // { int sys_getpgrp(void); } - SYS_SETPGID = 82 // { int sys_setpgid(pid_t pid, int pgid); } + SYS_SETPGID = 82 // { int sys_setpgid(pid_t pid, pid_t pgid); } + SYS_FUTEX = 83 // { int sys_futex(uint32_t *f, int op, int val, \ SYS_UTIMENSAT = 84 // { int sys_utimensat(int fd, const char *path, \ SYS_FUTIMENS = 85 // { int sys_futimens(int fd, \ + SYS_KBIND = 86 // { int sys_kbind(const struct __kbind *param, \ SYS_CLOCK_GETTIME = 87 // { int sys_clock_gettime(clockid_t clock_id, \ SYS_CLOCK_SETTIME = 88 // { int sys_clock_settime(clockid_t clock_id, \ SYS_CLOCK_GETRES = 89 // { int sys_clock_getres(clockid_t clock_id, \ SYS_DUP2 = 90 // { int sys_dup2(int from, int to); } SYS_NANOSLEEP = 91 // { int sys_nanosleep(const struct timespec *rqtp, \ SYS_FCNTL = 92 // { int sys_fcntl(int fd, int cmd, ... void *arg); } + SYS_ACCEPT4 = 93 // { int sys_accept4(int s, struct sockaddr *name, \ SYS___THRSLEEP = 94 // { int sys___thrsleep(const volatile void *ident, \ SYS_FSYNC = 95 // { int sys_fsync(int fd); } SYS_SETPRIORITY = 96 // { int sys_setpriority(int which, id_t who, int prio); } @@ -102,16 +104,24 @@ const ( SYS_CONNECT = 98 // { int sys_connect(int s, const struct sockaddr *name, \ SYS_GETDENTS = 99 // { int sys_getdents(int fd, void *buf, size_t buflen); } SYS_GETPRIORITY = 100 // { int sys_getpriority(int which, id_t who); } + SYS_PIPE2 = 101 // { int sys_pipe2(int *fdp, int flags); } + SYS_DUP3 = 102 // { int sys_dup3(int from, int to, int flags); } SYS_SIGRETURN = 103 // { int sys_sigreturn(struct sigcontext *sigcntxp); } SYS_BIND = 104 // { int sys_bind(int s, const struct sockaddr *name, \ SYS_SETSOCKOPT = 105 // { int sys_setsockopt(int s, int level, int name, \ SYS_LISTEN = 106 // { int sys_listen(int s, int backlog); } + SYS_CHFLAGSAT = 107 // { int sys_chflagsat(int fd, const char *path, \ + SYS_PLEDGE = 108 // { int sys_pledge(const char *promises, \ SYS_PPOLL = 109 // { int sys_ppoll(struct pollfd *fds, \ SYS_PSELECT = 110 // { int sys_pselect(int nd, fd_set *in, fd_set *ou, \ SYS_SIGSUSPEND = 111 // { int sys_sigsuspend(int mask); } + SYS_SENDSYSLOG = 112 // { int sys_sendsyslog(const char *buf, size_t nbyte, \ + SYS_UNVEIL = 114 // { int sys_unveil(const char *path, \ SYS_GETSOCKOPT = 118 // { int sys_getsockopt(int s, int level, int name, \ + SYS_THRKILL = 119 // { int sys_thrkill(pid_t tid, int signum, void *tcb); } SYS_READV = 120 // { ssize_t sys_readv(int fd, \ SYS_WRITEV = 121 // { ssize_t sys_writev(int fd, \ + SYS_KILL = 122 // { int sys_kill(int pid, int signum); } SYS_FCHOWN = 123 // { int sys_fchown(int fd, uid_t uid, gid_t gid); } SYS_FCHMOD = 124 // { int sys_fchmod(int fd, mode_t mode); } SYS_SETREUID = 126 // { int sys_setreuid(uid_t ruid, uid_t euid); } @@ -125,6 +135,7 @@ const ( SYS_MKDIR = 136 // { int sys_mkdir(const char *path, mode_t mode); } SYS_RMDIR = 137 // { int sys_rmdir(const char *path); } SYS_ADJTIME = 140 // { int sys_adjtime(const struct timeval *delta, \ + SYS_GETLOGIN_R = 141 // { int sys_getlogin_r(char *namebuf, u_int namelen); } SYS_SETSID = 147 // { int sys_setsid(void); } SYS_QUOTACTL = 148 // { int sys_quotactl(const char *path, int cmd, \ SYS_NFSSVC = 155 // { int sys_nfssvc(int flag, void *argp); } @@ -144,7 +155,7 @@ const ( SYS_LSEEK = 199 // { off_t sys_lseek(int fd, int pad, off_t offset, \ SYS_TRUNCATE = 200 // { int sys_truncate(const char *path, int pad, \ SYS_FTRUNCATE = 201 // { int sys_ftruncate(int fd, int pad, off_t length); } - SYS___SYSCTL = 202 // { int sys___sysctl(const int *name, u_int namelen, \ + SYS_SYSCTL = 202 // { int sys_sysctl(const int *name, u_int namelen, \ SYS_MLOCK = 203 // { int sys_mlock(const void *addr, size_t len); } SYS_MUNLOCK = 204 // { int sys_munlock(const void *addr, size_t len); } SYS_GETPGID = 207 // { pid_t sys_getpgid(pid_t pid); } diff --git a/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go b/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go index 7a1693acb..be1198d91 100644 --- a/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go +++ b/vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go @@ -1,5 +1,5 @@ // mksysnum_openbsd.pl -// Code generated by the command above; DO NOT EDIT. +// Code generated by the command above; see README.md. DO NOT EDIT. // +build arm,openbsd @@ -53,7 +53,6 @@ const ( SYS_SIGACTION = 46 // { int sys_sigaction(int signum, \ SYS_GETGID = 47 // { gid_t sys_getgid(void); } SYS_SIGPROCMASK = 48 // { int sys_sigprocmask(int how, sigset_t mask); } - SYS_GETLOGIN = 49 // { int sys_getlogin(char *namebuf, u_int namelen); } SYS_SETLOGIN = 50 // { int sys_setlogin(const char *namebuf); } SYS_ACCT = 51 // { int sys_acct(const char *path); } SYS_SIGPENDING = 52 // { int sys_sigpending(void); } @@ -87,9 +86,10 @@ const ( SYS_SETGROUPS = 80 // { int sys_setgroups(int gidsetsize, \ SYS_GETPGRP = 81 // { int sys_getpgrp(void); } SYS_SETPGID = 82 // { int sys_setpgid(pid_t pid, pid_t pgid); } - SYS_SENDSYSLOG = 83 // { int sys_sendsyslog(const void *buf, size_t nbyte); } + SYS_FUTEX = 83 // { int sys_futex(uint32_t *f, int op, int val, \ SYS_UTIMENSAT = 84 // { int sys_utimensat(int fd, const char *path, \ SYS_FUTIMENS = 85 // { int sys_futimens(int fd, \ + SYS_KBIND = 86 // { int sys_kbind(const struct __kbind *param, \ SYS_CLOCK_GETTIME = 87 // { int sys_clock_gettime(clockid_t clock_id, \ SYS_CLOCK_SETTIME = 88 // { int sys_clock_settime(clockid_t clock_id, \ SYS_CLOCK_GETRES = 89 // { int sys_clock_getres(clockid_t clock_id, \ @@ -111,10 +111,14 @@ const ( SYS_SETSOCKOPT = 105 // { int sys_setsockopt(int s, int level, int name, \ SYS_LISTEN = 106 // { int sys_listen(int s, int backlog); } SYS_CHFLAGSAT = 107 // { int sys_chflagsat(int fd, const char *path, \ + SYS_PLEDGE = 108 // { int sys_pledge(const char *promises, \ SYS_PPOLL = 109 // { int sys_ppoll(struct pollfd *fds, \ SYS_PSELECT = 110 // { int sys_pselect(int nd, fd_set *in, fd_set *ou, \ SYS_SIGSUSPEND = 111 // { int sys_sigsuspend(int mask); } + SYS_SENDSYSLOG = 112 // { int sys_sendsyslog(const char *buf, size_t nbyte, \ + SYS_UNVEIL = 114 // { int sys_unveil(const char *path, \ SYS_GETSOCKOPT = 118 // { int sys_getsockopt(int s, int level, int name, \ + SYS_THRKILL = 119 // { int sys_thrkill(pid_t tid, int signum, void *tcb); } SYS_READV = 120 // { ssize_t sys_readv(int fd, \ SYS_WRITEV = 121 // { ssize_t sys_writev(int fd, \ SYS_KILL = 122 // { int sys_kill(int pid, int signum); } @@ -131,6 +135,7 @@ const ( SYS_MKDIR = 136 // { int sys_mkdir(const char *path, mode_t mode); } SYS_RMDIR = 137 // { int sys_rmdir(const char *path); } SYS_ADJTIME = 140 // { int sys_adjtime(const struct timeval *delta, \ + SYS_GETLOGIN_R = 141 // { int sys_getlogin_r(char *namebuf, u_int namelen); } SYS_SETSID = 147 // { int sys_setsid(void); } SYS_QUOTACTL = 148 // { int sys_quotactl(const char *path, int cmd, \ SYS_NFSSVC = 155 // { int sys_nfssvc(int flag, void *argp); } @@ -150,7 +155,7 @@ const ( SYS_LSEEK = 199 // { off_t sys_lseek(int fd, int pad, off_t offset, \ SYS_TRUNCATE = 200 // { int sys_truncate(const char *path, int pad, \ SYS_FTRUNCATE = 201 // { int sys_ftruncate(int fd, int pad, off_t length); } - SYS___SYSCTL = 202 // { int sys___sysctl(const int *name, u_int namelen, \ + SYS_SYSCTL = 202 // { int sys_sysctl(const int *name, u_int namelen, \ SYS_MLOCK = 203 // { int sys_mlock(const void *addr, size_t len); } SYS_MUNLOCK = 204 // { int sys_munlock(const void *addr, size_t len); } SYS_GETPGID = 207 // { pid_t sys_getpgid(pid_t pid); } diff --git a/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go b/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go index 11380294a..28ef5242f 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go +++ b/vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go @@ -56,28 +56,84 @@ type Rlimit struct { type _Gid_t uint32 +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + type Stat_t struct { - Dev uint32 - Ino uint32 - Mode uint16 - Nlink uint16 - Uid uint32 - Gid uint32 - Rdev uint32 - Atimespec Timespec - Mtimespec Timespec - Ctimespec Timespec - Size int64 - Blocks int64 - Blksize int32 - Flags uint32 - Gen uint32 - Lspare int32 - Birthtimespec Timespec - Pad_cgo_0 [8]byte + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim_ext int32 + Atim Timespec + Mtim_ext int32 + Mtim Timespec + Ctim_ext int32 + Ctim Timespec + Btim_ext int32 + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec + _ [8]byte } type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { Version uint32 Type uint32 Flags uint64 @@ -112,6 +168,17 @@ type Flock_t struct { } type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { Fileno uint32 Reclen uint16 Type uint8 @@ -272,7 +339,7 @@ type Kevent_t struct { } type FdSet struct { - X__fds_bits [32]uint32 + _ [32]uint32 } const ( @@ -288,53 +355,53 @@ const ( ) type ifMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data ifData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData } type IfMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data IfData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData } type ifData struct { - Type uint8 - Physical uint8 - Addrlen uint8 - Hdrlen uint8 - Link_state uint8 - Vhid uint8 - Datalen uint16 - Mtu uint32 - Metric uint32 - Baudrate uint64 - Ipackets uint64 - Ierrors uint64 - Opackets uint64 - Oerrors uint64 - Collisions uint64 - Ibytes uint64 - Obytes uint64 - Imcasts uint64 - Omcasts uint64 - Iqdrops uint64 - Oqdrops uint64 - Noproto uint64 - Hwassist uint64 - X__ifi_epoch [8]byte - X__ifi_lastchange [16]byte + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte } type IfData struct { @@ -366,24 +433,24 @@ type IfData struct { } type IfaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Metric int32 + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 } type IfmaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte } type IfAnnounceMsghdr struct { @@ -396,19 +463,19 @@ type IfAnnounceMsghdr struct { } type RtMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Index uint16 - Pad_cgo_0 [2]byte - Flags int32 - Addrs int32 - Pid int32 - Seq int32 - Errno int32 - Fmask int32 - Inits uint32 - Rmx RtMetrics + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics } type RtMetrics struct { @@ -465,18 +532,18 @@ type BpfInsn struct { } type BpfHdr struct { - Tstamp Timeval - Caplen uint32 - Datalen uint32 - Hdrlen uint16 - Pad_cgo_0 [2]byte + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [2]byte } type BpfZbufHeader struct { Kernel_gen uint32 Kernel_len uint32 User_gen uint32 - X_bzh_pad [5]uint32 + _ [5]uint32 } type Termios struct { diff --git a/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go b/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go index a6fc12718..e2d984a48 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go @@ -56,27 +56,79 @@ type Rlimit struct { type _Gid_t uint32 +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + type Stat_t struct { - Dev uint32 - Ino uint32 - Mode uint16 - Nlink uint16 - Uid uint32 - Gid uint32 - Rdev uint32 - Atimespec Timespec - Mtimespec Timespec - Ctimespec Timespec - Size int64 - Blocks int64 - Blksize int32 - Flags uint32 - Gen uint32 - Lspare int32 - Birthtimespec Timespec + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec } type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { Version uint32 Type uint32 Flags uint64 @@ -102,16 +154,27 @@ type Statfs_t struct { } type Flock_t struct { - Start int64 - Len int64 - Pid int32 - Type int16 - Whence int16 - Sysid int32 - Pad_cgo_0 [4]byte + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte } type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { Fileno uint32 Reclen uint16 Type uint8 @@ -212,10 +275,10 @@ type IPv6Mreq struct { type Msghdr struct { Name *byte Namelen uint32 - Pad_cgo_0 [4]byte + _ [4]byte Iov *Iovec Iovlen int32 - Pad_cgo_1 [4]byte + _ [4]byte Control *byte Controllen uint32 Flags int32 @@ -274,7 +337,7 @@ type Kevent_t struct { } type FdSet struct { - X__fds_bits [16]uint64 + _ [16]uint64 } const ( @@ -290,53 +353,53 @@ const ( ) type ifMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data ifData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData } type IfMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data IfData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData } type ifData struct { - Type uint8 - Physical uint8 - Addrlen uint8 - Hdrlen uint8 - Link_state uint8 - Vhid uint8 - Datalen uint16 - Mtu uint32 - Metric uint32 - Baudrate uint64 - Ipackets uint64 - Ierrors uint64 - Opackets uint64 - Oerrors uint64 - Collisions uint64 - Ibytes uint64 - Obytes uint64 - Imcasts uint64 - Omcasts uint64 - Iqdrops uint64 - Oqdrops uint64 - Noproto uint64 - Hwassist uint64 - X__ifi_epoch [8]byte - X__ifi_lastchange [16]byte + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte } type IfData struct { @@ -368,24 +431,24 @@ type IfData struct { } type IfaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Metric int32 + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 } type IfmaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte } type IfAnnounceMsghdr struct { @@ -398,19 +461,19 @@ type IfAnnounceMsghdr struct { } type RtMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Index uint16 - Pad_cgo_0 [2]byte - Flags int32 - Addrs int32 - Pid int32 - Seq int32 - Errno int32 - Fmask int32 - Inits uint64 - Rmx RtMetrics + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint64 + Rmx RtMetrics } type RtMetrics struct { @@ -455,9 +518,9 @@ type BpfZbuf struct { } type BpfProgram struct { - Len uint32 - Pad_cgo_0 [4]byte - Insns *BpfInsn + Len uint32 + _ [4]byte + Insns *BpfInsn } type BpfInsn struct { @@ -468,18 +531,18 @@ type BpfInsn struct { } type BpfHdr struct { - Tstamp Timeval - Caplen uint32 - Datalen uint32 - Hdrlen uint16 - Pad_cgo_0 [6]byte + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte } type BpfZbufHeader struct { Kernel_gen uint32 Kernel_len uint32 User_gen uint32 - X_bzh_pad [5]uint32 + _ [5]uint32 } type Termios struct { diff --git a/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go b/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go index 6b3006d6b..9b415aba4 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go +++ b/vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go @@ -21,15 +21,15 @@ type ( ) type Timespec struct { - Sec int64 - Nsec int32 - Pad_cgo_0 [4]byte + Sec int64 + Nsec int32 + _ [4]byte } type Timeval struct { - Sec int64 - Usec int32 - Pad_cgo_0 [4]byte + Sec int64 + Usec int32 + _ [4]byte } type Rusage struct { @@ -58,27 +58,79 @@ type Rlimit struct { type _Gid_t uint32 +const ( + _statfsVersion = 0x20140518 + _dirblksiz = 0x400 +) + type Stat_t struct { - Dev uint32 - Ino uint32 - Mode uint16 - Nlink uint16 - Uid uint32 - Gid uint32 - Rdev uint32 - Atimespec Timespec - Mtimespec Timespec - Ctimespec Timespec - Size int64 - Blocks int64 - Blksize int32 - Flags uint32 - Gen uint32 - Lspare int32 - Birthtimespec Timespec + Dev uint64 + Ino uint64 + Nlink uint64 + Mode uint16 + _0 int16 + Uid uint32 + Gid uint32 + _1 int32 + Rdev uint64 + Atim Timespec + Mtim Timespec + Ctim Timespec + Birthtim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint64 + Spare [10]uint64 +} + +type stat_freebsd11_t struct { + Dev uint32 + Ino uint32 + Mode uint16 + Nlink uint16 + Uid uint32 + Gid uint32 + Rdev uint32 + Atim Timespec + Mtim Timespec + Ctim Timespec + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Lspare int32 + Birthtim Timespec } type Statfs_t struct { + Version uint32 + Type uint32 + Flags uint64 + Bsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail int64 + Files uint64 + Ffree int64 + Syncwrites uint64 + Asyncwrites uint64 + Syncreads uint64 + Asyncreads uint64 + Spare [10]uint64 + Namemax uint32 + Owner uint32 + Fsid Fsid + Charspare [80]int8 + Fstypename [16]int8 + Mntfromname [1024]int8 + Mntonname [1024]int8 +} + +type statfs_freebsd11_t struct { Version uint32 Type uint32 Flags uint64 @@ -104,16 +156,27 @@ type Statfs_t struct { } type Flock_t struct { - Start int64 - Len int64 - Pid int32 - Type int16 - Whence int16 - Sysid int32 - Pad_cgo_0 [4]byte + Start int64 + Len int64 + Pid int32 + Type int16 + Whence int16 + Sysid int32 + _ [4]byte } type Dirent struct { + Fileno uint64 + Off int64 + Reclen uint16 + Type uint8 + Pad0 uint8 + Namlen uint16 + Pad1 uint16 + Name [256]int8 +} + +type dirent_freebsd11 struct { Fileno uint32 Reclen uint16 Type uint8 @@ -274,7 +337,7 @@ type Kevent_t struct { } type FdSet struct { - X__fds_bits [32]uint32 + _ [32]uint32 } const ( @@ -290,53 +353,53 @@ const ( ) type ifMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data ifData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data ifData } type IfMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Data IfData + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Data IfData } type ifData struct { - Type uint8 - Physical uint8 - Addrlen uint8 - Hdrlen uint8 - Link_state uint8 - Vhid uint8 - Datalen uint16 - Mtu uint32 - Metric uint32 - Baudrate uint64 - Ipackets uint64 - Ierrors uint64 - Opackets uint64 - Oerrors uint64 - Collisions uint64 - Ibytes uint64 - Obytes uint64 - Imcasts uint64 - Omcasts uint64 - Iqdrops uint64 - Oqdrops uint64 - Noproto uint64 - Hwassist uint64 - X__ifi_epoch [8]byte - X__ifi_lastchange [16]byte + Type uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Link_state uint8 + Vhid uint8 + Datalen uint16 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Oqdrops uint64 + Noproto uint64 + Hwassist uint64 + _ [8]byte + _ [16]byte } type IfData struct { @@ -363,30 +426,30 @@ type IfData struct { Iqdrops uint32 Noproto uint32 Hwassist uint32 - Pad_cgo_0 [4]byte + _ [4]byte Epoch int64 Lastchange Timeval } type IfaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte - Metric int32 + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte + Metric int32 } type IfmaMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Addrs int32 - Flags int32 - Index uint16 - Pad_cgo_0 [2]byte + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + _ [2]byte } type IfAnnounceMsghdr struct { @@ -399,19 +462,19 @@ type IfAnnounceMsghdr struct { } type RtMsghdr struct { - Msglen uint16 - Version uint8 - Type uint8 - Index uint16 - Pad_cgo_0 [2]byte - Flags int32 - Addrs int32 - Pid int32 - Seq int32 - Errno int32 - Fmask int32 - Inits uint32 - Rmx RtMetrics + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + _ [2]byte + Flags int32 + Addrs int32 + Pid int32 + Seq int32 + Errno int32 + Fmask int32 + Inits uint32 + Rmx RtMetrics } type RtMetrics struct { @@ -468,18 +531,18 @@ type BpfInsn struct { } type BpfHdr struct { - Tstamp Timeval - Caplen uint32 - Datalen uint32 - Hdrlen uint16 - Pad_cgo_0 [6]byte + Tstamp Timeval + Caplen uint32 + Datalen uint32 + Hdrlen uint16 + _ [6]byte } type BpfZbufHeader struct { Kernel_gen uint32 Kernel_len uint32 User_gen uint32 - X_bzh_pad [5]uint32 + _ [5]uint32 } type Termios struct { diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_386.go b/vendor/golang.org/x/sys/unix/ztypes_linux_386.go index 3879002a9..5f8f03492 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_386.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_386.go @@ -494,7 +494,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1965,3 +1965,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go b/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go index cbc2c7d07..aa52a439d 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go @@ -498,7 +498,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1987,3 +1987,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go b/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go index 6ed804fa3..23c8438be 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go @@ -497,7 +497,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1955,3 +1955,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go b/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go index b5fe7ddf7..d7a993e25 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go @@ -499,7 +499,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1966,3 +1966,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go b/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go index 7379ad2d8..b8c3d0a4d 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go @@ -495,7 +495,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1960,3 +1960,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go b/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go index 0b131a24e..a6f76149a 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go @@ -499,7 +499,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1968,3 +1968,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go b/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go index 9191020cc..3dd194176 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go @@ -499,7 +499,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1968,3 +1968,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go b/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go index 8fcad32bf..210de76cc 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go @@ -495,7 +495,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1960,3 +1960,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go b/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go index a9d1b6c9f..b46d54e37 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go @@ -500,7 +500,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1976,3 +1976,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go b/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go index f0f5214a5..6ee799cef 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go @@ -500,7 +500,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1976,3 +1976,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go b/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go index 09c905866..60ae71e62 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go @@ -499,7 +499,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1993,3 +1993,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go b/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go index 5e86e496c..dea88f7bb 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go @@ -498,7 +498,7 @@ const ( IFLA_EVENT = 0x2c IFLA_NEW_NETNSID = 0x2d IFLA_IF_NETNSID = 0x2e - IFLA_MAX = 0x31 + IFLA_MAX = 0x33 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -1993,3 +1993,24 @@ const ( NCSI_CHANNEL_ATTR_VLAN_LIST = 0x9 NCSI_CHANNEL_ATTR_VLAN_ID = 0xa ) + +const ( + SOF_TIMESTAMPING_TX_HARDWARE = 0x1 + SOF_TIMESTAMPING_TX_SOFTWARE = 0x2 + SOF_TIMESTAMPING_RX_HARDWARE = 0x4 + SOF_TIMESTAMPING_RX_SOFTWARE = 0x8 + SOF_TIMESTAMPING_SOFTWARE = 0x10 + SOF_TIMESTAMPING_SYS_HARDWARE = 0x20 + SOF_TIMESTAMPING_RAW_HARDWARE = 0x40 + SOF_TIMESTAMPING_OPT_ID = 0x80 + SOF_TIMESTAMPING_TX_SCHED = 0x100 + SOF_TIMESTAMPING_TX_ACK = 0x200 + SOF_TIMESTAMPING_OPT_CMSG = 0x400 + SOF_TIMESTAMPING_OPT_TSONLY = 0x800 + SOF_TIMESTAMPING_OPT_STATS = 0x1000 + SOF_TIMESTAMPING_OPT_PKTINFO = 0x2000 + SOF_TIMESTAMPING_OPT_TX_SWHW = 0x4000 + + SOF_TIMESTAMPING_LAST = 0x4000 + SOF_TIMESTAMPING_MASK = 0x7fff +) From 5e5f2c28a775163f1c7e23c67ffb8a7e6ac95c29 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 23 Oct 2018 14:42:43 +0800 Subject: [PATCH 36/38] Complete explorer refactor --- blockproducer/blockindex.go | 12 + blockproducer/chain.go | 32 ++- blockproducer/chain_test.go | 6 +- blockproducer/rpc.go | 29 ++- build.sh | 3 + cmd/cql-explorer/api.go | 324 +++++++++++++++++++++++++ cmd/cql-explorer/errors.go | 34 +++ cmd/cql-explorer/main.go | 67 ++++++ cmd/cql-explorer/service.go | 462 ++++++++++++++++++++++++++++++++++++ route/acl.go | 4 + 10 files changed, 961 insertions(+), 12 deletions(-) create mode 100644 cmd/cql-explorer/api.go create mode 100644 cmd/cql-explorer/errors.go create mode 100644 cmd/cql-explorer/service.go diff --git a/blockproducer/blockindex.go b/blockproducer/blockindex.go index ec3b9327d..a916b5902 100644 --- a/blockproducer/blockindex.go +++ b/blockproducer/blockindex.go @@ -79,6 +79,18 @@ func (bn *blockNode) ancestor(h uint32) *blockNode { return ancestor } +func (bn *blockNode) ancestorByCount(c uint32) *blockNode { + if c > bn.count { + return nil + } + + ancestor := bn + for ancestor != nil && ancestor.count != c { + ancestor = ancestor.parent + } + return ancestor +} + type blockIndex struct { mu sync.RWMutex index map[hash.Hash]*blockNode diff --git a/blockproducer/chain.go b/blockproducer/chain.go index 09f2e3d14..dbdf1a297 100644 --- a/blockproducer/chain.go +++ b/blockproducer/chain.go @@ -469,24 +469,44 @@ func (c *Chain) checkBillingRequest(br *pt.BillingRequest) (err error) { return } -func (c *Chain) fetchBlockByHeight(h uint32) (*pt.Block, error) { +func (c *Chain) fetchBlockByHeight(h uint32) (b *pt.Block, count uint32, err error) { node := c.rt.getHead().getNode().ancestor(h) if node == nil { - return nil, ErrNoSuchBlock + return nil, 0, ErrNoSuchBlock } - b := &pt.Block{} + b = &pt.Block{} k := node.indexKey() - err := c.db.View(func(tx *bolt.Tx) error { + err = c.db.View(func(tx *bolt.Tx) error { v := tx.Bucket(metaBucket[:]).Bucket(metaBlockIndexBucket).Get(k) return utils.DecodeMsgPack(v, b) }) if err != nil { - return nil, err + return nil, 0, err + } + + return b, node.count, nil +} + +func (c *Chain) fetchBlockByCount(count uint32) (b *pt.Block, height uint32, err error) { + node := c.rt.getHead().getNode().ancestorByCount(count) + if node == nil { + return nil, 0, ErrNoSuchBlock + } + + b = &pt.Block{} + k := node.indexKey() + + err = c.db.View(func(tx *bolt.Tx) error { + v := tx.Bucket(metaBucket[:]).Bucket(metaBlockIndexBucket).Get(k) + return utils.DecodeMsgPack(v, b) + }) + if err != nil { + return nil, 0, err } - return b, nil + return b, node.height, nil } // runCurrentTurn does the check and runs block producing if its my turn. diff --git a/blockproducer/chain_test.go b/blockproducer/chain_test.go index 1b41531d5..876ea3804 100644 --- a/blockproducer/chain_test.go +++ b/blockproducer/chain_test.go @@ -101,7 +101,7 @@ func TestChain(t *testing.T) { t.Logf("Chain state: head = %s, height = %d, turn = %d, nextturnstart = %s, ismyturn = %t", chain.rt.getHead().getHeader(), chain.rt.getHead().getHeight(), chain.rt.nextTurn, chain.rt.chainInitTime.Add( - chain.rt.period * time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), + chain.rt.period*time.Duration(chain.rt.nextTurn)).Format(time.RFC3339Nano), chain.rt.isMyTurn()) // chain will receive blocks and tx @@ -133,10 +133,10 @@ func TestChain(t *testing.T) { // So(chain.rt.getHead().Height, ShouldEqual, height) height := chain.rt.getHead().getHeight() - specificHeightBlock1, err := chain.fetchBlockByHeight(height) + specificHeightBlock1, _, err := chain.fetchBlockByHeight(height) So(err, ShouldBeNil) So(block.SignedHeader.BlockHash, ShouldResemble, specificHeightBlock1.SignedHeader.BlockHash) - specificHeightBlock2, err := chain.fetchBlockByHeight(height + 1000) + specificHeightBlock2, _, err := chain.fetchBlockByHeight(height + 1000) So(specificHeightBlock2, ShouldBeNil) So(err, ShouldNotBeNil) diff --git a/blockproducer/rpc.go b/blockproducer/rpc.go index 897971523..358e5bad0 100644 --- a/blockproducer/rpc.go +++ b/blockproducer/rpc.go @@ -60,9 +60,16 @@ type FetchBlockReq struct { type FetchBlockResp struct { proto.Envelope Height uint32 + Count uint32 Block *types.Block } +// FetchBlockByCountReq define a request of the FetchBlockByCount RPC method. +type FetchBlockByCountReq struct { + proto.Envelope + Count uint32 +} + // FetchTxBillingReq defines a request of the FetchTxBilling RPC method. type FetchTxBillingReq struct { proto.Envelope @@ -141,15 +148,31 @@ func (s *ChainRPCService) AdviseBillingRequest(req *ct.AdviseBillingReq, resp *c return nil } -// FetchBlock is the RPC method to fetch a known block form the target server. +// FetchBlock is the RPC method to fetch a known block from the target server. func (s *ChainRPCService) FetchBlock(req *FetchBlockReq, resp *FetchBlockResp) error { resp.Height = req.Height - block, err := s.chain.fetchBlockByHeight(req.Height) + block, count, err := s.chain.fetchBlockByHeight(req.Height) + if err != nil { + return err + } + resp.Block = block + resp.Count = count + return err +} + +// FetchBlockByCount is the RPC method to fetch a known block from the target server. +func (s *ChainRPCService) FetchBlockByCount(req *FetchBlockByCountReq, resp *FetchBlockResp) error { + resp.Count = req.Count + block, height, err := s.chain.fetchBlockByCount(req.Count) + if err != nil { + return err + } resp.Block = block + resp.Height = height return err } -// FetchTxBilling is the RPC method to fetch a known billing tx form the target server. +// FetchTxBilling is the RPC method to fetch a known billing tx from the target server. func (s *ChainRPCService) FetchTxBilling(req *FetchTxBillingReq, resp *FetchTxBillingResp) error { return nil } diff --git a/build.sh b/build.sh index cb5211048..5482d38f2 100755 --- a/build.sh +++ b/build.sh @@ -49,5 +49,8 @@ CGO_ENABLED=1 go build -ldflags "-X main.version=${version} -X github.com/Covena cql_mysql_adapter_pkgpath="github.com/CovenantSQL/CovenantSQL/cmd/cql-mysql-adapter" CGO_ENABLED=1 go build -ldflags "-X github.com/CovenantSQL/CovenantSQL/conf.RoleTag=C ${GOLDFLAGS}" --tags ${platform}" sqlite_omit_load_extension" -o bin/cql-mysql-adapter ${cql_mysql_adapter_pkgpath} +cql_explorer_pkgpath="github.com/CovenantSQL/CovenantSQL/cmd/cql-explorer" +CGO_ENABLED=1 go build -ldflags "-X github.com/CovenantSQL/CovenantSQL/conf.RoleTag=C ${GOLDFLAGS}" --tags ${platform}" sqlite_omit_load_extension" -o bin/cql-explorer ${cql_explorer_pkgpath} + echo "done" diff --git a/cmd/cql-explorer/api.go b/cmd/cql-explorer/api.go new file mode 100644 index 000000000..767c8075f --- /dev/null +++ b/cmd/cql-explorer/api.go @@ -0,0 +1,324 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "strconv" + "time" + + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" + pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils/log" + "github.com/gorilla/mux" +) + +var ( + apiTimeout = time.Second * 10 +) + +func sendResponse(code int, success bool, msg interface{}, data interface{}, rw http.ResponseWriter) { + msgStr := "ok" + if msg != nil { + msgStr = fmt.Sprint(msg) + } + rw.WriteHeader(code) + json.NewEncoder(rw).Encode(map[string]interface{}{ + "status": msgStr, + "success": success, + "data": data, + }) +} + +func sendError(err error, rw http.ResponseWriter) { + if err == ErrNotFound { + sendResponse(404, false, err, nil, rw) + } else if err == ErrBadRequest { + sendResponse(400, false, err, nil, rw) + } else if err != nil { + sendResponse(500, false, err, nil, rw) + } else { + sendResponse(200, true, nil, nil, rw) + } +} + +func getUintFromVars(field string, r *http.Request) (value uint32, err error) { + vars := mux.Vars(r) + valueStr := vars[field] + if valueStr == "" { + err = ErrBadRequest + return + } + + valueUint, err := strconv.ParseUint(valueStr, 10, 32) + if err != nil { + return + } + + value = uint32(valueUint) + + return +} + +type explorerAPI struct { + service *Service +} + +func (a *explorerAPI) GetHighestBlock(rw http.ResponseWriter, r *http.Request) { + count, err := a.service.getHighestCount() + if err != nil { + sendError(err, rw) + return + } + + block, _, height, err := a.service.getBlockByCount(count) + if err != nil { + sendError(err, rw) + return + } + + sendResponse(200, true, nil, a.formatBlock(count, height, block), rw) +} + +func (a *explorerAPI) GetBlockByCount(rw http.ResponseWriter, r *http.Request) { + count, err := getUintFromVars("count", r) + if err != nil { + sendError(err, rw) + return + } + + block, _, height, err := a.service.getBlockByCount(count) + if err != nil { + sendError(err, rw) + return + } + + sendResponse(200, true, nil, a.formatBlock(count, height, block), rw) +} + +func (a *explorerAPI) GetBlockByHeight(rw http.ResponseWriter, r *http.Request) { + height, err := getUintFromVars("height", r) + if err != nil { + sendError(err, rw) + return + } + + block, count, _, err := a.service.getBlockByHeight(height) + if err != nil { + sendError(err, rw) + return + } + + sendResponse(200, true, nil, a.formatBlock(count, height, block), rw) +} + +func (a *explorerAPI) GetBlockByHash(rw http.ResponseWriter, r *http.Request) { + h, err := a.getHash(r) + if err != nil { + sendError(err, rw) + return + } + + block, count, height, err := a.service.getBlockByHash(h) + if err != nil { + sendError(err, rw) + return + } + + sendResponse(200, true, nil, a.formatBlock(count, height, block), rw) +} + +func (a *explorerAPI) GetTxByHash(rw http.ResponseWriter, r *http.Request) { + h, err := a.getHash(r) + if err != nil { + sendError(err, rw) + return + } + + tx, count, height, err := a.service.getTxByHash(h) + if err != nil { + sendError(err, rw) + return + } + + sendResponse(200, true, nil, a.formatTx(count, height, tx), rw) +} + +func (a *explorerAPI) formatTime(t time.Time) float64 { + return float64(t.UnixNano()) / 1e6 +} + +func (a *explorerAPI) formatBlock(count uint32, height uint32, b *pt.Block) map[string]interface{} { + txs := make([]map[string]interface{}, 0, len(b.Transactions)) + + for _, tx := range b.Transactions { + txs = append(txs, a.formatRawTx(tx)) + } + + return map[string]interface{}{ + "block": map[string]interface{}{ + "height": height, + "count": count, + "hash": b.BlockHash().String(), + "parent": b.ParentHash().String(), + "timestamp": a.formatTime(b.Timestamp()), + "version": b.SignedHeader.Version, + "producer": b.Producer(), + "txs": txs, + }, + } +} + +func (a *explorerAPI) formatRawTx(t pi.Transaction) (res map[string]interface{}) { + if t == nil { + return nil + } + + switch tx := t.(type) { + case *pt.Transfer: + res = map[string]interface{}{ + "nonce": tx.Nonce, + "sender": tx.Sender.String(), + "receiver": tx.Receiver.String(), + "amount": tx.Amount, + } + case *pt.Billing: + res = a.formatTxBilling(tx) + case *pt.BaseAccount: + res = map[string]interface{}{ + "next_nonce": tx.NextNonce, + "address": tx.Address, + "stable_balance": tx.StableCoinBalance, + "covenant_balance": tx.CovenantCoinBalance, + "rating": tx.Rating, + } + case *pi.TransactionWrapper: + res = a.formatRawTx(tx.Unwrap()) + default: + // for unknown transactions + if txBytes, err := json.Marshal(tx); err != nil { + res = map[string]interface{}{ + "error": err.Error(), + } + } else if err = json.Unmarshal(txBytes, &res); err != nil { + res = map[string]interface{}{ + "error": err.Error(), + } + } + } + + return +} + +func (a *explorerAPI) formatTxBilling(tx *pt.Billing) (res map[string]interface{}) { + if tx == nil { + return + } + + return map[string]interface{}{ + "nonce": tx.Nonce, + "producer": tx.Producer.String(), + "billing_request": func(br pt.BillingRequest) map[string]interface{} { + return map[string]interface{}{ + "database_id": br.Header.DatabaseID, + "low_block": br.Header.LowBlock.String(), + "low_height": br.Header.LowHeight, + "high_block": br.Header.HighBlock.String(), + "high_height": br.Header.HighHeight, + "gas_amounts": func(gasAmounts []*proto.AddrAndGas) (d []map[string]interface{}) { + for _, g := range gasAmounts { + d = append(d, map[string]interface{}{ + "address": g.AccountAddress.String(), + "node": g.RawNodeID.String(), + "amount": g.GasAmount, + }) + } + return + }(br.Header.GasAmounts), + } + }(tx.BillingRequest), + "receivers": func(receivers []*proto.AccountAddress) (s []string) { + for _, r := range receivers { + s = append(s, r.String()) + } + return + }(tx.Receivers), + "fees": tx.Fees, + "rewards": tx.Rewards, + } +} + +func (a *explorerAPI) formatTx(count uint32, height uint32, tx pi.Transaction) map[string]interface{} { + var res map[string]interface{} + + if res = a.formatRawTx(tx); res != nil { + res["height"] = height + res["count"] = count + } + + return map[string]interface{}{ + "tx": res, + } +} + +func (a *explorerAPI) getHash(r *http.Request) (h *hash.Hash, err error) { + vars := mux.Vars(r) + hStr := vars["hash"] + return hash.NewHashFromStr(hStr) +} + +func startAPI(service *Service, listenAddr string) (server *http.Server, err error) { + router := mux.NewRouter() + router.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { + sendResponse(http.StatusOK, true, nil, nil, rw) + }).Methods("GET") + + api := &explorerAPI{ + service: service, + } + v1Router := router.PathPrefix("/v1").Subrouter() + v1Router.HandleFunc("/tx/{hash}", api.GetTxByHash).Methods("GET") + v1Router.HandleFunc("/height/{height:[0-9]+}", api.GetBlockByHeight).Methods("GET") + v1Router.HandleFunc("/block/{hash}", api.GetBlockByHash).Methods("GET") + v1Router.HandleFunc("/count/{count:[0-9]+}", api.GetBlockByCount).Methods("GET") + v1Router.HandleFunc("/head", api.GetHighestBlock).Methods("GET") + + server = &http.Server{ + Addr: listenAddr, + WriteTimeout: apiTimeout, + ReadTimeout: apiTimeout, + IdleTimeout: apiTimeout, + Handler: router, + } + + go func() { + if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("start api server failed: %v", err) + } + }() + + return server, err +} + +func stopAPI(server *http.Server) (err error) { + return server.Shutdown(context.Background()) +} diff --git a/cmd/cql-explorer/errors.go b/cmd/cql-explorer/errors.go new file mode 100644 index 000000000..30fef19de --- /dev/null +++ b/cmd/cql-explorer/errors.go @@ -0,0 +1,34 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import "github.com/pkg/errors" + +var ( + // ErrNilBlock represents nil block received. + ErrNilBlock = errors.New("nil block received") + // ErrNilTransactions represents nil transaction received. + ErrNilTransactions = errors.New("nil transactions received") + // ErrNilTransaction represents nil transaction received. + ErrNilTransaction = errors.New("nil transaction received") + // ErrStopped defines error on explorer service has already stopped + ErrStopped = errors.New("explorer service has stopped") + // ErrNotFound defines error on failed to found specified resource + ErrNotFound = errors.New("resource not found") + // ErrBadRequest defines errors on error input field. + ErrBadRequest = errors.New("request field not fulfilled") +) diff --git a/cmd/cql-explorer/main.go b/cmd/cql-explorer/main.go index 4e37f4699..4760aa00d 100644 --- a/cmd/cql-explorer/main.go +++ b/cmd/cql-explorer/main.go @@ -18,7 +18,15 @@ package main import ( "flag" + "math/rand" + "net/http" + "os" + "os/signal" + "syscall" "time" + + "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/utils/log" ) var ( @@ -30,6 +38,7 @@ var ( var ( // config configFile string + password string listenAddr string checkInterval time.Duration ) @@ -38,8 +47,66 @@ func init() { flag.StringVar(&configFile, "config", "./config.yaml", "config file path") flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api") flag.DurationVar(&checkInterval, "interval", time.Second*2, "new block check interval for explorer") + flag.StringVar(&password, "password", "", "") } func main() { + // set random + rand.Seed(time.Now().UnixNano()) + log.SetLevel(log.DebugLevel) + flag.Parse() + flag.Visit(func(f *flag.Flag) { + log.Infof("Args %s : %v", f.Name, f.Value) + }) + + // init client + var err error + if err = client.Init(configFile, []byte(password)); err != nil { + log.Fatalf("init node failed: %v", err) + return + } + + // start service + var service *Service + if service, err = NewService(checkInterval); err != nil { + log.Fatalf("init service failed: %v", err) + return + } + + // start api + var httpServer *http.Server + if httpServer, err = startAPI(service, listenAddr); err != nil { + log.Fatalf("start explorer api failed: %v", err) + return + } + + // start subscription + if err = service.start(); err != nil { + log.Fatalf("start service failed: %v", err) + return + } + + signalCh := make(chan os.Signal, 1) + signal.Notify( + signalCh, + syscall.SIGINT, + syscall.SIGTERM, + ) + signal.Ignore(syscall.SIGHUP, syscall.SIGTTIN, syscall.SIGTTOU) + + <-signalCh + + // stop explorer api + if err = stopAPI(httpServer); err != nil { + log.Fatalf("stop explorer api failed: %v", err) + return + } + + // stop subscription + if err = service.stop(); err != nil { + log.Fatalf("stop service failed: %v", err) + return + } + log.Info("explorer stopped") } diff --git a/cmd/cql-explorer/service.go b/cmd/cql-explorer/service.go new file mode 100644 index 000000000..1b133015f --- /dev/null +++ b/cmd/cql-explorer/service.go @@ -0,0 +1,462 @@ +/* + * Copyright 2018 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "bytes" + "encoding/binary" + "path/filepath" + "sync" + "sync/atomic" + "time" + + bp "github.com/CovenantSQL/CovenantSQL/blockproducer" + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" + pt "github.com/CovenantSQL/CovenantSQL/blockproducer/types" + "github.com/CovenantSQL/CovenantSQL/conf" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" + "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/route" + "github.com/CovenantSQL/CovenantSQL/rpc" + "github.com/CovenantSQL/CovenantSQL/utils" + "github.com/CovenantSQL/CovenantSQL/utils/log" + "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/util" +) + +const ( + dbFileName = "explorer.db" +) + +var ( + // storage keys + blockKeyPrefix = []byte("BLOCK_") + blockHashPrefix = []byte("HASH_") + blockHeightPrefix = []byte("HEIGHT_") + txKeyPrefix = []byte("TX_") +) + +// Service defines the main chain explorer service structure. +type Service struct { + db *leveldb.DB + + caller *rpc.Caller + stopped int32 + stopCh chan struct{} + triggerCh chan struct{} + wg sync.WaitGroup + + // new block check interval + checkInterval time.Duration + + // next block to fetch + nextBlockToFetch uint32 +} + +// NewService creates new explorer service handler. +func NewService(checkInterval time.Duration) (service *Service, err error) { + // open explorer database + dbFile := filepath.Join(conf.GConf.WorkingRoot, dbFileName) + db, err := leveldb.OpenFile(dbFile, nil) + if err != nil { + return + } + + defer func() { + if err != nil { + db.Close() + } + }() + + // init service + service = &Service{ + db: db, + caller: rpc.NewCaller(), + stopCh: make(chan struct{}), + triggerCh: make(chan struct{}, 1), + checkInterval: checkInterval, + } + + return +} + +func (s *Service) start() (err error) { + if atomic.LoadInt32(&s.stopped) == 1 { + // stopped + return ErrStopped + } + + if err = s.getSubscriptionCheckpoint(); err != nil { + return + } + + // start subscription worker + s.wg.Add(1) + go s.subscriptionWorker() + + return +} + +func (s *Service) getBlockByCount(c uint32) (b *pt.Block, count uint32, height uint32, err error) { + var bKey []byte + bKey = append(bKey, blockKeyPrefix...) + bKey = append(bKey, uint32ToBytes(c)...) + + it := s.db.NewIterator(util.BytesPrefix(bKey), nil) + if it.First() { + // decode + hBytes := it.Key()[len(bKey):] + height = bytesToUint32(hBytes) + count = c + err = utils.DecodeMsgPack(it.Value(), &b) + } else { + // not found + err = ErrNotFound + } + it.Release() + + if err != nil { + // ignore iterator error + it.Error() + return + } + + err = it.Error() + + return +} + +func (s *Service) getBlockByHash(h *hash.Hash) (b *pt.Block, count uint32, height uint32, err error) { + if h == nil { + err = ErrNotFound + return + } + + var bKey []byte + bKey = append(bKey, blockHashPrefix...) + bKey = append(bKey, h[:]...) + + var bCountData []byte + if bCountData, err = s.db.Get(bKey, nil); err != nil { + if err == leveldb.ErrNotFound { + err = ErrNotFound + } + return + } + + count = bytesToUint32(bCountData) + return s.getBlockByCount(count) +} + +func (s *Service) getBlockByHeight(h uint32) (b *pt.Block, count uint32, height uint32, err error) { + var bKey []byte + bKey = append(bKey, blockHeightPrefix...) + bKey = append(bKey, uint32ToBytes(h)...) + + var bCountData []byte + if bCountData, err = s.db.Get(bKey, nil); err != nil { + if err == leveldb.ErrNotFound { + err = ErrNotFound + } + return + } + + count = bytesToUint32(bCountData) + return s.getBlockByCount(count) +} + +func (s *Service) getTxByHash(h *hash.Hash) (tx pi.Transaction, c uint32, height uint32, err error) { + if h == nil { + err = ErrNotFound + return + } + + var txKey []byte + txKey = append(txKey, txKeyPrefix...) + txKey = append(txKey, h[:]...) + + var bCountData []byte + if bCountData, err = s.db.Get(txKeyPrefix, nil); err != nil { + if err == leveldb.ErrNotFound { + err = ErrNotFound + } + return + } + + c = bytesToUint32(bCountData) + + var b *pt.Block + if b, _, height, err = s.getBlockByCount(c); err != nil { + return + } + + if b == nil || b.Transactions == nil { + err = ErrNotFound + return + } + + for _, curTx := range b.Transactions { + if curTx == nil { + continue + } + + if curH := curTx.GetHash(); h.IsEqual(&curH) { + tx = curTx + break + } + } + + if tx == nil { + err = ErrNotFound + return + } + + return +} + +func (s *Service) getHighestCount() (c uint32, err error) { + // load previous committed counts + it := s.db.NewIterator(util.BytesPrefix(blockKeyPrefix), nil) + if it.Last() { + // decode block count from key + blockKey := it.Key() + if len(blockKey)-len(blockKeyPrefix) == 4 { + // valid block + prefixLen := len(blockKeyPrefix) + c = bytesToUint32(blockKey[prefixLen:]) + } else { + err = ErrNotFound + } + } else { + err = ErrNotFound + } + it.Release() + + if err != nil { + it.Error() + return + } + + err = it.Error() + + return +} + +func (s *Service) getSubscriptionCheckpoint() (err error) { + var lastBlockCount uint32 + if lastBlockCount, err = s.getHighestCount(); err != nil { + log.Warningf("get last block failed: %v", err) + + if err == ErrNotFound { + // not found, set last block count to 0 + log.Info("set current block count fetch head to 0") + err = nil + atomic.StoreUint32(&s.nextBlockToFetch, 0) + } + + return + } + + log.WithFields(log.Fields{ + "count": lastBlockCount, + }).Infof("get last block count: %v", err) + + atomic.StoreUint32(&s.nextBlockToFetch, lastBlockCount+1) + + return +} + +func (s *Service) subscriptionWorker() { + defer s.wg.Done() + + log.Info("started subscription worker") + for { + select { + case <-s.stopCh: + log.Info("exited subscription worker") + return + case <-s.triggerCh: + case <-time.After(s.checkInterval): + } + + // request block producer for next block + s.requestBlock() + } +} + +func (s *Service) requestBlock() { + if atomic.LoadInt32(&s.stopped) == 1 { + return + } + + blockCount := atomic.LoadUint32(&s.nextBlockToFetch) + log.WithFields(log.Fields{"count": blockCount}).Infof("try fetch next block") + + req := &bp.FetchBlockByCountReq{Count: blockCount} + resp := &bp.FetchBlockResp{} + + if err := s.requestBP(route.MCCFetchBlockByCount.String(), req, resp); err != nil { + // fetch block failed + log.Warningf("fetch block failed, wait for next round: %v", err) + return + } + + // process block + s.processBlock(blockCount, resp.Height, resp.Block) + + atomic.AddUint32(&s.nextBlockToFetch, 1) + + // last fetch success, trigger next fetch for fast sync + select { + case s.triggerCh <- struct{}{}: + default: + } +} + +func (s *Service) processBlock(c uint32, h uint32, b *pt.Block) (err error) { + if b == nil { + log.Warningf("processed nil block on count: %v", c) + return ErrNilBlock + } + + log.WithFields(log.Fields{ + "hash": b.BlockHash(), + "parent": b.ParentHash(), + "height": h, + "count": c, + }).Info("process new block") + + if err = s.saveTransactions(c, b.Transactions); err != nil { + return + } + + err = s.saveBlock(c, h, b) + + return +} + +func (s *Service) saveTransactions(c uint32, txs []pi.Transaction) (err error) { + if txs == nil { + log.Warning("nil transactions received") + return ErrNilTransactions + } + + for _, t := range txs { + if err = s.saveTransaction(c, t); err != nil { + return + } + } + + return +} + +func (s *Service) saveTransaction(c uint32, tx pi.Transaction) (err error) { + if tx == nil { + return ErrNilTransaction + } + + txHash := tx.GetHash() + + var txKey []byte + + txKey = append(txKey, txKeyPrefix...) + txKey = append(txKey, txHash[:]...) + txData := uint32ToBytes(c) + + err = s.db.Put(txKey, txData, nil) + + return +} + +func (s *Service) saveBlock(c uint32, h uint32, b *pt.Block) (err error) { + if b == nil { + return ErrNilBlock + } + + bHash := b.BlockHash() + + var buf *bytes.Buffer + + if buf, err = utils.EncodeMsgPack(b); err != nil { + return + } + + cBytes := uint32ToBytes(c) + hBytes := uint32ToBytes(h) + + var bKey, bHashKey, bHeightKey []byte + + bKey = append(bKey, blockKeyPrefix...) + bKey = append(bKey, cBytes...) + bKey = append(bKey, hBytes...) + + bHashKey = append(bHashKey, blockHashPrefix...) + bHashKey = append(bHashKey, bHash[:]...) + + bHeightKey = append(bHeightKey, blockHeightPrefix...) + bHeightKey = append(bHeightKey, hBytes...) + + if err = s.db.Put(bKey, buf.Bytes(), nil); err != nil { + return + } + + if err = s.db.Put(bHashKey, cBytes, nil); err != nil { + return + } + + err = s.db.Put(bHeightKey, cBytes, nil) + + return +} + +func (s *Service) requestBP(method string, request interface{}, response interface{}) (err error) { + var bpNodeID proto.NodeID + if bpNodeID, err = rpc.GetCurrentBP(); err != nil { + return + } + return s.caller.CallNode(bpNodeID, method, request, response) +} + +func (s *Service) stop() (err error) { + if !atomic.CompareAndSwapInt32(&s.stopped, 0, 1) { + // stopped + return ErrStopped + } + + log.Info("stop subscription") + + select { + case <-s.stopCh: + default: + close(s.stopCh) + } + + s.wg.Wait() + s.db.Close() + + return +} + +func uint32ToBytes(h uint32) (data []byte) { + data = make([]byte, 4) + binary.BigEndian.PutUint32(data, h) + return +} + +func bytesToUint32(data []byte) uint32 { + return binary.BigEndian.Uint32(data) +} diff --git a/route/acl.go b/route/acl.go index c1f054239..0504ab1f1 100644 --- a/route/acl.go +++ b/route/acl.go @@ -121,6 +121,8 @@ const ( MCCAdviseBillingRequest // MCCFetchBlock is used by nodes to fetch block from block producer MCCFetchBlock + // MCCFetchBlockByCount is used by nodes to fetch block from block producer by block count since genesis + MCCFetchBlockByCount // MCCFetchTxBilling is used by nodes to fetch billing transaction from block producer MCCFetchTxBilling // MCCNextAccountNonce is used by block producer main chain to allocate next nonce for transactions @@ -209,6 +211,8 @@ func (s RemoteFunc) String() string { return "MCC.AdviseBillingRequest" case MCCFetchBlock: return "MCC.FetchBlock" + case MCCFetchBlockByCount: + return "MCC.FetchBlockByCount" case MCCFetchTxBilling: return "MCC.FetchTxBilling" case MCCNextAccountNonce: From c5c62d9ae4a68c235d1dcf48db643da8bd0ee0b9 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 23 Oct 2018 15:06:51 +0800 Subject: [PATCH 37/38] Fix nil transactions bug in explorer --- cmd/cql-explorer/api.go | 2 +- cmd/cql-explorer/errors.go | 2 -- cmd/cql-explorer/service.go | 26 ++++++++++++-------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cmd/cql-explorer/api.go b/cmd/cql-explorer/api.go index 767c8075f..928536f08 100644 --- a/cmd/cql-explorer/api.go +++ b/cmd/cql-explorer/api.go @@ -182,7 +182,7 @@ func (a *explorerAPI) formatBlock(count uint32, height uint32, b *pt.Block) map[ "parent": b.ParentHash().String(), "timestamp": a.formatTime(b.Timestamp()), "version": b.SignedHeader.Version, - "producer": b.Producer(), + "producer": b.SignedHeader.Producer.String(), "txs": txs, }, } diff --git a/cmd/cql-explorer/errors.go b/cmd/cql-explorer/errors.go index 30fef19de..22937dac8 100644 --- a/cmd/cql-explorer/errors.go +++ b/cmd/cql-explorer/errors.go @@ -21,8 +21,6 @@ import "github.com/pkg/errors" var ( // ErrNilBlock represents nil block received. ErrNilBlock = errors.New("nil block received") - // ErrNilTransactions represents nil transaction received. - ErrNilTransactions = errors.New("nil transactions received") // ErrNilTransaction represents nil transaction received. ErrNilTransaction = errors.New("nil transaction received") // ErrStopped defines error on explorer service has already stopped diff --git a/cmd/cql-explorer/service.go b/cmd/cql-explorer/service.go index 1b133015f..74c269264 100644 --- a/cmd/cql-explorer/service.go +++ b/cmd/cql-explorer/service.go @@ -119,7 +119,8 @@ func (s *Service) getBlockByCount(c uint32) (b *pt.Block, count uint32, height u it := s.db.NewIterator(util.BytesPrefix(bKey), nil) if it.First() { // decode - hBytes := it.Key()[len(bKey):] + bKeyLen := len(bKey) + hBytes := it.Key()[bKeyLen : bKeyLen+4] height = bytesToUint32(hBytes) count = c err = utils.DecodeMsgPack(it.Value(), &b) @@ -234,13 +235,8 @@ func (s *Service) getHighestCount() (c uint32, err error) { if it.Last() { // decode block count from key blockKey := it.Key() - if len(blockKey)-len(blockKeyPrefix) == 4 { - // valid block - prefixLen := len(blockKeyPrefix) - c = bytesToUint32(blockKey[prefixLen:]) - } else { - err = ErrNotFound - } + prefixLen := len(blockKeyPrefix) + c = bytesToUint32(blockKey[prefixLen : prefixLen+4]) } else { err = ErrNotFound } @@ -273,7 +269,7 @@ func (s *Service) getSubscriptionCheckpoint() (err error) { log.WithFields(log.Fields{ "count": lastBlockCount, - }).Infof("get last block count: %v", err) + }).Infof("fetched last block count") atomic.StoreUint32(&s.nextBlockToFetch, lastBlockCount+1) @@ -311,12 +307,15 @@ func (s *Service) requestBlock() { if err := s.requestBP(route.MCCFetchBlockByCount.String(), req, resp); err != nil { // fetch block failed - log.Warningf("fetch block failed, wait for next round: %v", err) + log.Warningf("fetch block failed,wait for next round: %v", err) return } // process block - s.processBlock(blockCount, resp.Height, resp.Block) + if err := s.processBlock(blockCount, resp.Height, resp.Block); err != nil { + log.Warningf("process block failed, try fetch/process again: %v", err) + return + } atomic.AddUint32(&s.nextBlockToFetch, 1) @@ -350,9 +349,8 @@ func (s *Service) processBlock(c uint32, h uint32, b *pt.Block) (err error) { } func (s *Service) saveTransactions(c uint32, txs []pi.Transaction) (err error) { - if txs == nil { - log.Warning("nil transactions received") - return ErrNilTransactions + if txs == nil || len(txs) == 0 { + return } for _, t := range txs { From 43d9acf031847fecff4140ec0b77554acf8957d6 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Tue, 23 Oct 2018 15:26:05 +0800 Subject: [PATCH 38/38] Add explorer README and transaction type pretty formatting --- bin/docker-entry.sh | 3 + blockproducer/interfaces/transaction.go | 25 ++++ cmd/cql-explorer/README.md | 182 ++++++++++++++++++++++++ cmd/cql-explorer/api.go | 3 + cmd/cql-explorer/main.go | 2 +- 5 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 cmd/cql-explorer/README.md diff --git a/bin/docker-entry.sh b/bin/docker-entry.sh index 8726f5b77..fd5348d4a 100755 --- a/bin/docker-entry.sh +++ b/bin/docker-entry.sh @@ -24,5 +24,8 @@ cli) faucet) exec /app/cql-faucet -config ${COVENANT_CONF} "${@}" ;; +explorer) + exec /app/cql-explorer -config ${COVENANT_CONF} "${@}" + ;; esac diff --git a/blockproducer/interfaces/transaction.go b/blockproducer/interfaces/transaction.go index 7aec5aabd..f4916ac80 100644 --- a/blockproducer/interfaces/transaction.go +++ b/blockproducer/interfaces/transaction.go @@ -67,6 +67,31 @@ const ( TransactionTypeNumber ) +func (t TransactionType) String() string { + switch t { + case TransactionTypeBilling: + return "Billing" + case TransactionTypeTransfer: + return "Transfer" + case TransactionTypeCreateAccount: + return "CreateAccount" + case TransactionTypeDeleteAccount: + return "DeleteAccount" + case TransactionTypeAddDatabaseUser: + return "AddDatabaseUser" + case TransactionTypeAlterDatabaseUser: + return "AlterDatabaseUser" + case TransactionTypeDeleteDatabaseUser: + return "DeleteDatabaseUser" + case TransactionTypeBaseAccount: + return "BaseAccount" + case TransactionTypeCreateDatabase: + return "CreateDatabase" + default: + return "Unknown" + } +} + // Transaction is the interface implemented by an object that can be verified and processed by // block producers. type Transaction interface { diff --git a/cmd/cql-explorer/README.md b/cmd/cql-explorer/README.md new file mode 100644 index 000000000..6bce4872e --- /dev/null +++ b/cmd/cql-explorer/README.md @@ -0,0 +1,182 @@ +This doc introduce the usage of CovenantSQL block producer chain explorer server. + +## Prerequisites + +Make sure the ```$GOPATH/bin``` is in your ```$PATH```, download/build the explorer binary. + +```shell +$ go get github.com/CovenantSQL/CovenantSQL/cmd/cql-explorer +``` + +Adapter requires a CovenantSQL ```config.yaml``` which can by generated by configuration generator. + +### Generating Default Config File + +Generate the main configuration file. Same as [Generating Default Config File in Golang Client Doc](https://github.com/CovenantSQL/CovenantSQL/tree/develop/client#generating-default-config-file). An existing configuration file can also be used. + +## Explorer Usage + +### Start + +Start the explorer by following commands: + +```shell +$ cql-explorer -config config.yaml +``` + +The available options are: + +```shell +$ cql-explorer --help +Usage of cql-explorer: + -config string + config file path (default "./config.yaml") + -interval duration + new block check interval for explorer (default 2s) + -listen string + listen address for http explorer api (default "127.0.0.1:4665") + -password string + master key password for covenantsql +``` + +### API + +#### Query Synced Head Block + +**GET** /v1/head + +##### Request + +##### Response + +```json +{ + "success" : true, + "status" : "ok", + "data" : { + "block" : { + "txs" : [], + "hash" : "20ba21af54da3e17252fb4b6b7331fb6f36aca1b9b793597af6ef46faad34dea", + "timestamp" : 1540278575120.34, + "version" : 1, + "count" : 561, + "producer" : "8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549", + "height" : 3040488, + "parent" : "f9c4f9c7a1dcbcf14a13eb91a007b33672f1f8a261738f5a25fee27c3ccaa584" + } + } +} +``` + +#### Query Block by _COUNT_ + +**GET** /v1/count/{count} + +##### Request + +__count__: count of specified block, 0 for genesis block + +##### Response + +```json +{ + "success" : true, + "status" : "ok", + "data" : { + "block" : { + "version" : 1, + "height" : 0, + "count" : 0, + "timestamp" : 1534197599120, + "hash" : "f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154", + "txs" : [], + "parent" : "0000000000000000000000000000000000000000000000000000000000000001", + "producer" : "0000000000000000000000000000000000000000000000000000000000000001" + } + } +} +``` + +#### Query Block by _HASH_ + +**GET** /v1/block/{hash} + +##### Request + +__hash__: hash of specified block + +##### Response + +```json +{ + "success" : true, + "status" : "ok", + "data" : { + "block" : { + "version" : 1, + "height" : 0, + "count" : 0, + "timestamp" : 1534197599120, + "hash" : "f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154", + "txs" : [], + "parent" : "0000000000000000000000000000000000000000000000000000000000000001", + "producer" : "0000000000000000000000000000000000000000000000000000000000000001" + } + } +} +``` + +#### Query Block by _HEIGHT_ + +**GET** /v1/height/{height} + +##### Request + +__height__: height of specified block, 0 for genesis block (height is related to block produce time and interval) + +##### Response + +```json +{ + "success" : true, + "status" : "ok", + "data" : { + "block" : { + "version" : 1, + "height" : 0, + "count" : 0, + "timestamp" : 1534197599120, + "hash" : "f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154", + "txs" : [], + "parent" : "0000000000000000000000000000000000000000000000000000000000000001", + "producer" : "0000000000000000000000000000000000000000000000000000000000000001" + } + } +} +``` + +#### Query Transaction by _HASH_ + +**GET** /v1/tx/{hash} + +##### Request + +__hash__: hash of specified tx + +##### Response + +```json +{ + "success": true, + "status": "ok", + "data": { + "tx": { + "nonce": 11616, + "amount": 1225, + "sender": "00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9", + "receiver": "676b12fef8732ac78a97ea5dba0977bbbabc48f64eee66f09be89a589297e567", + "type": "Transfer" + } + } +} +``` \ No newline at end of file diff --git a/cmd/cql-explorer/api.go b/cmd/cql-explorer/api.go index 928536f08..8ac3f61a1 100644 --- a/cmd/cql-explorer/api.go +++ b/cmd/cql-explorer/api.go @@ -213,6 +213,7 @@ func (a *explorerAPI) formatRawTx(t pi.Transaction) (res map[string]interface{}) } case *pi.TransactionWrapper: res = a.formatRawTx(tx.Unwrap()) + return default: // for unknown transactions if txBytes, err := json.Marshal(tx); err != nil { @@ -226,6 +227,8 @@ func (a *explorerAPI) formatRawTx(t pi.Transaction) (res map[string]interface{}) } } + res["type"] = t.GetTransactionType().String() + return } diff --git a/cmd/cql-explorer/main.go b/cmd/cql-explorer/main.go index 4760aa00d..a20610812 100644 --- a/cmd/cql-explorer/main.go +++ b/cmd/cql-explorer/main.go @@ -47,7 +47,7 @@ func init() { flag.StringVar(&configFile, "config", "./config.yaml", "config file path") flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api") flag.DurationVar(&checkInterval, "interval", time.Second*2, "new block check interval for explorer") - flag.StringVar(&password, "password", "", "") + flag.StringVar(&password, "password", "", "master key password for covenantsql") } func main() {