From 53e8c945a14588cbedac1117f6fea4a7883ec611 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Tue, 11 Jul 2023 08:37:44 -0700 Subject: [PATCH 01/28] Initial --- cmd/algons/dnsCmd.go | 79 ++++++++++++++++++++++++++++++++++++-------- go.mod | 8 +++++ go.sum | 17 ++++++++++ protocol/hash.go | 1 + 4 files changed, 92 insertions(+), 13 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index 10b4c18881..cf134752b2 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -20,12 +20,14 @@ import ( "bufio" "context" "fmt" + "github.com/multiformats/go-multiaddr" "net" "os" "regexp" "sort" "strings" + madns "github.com/multiformats/go-multiaddr-dns" "github.com/spf13/cobra" "github.com/algorand/go-algorand/tools/network" @@ -43,6 +45,7 @@ var ( includePattern string exportNetwork string outputFilename string + keyName string ) func init() { @@ -59,6 +62,7 @@ func init() { addCmd.MarkFlagRequired("from") addCmd.Flags().StringVarP(&addToAddress, "to", "t", "", "To address to map new DNS entry to") addCmd.MarkFlagRequired("to") + addCmd.Flags().StringVarP(&recordType, "recordType", "r", "", "DNS record type add (A, CNAME, SRV)") deleteCmd.Flags().StringVarP(&deleteNetwork, "network", "n", "", "Network name for records to delete") deleteCmd.Flags().BoolVarP(&noPrompt, "no-prompt", "y", false, "No prompting for records deletion") @@ -72,6 +76,9 @@ func init() { exportCmd.Flags().StringVarP(&exportNetwork, "network", "n", "", "Domain name to export") exportCmd.MarkFlagRequired("network") exportCmd.Flags().StringVarP(&outputFilename, "zonefile", "z", "", "Output file for backup ( intead of outputing it to stdout ) ") + + checkCmd.Flags().StringVarP(&recordType, "recordType", "t", "", "DNS record type to check value of") + checkCmd.Flags().StringVarP(&keyName, "key", "k", "", "DNS record key to check") } type byIP []net.IP @@ -101,11 +108,11 @@ var listCmd = &cobra.Command{ var listRecordsCmd = &cobra.Command{ Use: "records", - Short: "List the A/SRV entries of the given network", - Long: "List the A/SRV entries of the given network", + Short: "List the A/SRV/TXT entries of the given network", + Long: "List the A/SRV/TXT entries of the given network", Run: func(cmd *cobra.Command, args []string) { recordType = strings.ToUpper(recordType) - if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" { + if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" || recordType == "TXT" { listEntries(listNetwork, recordType) } else { fmt.Fprintf(os.Stderr, "Invalid recordType specified.\n") @@ -130,6 +137,22 @@ var checkCmd = &cobra.Command{ Short: "Check the status", Long: "Check the status", Run: func(cmd *cobra.Command, args []string) { + if (keyName != "" && recordType == "") || (keyName == "" && recordType != "") { + fmt.Printf("You must supply both or none of --key and --recordType") + } + if keyName != "" && recordType != "" { + switch recordType { + case "SRV": + checkSrvRecord(keyName) + case "CNAME": + checkDNSRecord(keyName) + case "DNSADDR": + checkDnsaddrRecord(keyName) + default: + fmt.Printf("Unrecognized check for dns record type %s\n", recordType) + } + return + } checkDNSRecord("relay-us-ea-1.algorand.network") checkDNSRecord("relay-us-ea-2.algorand.network") checkDNSRecord("relay-us-ea-3.algorand.network") @@ -141,17 +164,22 @@ var checkCmd = &cobra.Command{ checkSrvRecord("testnet.algorand.network") checkSrvRecord("bogus.algorand.network") fmt.Printf("------------------------\n") + + fmt.Printf("------------------------\n") + checkDnsaddrRecord("devnet.algorand.network") + fmt.Printf("------------------------\n") }, } var addCmd = &cobra.Command{ Use: "add", Short: "Add a DNS record", - Long: "Adds a DNS record to map --from to --to, using A if to == IP or CNAME otherwise\n", + Long: "Adds a DNS record to map --from to --to, using A if to == IP or CNAME otherwise\nYou can also set the desired type with -r\n", Example: "algons dns add -f a.test.algodev.network -t r1.algodev.network\n" + - "algons dns add -f a.test.algodev.network -t 192.168.100.10", + "algons dns add -f a.test.algodev.network -t 192.168.100.10\n" + + "algons dns add -r TXT -f _dnsaddr.a.test.algodev.network -t \"dnsaddr=/ip4/192.168.100.10/tcp/4001/ws\"", Run: func(cmd *cobra.Command, args []string) { - err := doAddDNS(addFromName, addToAddress) + err := doAddDNS(addFromName, addToAddress, recordType) if err != nil { fmt.Fprintf(os.Stderr, "Error adding DNS entry: %v\n", err) os.Exit(1) @@ -181,7 +209,7 @@ var exportCmd = &cobra.Command{ }, } -func doAddDNS(from string, to string) (err error) { +func doAddDNS(from string, to string, recordType string) (err error) { cfZoneID, cfToken, err := getClouldflareCredentials() if err != nil { return fmt.Errorf("error getting DNS credentials: %v", err) @@ -196,11 +224,13 @@ func doAddDNS(from string, to string) (err error) { // to map our network DNS name to our public name (or IP) provided to nodecfg // Network HostName = eg r1.testnet.algorand.network isIP := net.ParseIP(to) != nil - var recordType string - if isIP { - recordType = "A" - } else { - recordType = "CNAME" + // Preserves backwards compatibility for tools using existing algons functionality + if recordType == "" { + if isIP { + recordType = "A" + } else { + recordType = "CNAME" + } } err = cloudflareDNS.SetDNSRecord(context.Background(), recordType, from, to, cloudflare.AutomaticTTL, priority, proxied) @@ -241,6 +271,29 @@ func checkDNSRecord(dnsName string) { } } +func checkDnsaddrRecord(name string) { + fmt.Printf("------------------------\nDnsaddr Lookup: %s\n", name) + + resolver, err := madns.NewResolver(madns.WithDefaultResolver(net.DefaultResolver)) + if err != nil { + fmt.Printf("Unable to construct multiaddr dns resolver: %v\n", err) + return + } + dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", name)) + if err != nil { + fmt.Printf("Unable to construct multiaddr for %s : %v\n", name, err) + return + } + maddrs, err := resolver.Resolve(context.Background(), dnsaddr) + if err != nil { + fmt.Printf("Unable to resolve dnsaddr: %s\n", err) + } + for _, maddr := range maddrs { + fmt.Printf("%s\n", maddr.String()) + } + +} + func checkSrvRecord(dnsBootstrap string) { fmt.Printf("------------------------\nSRV Lookup: %s\n", dnsBootstrap) @@ -425,7 +478,7 @@ func listEntries(listNetwork string, recordType string) { } cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) - recordTypes := []string{"A", "CNAME", "SRV"} + recordTypes := []string{"A", "CNAME", "SRV", "TXT"} if recordType != "" { recordTypes = []string{recordType} } diff --git a/go.mod b/go.mod index a69db49ce5..e42d8db079 100644 --- a/go.mod +++ b/go.mod @@ -58,13 +58,21 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect + github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect + github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/mr-tron/base58 v1.1.2 // indirect + github.com/multiformats/go-multiaddr v0.2.0 // indirect + github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect + github.com/multiformats/go-multihash v0.0.8 // indirect + github.com/multiformats/go-varint v0.0.1 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect diff --git a/go.sum b/go.sum index 4e2d9d22ca..d9984e6743 100644 --- a/go.sum +++ b/go.sum @@ -349,6 +349,10 @@ github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= @@ -365,6 +369,16 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= +github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-multiaddr v0.2.0 h1:lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90= +github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= +github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= +github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= +github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= +github.com/multiformats/go-varint v0.0.1 h1:TR/0rdQtnNxuN2IhiB639xC3tWM4IUi7DkTBVTdGW/M= +github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -408,6 +422,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -464,6 +480,7 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/protocol/hash.go b/protocol/hash.go index 434deaf8c3..ef31923db1 100644 --- a/protocol/hash.go +++ b/protocol/hash.go @@ -43,6 +43,7 @@ const ( BlockHeader HashID = "BH" BalanceRecord HashID = "BR" Credential HashID = "CR" + DNSAddrNode HashID = "DNSADDR" Genesis HashID = "GE" KeysInMSS HashID = "KP" MerkleArrayNode HashID = "MA" From f2363a410bdc3c4f1551029cf981340d4b55d99b Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 13:51:41 -0700 Subject: [PATCH 02/28] Initial dnsaddr commit --- go.mod | 21 +++- go.sum | 37 +++++- network/p2p/dnsaddr/resolve.go | 61 ++++++++++ network/p2p/dnsaddr/resolveController.go | 56 +++++++++ network/p2p/dnsaddr/resolveController_test.go | 44 +++++++ network/p2p/dnsaddr/resolve_test.go | 111 ++++++++++++++++++ tools/block-generator/go.mod | 14 ++- tools/block-generator/go.sum | 38 +++++- tools/network/resolveController.go | 22 ++++ 9 files changed, 389 insertions(+), 15 deletions(-) create mode 100644 network/p2p/dnsaddr/resolve.go create mode 100644 network/p2p/dnsaddr/resolveController.go create mode 100644 network/p2p/dnsaddr/resolveController_test.go create mode 100644 network/p2p/dnsaddr/resolve_test.go diff --git a/go.mod b/go.mod index e42d8db079..0cba989743 100644 --- a/go.mod +++ b/go.mod @@ -29,12 +29,14 @@ require ( github.com/labstack/echo/v4 v4.9.1 github.com/mattn/go-sqlite3 v1.10.0 github.com/miekg/dns v1.1.41 + github.com/multiformats/go-multiaddr v0.10.1 + github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/olivere/elastic v6.2.14+incompatible github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.3.0 github.com/stretchr/testify v1.8.1 golang.org/x/crypto v0.1.0 - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df golang.org/x/sys v0.7.0 golang.org/x/text v0.9.0 gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 @@ -44,14 +46,17 @@ require ( require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/daixiang0/gci v0.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fortytw2/leaktest v1.3.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/swag v0.19.5 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/google/uuid v1.3.0 // indirect + github.com/hexops/gotextdiff v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/invopop/yaml v0.1.0 // indirect + github.com/ipfs/go-cid v0.0.7 // indirect github.com/jmespath/go-jmespath v0.3.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/labstack/gommon v0.4.0 // indirect @@ -62,11 +67,12 @@ require ( github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect - github.com/mr-tron/base58 v1.1.2 // indirect - github.com/multiformats/go-multiaddr v0.2.0 // indirect - github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect - github.com/multiformats/go-multihash v0.0.8 // indirect - github.com/multiformats/go-varint v0.0.1 // indirect + github.com/mr-tron/base58 v1.1.3 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/multiformats/go-multibase v0.0.3 // indirect + github.com/multiformats/go-multihash v0.0.14 // indirect + github.com/multiformats/go-varint v0.0.6 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -75,12 +81,15 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect + github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/term v0.7.0 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect + golang.org/x/tools v0.6.0 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index d9984e6743..c5389df8c2 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,8 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/daixiang0/gci v0.3.2 h1:MDBsgEJGSJ++/N6Je/b2yK5x5WqmKYlzmILLVP41nl8= +github.com/daixiang0/gci v0.3.2/go.mod h1:jaASoJmv/ykO9dAAPy31iJnreV19248qKDdVWf3QgC4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -281,6 +283,8 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -288,6 +292,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= +github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY= +github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= @@ -369,16 +375,29 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-multiaddr v0.2.0 h1:lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90= +github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc= +github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= +github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= +github.com/multiformats/go-multiaddr v0.10.1/go.mod h1:jLEZsA61rwWNZQTHHnqq2HNa+4os/Hz54eqiRnsRqYQ= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= -github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= +github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk= +github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-varint v0.0.1 h1:TR/0rdQtnNxuN2IhiB639xC3tWM4IUi7DkTBVTdGW/M= +github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= +github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I= +github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= +github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= +github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY= +github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -450,6 +469,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 h1:OXcKh35JaYsGMRzpvFkLv/MEyPuL49CThT1pZ8aSml4= +github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -499,8 +520,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -528,6 +549,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -745,6 +768,8 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go new file mode 100644 index 0000000000..c60c0e38b9 --- /dev/null +++ b/network/p2p/dnsaddr/resolve.go @@ -0,0 +1,61 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package dnsaddr + +import ( + "context" + "errors" + "fmt" + + "github.com/multiformats/go-multiaddr" +) + +func isDnsaddr(maddr multiaddr.Multiaddr) bool { + first, _ := multiaddr.SplitFirst(maddr) + return first.Protocol().Code == multiaddr.P_DNSADDR +} + +func MultiaddrsFromResolver(domain string, controller *DnsaddrResolveController) ([]multiaddr.Multiaddr, error) { + resolver := controller.Resolver() + if resolver == nil { + return nil, errors.New("passed controller has no resolvers MultiaddrsFromResolver") + } + dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", domain)) + if err != nil { + return nil, fmt.Errorf("Unable to construct multiaddr for %s : %v\n", domain, err) + } + var resolved []multiaddr.Multiaddr + var toResolve = []multiaddr.Multiaddr{dnsaddr} + for resolver != nil && len(toResolve) > 0 { + curr := toResolve[0] + maddrs, resolveErr := resolver.Resolve(context.Background(), curr) + if resolveErr != nil { + err = resolveErr + resolver = controller.NextResolver() + continue + } + for _, maddr := range maddrs { + if isDnsaddr(maddr) { + toResolve = append(toResolve, maddr) + } else { + resolved = append(resolved, maddr) + } + } + toResolve = toResolve[1:] + } + return resolved, err +} diff --git a/network/p2p/dnsaddr/resolveController.go b/network/p2p/dnsaddr/resolveController.go new file mode 100644 index 0000000000..9e7673164d --- /dev/null +++ b/network/p2p/dnsaddr/resolveController.go @@ -0,0 +1,56 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package dnsaddr + +import ( + madns "github.com/multiformats/go-multiaddr-dns" + + "github.com/algorand/go-algorand/tools/network" +) + +type DnsaddrResolveController struct { + resolver *madns.Resolver + nextResolvers []func() *madns.Resolver + controller network.ResolveController +} + +func NewDnsaddrResolveController(controller network.ResolveController) *DnsaddrResolveController { + return &DnsaddrResolveController{ + resolver: nil, + nextResolvers: []func() *madns.Resolver{controller.SystemDnsaddrResolver, controller.FallbackDnsaddrResolver, controller.DefaultDnsaddrResolver}, + controller: controller, + } +} + +// NextResolver applies the nextResolvers functions in order and returns the most recent result +func (c *DnsaddrResolveController) NextResolver() *madns.Resolver { + if len(c.nextResolvers) == 0 { + c.resolver = nil + } else { + c.resolver = c.nextResolvers[0]() + c.nextResolvers = c.nextResolvers[1:] + } + return c.resolver +} + +// Resolver returns the current resolver, invokes NextResolver if the resolver is nil +func (c *DnsaddrResolveController) Resolver() *madns.Resolver { + if c.resolver == nil { + c.resolver = c.NextResolver() + } + return c.resolver +} diff --git a/network/p2p/dnsaddr/resolveController_test.go b/network/p2p/dnsaddr/resolveController_test.go new file mode 100644 index 0000000000..7658147d19 --- /dev/null +++ b/network/p2p/dnsaddr/resolveController_test.go @@ -0,0 +1,44 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package dnsaddr + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + log "github.com/algorand/go-algorand/logging" + "github.com/algorand/go-algorand/test/partitiontest" + "github.com/algorand/go-algorand/tools/network" +) + +func TestDnsAddrResolveController(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + controller := network.NewResolveController(true, "127.0.0.1", log.Base()) + dnsaddrCont := NewDnsaddrResolveController(controller) + + // Assert that the dnsaddr resolver cycles through the dns resolvers properly + assert.Equal(t, controller.SystemDnsaddrResolver(), dnsaddrCont.Resolver()) + assert.Equal(t, controller.FallbackDnsaddrResolver(), dnsaddrCont.NextResolver()) + assert.Equal(t, controller.DefaultDnsaddrResolver(), dnsaddrCont.NextResolver()) + // It should return nil once all the resolvers have been tried + assert.Nil(t, dnsaddrCont.NextResolver()) + assert.Nil(t, dnsaddrCont.NextResolver()) + +} diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go new file mode 100644 index 0000000000..9629ad14e6 --- /dev/null +++ b/network/p2p/dnsaddr/resolve_test.go @@ -0,0 +1,111 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package dnsaddr + +import ( + "context" + "fmt" + log "github.com/algorand/go-algorand/logging" + "github.com/algorand/go-algorand/test/partitiontest" + "github.com/algorand/go-algorand/tools/network" + "github.com/multiformats/go-multiaddr" + madns "github.com/multiformats/go-multiaddr-dns" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "net" + "testing" +) + +func TestIsDnsaddr(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + testcases := []struct { + name string + addr string + expected bool + }{ + {name: "DnsAddr", addr: "/dnsaddr/foobar.com", expected: true}, + {name: "DnsAddrWithPeerId", addr: "/dnsaddr/foobar.com/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", expected: true}, + {name: "DnsAddrWithIPPeerId", addr: "/dnsaddr/foobar.com/ip4/127.0.0.1/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", expected: true}, + {name: "Dns4Addr", addr: "/dns4/foobar.com/", expected: false}, + {name: "Dns6Addr", addr: "/dns6/foobar.com/", expected: false}, + {name: "Dns4AddrWithPeerId", addr: "/dns4/foobar.com/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", expected: false}, + } + for _, testcase := range testcases { + t.Run(testcase.name, func(t *testing.T) { + maddr, err := multiaddr.NewMultiaddr(testcase.addr) + require.NoError(t, err) + require.Equal(t, testcase.expected, isDnsaddr(maddr)) + }) + } +} + +func TestMultiaddrsFromResolver(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + controller := network.NewResolveController(false, "", log.Base()) + dnsaddrCont := NewDnsaddrResolveController(controller) + + // Fail on bad dnsaddr domain + maddrs, err := MultiaddrsFromResolver("/bogus/foobar", dnsaddrCont) + assert.Empty(t, maddrs) + assert.ErrorContains(t, err, fmt.Sprintf("Unable to construct multiaddr for %s", "/bogus/foobar")) + + // Success on a dnsaddr that needs to resolve recursively + maddrs, err = MultiaddrsFromResolver("bootstrap.libp2p.io", dnsaddrCont) + assert.NoError(t, err) + assert.NotEmpty(t, maddrs) + // bootstrap.libp2p.io's dnsaddr record contains 4 more dnsaddrs to resolve + assert.Greater(t, len(maddrs), 4) +} + +type failureResolver struct{} + +func (f *failureResolver) LookupIPAddr(context.Context, string) ([]net.IPAddr, error) { + return nil, fmt.Errorf("always errors") +} +func (f *failureResolver) LookupTXT(context.Context, string) ([]string, error) { + return nil, fmt.Errorf("always errors") +} + +func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + dnsaddrCont := &DnsaddrResolveController{ + resolver: nil, + nextResolvers: nil, + } + + // Fail on no resolver + maddrs, err := MultiaddrsFromResolver("", dnsaddrCont) + assert.Empty(t, maddrs) + assert.ErrorContains(t, err, fmt.Sprintf("passed controller has no resolvers MultiaddrsFromResolver")) + + resolver, _ := madns.NewResolver(madns.WithDefaultResolver(&failureResolver{})) + dnsaddrCont = &DnsaddrResolveController{ + resolver: resolver, + nextResolvers: nil, + controller: network.ResolveController{}, + } + // Fail on resolver error + maddrs, err = MultiaddrsFromResolver("bootstrap.libp2p.io", dnsaddrCont) + assert.Empty(t, maddrs) + assert.ErrorContains(t, err, "always errors") +} diff --git a/tools/block-generator/go.mod b/tools/block-generator/go.mod index 12649d09bc..94cc9e7a61 100644 --- a/tools/block-generator/go.mod +++ b/tools/block-generator/go.mod @@ -32,20 +32,32 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/ipfs/go-cid v0.0.7 // indirect github.com/jmespath/go-jmespath v0.3.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-sqlite3 v1.10.0 // indirect github.com/miekg/dns v1.1.41 // indirect + github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect + github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/mr-tron/base58 v1.1.3 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/multiformats/go-multiaddr v0.10.1 // indirect + github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect + github.com/multiformats/go-multibase v0.0.3 // indirect + github.com/multiformats/go-multihash v0.0.14 // indirect + github.com/multiformats/go-varint v0.0.6 // indirect github.com/olivere/elastic v6.2.14+incompatible // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/crypto v0.1.0 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/sys v0.7.0 // indirect gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 // indirect diff --git a/tools/block-generator/go.sum b/tools/block-generator/go.sum index 86dd5643dc..01543a3cdc 100644 --- a/tools/block-generator/go.sum +++ b/tools/block-generator/go.sum @@ -42,6 +42,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY= +github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -56,9 +58,36 @@ github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK86 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo= +github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc= +github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= +github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= +github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= +github.com/multiformats/go-multiaddr v0.10.1/go.mod h1:jLEZsA61rwWNZQTHHnqq2HNa+4os/Hz54eqiRnsRqYQ= +github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= +github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= +github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk= +github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= +github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= +github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= +github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I= +github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= +github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= +github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= +github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY= +github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/olivere/elastic v6.2.14+incompatible h1:k+KadwNP/dkXE0/eu+T6otk1+5fe0tEpPyQJ4XVm5i8= github.com/olivere/elastic v6.2.14+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8= @@ -71,6 +100,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -83,12 +114,14 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -99,6 +132,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/tools/network/resolveController.go b/tools/network/resolveController.go index a36914f21b..37e3fa8f39 100644 --- a/tools/network/resolveController.go +++ b/tools/network/resolveController.go @@ -20,6 +20,8 @@ import ( "net" "time" + madns "github.com/multiformats/go-multiaddr-dns" + "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/tools/network/dnssec" ) @@ -85,3 +87,23 @@ func (c *ResolveController) DefaultResolver() ResolverIf { } return &Resolver{} } + +func (c *ResolveController) SystemDnsaddrResolver() *madns.Resolver { + resolver := c.SystemResolver() + // ignore errors here since we madns.WithDefaultResolver can't error + mResv, _ := madns.NewResolver(madns.WithDefaultResolver(resolver)) + return mResv +} + +func (c *ResolveController) FallbackDnsaddrResolver() *madns.Resolver { + resolver := c.FallbackResolver() + // ignore errors here since we madns.WithDefaultResolver can't error + mResv, _ := madns.NewResolver(madns.WithDefaultResolver(resolver)) + return mResv +} + +func (c *ResolveController) DefaultDnsaddrResolver() *madns.Resolver { + resolver := c.DefaultResolver() + mResv, _ := madns.NewResolver(madns.WithDefaultResolver(resolver)) + return mResv +} From 55be21beb2b1407e3a30bbedcd03b518973fd5a7 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 22:38:51 -0700 Subject: [PATCH 03/28] Add dnsaddr cmd to algons --- cmd/algons/commands.go | 1 + cmd/algons/dnsaddrCmd.go | 67 +++++++++++++++++++++++++++++ network/p2p/dnsaddr/resolve_test.go | 12 +++--- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 cmd/algons/dnsaddrCmd.go diff --git a/cmd/algons/commands.go b/cmd/algons/commands.go index 15469dd2b5..3e010951dc 100644 --- a/cmd/algons/commands.go +++ b/cmd/algons/commands.go @@ -25,6 +25,7 @@ import ( func init() { rootCmd.AddCommand(dnsCmd) + rootCmd.AddCommand(dnsaddrCmd) } var rootCmd = &cobra.Command{ diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go new file mode 100644 index 0000000000..541a1628a2 --- /dev/null +++ b/cmd/algons/dnsaddrCmd.go @@ -0,0 +1,67 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package main + +import ( + "fmt" + + "github.com/spf13/cobra" + + log "github.com/algorand/go-algorand/logging" + "github.com/algorand/go-algorand/network/p2p/dnsaddr" + "github.com/algorand/go-algorand/tools/network" +) + +var ( + dnsaddrDomain string + secure bool +) + +func init() { + dnsaddrCmd.AddCommand(dnsaddrTreeCmd) + + dnsaddrTreeCmd.Flags().StringVarP(&dnsaddrDomain, "domain", "d", "", "Top level domain") + dnsaddrTreeCmd.MarkFlagRequired("domain") + dnsaddrTreeCmd.Flags().BoolVarP(&secure, "secure", "s", true, "Enable dnssec") +} + +var dnsaddrCmd = &cobra.Command{ + Use: "dnsaddr", + Short: "Get, Set, and List Dnsaddr entries", + Long: "Get, Set, and List Dnsaddr entries", + Run: func(cmd *cobra.Command, args []string) { + // Fall back + cmd.HelpFunc()(cmd, args) + }, +} + +var dnsaddrTreeCmd = &cobra.Command{ + Use: "tree", + Short: "Recursively resolves and lists the dnsaddr entries of the given domain", + Long: "Recursively resolves and lists the dnsaddr entries of the given domain", + Run: func(cmd *cobra.Command, args []string) { + controller := dnsaddr.NewDnsaddrResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) + addrs, err := dnsaddr.MultiaddrsFromResolver(dnsaddrDomain, controller) + if err != nil { + fmt.Printf("%s\n", err.Error()) + return + } + for _, addr := range addrs { + fmt.Printf("%s\n", addr.String()) + } + }, +} diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go index 9629ad14e6..6c848f422c 100644 --- a/network/p2p/dnsaddr/resolve_test.go +++ b/network/p2p/dnsaddr/resolve_test.go @@ -19,15 +19,17 @@ package dnsaddr import ( "context" "fmt" - log "github.com/algorand/go-algorand/logging" - "github.com/algorand/go-algorand/test/partitiontest" - "github.com/algorand/go-algorand/tools/network" + "net" + "testing" + "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "net" - "testing" + + log "github.com/algorand/go-algorand/logging" + "github.com/algorand/go-algorand/test/partitiontest" + "github.com/algorand/go-algorand/tools/network" ) func TestIsDnsaddr(t *testing.T) { From c8d99106033a26e2045ff88024a771de23c33af5 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 22:41:42 -0700 Subject: [PATCH 04/28] Update algons dns check for txt records --- cmd/algons/dnsCmd.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index cf134752b2..a8baf6ef0b 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -148,6 +148,8 @@ var checkCmd = &cobra.Command{ checkDNSRecord(keyName) case "DNSADDR": checkDnsaddrRecord(keyName) + case "TXT": + checkTxtRecord(keyName) default: fmt.Printf("Unrecognized check for dns record type %s\n", recordType) } @@ -219,6 +221,10 @@ func doAddDNS(from string, to string, recordType string) (err error) { const priority = 1 const proxied = false + if recordType == "TXT" { + err = cloudflareDNS.CreateDNSRecord(context.Background(), recordType, from, to, cloudflare.AutomaticTTL, priority, proxied) + return + } // If we need to register anything, first register a DNS entry // to map our network DNS name to our public name (or IP) provided to nodecfg @@ -294,6 +300,23 @@ func checkDnsaddrRecord(name string) { } +func checkTxtRecord(name string) { + fmt.Printf("------------------------\nTXT Lookup: %s\n", name) + + records, err := net.LookupTXT(name) + if err != nil { + if !strings.HasSuffix(err.Error(), "cannot unmarshal DNS message") { + // we weren't able to get the TXT records. + fmt.Printf("Cannot lookup TXT record for %s: %v\n", name, err) + return + } + + for _, record := range records { + fmt.Printf("%s\n", record) + } + } +} + func checkSrvRecord(dnsBootstrap string) { fmt.Printf("------------------------\nSRV Lookup: %s\n", dnsBootstrap) @@ -420,7 +443,7 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa networkSuffix = "." + network + ".algodev.network" } - for _, recordType := range []string{"A", "CNAME"} { + for _, recordType := range []string{"A", "CNAME", "TXT"} { records, err := cloudflareDNS.ListDNSRecord(context.Background(), recordType, "", "", "", "", "") if err != nil { fmt.Fprintf(os.Stderr, "Error listing DNS '%s' entries: %v\n", recordType, err) From c8b8f738ea08eb78235888659f73bdf50c02ac56 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 22:42:38 -0700 Subject: [PATCH 05/28] import order --- cmd/algons/dnsCmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index a8baf6ef0b..ba5e70e92c 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -20,13 +20,13 @@ import ( "bufio" "context" "fmt" - "github.com/multiformats/go-multiaddr" "net" "os" "regexp" "sort" "strings" + "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" "github.com/spf13/cobra" From fc461f7e1153b74bfd48394898abe9af6bad36fe Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 22:44:32 -0700 Subject: [PATCH 06/28] remove dns cmd changes --- cmd/algons/dnsCmd.go | 104 ++++++------------------------------------- 1 file changed, 14 insertions(+), 90 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index ba5e70e92c..10b4c18881 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -26,8 +26,6 @@ import ( "sort" "strings" - "github.com/multiformats/go-multiaddr" - madns "github.com/multiformats/go-multiaddr-dns" "github.com/spf13/cobra" "github.com/algorand/go-algorand/tools/network" @@ -45,7 +43,6 @@ var ( includePattern string exportNetwork string outputFilename string - keyName string ) func init() { @@ -62,7 +59,6 @@ func init() { addCmd.MarkFlagRequired("from") addCmd.Flags().StringVarP(&addToAddress, "to", "t", "", "To address to map new DNS entry to") addCmd.MarkFlagRequired("to") - addCmd.Flags().StringVarP(&recordType, "recordType", "r", "", "DNS record type add (A, CNAME, SRV)") deleteCmd.Flags().StringVarP(&deleteNetwork, "network", "n", "", "Network name for records to delete") deleteCmd.Flags().BoolVarP(&noPrompt, "no-prompt", "y", false, "No prompting for records deletion") @@ -76,9 +72,6 @@ func init() { exportCmd.Flags().StringVarP(&exportNetwork, "network", "n", "", "Domain name to export") exportCmd.MarkFlagRequired("network") exportCmd.Flags().StringVarP(&outputFilename, "zonefile", "z", "", "Output file for backup ( intead of outputing it to stdout ) ") - - checkCmd.Flags().StringVarP(&recordType, "recordType", "t", "", "DNS record type to check value of") - checkCmd.Flags().StringVarP(&keyName, "key", "k", "", "DNS record key to check") } type byIP []net.IP @@ -108,11 +101,11 @@ var listCmd = &cobra.Command{ var listRecordsCmd = &cobra.Command{ Use: "records", - Short: "List the A/SRV/TXT entries of the given network", - Long: "List the A/SRV/TXT entries of the given network", + Short: "List the A/SRV entries of the given network", + Long: "List the A/SRV entries of the given network", Run: func(cmd *cobra.Command, args []string) { recordType = strings.ToUpper(recordType) - if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" || recordType == "TXT" { + if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" { listEntries(listNetwork, recordType) } else { fmt.Fprintf(os.Stderr, "Invalid recordType specified.\n") @@ -137,24 +130,6 @@ var checkCmd = &cobra.Command{ Short: "Check the status", Long: "Check the status", Run: func(cmd *cobra.Command, args []string) { - if (keyName != "" && recordType == "") || (keyName == "" && recordType != "") { - fmt.Printf("You must supply both or none of --key and --recordType") - } - if keyName != "" && recordType != "" { - switch recordType { - case "SRV": - checkSrvRecord(keyName) - case "CNAME": - checkDNSRecord(keyName) - case "DNSADDR": - checkDnsaddrRecord(keyName) - case "TXT": - checkTxtRecord(keyName) - default: - fmt.Printf("Unrecognized check for dns record type %s\n", recordType) - } - return - } checkDNSRecord("relay-us-ea-1.algorand.network") checkDNSRecord("relay-us-ea-2.algorand.network") checkDNSRecord("relay-us-ea-3.algorand.network") @@ -166,22 +141,17 @@ var checkCmd = &cobra.Command{ checkSrvRecord("testnet.algorand.network") checkSrvRecord("bogus.algorand.network") fmt.Printf("------------------------\n") - - fmt.Printf("------------------------\n") - checkDnsaddrRecord("devnet.algorand.network") - fmt.Printf("------------------------\n") }, } var addCmd = &cobra.Command{ Use: "add", Short: "Add a DNS record", - Long: "Adds a DNS record to map --from to --to, using A if to == IP or CNAME otherwise\nYou can also set the desired type with -r\n", + Long: "Adds a DNS record to map --from to --to, using A if to == IP or CNAME otherwise\n", Example: "algons dns add -f a.test.algodev.network -t r1.algodev.network\n" + - "algons dns add -f a.test.algodev.network -t 192.168.100.10\n" + - "algons dns add -r TXT -f _dnsaddr.a.test.algodev.network -t \"dnsaddr=/ip4/192.168.100.10/tcp/4001/ws\"", + "algons dns add -f a.test.algodev.network -t 192.168.100.10", Run: func(cmd *cobra.Command, args []string) { - err := doAddDNS(addFromName, addToAddress, recordType) + err := doAddDNS(addFromName, addToAddress) if err != nil { fmt.Fprintf(os.Stderr, "Error adding DNS entry: %v\n", err) os.Exit(1) @@ -211,7 +181,7 @@ var exportCmd = &cobra.Command{ }, } -func doAddDNS(from string, to string, recordType string) (err error) { +func doAddDNS(from string, to string) (err error) { cfZoneID, cfToken, err := getClouldflareCredentials() if err != nil { return fmt.Errorf("error getting DNS credentials: %v", err) @@ -221,22 +191,16 @@ func doAddDNS(from string, to string, recordType string) (err error) { const priority = 1 const proxied = false - if recordType == "TXT" { - err = cloudflareDNS.CreateDNSRecord(context.Background(), recordType, from, to, cloudflare.AutomaticTTL, priority, proxied) - return - } // If we need to register anything, first register a DNS entry // to map our network DNS name to our public name (or IP) provided to nodecfg // Network HostName = eg r1.testnet.algorand.network isIP := net.ParseIP(to) != nil - // Preserves backwards compatibility for tools using existing algons functionality - if recordType == "" { - if isIP { - recordType = "A" - } else { - recordType = "CNAME" - } + var recordType string + if isIP { + recordType = "A" + } else { + recordType = "CNAME" } err = cloudflareDNS.SetDNSRecord(context.Background(), recordType, from, to, cloudflare.AutomaticTTL, priority, proxied) @@ -277,46 +241,6 @@ func checkDNSRecord(dnsName string) { } } -func checkDnsaddrRecord(name string) { - fmt.Printf("------------------------\nDnsaddr Lookup: %s\n", name) - - resolver, err := madns.NewResolver(madns.WithDefaultResolver(net.DefaultResolver)) - if err != nil { - fmt.Printf("Unable to construct multiaddr dns resolver: %v\n", err) - return - } - dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", name)) - if err != nil { - fmt.Printf("Unable to construct multiaddr for %s : %v\n", name, err) - return - } - maddrs, err := resolver.Resolve(context.Background(), dnsaddr) - if err != nil { - fmt.Printf("Unable to resolve dnsaddr: %s\n", err) - } - for _, maddr := range maddrs { - fmt.Printf("%s\n", maddr.String()) - } - -} - -func checkTxtRecord(name string) { - fmt.Printf("------------------------\nTXT Lookup: %s\n", name) - - records, err := net.LookupTXT(name) - if err != nil { - if !strings.HasSuffix(err.Error(), "cannot unmarshal DNS message") { - // we weren't able to get the TXT records. - fmt.Printf("Cannot lookup TXT record for %s: %v\n", name, err) - return - } - - for _, record := range records { - fmt.Printf("%s\n", record) - } - } -} - func checkSrvRecord(dnsBootstrap string) { fmt.Printf("------------------------\nSRV Lookup: %s\n", dnsBootstrap) @@ -443,7 +367,7 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa networkSuffix = "." + network + ".algodev.network" } - for _, recordType := range []string{"A", "CNAME", "TXT"} { + for _, recordType := range []string{"A", "CNAME"} { records, err := cloudflareDNS.ListDNSRecord(context.Background(), recordType, "", "", "", "", "") if err != nil { fmt.Fprintf(os.Stderr, "Error listing DNS '%s' entries: %v\n", recordType, err) @@ -501,7 +425,7 @@ func listEntries(listNetwork string, recordType string) { } cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) - recordTypes := []string{"A", "CNAME", "SRV", "TXT"} + recordTypes := []string{"A", "CNAME", "SRV"} if recordType != "" { recordTypes = []string{recordType} } From 6a976bc309e538a48ad508fc5965eb37de13fc94 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 17 Jul 2023 22:52:51 -0700 Subject: [PATCH 07/28] Rename, add comments --- cmd/algons/dnsaddrCmd.go | 2 +- network/p2p/dnsaddr/resolve.go | 6 +++++- network/p2p/dnsaddr/resolveController.go | 12 +++++++----- network/p2p/dnsaddr/resolveController_test.go | 2 +- network/p2p/dnsaddr/resolve_test.go | 6 +++--- protocol/hash.go | 1 - 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 541a1628a2..4d22e0fca0 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -54,7 +54,7 @@ var dnsaddrTreeCmd = &cobra.Command{ Short: "Recursively resolves and lists the dnsaddr entries of the given domain", Long: "Recursively resolves and lists the dnsaddr entries of the given domain", Run: func(cmd *cobra.Command, args []string) { - controller := dnsaddr.NewDnsaddrResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) + controller := dnsaddr.NewMultiaddrDnsResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) addrs, err := dnsaddr.MultiaddrsFromResolver(dnsaddrDomain, controller) if err != nil { fmt.Printf("%s\n", err.Error()) diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go index c60c0e38b9..1330c107b4 100644 --- a/network/p2p/dnsaddr/resolve.go +++ b/network/p2p/dnsaddr/resolve.go @@ -29,7 +29,11 @@ func isDnsaddr(maddr multiaddr.Multiaddr) bool { return first.Protocol().Code == multiaddr.P_DNSADDR } -func MultiaddrsFromResolver(domain string, controller *DnsaddrResolveController) ([]multiaddr.Multiaddr, error) { +// MultiaddrsFromResolver attempts to recurse through dnsaddrs starting at domain. +// Any further dnsaddrs will be looked up until all TXT records have been fetched, +// and the full list of resulting Multiaddrs is returned. +// It uses the MultiaddrDnsResolveController to cycle through DNS resolvers on failure. +func MultiaddrsFromResolver(domain string, controller *MultiaddrDnsResolveController) ([]multiaddr.Multiaddr, error) { resolver := controller.Resolver() if resolver == nil { return nil, errors.New("passed controller has no resolvers MultiaddrsFromResolver") diff --git a/network/p2p/dnsaddr/resolveController.go b/network/p2p/dnsaddr/resolveController.go index 9e7673164d..b5fbc4130b 100644 --- a/network/p2p/dnsaddr/resolveController.go +++ b/network/p2p/dnsaddr/resolveController.go @@ -22,14 +22,16 @@ import ( "github.com/algorand/go-algorand/tools/network" ) -type DnsaddrResolveController struct { +// MultiaddrDnsResolveController returns a madns.Resolver, cycling through underlying net.Resolvers +type MultiaddrDnsResolveController struct { resolver *madns.Resolver nextResolvers []func() *madns.Resolver controller network.ResolveController } -func NewDnsaddrResolveController(controller network.ResolveController) *DnsaddrResolveController { - return &DnsaddrResolveController{ +// NewMultiaddrDnsResolveController constructs a MultiaddrDnsResolveController +func NewMultiaddrDnsResolveController(controller network.ResolveController) *MultiaddrDnsResolveController { + return &MultiaddrDnsResolveController{ resolver: nil, nextResolvers: []func() *madns.Resolver{controller.SystemDnsaddrResolver, controller.FallbackDnsaddrResolver, controller.DefaultDnsaddrResolver}, controller: controller, @@ -37,7 +39,7 @@ func NewDnsaddrResolveController(controller network.ResolveController) *DnsaddrR } // NextResolver applies the nextResolvers functions in order and returns the most recent result -func (c *DnsaddrResolveController) NextResolver() *madns.Resolver { +func (c *MultiaddrDnsResolveController) NextResolver() *madns.Resolver { if len(c.nextResolvers) == 0 { c.resolver = nil } else { @@ -48,7 +50,7 @@ func (c *DnsaddrResolveController) NextResolver() *madns.Resolver { } // Resolver returns the current resolver, invokes NextResolver if the resolver is nil -func (c *DnsaddrResolveController) Resolver() *madns.Resolver { +func (c *MultiaddrDnsResolveController) Resolver() *madns.Resolver { if c.resolver == nil { c.resolver = c.NextResolver() } diff --git a/network/p2p/dnsaddr/resolveController_test.go b/network/p2p/dnsaddr/resolveController_test.go index 7658147d19..1e1dbd41d8 100644 --- a/network/p2p/dnsaddr/resolveController_test.go +++ b/network/p2p/dnsaddr/resolveController_test.go @@ -31,7 +31,7 @@ func TestDnsAddrResolveController(t *testing.T) { t.Parallel() controller := network.NewResolveController(true, "127.0.0.1", log.Base()) - dnsaddrCont := NewDnsaddrResolveController(controller) + dnsaddrCont := NewMultiaddrDnsResolveController(controller) // Assert that the dnsaddr resolver cycles through the dns resolvers properly assert.Equal(t, controller.SystemDnsaddrResolver(), dnsaddrCont.Resolver()) diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go index 6c848f422c..c6e10c028d 100644 --- a/network/p2p/dnsaddr/resolve_test.go +++ b/network/p2p/dnsaddr/resolve_test.go @@ -62,7 +62,7 @@ func TestMultiaddrsFromResolver(t *testing.T) { t.Parallel() controller := network.NewResolveController(false, "", log.Base()) - dnsaddrCont := NewDnsaddrResolveController(controller) + dnsaddrCont := NewMultiaddrDnsResolveController(controller) // Fail on bad dnsaddr domain maddrs, err := MultiaddrsFromResolver("/bogus/foobar", dnsaddrCont) @@ -90,7 +90,7 @@ func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() - dnsaddrCont := &DnsaddrResolveController{ + dnsaddrCont := &MultiaddrDnsResolveController{ resolver: nil, nextResolvers: nil, } @@ -101,7 +101,7 @@ func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { assert.ErrorContains(t, err, fmt.Sprintf("passed controller has no resolvers MultiaddrsFromResolver")) resolver, _ := madns.NewResolver(madns.WithDefaultResolver(&failureResolver{})) - dnsaddrCont = &DnsaddrResolveController{ + dnsaddrCont = &MultiaddrDnsResolveController{ resolver: resolver, nextResolvers: nil, controller: network.ResolveController{}, diff --git a/protocol/hash.go b/protocol/hash.go index ef31923db1..434deaf8c3 100644 --- a/protocol/hash.go +++ b/protocol/hash.go @@ -43,7 +43,6 @@ const ( BlockHeader HashID = "BH" BalanceRecord HashID = "BR" Credential HashID = "CR" - DNSAddrNode HashID = "DNSADDR" Genesis HashID = "GE" KeysInMSS HashID = "KP" MerkleArrayNode HashID = "MA" From c84298b42840c5f3d49ba2c943ddd11a553c0c0c Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Tue, 18 Jul 2023 09:27:35 -0700 Subject: [PATCH 08/28] Fix lint errors --- cmd/algons/dnsaddrCmd.go | 2 +- network/p2p/dnsaddr/resolve.go | 6 +++--- network/p2p/dnsaddr/resolveController.go | 14 +++++++------- network/p2p/dnsaddr/resolveController_test.go | 2 +- network/p2p/dnsaddr/resolve_test.go | 8 ++++---- tools/network/resolveController.go | 3 +++ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 4d22e0fca0..38a66f0070 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -54,7 +54,7 @@ var dnsaddrTreeCmd = &cobra.Command{ Short: "Recursively resolves and lists the dnsaddr entries of the given domain", Long: "Recursively resolves and lists the dnsaddr entries of the given domain", Run: func(cmd *cobra.Command, args []string) { - controller := dnsaddr.NewMultiaddrDnsResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) + controller := dnsaddr.NewMultiaddrDNSResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) addrs, err := dnsaddr.MultiaddrsFromResolver(dnsaddrDomain, controller) if err != nil { fmt.Printf("%s\n", err.Error()) diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go index 1330c107b4..d62c7b111d 100644 --- a/network/p2p/dnsaddr/resolve.go +++ b/network/p2p/dnsaddr/resolve.go @@ -32,15 +32,15 @@ func isDnsaddr(maddr multiaddr.Multiaddr) bool { // MultiaddrsFromResolver attempts to recurse through dnsaddrs starting at domain. // Any further dnsaddrs will be looked up until all TXT records have been fetched, // and the full list of resulting Multiaddrs is returned. -// It uses the MultiaddrDnsResolveController to cycle through DNS resolvers on failure. -func MultiaddrsFromResolver(domain string, controller *MultiaddrDnsResolveController) ([]multiaddr.Multiaddr, error) { +// It uses the MultiaddrDNSResolveController to cycle through DNS resolvers on failure. +func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveController) ([]multiaddr.Multiaddr, error) { resolver := controller.Resolver() if resolver == nil { return nil, errors.New("passed controller has no resolvers MultiaddrsFromResolver") } dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", domain)) if err != nil { - return nil, fmt.Errorf("Unable to construct multiaddr for %s : %v\n", domain, err) + return nil, fmt.Errorf("unable to construct multiaddr for %s : %v", domain, err) } var resolved []multiaddr.Multiaddr var toResolve = []multiaddr.Multiaddr{dnsaddr} diff --git a/network/p2p/dnsaddr/resolveController.go b/network/p2p/dnsaddr/resolveController.go index b5fbc4130b..d1558de584 100644 --- a/network/p2p/dnsaddr/resolveController.go +++ b/network/p2p/dnsaddr/resolveController.go @@ -22,16 +22,16 @@ import ( "github.com/algorand/go-algorand/tools/network" ) -// MultiaddrDnsResolveController returns a madns.Resolver, cycling through underlying net.Resolvers -type MultiaddrDnsResolveController struct { +// MultiaddrDNSResolveController returns a madns.Resolver, cycling through underlying net.Resolvers +type MultiaddrDNSResolveController struct { resolver *madns.Resolver nextResolvers []func() *madns.Resolver controller network.ResolveController } -// NewMultiaddrDnsResolveController constructs a MultiaddrDnsResolveController -func NewMultiaddrDnsResolveController(controller network.ResolveController) *MultiaddrDnsResolveController { - return &MultiaddrDnsResolveController{ +// NewMultiaddrDNSResolveController constructs a MultiaddrDNSResolveController +func NewMultiaddrDNSResolveController(controller network.ResolveController) *MultiaddrDNSResolveController { + return &MultiaddrDNSResolveController{ resolver: nil, nextResolvers: []func() *madns.Resolver{controller.SystemDnsaddrResolver, controller.FallbackDnsaddrResolver, controller.DefaultDnsaddrResolver}, controller: controller, @@ -39,7 +39,7 @@ func NewMultiaddrDnsResolveController(controller network.ResolveController) *Mul } // NextResolver applies the nextResolvers functions in order and returns the most recent result -func (c *MultiaddrDnsResolveController) NextResolver() *madns.Resolver { +func (c *MultiaddrDNSResolveController) NextResolver() *madns.Resolver { if len(c.nextResolvers) == 0 { c.resolver = nil } else { @@ -50,7 +50,7 @@ func (c *MultiaddrDnsResolveController) NextResolver() *madns.Resolver { } // Resolver returns the current resolver, invokes NextResolver if the resolver is nil -func (c *MultiaddrDnsResolveController) Resolver() *madns.Resolver { +func (c *MultiaddrDNSResolveController) Resolver() *madns.Resolver { if c.resolver == nil { c.resolver = c.NextResolver() } diff --git a/network/p2p/dnsaddr/resolveController_test.go b/network/p2p/dnsaddr/resolveController_test.go index 1e1dbd41d8..e4a084a271 100644 --- a/network/p2p/dnsaddr/resolveController_test.go +++ b/network/p2p/dnsaddr/resolveController_test.go @@ -31,7 +31,7 @@ func TestDnsAddrResolveController(t *testing.T) { t.Parallel() controller := network.NewResolveController(true, "127.0.0.1", log.Base()) - dnsaddrCont := NewMultiaddrDnsResolveController(controller) + dnsaddrCont := NewMultiaddrDNSResolveController(controller) // Assert that the dnsaddr resolver cycles through the dns resolvers properly assert.Equal(t, controller.SystemDnsaddrResolver(), dnsaddrCont.Resolver()) diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go index c6e10c028d..75e7d4b830 100644 --- a/network/p2p/dnsaddr/resolve_test.go +++ b/network/p2p/dnsaddr/resolve_test.go @@ -62,12 +62,12 @@ func TestMultiaddrsFromResolver(t *testing.T) { t.Parallel() controller := network.NewResolveController(false, "", log.Base()) - dnsaddrCont := NewMultiaddrDnsResolveController(controller) + dnsaddrCont := NewMultiaddrDNSResolveController(controller) // Fail on bad dnsaddr domain maddrs, err := MultiaddrsFromResolver("/bogus/foobar", dnsaddrCont) assert.Empty(t, maddrs) - assert.ErrorContains(t, err, fmt.Sprintf("Unable to construct multiaddr for %s", "/bogus/foobar")) + assert.ErrorContains(t, err, fmt.Sprintf("unable to construct multiaddr for %s", "/bogus/foobar")) // Success on a dnsaddr that needs to resolve recursively maddrs, err = MultiaddrsFromResolver("bootstrap.libp2p.io", dnsaddrCont) @@ -90,7 +90,7 @@ func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() - dnsaddrCont := &MultiaddrDnsResolveController{ + dnsaddrCont := &MultiaddrDNSResolveController{ resolver: nil, nextResolvers: nil, } @@ -101,7 +101,7 @@ func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { assert.ErrorContains(t, err, fmt.Sprintf("passed controller has no resolvers MultiaddrsFromResolver")) resolver, _ := madns.NewResolver(madns.WithDefaultResolver(&failureResolver{})) - dnsaddrCont = &MultiaddrDnsResolveController{ + dnsaddrCont = &MultiaddrDNSResolveController{ resolver: resolver, nextResolvers: nil, controller: network.ResolveController{}, diff --git a/tools/network/resolveController.go b/tools/network/resolveController.go index 37e3fa8f39..b9b75fb7b7 100644 --- a/tools/network/resolveController.go +++ b/tools/network/resolveController.go @@ -88,6 +88,7 @@ func (c *ResolveController) DefaultResolver() ResolverIf { return &Resolver{} } +// SystemDnsaddrResolver returns the dnsaddr resolver that uses OS-defined DNS server func (c *ResolveController) SystemDnsaddrResolver() *madns.Resolver { resolver := c.SystemResolver() // ignore errors here since we madns.WithDefaultResolver can't error @@ -95,6 +96,7 @@ func (c *ResolveController) SystemDnsaddrResolver() *madns.Resolver { return mResv } +// FallbackDnsaddrResolver returns the dnsaddr resolver w/ fallback DNS address func (c *ResolveController) FallbackDnsaddrResolver() *madns.Resolver { resolver := c.FallbackResolver() // ignore errors here since we madns.WithDefaultResolver can't error @@ -102,6 +104,7 @@ func (c *ResolveController) FallbackDnsaddrResolver() *madns.Resolver { return mResv } +// DefaultDnsaddrResolver returns the dnsaddr resolver w/ default DNS address func (c *ResolveController) DefaultDnsaddrResolver() *madns.Resolver { resolver := c.DefaultResolver() mResv, _ := madns.NewResolver(madns.WithDefaultResolver(resolver)) From f51575779736a14b1a63c0efd87e2974352e5167 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Tue, 18 Jul 2023 09:54:05 -0700 Subject: [PATCH 09/28] make tidy --- go.mod | 5 ----- go.sum | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/go.mod b/go.mod index 0cba989743..c1150efbb2 100644 --- a/go.mod +++ b/go.mod @@ -46,14 +46,12 @@ require ( require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect - github.com/daixiang0/gci v0.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fortytw2/leaktest v1.3.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/swag v0.19.5 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/google/uuid v1.3.0 // indirect - github.com/hexops/gotextdiff v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/invopop/yaml v0.1.0 // indirect github.com/ipfs/go-cid v0.0.7 // indirect @@ -81,15 +79,12 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect - github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect - golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/term v0.7.0 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect - golang.org/x/tools v0.6.0 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index c5389df8c2..f8d925dfb9 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,6 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/daixiang0/gci v0.3.2 h1:MDBsgEJGSJ++/N6Je/b2yK5x5WqmKYlzmILLVP41nl8= -github.com/daixiang0/gci v0.3.2/go.mod h1:jaASoJmv/ykO9dAAPy31iJnreV19248qKDdVWf3QgC4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -283,8 +281,6 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= -github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= -github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -469,8 +465,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 h1:OXcKh35JaYsGMRzpvFkLv/MEyPuL49CThT1pZ8aSml4= -github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -549,8 +543,6 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -768,8 +760,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 6f8a0d9bf92f84fb0910024439d19e5ddf0f932a Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 19 Jul 2023 12:44:20 -0700 Subject: [PATCH 10/28] Add configs for PeerID, P2PEnable --- config/localTemplate.go | 11 +++++++++++ config/local_defaults.go | 3 +++ installer/config.json.example | 3 +++ test/testdata/configs/config-v28.json | 3 +++ 4 files changed, 20 insertions(+) diff --git a/config/localTemplate.go b/config/localTemplate.go index 47cfa48ca5..fbdfbc8902 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -520,6 +520,17 @@ type Local struct { // BlockServiceMemCap is the memory capacity in bytes which is allowed for the block service to use for HTTP block requests. // When it exceeds this capacity, it redirects the block requests to a different node BlockServiceMemCap uint64 `version[28]:"500000000"` + + // P2PEnable turns on the peer to peer network + P2PEnable bool `version[28]:"false"` + + // P2PPersistPeerID will write the private key used for the node's PeerID to the P2PPrivateKeyLocation. + // This is only used when P2PEnable is true. If P2PPrivateKey is not specified, it uses the default location. + P2PPersistPeerID bool `version[28]:"true"` + + // P2PPrivateKeyLocation allows the user to specify a custom path to the private key used for the node's PeerID. + // This is only used when P2PEnable is true. If the parameter is not set, it uses the default location. + P2PPrivateKeyLocation string `version[28]:""` } // DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers diff --git a/config/local_defaults.go b/config/local_defaults.go index a721cd8eb8..fb48c9adc3 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -106,6 +106,9 @@ var defaultLocal = Local{ OptimizeAccountsDatabaseOnStartup: false, OutgoingMessageFilterBucketCount: 3, OutgoingMessageFilterBucketSize: 128, + P2PEnable: false, + P2PPersistPeerID: true, + P2PPrivateKeyLocation: "", ParticipationKeysRefreshInterval: 60000000000, PeerConnectionsUpdateInterval: 3600, PeerPingPeriodSeconds: 0, diff --git a/installer/config.json.example b/installer/config.json.example index 7b6ceb5326..3d3eb0b2fc 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -85,6 +85,9 @@ "OptimizeAccountsDatabaseOnStartup": false, "OutgoingMessageFilterBucketCount": 3, "OutgoingMessageFilterBucketSize": 128, + "P2PEnable": false, + "P2PPersistPeerID": true, + "P2PPrivateKeyLocation": "", "ParticipationKeysRefreshInterval": 60000000000, "PeerConnectionsUpdateInterval": 3600, "PeerPingPeriodSeconds": 0, diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json index 7b6ceb5326..3d3eb0b2fc 100644 --- a/test/testdata/configs/config-v28.json +++ b/test/testdata/configs/config-v28.json @@ -85,6 +85,9 @@ "OptimizeAccountsDatabaseOnStartup": false, "OutgoingMessageFilterBucketCount": 3, "OutgoingMessageFilterBucketSize": 128, + "P2PEnable": false, + "P2PPersistPeerID": true, + "P2PPrivateKeyLocation": "", "ParticipationKeysRefreshInterval": 60000000000, "PeerConnectionsUpdateInterval": 3600, "PeerPingPeriodSeconds": 0, From 709c43f9372bb8b2ea64b8beafb800fba8897a72 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Thu, 20 Jul 2023 15:39:43 -0700 Subject: [PATCH 11/28] Add peerID fetching/generation --- go.mod | 32 ++++++++----- go.sum | 82 ++++++++++++++++++++++---------- network/p2p/peerID.go | 92 ++++++++++++++++++++++++++++++++++++ network/p2p/peerID_test.go | 77 ++++++++++++++++++++++++++++++ tools/block-generator/go.mod | 17 ++++--- tools/block-generator/go.sum | 51 ++++++++++++-------- tools/x-repo-types/go.mod | 4 +- tools/x-repo-types/go.sum | 19 ++++---- 8 files changed, 298 insertions(+), 76 deletions(-) create mode 100644 network/p2p/peerID.go create mode 100644 network/p2p/peerID_test.go diff --git a/go.mod b/go.mod index a69db49ce5..e0d15102ac 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/algorand/websocket v1.4.6 github.com/aws/aws-sdk-go v1.33.0 github.com/consensys/gnark-crypto v0.7.0 - github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 + github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c github.com/dchest/siphash v1.2.1 github.com/fatih/color v1.13.0 github.com/getkin/kin-openapi v0.107.0 @@ -27,16 +27,17 @@ require ( github.com/jmoiron/sqlx v1.2.0 github.com/karalabe/usb v0.0.2 github.com/labstack/echo/v4 v4.9.1 + github.com/libp2p/go-libp2p v0.29.0 github.com/mattn/go-sqlite3 v1.10.0 - github.com/miekg/dns v1.1.41 + github.com/miekg/dns v1.1.55 github.com/olivere/elastic v6.2.14+incompatible github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.3.0 - github.com/stretchr/testify v1.8.1 - golang.org/x/crypto v0.1.0 - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 - golang.org/x/sys v0.7.0 - golang.org/x/text v0.9.0 + github.com/stretchr/testify v1.8.4 + golang.org/x/crypto v0.11.0 + golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 + golang.org/x/sys v0.10.0 + golang.org/x/text v0.11.0 gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 pgregory.net/rapid v0.6.2 ) @@ -45,22 +46,25 @@ require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/fortytw2/leaktest v1.3.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/swag v0.19.5 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/google/uuid v1.3.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/invopop/yaml v0.1.0 // indirect github.com/jmespath/go-jmespath v0.3.0 // indirect github.com/josharian/intern v1.0.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/minio/sha256-simd v1.0.1 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -69,11 +73,13 @@ require ( github.com/stretchr/objx v0.5.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect - golang.org/x/net v0.9.0 // indirect - golang.org/x/sync v0.1.0 // indirect - golang.org/x/term v0.7.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/term v0.10.0 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + golang.org/x/tools v0.11.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4e2d9d22ca..d6fbc3b535 100644 --- a/go.sum +++ b/go.sum @@ -123,10 +123,13 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= -github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= +github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= +github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4= github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -218,6 +221,8 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -288,6 +293,7 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= +github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= @@ -306,11 +312,15 @@ github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -321,6 +331,9 @@ github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3 github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= +github.com/libp2p/go-libp2p v0.29.0 h1:QduJ2XQr/Crg4EnloueWDL0Jj86N3Ezhyyj7XH+XwHI= +github.com/libp2p/go-libp2p v0.29.0/go.mod h1:iNKL7mEnZ9wAss+03IjAwM9ZAQXfVUAPUUmOACQfQ/g= github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -339,16 +352,20 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= -github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= +github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= +github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= @@ -365,9 +382,15 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= +github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= +github.com/multiformats/go-multiaddr v0.10.1 h1:HghtFrWyZEPrpTvgAMFJi6gFdgHfs2cb0pyfDsk+lqU= +github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= +github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= +github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/olivere/elastic v6.2.14+incompatible h1:k+KadwNP/dkXE0/eu+T6otk1+5fe0tEpPyQJ4XVm5i8= github.com/olivere/elastic v6.2.14+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -408,6 +431,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -431,8 +455,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -467,11 +491,12 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -482,8 +507,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= +golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -511,6 +536,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -553,8 +580,8 @@ golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -583,8 +610,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -621,6 +647,7 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -652,11 +679,13 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -666,8 +695,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -728,6 +757,8 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= +golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -875,12 +906,14 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 h1:q/fZgS8MMadqFFGa8WL4Oyz+TmjiZfi8UrzWhTl8d5w= @@ -905,6 +938,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= pgregory.net/rapid v0.6.2 h1:ErW5sL+UKtfBfUTsWHDCoeB+eZKLKMxrSd1VJY6W4bw= pgregory.net/rapid v0.6.2/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/network/p2p/peerID.go b/network/p2p/peerID.go new file mode 100644 index 0000000000..701edb5de0 --- /dev/null +++ b/network/p2p/peerID.go @@ -0,0 +1,92 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +// Package node is the Algorand node itself, with functions exposed to the frontend + +package p2p + +import ( + "crypto/rand" + "fmt" + "os" + "path" + + "github.com/libp2p/go-libp2p/core/crypto" + + "github.com/algorand/go-algorand/config" +) + +const DefaultPrivKeyPath = "peerIDPrivKey.pem" + +// GetPrivKey manages loading and creation of private keys for network PeerIDs +// It prioritizes, in this order: +// 1. user supplied path to privKey +// 2. default path to privKey, +// 3. generating a new privKey. +// +// If a new privKey is generated it will be saved to default path if cfg.P2PPersistPeerID. +func GetPrivKey(cfg config.Local, dataDir string) (crypto.PrivKey, error) { + // if user-supplied, try to load it from there + if cfg.P2PPrivateKeyLocation != "" { + return loadPrivateKeyFromFile(cfg.P2PPrivateKeyLocation) + } + // if a default path key exists load it + defaultPrivKeyPath := path.Join(dataDir, DefaultPrivKeyPath) + _, err := os.Stat(defaultPrivKeyPath) + if err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to stat %s %w", defaultPrivKeyPath, err) + } + defaultPrivKeyExists := !os.IsNotExist(err) + if defaultPrivKeyExists { + return loadPrivateKeyFromFile(defaultPrivKeyPath) + } + // generate a new key + privKey, err := generatePrivKey() + if err != nil { + return privKey, fmt.Errorf("failed to generate private key %w", err) + } + // if we want persistent PeerID, save the generated PrivKey + if cfg.P2PPersistPeerID { + return privKey, writePrivateKeyToFile(defaultPrivKeyPath, privKey) + } + return privKey, nil +} + +// loadPrivateKeyFromFile attempts to read raw privKey bytes from path +// It only supports Ed25519 keys. +func loadPrivateKeyFromFile(path string) (crypto.PrivKey, error) { + bytes, err := os.ReadFile(path) + if err != nil { + return nil, err + } + // We only support Ed25519 keys + return crypto.UnmarshalEd25519PrivateKey(bytes) +} + +// writePrivateKeyToFile attempts to write raw privKey bytes to path +func writePrivateKeyToFile(path string, privKey crypto.PrivKey) error { + bytes, err := privKey.Raw() + if err != nil { + return err + } + return os.WriteFile(path, bytes, 0600) +} + +// generatePrivKey creates a new Ed25519 key +func generatePrivKey() (crypto.PrivKey, error) { + priv, _, err := crypto.GenerateEd25519Key(rand.Reader) + return priv, err +} diff --git a/network/p2p/peerID_test.go b/network/p2p/peerID_test.go new file mode 100644 index 0000000000..35ddfe1a6f --- /dev/null +++ b/network/p2p/peerID_test.go @@ -0,0 +1,77 @@ +package p2p + +import ( + "os" + "path" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/algorand/go-algorand/config" +) + +func TestGetPrivKeyUserSupplied(t *testing.T) { + tempdir := t.TempDir() + cfg := config.GetDefaultLocal() + customPath := path.Join(tempdir, "foobar.pem") + // generate a new private key + privKey, err := generatePrivKey() + require.NoError(t, err) + // write it to our custom path + err = writePrivateKeyToFile(customPath, privKey) + require.NoError(t, err) + cfg.P2PPrivateKeyLocation = customPath + // make sure GetPrivKey loads our custom key + loadedPrivKey, err := GetPrivKey(cfg, tempdir) + assert.NoError(t, err) + assert.Equal(t, privKey, loadedPrivKey) +} + +func TestGetPrivKeyUserSuppliedDoesNotExistErrors(t *testing.T) { + tempdir := t.TempDir() + cfg := config.GetDefaultLocal() + cfg.P2PPrivateKeyLocation = path.Join(tempdir, "foobar.pem") + _, err := GetPrivKey(cfg, tempdir) + assert.True(t, os.IsNotExist(err)) +} + +func TestGetPrivKeyDefault(t *testing.T) { + tempdir := t.TempDir() + cfg := config.GetDefaultLocal() + + // generate a new private key + privKey, err := generatePrivKey() + require.NoError(t, err) + // write it to the default path + err = writePrivateKeyToFile(path.Join(tempdir, DefaultPrivKeyPath), privKey) + require.NoError(t, err) + // fetch the default private key + loadedPrivKey, err := GetPrivKey(cfg, tempdir) + assert.NoError(t, err) + assert.Equal(t, privKey, loadedPrivKey) +} + +func TestGetPrivKeyUserGeneratedPersisted(t *testing.T) { + tempdir := t.TempDir() + cfg := config.GetDefaultLocal() + // get a generated private key + privKey, err := GetPrivKey(cfg, tempdir) + require.NoError(t, err) + // make sure it was persisted + loadedPrivKey, err := loadPrivateKeyFromFile(path.Join(tempdir, DefaultPrivKeyPath)) + assert.NoError(t, err) + assert.Equal(t, privKey, loadedPrivKey) +} + +func TestGetPrivKeyUserGeneratedEphemeral(t *testing.T) { + tempdir := t.TempDir() + cfg := config.GetDefaultLocal() + cfg.P2PPersistPeerID = false + // get a generated private key + _, err := GetPrivKey(cfg, tempdir) + require.NoError(t, err) + // make sure it was not persisted + _, err = loadPrivateKeyFromFile(path.Join(tempdir, DefaultPrivKeyPath)) + assert.True(t, os.IsNotExist(err)) +} diff --git a/tools/block-generator/go.mod b/tools/block-generator/go.mod index 12649d09bc..447571947b 100644 --- a/tools/block-generator/go.mod +++ b/tools/block-generator/go.mod @@ -11,7 +11,7 @@ require ( github.com/algorand/go-deadlock v0.2.2 github.com/lib/pq v1.10.9 github.com/spf13/cobra v1.7.0 - github.com/stretchr/testify v1.8.3 + github.com/stretchr/testify v1.8.4 gopkg.in/yaml.v3 v3.0.1 ) @@ -26,7 +26,7 @@ require ( github.com/aws/aws-sdk-go v1.33.0 // indirect github.com/consensys/gnark-crypto v0.7.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 // indirect + github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/dchest/siphash v1.2.1 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.3.0 // indirect @@ -34,9 +34,10 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.3.0 // indirect github.com/josharian/intern v1.0.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-sqlite3 v1.10.0 // indirect - github.com/miekg/dns v1.1.41 // indirect + github.com/miekg/dns v1.1.55 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/olivere/elastic v6.2.14+incompatible // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -44,9 +45,11 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/crypto v0.1.0 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/net v0.9.0 // indirect - golang.org/x/sys v0.7.0 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/tools v0.11.0 // indirect gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 // indirect ) diff --git a/tools/block-generator/go.sum b/tools/block-generator/go.sum index 86dd5643dc..82cd4aff9e 100644 --- a/tools/block-generator/go.sum +++ b/tools/block-generator/go.sum @@ -24,11 +24,12 @@ github.com/chrismcguire/gobberish v0.0.0-20150821175641-1d8adb509a0e h1:CHPYEbz7 github.com/consensys/gnark-crypto v0.7.0 h1:rwdy8+ssmLYRqKp+ryRRgQJl/rCq2uv+n83cOydm5UE= github.com/consensys/gnark-crypto v0.7.0/go.mod h1:KPSuJzyxkJA8xZ/+CV47tyqkr9MmpZA3PXivK4VPrVg= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= -github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= +github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= +github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4= github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -46,7 +47,10 @@ github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2 github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= @@ -54,20 +58,22 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= -github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= -github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= +github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/olivere/elastic v6.2.14+incompatible h1:k+KadwNP/dkXE0/eu+T6otk1+5fe0tEpPyQJ4XVm5i8= github.com/olivere/elastic v6.2.14+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -79,48 +85,55 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= +golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= +golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009 h1:q/fZgS8MMadqFFGa8WL4Oyz+TmjiZfi8UrzWhTl8d5w= gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009/go.mod h1:O0bY1e/dSoxMYZYTHP0SWKxG5EWLEvKR9/cOjWPPMKU= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/x-repo-types/go.mod b/tools/x-repo-types/go.mod index 776b76a0ec..c3daa2f5b6 100644 --- a/tools/x-repo-types/go.mod +++ b/tools/x-repo-types/go.mod @@ -7,13 +7,13 @@ replace github.com/algorand/go-algorand => ../.. require ( github.com/algorand/go-algorand v0.0.0-20230502140608-e24a35add0bb github.com/spf13/cobra v1.7.0 - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/tools/x-repo-types/go.sum b/tools/x-repo-types/go.sum index dba66ee268..e5ade7691d 100644 --- a/tools/x-repo-types/go.sum +++ b/tools/x-repo-types/go.sum @@ -1,29 +1,26 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From c62972cb282a814a06d4886e7f0f6f2c875144df Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Thu, 20 Jul 2023 15:52:29 -0700 Subject: [PATCH 12/28] Fix lint --- network/p2p/peerID.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/network/p2p/peerID.go b/network/p2p/peerID.go index 701edb5de0..08dd5a368f 100644 --- a/network/p2p/peerID.go +++ b/network/p2p/peerID.go @@ -29,6 +29,8 @@ import ( "github.com/algorand/go-algorand/config" ) +// DefaultPrivKeyPath is the default path inside the node's root directory at which the private key +// for p2p identity is found and persisted to when a new one is generated. const DefaultPrivKeyPath = "peerIDPrivKey.pem" // GetPrivKey manages loading and creation of private keys for network PeerIDs From 04a25e25bed5cacd7262b055f8356048f5d1ee83 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Thu, 20 Jul 2023 15:57:01 -0700 Subject: [PATCH 13/28] Add license, partitiontest, parallel --- network/p2p/peerID_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/network/p2p/peerID_test.go b/network/p2p/peerID_test.go index 35ddfe1a6f..5fea2b6a5c 100644 --- a/network/p2p/peerID_test.go +++ b/network/p2p/peerID_test.go @@ -1,6 +1,23 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + package p2p import ( + "github.com/algorand/go-algorand/test/partitiontest" "os" "path" "testing" @@ -12,6 +29,8 @@ import ( ) func TestGetPrivKeyUserSupplied(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() tempdir := t.TempDir() cfg := config.GetDefaultLocal() customPath := path.Join(tempdir, "foobar.pem") @@ -29,6 +48,8 @@ func TestGetPrivKeyUserSupplied(t *testing.T) { } func TestGetPrivKeyUserSuppliedDoesNotExistErrors(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() tempdir := t.TempDir() cfg := config.GetDefaultLocal() cfg.P2PPrivateKeyLocation = path.Join(tempdir, "foobar.pem") @@ -37,6 +58,8 @@ func TestGetPrivKeyUserSuppliedDoesNotExistErrors(t *testing.T) { } func TestGetPrivKeyDefault(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() tempdir := t.TempDir() cfg := config.GetDefaultLocal() @@ -53,6 +76,8 @@ func TestGetPrivKeyDefault(t *testing.T) { } func TestGetPrivKeyUserGeneratedPersisted(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() tempdir := t.TempDir() cfg := config.GetDefaultLocal() // get a generated private key @@ -65,6 +90,8 @@ func TestGetPrivKeyUserGeneratedPersisted(t *testing.T) { } func TestGetPrivKeyUserGeneratedEphemeral(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() tempdir := t.TempDir() cfg := config.GetDefaultLocal() cfg.P2PPersistPeerID = false From df5b0deef0a62e82aa528e93f2c61126aba00eba Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Fri, 21 Jul 2023 09:18:00 -0700 Subject: [PATCH 14/28] Update error logic in dnsaddr resolve --- network/p2p/dnsaddr/resolve.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go index d62c7b111d..ad9f4e8b42 100644 --- a/network/p2p/dnsaddr/resolve.go +++ b/network/p2p/dnsaddr/resolve.go @@ -48,8 +48,11 @@ func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveContro curr := toResolve[0] maddrs, resolveErr := resolver.Resolve(context.Background(), curr) if resolveErr != nil { - err = resolveErr resolver = controller.NextResolver() + // If we errored, and have exhausted all resolvers, just return + if resolver == nil { + return resolved, resolveErr + } continue } for _, maddr := range maddrs { @@ -61,5 +64,5 @@ func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveContro } toResolve = toResolve[1:] } - return resolved, err + return resolved, nil } From 6c92169418f63d7039141915d22f201e3034ec64 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Fri, 21 Jul 2023 09:56:49 -0700 Subject: [PATCH 15/28] Minor change --- network/p2p/peerID.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/network/p2p/peerID.go b/network/p2p/peerID.go index 08dd5a368f..05c99ce435 100644 --- a/network/p2p/peerID.go +++ b/network/p2p/peerID.go @@ -51,8 +51,7 @@ func GetPrivKey(cfg config.Local, dataDir string) (crypto.PrivKey, error) { if err != nil && !os.IsNotExist(err) { return nil, fmt.Errorf("failed to stat %s %w", defaultPrivKeyPath, err) } - defaultPrivKeyExists := !os.IsNotExist(err) - if defaultPrivKeyExists { + if !os.IsNotExist(err) { return loadPrivateKeyFromFile(defaultPrivKeyPath) } // generate a new key From 8b7ddd302ecd1dad4af4a36ae6685d5861f0a6b4 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 09:34:23 -0700 Subject: [PATCH 16/28] Change fallback dns resolver address --- cmd/algons/dnsaddrCmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 38a66f0070..83c9a898ff 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -54,7 +54,7 @@ var dnsaddrTreeCmd = &cobra.Command{ Short: "Recursively resolves and lists the dnsaddr entries of the given domain", Long: "Recursively resolves and lists the dnsaddr entries of the given domain", Run: func(cmd *cobra.Command, args []string) { - controller := dnsaddr.NewMultiaddrDNSResolveController(network.NewResolveController(secure, "127.0.0.1", log.Base())) + controller := dnsaddr.NewMultiaddrDNSResolveController(network.NewResolveController(secure, "", log.Base())) addrs, err := dnsaddr.MultiaddrsFromResolver(dnsaddrDomain, controller) if err != nil { fmt.Printf("%s\n", err.Error()) From 0ed14e4f5b10f6226a33eaaebe1affcd5a0674e8 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 09:43:08 -0700 Subject: [PATCH 17/28] Update config version to 29 --- config/localTemplate.go | 8 ++++---- config/local_defaults.go | 2 +- installer/config.json.example | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index fbdfbc8902..60098254a5 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -41,7 +41,7 @@ type Local struct { // Version tracks the current version of the defaults so we can migrate old -> new // This is specifically important whenever we decide to change the default value // for an existing parameter. This field tag must be updated any time we add a new version. - Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27" version[28]:"28"` + Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27" version[28]:"28" version[29]:"29"` // environmental (may be overridden) // When enabled, stores blocks indefinitely, otherwise, only the most recent blocks @@ -522,15 +522,15 @@ type Local struct { BlockServiceMemCap uint64 `version[28]:"500000000"` // P2PEnable turns on the peer to peer network - P2PEnable bool `version[28]:"false"` + P2PEnable bool `version[29]:"false"` // P2PPersistPeerID will write the private key used for the node's PeerID to the P2PPrivateKeyLocation. // This is only used when P2PEnable is true. If P2PPrivateKey is not specified, it uses the default location. - P2PPersistPeerID bool `version[28]:"true"` + P2PPersistPeerID bool `version[29]:"true"` // P2PPrivateKeyLocation allows the user to specify a custom path to the private key used for the node's PeerID. // This is only used when P2PEnable is true. If the parameter is not set, it uses the default location. - P2PPrivateKeyLocation string `version[28]:""` + P2PPrivateKeyLocation string `version[29]:""` } // DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers diff --git a/config/local_defaults.go b/config/local_defaults.go index fb48c9adc3..a3c55c1e1b 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -20,7 +20,7 @@ package config var defaultLocal = Local{ - Version: 28, + Version: 29, AccountUpdatesStatsInterval: 5000000000, AccountsRebuildSynchronousMode: 1, AgreementIncomingBundlesQueueLength: 15, diff --git a/installer/config.json.example b/installer/config.json.example index 3d3eb0b2fc..8522011ce6 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -1,5 +1,5 @@ { - "Version": 28, + "Version": 29, "AccountUpdatesStatsInterval": 5000000000, "AccountsRebuildSynchronousMode": 1, "AgreementIncomingBundlesQueueLength": 15, From c9f56eb3b544f2539d1d22848944290d5d83d39f Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 09:45:04 -0700 Subject: [PATCH 18/28] Update config comment to mention ed25519 limitation --- config/localTemplate.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/localTemplate.go b/config/localTemplate.go index 60098254a5..f13fc97f1f 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -529,6 +529,7 @@ type Local struct { P2PPersistPeerID bool `version[29]:"true"` // P2PPrivateKeyLocation allows the user to specify a custom path to the private key used for the node's PeerID. + // The private key provided must be an ed25519 private key. // This is only used when P2PEnable is true. If the parameter is not set, it uses the default location. P2PPrivateKeyLocation string `version[29]:""` } From ad89a9538c5f09ef463de39978c46b7426a952f0 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 09:45:33 -0700 Subject: [PATCH 19/28] Run gci --- network/p2p/peerID_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/p2p/peerID_test.go b/network/p2p/peerID_test.go index 5fea2b6a5c..1f15b32141 100644 --- a/network/p2p/peerID_test.go +++ b/network/p2p/peerID_test.go @@ -17,7 +17,6 @@ package p2p import ( - "github.com/algorand/go-algorand/test/partitiontest" "os" "path" "testing" @@ -26,6 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/algorand/go-algorand/config" + "github.com/algorand/go-algorand/test/partitiontest" ) func TestGetPrivKeyUserSupplied(t *testing.T) { From ff9e9680ac0fc18dd0b7ff32df3ef57e93902076 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 09:49:34 -0700 Subject: [PATCH 20/28] Use io util FileExists --- network/p2p/peerID.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/network/p2p/peerID.go b/network/p2p/peerID.go index 05c99ce435..fce32a3afc 100644 --- a/network/p2p/peerID.go +++ b/network/p2p/peerID.go @@ -21,6 +21,7 @@ package p2p import ( "crypto/rand" "fmt" + "github.com/algorand/go-algorand/util" "os" "path" @@ -47,11 +48,7 @@ func GetPrivKey(cfg config.Local, dataDir string) (crypto.PrivKey, error) { } // if a default path key exists load it defaultPrivKeyPath := path.Join(dataDir, DefaultPrivKeyPath) - _, err := os.Stat(defaultPrivKeyPath) - if err != nil && !os.IsNotExist(err) { - return nil, fmt.Errorf("failed to stat %s %w", defaultPrivKeyPath, err) - } - if !os.IsNotExist(err) { + if util.FileExists(defaultPrivKeyPath) { return loadPrivateKeyFromFile(defaultPrivKeyPath) } // generate a new key From 89efbccce21f98ab104e74e7f3e21fdb019e8b82 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 10:01:38 -0700 Subject: [PATCH 21/28] Add testdata config --- test/testdata/configs/config-v29.json | 124 ++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 test/testdata/configs/config-v29.json diff --git a/test/testdata/configs/config-v29.json b/test/testdata/configs/config-v29.json new file mode 100644 index 0000000000..8522011ce6 --- /dev/null +++ b/test/testdata/configs/config-v29.json @@ -0,0 +1,124 @@ +{ + "Version": 29, + "AccountUpdatesStatsInterval": 5000000000, + "AccountsRebuildSynchronousMode": 1, + "AgreementIncomingBundlesQueueLength": 15, + "AgreementIncomingProposalsQueueLength": 50, + "AgreementIncomingVotesQueueLength": 20000, + "AnnounceParticipationKey": true, + "Archival": false, + "BaseLoggerDebugLevel": 4, + "BlockServiceCustomFallbackEndpoints": "", + "BlockServiceMemCap": 500000000, + "BroadcastConnectionsLimit": -1, + "CadaverDirectory": "", + "CadaverSizeTarget": 0, + "CatchpointFileHistoryLength": 365, + "CatchpointInterval": 10000, + "CatchpointTracking": 0, + "CatchupBlockDownloadRetryAttempts": 1000, + "CatchupBlockValidateMode": 0, + "CatchupFailurePeerRefreshRate": 10, + "CatchupGossipBlockFetchTimeoutSec": 4, + "CatchupHTTPBlockFetchTimeoutSec": 4, + "CatchupLedgerDownloadRetryAttempts": 50, + "CatchupParallelBlocks": 16, + "ConnectionsRateLimitingCount": 60, + "ConnectionsRateLimitingWindowSeconds": 1, + "DNSBootstrapID": ".algorand.network?backup=.algorand.net&dedup=.algorand-.(network|net)", + "DNSSecurityFlags": 1, + "DeadlockDetection": 0, + "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, + "DisableLocalhostConnectionRateLimit": true, + "DisableNetworking": false, + "DisableOutgoingConnectionThrottling": false, + "EnableAccountUpdatesStats": false, + "EnableAgreementReporting": false, + "EnableAgreementTimeMetrics": false, + "EnableAssembleStats": false, + "EnableBlockService": false, + "EnableBlockServiceFallbackToArchiver": true, + "EnableCatchupFromArchiveServers": false, + "EnableDeveloperAPI": false, + "EnableExperimentalAPI": false, + "EnableFollowMode": false, + "EnableGossipBlockService": true, + "EnableIncomingMessageFilter": false, + "EnableLedgerService": false, + "EnableMetricReporting": false, + "EnableOutgoingNetworkMessageFiltering": true, + "EnablePingHandler": true, + "EnableProcessBlockStats": false, + "EnableProfiler": false, + "EnableRequestLogger": false, + "EnableRuntimeMetrics": false, + "EnableTopAccountsReporting": false, + "EnableTxBacklogRateLimiting": false, + "EnableTxnEvalTracer": false, + "EnableUsageLog": false, + "EnableVerbosedTransactionSyncLogging": false, + "EndpointAddress": "127.0.0.1:0", + "FallbackDNSResolverAddress": "", + "ForceFetchTransactions": false, + "ForceRelayMessages": false, + "GossipFanout": 4, + "HeartbeatUpdateInterval": 600, + "IncomingConnectionsLimit": 2400, + "IncomingMessageFilterBucketCount": 5, + "IncomingMessageFilterBucketSize": 512, + "LedgerSynchronousMode": 2, + "LogArchiveMaxAge": "", + "LogArchiveName": "node.archive.log", + "LogSizeLimit": 1073741824, + "MaxAPIBoxPerApplication": 100000, + "MaxAPIResourcesPerAccount": 100000, + "MaxAcctLookback": 4, + "MaxCatchpointDownloadDuration": 43200000000000, + "MaxConnectionsPerIP": 15, + "MinCatchpointFileDownloadBytesPerSecond": 20480, + "NetAddress": "", + "NetworkMessageTraceServer": "", + "NetworkProtocolVersion": "", + "NodeExporterListenAddress": ":9100", + "NodeExporterPath": "./node_exporter", + "OptimizeAccountsDatabaseOnStartup": false, + "OutgoingMessageFilterBucketCount": 3, + "OutgoingMessageFilterBucketSize": 128, + "P2PEnable": false, + "P2PPersistPeerID": true, + "P2PPrivateKeyLocation": "", + "ParticipationKeysRefreshInterval": 60000000000, + "PeerConnectionsUpdateInterval": 3600, + "PeerPingPeriodSeconds": 0, + "PriorityPeers": {}, + "ProposalAssemblyTime": 500000000, + "PublicAddress": "", + "ReconnectTime": 60000000000, + "ReservedFDs": 256, + "RestConnectionsHardLimit": 2048, + "RestConnectionsSoftLimit": 1024, + "RestReadTimeoutSeconds": 15, + "RestWriteTimeoutSeconds": 120, + "RunHosted": false, + "StorageEngine": "sqlite", + "SuggestedFeeBlockHistory": 3, + "SuggestedFeeSlidingWindowSize": 50, + "TLSCertFile": "", + "TLSKeyFile": "", + "TelemetryToLog": true, + "TransactionSyncDataExchangeRate": 0, + "TransactionSyncSignificantMessageThreshold": 0, + "TxBacklogReservedCapacityPerPeer": 20, + "TxBacklogServiceRateWindowSeconds": 10, + "TxBacklogSize": 26000, + "TxIncomingFilterMaxSize": 500000, + "TxIncomingFilteringFlags": 1, + "TxPoolExponentialIncreaseFactor": 2, + "TxPoolSize": 75000, + "TxSyncIntervalSeconds": 60, + "TxSyncServeResponseSize": 1000000, + "TxSyncTimeoutSeconds": 30, + "UseXForwardedForAddressField": "", + "VerifiedTranscationsCacheSize": 150000 +} From 9efdd656a752b6943407a78ccd5a02467e26cc70 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 26 Jul 2023 10:56:52 -0700 Subject: [PATCH 22/28] Remove v28 config changes --- test/testdata/configs/config-v28.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json index 3d3eb0b2fc..7b6ceb5326 100644 --- a/test/testdata/configs/config-v28.json +++ b/test/testdata/configs/config-v28.json @@ -85,9 +85,6 @@ "OptimizeAccountsDatabaseOnStartup": false, "OutgoingMessageFilterBucketCount": 3, "OutgoingMessageFilterBucketSize": 128, - "P2PEnable": false, - "P2PPersistPeerID": true, - "P2PPrivateKeyLocation": "", "ParticipationKeysRefreshInterval": 60000000000, "PeerConnectionsUpdateInterval": 3600, "PeerPingPeriodSeconds": 0, From 583881361f7485da5fb8946febfb1516089124e1 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Mon, 31 Jul 2023 12:35:06 -0700 Subject: [PATCH 23/28] Omit fallback controller if not specified --- cmd/algons/dnsaddrCmd.go | 4 +--- network/p2p/dnsaddr/resolveController.go | 10 ++++++++-- network/p2p/dnsaddr/resolveController_test.go | 15 ++++++++------- network/p2p/dnsaddr/resolve_test.go | 4 +--- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 83c9a898ff..1df13cecfe 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -21,9 +21,7 @@ import ( "github.com/spf13/cobra" - log "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/network/p2p/dnsaddr" - "github.com/algorand/go-algorand/tools/network" ) var ( @@ -54,7 +52,7 @@ var dnsaddrTreeCmd = &cobra.Command{ Short: "Recursively resolves and lists the dnsaddr entries of the given domain", Long: "Recursively resolves and lists the dnsaddr entries of the given domain", Run: func(cmd *cobra.Command, args []string) { - controller := dnsaddr.NewMultiaddrDNSResolveController(network.NewResolveController(secure, "", log.Base())) + controller := dnsaddr.NewMultiaddrDNSResolveController(secure, "") addrs, err := dnsaddr.MultiaddrsFromResolver(dnsaddrDomain, controller) if err != nil { fmt.Printf("%s\n", err.Error()) diff --git a/network/p2p/dnsaddr/resolveController.go b/network/p2p/dnsaddr/resolveController.go index d1558de584..7fb920ecb3 100644 --- a/network/p2p/dnsaddr/resolveController.go +++ b/network/p2p/dnsaddr/resolveController.go @@ -19,6 +19,7 @@ package dnsaddr import ( madns "github.com/multiformats/go-multiaddr-dns" + log "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/tools/network" ) @@ -30,10 +31,15 @@ type MultiaddrDNSResolveController struct { } // NewMultiaddrDNSResolveController constructs a MultiaddrDNSResolveController -func NewMultiaddrDNSResolveController(controller network.ResolveController) *MultiaddrDNSResolveController { +func NewMultiaddrDNSResolveController(secure bool, fallbackDNSResolverAddress string) *MultiaddrDNSResolveController { + controller := network.NewResolveController(secure, fallbackDNSResolverAddress, log.Base()) + nextResolvers := []func() *madns.Resolver{controller.SystemDnsaddrResolver} + if fallbackDNSResolverAddress != "" { + nextResolvers = append(nextResolvers, controller.FallbackDnsaddrResolver) + } return &MultiaddrDNSResolveController{ resolver: nil, - nextResolvers: []func() *madns.Resolver{controller.SystemDnsaddrResolver, controller.FallbackDnsaddrResolver, controller.DefaultDnsaddrResolver}, + nextResolvers: append(nextResolvers, controller.DefaultDnsaddrResolver), controller: controller, } } diff --git a/network/p2p/dnsaddr/resolveController_test.go b/network/p2p/dnsaddr/resolveController_test.go index e4a084a271..c097240ac6 100644 --- a/network/p2p/dnsaddr/resolveController_test.go +++ b/network/p2p/dnsaddr/resolveController_test.go @@ -21,24 +21,25 @@ import ( "github.com/stretchr/testify/assert" - log "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/test/partitiontest" - "github.com/algorand/go-algorand/tools/network" ) func TestDnsAddrResolveController(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() - controller := network.NewResolveController(true, "127.0.0.1", log.Base()) - dnsaddrCont := NewMultiaddrDNSResolveController(controller) + dnsaddrCont := NewMultiaddrDNSResolveController(true, "127.0.0.1") // Assert that the dnsaddr resolver cycles through the dns resolvers properly - assert.Equal(t, controller.SystemDnsaddrResolver(), dnsaddrCont.Resolver()) - assert.Equal(t, controller.FallbackDnsaddrResolver(), dnsaddrCont.NextResolver()) - assert.Equal(t, controller.DefaultDnsaddrResolver(), dnsaddrCont.NextResolver()) + assert.Equal(t, dnsaddrCont.controller.SystemDnsaddrResolver(), dnsaddrCont.Resolver()) + assert.Equal(t, dnsaddrCont.controller.FallbackDnsaddrResolver(), dnsaddrCont.NextResolver()) + assert.Equal(t, dnsaddrCont.controller.DefaultDnsaddrResolver(), dnsaddrCont.NextResolver()) // It should return nil once all the resolvers have been tried assert.Nil(t, dnsaddrCont.NextResolver()) assert.Nil(t, dnsaddrCont.NextResolver()) + // It should not include fallback if none was specified + dnsaddrCont = NewMultiaddrDNSResolveController(true, "") + assert.Equal(t, 2, len(dnsaddrCont.nextResolvers)) + } diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go index 75e7d4b830..df564d5e92 100644 --- a/network/p2p/dnsaddr/resolve_test.go +++ b/network/p2p/dnsaddr/resolve_test.go @@ -27,7 +27,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - log "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/test/partitiontest" "github.com/algorand/go-algorand/tools/network" ) @@ -61,8 +60,7 @@ func TestMultiaddrsFromResolver(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() - controller := network.NewResolveController(false, "", log.Base()) - dnsaddrCont := NewMultiaddrDNSResolveController(controller) + dnsaddrCont := NewMultiaddrDNSResolveController(false, "") // Fail on bad dnsaddr domain maddrs, err := MultiaddrsFromResolver("/bogus/foobar", dnsaddrCont) From 887c4b01fc44c84a127eb27bdd1b8b6e5d8f0f48 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 2 Aug 2023 15:41:40 -0700 Subject: [PATCH 24/28] Initial commit of algons dnsaddr tree create|delete --- cmd/algons/dnsCmd.go | 49 +++++++++---- cmd/algons/dnsaddrCmd.go | 107 ++++++++++++++++++++++++++++ network/p2p/dnsaddr/resolve.go | 45 +++++++----- network/p2p/dnsaddr/resolve_test.go | 4 +- 4 files changed, 173 insertions(+), 32 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index 10b4c18881..ca6925fb45 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -105,7 +105,7 @@ var listRecordsCmd = &cobra.Command{ Long: "List the A/SRV entries of the given network", Run: func(cmd *cobra.Command, args []string) { recordType = strings.ToUpper(recordType) - if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" { + if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" || recordType == "TXT" { listEntries(listNetwork, recordType) } else { fmt.Fprintf(os.Stderr, "Invalid recordType specified.\n") @@ -181,6 +181,19 @@ var exportCmd = &cobra.Command{ }, } +func doAddTXT(from string, to string) error { + cfZoneID, cfToken, err := getClouldflareCredentials() + if err != nil { + return fmt.Errorf("error getting DNS credentials: %v", err) + } + + cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) + + const priority = 1 + const proxied = false + return cloudflareDNS.CreateDNSRecord(context.Background(), "TXT", from, to, cloudflare.AutomaticTTL, priority, proxied) +} + func doAddDNS(from string, to string) (err error) { cfZoneID, cfToken, err := getClouldflareCredentials() if err != nil { @@ -315,7 +328,7 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) - idsToDelete := make(map[string]string) // Maps record ID to Name + var idsToDelete []cloudflare.DNSRecordResponseEntry services := []string{"_algobootstrap", "_metrics"} servicesRegexp, err := regexp.Compile("^(_algobootstrap|_metrics)\\._tcp\\..*algodev.network$") @@ -355,7 +368,7 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa if includeRegex == nil || (includeRegex.MatchString(r.Name) && servicesRegexp.MatchString(r.Name)) { fmt.Printf("Found SRV record: %s\n", r.Name) - idsToDelete[r.ID] = r.Name + idsToDelete = append(idsToDelete, r) } } } @@ -367,7 +380,7 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa networkSuffix = "." + network + ".algodev.network" } - for _, recordType := range []string{"A", "CNAME"} { + for _, recordType := range []string{"A", "CNAME", "TXT"} { records, err := cloudflareDNS.ListDNSRecord(context.Background(), recordType, "", "", "", "", "") if err != nil { fmt.Fprintf(os.Stderr, "Error listing DNS '%s' entries: %v\n", recordType, err) @@ -384,21 +397,29 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa if includeRegex == nil || includeRegex.MatchString(r.Name) { fmt.Printf("Found DNS '%s' record: %s\n", recordType, r.Name) - idsToDelete[r.ID] = r.Name + idsToDelete = append(idsToDelete, r) } } } } - if len(idsToDelete) == 0 { + err = checkedDelete(idsToDelete, cloudflareDNS) + if err != nil { + fmt.Fprintf(os.Stderr, "Error deleting: %s\n", err) + } + return true +} + +func checkedDelete(toDelete []cloudflare.DNSRecordResponseEntry, cloudflareDNS *cloudflare.DNS) error { + if len(toDelete) == 0 { fmt.Printf("No DNS/SRV records found\n") - return true + return nil } var text string if !noPrompt { reader := bufio.NewReader(os.Stdin) - fmt.Printf("Delete these %d entries (type 'yes' to delete)? ", len(idsToDelete)) + fmt.Printf("Delete these %d entries (type 'yes' to delete)? ", len(toDelete)) text, _ = reader.ReadString('\n') text = strings.Replace(text, "\n", "", -1) } else { @@ -406,15 +427,15 @@ func doDeleteDNS(network string, noPrompt bool, excludePattern string, includePa } if text == "yes" { - for id, name := range idsToDelete { - fmt.Fprintf(os.Stdout, "Deleting %s\n", name) - err = cloudflareDNS.DeleteDNSRecord(context.Background(), id) + for _, entry := range toDelete { + fmt.Fprintf(os.Stdout, "Deleting %s\n", entry.Name) + err := cloudflareDNS.DeleteDNSRecord(context.Background(), entry.ID) if err != nil { - fmt.Fprintf(os.Stderr, " !! error deleting %s: %v\n", name, err) + return fmt.Errorf(" !! error deleting %s: %v\n", entry.Name, err) } } } - return true + return nil } func listEntries(listNetwork string, recordType string) { @@ -425,7 +446,7 @@ func listEntries(listNetwork string, recordType string) { } cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) - recordTypes := []string{"A", "CNAME", "SRV"} + recordTypes := []string{"A", "CNAME", "SRV", "TXT"} if recordType != "" { recordTypes = []string{recordType} } diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 1df13cecfe..c7ab7d9546 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -17,16 +17,21 @@ package main import ( + "context" "fmt" + "os" + "github.com/multiformats/go-multiaddr" "github.com/spf13/cobra" "github.com/algorand/go-algorand/network/p2p/dnsaddr" + "github.com/algorand/go-algorand/tools/network/cloudflare" ) var ( dnsaddrDomain string secure bool + cmdMultiaddrs []string ) func init() { @@ -35,6 +40,16 @@ func init() { dnsaddrTreeCmd.Flags().StringVarP(&dnsaddrDomain, "domain", "d", "", "Top level domain") dnsaddrTreeCmd.MarkFlagRequired("domain") dnsaddrTreeCmd.Flags().BoolVarP(&secure, "secure", "s", true, "Enable dnssec") + + dnsaddrTreeCmd.AddCommand(dnsaddrTreeCreateCmd) + dnsaddrTreeCreateCmd.Flags().StringArrayVarP(&cmdMultiaddrs, "multiaddrs", "m", []string{}, "multiaddrs to add") + dnsaddrTreeCreateCmd.Flags().StringVarP(&dnsaddrDomain, "domain", "d", "", "Top level domain") + dnsaddrTreeCreateCmd.MarkFlagRequired("domain") + dnsaddrTreeCreateCmd.MarkFlagRequired("multiaddrs") + + dnsaddrTreeCmd.AddCommand(dnsaddrTreeDeleteCmd) + dnsaddrTreeDeleteCmd.Flags().StringVarP(&dnsaddrDomain, "domain", "d", "", "Top level domain") + dnsaddrTreeDeleteCmd.MarkFlagRequired("domain") } var dnsaddrCmd = &cobra.Command{ @@ -63,3 +78,95 @@ var dnsaddrTreeCmd = &cobra.Command{ } }, } + +var dnsaddrTreeDeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Recursively resolves and deletes the dnsaddr entries of the given domain", + Long: "Recursively resolves and deletes the dnsaddr entries of the given domain", + Run: func(cmd *cobra.Command, args []string) { + addr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", dnsaddrDomain)) + if err != nil { + fmt.Printf("unable to construct multiaddr for %s : %v\n", dnsaddrDomain, err) + return + } + controller := dnsaddr.NewMultiaddrDNSResolveController(secure, "") + cfZoneID, cfToken, err := getClouldflareCredentials() + if err != nil { + fmt.Fprintf(os.Stderr, "error getting DNS credentials: %v", err) + return + } + cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) + var recordsToDelete []cloudflare.DNSRecordResponseEntry + err = dnsaddr.Iterate(addr, controller, func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { + domain, _ := dnsaddr.ValueForProtocol(multiaddr.P_DNSADDR) + name := fmt.Sprintf("_dnsaddr.%s", domain) + fmt.Printf("listing records for %s\n", name) + records, err := cloudflareDNS.ListDNSRecord(context.Background(), "TXT", name, "", "", "", "") + if err != nil { + fmt.Printf("erroring listing dns records for %s %s\n", domain, err) + return err + } + for _, record := range records { + fmt.Printf("found record to delete %s:%s\n", record.Name, record.Content) + recordsToDelete = append(recordsToDelete, record) + } + return nil + }) + if err != nil { + fmt.Printf("%s\n", err.Error()) + return + } + err = checkedDelete(recordsToDelete, cloudflareDNS) + if err != nil { + fmt.Printf("error deleting records: %s\n", err) + } + }, +} + +var dnsaddrTreeCreateCmd = &cobra.Command{ + Use: "create", + Short: "Creates a tree of entries containing the multiaddrs at the provided root domain", + Long: "Creates a tree of entries containing the multiaddrs at the provided root domain", + Run: func(cmd *cobra.Command, args []string) { + if len(cmdMultiaddrs) == 0 { + fmt.Printf("must provide multiaddrs to put in the DNS records") + return + } + recordsPerEntry := 4 + // Generate the dnsaddr entries required for the full tree + var dnsaddrsTo []string + for i := 0; i < len(cmdMultiaddrs)/recordsPerEntry; i++ { + dnsaddrsTo = append(dnsaddrsTo, fmt.Sprintf("%d%s", i, dnsaddrDomain)) + } + dnsaddrsFrom := []string{fmt.Sprintf("_dnsaddr.%s", dnsaddrDomain)} + for _, addrTo := range dnsaddrsTo { + dnsaddrsFrom = append(dnsaddrsFrom, fmt.Sprintf("_dnsaddr.%s", addrTo)) + } + for _, from := range dnsaddrsFrom { + for i := 0; i < recordsPerEntry; i++ { + if len(dnsaddrsTo) > 0 { + newDnsaddr := fmt.Sprintf("dnsaddr=/dnsaddr/%s", dnsaddrsTo[len(dnsaddrsTo)-1]) + fmt.Printf("writing %s => %s\n", from, newDnsaddr) + err := doAddTXT(from, newDnsaddr) + if err != nil { + fmt.Printf("failed writing dnsaddr entry %s: %s\n", newDnsaddr, err) + return + } + dnsaddrsTo = dnsaddrsTo[:len(dnsaddrsTo)-1] + continue + } + newDnsaddr := fmt.Sprintf("dnsaddr=%s", cmdMultiaddrs[len(cmdMultiaddrs)-1]) + fmt.Printf("writing %s => %s\n", from, newDnsaddr) + err := doAddTXT(from, newDnsaddr) + if err != nil { + fmt.Printf("failed writing dns entry %s\n", err) + return + } + cmdMultiaddrs = cmdMultiaddrs[:len(cmdMultiaddrs)-1] + if len(cmdMultiaddrs) == 0 { + return + } + } + } + }, +} diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go index ad9f4e8b42..9ac3010415 100644 --- a/network/p2p/dnsaddr/resolve.go +++ b/network/p2p/dnsaddr/resolve.go @@ -29,21 +29,12 @@ func isDnsaddr(maddr multiaddr.Multiaddr) bool { return first.Protocol().Code == multiaddr.P_DNSADDR } -// MultiaddrsFromResolver attempts to recurse through dnsaddrs starting at domain. -// Any further dnsaddrs will be looked up until all TXT records have been fetched, -// and the full list of resulting Multiaddrs is returned. -// It uses the MultiaddrDNSResolveController to cycle through DNS resolvers on failure. -func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveController) ([]multiaddr.Multiaddr, error) { +func Iterate(initial multiaddr.Multiaddr, controller *MultiaddrDNSResolveController, f func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error) error { resolver := controller.Resolver() if resolver == nil { - return nil, errors.New("passed controller has no resolvers MultiaddrsFromResolver") - } - dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", domain)) - if err != nil { - return nil, fmt.Errorf("unable to construct multiaddr for %s : %v", domain, err) + return errors.New("passed controller has no resolvers Iterate") } - var resolved []multiaddr.Multiaddr - var toResolve = []multiaddr.Multiaddr{dnsaddr} + var toResolve = []multiaddr.Multiaddr{initial} for resolver != nil && len(toResolve) > 0 { curr := toResolve[0] maddrs, resolveErr := resolver.Resolve(context.Background(), curr) @@ -51,18 +42,40 @@ func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveContro resolver = controller.NextResolver() // If we errored, and have exhausted all resolvers, just return if resolver == nil { - return resolved, resolveErr + return resolveErr } continue } for _, maddr := range maddrs { if isDnsaddr(maddr) { toResolve = append(toResolve, maddr) - } else { - resolved = append(resolved, maddr) } } + if err := f(curr, maddrs); err != nil { + return err + } toResolve = toResolve[1:] } - return resolved, nil + return nil +} + +// MultiaddrsFromResolver attempts to recurse through dnsaddrs starting at domain. +// Any further dnsaddrs will be looked up until all TXT records have been fetched, +// and the full list of resulting Multiaddrs is returned. +// It uses the MultiaddrDNSResolveController to cycle through DNS resolvers on failure. +func MultiaddrsFromResolver(domain string, controller *MultiaddrDNSResolveController) ([]multiaddr.Multiaddr, error) { + dnsaddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", domain)) + if err != nil { + return nil, fmt.Errorf("unable to construct multiaddr for %s : %v", domain, err) + } + var resolved []multiaddr.Multiaddr + err = Iterate(dnsaddr, controller, func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { + for _, maddr := range entries { + if !isDnsaddr(maddr) { + resolved = append(resolved, maddr) + } + } + return nil + }) + return resolved, err } diff --git a/network/p2p/dnsaddr/resolve_test.go b/network/p2p/dnsaddr/resolve_test.go index df564d5e92..2834a2a5e7 100644 --- a/network/p2p/dnsaddr/resolve_test.go +++ b/network/p2p/dnsaddr/resolve_test.go @@ -94,9 +94,9 @@ func TestMultiaddrsFromResolverDnsFailure(t *testing.T) { } // Fail on no resolver - maddrs, err := MultiaddrsFromResolver("", dnsaddrCont) + maddrs, err := MultiaddrsFromResolver("0.0.0.1", dnsaddrCont) assert.Empty(t, maddrs) - assert.ErrorContains(t, err, fmt.Sprintf("passed controller has no resolvers MultiaddrsFromResolver")) + assert.ErrorContains(t, err, fmt.Sprintf("passed controller has no resolvers Iterate")) resolver, _ := madns.NewResolver(madns.WithDefaultResolver(&failureResolver{})) dnsaddrCont = &MultiaddrDNSResolveController{ From f122b6838bca97d24b1e50262569fb1267049927 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Wed, 2 Aug 2023 16:10:46 -0700 Subject: [PATCH 25/28] Fix lint --- cmd/algons/dnsCmd.go | 2 +- cmd/algons/dnsaddrCmd.go | 4 ++-- network/p2p/dnsaddr/resolve.go | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index ca6925fb45..00e30a9291 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -431,7 +431,7 @@ func checkedDelete(toDelete []cloudflare.DNSRecordResponseEntry, cloudflareDNS * fmt.Fprintf(os.Stdout, "Deleting %s\n", entry.Name) err := cloudflareDNS.DeleteDNSRecord(context.Background(), entry.ID) if err != nil { - return fmt.Errorf(" !! error deleting %s: %v\n", entry.Name, err) + return fmt.Errorf(" !! error deleting %s: %v", entry.Name, err) } } } diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 82dcca59e0..8649a50077 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -100,8 +100,8 @@ var dnsaddrTreeDeleteCmd = &cobra.Command{ domain, _ := entryFrom.ValueForProtocol(multiaddr.P_DNSADDR) name := fmt.Sprintf("_dnsaddr.%s", domain) fmt.Printf("listing records for %s\n", name) - records, err := cloudflareDNS.ListDNSRecord(context.Background(), "TXT", name, "", "", "", "") - if err != nil { + records, err0 := cloudflareDNS.ListDNSRecord(context.Background(), "TXT", name, "", "", "", "") + if err0 != nil { fmt.Printf("erroring listing dns records for %s %s\n", domain, err) return err } diff --git a/network/p2p/dnsaddr/resolve.go b/network/p2p/dnsaddr/resolve.go index 2289033aee..0e21a5704a 100644 --- a/network/p2p/dnsaddr/resolve.go +++ b/network/p2p/dnsaddr/resolve.go @@ -29,6 +29,7 @@ func isDnsaddr(maddr multiaddr.Multiaddr) bool { return first.Protocol().Code == multiaddr.P_DNSADDR } +// Iterate runs through the resolvable dnsaddrs in the tree using the resolveController and invokes f for each dnsaddr node lookup func Iterate(initial multiaddr.Multiaddr, controller *MultiaddrDNSResolveController, f func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error) error { resolver := controller.Resolver() if resolver == nil { From c2655e0bc28bb4c581798600eda382cbb7f5de33 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Tue, 8 Aug 2023 09:17:03 -0700 Subject: [PATCH 26/28] Move nodeSize to arg, provide high default --- cmd/algons/dnsaddrCmd.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 8649a50077..137e35aed6 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -32,6 +32,7 @@ var ( dnsaddrDomain string secure bool cmdMultiaddrs []string + nodeSize int ) func init() { @@ -44,6 +45,7 @@ func init() { dnsaddrTreeCmd.AddCommand(dnsaddrTreeCreateCmd) dnsaddrTreeCreateCmd.Flags().StringArrayVarP(&cmdMultiaddrs, "multiaddrs", "m", []string{}, "multiaddrs to add") dnsaddrTreeCreateCmd.Flags().StringVarP(&dnsaddrDomain, "domain", "d", "", "Top level domain") + dnsaddrTreeCreateCmd.Flags().IntVarP(&nodeSize, "node-size", "n", 50, "Number of multiaddrs entries per TXT record") dnsaddrTreeCreateCmd.MarkFlagRequired("domain") dnsaddrTreeCreateCmd.MarkFlagRequired("multiaddrs") @@ -131,10 +133,9 @@ var dnsaddrTreeCreateCmd = &cobra.Command{ fmt.Printf("must provide multiaddrs to put in the DNS records") return } - recordsPerEntry := 4 // Generate the dnsaddr entries required for the full tree var dnsaddrsTo []string - for i := 0; i < len(cmdMultiaddrs)/recordsPerEntry; i++ { + for i := 0; i < len(cmdMultiaddrs)/nodeSize; i++ { dnsaddrsTo = append(dnsaddrsTo, fmt.Sprintf("%d%s", i, dnsaddrDomain)) } dnsaddrsFrom := []string{fmt.Sprintf("_dnsaddr.%s", dnsaddrDomain)} @@ -142,7 +143,7 @@ var dnsaddrTreeCreateCmd = &cobra.Command{ dnsaddrsFrom = append(dnsaddrsFrom, fmt.Sprintf("_dnsaddr.%s", addrTo)) } for _, from := range dnsaddrsFrom { - for i := 0; i < recordsPerEntry; i++ { + for i := 0; i < nodeSize; i++ { if len(dnsaddrsTo) > 0 { newDnsaddr := fmt.Sprintf("dnsaddr=/dnsaddr/%s", dnsaddrsTo[len(dnsaddrsTo)-1]) fmt.Printf("writing %s => %s\n", from, newDnsaddr) From 70cf8ff89aec7f84f70c2ae7a23e7aa0dc417f65 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Fri, 11 Aug 2023 09:19:00 -0700 Subject: [PATCH 27/28] PR comments --- cmd/algons/dnsCmd.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index 00e30a9291..e5e9119a6a 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -105,10 +105,9 @@ var listRecordsCmd = &cobra.Command{ Long: "List the A/SRV entries of the given network", Run: func(cmd *cobra.Command, args []string) { recordType = strings.ToUpper(recordType) - if recordType == "" || recordType == "A" || recordType == "CNAME" || recordType == "SRV" || recordType == "TXT" { - listEntries(listNetwork, recordType) - } else { - fmt.Fprintf(os.Stderr, "Invalid recordType specified.\n") + err := listEntries(listNetwork, recordType) + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } }, @@ -438,23 +437,31 @@ func checkedDelete(toDelete []cloudflare.DNSRecordResponseEntry, cloudflareDNS * return nil } -func listEntries(listNetwork string, recordType string) { +func listEntries(listNetwork string, recordType string) error { + recordTypes := []string{"A", "CNAME", "SRV", "TXT"} + isKnown := false + for _, known := range append(recordTypes, "") { + if recordType == known { + isKnown = true + break + } + } + if !isKnown { + return fmt.Errorf("invalid recordType specified %s", recordType) + } cfZoneID, cfToken, err := getClouldflareCredentials() if err != nil { - fmt.Fprintf(os.Stderr, "error getting DNS credentials: %v", err) - return + return fmt.Errorf("error getting DNS credentials: %v", err) } cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) - recordTypes := []string{"A", "CNAME", "SRV", "TXT"} if recordType != "" { recordTypes = []string{recordType} } for _, recType := range recordTypes { - records, err := cloudflareDNS.ListDNSRecord(context.Background(), recType, "", "", "", "", "") - if err != nil { - fmt.Fprintf(os.Stderr, "Error listing DNS entries: %v\n", err) - os.Exit(1) + records, err0 := cloudflareDNS.ListDNSRecord(context.Background(), recType, "", "", "", "", "") + if err0 != nil { + return fmt.Errorf("error listing DNS entries %w", err) } for _, record := range records { @@ -463,6 +470,7 @@ func listEntries(listNetwork string, recordType string) { } } } + return nil } func doExportZone(network string, outputFilename string) bool { From 95efdb7b73d8804e8a62fc0f4fb5645a0f123973 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Fri, 11 Aug 2023 09:42:50 -0700 Subject: [PATCH 28/28] Small refactoring --- cmd/algons/dnsCmd.go | 28 ++++++++++++++++++---------- cmd/algons/dnsaddrCmd.go | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/cmd/algons/dnsCmd.go b/cmd/algons/dnsCmd.go index e5e9119a6a..97b3b5f334 100644 --- a/cmd/algons/dnsCmd.go +++ b/cmd/algons/dnsCmd.go @@ -437,7 +437,7 @@ func checkedDelete(toDelete []cloudflare.DNSRecordResponseEntry, cloudflareDNS * return nil } -func listEntries(listNetwork string, recordType string) error { +func getEntries(getNetwork string, recordType string) ([]cloudflare.DNSRecordResponseEntry, error) { recordTypes := []string{"A", "CNAME", "SRV", "TXT"} isKnown := false for _, known := range append(recordTypes, "") { @@ -447,27 +447,35 @@ func listEntries(listNetwork string, recordType string) error { } } if !isKnown { - return fmt.Errorf("invalid recordType specified %s", recordType) + return nil, fmt.Errorf("invalid recordType specified %s", recordType) } cfZoneID, cfToken, err := getClouldflareCredentials() if err != nil { - return fmt.Errorf("error getting DNS credentials: %v", err) + return nil, fmt.Errorf("error getting DNS credentials: %v", err) } cloudflareDNS := cloudflare.NewDNS(cfZoneID, cfToken) if recordType != "" { recordTypes = []string{recordType} } + var records []cloudflare.DNSRecordResponseEntry for _, recType := range recordTypes { - records, err0 := cloudflareDNS.ListDNSRecord(context.Background(), recType, "", "", "", "", "") - if err0 != nil { - return fmt.Errorf("error listing DNS entries %w", err) + records, err = cloudflareDNS.ListDNSRecord(context.Background(), recType, getNetwork, "", "", "", "") + if err != nil { + return nil, fmt.Errorf("error listing DNS entries %w", err) } + } + return records, nil +} - for _, record := range records { - if strings.HasSuffix(record.Name, listNetwork) { - fmt.Printf("%v\n", record.Name) - } +func listEntries(listNetwork string, recordType string) error { + records, err := getEntries("", recordType) + if err != nil { + return err + } + for _, record := range records { + if strings.HasSuffix(record.Name, listNetwork) { + fmt.Printf("%v\n", record.Name) } } return nil diff --git a/cmd/algons/dnsaddrCmd.go b/cmd/algons/dnsaddrCmd.go index 137e35aed6..1d9189082b 100644 --- a/cmd/algons/dnsaddrCmd.go +++ b/cmd/algons/dnsaddrCmd.go @@ -139,6 +139,18 @@ var dnsaddrTreeCreateCmd = &cobra.Command{ dnsaddrsTo = append(dnsaddrsTo, fmt.Sprintf("%d%s", i, dnsaddrDomain)) } dnsaddrsFrom := []string{fmt.Sprintf("_dnsaddr.%s", dnsaddrDomain)} + entries, err := getEntries(dnsaddrsFrom[0], "TXT") + if err != nil { + fmt.Printf("failed fetching entries for %s\n", dnsaddrsFrom[0]) + os.Exit(1) + } + if len(entries) > 0 { + for _, entry := range entries { + fmt.Printf("found entry %s => %s\n", entry.Name, entry.Content) + } + fmt.Printf("found entries already existing at %s, bailing out\n", dnsaddrsFrom[0]) + os.Exit(1) + } for _, addrTo := range dnsaddrsTo { dnsaddrsFrom = append(dnsaddrsFrom, fmt.Sprintf("_dnsaddr.%s", addrTo)) } @@ -150,7 +162,7 @@ var dnsaddrTreeCreateCmd = &cobra.Command{ err := doAddTXT(from, newDnsaddr) if err != nil { fmt.Printf("failed writing dnsaddr entry %s: %s\n", newDnsaddr, err) - return + os.Exit(1) } dnsaddrsTo = dnsaddrsTo[:len(dnsaddrsTo)-1] continue @@ -160,7 +172,7 @@ var dnsaddrTreeCreateCmd = &cobra.Command{ err := doAddTXT(from, newDnsaddr) if err != nil { fmt.Printf("failed writing dns entry %s\n", err) - return + os.Exit(1) } cmdMultiaddrs = cmdMultiaddrs[:len(cmdMultiaddrs)-1] if len(cmdMultiaddrs) == 0 {