From 605978b9c3f7bd84b33dfbcecd7392280cb62469 Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Thu, 28 Aug 2014 20:49:41 +0200 Subject: [PATCH 01/75] e3x: working on channel implementation --- LICENSE | 191 ++++++++++++++++++++++++++++++++ README.md | 3 + _examples/nat-tester.go | 67 +++++++++++ nat.go | 42 +++++++ natpmp.go | 178 ++++++++++++++++++++++++++++++ upnp.go | 239 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 720 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 _examples/nat-tester.go create mode 100644 nat.go create mode 100644 natpmp.go create mode 100644 upnp.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..37ec93a14f --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets "[]" replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same "printed page" as the copyright notice for easier identification within +third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000000..24ddea09e6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# go-nat + +[![GoDoc](https://godoc.org/github.com/fd/go-nat?status.svg)](https://godoc.org/github.com/fd/go-nat) [![status](https://sourcegraph.com/api/repos/github.com/fd/go-nat/.badges/status.png)](https://sourcegraph.com/github.com/fd/go-nat) diff --git a/_examples/nat-tester.go b/_examples/nat-tester.go new file mode 100644 index 0000000000..1033293888 --- /dev/null +++ b/_examples/nat-tester.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "time" + + "bitbucket.org/simonmenke/go-telehash/util/nat" +) + +func main() { + nat, err := nat.Discover() + if err != nil { + log.Fatalf("error: %s", err) + } + log.Printf("nat type: %s", nat.Type()) + + daddr, err := nat.GetDeviceAddress() + if err != nil { + log.Fatalf("error: %s", err) + } + log.Printf("device address: %s", daddr) + + iaddr, err := nat.GetInternalAddress() + if err != nil { + log.Fatalf("error: %s", err) + } + log.Printf("internal address: %s", iaddr) + + eaddr, err := nat.GetExternalAddress() + if err != nil { + log.Fatalf("error: %s", err) + } + log.Printf("external address: %s", eaddr) + + eport, err := nat.AddPortMapping("tcp", 3080, "http", 60) + if err != nil { + log.Fatalf("error: %s", err) + } + + log.Printf("test-page: http://%s:%d/", eaddr, eport) + + go func() { + for { + time.Sleep(30 * time.Second) + + _, err = nat.AddPortMapping("tcp", 3080, "http", 60) + if err != nil { + log.Fatalf("error: %s", err) + } + } + }() + + defer nat.DeletePortMapping("txp", 3080) + + http.ListenAndServe(":3080", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.Header().Set("Content-Type", "text/plain") + rw.WriteHeader(200) + fmt.Fprintf(rw, "Hello there!\n") + fmt.Fprintf(rw, "nat type: %s\n", nat.Type()) + fmt.Fprintf(rw, "device address: %s\n", daddr) + fmt.Fprintf(rw, "internal address: %s\n", iaddr) + fmt.Fprintf(rw, "external address: %s\n", eaddr) + fmt.Fprintf(rw, "test-page: http://%s:%d/\n", eaddr, eport) + })) +} diff --git a/nat.go b/nat.go new file mode 100644 index 0000000000..59b970f4f4 --- /dev/null +++ b/nat.go @@ -0,0 +1,42 @@ +package nat + +import ( + "errors" + "math" + "math/rand" + "net" + "time" +) + +var ErrNoExternalAddress = errors.New("nat: no external address") +var ErrNoInternalAddress = errors.New("nat: no internal address") +var ErrNoNATFound = errors.New("nat: no NAT found") + +// protocol is either "udp" or "tcp" +type NAT interface { + Type() string + GetDeviceAddress() (addr net.IP, err error) + GetInternalAddress() (addr net.IP, err error) + GetExternalAddress() (addr net.IP, err error) + + AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error) + DeletePortMapping(protocol string, internalPort int) (err error) +} + +func Discover() (NAT, error) { + select { + case nat := <-discoverUPNP_IG1(): + return nat, nil + case nat := <-discoverUPNP_IG2(): + return nat, nil + case nat := <-discoverNATPMP(): + return nat, nil + case <-time.After(10 * time.Second): + return nil, ErrNoNATFound + } +} + +func randomPort() int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(math.MaxUint16-10000) + 10000 +} diff --git a/natpmp.go b/natpmp.go new file mode 100644 index 0000000000..8bc6c07171 --- /dev/null +++ b/natpmp.go @@ -0,0 +1,178 @@ +package nat + +import ( + "net" + "time" + + "github.com/jackpal/go-nat-pmp" +) + +var ( + _ NAT = (*natpmp_NAT)(nil) +) + +func natpmp_PotentialGateways() ([]net.IP, error) { + _, ipNet_10, err := net.ParseCIDR("10.0.0.0/8") + if err != nil { + panic(err) + } + + _, ipNet_172_16, err := net.ParseCIDR("172.16.0.0/12") + if err != nil { + panic(err) + } + + _, ipNet_192_168, err := net.ParseCIDR("192.168.0.0/16") + if err != nil { + panic(err) + } + + ifaces, err := net.Interfaces() + if err != nil { + return nil, err + } + + var ips []net.IP + + for _, iface := range ifaces { + addrs, err := iface.Addrs() + if err != nil { + return nil, err + } + + for _, addr := range addrs { + switch x := addr.(type) { + case *net.IPNet: + var ipNet *net.IPNet + if ipNet_10.Contains(x.IP) { + ipNet = ipNet_10 + } else if ipNet_172_16.Contains(x.IP) { + ipNet = ipNet_172_16 + } else if ipNet_192_168.Contains(x.IP) { + ipNet = ipNet_192_168 + } + + if ipNet != nil { + ip := x.IP.Mask(x.Mask) + ip = ip.To4() + if ip != nil { + ip[3] = ip[3] | 0x01 + ips = append(ips, ip) + } + } + } + } + } + + if len(ips) == 0 { + return nil, ErrNoNATFound + } + + return ips, nil +} + +func discoverNATPMP() <-chan NAT { + ips, err := natpmp_PotentialGateways() + if err != nil { + return nil + } + + res := make(chan NAT, len(ips)) + + for _, ip := range ips { + go discoverNATPMPWithAddr(res, ip) + } + + return res +} + +func discoverNATPMPWithAddr(c chan NAT, ip net.IP) { + client := natpmp.NewClient(ip) + _, err := client.GetExternalAddress() + if err != nil { + return + } + + c <- &natpmp_NAT{client, ip, make(map[int]int)} +} + +type natpmp_NAT struct { + c *natpmp.Client + gateway net.IP + ports map[int]int +} + +func (n *natpmp_NAT) GetDeviceAddress() (addr net.IP, err error) { + return n.gateway, nil +} + +func (n *natpmp_NAT) GetInternalAddress() (addr net.IP, err error) { + ifaces, err := net.Interfaces() + if err != nil { + return nil, err + } + + for _, iface := range ifaces { + addrs, err := iface.Addrs() + if err != nil { + return nil, err + } + + for _, addr := range addrs { + switch x := addr.(type) { + case *net.IPNet: + if x.Contains(n.gateway) { + return x.IP, nil + } + } + } + } + + return nil, ErrNoInternalAddress +} + +func (n *natpmp_NAT) GetExternalAddress() (addr net.IP, err error) { + res, err := n.c.GetExternalAddress() + if err != nil { + return nil, err + } + + d := res.ExternalIPAddress + return net.IPv4(d[0], d[1], d[2], d[3]), nil +} + +func (n *natpmp_NAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { + var ( + err error + ) + + timeoutInSeconds := int(timeout / time.Second) + + if externalPort := n.ports[internalPort]; externalPort > 0 { + _, err = n.c.AddPortMapping(protocol, internalPort, externalPort, timeoutInSeconds) + if err == nil { + n.ports[internalPort] = externalPort + return externalPort, nil + } + } + + for i := 0; i < 3; i++ { + externalPort := randomPort() + _, err = n.c.AddPortMapping(protocol, internalPort, externalPort, timeoutInSeconds) + if err == nil { + n.ports[internalPort] = externalPort + return externalPort, nil + } + } + + return 0, err +} + +func (n *natpmp_NAT) DeletePortMapping(protocol string, internalPort int) (err error) { + delete(n.ports, internalPort) + return nil +} + +func (n *natpmp_NAT) Type() string { + return "NAT-PMP" +} diff --git a/upnp.go b/upnp.go new file mode 100644 index 0000000000..b27ca1e9a9 --- /dev/null +++ b/upnp.go @@ -0,0 +1,239 @@ +package nat + +import ( + "net" + "time" + + "github.com/huin/goupnp" + "github.com/huin/goupnp/dcps/internetgateway1" + "github.com/huin/goupnp/dcps/internetgateway2" +) + +var ( + _ NAT = (*upnp_NAT)(nil) +) + +func discoverUPNP_IG1() <-chan NAT { + res := make(chan NAT, 1) + go func() { + + // find devices + devs, err := goupnp.DiscoverDevices(internetgateway1.URN_WANConnectionDevice_1) + if err != nil { + return + } + + for _, dev := range devs { + if dev.Root == nil { + continue + } + + dev.Root.Device.VisitServices(func(srv *goupnp.Service) { + switch srv.ServiceType { + case internetgateway1.URN_WANIPConnection_1: + client := &internetgateway1.WANIPConnection1{goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: dev.Root, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", dev.Root} + return + } + + case internetgateway1.URN_WANPPPConnection_1: + client := &internetgateway1.WANPPPConnection1{goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: dev.Root, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", dev.Root} + return + } + + } + }) + } + + }() + return res +} + +func discoverUPNP_IG2() <-chan NAT { + res := make(chan NAT, 1) + go func() { + + // find devices + devs, err := goupnp.DiscoverDevices(internetgateway2.URN_WANConnectionDevice_2) + if err != nil { + return + } + + for _, dev := range devs { + if dev.Root == nil { + continue + } + + dev.Root.Device.VisitServices(func(srv *goupnp.Service) { + switch srv.ServiceType { + case internetgateway2.URN_WANIPConnection_1: + client := &internetgateway2.WANIPConnection1{goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: dev.Root, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP1)", dev.Root} + return + } + + case internetgateway2.URN_WANIPConnection_2: + client := &internetgateway2.WANIPConnection2{goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: dev.Root, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP2)", dev.Root} + return + } + + case internetgateway2.URN_WANPPPConnection_1: + client := &internetgateway2.WANPPPConnection1{goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: dev.Root, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-PPP1)", dev.Root} + return + } + + } + }) + } + + }() + return res +} + +type upnp_NAT_Client interface { + GetExternalIPAddress() (string, error) + AddPortMapping(string, uint16, string, uint16, string, bool, string, uint32) error + DeletePortMapping(string, uint16, string) error +} + +type upnp_NAT struct { + c upnp_NAT_Client + ports map[int]int + typ string + rootDevice *goupnp.RootDevice +} + +func (u *upnp_NAT) GetExternalAddress() (addr net.IP, err error) { + ipString, err := u.c.GetExternalIPAddress() + if err != nil { + return nil, err + } + + ip := net.ParseIP(ipString) + if ip == nil { + return nil, ErrNoExternalAddress + } + + return ip, nil +} + +func mapProtocol(s string) string { + switch s { + case "udp": + return "UDP" + case "tcp": + return "TCP" + default: + panic("invalid protocol: " + s) + } +} + +func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { + ip, err := u.GetInternalAddress() + if err != nil { + return 0, nil + } + + timeoutInSeconds := uint32(timeout / time.Second) + + if externalPort := u.ports[internalPort]; externalPort > 0 { + err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) + if err == nil { + return externalPort, nil + } + } + + for i := 0; i < 3; i++ { + externalPort := randomPort() + err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) + if err == nil { + u.ports[internalPort] = externalPort + return externalPort, nil + } + } + + return 0, err +} + +func (u *upnp_NAT) DeletePortMapping(protocol string, internalPort int) error { + if externalPort := u.ports[internalPort]; externalPort > 0 { + delete(u.ports, internalPort) + return u.c.DeletePortMapping("", uint16(externalPort), mapProtocol(protocol)) + } + + return nil +} + +func (u *upnp_NAT) GetDeviceAddress() (net.IP, error) { + addr, err := net.ResolveUDPAddr("udp4", u.rootDevice.URLBase.Host) + if err != nil { + return nil, err + } + + return addr.IP, nil +} + +func (u *upnp_NAT) GetInternalAddress() (net.IP, error) { + devAddr, err := u.GetDeviceAddress() + if err != nil { + return nil, err + } + + ifaces, err := net.Interfaces() + if err != nil { + return nil, err + } + + for _, iface := range ifaces { + addrs, err := iface.Addrs() + if err != nil { + return nil, err + } + + for _, addr := range addrs { + switch x := addr.(type) { + case *net.IPNet: + if x.Contains(devAddr) { + return x.IP, nil + } + } + } + } + + return nil, ErrNoInternalAddress +} + +func (n *upnp_NAT) Type() string { return n.typ } From d827c54a1e8044b91c5c20885ad53524432fa83e Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Mon, 27 Oct 2014 08:07:06 +0100 Subject: [PATCH 02/75] Moving to github --- _examples/nat-tester.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_examples/nat-tester.go b/_examples/nat-tester.go index 1033293888..592125639f 100644 --- a/_examples/nat-tester.go +++ b/_examples/nat-tester.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "bitbucket.org/simonmenke/go-telehash/util/nat" + "github.com/telehash/gogotelehash/util/nat" ) func main() { From 83bf98db65f0e298f73df271e80b35d42eebe4a5 Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Mon, 27 Oct 2014 17:39:55 +0100 Subject: [PATCH 03/75] Vendored dependencies --- natpmp.go | 2 +- upnp.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/natpmp.go b/natpmp.go index 8bc6c07171..33fb5028a7 100644 --- a/natpmp.go +++ b/natpmp.go @@ -4,7 +4,7 @@ import ( "net" "time" - "github.com/jackpal/go-nat-pmp" + "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/jackpal/go-nat-pmp" ) var ( diff --git a/upnp.go b/upnp.go index b27ca1e9a9..4cabd661aa 100644 --- a/upnp.go +++ b/upnp.go @@ -4,9 +4,9 @@ import ( "net" "time" - "github.com/huin/goupnp" - "github.com/huin/goupnp/dcps/internetgateway1" - "github.com/huin/goupnp/dcps/internetgateway2" + "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp" + "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway1" + "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway2" ) var ( From 4dbe9af9ab7666bc2ee453e9d08cd59448ca4bbb Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Thu, 30 Oct 2014 16:41:18 +0100 Subject: [PATCH 04/75] WIP go vet and golint --- upnp.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upnp.go b/upnp.go index 4cabd661aa..b6c3bfa1ab 100644 --- a/upnp.go +++ b/upnp.go @@ -31,7 +31,7 @@ func discoverUPNP_IG1() <-chan NAT { dev.Root.Device.VisitServices(func(srv *goupnp.Service) { switch srv.ServiceType { case internetgateway1.URN_WANIPConnection_1: - client := &internetgateway1.WANIPConnection1{goupnp.ServiceClient{ + client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ SOAPClient: srv.NewSOAPClient(), RootDevice: dev.Root, Service: srv, @@ -43,7 +43,7 @@ func discoverUPNP_IG1() <-chan NAT { } case internetgateway1.URN_WANPPPConnection_1: - client := &internetgateway1.WANPPPConnection1{goupnp.ServiceClient{ + client := &internetgateway1.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ SOAPClient: srv.NewSOAPClient(), RootDevice: dev.Root, Service: srv, @@ -80,7 +80,7 @@ func discoverUPNP_IG2() <-chan NAT { dev.Root.Device.VisitServices(func(srv *goupnp.Service) { switch srv.ServiceType { case internetgateway2.URN_WANIPConnection_1: - client := &internetgateway2.WANIPConnection1{goupnp.ServiceClient{ + client := &internetgateway2.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ SOAPClient: srv.NewSOAPClient(), RootDevice: dev.Root, Service: srv, @@ -92,7 +92,7 @@ func discoverUPNP_IG2() <-chan NAT { } case internetgateway2.URN_WANIPConnection_2: - client := &internetgateway2.WANIPConnection2{goupnp.ServiceClient{ + client := &internetgateway2.WANIPConnection2{ServiceClient: goupnp.ServiceClient{ SOAPClient: srv.NewSOAPClient(), RootDevice: dev.Root, Service: srv, @@ -104,7 +104,7 @@ func discoverUPNP_IG2() <-chan NAT { } case internetgateway2.URN_WANPPPConnection_1: - client := &internetgateway2.WANPPPConnection1{goupnp.ServiceClient{ + client := &internetgateway2.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ SOAPClient: srv.NewSOAPClient(), RootDevice: dev.Root, Service: srv, From c0902fb9c1dabc41dd65e0189061594b37726af0 Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Wed, 5 Nov 2014 12:43:11 +0100 Subject: [PATCH 05/75] Extracted from gogotelehash --- _examples/nat-tester.go | 2 +- nat.go | 22 +++++++++++++++++----- natpmp.go | 2 +- upnp.go | 6 +++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/_examples/nat-tester.go b/_examples/nat-tester.go index 592125639f..e534d3f11d 100644 --- a/_examples/nat-tester.go +++ b/_examples/nat-tester.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/telehash/gogotelehash/util/nat" + "github.com/fd/go-nat" ) func main() { diff --git a/nat.go b/nat.go index 59b970f4f4..3cf9648585 100644 --- a/nat.go +++ b/nat.go @@ -1,3 +1,4 @@ +// Package nat implements NAT handling facilities package nat import ( @@ -8,22 +9,33 @@ import ( "time" ) -var ErrNoExternalAddress = errors.New("nat: no external address") -var ErrNoInternalAddress = errors.New("nat: no internal address") -var ErrNoNATFound = errors.New("nat: no NAT found") +var ErrNoExternalAddress = errors.New("no external address") +var ErrNoInternalAddress = errors.New("no internal address") +var ErrNoNATFound = errors.New("no NAT found") // protocol is either "udp" or "tcp" type NAT interface { + // Type returns the kind of NAT port mapping service that is used Type() string + + // GetDeviceAddress returns the internal address of the gateway device. GetDeviceAddress() (addr net.IP, err error) - GetInternalAddress() (addr net.IP, err error) + + // GetExternalAddress returns the external address of the gateway device. GetExternalAddress() (addr net.IP, err error) + // GetInternalAddress returns the address of the local host. + GetInternalAddress() (addr net.IP, err error) + + // AddPortMapping maps a port on the local host to an external port. AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error) + + // DeletePortMapping removes a port mapping. DeletePortMapping(protocol string, internalPort int) (err error) } -func Discover() (NAT, error) { +// DiscoverGateway attempts to find a gateway device. +func DiscoverGateway() (NAT, error) { select { case nat := <-discoverUPNP_IG1(): return nat, nil diff --git a/natpmp.go b/natpmp.go index 33fb5028a7..8bc6c07171 100644 --- a/natpmp.go +++ b/natpmp.go @@ -4,7 +4,7 @@ import ( "net" "time" - "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/jackpal/go-nat-pmp" + "github.com/jackpal/go-nat-pmp" ) var ( diff --git a/upnp.go b/upnp.go index b6c3bfa1ab..86d6e9b3ba 100644 --- a/upnp.go +++ b/upnp.go @@ -4,9 +4,9 @@ import ( "net" "time" - "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp" - "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway1" - "github.com/telehash/gogotelehash/Godeps/_workspace/src/github.com/huin/goupnp/dcps/internetgateway2" + "github.com/huin/goupnp" + "github.com/huin/goupnp/dcps/internetgateway1" + "github.com/huin/goupnp/dcps/internetgateway2" ) var ( From 50e7633d5f27d81490026a13e5b92d2e42d8c6bb Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Wed, 5 Nov 2014 13:04:22 +0100 Subject: [PATCH 06/75] Fixed the example --- _examples/nat-tester.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_examples/nat-tester.go b/_examples/nat-tester.go index e534d3f11d..f2f3bc9afc 100644 --- a/_examples/nat-tester.go +++ b/_examples/nat-tester.go @@ -10,7 +10,7 @@ import ( ) func main() { - nat, err := nat.Discover() + nat, err := nat.DiscoverGateway() if err != nil { log.Fatalf("error: %s", err) } From dcaf50131e4810440bed2cbb6f7f32c4f4cc95dd Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Fri, 8 May 2015 11:37:58 +0200 Subject: [PATCH 07/75] Using github.com/jackpal/gateway to discover NAT-PMP/PCP gateways This change also removes the restriction on what IP ranges can be used with NAT-PMP/PCP. Fixes: #1, #2 --- natpmp.go | 89 ++++++++----------------------------------------------- 1 file changed, 13 insertions(+), 76 deletions(-) diff --git a/natpmp.go b/natpmp.go index 8bc6c07171..395a5dd578 100644 --- a/natpmp.go +++ b/natpmp.go @@ -4,82 +4,19 @@ import ( "net" "time" + "github.com/jackpal/gateway" "github.com/jackpal/go-nat-pmp" ) var ( - _ NAT = (*natpmp_NAT)(nil) + _ NAT = (*natpmpNAT)(nil) ) -func natpmp_PotentialGateways() ([]net.IP, error) { - _, ipNet_10, err := net.ParseCIDR("10.0.0.0/8") - if err != nil { - panic(err) - } - - _, ipNet_172_16, err := net.ParseCIDR("172.16.0.0/12") - if err != nil { - panic(err) - } - - _, ipNet_192_168, err := net.ParseCIDR("192.168.0.0/16") - if err != nil { - panic(err) - } - - ifaces, err := net.Interfaces() - if err != nil { - return nil, err - } - - var ips []net.IP - - for _, iface := range ifaces { - addrs, err := iface.Addrs() - if err != nil { - return nil, err - } - - for _, addr := range addrs { - switch x := addr.(type) { - case *net.IPNet: - var ipNet *net.IPNet - if ipNet_10.Contains(x.IP) { - ipNet = ipNet_10 - } else if ipNet_172_16.Contains(x.IP) { - ipNet = ipNet_172_16 - } else if ipNet_192_168.Contains(x.IP) { - ipNet = ipNet_192_168 - } - - if ipNet != nil { - ip := x.IP.Mask(x.Mask) - ip = ip.To4() - if ip != nil { - ip[3] = ip[3] | 0x01 - ips = append(ips, ip) - } - } - } - } - } - - if len(ips) == 0 { - return nil, ErrNoNATFound - } - - return ips, nil -} - func discoverNATPMP() <-chan NAT { - ips, err := natpmp_PotentialGateways() - if err != nil { - return nil - } - - res := make(chan NAT, len(ips)) + res := make(chan NAT, 1) - for _, ip := range ips { + ip, err := gateway.DiscoverGateway() + if err == nil { go discoverNATPMPWithAddr(res, ip) } @@ -93,20 +30,20 @@ func discoverNATPMPWithAddr(c chan NAT, ip net.IP) { return } - c <- &natpmp_NAT{client, ip, make(map[int]int)} + c <- &natpmpNAT{client, ip, make(map[int]int)} } -type natpmp_NAT struct { +type natpmpNAT struct { c *natpmp.Client gateway net.IP ports map[int]int } -func (n *natpmp_NAT) GetDeviceAddress() (addr net.IP, err error) { +func (n *natpmpNAT) GetDeviceAddress() (addr net.IP, err error) { return n.gateway, nil } -func (n *natpmp_NAT) GetInternalAddress() (addr net.IP, err error) { +func (n *natpmpNAT) GetInternalAddress() (addr net.IP, err error) { ifaces, err := net.Interfaces() if err != nil { return nil, err @@ -131,7 +68,7 @@ func (n *natpmp_NAT) GetInternalAddress() (addr net.IP, err error) { return nil, ErrNoInternalAddress } -func (n *natpmp_NAT) GetExternalAddress() (addr net.IP, err error) { +func (n *natpmpNAT) GetExternalAddress() (addr net.IP, err error) { res, err := n.c.GetExternalAddress() if err != nil { return nil, err @@ -141,7 +78,7 @@ func (n *natpmp_NAT) GetExternalAddress() (addr net.IP, err error) { return net.IPv4(d[0], d[1], d[2], d[3]), nil } -func (n *natpmp_NAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { +func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { var ( err error ) @@ -168,11 +105,11 @@ func (n *natpmp_NAT) AddPortMapping(protocol string, internalPort int, descripti return 0, err } -func (n *natpmp_NAT) DeletePortMapping(protocol string, internalPort int) (err error) { +func (n *natpmpNAT) DeletePortMapping(protocol string, internalPort int) (err error) { delete(n.ports, internalPort) return nil } -func (n *natpmp_NAT) Type() string { +func (n *natpmpNAT) Type() string { return "NAT-PMP" } From bad65a492f32121a87197f4a085905c35e2a367e Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Fri, 25 May 2018 15:02:20 +0200 Subject: [PATCH 08/75] Added go.mod file --- go.mod | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000..d7f4b28787 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/fd/go-nat + +require ( + github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324 + github.com/jackpal/gateway v1.0.4 + github.com/jackpal/go-nat-pmp v1.0.1 + golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 + golang.org/x/text v0.3.0 +) From 66a3ad4c648a674f402de64e127780bff064126d Mon Sep 17 00:00:00 2001 From: Can ZHANG Date: Thu, 13 Sep 2018 15:04:26 +0800 Subject: [PATCH 09/75] Fix test --- _examples/nat-tester.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_examples/nat-tester.go b/_examples/nat-tester.go index f2f3bc9afc..e3b616b2a5 100644 --- a/_examples/nat-tester.go +++ b/_examples/nat-tester.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/fd/go-nat" + "github.com/libp2p/go-nat" ) func main() { @@ -52,7 +52,7 @@ func main() { } }() - defer nat.DeletePortMapping("txp", 3080) + defer nat.DeletePortMapping("tcp", 3080) http.ListenAndServe(":3080", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("Content-Type", "text/plain") From 3fa58ced20b2ff6110ae7eca6c22e18c06c8da6f Mon Sep 17 00:00:00 2001 From: Can ZHANG Date: Thu, 13 Sep 2018 15:11:48 +0800 Subject: [PATCH 10/75] Try to map external port the same as internal port --- natpmp.go | 7 +++++++ upnp.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/natpmp.go b/natpmp.go index 395a5dd578..9a2c27d9e7 100644 --- a/natpmp.go +++ b/natpmp.go @@ -93,6 +93,13 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio } } + // try to map external port the same as internal port + _, err = n.c.AddPortMapping(protocol, internalPort, internalPort, timeoutInSeconds) + if err == nil { + n.ports[internalPort] = internalPort + return internalPort, nil + } + for i := 0; i < 3; i++ { externalPort := randomPort() _, err = n.c.AddPortMapping(protocol, internalPort, externalPort, timeoutInSeconds) diff --git a/upnp.go b/upnp.go index 86d6e9b3ba..8b0975783b 100644 --- a/upnp.go +++ b/upnp.go @@ -176,6 +176,12 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description } } + // try to map external port the same as internal port + err = u.c.AddPortMapping("", uint16(internalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) + if err == nil { + return internalPort, nil + } + for i := 0; i < 3; i++ { externalPort := randomPort() err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) From 329756a8946a72449a3d3277865331ff52c0fd7b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 17 Sep 2018 13:51:20 -0700 Subject: [PATCH 11/75] gx import --- .gx/lastpubver | 1 + package.json | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .gx/lastpubver create mode 100644 package.json diff --git a/.gx/lastpubver b/.gx/lastpubver new file mode 100644 index 0000000000..79ffaca958 --- /dev/null +++ b/.gx/lastpubver @@ -0,0 +1 @@ +1.0.1: QmZ4g5TSk6EKQHrR61FgnE1ytJfirDHKvquL93a3Na1wJT diff --git a/package.json b/package.json new file mode 100644 index 0000000000..1155730974 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "author": "fd", + "bugs": { + "url": "https://github.com/issues/go-nat/issues" + }, + "gx": { + "dvcsimport": "github.com/libp2p/go-nat" + }, + "gxDependencies": [ + { + "author": "huin", + "hash": "QmVwfv63beSAAirq3tiLY6fkNqvjThLnCofL7363YkaScy", + "name": "goupnp", + "version": "0.1.0" + }, + { + "author": "jackpal", + "hash": "Qmf2fBLzCvFxs3vvZaoQyKSTv2rjApek4F1kzRxAfK6P4P", + "name": "gateway", + "version": "1.0.4" + }, + { + "author": "jackpal", + "hash": "QmYsYNh6saxUYHajdj49uiRzdxQgiFTtymrjf3d1f2Cer4", + "name": "go-nat-pmp", + "version": "1.0.1" + } + ], + "gxVersion": "0.9.0", + "language": "go", + "license": "Apache-2.0", + "name": "go-nat", + "version": "1.0.1" +} + From 78a6e612d20233659382cd253145d38d6d24cdd7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 17 Sep 2018 13:56:12 -0700 Subject: [PATCH 12/75] finish fd -> libp2p migration --- README.md | 4 +++- go.mod | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24ddea09e6..eec79193e6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # go-nat -[![GoDoc](https://godoc.org/github.com/fd/go-nat?status.svg)](https://godoc.org/github.com/fd/go-nat) [![status](https://sourcegraph.com/api/repos/github.com/fd/go-nat/.badges/status.png)](https://sourcegraph.com/github.com/fd/go-nat) +[![GoDoc](https://godoc.org/github.com/libp2p/go-nat?status.svg)](https://godoc.org/github.com/libp2p/go-nat) [![status](https://sourcegraph.com/api/repos/github.com/libp2p/go-nat/.badges/status.png)](https://sourcegraph.com/github.com/libp2p/go-nat) + +Forked from: [fd/go-nat](https://github.com/fd/go-nat). diff --git a/go.mod b/go.mod index d7f4b28787..4ac4a3dec7 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/fd/go-nat +module github.com/libp2p/go-nat require ( github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324 From ab584c7bce7cd20eb179845a3c93059661fedc0c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 17 Sep 2018 13:56:40 -0700 Subject: [PATCH 13/75] gx release 1.0.2 --- .gx/lastpubver | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gx/lastpubver b/.gx/lastpubver index 79ffaca958..d816451dee 100644 --- a/.gx/lastpubver +++ b/.gx/lastpubver @@ -1 +1 @@ -1.0.1: QmZ4g5TSk6EKQHrR61FgnE1ytJfirDHKvquL93a3Na1wJT +1.0.2: QmUTkdfn3e6EDb15C4XMHfooD5AoQxt5joYMeaqU56LU8h diff --git a/package.json b/package.json index 1155730974..61cdf82719 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,6 @@ "language": "go", "license": "Apache-2.0", "name": "go-nat", - "version": "1.0.1" + "version": "1.0.2" } From 2d37539e73354531e1aa084b68823775bf739c6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 12 Feb 2019 12:02:01 +0000 Subject: [PATCH 14/75] Bump github.com/jackpal/gateway from 1.0.4 to 1.0.5 Bumps [github.com/jackpal/gateway](https://github.com/jackpal/gateway) from 1.0.4 to 1.0.5. - [Release notes](https://github.com/jackpal/gateway/releases) - [Commits](https://github.com/jackpal/gateway/compare/v1.0.4...v1.0.5) Signed-off-by: dependabot[bot] --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d7f4b28787..73255a0b80 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/fd/go-nat require ( github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324 - github.com/jackpal/gateway v1.0.4 + github.com/jackpal/gateway v1.0.5 github.com/jackpal/go-nat-pmp v1.0.1 golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 golang.org/x/text v0.3.0 From 06c184b582abc99b71b8c53ea783e8778759c7f5 Mon Sep 17 00:00:00 2001 From: Ryan Skidmore Date: Fri, 1 Mar 2019 15:09:57 +0000 Subject: [PATCH 15/75] Added method to generically discover IG Devices --- nat.go | 2 ++ upnp.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/nat.go b/nat.go index 3cf9648585..eb574d63c2 100644 --- a/nat.go +++ b/nat.go @@ -41,6 +41,8 @@ func DiscoverGateway() (NAT, error) { return nat, nil case nat := <-discoverUPNP_IG2(): return nat, nil + case nat := <-discoverUPNP_GenIGDev(): + return nat, nil case nat := <-discoverNATPMP(): return nat, nil case <-time.After(10 * time.Second): diff --git a/upnp.go b/upnp.go index 86d6e9b3ba..caad350114 100644 --- a/upnp.go +++ b/upnp.go @@ -2,11 +2,15 @@ package nat import ( "net" + "net/url" + "strings" "time" "github.com/huin/goupnp" "github.com/huin/goupnp/dcps/internetgateway1" "github.com/huin/goupnp/dcps/internetgateway2" + + "github.com/koron/go-ssdp" ) var ( @@ -123,6 +127,62 @@ func discoverUPNP_IG2() <-chan NAT { return res } +func discoverUPNP_GenIGDev() <-chan NAT { + res := make(chan NAT, 1) + go func() { + DeviceList, err := ssdp.Search(ssdp.All, 5, "") + if err != nil { + return + } + var gw ssdp.Service + for _, Service := range DeviceList { + if strings.Contains(Service.Type, "InternetGatewayDevice") { + gw = Service + break + } + } + + DeviceURL, err := url.Parse(gw.Location) + if err != nil { + return + } + RootDevice, err := goupnp.DeviceByURL(DeviceURL) + if err != nil { + return + } + + RootDevice.Device.VisitServices(func(srv *goupnp.Service) { + switch srv.ServiceType { + case internetgateway1.URN_WANIPConnection_1: + client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: RootDevice, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice} + return + } + + case internetgateway1.URN_WANPPPConnection_1: + client := &internetgateway1.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: RootDevice, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatus() + if err == nil && isNat { + res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice} + return + } + + } + }) + }() + return res +} + type upnp_NAT_Client interface { GetExternalIPAddress() (string, error) AddPortMapping(string, uint16, string, uint16, string, bool, string, uint32) error From 900ec35643486e5263aff91711dd2bf949945d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Fri, 1 Mar 2019 16:43:50 +0000 Subject: [PATCH 16/75] add gomod support // tag v0.0.1. --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ go.mod | 4 +--- go.sum | 11 +++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100644 go.sum diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..4cfe98c242 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +os: + - linux + +language: go + +go: + - 1.11.x + +env: + global: + - GOTFLAGS="-race" + matrix: + - BUILD_DEPTYPE=gx + - BUILD_DEPTYPE=gomod + + +# disable travis install +install: + - true + +script: + - bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh) + + +cache: + directories: + - $GOPATH/src/gx + - $GOPATH/pkg/mod + - $HOME/.cache/go-build + +notifications: + email: false diff --git a/go.mod b/go.mod index eb7991248d..bc8f7bcac9 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,7 @@ module github.com/libp2p/go-nat require ( - github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324 + github.com/huin/goupnp v1.0.0 github.com/jackpal/gateway v1.0.5 github.com/jackpal/go-nat-pmp v1.0.1 - golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 - golang.org/x/text v0.3.0 ) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000..cf1f0624a3 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= +github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= +github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= +github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= +github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= +github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From 943d7b398fc871282f7d14b0e16171ac0d3fbd2e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 6 Mar 2019 09:58:32 -0800 Subject: [PATCH 17/75] expose all discovered NATs This change makes it possible to configure all discovered NATs, not just the first one found. --- nat.go | 65 +++++++++++++++++++++++++++++++++++++++++++++--------- natpmp.go | 40 +++++++++++++++++++++++---------- upnp.go | 66 +++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 131 insertions(+), 40 deletions(-) diff --git a/nat.go b/nat.go index eb574d63c2..4505df60bb 100644 --- a/nat.go +++ b/nat.go @@ -2,6 +2,7 @@ package nat import ( + "context" "errors" "math" "math/rand" @@ -34,20 +35,64 @@ type NAT interface { DeletePortMapping(protocol string, internalPort int) (err error) } +// DiscoverNATs returns all NATs discovered in the network. +func DiscoverNATs(ctx context.Context) <-chan NAT { + nats := make(chan NAT) + + go func() { + defer close(nats) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + upnpIg1 := discoverUPNP_IG1(ctx) + upnpIg2 := discoverUPNP_IG2(ctx) + natpmp := discoverNATPMP(ctx) + upnpGenIGDev := discoverUPNP_GenIGDev(ctx) + for upnpIg1 != nil || upnpIg2 != nil || natpmp != nil { + var ( + nat NAT + ok bool + ) + select { + case nat, ok = <-upnpIg1: + if !ok { + upnpIg1 = nil + } + case nat, ok = <-upnpIg2: + if !ok { + upnpIg2 = nil + } + case nat, ok = <-upnpGenIGDev: + if !ok { + upnpGenIGDev = nil + } + case nat, ok = <-natpmp: + if !ok { + natpmp = nil + } + } + if ok { + select { + case nats <- nat: + case <-ctx.Done(): + return + } + } + } + }() + return nats +} + // DiscoverGateway attempts to find a gateway device. func DiscoverGateway() (NAT, error) { - select { - case nat := <-discoverUPNP_IG1(): - return nat, nil - case nat := <-discoverUPNP_IG2(): - return nat, nil - case nat := <-discoverUPNP_GenIGDev(): - return nat, nil - case nat := <-discoverNATPMP(): - return nat, nil - case <-time.After(10 * time.Second): + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + nat := <-DiscoverNATs(ctx) + if nat == nil { return nil, ErrNoNATFound } + return nat, nil } func randomPort() int { diff --git a/natpmp.go b/natpmp.go index 395a5dd578..a31a499988 100644 --- a/natpmp.go +++ b/natpmp.go @@ -1,6 +1,7 @@ package nat import ( + "context" "net" "time" @@ -12,25 +13,42 @@ var ( _ NAT = (*natpmpNAT)(nil) ) -func discoverNATPMP() <-chan NAT { +func discoverNATPMP(ctx context.Context) <-chan NAT { res := make(chan NAT, 1) ip, err := gateway.DiscoverGateway() if err == nil { - go discoverNATPMPWithAddr(res, ip) + go func() { + defer close(res) + // Unfortunately, we can't actually _stop_ the natpmp + // library. However, we can at least close _our_ channel + // and walk away. + select { + case client, ok := <-discoverNATPMPWithAddr(ip): + if ok { + res <- &natpmpNAT{client, ip, make(map[int]int)} + } + case <-ctx.Done(): + } + }() + } else { + close(res) } - return res } -func discoverNATPMPWithAddr(c chan NAT, ip net.IP) { - client := natpmp.NewClient(ip) - _, err := client.GetExternalAddress() - if err != nil { - return - } - - c <- &natpmpNAT{client, ip, make(map[int]int)} +func discoverNATPMPWithAddr(ip net.IP) <-chan *natpmp.Client { + res := make(chan *natpmp.Client, 1) + go func() { + defer close(res) + client := natpmp.NewClient(ip) + _, err := client.GetExternalAddress() + if err != nil { + return + } + res <- client + }() + return res } type natpmpNAT struct { diff --git a/upnp.go b/upnp.go index caad350114..ccfeb14a2f 100644 --- a/upnp.go +++ b/upnp.go @@ -1,6 +1,7 @@ package nat import ( + "context" "net" "net/url" "strings" @@ -17,9 +18,10 @@ var ( _ NAT = (*upnp_NAT)(nil) ) -func discoverUPNP_IG1() <-chan NAT { - res := make(chan NAT, 1) +func discoverUPNP_IG1(ctx context.Context) <-chan NAT { + res := make(chan NAT) go func() { + defer close(res) // find devices devs, err := goupnp.DiscoverDevices(internetgateway1.URN_WANConnectionDevice_1) @@ -33,6 +35,9 @@ func discoverUPNP_IG1() <-chan NAT { } dev.Root.Device.VisitServices(func(srv *goupnp.Service) { + if ctx.Err() != nil { + return + } switch srv.ServiceType { case internetgateway1.URN_WANIPConnection_1: client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ @@ -42,8 +47,10 @@ func discoverUPNP_IG1() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", dev.Root} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", dev.Root}: + case <-ctx.Done(): + } } case internetgateway1.URN_WANPPPConnection_1: @@ -54,8 +61,10 @@ func discoverUPNP_IG1() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", dev.Root} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", dev.Root}: + case <-ctx.Done(): + } } } @@ -66,9 +75,10 @@ func discoverUPNP_IG1() <-chan NAT { return res } -func discoverUPNP_IG2() <-chan NAT { - res := make(chan NAT, 1) +func discoverUPNP_IG2(ctx context.Context) <-chan NAT { + res := make(chan NAT) go func() { + defer close(res) // find devices devs, err := goupnp.DiscoverDevices(internetgateway2.URN_WANConnectionDevice_2) @@ -82,6 +92,9 @@ func discoverUPNP_IG2() <-chan NAT { } dev.Root.Device.VisitServices(func(srv *goupnp.Service) { + if ctx.Err() != nil { + return + } switch srv.ServiceType { case internetgateway2.URN_WANIPConnection_1: client := &internetgateway2.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ @@ -91,8 +104,10 @@ func discoverUPNP_IG2() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP1)", dev.Root} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP1)", dev.Root}: + case <-ctx.Done(): + } } case internetgateway2.URN_WANIPConnection_2: @@ -103,8 +118,10 @@ func discoverUPNP_IG2() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP2)", dev.Root} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP2)", dev.Root}: + case <-ctx.Done(): + } } case internetgateway2.URN_WANPPPConnection_1: @@ -115,8 +132,10 @@ func discoverUPNP_IG2() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-PPP1)", dev.Root} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-PPP1)", dev.Root}: + case <-ctx.Done(): + } } } @@ -127,9 +146,11 @@ func discoverUPNP_IG2() <-chan NAT { return res } -func discoverUPNP_GenIGDev() <-chan NAT { +func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { res := make(chan NAT, 1) go func() { + defer close(res) + DeviceList, err := ssdp.Search(ssdp.All, 5, "") if err != nil { return @@ -152,6 +173,9 @@ func discoverUPNP_GenIGDev() <-chan NAT { } RootDevice.Device.VisitServices(func(srv *goupnp.Service) { + if ctx.Err() != nil { + return + } switch srv.ServiceType { case internetgateway1.URN_WANIPConnection_1: client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ @@ -161,8 +185,10 @@ func discoverUPNP_GenIGDev() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice}: + case <-ctx.Done(): + } } case internetgateway1.URN_WANPPPConnection_1: @@ -173,8 +199,10 @@ func discoverUPNP_GenIGDev() <-chan NAT { }} _, isNat, err := client.GetNATRSIPStatus() if err == nil && isNat { - res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice} - return + select { + case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice}: + case <-ctx.Done(): + } } } From c8594db014d29a36fe16880224818429f2a867c2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 6 Mar 2019 10:44:40 -0800 Subject: [PATCH 18/75] try to pick the best NAT when multiple NATs are discovered --- nat.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/nat.go b/nat.go index 4505df60bb..727ae2a2e9 100644 --- a/nat.go +++ b/nat.go @@ -8,6 +8,8 @@ import ( "math/rand" "net" "time" + + "github.com/jackpal/gateway" ) var ErrNoExternalAddress = errors.New("no external address") @@ -88,11 +90,37 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { func DiscoverGateway() (NAT, error) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - nat := <-DiscoverNATs(ctx) - if nat == nil { + + var nats []NAT + for nat := range DiscoverNATs(ctx) { + nats = append(nats, nat) + } + switch len(nats) { + case 0: return nil, ErrNoNATFound + case 1: + return nats[0], nil + } + gw, _ := gateway.DiscoverGateway() + bestNAT := nats[0] + natGw, _ := bestNAT.GetDeviceAddress() + bestNATIsGw := gw != nil && natGw.Equal(gw) + // 1. Prefer gateways discovered _last_. This is an OK heuristic for + // discovering the most-upstream (furthest) NAT. + // 2. Prefer gateways that actually match our known gateway address. + // Some relays like to claim to be NATs even if they aren't. + for _, nat := range nats[1:] { + natGw, _ := nat.GetDeviceAddress() + natIsGw := gw != nil && natGw.Equal(gw) + + if bestNATIsGw && !natIsGw { + continue + } + + bestNATIsGw = natIsGw + bestNAT = nat } - return nat, nil + return bestNAT, nil } func randomPort() int { From e426ef9d27106ae2b62c8284a54059ec4c9fd263 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 11 Mar 2019 18:53:11 -0700 Subject: [PATCH 19/75] gx import go-ssdp --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 61cdf82719..b8fa3361bb 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,12 @@ "hash": "QmYsYNh6saxUYHajdj49uiRzdxQgiFTtymrjf3d1f2Cer4", "name": "go-nat-pmp", "version": "1.0.1" + }, + { + "author": "koron", + "hash": "QmfDrLLyLVTLbDFfYvPsMqj3hgacxFCXyShZ5YjobqUAtr", + "name": "go-ssdp", + "version": "0.0.0" } ], "gxVersion": "0.9.0", From ab32e615c4b32a07ccbe9a857901c7e60a291754 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 12 Mar 2019 10:40:02 -0700 Subject: [PATCH 20/75] gx release 1.0.3 --- .gx/lastpubver | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gx/lastpubver b/.gx/lastpubver index d816451dee..0306793c53 100644 --- a/.gx/lastpubver +++ b/.gx/lastpubver @@ -1 +1 @@ -1.0.2: QmUTkdfn3e6EDb15C4XMHfooD5AoQxt5joYMeaqU56LU8h +1.0.3: QmdwkZHamNNrj7k3G29rnurmW3mFzsDhnyXppNcgYsiBVz diff --git a/package.json b/package.json index b8fa3361bb..7e176a89b2 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,6 @@ "language": "go", "license": "Apache-2.0", "name": "go-nat", - "version": "1.0.2" + "version": "1.0.3" } From 4a84cb455f3eddc5e46927656256c56b1e5c5cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Thu, 11 Apr 2019 21:11:16 +0100 Subject: [PATCH 21/75] farewell gx; thanks for serving us well. --- .gx/lastpubver | 1 - .travis.yml | 2 -- README.md | 4 ++++ package.json | 41 ----------------------------------------- 4 files changed, 4 insertions(+), 44 deletions(-) delete mode 100644 .gx/lastpubver delete mode 100644 package.json diff --git a/.gx/lastpubver b/.gx/lastpubver deleted file mode 100644 index 0306793c53..0000000000 --- a/.gx/lastpubver +++ /dev/null @@ -1 +0,0 @@ -1.0.3: QmdwkZHamNNrj7k3G29rnurmW3mFzsDhnyXppNcgYsiBVz diff --git a/.travis.yml b/.travis.yml index 4cfe98c242..5163d693fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ env: global: - GOTFLAGS="-race" matrix: - - BUILD_DEPTYPE=gx - BUILD_DEPTYPE=gomod @@ -24,7 +23,6 @@ script: cache: directories: - - $GOPATH/src/gx - $GOPATH/pkg/mod - $HOME/.cache/go-build diff --git a/README.md b/README.md index eec79193e6..61b5cc8891 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ [![GoDoc](https://godoc.org/github.com/libp2p/go-nat?status.svg)](https://godoc.org/github.com/libp2p/go-nat) [![status](https://sourcegraph.com/api/repos/github.com/libp2p/go-nat/.badges/status.png)](https://sourcegraph.com/github.com/libp2p/go-nat) Forked from: [fd/go-nat](https://github.com/fd/go-nat). + +--- + +The last gx published version of this module was: 1.0.3: QmdwkZHamNNrj7k3G29rnurmW3mFzsDhnyXppNcgYsiBVz diff --git a/package.json b/package.json deleted file mode 100644 index 7e176a89b2..0000000000 --- a/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "author": "fd", - "bugs": { - "url": "https://github.com/issues/go-nat/issues" - }, - "gx": { - "dvcsimport": "github.com/libp2p/go-nat" - }, - "gxDependencies": [ - { - "author": "huin", - "hash": "QmVwfv63beSAAirq3tiLY6fkNqvjThLnCofL7363YkaScy", - "name": "goupnp", - "version": "0.1.0" - }, - { - "author": "jackpal", - "hash": "Qmf2fBLzCvFxs3vvZaoQyKSTv2rjApek4F1kzRxAfK6P4P", - "name": "gateway", - "version": "1.0.4" - }, - { - "author": "jackpal", - "hash": "QmYsYNh6saxUYHajdj49uiRzdxQgiFTtymrjf3d1f2Cer4", - "name": "go-nat-pmp", - "version": "1.0.1" - }, - { - "author": "koron", - "hash": "QmfDrLLyLVTLbDFfYvPsMqj3hgacxFCXyShZ5YjobqUAtr", - "name": "go-ssdp", - "version": "0.0.0" - } - ], - "gxVersion": "0.9.0", - "language": "go", - "license": "Apache-2.0", - "name": "go-nat", - "version": "1.0.3" -} - From 3f647da3badec64ef95ad393e159386e171204fb Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 11 Apr 2019 22:31:41 -0700 Subject: [PATCH 22/75] fix detection of GenIG NATs fixes #6 --- nat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nat.go b/nat.go index 727ae2a2e9..371fdb0354 100644 --- a/nat.go +++ b/nat.go @@ -51,7 +51,7 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { upnpIg2 := discoverUPNP_IG2(ctx) natpmp := discoverNATPMP(ctx) upnpGenIGDev := discoverUPNP_GenIGDev(ctx) - for upnpIg1 != nil || upnpIg2 != nil || natpmp != nil { + for upnpIg1 != nil || upnpIg2 != nil || natpmp != nil || upnpGenIGDev != nil { var ( nat NAT ok bool From 523cb01fafd52a886eff7de2af8c2846322e761f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 11 Apr 2019 22:34:27 -0700 Subject: [PATCH 23/75] Revert "Try to map external port the same as internal port" This reverts commit 3fa58ced20b2ff6110ae7eca6c22e18c06c8da6f. Its safer to just pick a random port. Unfortunately, some NATs (e.g., mine) suck and will happily map a port that's already been mapped elsewhere (e.g., in the port forwarding config). While this patch does the _nice_ thing, it was mostly cosmetic. --- natpmp.go | 7 ------- upnp.go | 6 ------ 2 files changed, 13 deletions(-) diff --git a/natpmp.go b/natpmp.go index e437250c3f..a31a499988 100644 --- a/natpmp.go +++ b/natpmp.go @@ -111,13 +111,6 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio } } - // try to map external port the same as internal port - _, err = n.c.AddPortMapping(protocol, internalPort, internalPort, timeoutInSeconds) - if err == nil { - n.ports[internalPort] = internalPort - return internalPort, nil - } - for i := 0; i < 3; i++ { externalPort := randomPort() _, err = n.c.AddPortMapping(protocol, internalPort, externalPort, timeoutInSeconds) diff --git a/upnp.go b/upnp.go index dddf7e7047..ccfeb14a2f 100644 --- a/upnp.go +++ b/upnp.go @@ -264,12 +264,6 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description } } - // try to map external port the same as internal port - err = u.c.AddPortMapping("", uint16(internalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) - if err == nil { - return internalPort, nil - } - for i := 0; i < 3; i++ { externalPort := randomPort() err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) From 0938e5d8a2a3ad5f5d8706159eefec54c7fe0230 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 3 May 2019 10:27:04 -0700 Subject: [PATCH 24/75] don't mask context --- nat.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/nat.go b/nat.go index 371fdb0354..c38030075c 100644 --- a/nat.go +++ b/nat.go @@ -44,9 +44,6 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { go func() { defer close(nats) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - upnpIg1 := discoverUPNP_IG1(ctx) upnpIg2 := discoverUPNP_IG2(ctx) natpmp := discoverNATPMP(ctx) From 93d0ace99efa5d8be6a0ddf83f601d304ddb0ee7 Mon Sep 17 00:00:00 2001 From: iulianpascalau Date: Thu, 21 Nov 2019 20:16:09 +0200 Subject: [PATCH 25/75] updated go.mod and go.sum to the latest version of github.com/koron/go-ssdp library that has the race condition fixed --- go.mod | 4 +++- go.sum | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 718fdbdff7..a6dd7e1e41 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,7 @@ require ( github.com/huin/goupnp v1.0.0 github.com/jackpal/gateway v1.0.5 github.com/jackpal/go-nat-pmp v1.0.1 - github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b + github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d ) + +go 1.12 diff --git a/go.sum b/go.sum index 1a3a280ed3..399175cc00 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= -github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= +github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= From 199acda704ad6efe375ad8dcd39eb44f8017a6f7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Nov 2019 08:20:25 -0800 Subject: [PATCH 26/75] fix: really obey the context The internal nat discovery logic doesn't properly propagate the context. --- nat.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nat.go b/nat.go index c38030075c..d38ad52c12 100644 --- a/nat.go +++ b/nat.go @@ -70,6 +70,9 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { if !ok { natpmp = nil } + case <-ctx.Done(): + // timeout. + return } if ok { select { From c437f7a097d61f1a7cabac8c4ef4a32e0f35961f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2019 17:39:48 +0000 Subject: [PATCH 27/75] Bump github.com/jackpal/go-nat-pmp from 1.0.1 to 1.0.2 Bumps [github.com/jackpal/go-nat-pmp](https://github.com/jackpal/go-nat-pmp) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/jackpal/go-nat-pmp/releases) - [Commits](https://github.com/jackpal/go-nat-pmp/compare/v1.0.1...v1.0.2) Signed-off-by: dependabot-preview[bot] --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a6dd7e1e41..3b3c622235 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/libp2p/go-nat require ( github.com/huin/goupnp v1.0.0 github.com/jackpal/gateway v1.0.5 - github.com/jackpal/go-nat-pmp v1.0.1 + github.com/jackpal/go-nat-pmp v1.0.2 github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d ) diff --git a/go.sum b/go.sum index 399175cc00..547800b2b7 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= +github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= From 4b6e89e7d7f1616b924bd44b8fc8bb8b432957a8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 6 Dec 2019 16:33:55 -0500 Subject: [PATCH 28/75] ci: bump to go 1.13 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5163d693fc..a156d3eb5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: language: go go: - - 1.11.x + - 1.13.x env: global: From d4146fbf230ffc7c46cc165761908501cb5db8c1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 30 Mar 2020 14:05:40 -0700 Subject: [PATCH 29/75] feat: switch to go-netroute This library makes the correct syscalls instead of shelling out to a binary. --- gateway.go | 17 +++++++++++++++++ go.mod | 2 +- go.sum | 17 +++++++++++++---- nat.go | 4 +--- natpmp.go | 35 +++++++++++++++++------------------ 5 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 gateway.go diff --git a/gateway.go b/gateway.go new file mode 100644 index 0000000000..a87e46a892 --- /dev/null +++ b/gateway.go @@ -0,0 +1,17 @@ +package nat + +import ( + "net" + + "github.com/libp2p/go-netroute" +) + +func getDefaultGateway() (net.IP, error) { + router, err := netroute.New() + if err != nil { + return nil, err + } + + _, ip, _, err := router.Route(net.IPv4zero) + return ip, err +} diff --git a/go.mod b/go.mod index 3b3c622235..605525ba0c 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/libp2p/go-nat require ( github.com/huin/goupnp v1.0.0 - github.com/jackpal/gateway v1.0.5 github.com/jackpal/go-nat-pmp v1.0.2 github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d + github.com/libp2p/go-netroute v0.1.2 ) go 1.12 diff --git a/go.sum b/go.sum index 547800b2b7..70ef62784e 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,24 @@ +github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY= +github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= -github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= -github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= -github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= -github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/libp2p/go-netroute v0.1.2 h1:UHhB35chwgvcRI392znJA3RCBtZ3MpE3ahNCN5MR4Xg= +github.com/libp2p/go-netroute v0.1.2/go.mod h1:jZLDV+1PE8y5XxBySEBgbuVAXbhtuHSdmLPL2n9MKbk= +github.com/libp2p/go-sockaddr v0.0.2 h1:tCuXfpA9rq7llM/v834RKc/Xvovy/AqM9kHvTV/jY/Q= +github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998= +golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/nat.go b/nat.go index d38ad52c12..a2606794fe 100644 --- a/nat.go +++ b/nat.go @@ -8,8 +8,6 @@ import ( "math/rand" "net" "time" - - "github.com/jackpal/gateway" ) var ErrNoExternalAddress = errors.New("no external address") @@ -101,7 +99,7 @@ func DiscoverGateway() (NAT, error) { case 1: return nats[0], nil } - gw, _ := gateway.DiscoverGateway() + gw, _ := getDefaultGateway() bestNAT := nats[0] natGw, _ := bestNAT.GetDeviceAddress() bestNATIsGw := gw != nil && natGw.Equal(gw) diff --git a/natpmp.go b/natpmp.go index a31a499988..495d42b49e 100644 --- a/natpmp.go +++ b/natpmp.go @@ -5,7 +5,6 @@ import ( "net" "time" - "github.com/jackpal/gateway" "github.com/jackpal/go-nat-pmp" ) @@ -16,24 +15,24 @@ var ( func discoverNATPMP(ctx context.Context) <-chan NAT { res := make(chan NAT, 1) - ip, err := gateway.DiscoverGateway() - if err == nil { - go func() { - defer close(res) - // Unfortunately, we can't actually _stop_ the natpmp - // library. However, we can at least close _our_ channel - // and walk away. - select { - case client, ok := <-discoverNATPMPWithAddr(ip): - if ok { - res <- &natpmpNAT{client, ip, make(map[int]int)} - } - case <-ctx.Done(): - } - }() - } else { - close(res) + ip, err := getDefaultGateway() + if err != nil { + return nil } + + go func() { + defer close(res) + // Unfortunately, we can't actually _stop_ the natpmp + // library. However, we can at least close _our_ channel + // and walk away. + select { + case client, ok := <-discoverNATPMPWithAddr(ip): + if ok { + res <- &natpmpNAT{client, ip, make(map[int]int)} + } + case <-ctx.Done(): + } + }() return res } From c7e6c5b5c607520f521088ce957563618b8588e5 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Thu, 22 Apr 2021 06:09:21 -0400 Subject: [PATCH 30/75] sync: update CI config files (#20) --- .github/workflows/automerge.yml | 27 ++++++++++++++++++++++ .github/workflows/go-check.yml | 41 +++++++++++++++++++++++++++++++++ .github/workflows/go-test.yml | 38 ++++++++++++++++++++++++++++++ .travis.yml | 30 ------------------------ go.mod | 2 +- go.sum | 1 - 6 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/automerge.yml create mode 100644 .github/workflows/go-check.yml create mode 100644 .github/workflows/go-test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000000..840618d88f --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,27 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass. +# This reduces the friction associated with updating with our workflows. + +on: [ pull_request ] + +jobs: + automerge: + if: github.event.pull_request.user.login == 'web3-bot' + runs-on: ubuntu-latest + steps: + - name: Wait on tests + uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 + with: + ref: ${{ github.event.pull_request.head.sha }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + running-workflow-name: 'automerge' # the name of this job + - name: Merge PR + uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + MERGE_LABELS: "" + MERGE_METHOD: "squash" + MERGE_DELETE_BRANCH: true diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml new file mode 100644 index 0000000000..862d49fc9f --- /dev/null +++ b/.github/workflows/go-check.yml @@ -0,0 +1,41 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +on: [push, pull_request] + +jobs: + unit: + runs-on: ubuntu-latest + name: Go checks + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "1.16.x" + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@be534f007836a777104a15f2456cd1fffd3ddee8 # v2020.2.2 + - name: Check that go.mod is tidy + run: | + go mod tidy + if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then + echo "go.sum was added by go mod tidy" + exit 1 + fi + git diff --exit-code -- go.sum go.mod + - name: gofmt + if: ${{ success() || failure() }} # run this step even if the previous one failed + run: | + out=$(gofmt -s -l .) + if [[ -n "$out" ]]; then + echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}' + exit 1 + fi + - name: go vet + if: ${{ success() || failure() }} # run this step even if the previous one failed + run: go vet ./... + - name: staticcheck + if: ${{ success() || failure() }} # run this step even if the previous one failed + run: | + set -o pipefail + staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' + diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000000..9b38420862 --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,38 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +on: [push, pull_request] + +jobs: + unit: + strategy: + fail-fast: false + matrix: + os: [ "ubuntu", "windows", "macos" ] + go: [ "1.15.x", "1.16.x" ] + runs-on: ${{ matrix.os }}-latest + name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }}) + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: Go information + run: | + go version + go env + - name: Run tests + run: go test -v -coverprofile coverage.txt ./... + - name: Run tests (32 bit) + if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. + env: + GOARCH: 386 + run: go test -v ./... + - name: Run tests with race detector + if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow + run: go test -v -race ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@967e2b38a85a62bd61be5529ada27ebc109948c2 # v1.4.1 + with: + file: coverage.txt + env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a156d3eb5e..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -os: - - linux - -language: go - -go: - - 1.13.x - -env: - global: - - GOTFLAGS="-race" - matrix: - - BUILD_DEPTYPE=gomod - - -# disable travis install -install: - - true - -script: - - bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh) - - -cache: - directories: - - $GOPATH/pkg/mod - - $HOME/.cache/go-build - -notifications: - email: false diff --git a/go.mod b/go.mod index 605525ba0c..1157feea8e 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,4 @@ require ( github.com/libp2p/go-netroute v0.1.2 ) -go 1.12 +go 1.15 diff --git a/go.sum b/go.sum index 70ef62784e..be2d04ac02 100644 --- a/go.sum +++ b/go.sum @@ -12,7 +12,6 @@ github.com/libp2p/go-netroute v0.1.2/go.mod h1:jZLDV+1PE8y5XxBySEBgbuVAXbhtuHSdm github.com/libp2p/go-sockaddr v0.0.2 h1:tCuXfpA9rq7llM/v834RKc/Xvovy/AqM9kHvTV/jY/Q= github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= From 18d105319b4b4595a3b44f9c47999b8f9795c54c Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Tue, 1 Jun 2021 13:59:30 -0400 Subject: [PATCH 31/75] sync: update CI config files (#21) --- .github/workflows/automerge.yml | 26 +++++++++++++++++++++++- .github/workflows/go-check.yml | 35 +++++++++++++++++++++------------ .github/workflows/go-test.yml | 19 +++++++++++++----- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 840618d88f..32bcc2e6e5 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -5,11 +5,35 @@ # This reduces the friction associated with updating with our workflows. on: [ pull_request ] +name: Automerge jobs: - automerge: + automerge-check: if: github.event.pull_request.user.login == 'web3-bot' runs-on: ubuntu-latest + outputs: + status: ${{ steps.should-automerge.outputs.status }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Check if we should automerge + id: should-automerge + run: | + for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do + committer=$(git show --format=$'%ce' -s $commit) + echo "Committer: $committer" + if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then + echo "Commit $commit wasn't committed by web3-bot, but by $committer." + echo "::set-output name=status::false" + exit + fi + done + echo "::set-output name=status::true" + automerge: + needs: automerge-check + runs-on: ubuntu-latest + if: ${{ needs.automerge-check.outputs.status == 'true' }} steps: - name: Wait on tests uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 862d49fc9f..00ce947c82 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -2,26 +2,31 @@ # See https://github.com/protocol/.github/ for details. on: [push, pull_request] +name: Go Checks jobs: unit: runs-on: ubuntu-latest - name: Go checks + name: All steps: - uses: actions/checkout@v2 + with: + submodules: recursive - uses: actions/setup-go@v2 with: go-version: "1.16.x" - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@be534f007836a777104a15f2456cd1fffd3ddee8 # v2020.2.2 + run: go install honnef.co/go/tools/cmd/staticcheck@434f5f3816b358fe468fa83dcba62d794e7fe04b # 2021.1 (v0.2.0) - name: Check that go.mod is tidy - run: | - go mod tidy - if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then - echo "go.sum was added by go mod tidy" - exit 1 - fi - git diff --exit-code -- go.sum go.mod + uses: protocol/multiple-go-modules@v1.0 + with: + run: | + go mod tidy + if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then + echo "go.sum was added by go mod tidy" + exit 1 + fi + git diff --exit-code -- go.sum go.mod - name: gofmt if: ${{ success() || failure() }} # run this step even if the previous one failed run: | @@ -32,10 +37,14 @@ jobs: fi - name: go vet if: ${{ success() || failure() }} # run this step even if the previous one failed - run: go vet ./... + uses: protocol/multiple-go-modules@v1.0 + with: + run: go vet ./... - name: staticcheck if: ${{ success() || failure() }} # run this step even if the previous one failed - run: | - set -o pipefail - staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' + uses: protocol/multiple-go-modules@v1.0 + with: + run: | + set -o pipefail + staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 9b38420862..4c7138b01d 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -2,6 +2,7 @@ # See https://github.com/protocol/.github/ for details. on: [push, pull_request] +name: Go Test jobs: unit: @@ -11,9 +12,11 @@ jobs: os: [ "ubuntu", "windows", "macos" ] go: [ "1.15.x", "1.16.x" ] runs-on: ${{ matrix.os }}-latest - name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }}) + name: ${{ matrix.os}} (go ${{ matrix.go }}) steps: - uses: actions/checkout@v2 + with: + submodules: recursive - uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} @@ -22,17 +25,23 @@ jobs: go version go env - name: Run tests - run: go test -v -coverprofile coverage.txt ./... + uses: protocol/multiple-go-modules@v1.0 + with: + run: go test -v -coverprofile coverage.txt ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. + uses: protocol/multiple-go-modules@v1.0 env: GOARCH: 386 - run: go test -v ./... + with: + run: go test -v ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow - run: go test -v -race ./... + uses: protocol/multiple-go-modules@v1.0 + with: + run: go test -v -race ./... - name: Upload coverage to Codecov - uses: codecov/codecov-action@967e2b38a85a62bd61be5529ada27ebc109948c2 # v1.4.1 + uses: codecov/codecov-action@a1ed4b322b4b38cb846afb5a0ebfa17086917d27 # v1.5.0 with: file: coverage.txt env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} From 558869fa7f90efdfdc9058e206ad79e28d8bd2eb Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Tue, 17 Aug 2021 10:45:47 -0400 Subject: [PATCH 32/75] sync: update CI config files (#22) --- .github/workflows/automerge.yml | 4 +++- .github/workflows/go-check.yml | 34 ++++++++++++++++++++++++++++----- .github/workflows/go-test.yml | 22 ++++++++++++++------- go.mod | 2 +- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 32bcc2e6e5..44fad65fc1 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -33,7 +33,9 @@ jobs: automerge: needs: automerge-check runs-on: ubuntu-latest - if: ${{ needs.automerge-check.outputs.status == 'true' }} + # The check for the user is redundant here, as this job depends on the automerge-check job, + # but it prevents this job from spinning up, just to be skipped shortly after. + if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true' steps: - name: Wait on tests uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 00ce947c82..6acdd48f97 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -8,17 +8,28 @@ jobs: unit: runs-on: ubuntu-latest name: All + env: + RUNGOGENERATE: false steps: - uses: actions/checkout@v2 with: submodules: recursive - uses: actions/setup-go@v2 with: - go-version: "1.16.x" + go-version: "1.17.x" + - name: Run repo-specific setup + uses: ./.github/actions/go-check-setup + if: hashFiles('./.github/actions/go-check-setup') != '' + - name: Read config + if: hashFiles('./.github/workflows/go-check-config.json') != '' + run: | + if jq -re .gogenerate ./.github/workflows/go-check-config.json; then + echo "RUNGOGENERATE=true" >> $GITHUB_ENV + fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@434f5f3816b358fe468fa83dcba62d794e7fe04b # 2021.1 (v0.2.0) + run: go install honnef.co/go/tools/cmd/staticcheck@df71e5d0e0ed317ebf43e6e59cf919430fa4b8f2 # 2021.1.1 (v0.2.1) - name: Check that go.mod is tidy - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 with: run: | go mod tidy @@ -37,14 +48,27 @@ jobs: fi - name: go vet if: ${{ success() || failure() }} # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 with: run: go vet ./... - name: staticcheck if: ${{ success() || failure() }} # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 with: run: | set -o pipefail staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' + - name: go generate + uses: protocol/multiple-go-modules@v1.2 + if: (success() || failure()) && env.RUNGOGENERATE == 'true' + with: + run: | + git clean -fd # make sure there aren't untracked files / directories + go generate ./... + # check if go generate modified or added any files + if ! $(git add . && git diff-index HEAD --exit-code --quiet); then + echo "go generated caused changes to the repository:" + git status --short + exit 1 + fi diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 4c7138b01d..7010dccec4 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,7 +10,9 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.15.x", "1.16.x" ] + go: [ "1.16.x", "1.17.x" ] + env: + COVERAGES: "" runs-on: ${{ matrix.os }}-latest name: ${{ matrix.os}} (go ${{ matrix.go }}) steps: @@ -24,24 +26,30 @@ jobs: run: | go version go env + - name: Run repo-specific setup + uses: ./.github/actions/go-test-setup + if: hashFiles('./.github/actions/go-test-setup') != '' - name: Run tests - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 with: - run: go test -v -coverprofile coverage.txt ./... + run: go test -v -coverprofile module-coverage.txt ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 env: GOARCH: 386 with: run: go test -v ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow - uses: protocol/multiple-go-modules@v1.0 + uses: protocol/multiple-go-modules@v1.2 with: run: go test -v -race ./... + - name: Collect coverage files + shell: bash + run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@a1ed4b322b4b38cb846afb5a0ebfa17086917d27 # v1.5.0 + uses: codecov/codecov-action@51d810878be5422784e86451c0e7c14e5860ec47 # v2.0.2 with: - file: coverage.txt + files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/go.mod b/go.mod index 1157feea8e..53fe02c477 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,4 @@ require ( github.com/libp2p/go-netroute v0.1.2 ) -go 1.15 +go 1.16 From d0d64ea585d6f0f677454ade85f59fbccdf35b06 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 19 Sep 2021 10:02:49 +0100 Subject: [PATCH 33/75] pass a context to DiscoverGateway --- nat.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nat.go b/nat.go index a2606794fe..6d295e66f5 100644 --- a/nat.go +++ b/nat.go @@ -85,10 +85,7 @@ func DiscoverNATs(ctx context.Context) <-chan NAT { } // DiscoverGateway attempts to find a gateway device. -func DiscoverGateway() (NAT, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - +func DiscoverGateway(ctx context.Context) (NAT, error) { var nats []NAT for nat := range DiscoverNATs(ctx) { nats = append(nats, nat) From 763460e5306c204c55bcdd411675184de2ea137a Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:50:40 -0500 Subject: [PATCH 34/75] sync: update CI config files (#24) --- .github/workflows/go-check.yml | 2 +- .github/workflows/go-test.yml | 15 +++++++++++++-- .github/workflows/release-check.yml | 11 +++++++++++ .github/workflows/releaser.yml | 11 +++++++++++ .github/workflows/tagpush.yml | 12 ++++++++++++ version.json | 3 +++ 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release-check.yml create mode 100644 .github/workflows/releaser.yml create mode 100644 .github/workflows/tagpush.yml create mode 100644 version.json diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 6acdd48f97..e127cf1792 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@df71e5d0e0ed317ebf43e6e59cf919430fa4b8f2 # 2021.1.1 (v0.2.1) + run: go install honnef.co/go/tools/cmd/staticcheck@c8caa92bad8c27ae734c6725b8a04932d54a147b # 2021.1.2 (v0.2.2) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 7010dccec4..606e0c7f3d 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -26,13 +26,24 @@ jobs: run: | go version go env + - name: Use msys2 on windows + if: ${{ matrix.os == 'windows' }} + shell: bash + # The executable for msys2 is also called bash.cmd + # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells + # If we prepend its location to the PATH + # subsequent 'shell: bash' steps will use msys2 instead of gitbash + run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH - name: Run repo-specific setup uses: ./.github/actions/go-test-setup if: hashFiles('./.github/actions/go-test-setup') != '' - name: Run tests uses: protocol/multiple-go-modules@v1.2 with: - run: go test -v -coverprofile module-coverage.txt ./... + # Use -coverpkg=./..., so that we include cross-package coverage. + # If package ./A imports ./B, and ./A's tests also cover ./B, + # this means ./B's coverage will be significantly higher than 0%. + run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -49,7 +60,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@51d810878be5422784e86451c0e7c14e5860ec47 # v2.0.2 + uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml new file mode 100644 index 0000000000..fde81c1f88 --- /dev/null +++ b/.github/workflows/release-check.yml @@ -0,0 +1,11 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +name: Release Checker +on: + pull_request: + paths: [ 'version.json' ] + +jobs: + release-check: + uses: protocol/.github/.github/workflows/release-check.yml@master diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml new file mode 100644 index 0000000000..cdccbf873d --- /dev/null +++ b/.github/workflows/releaser.yml @@ -0,0 +1,11 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +name: Releaser +on: + push: + paths: [ 'version.json' ] + +jobs: + releaser: + uses: protocol/.github/.github/workflows/releaser.yml@master diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml new file mode 100644 index 0000000000..d84996187a --- /dev/null +++ b/.github/workflows/tagpush.yml @@ -0,0 +1,12 @@ +# File managed by web3-bot. DO NOT EDIT. +# See https://github.com/protocol/.github/ for details. + +name: Tag Push Checker +on: + push: + tags: + - v* + +jobs: + releaser: + uses: protocol/.github/.github/workflows/tagpush.yml@master diff --git a/version.json b/version.json new file mode 100644 index 0000000000..557859c534 --- /dev/null +++ b/version.json @@ -0,0 +1,3 @@ +{ + "version": "v0.1.0" +} From f775be19d726fa7532c58cfabb4a8c1640722b06 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:58:11 +0200 Subject: [PATCH 35/75] sync: update CI config files (#25) --- .github/workflows/automerge.yml | 50 +++------------------------------ .github/workflows/go-check.yml | 5 ++-- .github/workflows/go-test.yml | 10 ++++--- go.mod | 10 ++++++- 4 files changed, 21 insertions(+), 54 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 44fad65fc1..3833fc2291 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -1,53 +1,11 @@ # File managed by web3-bot. DO NOT EDIT. # See https://github.com/protocol/.github/ for details. -# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass. -# This reduces the friction associated with updating with our workflows. - -on: [ pull_request ] name: Automerge +on: [ pull_request ] jobs: - automerge-check: - if: github.event.pull_request.user.login == 'web3-bot' - runs-on: ubuntu-latest - outputs: - status: ${{ steps.should-automerge.outputs.status }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Check if we should automerge - id: should-automerge - run: | - for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do - committer=$(git show --format=$'%ce' -s $commit) - echo "Committer: $committer" - if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then - echo "Commit $commit wasn't committed by web3-bot, but by $committer." - echo "::set-output name=status::false" - exit - fi - done - echo "::set-output name=status::true" automerge: - needs: automerge-check - runs-on: ubuntu-latest - # The check for the user is redundant here, as this job depends on the automerge-check job, - # but it prevents this job from spinning up, just to be skipped shortly after. - if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true' - steps: - - name: Wait on tests - uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 - with: - ref: ${{ github.event.pull_request.head.sha }} - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 10 - running-workflow-name: 'automerge' # the name of this job - - name: Merge PR - uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1 - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - MERGE_LABELS: "" - MERGE_METHOD: "squash" - MERGE_DELETE_BRANCH: true + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index e127cf1792..25e1afde5f 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -16,7 +16,7 @@ jobs: submodules: recursive - uses: actions/setup-go@v2 with: - go-version: "1.17.x" + go-version: "1.18.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@c8caa92bad8c27ae734c6725b8a04932d54a147b # 2021.1.2 (v0.2.2) + run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: @@ -71,4 +71,3 @@ jobs: git status --short exit 1 fi - diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 606e0c7f3d..b86241a96a 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,11 +10,11 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.16.x", "1.17.x" ] + go: [ "1.17.x", "1.18.x" ] env: COVERAGES: "" - runs-on: ${{ matrix.os }}-latest - name: ${{ matrix.os}} (go ${{ matrix.go }}) + runs-on: ${{ format('{0}-latest', matrix.os) }} + name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - uses: actions/checkout@v2 with: @@ -50,7 +50,9 @@ jobs: env: GOARCH: 386 with: - run: go test -v ./... + run: | + export "PATH=${{ env.PATH_386 }}:$PATH" + go test -v ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 diff --git a/go.mod b/go.mod index 53fe02c477..bd6064ff3e 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,12 @@ require ( github.com/libp2p/go-netroute v0.1.2 ) -go 1.16 +require ( + github.com/google/gopacket v1.1.17 // indirect + github.com/libp2p/go-sockaddr v0.0.2 // indirect + golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect + golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 // indirect + golang.org/x/text v0.3.0 // indirect +) + +go 1.17 From afac959aa59868d8fdc27055763d1caa8617e23e Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Tue, 23 Aug 2022 17:39:57 +0200 Subject: [PATCH 36/75] sync: update CI config files (#26) --- .github/workflows/go-check.yml | 8 ++++---- .github/workflows/go-test.yml | 12 ++++++------ go.mod | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 25e1afde5f..251f7faa99 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -11,12 +11,12 @@ jobs: env: RUNGOGENERATE: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: - go-version: "1.18.x" + go-version: "1.19.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) + run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index b86241a96a..8a1697b2d0 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.17.x", "1.18.x" ] + go: [ "1.18.x", "1.19.x" ] env: COVERAGES: "" runs-on: ${{ format('{0}-latest', matrix.os) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Go information @@ -43,7 +43,7 @@ jobs: # Use -coverpkg=./..., so that we include cross-package coverage. # If package ./A imports ./B, and ./A's tests also cover ./B, # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... + run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -52,7 +52,7 @@ jobs: with: run: | export "PATH=${{ env.PATH_386 }}:$PATH" - go test -v ./... + go test -v -shuffle=on ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 @@ -62,7 +62,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/go.mod b/go.mod index bd6064ff3e..58a070bdb0 100644 --- a/go.mod +++ b/go.mod @@ -15,4 +15,4 @@ require ( golang.org/x/text v0.3.0 // indirect ) -go 1.17 +go 1.18 From 5b1afd6fe97cd85af0777e7603e8f10a064cba74 Mon Sep 17 00:00:00 2001 From: "libp2p-mgmt-read-write[bot]" <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 13:40:11 +0000 Subject: [PATCH 37/75] chore: Update .github/workflows/stale.yml [skip ci] --- .github/workflows/stale.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000000..6f6d895d19 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,26 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' + close-issue-message: 'This issue was closed because it is missing author input.' + stale-issue-label: 'kind/stale' + any-of-labels: 'need/author-input' + exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' + days-before-issue-stale: 6 + days-before-issue-close: 7 + enable-statistics: true From dc44869708bb967ad8c354a9d89b5b96e9494d71 Mon Sep 17 00:00:00 2001 From: web3-bot <81333946+web3-bot@users.noreply.github.com> Date: Sat, 8 Apr 2023 07:00:14 +0200 Subject: [PATCH 38/75] sync: update CI config files (#28) * bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * update .github/workflows/go-test.yml * update .github/workflows/go-check.yml * update .github/workflows/release-check.yml * don't use rand.Seed any more --------- Co-authored-by: web3-bot Co-authored-by: Marten Seemann --- .github/workflows/go-check.yml | 24 +++++++++--------------- .github/workflows/go-test.yml | 22 +++++++++++++++------- .github/workflows/release-check.yml | 4 +++- go.mod | 2 +- nat.go | 5 +++-- natpmp.go | 2 +- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 251f7faa99..cc65ce68a9 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -8,26 +8,20 @@ jobs: unit: runs-on: ubuntu-latest name: All - env: - RUNGOGENERATE: false steps: - uses: actions/checkout@v3 with: submodules: recursive + - id: config + uses: protocol/.github/.github/actions/read-config@master - uses: actions/setup-go@v3 with: - go-version: "1.19.x" + go-version: 1.20.x - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' - - name: Read config - if: hashFiles('./.github/workflows/go-check-config.json') != '' - run: | - if jq -re .gogenerate ./.github/workflows/go-check-config.json; then - echo "RUNGOGENERATE=true" >> $GITHUB_ENV - fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) + run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: @@ -39,7 +33,7 @@ jobs: fi git diff --exit-code -- go.sum go.mod - name: gofmt - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed run: | out=$(gofmt -s -l .) if [[ -n "$out" ]]; then @@ -47,12 +41,12 @@ jobs: exit 1 fi - name: go vet - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed uses: protocol/multiple-go-modules@v1.2 with: run: go vet ./... - name: staticcheck - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed uses: protocol/multiple-go-modules@v1.2 with: run: | @@ -60,11 +54,11 @@ jobs: staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' - name: go generate uses: protocol/multiple-go-modules@v1.2 - if: (success() || failure()) && env.RUNGOGENERATE == 'true' + if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true with: run: | git clean -fd # make sure there aren't untracked files / directories - go generate ./... + go generate -x ./... # check if go generate modified or added any files if ! $(git add . && git diff-index HEAD --exit-code --quiet); then echo "go generated caused changes to the repository:" diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 8a1697b2d0..c5cb3efc7a 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,15 +10,17 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.18.x", "1.19.x" ] + go: ["1.19.x","1.20.x"] env: COVERAGES: "" - runs-on: ${{ format('{0}-latest', matrix.os) }} + runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - uses: actions/checkout@v3 with: submodules: recursive + - id: config + uses: protocol/.github/.github/actions/read-config@master - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} @@ -27,7 +29,7 @@ jobs: go version go env - name: Use msys2 on windows - if: ${{ matrix.os == 'windows' }} + if: matrix.os == 'windows' shell: bash # The executable for msys2 is also called bash.cmd # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells @@ -38,6 +40,7 @@ jobs: uses: ./.github/actions/go-test-setup if: hashFiles('./.github/actions/go-test-setup') != '' - name: Run tests + if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false uses: protocol/multiple-go-modules@v1.2 with: # Use -coverpkg=./..., so that we include cross-package coverage. @@ -45,16 +48,21 @@ jobs: # this means ./B's coverage will be significantly higher than 0%. run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) - if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. + # can't run 32 bit tests on OSX. + if: matrix.os != 'macos' && + fromJSON(steps.config.outputs.json).skip32bit != true && + contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false uses: protocol/multiple-go-modules@v1.2 env: GOARCH: 386 with: run: | - export "PATH=${{ env.PATH_386 }}:$PATH" + export "PATH=$PATH_386:$PATH" go test -v -shuffle=on ./... - name: Run tests with race detector - if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow + # speed things up. Windows and OSX VMs are slow + if: matrix.os == 'ubuntu' && + contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false uses: protocol/multiple-go-modules@v1.2 with: run: go test -v -race ./... @@ -62,7 +70,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index fde81c1f88..e2408e37c4 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -3,9 +3,11 @@ name: Release Checker on: - pull_request: + pull_request_target: paths: [ 'version.json' ] jobs: release-check: uses: protocol/.github/.github/workflows/release-check.yml@master + with: + go-version: 1.20.x diff --git a/go.mod b/go.mod index 58a070bdb0..b814e3f3fa 100644 --- a/go.mod +++ b/go.mod @@ -15,4 +15,4 @@ require ( golang.org/x/text v0.3.0 // indirect ) -go 1.18 +go 1.19 diff --git a/nat.go b/nat.go index 6d295e66f5..6f2ae187cb 100644 --- a/nat.go +++ b/nat.go @@ -118,7 +118,8 @@ func DiscoverGateway(ctx context.Context) (NAT, error) { return bestNAT, nil } +var random = rand.New(rand.NewSource(time.Now().UnixNano())) + func randomPort() int { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(math.MaxUint16-10000) + 10000 + return random.Intn(math.MaxUint16-10000) + 10000 } diff --git a/natpmp.go b/natpmp.go index 495d42b49e..a573f09ec8 100644 --- a/natpmp.go +++ b/natpmp.go @@ -5,7 +5,7 @@ import ( "net" "time" - "github.com/jackpal/go-nat-pmp" + natpmp "github.com/jackpal/go-nat-pmp" ) var ( From 25823d784182059ed256340aec46a2c34d07d8c6 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 1 Jun 2023 12:14:35 +0300 Subject: [PATCH 39/75] update deps, use contexts on UPnP functions (#29) * update deps, use contexts on UPnP functions * add contexts to NAT.AddPortMapping and NAT.DeletePortMapping --- go.mod | 15 +++++++-------- go.sum | 39 ++++++++++++++++++++++----------------- nat.go | 4 ++-- natpmp.go | 4 ++-- upnp.go | 38 ++++++++++++++++++-------------------- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index b814e3f3fa..9abe6b0017 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,17 @@ module github.com/libp2p/go-nat require ( - github.com/huin/goupnp v1.0.0 + github.com/huin/goupnp v1.1.0 github.com/jackpal/go-nat-pmp v1.0.2 - github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d - github.com/libp2p/go-netroute v0.1.2 + github.com/koron/go-ssdp v0.0.4 + github.com/libp2p/go-netroute v0.2.1 ) require ( - github.com/google/gopacket v1.1.17 // indirect - github.com/libp2p/go-sockaddr v0.0.2 // indirect - golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect - golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 // indirect - golang.org/x/text v0.3.0 // indirect + github.com/google/gopacket v1.1.19 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/sys v0.5.0 // indirect ) go 1.19 diff --git a/go.sum b/go.sum index be2d04ac02..7e568f4998 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,28 @@ -github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY= -github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= -github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= -github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= -github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= +github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= +github.com/huin/goupnp v1.1.0 h1:gEe0Dp/lZmPZiDFzJJaOfUpOvv2MKUkoBX8lDrn9vKU= +github.com/huin/goupnp v1.1.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d h1:68u9r4wEvL3gYg2jvAOgROwZ3H+Y3hIDk4tbbmIjcYQ= -github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= -github.com/libp2p/go-netroute v0.1.2 h1:UHhB35chwgvcRI392znJA3RCBtZ3MpE3ahNCN5MR4Xg= -github.com/libp2p/go-netroute v0.1.2/go.mod h1:jZLDV+1PE8y5XxBySEBgbuVAXbhtuHSdmLPL2n9MKbk= -github.com/libp2p/go-sockaddr v0.0.2 h1:tCuXfpA9rq7llM/v834RKc/Xvovy/AqM9kHvTV/jY/Q= -github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= +github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= +github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= +github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= +github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 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.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998= -golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/nat.go b/nat.go index 6f2ae187cb..6b3e19c444 100644 --- a/nat.go +++ b/nat.go @@ -29,10 +29,10 @@ type NAT interface { GetInternalAddress() (addr net.IP, err error) // AddPortMapping maps a port on the local host to an external port. - AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error) + AddPortMapping(ctx context.Context, protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error) // DeletePortMapping removes a port mapping. - DeletePortMapping(protocol string, internalPort int) (err error) + DeletePortMapping(ctx context.Context, protocol string, internalPort int) (err error) } // DiscoverNATs returns all NATs discovered in the network. diff --git a/natpmp.go b/natpmp.go index a573f09ec8..2378d8d7ec 100644 --- a/natpmp.go +++ b/natpmp.go @@ -95,7 +95,7 @@ func (n *natpmpNAT) GetExternalAddress() (addr net.IP, err error) { return net.IPv4(d[0], d[1], d[2], d[3]), nil } -func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { +func (n *natpmpNAT) AddPortMapping(_ context.Context, protocol string, internalPort int, _ string, timeout time.Duration) (int, error) { var ( err error ) @@ -122,7 +122,7 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio return 0, err } -func (n *natpmpNAT) DeletePortMapping(protocol string, internalPort int) (err error) { +func (n *natpmpNAT) DeletePortMapping(_ context.Context, _ string, internalPort int) (err error) { delete(n.ports, internalPort) return nil } diff --git a/upnp.go b/upnp.go index ccfeb14a2f..c50b952bbe 100644 --- a/upnp.go +++ b/upnp.go @@ -14,9 +14,7 @@ import ( "github.com/koron/go-ssdp" ) -var ( - _ NAT = (*upnp_NAT)(nil) -) +var _ NAT = (*upnp_NAT)(nil) func discoverUPNP_IG1(ctx context.Context) <-chan NAT { res := make(chan NAT) @@ -24,7 +22,7 @@ func discoverUPNP_IG1(ctx context.Context) <-chan NAT { defer close(res) // find devices - devs, err := goupnp.DiscoverDevices(internetgateway1.URN_WANConnectionDevice_1) + devs, err := goupnp.DiscoverDevicesCtx(ctx, internetgateway1.URN_WANConnectionDevice_1) if err != nil { return } @@ -45,7 +43,7 @@ func discoverUPNP_IG1(ctx context.Context) <-chan NAT { RootDevice: dev.Root, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", dev.Root}: @@ -59,7 +57,7 @@ func discoverUPNP_IG1(ctx context.Context) <-chan NAT { RootDevice: dev.Root, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", dev.Root}: @@ -81,7 +79,7 @@ func discoverUPNP_IG2(ctx context.Context) <-chan NAT { defer close(res) // find devices - devs, err := goupnp.DiscoverDevices(internetgateway2.URN_WANConnectionDevice_2) + devs, err := goupnp.DiscoverDevicesCtx(ctx, internetgateway2.URN_WANConnectionDevice_2) if err != nil { return } @@ -102,7 +100,7 @@ func discoverUPNP_IG2(ctx context.Context) <-chan NAT { RootDevice: dev.Root, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP1)", dev.Root}: @@ -116,7 +114,7 @@ func discoverUPNP_IG2(ctx context.Context) <-chan NAT { RootDevice: dev.Root, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP2)", dev.Root}: @@ -130,7 +128,7 @@ func discoverUPNP_IG2(ctx context.Context) <-chan NAT { RootDevice: dev.Root, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-PPP1)", dev.Root}: @@ -167,7 +165,7 @@ func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { if err != nil { return } - RootDevice, err := goupnp.DeviceByURL(DeviceURL) + RootDevice, err := goupnp.DeviceByURLCtx(ctx, DeviceURL) if err != nil { return } @@ -183,7 +181,7 @@ func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { RootDevice: RootDevice, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice}: @@ -197,7 +195,7 @@ func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { RootDevice: RootDevice, Service: srv, }} - _, isNat, err := client.GetNATRSIPStatus() + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) if err == nil && isNat { select { case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice}: @@ -213,8 +211,8 @@ func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { type upnp_NAT_Client interface { GetExternalIPAddress() (string, error) - AddPortMapping(string, uint16, string, uint16, string, bool, string, uint32) error - DeletePortMapping(string, uint16, string) error + AddPortMappingCtx(context.Context, string, uint16, string, uint16, string, bool, string, uint32) error + DeletePortMappingCtx(context.Context, string, uint16, string) error } type upnp_NAT struct { @@ -249,7 +247,7 @@ func mapProtocol(s string) string { } } -func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (int, error) { +func (u *upnp_NAT) AddPortMapping(ctx context.Context, protocol string, internalPort int, description string, timeout time.Duration) (int, error) { ip, err := u.GetInternalAddress() if err != nil { return 0, nil @@ -258,7 +256,7 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description timeoutInSeconds := uint32(timeout / time.Second) if externalPort := u.ports[internalPort]; externalPort > 0 { - err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) + err = u.c.AddPortMappingCtx(ctx, "", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) if err == nil { return externalPort, nil } @@ -266,7 +264,7 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description for i := 0; i < 3; i++ { externalPort := randomPort() - err = u.c.AddPortMapping("", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) + err = u.c.AddPortMappingCtx(ctx, "", uint16(externalPort), mapProtocol(protocol), uint16(internalPort), ip.String(), true, description, timeoutInSeconds) if err == nil { u.ports[internalPort] = externalPort return externalPort, nil @@ -276,10 +274,10 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description return 0, err } -func (u *upnp_NAT) DeletePortMapping(protocol string, internalPort int) error { +func (u *upnp_NAT) DeletePortMapping(ctx context.Context, protocol string, internalPort int) error { if externalPort := u.ports[internalPort]; externalPort > 0 { delete(u.ports, internalPort) - return u.c.DeletePortMapping("", uint16(externalPort), mapProtocol(protocol)) + return u.c.DeletePortMappingCtx(ctx, "", uint16(externalPort), mapProtocol(protocol)) } return nil From 2366bb0b0085a84ede39c3015286d9895a24106a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 1 Jun 2023 15:59:46 +0300 Subject: [PATCH 40/75] chore: update deps (#31) --- go.mod | 8 ++++---- go.sum | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 9abe6b0017..b6ad822f81 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/libp2p/go-nat require ( - github.com/huin/goupnp v1.1.0 + github.com/huin/goupnp v1.2.0 github.com/jackpal/go-nat-pmp v1.0.2 github.com/koron/go-ssdp v0.0.4 github.com/libp2p/go-netroute v0.2.1 @@ -9,9 +9,9 @@ require ( require ( github.com/google/gopacket v1.1.19 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.5.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sync v0.2.0 // indirect + golang.org/x/sys v0.8.0 // indirect ) go 1.19 diff --git a/go.sum b/go.sum index 7e568f4998..b20c1c6226 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= -github.com/huin/goupnp v1.1.0 h1:gEe0Dp/lZmPZiDFzJJaOfUpOvv2MKUkoBX8lDrn9vKU= -github.com/huin/goupnp v1.1.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= +github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= @@ -14,15 +14,16 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 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.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 14ce74b6949ca4d3f4889568e20840bdf0b05009 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 1 Jun 2023 16:09:11 +0300 Subject: [PATCH 41/75] release v0.2.0 (#30) --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 557859c534..1437d5b735 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.1.0" + "version": "v0.2.0" } From 29fad80565ee0398475348242019bf489601fb78 Mon Sep 17 00:00:00 2001 From: GitHub Date: Wed, 14 Jun 2023 09:07:42 +0000 Subject: [PATCH 42/75] chore: Update .github/workflows/stale.yml [skip ci] --- .github/workflows/stale.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 6f6d895d19..668bd07d49 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -6,21 +6,4 @@ on: jobs: stale: - - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - - steps: - - uses: actions/stale@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' - close-issue-message: 'This issue was closed because it is missing author input.' - stale-issue-label: 'kind/stale' - any-of-labels: 'need/author-input' - exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' - days-before-issue-stale: 6 - days-before-issue-close: 7 - enable-statistics: true + uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 From 5cc65f94aef93f7ded9b79ebd878620482346b07 Mon Sep 17 00:00:00 2001 From: GitHub Date: Wed, 28 Jun 2023 08:54:32 +0000 Subject: [PATCH 43/75] chore: Update .github/workflows/stale.yml [skip ci] --- .github/workflows/stale.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 668bd07d49..16d65d7217 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -2,7 +2,11 @@ name: Close and mark stale issue on: schedule: - - cron: '0 0 * * *' + - cron: '0 0 * * *' + +permissions: + issues: write + pull-requests: write jobs: stale: From da1dc6d581c0bf0778cc01c451d89858e50b6dd5 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Sun, 13 Aug 2023 20:53:39 +0200 Subject: [PATCH 44/75] chore: delete templates [skip ci] (#32) --- .github/workflows/automerge.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/workflows/automerge.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml deleted file mode 100644 index 3833fc2291..0000000000 --- a/.github/workflows/automerge.yml +++ /dev/null @@ -1,11 +0,0 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -name: Automerge -on: [ pull_request ] - -jobs: - automerge: - uses: protocol/.github/.github/workflows/automerge.yml@master - with: - job: 'automerge' From 90336fa854d3e187745eb0c58e954f300b134302 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Mon, 14 Aug 2023 08:20:38 +0200 Subject: [PATCH 45/75] ci: uci/copy-templates (#33) * chore: add or force update .github/workflows/go-test.yml * chore: add or force update .github/workflows/go-check.yml * chore: add or force update .github/workflows/releaser.yml * chore: add or force update .github/workflows/release-check.yml * chore: add or force update .github/workflows/tagpush.yml --- .github/workflows/go-check.yml | 79 +++++--------------------- .github/workflows/go-test.yml | 88 +++++------------------------ .github/workflows/release-check.yml | 18 ++++-- .github/workflows/releaser.yml | 14 +++-- .github/workflows/tagpush.yml | 14 +++-- 5 files changed, 62 insertions(+), 151 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index cc65ce68a9..9ce6260de9 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -1,67 +1,18 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -on: [push, pull_request] name: Go Checks +on: + pull_request: + push: + branches: ["master"] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true + jobs: - unit: - runs-on: ubuntu-latest - name: All - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - id: config - uses: protocol/.github/.github/actions/read-config@master - - uses: actions/setup-go@v3 - with: - go-version: 1.20.x - - name: Run repo-specific setup - uses: ./.github/actions/go-check-setup - if: hashFiles('./.github/actions/go-check-setup') != '' - - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0) - - name: Check that go.mod is tidy - uses: protocol/multiple-go-modules@v1.2 - with: - run: | - go mod tidy - if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then - echo "go.sum was added by go mod tidy" - exit 1 - fi - git diff --exit-code -- go.sum go.mod - - name: gofmt - if: success() || failure() # run this step even if the previous one failed - run: | - out=$(gofmt -s -l .) - if [[ -n "$out" ]]; then - echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}' - exit 1 - fi - - name: go vet - if: success() || failure() # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.2 - with: - run: go vet ./... - - name: staticcheck - if: success() || failure() # run this step even if the previous one failed - uses: protocol/multiple-go-modules@v1.2 - with: - run: | - set -o pipefail - staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' - - name: go generate - uses: protocol/multiple-go-modules@v1.2 - if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true - with: - run: | - git clean -fd # make sure there aren't untracked files / directories - go generate -x ./... - # check if go generate modified or added any files - if ! $(git add . && git diff-index HEAD --exit-code --quiet); then - echo "go generated caused changes to the repository:" - git status --short - exit 1 - fi + go-check: + uses: pl-strflt/uci/.github/workflows/go-check.yml@v0.0 diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index c5cb3efc7a..d4ca588cd4 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -1,76 +1,18 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - -on: [push, pull_request] name: Go Test +on: + pull_request: + push: + branches: ["master"] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true + jobs: - unit: - strategy: - fail-fast: false - matrix: - os: [ "ubuntu", "windows", "macos" ] - go: ["1.19.x","1.20.x"] - env: - COVERAGES: "" - runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }} - name: ${{ matrix.os }} (go ${{ matrix.go }}) - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - id: config - uses: protocol/.github/.github/actions/read-config@master - - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go }} - - name: Go information - run: | - go version - go env - - name: Use msys2 on windows - if: matrix.os == 'windows' - shell: bash - # The executable for msys2 is also called bash.cmd - # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells - # If we prepend its location to the PATH - # subsequent 'shell: bash' steps will use msys2 instead of gitbash - run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH - - name: Run repo-specific setup - uses: ./.github/actions/go-test-setup - if: hashFiles('./.github/actions/go-test-setup') != '' - - name: Run tests - if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - with: - # Use -coverpkg=./..., so that we include cross-package coverage. - # If package ./A imports ./B, and ./A's tests also cover ./B, - # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - - name: Run tests (32 bit) - # can't run 32 bit tests on OSX. - if: matrix.os != 'macos' && - fromJSON(steps.config.outputs.json).skip32bit != true && - contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - env: - GOARCH: 386 - with: - run: | - export "PATH=$PATH_386:$PATH" - go test -v -shuffle=on ./... - - name: Run tests with race detector - # speed things up. Windows and OSX VMs are slow - if: matrix.os == 'ubuntu' && - contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false - uses: protocol/multiple-go-modules@v1.2 - with: - run: go test -v -race ./... - - name: Collect coverage files - shell: bash - run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - - name: Upload coverage to Codecov - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 - with: - files: '${{ env.COVERAGES }}' - env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} + go-test: + uses: pl-strflt/uci/.github/workflows/go-test.yml@v0.0 diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index e2408e37c4..bda616005b 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -1,13 +1,19 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Release Checker + on: pull_request_target: paths: [ 'version.json' ] + types: [ opened, synchronize, reopened, labeled, unlabeled ] + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: release-check: - uses: protocol/.github/.github/workflows/release-check.yml@master - with: - go-version: 1.20.x + uses: pl-strflt/uci/.github/workflows/release-check.yml@v0.0 diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index cdccbf873d..dd8081b919 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -1,11 +1,17 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Releaser + on: push: paths: [ 'version.json' ] + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.sha }} + cancel-in-progress: true jobs: releaser: - uses: protocol/.github/.github/workflows/releaser.yml@master + uses: pl-strflt/uci/.github/workflows/releaser.yml@v0.0 diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml index d84996187a..59de8cb917 100644 --- a/.github/workflows/tagpush.yml +++ b/.github/workflows/tagpush.yml @@ -1,12 +1,18 @@ -# File managed by web3-bot. DO NOT EDIT. -# See https://github.com/protocol/.github/ for details. - name: Tag Push Checker + on: push: tags: - v* +permissions: + contents: read + issues: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: releaser: - uses: protocol/.github/.github/workflows/tagpush.yml@master + uses: pl-strflt/uci/.github/workflows/tagpush.yml@v0.0 From 002425958110f89f4ae4f49fca50de2cac0ee0e1 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Mon, 14 Aug 2023 15:36:26 +0200 Subject: [PATCH 46/75] chore: bump go.mod to Go 1.20 and run go fix (#34) --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b6ad822f81..f00189c711 100644 --- a/go.mod +++ b/go.mod @@ -14,4 +14,4 @@ require ( golang.org/x/sys v0.8.0 // indirect ) -go 1.19 +go 1.20 From 07ada58a73ca51b1ca7560c9d31d4d2a1938986d Mon Sep 17 00:00:00 2001 From: GitHub Date: Wed, 31 Jan 2024 16:49:14 +0000 Subject: [PATCH 47/75] chore: Update .github/workflows/stale.yml [skip ci] From 7083c1cde25266ef70ad52d147aaa70373f935ca Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 14 Mar 2024 12:26:06 +0100 Subject: [PATCH 48/75] ci: uci/update-go (#36) * chore: bump go.mod to Go 1.21 and run go fix * chore: run go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f00189c711..972d997ab3 100644 --- a/go.mod +++ b/go.mod @@ -14,4 +14,4 @@ require ( golang.org/x/sys v0.8.0 // indirect ) -go 1.20 +go 1.21 From 01a3d9956ae145b41d9a72bb1e3a2bdad57a7606 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Fri, 22 Mar 2024 07:17:23 +0000 Subject: [PATCH 49/75] ci: uci/copy-templates (#37) * chore: add or force update .github/workflows/go-test.yml * chore: add or force update .github/workflows/go-check.yml * chore: add or force update .github/workflows/releaser.yml * chore: add or force update .github/workflows/release-check.yml * chore: add or force update .github/workflows/tagpush.yml * chore: add or force update .github/workflows/go-test.yml * chore: add or force update .github/workflows/go-check.yml * chore: add or force update .github/workflows/releaser.yml * chore: add or force update .github/workflows/release-check.yml * chore: add or force update .github/workflows/tagpush.yml * chore: add or force update .github/workflows/go-test.yml * chore: add or force update .github/workflows/go-check.yml * chore: add or force update .github/workflows/releaser.yml * chore: add or force update .github/workflows/release-check.yml * chore: add or force update .github/workflows/tagpush.yml --- .github/workflows/go-check.yml | 2 +- .github/workflows/go-test.yml | 4 +++- .github/workflows/release-check.yml | 2 +- .github/workflows/releaser.yml | 2 +- .github/workflows/tagpush.yml | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 9ce6260de9..26f63bc126 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -15,4 +15,4 @@ concurrency: jobs: go-check: - uses: pl-strflt/uci/.github/workflows/go-check.yml@v0.0 + uses: ipdxco/unified-github-workflows/.github/workflows/go-check.yml@v1.0 diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index d4ca588cd4..778de6ed48 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -15,4 +15,6 @@ concurrency: jobs: go-test: - uses: pl-strflt/uci/.github/workflows/go-test.yml@v0.0 + uses: ipdxco/unified-github-workflows/.github/workflows/go-test.yml@v1.0 + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index bda616005b..0b5ff6070f 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -16,4 +16,4 @@ concurrency: jobs: release-check: - uses: pl-strflt/uci/.github/workflows/release-check.yml@v0.0 + uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0 diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index dd8081b919..2ebdbed31a 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -14,4 +14,4 @@ concurrency: jobs: releaser: - uses: pl-strflt/uci/.github/workflows/releaser.yml@v0.0 + uses: ipdxco/unified-github-workflows/.github/workflows/releaser.yml@v1.0 diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml index 59de8cb917..5ef3fb9ede 100644 --- a/.github/workflows/tagpush.yml +++ b/.github/workflows/tagpush.yml @@ -15,4 +15,4 @@ concurrency: jobs: releaser: - uses: pl-strflt/uci/.github/workflows/tagpush.yml@v0.0 + uses: ipdxco/unified-github-workflows/.github/workflows/tagpush.yml@v1.0 From 2fac9092f3fc908fb38bc52fa99234c9fc5f175c Mon Sep 17 00:00:00 2001 From: web3-bot Date: Mon, 26 Aug 2024 11:26:47 +0100 Subject: [PATCH 50/75] chore: bump go.mod to Go 1.22 and run go fix (#38) --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 972d997ab3..837511836b 100644 --- a/go.mod +++ b/go.mod @@ -14,4 +14,4 @@ require ( golang.org/x/sys v0.8.0 // indirect ) -go 1.21 +go 1.22 From 37fbd7e2071c71df3fd4774ec2293dcdd1532538 Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 18 Dec 2024 00:44:29 +0530 Subject: [PATCH 51/75] swarm: record conn metrics only once (#3091) --- p2p/net/swarm/swarm.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go index ef1fc2a2b3..eb6abbcd84 100644 --- a/p2p/net/swarm/swarm.go +++ b/p2p/net/swarm/swarm.go @@ -823,31 +823,36 @@ type connWithMetrics struct { opened time.Time dir network.Direction metricsTracer MetricsTracer + once sync.Once + closeErr error } -func wrapWithMetrics(capableConn transport.CapableConn, metricsTracer MetricsTracer, opened time.Time, dir network.Direction) connWithMetrics { - c := connWithMetrics{CapableConn: capableConn, opened: opened, dir: dir, metricsTracer: metricsTracer} +func wrapWithMetrics(capableConn transport.CapableConn, metricsTracer MetricsTracer, opened time.Time, dir network.Direction) *connWithMetrics { + c := &connWithMetrics{CapableConn: capableConn, opened: opened, dir: dir, metricsTracer: metricsTracer} c.metricsTracer.OpenedConnection(c.dir, capableConn.RemotePublicKey(), capableConn.ConnState(), capableConn.LocalMultiaddr()) return c } -func (c connWithMetrics) completedHandshake() { +func (c *connWithMetrics) completedHandshake() { c.metricsTracer.CompletedHandshake(time.Since(c.opened), c.ConnState(), c.LocalMultiaddr()) } -func (c connWithMetrics) Close() error { - c.metricsTracer.ClosedConnection(c.dir, time.Since(c.opened), c.ConnState(), c.LocalMultiaddr()) - return c.CapableConn.Close() +func (c *connWithMetrics) Close() error { + c.once.Do(func() { + c.metricsTracer.ClosedConnection(c.dir, time.Since(c.opened), c.ConnState(), c.LocalMultiaddr()) + c.closeErr = c.CapableConn.Close() + }) + return c.closeErr } -func (c connWithMetrics) Stat() network.ConnStats { +func (c *connWithMetrics) Stat() network.ConnStats { if cs, ok := c.CapableConn.(network.ConnStat); ok { return cs.Stat() } return network.ConnStats{} } -var _ network.ConnStat = connWithMetrics{} +var _ network.ConnStat = &connWithMetrics{} type ResolverFromMaDNS struct { *madns.Resolver From ba1703face5c147b0eadab00308da3de92a53fae Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 18 Dec 2024 04:03:10 +0530 Subject: [PATCH 52/75] peerstore: fix addressbook benchmark timing (#3092) --- p2p/host/peerstore/test/benchmarks_suite.go | 164 +++++++------------- p2p/host/peerstore/test/utils.go | 16 +- 2 files changed, 60 insertions(+), 120 deletions(-) diff --git a/p2p/host/peerstore/test/benchmarks_suite.go b/p2p/host/peerstore/test/benchmarks_suite.go index d45cac897e..8fc1f4fc7e 100644 --- a/p2p/host/peerstore/test/benchmarks_suite.go +++ b/p2p/host/peerstore/test/benchmarks_suite.go @@ -1,124 +1,70 @@ package test import ( - "context" "fmt" - "sort" "testing" pstore "github.com/libp2p/go-libp2p/core/peerstore" ) -var peerstoreBenchmarks = map[string]func(pstore.Peerstore, chan *peerpair) func(*testing.B){ - "AddAddrs": benchmarkAddAddrs, - "SetAddrs": benchmarkSetAddrs, - "GetAddrs": benchmarkGetAddrs, - // The in-between get allows us to benchmark the read-through cache. - "AddGetAndClearAddrs": benchmarkAddGetAndClearAddrs, - // Calls PeersWithAddr on a peerstore with 1000 peers. - "Get1000PeersWithAddrs": benchmarkGet1000PeersWithAddrs, -} - func BenchmarkPeerstore(b *testing.B, factory PeerstoreFactory, variant string) { - // Parameterises benchmarks to tackle peers with 1, 10, 100 multiaddrs. - params := []struct { - n int - ch chan *peerpair - }{ - {1, make(chan *peerpair, 100)}, - {10, make(chan *peerpair, 100)}, - {100, make(chan *peerpair, 100)}, - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - // Start all test peer producing goroutines, where each produces peers with as many - // multiaddrs as the n field in the param struct. - for _, p := range params { - go AddressProducer(ctx, b, p.ch, p.n) - } - - // So tests are always run in the same order. - ordernames := make([]string, 0, len(peerstoreBenchmarks)) - for name := range peerstoreBenchmarks { - ordernames = append(ordernames, name) - } - sort.Strings(ordernames) - - for _, name := range ordernames { - bench := peerstoreBenchmarks[name] - for _, p := range params { - // Create a new peerstore. - ps, closeFunc := factory() - - // Run the test. - b.Run(fmt.Sprintf("%s-%dAddrs-%s", name, p.n, variant), bench(ps, p.ch)) - - // Cleanup. - if closeFunc != nil { - closeFunc() + for _, sz := range []int{1, 10, 100} { + const N = 10000 + peers := getPeerPairs(b, N, sz) + + b.Run(fmt.Sprintf("AddAddrs-%d", sz), func(b *testing.B) { + ps, cleanup := factory() + defer cleanup() + b.ResetTimer() + for i := 0; i < b.N; i++ { + pp := peers[i%N] + ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) } - } - } -} - -func benchmarkAddAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) { - return func(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - pp := <-addrs - ps.AddAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL) - } - } -} - -func benchmarkSetAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) { - return func(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - pp := <-addrs - ps.SetAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL) - } - } -} - -func benchmarkGetAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) { - return func(b *testing.B) { - pp := <-addrs - ps.SetAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL) - - b.ResetTimer() - for i := 0; i < b.N; i++ { - _ = ps.Addrs(pp.ID) - } - } -} - -func benchmarkAddGetAndClearAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) { - return func(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - pp := <-addrs - ps.AddAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL) - ps.Addrs(pp.ID) - ps.ClearAddrs(pp.ID) - } - } -} + }) + + b.Run(fmt.Sprintf("GetAddrs-%d", sz), func(b *testing.B) { + ps, cleanup := factory() + defer cleanup() + b.ResetTimer() + for i := 0; i < b.N; i++ { + pp := peers[i%N] + ps.SetAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + } + }) + + b.Run(fmt.Sprintf("GetAndClearAddrs-%d", sz), func(b *testing.B) { + ps, cleanup := factory() + defer cleanup() + b.ResetTimer() + for i := 0; i < b.N; i++ { + pp := peers[i%N] + ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + ps.Addrs(pp.ID) + ps.ClearAddrs(pp.ID) + } + }) -func benchmarkGet1000PeersWithAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) { - return func(b *testing.B) { - var peers = make([]*peerpair, 1000) - for i := range peers { - pp := <-addrs - ps.AddAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL) - peers[i] = pp - } + b.Run(fmt.Sprintf("PeersWithAddrs-%d", sz), func(b *testing.B) { + ps, cleanup := factory() + defer cleanup() + for _, pp := range peers { + ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + } - b.ResetTimer() - for i := 0; i < b.N; i++ { - _ = ps.PeersWithAddrs() - } + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = ps.PeersWithAddrs() + } + }) + + b.Run(fmt.Sprintf("SetAddrs-%d", sz), func(b *testing.B) { + ps, cleanup := factory() + defer cleanup() + b.ResetTimer() + for i := 0; i < b.N; i++ { + pp := peers[i%N] + ps.SetAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + } + }) } } diff --git a/p2p/host/peerstore/test/utils.go b/p2p/host/peerstore/test/utils.go index 254b713957..cb7309290c 100644 --- a/p2p/host/peerstore/test/utils.go +++ b/p2p/host/peerstore/test/utils.go @@ -1,7 +1,6 @@ package test import ( - "context" "fmt" "testing" @@ -45,17 +44,12 @@ func RandomPeer(b *testing.B, addrCount int) *peerpair { return &peerpair{pid, addrs} } -func AddressProducer(ctx context.Context, b *testing.B, addrs chan *peerpair, addrsPerPeer int) { - b.Helper() - defer close(addrs) - for { - p := RandomPeer(b, addrsPerPeer) - select { - case addrs <- p: - case <-ctx.Done(): - return - } +func getPeerPairs(b *testing.B, n int, addrsPerPeer int) []*peerpair { + pps := make([]*peerpair, n) + for i := 0; i < n; i++ { + pps[i] = RandomPeer(b, addrsPerPeer) } + return pps } func GenerateAddrs(count int) []ma.Multiaddr { From d80b1da6689b3d08fc69b19fc67e2ce6f66a68d6 Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 18 Dec 2024 04:48:57 +0530 Subject: [PATCH 53/75] webtransport: close quic conn on dial error (#3104) --- p2p/transport/webtransport/transport.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/transport/webtransport/transport.go b/p2p/transport/webtransport/transport.go index acb40f0b89..0e35b44398 100644 --- a/p2p/transport/webtransport/transport.go +++ b/p2p/transport/webtransport/transport.go @@ -175,10 +175,12 @@ func (t *transport) dialWithScope(ctx context.Context, raddr ma.Multiaddr, p pee sconn, err := t.upgrade(ctx, sess, p, certHashes) if err != nil { sess.CloseWithError(1, "") + qconn.CloseWithError(1, "") return nil, err } if t.gater != nil && !t.gater.InterceptSecured(network.DirOutbound, p, sconn) { sess.CloseWithError(errorCodeConnectionGating, "") + qconn.CloseWithError(errorCodeConnectionGating, "") return nil, fmt.Errorf("secured connection gated") } conn := newConn(t, sess, sconn, scope, qconn) From e959b3c64597519b6f80284c7bbf5d5f42cbf3a7 Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 18 Dec 2024 04:56:32 +0530 Subject: [PATCH 54/75] peerstore: remove sync.Pool for expiringAddrs (#3093) --- p2p/host/peerstore/pstoremem/addr_book.go | 28 ++------------------- p2p/host/peerstore/test/benchmarks_suite.go | 17 ++++++++++--- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/p2p/host/peerstore/pstoremem/addr_book.go b/p2p/host/peerstore/pstoremem/addr_book.go index 2520f6ef22..32758f2ab9 100644 --- a/p2p/host/peerstore/pstoremem/addr_book.go +++ b/p2p/host/peerstore/pstoremem/addr_book.go @@ -42,22 +42,6 @@ func ttlIsConnected(ttl time.Duration) bool { return ttl >= peerstore.ConnectedAddrTTL } -var expiringAddrPool = sync.Pool{New: func() any { return &expiringAddr{} }} - -func getExpiringAddrs() *expiringAddr { - a := expiringAddrPool.Get().(*expiringAddr) - a.heapIndex = -1 - return a -} - -func putExpiringAddrs(ea *expiringAddr) { - if ea == nil { - return - } - *ea = expiringAddr{} - expiringAddrPool.Put(ea) -} - type peerRecordState struct { Envelope *record.Envelope Seq uint64 @@ -280,7 +264,6 @@ func (mab *memoryAddrBook) gc() { if !ok { return } - putExpiringAddrs(ea) mab.maybeDeleteSignedPeerRecordUnlocked(ea.Peer) } } @@ -382,8 +365,7 @@ func (mab *memoryAddrBook) addAddrsUnlocked(p peer.ID, addrs []ma.Multiaddr, ttl a, found := mab.addrs.FindAddr(p, addr) if !found { // not found, announce it. - entry := getExpiringAddrs() - *entry = expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} + entry := &expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} mab.addrs.Insert(entry) mab.subManager.BroadcastAddr(p, addr) } else { @@ -433,7 +415,6 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du if ttl > 0 { if a.IsConnected() && !ttlIsConnected(ttl) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { a.Addr = addr a.Expiry = exp @@ -443,15 +424,13 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du } } else { mab.addrs.Delete(a) - putExpiringAddrs(a) } } else { if ttl > 0 { if !ttlIsConnected(ttl) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { continue } - entry := getExpiringAddrs() - *entry = expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} + entry := &expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} mab.addrs.Insert(entry) mab.subManager.BroadcastAddr(p, addr) } @@ -472,12 +451,10 @@ func (mab *memoryAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL t if oldTTL == a.TTL { if newTTL == 0 { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { // We are over limit, drop these addresses. if ttlIsConnected(oldTTL) && !ttlIsConnected(newTTL) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { a.TTL = newTTL a.Expiry = exp @@ -541,7 +518,6 @@ func (mab *memoryAddrBook) ClearAddrs(p peer.ID) { delete(mab.signedPeerRecords, p) for _, a := range mab.addrs.Addrs[p] { mab.addrs.Delete(a) - putExpiringAddrs(a) } } diff --git a/p2p/host/peerstore/test/benchmarks_suite.go b/p2p/host/peerstore/test/benchmarks_suite.go index 8fc1f4fc7e..01669a1b2d 100644 --- a/p2p/host/peerstore/test/benchmarks_suite.go +++ b/p2p/host/peerstore/test/benchmarks_suite.go @@ -36,11 +36,20 @@ func BenchmarkPeerstore(b *testing.B, factory PeerstoreFactory, variant string) ps, cleanup := factory() defer cleanup() b.ResetTimer() + itersPerBM := 10 for i := 0; i < b.N; i++ { - pp := peers[i%N] - ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) - ps.Addrs(pp.ID) - ps.ClearAddrs(pp.ID) + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + } + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.Addrs(pp.ID) + } + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.ClearAddrs(pp.ID) + } } }) From 88ae97914e1708f2e7714104ca1d921bb9073c80 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 18 Dec 2024 11:22:30 -0800 Subject: [PATCH 55/75] chore: Release v0.38.0 (#3106) --- go.mod | 47 ++++++++++--------- go.sum | 91 +++++++++++++++++++------------------ p2p/protocol/identify/id.go | 7 ++- scripts/gen-proto.sh | 1 + test-plans/go.mod | 47 ++++++++++--------- test-plans/go.sum | 91 +++++++++++++++++++------------------ version.json | 2 +- 7 files changed, 143 insertions(+), 143 deletions(-) diff --git a/go.mod b/go.mod index 62ef58c06c..7da5a50105 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/libp2p/go-libp2p go 1.22.0 -toolchain go1.22.1 - retract v0.26.1 // Tag was applied incorrectly due to a bug in the release workflow. retract v0.36.0 // Accidentally modified the tag. @@ -30,7 +28,7 @@ require ( github.com/libp2p/go-libp2p-testing v0.12.0 github.com/libp2p/go-msgio v0.3.0 github.com/libp2p/go-nat v0.2.0 - github.com/libp2p/go-netroute v0.2.1 + github.com/libp2p/go-netroute v0.2.2 github.com/libp2p/go-reuseport v0.4.0 github.com/libp2p/go-yamux/v4 v4.0.1 github.com/libp2p/zeroconf/v2 v2.2.0 @@ -38,7 +36,7 @@ require ( github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-base32 v0.1.0 - github.com/multiformats/go-multiaddr v0.13.0 + github.com/multiformats/go-multiaddr v0.14.0 github.com/multiformats/go-multiaddr-dns v0.4.1 github.com/multiformats/go-multiaddr-fmt v0.1.0 github.com/multiformats/go-multibase v0.2.0 @@ -47,28 +45,28 @@ require ( github.com/multiformats/go-multistream v0.6.0 github.com/multiformats/go-varint v0.0.7 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 - github.com/pion/datachannel v1.5.9 - github.com/pion/ice/v2 v2.3.36 + github.com/pion/datachannel v1.5.10 + github.com/pion/ice/v2 v2.3.37 github.com/pion/logging v0.2.2 - github.com/pion/sctp v1.8.33 + github.com/pion/sctp v1.8.35 github.com/pion/stun v0.6.1 - github.com/pion/webrtc/v3 v3.3.4 + github.com/pion/webrtc/v3 v3.3.5 github.com/prometheus/client_golang v1.20.5 github.com/prometheus/client_model v0.6.1 github.com/quic-go/quic-go v0.48.2 github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 github.com/raulk/go-watchdog v1.3.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.10.0 go.uber.org/fx v1.23.0 go.uber.org/goleak v1.3.0 go.uber.org/mock v0.5.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.28.0 - golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c - golang.org/x/sync v0.8.0 - golang.org/x/sys v0.26.0 - golang.org/x/tools v0.26.0 - google.golang.org/protobuf v1.35.1 + golang.org/x/crypto v0.31.0 + golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 + golang.org/x/sync v0.10.0 + golang.org/x/sys v0.28.0 + golang.org/x/tools v0.28.0 + google.golang.org/protobuf v1.36.0 ) require ( @@ -90,12 +88,12 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect - github.com/google/pprof v0.0.0-20241017200806-017d972448fc // indirect + github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect github.com/google/uuid v1.6.0 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/miekg/dns v1.1.62 // indirect @@ -104,21 +102,22 @@ require ( github.com/multiformats/go-base36 v0.2.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nxadm/tail v1.4.11 // indirect - github.com/onsi/ginkgo/v2 v2.20.2 // indirect + github.com/onsi/ginkgo/v2 v2.22.0 // indirect github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/pion/dtls/v2 v2.2.12 // indirect github.com/pion/interceptor v0.1.37 // indirect github.com/pion/mdns v0.0.12 // indirect github.com/pion/randutil v0.1.0 // indirect - github.com/pion/rtcp v1.2.14 // indirect - github.com/pion/rtp v1.8.9 // indirect + github.com/pion/rtcp v1.2.15 // indirect + github.com/pion/rtp v1.8.10 // indirect github.com/pion/sdp/v3 v3.0.9 // indirect github.com/pion/srtp/v2 v2.0.20 // indirect github.com/pion/transport/v2 v2.2.10 // indirect + github.com/pion/transport/v3 v3.0.7 // indirect github.com/pion/turn/v2 v2.1.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/common v0.60.0 // indirect + github.com/prometheus/common v0.61.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/quic-go/qpack v0.5.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect @@ -126,9 +125,9 @@ require ( github.com/wlynxg/anet v0.0.5 // indirect go.uber.org/dig v1.18.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/mod v0.21.0 // indirect - golang.org/x/net v0.30.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/net v0.32.0 // indirect + golang.org/x/text v0.21.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 047083b063..7a822e8481 100644 --- a/go.sum +++ b/go.sum @@ -111,8 +111,8 @@ github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20241017200806-017d972448fc h1:NGyrhhFhwvRAZg02jnYVg3GBQy0qGBKmFQJwaPmpmxs= -github.com/google/pprof v0.0.0-20241017200806-017d972448fc/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -164,8 +164,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= -github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -190,8 +190,8 @@ github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= -github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= -github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= +github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8= +github.com/libp2p/go-netroute v0.2.2/go.mod h1:Rntq6jUAH0l9Gg17w5bFGhcC9a+vk4KNXs6s7IljKYE= github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= @@ -233,8 +233,8 @@ github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYg github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= -github.com/multiformats/go-multiaddr v0.13.0 h1:BCBzs61E3AGHcYYTv8dqRH43ZfyrqM8RXVPT8t13tLQ= -github.com/multiformats/go-multiaddr v0.13.0/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= +github.com/multiformats/go-multiaddr v0.14.0 h1:bfrHrJhrRuh/NXH5mCnemjpbGjzRw/b+tJFOD41g2tU= +github.com/multiformats/go-multiaddr v0.14.0/go.mod h1:6EkVAxtznq2yC3QT5CM1UTAwG0GTP3EWAIcjHuzQ+r4= github.com/multiformats/go-multiaddr-dns v0.4.1 h1:whi/uCLbDS3mSEUMb1MsoT4uzUeZB0N32yzufqS0i5M= github.com/multiformats/go-multiaddr-dns v0.4.1/go.mod h1:7hfthtB4E4pQwirrz+J0CcDUfbWzTqEzVyYKKIKpgkc= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -260,11 +260,11 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4= -github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag= +github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg= +github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= -github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= +github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8= +github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= @@ -272,13 +272,13 @@ github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTm github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pion/datachannel v1.5.9 h1:LpIWAOYPyDrXtU+BW7X0Yt/vGtYxtXQ8ql7dFfYUVZA= -github.com/pion/datachannel v1.5.9/go.mod h1:kDUuk4CU4Uxp82NH4LQZbISULkX/HtzKa4P7ldf9izE= +github.com/pion/datachannel v1.5.10 h1:ly0Q26K1i6ZkGf42W7D4hQYR90pZwzFOjTq5AuCKk4o= +github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oLo8Rs4Py/M= github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk= github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= -github.com/pion/ice/v2 v2.3.36 h1:SopeXiVbbcooUg2EIR8sq4b13RQ8gzrkkldOVg+bBsc= -github.com/pion/ice/v2 v2.3.36/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= +github.com/pion/ice/v2 v2.3.37 h1:ObIdaNDu1rCo7hObhs34YSBcO7fjslJMZV0ux+uZWh0= +github.com/pion/ice/v2 v2.3.37/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI= github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= @@ -288,13 +288,13 @@ github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYF github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= -github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= -github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo= +github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0= github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= -github.com/pion/rtp v1.8.9 h1:E2HX740TZKaqdcPmf4pw6ZZuG8u5RlMMt+l3dxeu6Wk= -github.com/pion/rtp v1.8.9/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= -github.com/pion/sctp v1.8.33 h1:dSE4wX6uTJBcNm8+YlMg7lw1wqyKHggsP5uKbdj+NZw= -github.com/pion/sctp v1.8.33/go.mod h1:beTnqSzewI53KWoG3nqB282oDMGrhNxBdb+JZnkCwRM= +github.com/pion/rtp v1.8.10 h1:puphjdbjPB+L+NFaVuZ5h6bt1g5q4kFIoI+r5q/g0CU= +github.com/pion/rtp v1.8.10/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4= +github.com/pion/sctp v1.8.35 h1:qwtKvNK1Wc5tHMIYgTDJhfZk7vATGVHhXbUDfHbYwzA= +github.com/pion/sctp v1.8.35/go.mod h1:EcXP8zCYVTRy3W9xtOF7wJm1L1aXfKRQzaM33SjQlzg= github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= github.com/pion/srtp/v2 v2.0.20 h1:HNNny4s+OUmG280ETrCdgFndp4ufx3/uy85EawYEhTk= @@ -312,8 +312,8 @@ github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uP github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= -github.com/pion/webrtc/v3 v3.3.4 h1:v2heQVnXTSqNRXcaFQVOhIOYkLMxOu1iJG8uy1djvkk= -github.com/pion/webrtc/v3 v3.3.4/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= +github.com/pion/webrtc/v3 v3.3.5 h1:ZsSzaMz/i9nblPdiAkZoP+E6Kmjw+jnyq3bEmU3EtRg= +github.com/pion/webrtc/v3 v3.3.5/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -326,8 +326,8 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1: github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= -github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ= +github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= @@ -392,8 +392,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= @@ -446,11 +447,11 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -463,8 +464,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= -golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= 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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -488,8 +489,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -505,8 +506,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/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-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -538,8 +539,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -556,8 +557,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -579,8 +580,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= -golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= +golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= +golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= 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= @@ -603,8 +604,8 @@ google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 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.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 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= diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index b6d5240ba6..0f5fd8f6ac 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -445,10 +445,9 @@ func newStreamAndNegotiate(ctx context.Context, c network.Conn, proto protocol.I log.Debugw("error opening identify stream", "peer", c.RemotePeer(), "error", err) return nil, err } - err = s.SetDeadline(time.Now().Add(Timeout)) - if err != nil { - return nil, err - } + + // Ignore the error. Consistent with our previous behavior. (See https://github.com/libp2p/go-libp2p/issues/3109) + _ = s.SetDeadline(time.Now().Add(Timeout)) if err := s.SetProtocol(proto); err != nil { log.Warnf("error setting identify protocol for stream: %s", err) diff --git a/scripts/gen-proto.sh b/scripts/gen-proto.sh index 32c4274ecc..d06187bb67 100755 --- a/scripts/gen-proto.sh +++ b/scripts/gen-proto.sh @@ -24,4 +24,5 @@ for path in "${proto_array[@]}"; do proto_paths+="$path " done +echo protoc --version $(protoc --version) protoc --proto_path=$root --go_out=$root --go_opt=paths=source_relative $proto_paths diff --git a/test-plans/go.mod b/test-plans/go.mod index be83100fcf..a320074aed 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -2,12 +2,10 @@ module github.com/libp2p/go-libp2p/test-plans/m/v2 go 1.22.0 -toolchain go1.22.1 - require ( github.com/go-redis/redis/v8 v8.11.5 github.com/libp2p/go-libp2p v0.0.0 - github.com/multiformats/go-multiaddr v0.13.0 + github.com/multiformats/go-multiaddr v0.14.0 ) require ( @@ -28,7 +26,7 @@ require ( github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20241017200806-017d972448fc // indirect + github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/huin/goupnp v1.3.0 // indirect @@ -37,14 +35,14 @@ require ( github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/klauspost/compress v1.17.11 // indirect - github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.2.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect - github.com/libp2p/go-netroute v0.2.1 // indirect + github.com/libp2p/go-netroute v0.2.2 // indirect github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect @@ -64,52 +62,53 @@ require ( github.com/multiformats/go-multistream v0.6.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/onsi/ginkgo/v2 v2.20.2 // indirect + github.com/onsi/ginkgo/v2 v2.22.0 // indirect github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect - github.com/pion/datachannel v1.5.9 // indirect + github.com/pion/datachannel v1.5.10 // indirect github.com/pion/dtls/v2 v2.2.12 // indirect - github.com/pion/ice/v2 v2.3.36 // indirect + github.com/pion/ice/v2 v2.3.37 // indirect github.com/pion/interceptor v0.1.37 // indirect github.com/pion/logging v0.2.2 // indirect github.com/pion/mdns v0.0.12 // indirect github.com/pion/randutil v0.1.0 // indirect - github.com/pion/rtcp v1.2.14 // indirect - github.com/pion/rtp v1.8.9 // indirect - github.com/pion/sctp v1.8.33 // indirect + github.com/pion/rtcp v1.2.15 // indirect + github.com/pion/rtp v1.8.10 // indirect + github.com/pion/sctp v1.8.35 // indirect github.com/pion/sdp/v3 v3.0.9 // indirect github.com/pion/srtp/v2 v2.0.20 // indirect github.com/pion/stun v0.6.1 // indirect github.com/pion/transport/v2 v2.2.10 // indirect + github.com/pion/transport/v3 v3.0.7 // indirect github.com/pion/turn/v2 v2.1.6 // indirect - github.com/pion/webrtc/v3 v3.3.4 // indirect + github.com/pion/webrtc/v3 v3.3.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.60.0 // indirect + github.com/prometheus/common v0.61.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/quic-go/qpack v0.5.1 // indirect github.com/quic-go/quic-go v0.48.2 // indirect github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/wlynxg/anet v0.0.5 // indirect go.uber.org/dig v1.18.0 // indirect go.uber.org/fx v1.23.0 // indirect go.uber.org/mock v0.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.28.0 // indirect - golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect - golang.org/x/mod v0.21.0 // indirect - golang.org/x/net v0.30.0 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect - golang.org/x/tools v0.26.0 // indirect - google.golang.org/protobuf v1.35.1 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/net v0.32.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + golang.org/x/tools v0.28.0 // indirect + google.golang.org/protobuf v1.36.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect ) diff --git a/test-plans/go.sum b/test-plans/go.sum index 36002223f5..7b62798632 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -91,8 +91,8 @@ github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20241017200806-017d972448fc h1:NGyrhhFhwvRAZg02jnYVg3GBQy0qGBKmFQJwaPmpmxs= -github.com/google/pprof v0.0.0-20241017200806-017d972448fc/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -121,8 +121,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= -github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -146,8 +146,8 @@ github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= -github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= -github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= +github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8= +github.com/libp2p/go-netroute v0.2.2/go.mod h1:Rntq6jUAH0l9Gg17w5bFGhcC9a+vk4KNXs6s7IljKYE= github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= @@ -183,8 +183,8 @@ github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYg github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= -github.com/multiformats/go-multiaddr v0.13.0 h1:BCBzs61E3AGHcYYTv8dqRH43ZfyrqM8RXVPT8t13tLQ= -github.com/multiformats/go-multiaddr v0.13.0/go.mod h1:sBXrNzucqkFJhvKOiwwLyqamGa/P5EIXNPLovyhQCII= +github.com/multiformats/go-multiaddr v0.14.0 h1:bfrHrJhrRuh/NXH5mCnemjpbGjzRw/b+tJFOD41g2tU= +github.com/multiformats/go-multiaddr v0.14.0/go.mod h1:6EkVAxtznq2yC3QT5CM1UTAwG0GTP3EWAIcjHuzQ+r4= github.com/multiformats/go-multiaddr-dns v0.4.1 h1:whi/uCLbDS3mSEUMb1MsoT4uzUeZB0N32yzufqS0i5M= github.com/multiformats/go-multiaddr-dns v0.4.1/go.mod h1:7hfthtB4E4pQwirrz+J0CcDUfbWzTqEzVyYKKIKpgkc= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= @@ -208,23 +208,23 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4= -github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag= -github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= -github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= +github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg= +github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= +github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8= +github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= -github.com/pion/datachannel v1.5.9 h1:LpIWAOYPyDrXtU+BW7X0Yt/vGtYxtXQ8ql7dFfYUVZA= -github.com/pion/datachannel v1.5.9/go.mod h1:kDUuk4CU4Uxp82NH4LQZbISULkX/HtzKa4P7ldf9izE= +github.com/pion/datachannel v1.5.10 h1:ly0Q26K1i6ZkGf42W7D4hQYR90pZwzFOjTq5AuCKk4o= +github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oLo8Rs4Py/M= github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk= github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= -github.com/pion/ice/v2 v2.3.36 h1:SopeXiVbbcooUg2EIR8sq4b13RQ8gzrkkldOVg+bBsc= -github.com/pion/ice/v2 v2.3.36/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= +github.com/pion/ice/v2 v2.3.37 h1:ObIdaNDu1rCo7hObhs34YSBcO7fjslJMZV0ux+uZWh0= +github.com/pion/ice/v2 v2.3.37/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI= github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= @@ -234,13 +234,13 @@ github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYF github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= -github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= -github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= +github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo= +github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0= github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= -github.com/pion/rtp v1.8.9 h1:E2HX740TZKaqdcPmf4pw6ZZuG8u5RlMMt+l3dxeu6Wk= -github.com/pion/rtp v1.8.9/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= -github.com/pion/sctp v1.8.33 h1:dSE4wX6uTJBcNm8+YlMg7lw1wqyKHggsP5uKbdj+NZw= -github.com/pion/sctp v1.8.33/go.mod h1:beTnqSzewI53KWoG3nqB282oDMGrhNxBdb+JZnkCwRM= +github.com/pion/rtp v1.8.10 h1:puphjdbjPB+L+NFaVuZ5h6bt1g5q4kFIoI+r5q/g0CU= +github.com/pion/rtp v1.8.10/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4= +github.com/pion/sctp v1.8.35 h1:qwtKvNK1Wc5tHMIYgTDJhfZk7vATGVHhXbUDfHbYwzA= +github.com/pion/sctp v1.8.35/go.mod h1:EcXP8zCYVTRy3W9xtOF7wJm1L1aXfKRQzaM33SjQlzg= github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= github.com/pion/srtp/v2 v2.0.20 h1:HNNny4s+OUmG280ETrCdgFndp4ufx3/uy85EawYEhTk= @@ -258,8 +258,8 @@ github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uP github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= -github.com/pion/webrtc/v3 v3.3.4 h1:v2heQVnXTSqNRXcaFQVOhIOYkLMxOu1iJG8uy1djvkk= -github.com/pion/webrtc/v3 v3.3.4/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= +github.com/pion/webrtc/v3 v3.3.5 h1:ZsSzaMz/i9nblPdiAkZoP+E6Kmjw+jnyq3bEmU3EtRg= +github.com/pion/webrtc/v3 v3.3.5/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -272,8 +272,8 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1: github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= -github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ= +github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= @@ -330,8 +330,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= @@ -374,11 +375,11 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -390,8 +391,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= -golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= 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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -414,8 +415,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -431,8 +432,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/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-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -458,8 +459,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -475,8 +476,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -495,8 +496,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= -golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= +golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= +golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= 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= @@ -517,8 +518,8 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 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= diff --git a/version.json b/version.json index 707e97ed5b..903f67956b 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.37.0" + "version": "v0.38.0" } From aa7c048980b4e351f6a76bc973e6ee1dd779e13c Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 18 Dec 2024 13:02:56 -0800 Subject: [PATCH 56/75] fix(autorelay): Move relayFinder peer disconnect cleanup to separate goroutine (#3105) --- p2p/host/autorelay/relay_finder.go | 74 +++++++++++++++++------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/p2p/host/autorelay/relay_finder.go b/p2p/host/autorelay/relay_finder.go index 13f8c63e6b..54e38a1517 100644 --- a/p2p/host/autorelay/relay_finder.go +++ b/p2p/host/autorelay/relay_finder.go @@ -115,6 +115,45 @@ type scheduledWorkTimes struct { nextAllowedCallToPeerSource time.Time } +func (rf *relayFinder) cleanupDisconnectedPeers(ctx context.Context) { + subConnectedness, err := rf.host.EventBus().Subscribe(new(event.EvtPeerConnectednessChanged), eventbus.Name("autorelay (relay finder)"), eventbus.BufSize(32)) + if err != nil { + log.Error("failed to subscribe to the EvtPeerConnectednessChanged") + return + } + defer subConnectedness.Close() + for { + select { + case <-ctx.Done(): + return + case ev, ok := <-subConnectedness.Out(): + if !ok { + return + } + evt := ev.(event.EvtPeerConnectednessChanged) + if evt.Connectedness != network.NotConnected { + continue + } + push := false + + rf.relayMx.Lock() + if rf.usingRelay(evt.Peer) { // we were disconnected from a relay + log.Debugw("disconnected from relay", "id", evt.Peer) + delete(rf.relays, evt.Peer) + rf.notifyMaybeConnectToRelay() + rf.notifyMaybeNeedNewCandidates() + push = true + } + rf.relayMx.Unlock() + + if push { + rf.clearCachedAddrsAndSignalAddressChange() + rf.metricsTracer.ReservationEnded(1) + } + } + } +} + func (rf *relayFinder) background(ctx context.Context) { peerSourceRateLimiter := make(chan struct{}, 1) rf.refCount.Add(1) @@ -129,13 +168,6 @@ func (rf *relayFinder) background(ctx context.Context) { rf.handleNewCandidates(ctx) }() - subConnectedness, err := rf.host.EventBus().Subscribe(new(event.EvtPeerConnectednessChanged), eventbus.Name("autorelay (relay finder)")) - if err != nil { - log.Error("failed to subscribe to the EvtPeerConnectednessChanged") - return - } - defer subConnectedness.Close() - now := rf.conf.clock.Now() bootDelayTimer := rf.conf.clock.InstantTimer(now.Add(rf.conf.bootDelay)) defer bootDelayTimer.Stop() @@ -164,32 +196,10 @@ func (rf *relayFinder) background(ctx context.Context) { workTimer := rf.conf.clock.InstantTimer(rf.runScheduledWork(ctx, now, scheduledWork, peerSourceRateLimiter)) defer workTimer.Stop() + go rf.cleanupDisconnectedPeers(ctx) + for { select { - case ev, ok := <-subConnectedness.Out(): - if !ok { - return - } - evt := ev.(event.EvtPeerConnectednessChanged) - if evt.Connectedness != network.NotConnected { - continue - } - push := false - - rf.relayMx.Lock() - if rf.usingRelay(evt.Peer) { // we were disconnected from a relay - log.Debugw("disconnected from relay", "id", evt.Peer) - delete(rf.relays, evt.Peer) - rf.notifyMaybeConnectToRelay() - rf.notifyMaybeNeedNewCandidates() - push = true - } - rf.relayMx.Unlock() - - if push { - rf.clearCachedAddrsAndSignalAddressChange() - rf.metricsTracer.ReservationEnded(1) - } case <-rf.candidateFound: rf.notifyMaybeConnectToRelay() case <-bootDelayTimer.Ch(): @@ -264,7 +274,7 @@ func (rf *relayFinder) runScheduledWork(ctx context.Context, now time.Time, sche if scheduledWork.nextOldCandidateCheck.Before(nextTime) { nextTime = scheduledWork.nextOldCandidateCheck } - if nextTime == now { + if nextTime.Equal(now) { // Only happens in CI with a mock clock nextTime = nextTime.Add(1) // avoids an infinite loop } From b07e3aa6c56a4d3e8254d6689e9b32db4f0e6f61 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 18 Dec 2024 14:24:42 -0800 Subject: [PATCH 57/75] ci: Install specific protoc version when generating protobufs (#3112) --- core/crypto/pb/crypto.pb.go | 22 +++-- core/peer/pb/peer_record.pb.go | 20 ++--- core/record/pb/envelope.pb.go | 13 ++- core/sec/insecure/pb/plaintext.pb.go | 13 ++- p2p/host/autonat/pb/autonat.pb.go | 42 +++++---- p2p/host/peerstore/pstoreds/pb/pstore.pb.go | 31 +++---- p2p/protocol/autonatv2/pb/autonatv2.pb.go | 95 +++++++++++---------- p2p/protocol/circuitv2/pb/circuit.pb.go | 69 +++++++-------- p2p/protocol/circuitv2/pb/voucher.pb.go | 17 ++-- p2p/protocol/holepunch/pb/holepunch.pb.go | 13 ++- p2p/protocol/identify/pb/identify.pb.go | 11 ++- p2p/security/noise/pb/payload.pb.go | 26 +++--- p2p/transport/webrtc/pb/message.pb.go | 13 ++- scripts/.gitignore | 2 + scripts/download-protoc.sh | 78 +++++++++++++++++ scripts/gen-proto.sh | 37 ++++---- scripts/print-protoc-hashes.sh | 62 ++++++++++++++ 17 files changed, 345 insertions(+), 219 deletions(-) create mode 100644 scripts/.gitignore create mode 100755 scripts/download-protoc.sh create mode 100755 scripts/print-protoc-hashes.sh diff --git a/core/crypto/pb/crypto.pb.go b/core/crypto/pb/crypto.pb.go index d960889763..8bbc6a6077 100644 --- a/core/crypto/pb/crypto.pb.go +++ b/core/crypto/pb/crypto.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: core/crypto/pb/crypto.proto package pb @@ -83,12 +83,11 @@ func (KeyType) EnumDescriptor() ([]byte, []int) { } type PublicKey struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Type *KeyType `protobuf:"varint,1,req,name=Type,enum=crypto.pb.KeyType" json:"Type,omitempty"` + Data []byte `protobuf:"bytes,2,req,name=Data" json:"Data,omitempty"` unknownFields protoimpl.UnknownFields - - Type *KeyType `protobuf:"varint,1,req,name=Type,enum=crypto.pb.KeyType" json:"Type,omitempty"` - Data []byte `protobuf:"bytes,2,req,name=Data" json:"Data,omitempty"` + sizeCache protoimpl.SizeCache } func (x *PublicKey) Reset() { @@ -136,12 +135,11 @@ func (x *PublicKey) GetData() []byte { } type PrivateKey struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Type *KeyType `protobuf:"varint,1,req,name=Type,enum=crypto.pb.KeyType" json:"Type,omitempty"` + Data []byte `protobuf:"bytes,2,req,name=Data" json:"Data,omitempty"` unknownFields protoimpl.UnknownFields - - Type *KeyType `protobuf:"varint,1,req,name=Type,enum=crypto.pb.KeyType" json:"Type,omitempty"` - Data []byte `protobuf:"bytes,2,req,name=Data" json:"Data,omitempty"` + sizeCache protoimpl.SizeCache } func (x *PrivateKey) Reset() { diff --git a/core/peer/pb/peer_record.pb.go b/core/peer/pb/peer_record.pb.go index 8249ba4009..566b8b7a49 100644 --- a/core/peer/pb/peer_record.pb.go +++ b/core/peer/pb/peer_record.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: core/peer/pb/peer_record.proto package pb @@ -29,16 +29,15 @@ const ( // See https://github.com/libp2p/go-libp2p/blob/master/core/record/pb/envelope.proto for // the SignedEnvelope definition. type PeerRecord struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // peer_id contains a libp2p peer id in its binary representation. PeerId []byte `protobuf:"bytes,1,opt,name=peer_id,json=peerId,proto3" json:"peer_id,omitempty"` // seq contains a monotonically-increasing sequence counter to order PeerRecords in time. Seq uint64 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"` // addresses is a list of public listen addresses for the peer. - Addresses []*PeerRecord_AddressInfo `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty"` + Addresses []*PeerRecord_AddressInfo `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *PeerRecord) Reset() { @@ -95,11 +94,10 @@ func (x *PeerRecord) GetAddresses() []*PeerRecord_AddressInfo { // AddressInfo is a wrapper around a binary multiaddr. It is defined as a // separate message to allow us to add per-address metadata in the future. type PeerRecord_AddressInfo struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Multiaddr []byte `protobuf:"bytes,1,opt,name=multiaddr,proto3" json:"multiaddr,omitempty"` unknownFields protoimpl.UnknownFields - - Multiaddr []byte `protobuf:"bytes,1,opt,name=multiaddr,proto3" json:"multiaddr,omitempty"` + sizeCache protoimpl.SizeCache } func (x *PeerRecord_AddressInfo) Reset() { diff --git a/core/record/pb/envelope.pb.go b/core/record/pb/envelope.pb.go index 8da0e0eea5..d449959a99 100644 --- a/core/record/pb/envelope.pb.go +++ b/core/record/pb/envelope.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: core/record/pb/envelope.proto package pb @@ -29,10 +29,7 @@ const ( // can be deserialized deterministically. Often, this byte string is a // multicodec. type Envelope struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // public_key is the public key of the keypair the enclosed payload was // signed with. PublicKey *pb.PublicKey `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` @@ -44,7 +41,9 @@ type Envelope struct { // signature is the signature produced by the private key corresponding to // the enclosed public key, over the payload, prefixing a domain string for // additional security. - Signature []byte `protobuf:"bytes,5,opt,name=signature,proto3" json:"signature,omitempty"` + Signature []byte `protobuf:"bytes,5,opt,name=signature,proto3" json:"signature,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Envelope) Reset() { diff --git a/core/sec/insecure/pb/plaintext.pb.go b/core/sec/insecure/pb/plaintext.pb.go index 64ab191b99..45e90ac31b 100644 --- a/core/sec/insecure/pb/plaintext.pb.go +++ b/core/sec/insecure/pb/plaintext.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: core/sec/insecure/pb/plaintext.proto package pb @@ -22,12 +22,11 @@ const ( ) type Exchange struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Id []byte `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` + Pubkey *pb.PublicKey `protobuf:"bytes,2,opt,name=pubkey" json:"pubkey,omitempty"` unknownFields protoimpl.UnknownFields - - Id []byte `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - Pubkey *pb.PublicKey `protobuf:"bytes,2,opt,name=pubkey" json:"pubkey,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Exchange) Reset() { diff --git a/p2p/host/autonat/pb/autonat.pb.go b/p2p/host/autonat/pb/autonat.pb.go index 46eed5986b..013c1ad378 100644 --- a/p2p/host/autonat/pb/autonat.pb.go +++ b/p2p/host/autonat/pb/autonat.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/host/autonat/pb/autonat.proto package pb @@ -142,13 +142,12 @@ func (Message_ResponseStatus) EnumDescriptor() ([]byte, []int) { } type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Type *Message_MessageType `protobuf:"varint,1,opt,name=type,enum=autonat.pb.Message_MessageType" json:"type,omitempty"` + Dial *Message_Dial `protobuf:"bytes,2,opt,name=dial" json:"dial,omitempty"` + DialResponse *Message_DialResponse `protobuf:"bytes,3,opt,name=dialResponse" json:"dialResponse,omitempty"` unknownFields protoimpl.UnknownFields - - Type *Message_MessageType `protobuf:"varint,1,opt,name=type,enum=autonat.pb.Message_MessageType" json:"type,omitempty"` - Dial *Message_Dial `protobuf:"bytes,2,opt,name=dial" json:"dial,omitempty"` - DialResponse *Message_DialResponse `protobuf:"bytes,3,opt,name=dialResponse" json:"dialResponse,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Message) Reset() { @@ -203,12 +202,11 @@ func (x *Message) GetDialResponse() *Message_DialResponse { } type Message_PeerInfo struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Id []byte `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` + Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs" json:"addrs,omitempty"` unknownFields protoimpl.UnknownFields - - Id []byte `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs" json:"addrs,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Message_PeerInfo) Reset() { @@ -256,11 +254,10 @@ func (x *Message_PeerInfo) GetAddrs() [][]byte { } type Message_Dial struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Peer *Message_PeerInfo `protobuf:"bytes,1,opt,name=peer" json:"peer,omitempty"` unknownFields protoimpl.UnknownFields - - Peer *Message_PeerInfo `protobuf:"bytes,1,opt,name=peer" json:"peer,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Message_Dial) Reset() { @@ -301,13 +298,12 @@ func (x *Message_Dial) GetPeer() *Message_PeerInfo { } type Message_DialResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Status *Message_ResponseStatus `protobuf:"varint,1,opt,name=status,enum=autonat.pb.Message_ResponseStatus" json:"status,omitempty"` + StatusText *string `protobuf:"bytes,2,opt,name=statusText" json:"statusText,omitempty"` + Addr []byte `protobuf:"bytes,3,opt,name=addr" json:"addr,omitempty"` unknownFields protoimpl.UnknownFields - - Status *Message_ResponseStatus `protobuf:"varint,1,opt,name=status,enum=autonat.pb.Message_ResponseStatus" json:"status,omitempty"` - StatusText *string `protobuf:"bytes,2,opt,name=statusText" json:"statusText,omitempty"` - Addr []byte `protobuf:"bytes,3,opt,name=addr" json:"addr,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Message_DialResponse) Reset() { diff --git a/p2p/host/peerstore/pstoreds/pb/pstore.pb.go b/p2p/host/peerstore/pstoreds/pb/pstore.pb.go index 5130bb3865..a6ea3b906b 100644 --- a/p2p/host/peerstore/pstoreds/pb/pstore.pb.go +++ b/p2p/host/peerstore/pstoreds/pb/pstore.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/host/peerstore/pstoreds/pb/pstore.proto package pb @@ -22,16 +22,15 @@ const ( // AddrBookRecord represents a record for a peer in the address book. type AddrBookRecord struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // The peer ID. Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // The multiaddresses. This is a sorted list where element 0 expires the soonest. Addrs []*AddrBookRecord_AddrEntry `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` // The most recently received signed PeerRecord. CertifiedRecord *AddrBookRecord_CertifiedRecord `protobuf:"bytes,3,opt,name=certified_record,json=certifiedRecord,proto3" json:"certified_record,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *AddrBookRecord) Reset() { @@ -87,15 +86,14 @@ func (x *AddrBookRecord) GetCertifiedRecord() *AddrBookRecord_CertifiedRecord { // AddrEntry represents a single multiaddress. type AddrBookRecord_AddrEntry struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` // The point in time when this address expires. Expiry int64 `protobuf:"varint,2,opt,name=expiry,proto3" json:"expiry,omitempty"` // The original TTL of this address. - Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"` + Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *AddrBookRecord_AddrEntry) Reset() { @@ -152,14 +150,13 @@ func (x *AddrBookRecord_AddrEntry) GetTtl() int64 { // CertifiedRecord contains a serialized signed PeerRecord used to // populate the signedAddrs list. type AddrBookRecord_CertifiedRecord struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // The Seq counter from the signed PeerRecord envelope Seq uint64 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"` // The serialized bytes of the SignedEnvelope containing the PeerRecord. - Raw []byte `protobuf:"bytes,2,opt,name=raw,proto3" json:"raw,omitempty"` + Raw []byte `protobuf:"bytes,2,opt,name=raw,proto3" json:"raw,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *AddrBookRecord_CertifiedRecord) Reset() { diff --git a/p2p/protocol/autonatv2/pb/autonatv2.pb.go b/p2p/protocol/autonatv2/pb/autonatv2.pb.go index 3c1016fefd..ab2247947c 100644 --- a/p2p/protocol/autonatv2/pb/autonatv2.pb.go +++ b/p2p/protocol/autonatv2/pb/autonatv2.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/protocol/autonatv2/pb/autonatv2.proto package pb @@ -168,17 +168,16 @@ func (DialBackResponse_DialBackStatus) EnumDescriptor() ([]byte, []int) { } type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Types that are assignable to Msg: + state protoimpl.MessageState `protogen:"open.v1"` + // Types that are valid to be assigned to Msg: // // *Message_DialRequest // *Message_DialResponse // *Message_DialDataRequest // *Message_DialDataResponse - Msg isMessage_Msg `protobuf_oneof:"msg"` + Msg isMessage_Msg `protobuf_oneof:"msg"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Message) Reset() { @@ -211,37 +210,45 @@ func (*Message) Descriptor() ([]byte, []int) { return file_p2p_protocol_autonatv2_pb_autonatv2_proto_rawDescGZIP(), []int{0} } -func (m *Message) GetMsg() isMessage_Msg { - if m != nil { - return m.Msg +func (x *Message) GetMsg() isMessage_Msg { + if x != nil { + return x.Msg } return nil } func (x *Message) GetDialRequest() *DialRequest { - if x, ok := x.GetMsg().(*Message_DialRequest); ok { - return x.DialRequest + if x != nil { + if x, ok := x.Msg.(*Message_DialRequest); ok { + return x.DialRequest + } } return nil } func (x *Message) GetDialResponse() *DialResponse { - if x, ok := x.GetMsg().(*Message_DialResponse); ok { - return x.DialResponse + if x != nil { + if x, ok := x.Msg.(*Message_DialResponse); ok { + return x.DialResponse + } } return nil } func (x *Message) GetDialDataRequest() *DialDataRequest { - if x, ok := x.GetMsg().(*Message_DialDataRequest); ok { - return x.DialDataRequest + if x != nil { + if x, ok := x.Msg.(*Message_DialDataRequest); ok { + return x.DialDataRequest + } } return nil } func (x *Message) GetDialDataResponse() *DialDataResponse { - if x, ok := x.GetMsg().(*Message_DialDataResponse); ok { - return x.DialDataResponse + if x != nil { + if x, ok := x.Msg.(*Message_DialDataResponse); ok { + return x.DialDataResponse + } } return nil } @@ -275,12 +282,11 @@ func (*Message_DialDataRequest) isMessage_Msg() {} func (*Message_DialDataResponse) isMessage_Msg() {} type DialRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Addrs [][]byte `protobuf:"bytes,1,rep,name=addrs,proto3" json:"addrs,omitempty"` + Nonce uint64 `protobuf:"fixed64,2,opt,name=nonce,proto3" json:"nonce,omitempty"` unknownFields protoimpl.UnknownFields - - Addrs [][]byte `protobuf:"bytes,1,rep,name=addrs,proto3" json:"addrs,omitempty"` - Nonce uint64 `protobuf:"fixed64,2,opt,name=nonce,proto3" json:"nonce,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialRequest) Reset() { @@ -328,12 +334,11 @@ func (x *DialRequest) GetNonce() uint64 { } type DialDataRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + AddrIdx uint32 `protobuf:"varint,1,opt,name=addrIdx,proto3" json:"addrIdx,omitempty"` + NumBytes uint64 `protobuf:"varint,2,opt,name=numBytes,proto3" json:"numBytes,omitempty"` unknownFields protoimpl.UnknownFields - - AddrIdx uint32 `protobuf:"varint,1,opt,name=addrIdx,proto3" json:"addrIdx,omitempty"` - NumBytes uint64 `protobuf:"varint,2,opt,name=numBytes,proto3" json:"numBytes,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialDataRequest) Reset() { @@ -381,13 +386,12 @@ func (x *DialDataRequest) GetNumBytes() uint64 { } type DialResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Status DialResponse_ResponseStatus `protobuf:"varint,1,opt,name=status,proto3,enum=autonatv2.pb.DialResponse_ResponseStatus" json:"status,omitempty"` + AddrIdx uint32 `protobuf:"varint,2,opt,name=addrIdx,proto3" json:"addrIdx,omitempty"` + DialStatus DialStatus `protobuf:"varint,3,opt,name=dialStatus,proto3,enum=autonatv2.pb.DialStatus" json:"dialStatus,omitempty"` unknownFields protoimpl.UnknownFields - - Status DialResponse_ResponseStatus `protobuf:"varint,1,opt,name=status,proto3,enum=autonatv2.pb.DialResponse_ResponseStatus" json:"status,omitempty"` - AddrIdx uint32 `protobuf:"varint,2,opt,name=addrIdx,proto3" json:"addrIdx,omitempty"` - DialStatus DialStatus `protobuf:"varint,3,opt,name=dialStatus,proto3,enum=autonatv2.pb.DialStatus" json:"dialStatus,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialResponse) Reset() { @@ -442,11 +446,10 @@ func (x *DialResponse) GetDialStatus() DialStatus { } type DialDataResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` unknownFields protoimpl.UnknownFields - - Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialDataResponse) Reset() { @@ -487,11 +490,10 @@ func (x *DialDataResponse) GetData() []byte { } type DialBack struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Nonce uint64 `protobuf:"fixed64,1,opt,name=nonce,proto3" json:"nonce,omitempty"` unknownFields protoimpl.UnknownFields - - Nonce uint64 `protobuf:"fixed64,1,opt,name=nonce,proto3" json:"nonce,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialBack) Reset() { @@ -532,11 +534,10 @@ func (x *DialBack) GetNonce() uint64 { } type DialBackResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Status DialBackResponse_DialBackStatus `protobuf:"varint,1,opt,name=status,proto3,enum=autonatv2.pb.DialBackResponse_DialBackStatus" json:"status,omitempty"` unknownFields protoimpl.UnknownFields - - Status DialBackResponse_DialBackStatus `protobuf:"varint,1,opt,name=status,proto3,enum=autonatv2.pb.DialBackResponse_DialBackStatus" json:"status,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DialBackResponse) Reset() { diff --git a/p2p/protocol/circuitv2/pb/circuit.pb.go b/p2p/protocol/circuitv2/pb/circuit.pb.go index fda13bcbbc..cc346e4749 100644 --- a/p2p/protocol/circuitv2/pb/circuit.pb.go +++ b/p2p/protocol/circuitv2/pb/circuit.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/protocol/circuitv2/pb/circuit.proto package pb @@ -184,17 +184,16 @@ func (StopMessage_Type) EnumDescriptor() ([]byte, []int) { } type HopMessage struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // This field is marked optional for backwards compatibility with proto2. // Users should make sure to always set this. - Type *HopMessage_Type `protobuf:"varint,1,opt,name=type,proto3,enum=circuit.pb.HopMessage_Type,oneof" json:"type,omitempty"` - Peer *Peer `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` - Reservation *Reservation `protobuf:"bytes,3,opt,name=reservation,proto3,oneof" json:"reservation,omitempty"` - Limit *Limit `protobuf:"bytes,4,opt,name=limit,proto3,oneof" json:"limit,omitempty"` - Status *Status `protobuf:"varint,5,opt,name=status,proto3,enum=circuit.pb.Status,oneof" json:"status,omitempty"` + Type *HopMessage_Type `protobuf:"varint,1,opt,name=type,proto3,enum=circuit.pb.HopMessage_Type,oneof" json:"type,omitempty"` + Peer *Peer `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` + Reservation *Reservation `protobuf:"bytes,3,opt,name=reservation,proto3,oneof" json:"reservation,omitempty"` + Limit *Limit `protobuf:"bytes,4,opt,name=limit,proto3,oneof" json:"limit,omitempty"` + Status *Status `protobuf:"varint,5,opt,name=status,proto3,enum=circuit.pb.Status,oneof" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *HopMessage) Reset() { @@ -263,16 +262,15 @@ func (x *HopMessage) GetStatus() Status { } type StopMessage struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // This field is marked optional for backwards compatibility with proto2. // Users should make sure to always set this. - Type *StopMessage_Type `protobuf:"varint,1,opt,name=type,proto3,enum=circuit.pb.StopMessage_Type,oneof" json:"type,omitempty"` - Peer *Peer `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` - Limit *Limit `protobuf:"bytes,3,opt,name=limit,proto3,oneof" json:"limit,omitempty"` - Status *Status `protobuf:"varint,4,opt,name=status,proto3,enum=circuit.pb.Status,oneof" json:"status,omitempty"` + Type *StopMessage_Type `protobuf:"varint,1,opt,name=type,proto3,enum=circuit.pb.StopMessage_Type,oneof" json:"type,omitempty"` + Peer *Peer `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` + Limit *Limit `protobuf:"bytes,3,opt,name=limit,proto3,oneof" json:"limit,omitempty"` + Status *Status `protobuf:"varint,4,opt,name=status,proto3,enum=circuit.pb.Status,oneof" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *StopMessage) Reset() { @@ -334,14 +332,13 @@ func (x *StopMessage) GetStatus() Status { } type Peer struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // This field is marked optional for backwards compatibility with proto2. // Users should make sure to always set this. - Id []byte `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty"` - Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` + Id []byte `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty"` + Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Peer) Reset() { @@ -389,15 +386,14 @@ func (x *Peer) GetAddrs() [][]byte { } type Reservation struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // This field is marked optional for backwards compatibility with proto2. // Users should make sure to always set this. - Expire *uint64 `protobuf:"varint,1,opt,name=expire,proto3,oneof" json:"expire,omitempty"` // Unix expiration time (UTC) - Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` // relay addrs for reserving peer - Voucher []byte `protobuf:"bytes,3,opt,name=voucher,proto3,oneof" json:"voucher,omitempty"` // reservation voucher + Expire *uint64 `protobuf:"varint,1,opt,name=expire,proto3,oneof" json:"expire,omitempty"` // Unix expiration time (UTC) + Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` // relay addrs for reserving peer + Voucher []byte `protobuf:"bytes,3,opt,name=voucher,proto3,oneof" json:"voucher,omitempty"` // reservation voucher + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Reservation) Reset() { @@ -452,12 +448,11 @@ func (x *Reservation) GetVoucher() []byte { } type Limit struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Duration *uint32 `protobuf:"varint,1,opt,name=duration,proto3,oneof" json:"duration,omitempty"` // seconds + Data *uint64 `protobuf:"varint,2,opt,name=data,proto3,oneof" json:"data,omitempty"` // bytes unknownFields protoimpl.UnknownFields - - Duration *uint32 `protobuf:"varint,1,opt,name=duration,proto3,oneof" json:"duration,omitempty"` // seconds - Data *uint64 `protobuf:"varint,2,opt,name=data,proto3,oneof" json:"data,omitempty"` // bytes + sizeCache protoimpl.SizeCache } func (x *Limit) Reset() { diff --git a/p2p/protocol/circuitv2/pb/voucher.pb.go b/p2p/protocol/circuitv2/pb/voucher.pb.go index 5837d4de23..31b2ded0ea 100644 --- a/p2p/protocol/circuitv2/pb/voucher.pb.go +++ b/p2p/protocol/circuitv2/pb/voucher.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/protocol/circuitv2/pb/voucher.proto package pb @@ -21,15 +21,14 @@ const ( ) type ReservationVoucher struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // These fields are marked optional for backwards compatibility with proto2. // Users should make sure to always set these. - Relay []byte `protobuf:"bytes,1,opt,name=relay,proto3,oneof" json:"relay,omitempty"` - Peer []byte `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` - Expiration *uint64 `protobuf:"varint,3,opt,name=expiration,proto3,oneof" json:"expiration,omitempty"` + Relay []byte `protobuf:"bytes,1,opt,name=relay,proto3,oneof" json:"relay,omitempty"` + Peer []byte `protobuf:"bytes,2,opt,name=peer,proto3,oneof" json:"peer,omitempty"` + Expiration *uint64 `protobuf:"varint,3,opt,name=expiration,proto3,oneof" json:"expiration,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *ReservationVoucher) Reset() { diff --git a/p2p/protocol/holepunch/pb/holepunch.pb.go b/p2p/protocol/holepunch/pb/holepunch.pb.go index c8ab6f16c4..58ef725c8f 100644 --- a/p2p/protocol/holepunch/pb/holepunch.pb.go +++ b/p2p/protocol/holepunch/pb/holepunch.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/protocol/holepunch/pb/holepunch.proto package pb @@ -78,12 +78,11 @@ func (HolePunch_Type) EnumDescriptor() ([]byte, []int) { // spec: https://github.com/libp2p/specs/blob/master/relay/DCUtR.md type HolePunch struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Type *HolePunch_Type `protobuf:"varint,1,req,name=type,enum=holepunch.pb.HolePunch_Type" json:"type,omitempty"` + ObsAddrs [][]byte `protobuf:"bytes,2,rep,name=ObsAddrs" json:"ObsAddrs,omitempty"` unknownFields protoimpl.UnknownFields - - Type *HolePunch_Type `protobuf:"varint,1,req,name=type,enum=holepunch.pb.HolePunch_Type" json:"type,omitempty"` - ObsAddrs [][]byte `protobuf:"bytes,2,rep,name=ObsAddrs" json:"ObsAddrs,omitempty"` + sizeCache protoimpl.SizeCache } func (x *HolePunch) Reset() { diff --git a/p2p/protocol/identify/pb/identify.pb.go b/p2p/protocol/identify/pb/identify.pb.go index 66f4cb703a..b26bc0323b 100644 --- a/p2p/protocol/identify/pb/identify.pb.go +++ b/p2p/protocol/identify/pb/identify.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/protocol/identify/pb/identify.proto package pb @@ -21,10 +21,7 @@ const ( ) type Identify struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - + state protoimpl.MessageState `protogen:"open.v1"` // protocolVersion determines compatibility between peers ProtocolVersion *string `protobuf:"bytes,5,opt,name=protocolVersion" json:"protocolVersion,omitempty"` // e.g. ipfs/1.0.0 // agentVersion is like a UserAgent string in browsers, or client version in bittorrent @@ -48,6 +45,8 @@ type Identify struct { // see github.com/libp2p/go-libp2p/core/record/pb/envelope.proto and // github.com/libp2p/go-libp2p/core/peer/pb/peer_record.proto for message definitions. SignedPeerRecord []byte `protobuf:"bytes,8,opt,name=signedPeerRecord" json:"signedPeerRecord,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Identify) Reset() { diff --git a/p2p/security/noise/pb/payload.pb.go b/p2p/security/noise/pb/payload.pb.go index 45a104e222..e6c7bdd164 100644 --- a/p2p/security/noise/pb/payload.pb.go +++ b/p2p/security/noise/pb/payload.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/security/noise/pb/payload.proto package pb @@ -21,12 +21,11 @@ const ( ) type NoiseExtensions struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - WebtransportCerthashes [][]byte `protobuf:"bytes,1,rep,name=webtransport_certhashes,json=webtransportCerthashes" json:"webtransport_certhashes,omitempty"` - StreamMuxers []string `protobuf:"bytes,2,rep,name=stream_muxers,json=streamMuxers" json:"stream_muxers,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + WebtransportCerthashes [][]byte `protobuf:"bytes,1,rep,name=webtransport_certhashes,json=webtransportCerthashes" json:"webtransport_certhashes,omitempty"` + StreamMuxers []string `protobuf:"bytes,2,rep,name=stream_muxers,json=streamMuxers" json:"stream_muxers,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *NoiseExtensions) Reset() { @@ -74,13 +73,12 @@ func (x *NoiseExtensions) GetStreamMuxers() []string { } type NoiseHandshakePayload struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + IdentityKey []byte `protobuf:"bytes,1,opt,name=identity_key,json=identityKey" json:"identity_key,omitempty"` + IdentitySig []byte `protobuf:"bytes,2,opt,name=identity_sig,json=identitySig" json:"identity_sig,omitempty"` + Extensions *NoiseExtensions `protobuf:"bytes,4,opt,name=extensions" json:"extensions,omitempty"` unknownFields protoimpl.UnknownFields - - IdentityKey []byte `protobuf:"bytes,1,opt,name=identity_key,json=identityKey" json:"identity_key,omitempty"` - IdentitySig []byte `protobuf:"bytes,2,opt,name=identity_sig,json=identitySig" json:"identity_sig,omitempty"` - Extensions *NoiseExtensions `protobuf:"bytes,4,opt,name=extensions" json:"extensions,omitempty"` + sizeCache protoimpl.SizeCache } func (x *NoiseHandshakePayload) Reset() { diff --git a/p2p/transport/webrtc/pb/message.pb.go b/p2p/transport/webrtc/pb/message.pb.go index d7d4d583af..68eb45dda2 100644 --- a/p2p/transport/webrtc/pb/message.pb.go +++ b/p2p/transport/webrtc/pb/message.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.0 +// protoc v5.29.2 // source: p2p/transport/webrtc/pb/message.proto package pb @@ -91,12 +91,11 @@ func (Message_Flag) EnumDescriptor() ([]byte, []int) { } type Message struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Flag *Message_Flag `protobuf:"varint,1,opt,name=flag,enum=Message_Flag" json:"flag,omitempty"` + Message []byte `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` unknownFields protoimpl.UnknownFields - - Flag *Message_Flag `protobuf:"varint,1,opt,name=flag,enum=Message_Flag" json:"flag,omitempty"` - Message []byte `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` + sizeCache protoimpl.SizeCache } func (x *Message) Reset() { diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000000..7371c9e452 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,2 @@ +protobuf-bin/ +protoc-gen-go diff --git a/scripts/download-protoc.sh b/scripts/download-protoc.sh new file mode 100755 index 0000000000..6870c22c9f --- /dev/null +++ b/scripts/download-protoc.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +set -eou pipefail + +# Specify the protobuf release version +PROTOBUF_VERSION="29.2" + +# Define SHA-256 hashes for each supported platform +# Update these hashes by running ./print-protoc-hashes.sh +declare -A SHA256_HASHES=( + ["linux-aarch64"]="0019dfc4b32d63c1392aa264aed2253c1e0c2fb09216f8e2cc269bbfb8bb49b5" + ["linux-x86_64"]="52e9e7ece55c7e30e7e8bbd254b4b21b408a5309bca826763c7124b696a132e9" + ["darwin-aarch64"]="0e153a38d6da19594c980e7f7cd3ea0ddd52c9da1068c03c0d8533369fbfeb20" +) + +# Determine the platform +OS="$(uname -s | tr '[:upper:]' '[:lower:]')" +ARCH="$(uname -m)" +[[ "${ARCH}" == "arm64" ]] && ARCH="aarch64" + +PLATFORM="${OS}-${ARCH}" + +# Set the download URL based on the platform +case "${PLATFORM}" in +linux-x86_64) + PROTOC_ZIP="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" + ;; +linux-aarch64) + PROTOC_ZIP="protoc-${PROTOBUF_VERSION}-linux-aarch64.zip" + ;; +darwin-aarch64) + PROTOC_ZIP="protoc-${PROTOBUF_VERSION}-osx-aarch_64.zip" + ;; +*) + echo "Unsupported platform: ${PLATFORM}" >&2 + exit 1 + ;; +esac + +# Download the specified version of protobuf +DOWNLOAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_ZIP}" +echo "Downloading from: ${DOWNLOAD_URL}" >&2 +curl -LO "${DOWNLOAD_URL}" + +# Verify checksum +EXPECTED_SHA256="${SHA256_HASHES[${PLATFORM}]}" +if command -v shasum >/dev/null 2>&1; then + ACTUAL_SHA256=$(shasum -a 256 "${PROTOC_ZIP}" | cut -d' ' -f1) +else + ACTUAL_SHA256=$(sha256sum "${PROTOC_ZIP}" | cut -d' ' -f1) +fi + +if [[ "${ACTUAL_SHA256}" != "${EXPECTED_SHA256}" ]]; then + echo "Checksum verification failed!" >&2 + echo "Expected: ${EXPECTED_SHA256}" >&2 + echo "Got: ${ACTUAL_SHA256}" >&2 + rm "${PROTOC_ZIP}" + exit 1 +fi + +echo "Checksum verified successfully" >&2 + +# Create a directory for extraction +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +INSTALL_DIR="$SCRIPT_DIR/protobuf-bin/protoc-${PROTOBUF_VERSION}" +mkdir -p "${INSTALL_DIR}" + +# Unzip the downloaded file +unzip -q -o "${PROTOC_ZIP}" -d "${INSTALL_DIR}" + +# Clean up the zip file +rm "${PROTOC_ZIP}" + +# Return a new PATH with the protobuf binary +PROTOC_BIN="${INSTALL_DIR}/bin" +echo "Installed protoc ${PROTOBUF_VERSION} to ${INSTALL_DIR}" >&2 + +# Return the protoc bin path to stdout +printf "${PROTOC_BIN}" diff --git a/scripts/gen-proto.sh b/scripts/gen-proto.sh index d06187bb67..dac2cff2f9 100755 --- a/scripts/gen-proto.sh +++ b/scripts/gen-proto.sh @@ -4,25 +4,32 @@ set -eou pipefail root=$1 proto_array=( - core/crypto/pb/crypto.proto - core/record/pb/envelope.proto - core/peer/pb/peer_record.proto - core/sec/insecure/pb/plaintext.proto - p2p/host/autonat/pb/autonat.proto - p2p/security/noise/pb/payload.proto - p2p/transport/webrtc/pb/message.proto - p2p/protocol/identify/pb/identify.proto - p2p/protocol/circuitv2/pb/circuit.proto - p2p/protocol/circuitv2/pb/voucher.proto - p2p/protocol/autonatv2/pb/autonatv2.proto - p2p/protocol/holepunch/pb/holepunch.proto - p2p/host/peerstore/pstoreds/pb/pstore.proto + core/crypto/pb/crypto.proto + core/record/pb/envelope.proto + core/peer/pb/peer_record.proto + core/sec/insecure/pb/plaintext.proto + p2p/host/autonat/pb/autonat.proto + p2p/security/noise/pb/payload.proto + p2p/transport/webrtc/pb/message.proto + p2p/protocol/identify/pb/identify.proto + p2p/protocol/circuitv2/pb/circuit.proto + p2p/protocol/circuitv2/pb/voucher.proto + p2p/protocol/autonatv2/pb/autonatv2.proto + p2p/protocol/holepunch/pb/holepunch.proto + p2p/host/peerstore/pstoreds/pb/pstore.proto ) proto_paths="" for path in "${proto_array[@]}"; do - proto_paths+="$path " + proto_paths+="$path " done +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROTOC_BIN_PATH="$("${SCRIPT_DIR}/download-protoc.sh")" +export PATH="$PROTOC_BIN_PATH:$PATH" + echo protoc --version $(protoc --version) -protoc --proto_path=$root --go_out=$root --go_opt=paths=source_relative $proto_paths +(cd ${SCRIPT_DIR} && go build -o protoc-gen-go google.golang.org/protobuf/cmd/protoc-gen-go) + +echo protoc-gen-go --version $(${SCRIPT_DIR}/protoc-gen-go --version) +protoc --plugin="${SCRIPT_DIR}/protoc-gen-go" --proto_path=$root --go_out=$root --go_opt=paths=source_relative $proto_paths diff --git a/scripts/print-protoc-hashes.sh b/scripts/print-protoc-hashes.sh new file mode 100755 index 0000000000..9a9d270a30 --- /dev/null +++ b/scripts/print-protoc-hashes.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -eou pipefail + +# Specify the protobuf release version +PROTOBUF_VERSION="29.2" + +# Define the platforms +PLATFORMS=("linux-x86_64" "linux-aarch64" "darwin-aarch64") + +# Array to store the hashes +declare -A HASHES + +# Function to download and calculate the SHA-256 hash +calculate_hash() { + local platform=$1 + local protoc_zip + + case "${platform}" in + linux-x86_64) + protoc_zip="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" + ;; + linux-aarch64) + protoc_zip="protoc-${PROTOBUF_VERSION}-linux-aarch64.zip" + ;; + darwin-aarch64) + protoc_zip="protoc-${PROTOBUF_VERSION}-osx-aarch_64.zip" + ;; + *) + echo "Unsupported platform: ${platform}" + exit 1 + ;; + esac + + # Download the specified version of protobuf + download_url="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/${protoc_zip}" + echo "Downloading from: ${download_url}" + curl -LO "${download_url}" + + # Calculate the SHA-256 hash + if command -v shasum >/dev/null 2>&1; then + sha256_hash=$(shasum -a 256 "${protoc_zip}" | cut -d' ' -f1) + else + sha256_hash=$(sha256sum "${protoc_zip}" | cut -d' ' -f1) + fi + + # Store the hash in the array + HASHES["${platform}"]="${sha256_hash}" + + # Clean up the zip file + rm "${protoc_zip}" +} + +# Iterate over the platforms and calculate the hashes +for platform in "${PLATFORMS[@]}"; do + calculate_hash "${platform}" +done + +# Print all the hashes together at the end +echo "Expected SHA-256 hashes for protobuf ${PROTOBUF_VERSION}:" +for platform in "${!HASHES[@]}"; do + echo "[\"${platform}\"]=\"${HASHES[${platform}]}\"" +done From a0a498ed0e17e002af9e18104a3bc1393373bb16 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 18 Dec 2024 15:45:30 -0800 Subject: [PATCH 58/75] fix(httpauth): Correctly handle concurrent requests on server (#3111) Co-authored-by: Adin Schmahmann --- p2p/http/auth/auth_test.go | 66 +++++++++++++++++++++++++++++++------- p2p/http/auth/server.go | 39 +++++++++++++++++++--- 2 files changed, 89 insertions(+), 16 deletions(-) diff --git a/p2p/http/auth/auth_test.go b/p2p/http/auth/auth_test.go index d080b19511..9d1b4688d4 100644 --- a/p2p/http/auth/auth_test.go +++ b/p2p/http/auth/auth_test.go @@ -2,11 +2,9 @@ package httppeeridauth import ( "bytes" - "crypto/hmac" "crypto/rand" - "crypto/sha256" "crypto/tls" - "hash" + "fmt" "io" "net/http" "net/http/httptest" @@ -171,14 +169,12 @@ func TestMutualAuth(t *testing.T) { t.Run("Tokens Invalidated", func(t *testing.T) { // Clear the auth token on the server side - server.Hmac = func() hash.Hash { - key := make([]byte, 32) - _, err := rand.Read(key) - if err != nil { - panic(err) - } - return hmac.New(sha256.New, key) - }() + key := make([]byte, 32) + _, err := rand.Read(key) + if err != nil { + panic(err) + } + server.hmacPool = newHmacPool(key) req, err := http.NewRequest("POST", ts.URL, nil) req.GetBody = func() (io.ReadCloser, error) { @@ -241,3 +237,51 @@ func (irt *instrumentedRoundTripper) RoundTrip(req *http.Request) (*http.Respons func (irt *instrumentedRoundTripper) TLSClientConfig() *tls.Config { return irt.RoundTripper.(*http.Transport).TLSClientConfig } + +func TestConcurrentAuth(t *testing.T) { + serverKey, _, err := crypto.GenerateEd25519Key(rand.Reader) + require.NoError(t, err) + + auth := ServerPeerIDAuth{ + PrivKey: serverKey, + ValidHostnameFn: func(s string) bool { + return s == "example.com" + }, + TokenTTL: time.Hour, + NoTLS: true, + Next: func(peer peer.ID, w http.ResponseWriter, r *http.Request) { + reqBody, err := io.ReadAll(r.Body) + require.NoError(t, err) + _, err = w.Write(reqBody) + require.NoError(t, err) + }, + } + + ts := httptest.NewServer(&auth) + t.Cleanup(ts.Close) + + wg := sync.WaitGroup{} + for i := 0; i < 10; i++ { + wg.Add(1) + go func() { + defer wg.Done() + clientKey, _, err := crypto.GenerateEd25519Key(rand.Reader) + require.NoError(t, err) + + clientAuth := ClientPeerIDAuth{PrivKey: clientKey} + reqBody := []byte(fmt.Sprintf("echo %d", i)) + req, err := http.NewRequest("POST", ts.URL, bytes.NewReader(reqBody)) + require.NoError(t, err) + req.Host = "example.com" + + client := ts.Client() + _, resp, err := clientAuth.AuthenticatedDo(client, req) + require.NoError(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode) + respBody, err := io.ReadAll(resp.Body) + require.NoError(t, err) + require.Equal(t, reqBody, respBody) + }() + } + wg.Wait() +} diff --git a/p2p/http/auth/server.go b/p2p/http/auth/server.go index 3ee4f96dc8..b17c3fccf1 100644 --- a/p2p/http/auth/server.go +++ b/p2p/http/auth/server.go @@ -15,6 +15,30 @@ import ( "github.com/libp2p/go-libp2p/p2p/http/auth/internal/handshake" ) +type hmacPool struct { + p sync.Pool +} + +func newHmacPool(key []byte) *hmacPool { + return &hmacPool{ + p: sync.Pool{ + New: func() any { + return hmac.New(sha256.New, key) + }, + }, + } +} + +func (p *hmacPool) Get() hash.Hash { + h := p.p.Get().(hash.Hash) + h.Reset() + return h +} + +func (p *hmacPool) Put(h hash.Hash) { + p.p.Put(h) +} + type ServerPeerIDAuth struct { PrivKey crypto.PrivKey TokenTTL time.Duration @@ -26,8 +50,9 @@ type ServerPeerIDAuth struct { // which the Host header returns true. ValidHostnameFn func(hostname string) bool - Hmac hash.Hash + HmacKey []byte initHmac sync.Once + hmacPool *hmacPool } // ServeHTTP implements the http.Handler interface for PeerIDAuth. It will @@ -36,14 +61,15 @@ type ServerPeerIDAuth struct { // requests. func (a *ServerPeerIDAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) { a.initHmac.Do(func() { - if a.Hmac == nil { + if a.HmacKey == nil { key := make([]byte, 32) _, err := rand.Read(key) if err != nil { panic(err) } - a.Hmac = hmac.New(sha256.New, key) + a.HmacKey = key } + a.hmacPool = newHmacPool(a.HmacKey) }) hostname := r.Host @@ -76,11 +102,13 @@ func (a *ServerPeerIDAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + hmac := a.hmacPool.Get() + defer a.hmacPool.Put(hmac) hs := handshake.PeerIDAuthHandshakeServer{ Hostname: hostname, PrivKey: a.PrivKey, TokenTTL: a.TokenTTL, - Hmac: a.Hmac, + Hmac: hmac, } err := hs.ParseHeaderVal([]byte(r.Header.Get("Authorization"))) if err != nil { @@ -95,11 +123,12 @@ func (a *ServerPeerIDAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) { errors.Is(err, handshake.ErrExpiredChallenge), errors.Is(err, handshake.ErrExpiredToken): + hmac.Reset() hs := handshake.PeerIDAuthHandshakeServer{ Hostname: hostname, PrivKey: a.PrivKey, TokenTTL: a.TokenTTL, - Hmac: a.Hmac, + Hmac: hmac, } hs.Run() hs.SetHeader(w.Header()) From 7ce9c5024bc4c91fa7a3420e9a542435b9af6831 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 18 Dec 2024 16:01:19 -0800 Subject: [PATCH 59/75] chore: release v0.38.1 (#3114) --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 903f67956b..6e9b1709cc 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.38.0" + "version": "v0.38.1" } From 233720dc1f2807dd8ac790cbe0f24bca2dc34d21 Mon Sep 17 00:00:00 2001 From: linchizhen Date: Tue, 24 Dec 2024 00:45:29 +0800 Subject: [PATCH 60/75] webtransport: fix docstring comment for getCurrentBucketStartTime Signed-off-by: linchizhen --- p2p/transport/webtransport/cert_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/transport/webtransport/cert_manager.go b/p2p/transport/webtransport/cert_manager.go index d48a0aa537..4401175363 100644 --- a/p2p/transport/webtransport/cert_manager.go +++ b/p2p/transport/webtransport/cert_manager.go @@ -71,7 +71,7 @@ func newCertManager(hostKey ic.PrivKey, clock clock.Clock) (*certManager, error) return m, nil } -// getCurrentTimeBucket returns the canonical start time of the given time as +// getCurrentBucketStartTime returns the canonical start time of the given time as // bucketed by ranges of certValidity since unix epoch (plus an offset). This // lets you get the same time ranges across reboots without having to persist // state. From 3839c642a756ebb7a2dab2b24de91f680b626490 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Tue, 24 Dec 2024 15:09:38 +0000 Subject: [PATCH 61/75] ci: get back on the main release track of release checker (#3117) Co-authored-by: Prithvi Shahi --- .github/workflows/release-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index 4d37f9b4a3..0b5ff6070f 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -16,4 +16,4 @@ concurrency: jobs: release-check: - uses: marcopolo/unified-github-workflows/.github/workflows/release-check.yml@e66cb9667a2e1148efda4591e29c56258eaf385b + uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0 From 8f6d98d74cdaa3ed932c4d8c30319ebe87a28fdd Mon Sep 17 00:00:00 2001 From: "Yuttakhan B." Date: Wed, 25 Dec 2024 20:17:51 +0700 Subject: [PATCH 62/75] webrtc: upgrade pion/webrtc to v4 (#3098) Co-authored-by: sukun --- go.mod | 9 +++++++-- go.sum | 21 ++++++++++++++------- p2p/transport/webrtc/connection.go | 2 +- p2p/transport/webrtc/fingerprint.go | 2 +- p2p/transport/webrtc/listener.go | 2 +- p2p/transport/webrtc/stream.go | 2 +- p2p/transport/webrtc/stream_test.go | 2 +- p2p/transport/webrtc/transport.go | 2 +- test-plans/go.mod | 9 +++++++-- test-plans/go.sum | 21 ++++++++++++++------- 10 files changed, 48 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 7da5a50105..28abae8ffc 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( github.com/pion/logging v0.2.2 github.com/pion/sctp v1.8.35 github.com/pion/stun v0.6.1 - github.com/pion/webrtc/v3 v3.3.5 + github.com/pion/webrtc/v4 v4.0.7 github.com/prometheus/client_golang v1.20.5 github.com/prometheus/client_model v0.6.1 github.com/quic-go/quic-go v0.48.2 @@ -105,16 +105,21 @@ require ( github.com/onsi/ginkgo/v2 v2.22.0 // indirect github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/pion/dtls/v2 v2.2.12 // indirect + github.com/pion/dtls/v3 v3.0.4 // indirect + github.com/pion/ice/v4 v4.0.3 // indirect github.com/pion/interceptor v0.1.37 // indirect github.com/pion/mdns v0.0.12 // indirect + github.com/pion/mdns/v2 v2.0.7 // indirect github.com/pion/randutil v0.1.0 // indirect github.com/pion/rtcp v1.2.15 // indirect github.com/pion/rtp v1.8.10 // indirect github.com/pion/sdp/v3 v3.0.9 // indirect - github.com/pion/srtp/v2 v2.0.20 // indirect + github.com/pion/srtp/v3 v3.0.4 // indirect + github.com/pion/stun/v3 v3.0.0 // indirect github.com/pion/transport/v2 v2.2.10 // indirect github.com/pion/transport/v3 v3.0.7 // indirect github.com/pion/turn/v2 v2.1.6 // indirect + github.com/pion/turn/v4 v4.0.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.61.0 // indirect diff --git a/go.sum b/go.sum index 7a822e8481..2d8fb16cf3 100644 --- a/go.sum +++ b/go.sum @@ -277,32 +277,37 @@ github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oL github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk= github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U= +github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg= github.com/pion/ice/v2 v2.3.37 h1:ObIdaNDu1rCo7hObhs34YSBcO7fjslJMZV0ux+uZWh0= github.com/pion/ice/v2 v2.3.37/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= +github.com/pion/ice/v4 v4.0.3 h1:9s5rI1WKzF5DRqhJ+Id8bls/8PzM7mau0mj1WZb4IXE= +github.com/pion/ice/v4 v4.0.3/go.mod h1:VfHy0beAZ5loDT7BmJ2LtMtC4dbawIkkkejHPRZNB3Y= github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI= github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8= github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk= +github.com/pion/mdns/v2 v2.0.7 h1:c9kM8ewCgjslaAmicYMFQIde2H9/lrZpjBkN8VwoVtM= +github.com/pion/mdns/v2 v2.0.7/go.mod h1:vAdSYNAT0Jy3Ru0zl2YiW3Rm/fJCwIeM0nToenfOJKA= github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= -github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo= github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0= -github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= github.com/pion/rtp v1.8.10 h1:puphjdbjPB+L+NFaVuZ5h6bt1g5q4kFIoI+r5q/g0CU= github.com/pion/rtp v1.8.10/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4= github.com/pion/sctp v1.8.35 h1:qwtKvNK1Wc5tHMIYgTDJhfZk7vATGVHhXbUDfHbYwzA= github.com/pion/sctp v1.8.35/go.mod h1:EcXP8zCYVTRy3W9xtOF7wJm1L1aXfKRQzaM33SjQlzg= github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= -github.com/pion/srtp/v2 v2.0.20 h1:HNNny4s+OUmG280ETrCdgFndp4ufx3/uy85EawYEhTk= -github.com/pion/srtp/v2 v2.0.20/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA= +github.com/pion/srtp/v3 v3.0.4 h1:2Z6vDVxzrX3UHEgrUyIGM4rRouoC7v+NiF1IHtp9B5M= +github.com/pion/srtp/v3 v3.0.4/go.mod h1:1Jx3FwDoxpRaTh1oRV8A/6G1BnFL+QI82eK4ms8EEJQ= github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/stun/v3 v3.0.0 h1:4h1gwhWLWuZWOJIJR9s2ferRO+W3zA/b6ijOI6mKzUw= +github.com/pion/stun/v3 v3.0.0/go.mod h1:HvCN8txt8mwi4FBvS3EmDghW6aQJ24T+y+1TKjB5jyU= github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= -github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= github.com/pion/transport/v2 v2.2.10 h1:ucLBLE8nuxiHfvkFKnkDQRYWYfp8ejf4YBOPfaQpw6Q= github.com/pion/transport/v2 v2.2.10/go.mod h1:sq1kSLWs+cHW9E+2fJP95QudkzbK7wscs8yYgQToO5E= @@ -312,8 +317,10 @@ github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uP github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= -github.com/pion/webrtc/v3 v3.3.5 h1:ZsSzaMz/i9nblPdiAkZoP+E6Kmjw+jnyq3bEmU3EtRg= -github.com/pion/webrtc/v3 v3.3.5/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= +github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM= +github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA= +github.com/pion/webrtc/v4 v4.0.7 h1:aeq78uVnFZd2umXW0O9A2VFQYuS7+BZxWetQvSp2jPo= +github.com/pion/webrtc/v4 v4.0.7/go.mod h1:oFVBBVSHU3vAEwSgnk3BuKCwAUwpDwQhko1EDwyZWbU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/p2p/transport/webrtc/connection.go b/p2p/transport/webrtc/connection.go index 2fba37a970..b614b2c45d 100644 --- a/p2p/transport/webrtc/connection.go +++ b/p2p/transport/webrtc/connection.go @@ -17,7 +17,7 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/pion/datachannel" "github.com/pion/sctp" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" ) var _ tpt.CapableConn = &connection{} diff --git a/p2p/transport/webrtc/fingerprint.go b/p2p/transport/webrtc/fingerprint.go index fd715865a8..0b1fe488b4 100644 --- a/p2p/transport/webrtc/fingerprint.go +++ b/p2p/transport/webrtc/fingerprint.go @@ -8,7 +8,7 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multibase" mh "github.com/multiformats/go-multihash" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" ) // parseFingerprint is forked from pion to avoid bytes to string alloc, diff --git a/p2p/transport/webrtc/listener.go b/p2p/transport/webrtc/listener.go index c3e2f29799..3534fd2c76 100644 --- a/p2p/transport/webrtc/listener.go +++ b/p2p/transport/webrtc/listener.go @@ -20,7 +20,7 @@ import ( manet "github.com/multiformats/go-multiaddr/net" "github.com/multiformats/go-multibase" "github.com/multiformats/go-multihash" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" ) type connMultiaddrs struct { diff --git a/p2p/transport/webrtc/stream.go b/p2p/transport/webrtc/stream.go index 56f869f5e1..bce2f3f2e3 100644 --- a/p2p/transport/webrtc/stream.go +++ b/p2p/transport/webrtc/stream.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-msgio/pbio" "github.com/pion/datachannel" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" ) const ( diff --git a/p2p/transport/webrtc/stream_test.go b/p2p/transport/webrtc/stream_test.go index 0f57f44f79..4153ff830a 100644 --- a/p2p/transport/webrtc/stream_test.go +++ b/p2p/transport/webrtc/stream_test.go @@ -17,7 +17,7 @@ import ( "github.com/pion/datachannel" "github.com/pion/sctp" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/p2p/transport/webrtc/transport.go b/p2p/transport/webrtc/transport.go index c4c16fd402..1ee65a756b 100644 --- a/p2p/transport/webrtc/transport.go +++ b/p2p/transport/webrtc/transport.go @@ -35,7 +35,7 @@ import ( "github.com/multiformats/go-multihash" "github.com/pion/datachannel" - "github.com/pion/webrtc/v3" + "github.com/pion/webrtc/v4" ) var webrtcComponent *ma.Component diff --git a/test-plans/go.mod b/test-plans/go.mod index a320074aed..6bd58c0b95 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -67,21 +67,26 @@ require ( github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pion/datachannel v1.5.10 // indirect github.com/pion/dtls/v2 v2.2.12 // indirect + github.com/pion/dtls/v3 v3.0.4 // indirect github.com/pion/ice/v2 v2.3.37 // indirect + github.com/pion/ice/v4 v4.0.3 // indirect github.com/pion/interceptor v0.1.37 // indirect github.com/pion/logging v0.2.2 // indirect github.com/pion/mdns v0.0.12 // indirect + github.com/pion/mdns/v2 v2.0.7 // indirect github.com/pion/randutil v0.1.0 // indirect github.com/pion/rtcp v1.2.15 // indirect github.com/pion/rtp v1.8.10 // indirect github.com/pion/sctp v1.8.35 // indirect github.com/pion/sdp/v3 v3.0.9 // indirect - github.com/pion/srtp/v2 v2.0.20 // indirect + github.com/pion/srtp/v3 v3.0.4 // indirect github.com/pion/stun v0.6.1 // indirect + github.com/pion/stun/v3 v3.0.0 // indirect github.com/pion/transport/v2 v2.2.10 // indirect github.com/pion/transport/v3 v3.0.7 // indirect github.com/pion/turn/v2 v2.1.6 // indirect - github.com/pion/webrtc/v3 v3.3.5 // indirect + github.com/pion/turn/v4 v4.0.0 // indirect + github.com/pion/webrtc/v4 v4.0.7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.20.5 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index 7b62798632..439614d540 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -223,32 +223,37 @@ github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oL github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk= github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE= +github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U= +github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg= github.com/pion/ice/v2 v2.3.37 h1:ObIdaNDu1rCo7hObhs34YSBcO7fjslJMZV0ux+uZWh0= github.com/pion/ice/v2 v2.3.37/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ= +github.com/pion/ice/v4 v4.0.3 h1:9s5rI1WKzF5DRqhJ+Id8bls/8PzM7mau0mj1WZb4IXE= +github.com/pion/ice/v4 v4.0.3/go.mod h1:VfHy0beAZ5loDT7BmJ2LtMtC4dbawIkkkejHPRZNB3Y= github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI= github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8= github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk= +github.com/pion/mdns/v2 v2.0.7 h1:c9kM8ewCgjslaAmicYMFQIde2H9/lrZpjBkN8VwoVtM= +github.com/pion/mdns/v2 v2.0.7/go.mod h1:vAdSYNAT0Jy3Ru0zl2YiW3Rm/fJCwIeM0nToenfOJKA= github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= -github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo= github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0= -github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= github.com/pion/rtp v1.8.10 h1:puphjdbjPB+L+NFaVuZ5h6bt1g5q4kFIoI+r5q/g0CU= github.com/pion/rtp v1.8.10/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4= github.com/pion/sctp v1.8.35 h1:qwtKvNK1Wc5tHMIYgTDJhfZk7vATGVHhXbUDfHbYwzA= github.com/pion/sctp v1.8.35/go.mod h1:EcXP8zCYVTRy3W9xtOF7wJm1L1aXfKRQzaM33SjQlzg= github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY= github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M= -github.com/pion/srtp/v2 v2.0.20 h1:HNNny4s+OUmG280ETrCdgFndp4ufx3/uy85EawYEhTk= -github.com/pion/srtp/v2 v2.0.20/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA= +github.com/pion/srtp/v3 v3.0.4 h1:2Z6vDVxzrX3UHEgrUyIGM4rRouoC7v+NiF1IHtp9B5M= +github.com/pion/srtp/v3 v3.0.4/go.mod h1:1Jx3FwDoxpRaTh1oRV8A/6G1BnFL+QI82eK4ms8EEJQ= github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/stun/v3 v3.0.0 h1:4h1gwhWLWuZWOJIJR9s2ferRO+W3zA/b6ijOI6mKzUw= +github.com/pion/stun/v3 v3.0.0/go.mod h1:HvCN8txt8mwi4FBvS3EmDghW6aQJ24T+y+1TKjB5jyU= github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= -github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= github.com/pion/transport/v2 v2.2.10 h1:ucLBLE8nuxiHfvkFKnkDQRYWYfp8ejf4YBOPfaQpw6Q= github.com/pion/transport/v2 v2.2.10/go.mod h1:sq1kSLWs+cHW9E+2fJP95QudkzbK7wscs8yYgQToO5E= @@ -258,8 +263,10 @@ github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uP github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc= github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= -github.com/pion/webrtc/v3 v3.3.5 h1:ZsSzaMz/i9nblPdiAkZoP+E6Kmjw+jnyq3bEmU3EtRg= -github.com/pion/webrtc/v3 v3.3.5/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE= +github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM= +github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA= +github.com/pion/webrtc/v4 v4.0.7 h1:aeq78uVnFZd2umXW0O9A2VFQYuS7+BZxWetQvSp2jPo= +github.com/pion/webrtc/v4 v4.0.7/go.mod h1:oFVBBVSHU3vAEwSgnk3BuKCwAUwpDwQhko1EDwyZWbU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= From 2209ae05976df6a1cc2631c961f57549d109008c Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 26 Dec 2024 15:37:37 +0000 Subject: [PATCH 63/75] tcp: fix metrics test build directive (#3052) --- p2p/transport/tcp/{metrics_unix_test.go => metrics_test.go} | 2 -- 1 file changed, 2 deletions(-) rename p2p/transport/tcp/{metrics_unix_test.go => metrics_test.go} (98%) diff --git a/p2p/transport/tcp/metrics_unix_test.go b/p2p/transport/tcp/metrics_test.go similarity index 98% rename from p2p/transport/tcp/metrics_unix_test.go rename to p2p/transport/tcp/metrics_test.go index 0a09526206..9a9946968b 100644 --- a/p2p/transport/tcp/metrics_unix_test.go +++ b/p2p/transport/tcp/metrics_test.go @@ -1,5 +1,3 @@ -// go:build: unix - package tcp import ( From 3143db22c6e6b39bedd021ed04e0cdd74b382572 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Fri, 10 Jan 2025 10:36:52 -0500 Subject: [PATCH 64/75] chore: Update contribution guidelines (#3134) --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f785935fc2..8b9cde5634 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,25 @@ Guidelines: - ask questions or talk about things in our [discussion forums](https://discuss.libp2p.io), or open an [issue](https://github.com/libp2p/go-libp2p/issues) for bug reports, or #libp2p-implementers on [Filecoin slack](https://filecoin.io/slack). - ensure you are able to contribute (no legal issues please -- we use the DCO) - get in touch with @libp2p/go-libp2p-maintainers about how best to contribute +- No drive-by contributions seeking to collect airdrops. + - Many projects aim to reward contributors to common goods. Great. However, + this creates an unfortunate incentive for low-effort PRs, submitted solely to + claim rewards. These PRs consume maintainers’ time and energy to triage, with + little to no impact on end users. If we suspect this is the intent of a PR, + we may close it without comment. If you believe this was done in error, + contact us via email. Reference this README section and explain why your PR + is not a “drive-by contribution.” - have fun! There's a few things you can do right now to help out: - - Go through the modules below and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically. - **Perform code reviews**. - **Add tests**. There can never be enough tests. + - Go through the modules below and **check out existing issues**. This would + be especially useful for modules in active development. Some knowledge of + IPFS/libp2p may be required, as well as the infrastructure behind it - for + instance, you may need to read up on p2p and more complex operations like + muxing to be able to help technically. + ## Supported Go Versions From ca611f1c4e1e026d15f37f420ecb00c212112d37 Mon Sep 17 00:00:00 2001 From: sukun Date: Fri, 10 Jan 2025 18:14:35 +0000 Subject: [PATCH 65/75] tcpreuse: error on using tcpreuse with pnet (#3129) Co-authored-by: Marco Munizaga --- config/config.go | 34 +++++++++++++++++++++++++++++----- libp2p_test.go | 11 ++++++++++- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index f3ea35855a..ea94c067a3 100644 --- a/config/config.go +++ b/config/config.go @@ -446,12 +446,9 @@ func (cfg *Config) newBasicHost(swrm *swarm.Swarm, eventBus event.Bus) (*bhost.B return h, nil } -// NewNode constructs a new libp2p Host from the Config. -// -// This function consumes the config. Do not reuse it (really!). -func (cfg *Config) NewNode() (host.Host, error) { +func (cfg *Config) validate() error { if cfg.EnableAutoRelay && !cfg.Relay { - return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled") + return fmt.Errorf("cannot enable autorelay; relay is not enabled") } // If possible check that the resource manager conn limit is higher than the // limit set in the conn manager. @@ -462,6 +459,33 @@ func (cfg *Config) NewNode() (host.Host, error) { } } + if len(cfg.PSK) > 0 && cfg.ShareTCPListener { + return errors.New("cannot use shared TCP listener with PSK") + } + + return nil +} + +// NewNode constructs a new libp2p Host from the Config. +// +// This function consumes the config. Do not reuse it (really!). +func (cfg *Config) NewNode() (host.Host, error) { + + validateErr := cfg.validate() + if validateErr != nil { + if cfg.ResourceManager != nil { + cfg.ResourceManager.Close() + } + if cfg.ConnManager != nil { + cfg.ConnManager.Close() + } + if cfg.Peerstore != nil { + cfg.Peerstore.Close() + } + + return nil, validateErr + } + if !cfg.DisableMetrics { rcmgr.MustRegisterWith(cfg.PrometheusRegisterer) } diff --git a/libp2p_test.go b/libp2p_test.go index 3de82946d8..3dc7f2e8ab 100644 --- a/libp2p_test.go +++ b/libp2p_test.go @@ -26,6 +26,7 @@ import ( "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" + "github.com/libp2p/go-libp2p/core/pnet" "github.com/libp2p/go-libp2p/core/routing" "github.com/libp2p/go-libp2p/core/transport" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" @@ -761,6 +762,7 @@ func TestSharedTCPAddr(t *testing.T) { ListenAddrStrings("/ip4/0.0.0.0/tcp/8888/ws"), ) require.NoError(t, err) + defer h.Close() sawTCP := false sawWS := false for _, addr := range h.Addrs() { @@ -773,5 +775,12 @@ func TestSharedTCPAddr(t *testing.T) { } require.True(t, sawTCP) require.True(t, sawWS) - h.Close() + + _, err = New( + ShareTCPListener(), + Transport(tcp.NewTCPTransport), + Transport(websocket.New), + PrivateNetwork(pnet.PSK([]byte{1, 2, 3})), + ) + require.ErrorContains(t, err, "cannot use shared TCP listener with PSK") } From a2993c18f7e9a005e23feff49d7f3296188be631 Mon Sep 17 00:00:00 2001 From: sukun Date: Fri, 10 Jan 2025 18:25:24 +0000 Subject: [PATCH 66/75] nat: ignore mapping if external port is 0 (#3094) Co-authored-by: wlynxg --- p2p/net/nat/nat.go | 6 +++++- p2p/net/nat/nat_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/p2p/net/nat/nat.go b/p2p/net/nat/nat.go index 28ffd4a5b2..23af58075a 100644 --- a/p2p/net/nat/nat.go +++ b/p2p/net/nat/nat.go @@ -107,7 +107,8 @@ func (nat *NAT) GetMapping(protocol string, port int) (addr netip.AddrPort, foun return netip.AddrPort{}, false } extPort, found := nat.mappings[entry{protocol: protocol, port: port}] - if !found { + // The mapping may have an invalid port. + if !found || extPort == 0 { return netip.AddrPort{}, false } return netip.AddrPortFrom(nat.extAddr, uint16(extPort)), true @@ -135,6 +136,9 @@ func (nat *NAT) AddMapping(ctx context.Context, protocol string, port int) error // do it once synchronously, so first mapping is done right away, and before exiting, // allowing users -- in the optimistic case -- to use results right after. extPort := nat.establishMapping(ctx, protocol, port) + // Don't validate the mapping here, we refresh the mappings based on this map. + // We can try getting a port again in case it succeeds. In the worst case, + // this is one extra LAN request every few minutes. nat.mappings[entry{protocol: protocol, port: port}] = extPort return nil } diff --git a/p2p/net/nat/nat_test.go b/p2p/net/nat/nat_test.go index 772c876c72..e370fc8907 100644 --- a/p2p/net/nat/nat_test.go +++ b/p2p/net/nat/nat_test.go @@ -68,3 +68,18 @@ func TestRemoveMapping(t *testing.T) { _, found = nat.GetMapping("tcp", 10000) require.False(t, found, "didn't expect port mapping for deleted mapping") } + +func TestAddMappingInvalidPort(t *testing.T) { + mockNAT, reset := setupMockNAT(t) + defer reset() + + mockNAT.EXPECT().GetExternalAddress().Return(net.IPv4(1, 2, 3, 4), nil) + nat, err := DiscoverNAT(context.Background()) + require.NoError(t, err) + + mockNAT.EXPECT().AddPortMapping(gomock.Any(), "tcp", 10000, gomock.Any(), MappingDuration).Return(0, nil) + require.NoError(t, nat.AddMapping(context.Background(), "tcp", 10000)) + + _, found := nat.GetMapping("tcp", 10000) + require.False(t, found, "didn't expect a port mapping for invalid nat-ed port") +} From 4651a0d2247ab8964384919083ae42b995fed42a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 10 Jan 2025 10:25:48 -0800 Subject: [PATCH 67/75] quicreuse: make it possible to use an application-constructed quic.Transport (#3122) Co-authored-by: Marco Munizaga --- p2p/transport/quicreuse/connmgr.go | 65 ++++++++++++-- p2p/transport/quicreuse/connmgr_test.go | 62 ++++++++++++- p2p/transport/quicreuse/listener.go | 2 +- p2p/transport/quicreuse/nonquic_packetconn.go | 6 +- p2p/transport/quicreuse/reuse.go | 86 ++++++++++++++----- 5 files changed, 188 insertions(+), 33 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index c3aa0fa046..def7c5da56 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "errors" + "io" "net" "sync" @@ -15,6 +16,22 @@ import ( quicmetrics "github.com/quic-go/quic-go/metrics" ) +type QUICListener interface { + Accept(ctx context.Context) (quic.Connection, error) + Close() error + Addr() net.Addr +} + +var _ QUICListener = &quic.Listener{} + +type QUICTransport interface { + Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error) + Dial(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (quic.Connection, error) + WriteTo(b []byte, addr net.Addr) (int, error) + ReadNonQUICPacket(ctx context.Context, b []byte) (int, net.Addr, error) + io.Closer +} + type ConnManager struct { reuseUDP4 *reuse reuseUDP6 *reuse @@ -101,6 +118,32 @@ func (c *ConnManager) getReuse(network string) (*reuse, error) { } } +// LendTransport is an advanced method used to lend an existing QUICTransport +// to the ConnManager. The ConnManager will close the returned channel when it +// is done with the transport, so that the owner may safely close the transport. +func (c *ConnManager) LendTransport(network string, tr QUICTransport, conn net.PacketConn) (<-chan struct{}, error) { + c.quicListenersMu.Lock() + defer c.quicListenersMu.Unlock() + + localAddr, ok := conn.LocalAddr().(*net.UDPAddr) + if !ok { + return nil, errors.New("expected a conn.LocalAddr() to return a *net.UDPAddr") + } + + refCountedTr := &refcountedTransport{ + QUICTransport: tr, + packetConn: conn, + borrowDoneSignal: make(chan struct{}), + } + + var reuse *reuse + reuse, err := c.getReuse(network) + if err != nil { + return nil, err + } + return refCountedTr.borrowDoneSignal, reuse.AddTransport(refCountedTr, localAddr) +} + func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (Listener, error) { return c.ListenQUICAndAssociate(nil, addr, tlsConf, allowWindowIncrease) } @@ -175,7 +218,7 @@ func (c *ConnManager) SharedNonQUICPacketConn(network string, laddr *net.UDPAddr ctx: ctx, ctxCancel: cancel, owningTransport: t, - tr: &t.Transport, + tr: t.QUICTransport, }, nil } return nil, errors.New("expected to be able to share with a QUIC listener, but the QUIC listener is not using a refcountedTransport. `DisableReuseport` should not be set") @@ -201,10 +244,12 @@ func (c *ConnManager) transportForListen(association any, network string, laddr } return &singleOwnerTransport{ packetConn: conn, - Transport: quic.Transport{ - Conn: conn, - StatelessResetKey: &c.srk, - TokenGeneratorKey: &c.tokenKey, + Transport: &wrappedQUICTransport{ + &quic.Transport{ + Conn: conn, + StatelessResetKey: &c.srk, + TokenGeneratorKey: &c.tokenKey, + }, }, }, nil } @@ -279,7 +324,7 @@ func (c *ConnManager) TransportWithAssociationForDial(association any, network s if err != nil { return nil, err } - return &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil + return &singleOwnerTransport{Transport: &wrappedQUICTransport{&quic.Transport{Conn: conn, StatelessResetKey: &c.srk}}, packetConn: conn}, nil } func (c *ConnManager) Protocols() []int { @@ -299,3 +344,11 @@ func (c *ConnManager) Close() error { func (c *ConnManager) ClientConfig() *quic.Config { return c.clientConfig } + +type wrappedQUICTransport struct { + *quic.Transport +} + +func (t *wrappedQUICTransport) Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error) { + return t.Transport.Listen(tlsConf, conf) +} diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index 8e7da2cd7f..51646bac98 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -97,7 +97,7 @@ func TestConnectionPassedToQUICForListening(t *testing.T) { quicTr, err := cm.transportForListen(nil, netw, naddr) require.NoError(t, err) defer quicTr.Close() - if _, ok := quicTr.(*singleOwnerTransport).Transport.Conn.(quic.OOBCapablePacketConn); !ok { + if _, ok := quicTr.(*singleOwnerTransport).packetConn.(quic.OOBCapablePacketConn); !ok { t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") } } @@ -156,7 +156,7 @@ func TestConnectionPassedToQUICForDialing(t *testing.T) { require.NoError(t, err, "dial error") defer quicTr.Close() - if _, ok := quicTr.(*singleOwnerTransport).Transport.Conn.(quic.OOBCapablePacketConn); !ok { + if _, ok := quicTr.(*singleOwnerTransport).packetConn.(quic.OOBCapablePacketConn); !ok { t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") } } @@ -257,3 +257,61 @@ func testListener(t *testing.T, enableReuseport bool) { checkClosed(t, cm) } + +func TestExternalTransport(t *testing.T) { + conn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero}) + require.NoError(t, err) + defer conn.Close() + port := conn.LocalAddr().(*net.UDPAddr).Port + tr := &quic.Transport{Conn: conn} + defer tr.Close() + + cm, err := NewConnManager(quic.StatelessResetKey{}, quic.TokenGeneratorKey{}) + require.NoError(t, err) + doneWithTr, err := cm.LendTransport("udp4", &wrappedQUICTransport{tr}, conn) + require.NoError(t, err) + + // make sure this transport is used when listening on the same port + ln, err := cm.ListenQUICAndAssociate( + "quic", + ma.StringCast(fmt.Sprintf("/ip4/0.0.0.0/udp/%d", port)), + &tls.Config{NextProtos: []string{"libp2p"}}, + func(quic.Connection, uint64) bool { return false }, + ) + require.NoError(t, err) + defer ln.Close() + require.Equal(t, port, ln.Addr().(*net.UDPAddr).Port) + + // make sure this transport is used when dialing out + udpLn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)}) + require.NoError(t, err) + defer udpLn.Close() + addrChan := make(chan net.Addr, 1) + go func() { + _, addr, _ := udpLn.ReadFrom(make([]byte, 2000)) + addrChan <- addr + }() + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + defer cancel() + _, err = cm.DialQUIC( + ctx, + ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/udp/%d/quic-v1", udpLn.LocalAddr().(*net.UDPAddr).Port)), + &tls.Config{NextProtos: []string{"libp2p"}}, + func(quic.Connection, uint64) bool { return false }, + ) + require.ErrorIs(t, err, context.DeadlineExceeded) + + select { + case addr := <-addrChan: + require.Equal(t, port, addr.(*net.UDPAddr).Port) + case <-time.After(time.Second): + t.Fatal("timeout") + } + + cm.Close() + select { + case <-doneWithTr: + default: + t.Fatal("doneWithTr not closed") + } +} diff --git a/p2p/transport/quicreuse/listener.go b/p2p/transport/quicreuse/listener.go index 4ee20042d3..42f1d00cef 100644 --- a/p2p/transport/quicreuse/listener.go +++ b/p2p/transport/quicreuse/listener.go @@ -29,7 +29,7 @@ type protoConf struct { } type quicListener struct { - l *quic.Listener + l QUICListener transport refCountedQuicTransport running chan struct{} addrs []ma.Multiaddr diff --git a/p2p/transport/quicreuse/nonquic_packetconn.go b/p2p/transport/quicreuse/nonquic_packetconn.go index 2f950e76a1..833bd5804a 100644 --- a/p2p/transport/quicreuse/nonquic_packetconn.go +++ b/p2p/transport/quicreuse/nonquic_packetconn.go @@ -4,8 +4,6 @@ import ( "context" "net" "time" - - "github.com/quic-go/quic-go" ) // nonQUICPacketConn is a net.PacketConn that can be used to read and write @@ -13,7 +11,7 @@ import ( // other transports like WebRTC. type nonQUICPacketConn struct { owningTransport refCountedQuicTransport - tr *quic.Transport + tr QUICTransport ctx context.Context ctxCancel context.CancelFunc readCtx context.Context @@ -32,7 +30,7 @@ func (n *nonQUICPacketConn) Close() error { // LocalAddr implements net.PacketConn. func (n *nonQUICPacketConn) LocalAddr() net.Addr { - return n.tr.Conn.LocalAddr() + return n.owningTransport.LocalAddr() } // ReadFrom implements net.PacketConn. diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index c6fc611331..e329ea49dd 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -3,6 +3,8 @@ package quicreuse import ( "context" "crypto/tls" + "errors" + "fmt" "net" "sync" "time" @@ -25,23 +27,30 @@ type refCountedQuicTransport interface { IncreaseCount() Dial(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (quic.Connection, error) - Listen(tlsConf *tls.Config, conf *quic.Config) (*quic.Listener, error) + Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error) } type singleOwnerTransport struct { - quic.Transport + Transport QUICTransport // Used to write packets directly around QUIC. packetConn net.PacketConn } +var _ QUICTransport = &singleOwnerTransport{} + func (c *singleOwnerTransport) IncreaseCount() {} -func (c *singleOwnerTransport) DecreaseCount() { - c.Transport.Close() +func (c *singleOwnerTransport) DecreaseCount() { c.Transport.Close() } +func (c *singleOwnerTransport) LocalAddr() net.Addr { + return c.packetConn.LocalAddr() } -func (c *singleOwnerTransport) LocalAddr() net.Addr { - return c.Transport.Conn.LocalAddr() +func (c *singleOwnerTransport) Dial(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (quic.Connection, error) { + return c.Transport.Dial(ctx, addr, tlsConf, conf) +} + +func (c *singleOwnerTransport) ReadNonQUICPacket(ctx context.Context, b []byte) (int, net.Addr, error) { + return c.Transport.ReadNonQUICPacket(ctx, b) } func (c *singleOwnerTransport) Close() error { @@ -54,6 +63,10 @@ func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { return c.Transport.WriteTo(b, addr) } +func (c *singleOwnerTransport) Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error) { + return c.Transport.Listen(tlsConf, conf) +} + // Constant. Defined as variables to simplify testing. var ( garbageCollectInterval = 30 * time.Second @@ -61,7 +74,7 @@ var ( ) type refcountedTransport struct { - quic.Transport + QUICTransport // Used to write packets directly around QUIC. packetConn net.PacketConn @@ -70,6 +83,11 @@ type refcountedTransport struct { refCount int unusedSince time.Time + // Only set for transports we are borrowing. + // If set, we will _never_ close the underlying transport. We only close this + // channel to signal to the owner that we are done with it. + borrowDoneSignal chan struct{} + assocations map[any]struct{} } @@ -109,17 +127,24 @@ func (c *refcountedTransport) IncreaseCount() { } func (c *refcountedTransport) Close() error { - // TODO(when we drop support for go 1.19) use errors.Join - c.Transport.Close() - return c.packetConn.Close() + if c.borrowDoneSignal != nil { + close(c.borrowDoneSignal) + return nil + } + + return errors.Join(c.QUICTransport.Close(), c.packetConn.Close()) } func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { - return c.Transport.WriteTo(b, addr) + return c.QUICTransport.WriteTo(b, addr) } func (c *refcountedTransport) LocalAddr() net.Addr { - return c.Transport.Conn.LocalAddr() + return c.packetConn.LocalAddr() +} + +func (c *refcountedTransport) Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error) { + return c.QUICTransport.Listen(tlsConf, conf) } func (c *refcountedTransport) DecreaseCount() { @@ -302,15 +327,34 @@ func (r *reuse) transportForDialLocked(association any, network string, source * if err != nil { return nil, err } - tr := &refcountedTransport{Transport: quic.Transport{ - Conn: conn, - StatelessResetKey: r.statelessResetKey, - TokenGeneratorKey: r.tokenGeneratorKey, - }, packetConn: conn} + tr := &refcountedTransport{ + QUICTransport: &wrappedQUICTransport{ + Transport: &quic.Transport{ + Conn: conn, + StatelessResetKey: r.statelessResetKey, + TokenGeneratorKey: r.tokenGeneratorKey, + }, + }, + packetConn: conn, + } r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = tr return tr, nil } +func (r *reuse) AddTransport(tr *refcountedTransport, laddr *net.UDPAddr) error { + r.mutex.Lock() + defer r.mutex.Unlock() + + if !laddr.IP.IsUnspecified() { + return errors.New("adding transport for specific IP not supported") + } + if _, ok := r.globalDialers[laddr.Port]; ok { + return fmt.Errorf("already have global dialer for port %d", laddr.Port) + } + r.globalDialers[laddr.Port] = tr + return nil +} + func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcountedTransport, error) { r.mutex.Lock() defer r.mutex.Unlock() @@ -351,9 +395,11 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun } localAddr := conn.LocalAddr().(*net.UDPAddr) tr := &refcountedTransport{ - Transport: quic.Transport{ - Conn: conn, - StatelessResetKey: r.statelessResetKey, + QUICTransport: &wrappedQUICTransport{ + Transport: &quic.Transport{ + Conn: conn, + StatelessResetKey: r.statelessResetKey, + }, }, packetConn: conn, } From 9fe14c2b37dfbf4e9d737f150d74058a423f1579 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 16 Jan 2025 17:04:28 -0500 Subject: [PATCH 68/75] test: fix failing test (#3141) --- p2p/net/swarm/swarm_dial_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/p2p/net/swarm/swarm_dial_test.go b/p2p/net/swarm/swarm_dial_test.go index add6f5cbba..d3586ca5d9 100644 --- a/p2p/net/swarm/swarm_dial_test.go +++ b/p2p/net/swarm/swarm_dial_test.go @@ -399,8 +399,23 @@ func TestBlackHoledAddrBlocked(t *testing.T) { require.ErrorIs(t, err, ErrDialRefusedBlackHole) } +type mockDNSResolver struct { + ipsToReturn []net.IPAddr + txtsToReturn []string +} + +var _ madns.BasicResolver = (*mockDNSResolver)(nil) + +func (m *mockDNSResolver) LookupIPAddr(_ context.Context, _ string) ([]net.IPAddr, error) { + return m.ipsToReturn, nil +} + +func (m *mockDNSResolver) LookupTXT(_ context.Context, _ string) ([]string, error) { + return m.txtsToReturn, nil +} + func TestSkipDialingManyDNS(t *testing.T) { - resolver, err := madns.NewResolver() + resolver, err := madns.NewResolver(madns.WithDefaultResolver(&mockDNSResolver{ipsToReturn: []net.IPAddr{{IP: net.ParseIP("1.2.3.4")}, {IP: net.ParseIP("1.2.3.5")}}})) if err != nil { t.Fatal(err) } From 613f5a7e5bd5cb5b3f14668ee36d740ef47c292c Mon Sep 17 00:00:00 2001 From: Wlynxg Date: Fri, 17 Jan 2025 22:49:52 +0800 Subject: [PATCH 69/75] fix(net/nat): data race problem of `extAddr` (#3140) Co-authored-by: Marco Munizaga --- p2p/net/nat/nat.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/p2p/net/nat/nat.go b/p2p/net/nat/nat.go index 23af58075a..ebaa167568 100644 --- a/p2p/net/nat/nat.go +++ b/p2p/net/nat/nat.go @@ -6,6 +6,7 @@ import ( "fmt" "net/netip" "sync" + "sync/atomic" "time" logging "github.com/ipfs/go-log/v2" @@ -56,11 +57,11 @@ func DiscoverNAT(ctx context.Context) (*NAT, error) { ctx, cancel := context.WithCancel(context.Background()) nat := &NAT{ nat: natInstance, - extAddr: extAddr, mappings: make(map[entry]int), ctx: ctx, ctxCancel: cancel, } + nat.extAddr.Store(&extAddr) nat.refCount.Add(1) go func() { defer nat.refCount.Done() @@ -77,7 +78,7 @@ type NAT struct { natmu sync.Mutex nat nat.NAT // External IP of the NAT. Will be renewed periodically (every CacheTime). - extAddr netip.Addr + extAddr atomic.Pointer[netip.Addr] refCount sync.WaitGroup ctx context.Context @@ -103,7 +104,7 @@ func (nat *NAT) GetMapping(protocol string, port int) (addr netip.AddrPort, foun nat.mappingmu.Lock() defer nat.mappingmu.Unlock() - if !nat.extAddr.IsValid() { + if !nat.extAddr.Load().IsValid() { return netip.AddrPort{}, false } extPort, found := nat.mappings[entry{protocol: protocol, port: port}] @@ -111,7 +112,7 @@ func (nat *NAT) GetMapping(protocol string, port int) (addr netip.AddrPort, foun if !found || extPort == 0 { return netip.AddrPort{}, false } - return netip.AddrPortFrom(nat.extAddr, uint16(extPort)), true + return netip.AddrPortFrom(*nat.extAddr.Load(), uint16(extPort)), true } // AddMapping attempts to construct a mapping on protocol and internal port. @@ -206,7 +207,7 @@ func (nat *NAT) background() { if err == nil { extAddr, _ = netip.AddrFromSlice(extIP) } - nat.extAddr = extAddr + nat.extAddr.Store(&extAddr) nextAddrUpdate = time.Now().Add(CacheTime) } t.Reset(time.Until(minTime(nextAddrUpdate, nextMappingUpdate))) From 2a580cf7c8f53c66806100036c0d08bef0f343e0 Mon Sep 17 00:00:00 2001 From: sukun Date: Mon, 20 Jan 2025 23:14:31 +0530 Subject: [PATCH 70/75] tcpreuse: fix rcmgr accounting when tcp metrics are enabled (#3142) --- p2p/test/transport/transport_test.go | 36 ++++++++++++++++++++++++++++ p2p/transport/tcp/metrics.go | 11 +++++++++ 2 files changed, 47 insertions(+) diff --git a/p2p/test/transport/transport_test.go b/p2p/test/transport/transport_test.go index 60f8ca0c06..4984419dce 100644 --- a/p2p/test/transport/transport_test.go +++ b/p2p/test/transport/transport_test.go @@ -31,6 +31,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/libp2p/go-libp2p/p2p/security/noise" tls "github.com/libp2p/go-libp2p/p2p/security/tls" + "github.com/libp2p/go-libp2p/p2p/transport/tcp" libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc" "go.uber.org/mock/gomock" @@ -116,6 +117,41 @@ var transportsToTest = []TransportTestCase{ return h }, }, + { + Name: "TCP-Shared-WithMetrics / TLS / Yamux", + HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host { + libp2pOpts := transformOpts(opts) + libp2pOpts = append(libp2pOpts, libp2p.ShareTCPListener()) + libp2pOpts = append(libp2pOpts, libp2p.Security(tls.ID, tls.New)) + libp2pOpts = append(libp2pOpts, libp2p.Muxer(yamux.ID, yamux.DefaultTransport)) + libp2pOpts = append(libp2pOpts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics())) + if opts.NoListen { + libp2pOpts = append(libp2pOpts, libp2p.NoListenAddrs) + } else { + libp2pOpts = append(libp2pOpts, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) + } + h, err := libp2p.New(libp2pOpts...) + require.NoError(t, err) + return h + }, + }, + { + Name: "TCP-WithMetrics / TLS / Yamux", + HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host { + libp2pOpts := transformOpts(opts) + libp2pOpts = append(libp2pOpts, libp2p.Security(tls.ID, tls.New)) + libp2pOpts = append(libp2pOpts, libp2p.Muxer(yamux.ID, yamux.DefaultTransport)) + libp2pOpts = append(libp2pOpts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics())) + if opts.NoListen { + libp2pOpts = append(libp2pOpts, libp2p.NoListenAddrs) + } else { + libp2pOpts = append(libp2pOpts, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) + } + h, err := libp2p.New(libp2pOpts...) + require.NoError(t, err) + return h + }, + }, { Name: "WebSocket-Shared", HostGenerator: func(t *testing.T, opts TransportTestCaseOpts) host.Host { diff --git a/p2p/transport/tcp/metrics.go b/p2p/transport/tcp/metrics.go index 50820d870c..cbd2f92f73 100644 --- a/p2p/transport/tcp/metrics.go +++ b/p2p/transport/tcp/metrics.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/libp2p/go-libp2p/core/network" "github.com/marten-seemann/tcp" "github.com/mikioh/tcpinfo" manet "github.com/multiformats/go-multiaddr/net" @@ -252,6 +253,16 @@ func (c *tracingConn) Close() error { return c.closeErr } +func (c *tracingConn) Scope() network.ConnManagementScope { + if cs, ok := c.Conn.(interface { + Scope() network.ConnManagementScope + }); ok { + return cs.Scope() + } + // upgrader is expected to handle this + return nil +} + func (c *tracingConn) getTCPInfo() (*tcpinfo.Info, error) { var o tcpinfo.Info var b [256]byte From 49c95495f204ee403a4eddc467cc33f6572db578 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 23 Jan 2025 08:05:36 -0800 Subject: [PATCH 71/75] ci: move to actions/upload-artifact@v4 (#3152) --- .github/workflows/go-test-template.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go-test-template.yml b/.github/workflows/go-test-template.yml index fa7c974ea2..f79719ec4b 100644 --- a/.github/workflows/go-test-template.yml +++ b/.github/workflows/go-test-template.yml @@ -109,7 +109,7 @@ jobs: run: test_analysis ${{ env.GOTESTFLAGS }} - name: Upload test results if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}_${{ matrix.go }}_test_results.db path: ./test_results.db @@ -131,7 +131,7 @@ jobs: run: test_analysis -race ${{ env.GORACEFLAGS }} ./... - name: Upload test results (Race) if: (steps.race.conclusion == 'success' || steps.race.conclusion == 'failure') - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}_${{ matrix.go }}_test_results_race.db path: ./test_results.db From b2939f150c202694a0b5ed19305419640382e28d Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 23 Jan 2025 19:01:50 -0800 Subject: [PATCH 72/75] Make changes to internal nat library --- go.mod | 1 - .../nat/.github/workflows/go-check.yml | 18 -- .../nat/.github/workflows/go-test.yml | 20 -- .../nat/.github/workflows/release-check.yml | 19 -- .../nat/.github/workflows/releaser.yml | 17 -- .../internal/nat/.github/workflows/stale.yml | 13 - .../nat/.github/workflows/tagpush.yml | 18 -- p2p/net/nat/internal/nat/README.md | 10 +- .../nat/internal/nat/_examples/nat-tester.go | 67 ----- p2p/net/nat/internal/nat/gateway.go | 17 -- p2p/net/nat/internal/nat/go.mod | 17 -- p2p/net/nat/internal/nat/go.sum | 29 -- p2p/net/nat/internal/nat/nat.go | 154 +++++++---- p2p/net/nat/internal/nat/natpmp.go | 58 ++-- p2p/net/nat/internal/nat/upnp.go | 256 ++++++------------ p2p/net/nat/internal/nat/version.json | 3 - p2p/net/nat/nat.go | 2 +- p2p/net/nat/nat_test.go | 3 +- 18 files changed, 223 insertions(+), 499 deletions(-) delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/go-check.yml delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/go-test.yml delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/release-check.yml delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/releaser.yml delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/stale.yml delete mode 100644 p2p/net/nat/internal/nat/.github/workflows/tagpush.yml delete mode 100644 p2p/net/nat/internal/nat/_examples/nat-tester.go delete mode 100644 p2p/net/nat/internal/nat/gateway.go delete mode 100644 p2p/net/nat/internal/nat/go.mod delete mode 100644 p2p/net/nat/internal/nat/go.sum delete mode 100644 p2p/net/nat/internal/nat/version.json diff --git a/go.mod b/go.mod index 28abae8ffc..a9e4a04d6c 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( github.com/libp2p/go-libp2p-asn-util v0.4.1 github.com/libp2p/go-libp2p-testing v0.12.0 github.com/libp2p/go-msgio v0.3.0 - github.com/libp2p/go-nat v0.2.0 github.com/libp2p/go-netroute v0.2.2 github.com/libp2p/go-reuseport v0.4.0 github.com/libp2p/go-yamux/v4 v4.0.1 diff --git a/p2p/net/nat/internal/nat/.github/workflows/go-check.yml b/p2p/net/nat/internal/nat/.github/workflows/go-check.yml deleted file mode 100644 index 26f63bc126..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/go-check.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Go Checks - -on: - pull_request: - push: - branches: ["master"] - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} - cancel-in-progress: true - -jobs: - go-check: - uses: ipdxco/unified-github-workflows/.github/workflows/go-check.yml@v1.0 diff --git a/p2p/net/nat/internal/nat/.github/workflows/go-test.yml b/p2p/net/nat/internal/nat/.github/workflows/go-test.yml deleted file mode 100644 index 778de6ed48..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/go-test.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Go Test - -on: - pull_request: - push: - branches: ["master"] - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} - cancel-in-progress: true - -jobs: - go-test: - uses: ipdxco/unified-github-workflows/.github/workflows/go-test.yml@v1.0 - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/p2p/net/nat/internal/nat/.github/workflows/release-check.yml b/p2p/net/nat/internal/nat/.github/workflows/release-check.yml deleted file mode 100644 index 0b5ff6070f..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/release-check.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Release Checker - -on: - pull_request_target: - paths: [ 'version.json' ] - types: [ opened, synchronize, reopened, labeled, unlabeled ] - workflow_dispatch: - -permissions: - contents: write - pull-requests: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release-check: - uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0 diff --git a/p2p/net/nat/internal/nat/.github/workflows/releaser.yml b/p2p/net/nat/internal/nat/.github/workflows/releaser.yml deleted file mode 100644 index 2ebdbed31a..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/releaser.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Releaser - -on: - push: - paths: [ 'version.json' ] - workflow_dispatch: - -permissions: - contents: write - -concurrency: - group: ${{ github.workflow }}-${{ github.sha }} - cancel-in-progress: true - -jobs: - releaser: - uses: ipdxco/unified-github-workflows/.github/workflows/releaser.yml@v1.0 diff --git a/p2p/net/nat/internal/nat/.github/workflows/stale.yml b/p2p/net/nat/internal/nat/.github/workflows/stale.yml deleted file mode 100644 index 16d65d7217..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/stale.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close and mark stale issue - -on: - schedule: - - cron: '0 0 * * *' - -permissions: - issues: write - pull-requests: write - -jobs: - stale: - uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 diff --git a/p2p/net/nat/internal/nat/.github/workflows/tagpush.yml b/p2p/net/nat/internal/nat/.github/workflows/tagpush.yml deleted file mode 100644 index 5ef3fb9ede..0000000000 --- a/p2p/net/nat/internal/nat/.github/workflows/tagpush.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Tag Push Checker - -on: - push: - tags: - - v* - -permissions: - contents: read - issues: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - releaser: - uses: ipdxco/unified-github-workflows/.github/workflows/tagpush.yml@v1.0 diff --git a/p2p/net/nat/internal/nat/README.md b/p2p/net/nat/internal/nat/README.md index 61b5cc8891..a856a83072 100644 --- a/p2p/net/nat/internal/nat/README.md +++ b/p2p/net/nat/internal/nat/README.md @@ -1,9 +1 @@ -# go-nat - -[![GoDoc](https://godoc.org/github.com/libp2p/go-nat?status.svg)](https://godoc.org/github.com/libp2p/go-nat) [![status](https://sourcegraph.com/api/repos/github.com/libp2p/go-nat/.badges/status.png)](https://sourcegraph.com/github.com/libp2p/go-nat) - -Forked from: [fd/go-nat](https://github.com/fd/go-nat). - ---- - -The last gx published version of this module was: 1.0.3: QmdwkZHamNNrj7k3G29rnurmW3mFzsDhnyXppNcgYsiBVz +Originally forked from: [fd/go-nat](https://github.com/fd/go-nat). diff --git a/p2p/net/nat/internal/nat/_examples/nat-tester.go b/p2p/net/nat/internal/nat/_examples/nat-tester.go deleted file mode 100644 index e3b616b2a5..0000000000 --- a/p2p/net/nat/internal/nat/_examples/nat-tester.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "time" - - "github.com/libp2p/go-nat" -) - -func main() { - nat, err := nat.DiscoverGateway() - if err != nil { - log.Fatalf("error: %s", err) - } - log.Printf("nat type: %s", nat.Type()) - - daddr, err := nat.GetDeviceAddress() - if err != nil { - log.Fatalf("error: %s", err) - } - log.Printf("device address: %s", daddr) - - iaddr, err := nat.GetInternalAddress() - if err != nil { - log.Fatalf("error: %s", err) - } - log.Printf("internal address: %s", iaddr) - - eaddr, err := nat.GetExternalAddress() - if err != nil { - log.Fatalf("error: %s", err) - } - log.Printf("external address: %s", eaddr) - - eport, err := nat.AddPortMapping("tcp", 3080, "http", 60) - if err != nil { - log.Fatalf("error: %s", err) - } - - log.Printf("test-page: http://%s:%d/", eaddr, eport) - - go func() { - for { - time.Sleep(30 * time.Second) - - _, err = nat.AddPortMapping("tcp", 3080, "http", 60) - if err != nil { - log.Fatalf("error: %s", err) - } - } - }() - - defer nat.DeletePortMapping("tcp", 3080) - - http.ListenAndServe(":3080", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { - rw.Header().Set("Content-Type", "text/plain") - rw.WriteHeader(200) - fmt.Fprintf(rw, "Hello there!\n") - fmt.Fprintf(rw, "nat type: %s\n", nat.Type()) - fmt.Fprintf(rw, "device address: %s\n", daddr) - fmt.Fprintf(rw, "internal address: %s\n", iaddr) - fmt.Fprintf(rw, "external address: %s\n", eaddr) - fmt.Fprintf(rw, "test-page: http://%s:%d/\n", eaddr, eport) - })) -} diff --git a/p2p/net/nat/internal/nat/gateway.go b/p2p/net/nat/internal/nat/gateway.go deleted file mode 100644 index a87e46a892..0000000000 --- a/p2p/net/nat/internal/nat/gateway.go +++ /dev/null @@ -1,17 +0,0 @@ -package nat - -import ( - "net" - - "github.com/libp2p/go-netroute" -) - -func getDefaultGateway() (net.IP, error) { - router, err := netroute.New() - if err != nil { - return nil, err - } - - _, ip, _, err := router.Route(net.IPv4zero) - return ip, err -} diff --git a/p2p/net/nat/internal/nat/go.mod b/p2p/net/nat/internal/nat/go.mod deleted file mode 100644 index 837511836b..0000000000 --- a/p2p/net/nat/internal/nat/go.mod +++ /dev/null @@ -1,17 +0,0 @@ -module github.com/libp2p/go-nat - -require ( - github.com/huin/goupnp v1.2.0 - github.com/jackpal/go-nat-pmp v1.0.2 - github.com/koron/go-ssdp v0.0.4 - github.com/libp2p/go-netroute v0.2.1 -) - -require ( - github.com/google/gopacket v1.1.19 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect -) - -go 1.22 diff --git a/p2p/net/nat/internal/nat/go.sum b/p2p/net/nat/internal/nat/go.sum deleted file mode 100644 index b20c1c6226..0000000000 --- a/p2p/net/nat/internal/nat/go.sum +++ /dev/null @@ -1,29 +0,0 @@ -github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= -github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= -github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY= -github.com/huin/goupnp v1.2.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= -github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= -github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= -github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -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.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -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.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -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.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/p2p/net/nat/internal/nat/nat.go b/p2p/net/nat/internal/nat/nat.go index 6b3e19c444..87ffc3c264 100644 --- a/p2p/net/nat/internal/nat/nat.go +++ b/p2p/net/nat/internal/nat/nat.go @@ -4,15 +4,29 @@ package nat import ( "context" "errors" + "fmt" "math" "math/rand" "net" + "sync" "time" + + logging "github.com/ipfs/go-log/v2" + "github.com/libp2p/go-netroute" ) +var log = logging.Logger("internal/nat") + var ErrNoExternalAddress = errors.New("no external address") var ErrNoInternalAddress = errors.New("no internal address") -var ErrNoNATFound = errors.New("no NAT found") + +type ErrNoNATFound struct { + Errs []error +} + +func (e ErrNoNATFound) Error() string { + return fmt.Sprintf("no NAT found: %#v", e.Errs) +} // protocol is either "udp" or "tcp" type NAT interface { @@ -35,65 +49,93 @@ type NAT interface { DeletePortMapping(ctx context.Context, protocol string, internalPort int) (err error) } -// DiscoverNATs returns all NATs discovered in the network. -func DiscoverNATs(ctx context.Context) <-chan NAT { - nats := make(chan NAT) +type result[V any] struct { + Value V + Err error +} +// discoverNATs returns all NATs discovered in the network. +func discoverNATs(ctx context.Context) ([]NAT, []error) { + var nats []NAT + var errs []error + + type natsAndErrs struct { + nats []NAT + errs []error + } + resCh := make(chan natsAndErrs) + + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + nats, errs := discoverUPNP_IG1(ctx) + select { + case resCh <- natsAndErrs{nats, errs}: + case <-ctx.Done(): + } + }() + + wg.Add(1) go func() { - defer close(nats) - - upnpIg1 := discoverUPNP_IG1(ctx) - upnpIg2 := discoverUPNP_IG2(ctx) - natpmp := discoverNATPMP(ctx) - upnpGenIGDev := discoverUPNP_GenIGDev(ctx) - for upnpIg1 != nil || upnpIg2 != nil || natpmp != nil || upnpGenIGDev != nil { - var ( - nat NAT - ok bool - ) - select { - case nat, ok = <-upnpIg1: - if !ok { - upnpIg1 = nil - } - case nat, ok = <-upnpIg2: - if !ok { - upnpIg2 = nil - } - case nat, ok = <-upnpGenIGDev: - if !ok { - upnpGenIGDev = nil - } - case nat, ok = <-natpmp: - if !ok { - natpmp = nil - } - case <-ctx.Done(): - // timeout. - return - } - if ok { - select { - case nats <- nat: - case <-ctx.Done(): - return - } - } + defer wg.Done() + nats, errs := discoverUPNP_IG2(ctx) + select { + case resCh <- natsAndErrs{nats, errs}: + case <-ctx.Done(): } }() - return nats + + wg.Add(1) + go func() { + defer wg.Done() + nat, err := discoverNATPMP(ctx) + var nats []NAT + var errs []error + if err != nil { + errs = append(errs, err) + } else { + nats = append(nats, nat) + } + select { + case resCh <- natsAndErrs{nats, errs}: + case <-ctx.Done(): + } + }() + + allDone := make(chan struct{}) + go func() { + defer close(allDone) + wg.Wait() + }() + + for { + select { + case res := <-resCh: + nats = append(nats, res.nats...) + errs = append(errs, res.errs...) + return nats, errs + case <-allDone: + return nats, errs + case <-ctx.Done(): + errs = append(errs, ctx.Err()) + return nats, errs + } + } } // DiscoverGateway attempts to find a gateway device. func DiscoverGateway(ctx context.Context) (NAT, error) { - var nats []NAT - for nat := range DiscoverNATs(ctx) { - nats = append(nats, nat) - } + nats, errs := discoverNATs(ctx) + switch len(nats) { case 0: - return nil, ErrNoNATFound + return nil, ErrNoNATFound{Errs: errs} case 1: + if len(errs) > 0 { + log.Debugf("NAT found, but some potentially unrelated errors occurred: %v", errs) + } + return nats[0], nil } gw, _ := getDefaultGateway() @@ -115,6 +157,10 @@ func DiscoverGateway(ctx context.Context) (NAT, error) { bestNATIsGw = natIsGw bestNAT = nat } + + if len(errs) > 0 { + log.Debugf("NAT found, but some potentially unrelated errors occurred: %v", errs) + } return bestNAT, nil } @@ -123,3 +169,13 @@ var random = rand.New(rand.NewSource(time.Now().UnixNano())) func randomPort() int { return random.Intn(math.MaxUint16-10000) + 10000 } + +func getDefaultGateway() (net.IP, error) { + router, err := netroute.New() + if err != nil { + return nil, err + } + + _, ip, _, err := router.Route(net.IPv4zero) + return ip, err +} diff --git a/p2p/net/nat/internal/nat/natpmp.go b/p2p/net/nat/internal/nat/natpmp.go index 2378d8d7ec..a83bc805c9 100644 --- a/p2p/net/nat/internal/nat/natpmp.go +++ b/p2p/net/nat/internal/nat/natpmp.go @@ -12,42 +12,48 @@ var ( _ NAT = (*natpmpNAT)(nil) ) -func discoverNATPMP(ctx context.Context) <-chan NAT { - res := make(chan NAT, 1) - +func discoverNATPMP(ctx context.Context) (NAT, error) { ip, err := getDefaultGateway() if err != nil { - return nil + return nil, err } - go func() { - defer close(res) - // Unfortunately, we can't actually _stop_ the natpmp - // library. However, we can at least close _our_ channel - // and walk away. - select { - case client, ok := <-discoverNATPMPWithAddr(ip): - if ok { - res <- &natpmpNAT{client, ip, make(map[int]int)} - } - case <-ctx.Done(): - } - }() - return res -} + clientCh := make(chan *natpmp.Client) + errCh := make(chan error) -func discoverNATPMPWithAddr(ip net.IP) <-chan *natpmp.Client { - res := make(chan *natpmp.Client, 1) + // We can't cancel the natpmp library, but we can at least still return + // on context cancellation by putting this in a goroutine go func() { - defer close(res) - client := natpmp.NewClient(ip) - _, err := client.GetExternalAddress() + client, err := discoverNATPMPWithAddr(ctx, ip) if err != nil { + errCh <- err return } - res <- client + clientCh <- client }() - return res + + select { + case client := <-clientCh: + return &natpmpNAT{client, ip, make(map[int]int)}, nil + case err := <-errCh: + return nil, err + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +func discoverNATPMPWithAddr(ctx context.Context, ip net.IP) (*natpmp.Client, error) { + var client *natpmp.Client + if deadline, ok := ctx.Deadline(); ok { + client = natpmp.NewClientWithTimeout(ip, time.Until(deadline)) + } else { + client = natpmp.NewClient(ip) + } + _, err := client.GetExternalAddress() + if err != nil { + return nil, err + } + return client, nil } type natpmpNAT struct { diff --git a/p2p/net/nat/internal/nat/upnp.go b/p2p/net/nat/internal/nat/upnp.go index c50b952bbe..817fb6f4c6 100644 --- a/p2p/net/nat/internal/nat/upnp.go +++ b/p2p/net/nat/internal/nat/upnp.go @@ -16,197 +16,107 @@ import ( var _ NAT = (*upnp_NAT)(nil) -func discoverUPNP_IG1(ctx context.Context) <-chan NAT { - res := make(chan NAT) - go func() { - defer close(res) - - // find devices - devs, err := goupnp.DiscoverDevicesCtx(ctx, internetgateway1.URN_WANConnectionDevice_1) - if err != nil { - return - } +func discoverUPNP_IG1(ctx context.Context) ([]NAT, []error) { + return discoverSearchTarget(ctx, internetgateway1.URN_WANConnectionDevice_1) +} - for _, dev := range devs { - if dev.Root == nil { - continue - } +func discoverUPNP_IG2(ctx context.Context) ([]NAT, []error) { + return discoverSearchTarget(ctx, internetgateway2.URN_WANConnectionDevice_2) +} - dev.Root.Device.VisitServices(func(srv *goupnp.Service) { - if ctx.Err() != nil { - return - } - switch srv.ServiceType { - case internetgateway1.URN_WANIPConnection_1: - client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: dev.Root, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", dev.Root}: - case <-ctx.Done(): - } - } - - case internetgateway1.URN_WANPPPConnection_1: - client := &internetgateway1.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: dev.Root, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", dev.Root}: - case <-ctx.Done(): - } - } +func discoverSearchTarget(ctx context.Context, target string) (nats []NAT, errs []error) { + // find devices + devs, err := goupnp.DiscoverDevicesCtx(ctx, target) + if err != nil { + errs = append(errs, err) + return + } - } - }) + for _, dev := range devs { + if dev.Err != nil { + errs = append(errs, dev.Err) + continue } - - }() - return res + dev.Root.Device.VisitServices(serviceVisitor(ctx, dev.Root, &nats, &errs)) + } + return } -func discoverUPNP_IG2(ctx context.Context) <-chan NAT { - res := make(chan NAT) - go func() { - defer close(res) - - // find devices - devs, err := goupnp.DiscoverDevicesCtx(ctx, internetgateway2.URN_WANConnectionDevice_2) - if err != nil { - return +func discoverUPNP_GenIGDev(ctx context.Context) (nats []NAT, errs []error) { + DeviceList, err := ssdp.Search(ssdp.All, 5, "") + if err != nil { + errs = append(errs, err) + return + } + var gw ssdp.Service + for _, Service := range DeviceList { + if strings.Contains(Service.Type, "InternetGatewayDevice") { + gw = Service + break } + } - for _, dev := range devs { - if dev.Root == nil { - continue - } - - dev.Root.Device.VisitServices(func(srv *goupnp.Service) { - if ctx.Err() != nil { - return - } - switch srv.ServiceType { - case internetgateway2.URN_WANIPConnection_1: - client := &internetgateway2.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: dev.Root, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP1)", dev.Root}: - case <-ctx.Done(): - } - } - - case internetgateway2.URN_WANIPConnection_2: - client := &internetgateway2.WANIPConnection2{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: dev.Root, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-IP2)", dev.Root}: - case <-ctx.Done(): - } - } - - case internetgateway2.URN_WANPPPConnection_1: - client := &internetgateway2.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: dev.Root, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG2-PPP1)", dev.Root}: - case <-ctx.Done(): - } - } - - } - }) - } + DeviceURL, err := url.Parse(gw.Location) + if err != nil { + errs = append(errs, err) + return + } + RootDevice, err := goupnp.DeviceByURLCtx(ctx, DeviceURL) + if err != nil { + errs = append(errs, err) + return + } - }() - return res + RootDevice.Device.VisitServices(serviceVisitor(ctx, RootDevice, &nats, &errs)) + return } -func discoverUPNP_GenIGDev(ctx context.Context) <-chan NAT { - res := make(chan NAT, 1) - go func() { - defer close(res) - - DeviceList, err := ssdp.Search(ssdp.All, 5, "") - if err != nil { +func serviceVisitor(ctx context.Context, rootDevice *goupnp.RootDevice, outNats *[]NAT, outErrs *[]error) func(srv *goupnp.Service) { + return func(srv *goupnp.Service) { + if ctx.Err() != nil { return } - var gw ssdp.Service - for _, Service := range DeviceList { - if strings.Contains(Service.Type, "InternetGatewayDevice") { - gw = Service - break + switch srv.ServiceType { + case internetgateway2.URN_WANIPConnection_1: + client := &internetgateway2.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: rootDevice, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) + if err != nil { + *outErrs = append(*outErrs, err) + } else if isNat { + *outNats = append(*outNats, &upnp_NAT{client, make(map[int]int), "UPNP (IP1)", rootDevice}) } - } - - DeviceURL, err := url.Parse(gw.Location) - if err != nil { - return - } - RootDevice, err := goupnp.DeviceByURLCtx(ctx, DeviceURL) - if err != nil { - return - } - RootDevice.Device.VisitServices(func(srv *goupnp.Service) { - if ctx.Err() != nil { - return + case internetgateway2.URN_WANIPConnection_2: + client := &internetgateway2.WANIPConnection2{ServiceClient: goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: rootDevice, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) + if err != nil { + *outErrs = append(*outErrs, err) + } else if isNat { + *outNats = append(*outNats, &upnp_NAT{client, make(map[int]int), "UPNP (IP2)", rootDevice}) } - switch srv.ServiceType { - case internetgateway1.URN_WANIPConnection_1: - client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: RootDevice, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice}: - case <-ctx.Done(): - } - } - - case internetgateway1.URN_WANPPPConnection_1: - client := &internetgateway1.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ - SOAPClient: srv.NewSOAPClient(), - RootDevice: RootDevice, - Service: srv, - }} - _, isNat, err := client.GetNATRSIPStatusCtx(ctx) - if err == nil && isNat { - select { - case res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice}: - case <-ctx.Done(): - } - } + case internetgateway2.URN_WANPPPConnection_1: + client := &internetgateway2.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{ + SOAPClient: srv.NewSOAPClient(), + RootDevice: rootDevice, + Service: srv, + }} + _, isNat, err := client.GetNATRSIPStatusCtx(ctx) + if err != nil { + *outErrs = append(*outErrs, err) + } else if isNat { + *outNats = append(*outNats, &upnp_NAT{client, make(map[int]int), "UPNP (PPP1)", rootDevice}) } - }) - }() - return res + } + } } type upnp_NAT_Client interface { diff --git a/p2p/net/nat/internal/nat/version.json b/p2p/net/nat/internal/nat/version.json deleted file mode 100644 index 1437d5b735..0000000000 --- a/p2p/net/nat/internal/nat/version.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "v0.2.0" -} diff --git a/p2p/net/nat/nat.go b/p2p/net/nat/nat.go index ebaa167568..c45b067f9c 100644 --- a/p2p/net/nat/nat.go +++ b/p2p/net/nat/nat.go @@ -11,7 +11,7 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/libp2p/go-nat" + "github.com/libp2p/go-libp2p/p2p/net/nat/internal/nat" ) // ErrNoMapping signals no mapping exists for an address diff --git a/p2p/net/nat/nat_test.go b/p2p/net/nat/nat_test.go index e370fc8907..7cf37767b8 100644 --- a/p2p/net/nat/nat_test.go +++ b/p2p/net/nat/nat_test.go @@ -7,8 +7,7 @@ import ( "net/netip" "testing" - "github.com/libp2p/go-nat" - + "github.com/libp2p/go-libp2p/p2p/net/nat/internal/nat" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) From f4e28bae0a3d39c59a5c7730d57ab6364467cb24 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 23 Jan 2025 19:27:43 -0800 Subject: [PATCH 73/75] mod tidy test-plans --- test-plans/go.mod | 1 - test-plans/go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/test-plans/go.mod b/test-plans/go.mod index 6bd58c0b95..172151f4fa 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -41,7 +41,6 @@ require ( github.com/libp2p/go-flow-metrics v0.2.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect - github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.2 // indirect github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index 439614d540..329a2475d2 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -144,8 +144,6 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= -github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= -github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8= github.com/libp2p/go-netroute v0.2.2/go.mod h1:Rntq6jUAH0l9Gg17w5bFGhcC9a+vk4KNXs6s7IljKYE= github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= From 1f4471ae219667358270c14d2983f634cb25535e Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 23 Jan 2025 19:29:22 -0800 Subject: [PATCH 74/75] reference internal package for mockgen --- p2p/net/nat/mock_nat_test.go | 4 ++-- p2p/net/nat/nat_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/net/nat/mock_nat_test.go b/p2p/net/nat/mock_nat_test.go index c8023344ea..ed8b6a1a61 100644 --- a/p2p/net/nat/mock_nat_test.go +++ b/p2p/net/nat/mock_nat_test.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/libp2p/go-nat (interfaces: NAT) +// Source: github.com/libp2p/go-libp2p/p2p/net/nat/internal/nat (interfaces: NAT) // // Generated by this command: // -// mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT +// mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/net/nat/internal/nat NAT // // Package nat is a generated GoMock package. diff --git a/p2p/net/nat/nat_test.go b/p2p/net/nat/nat_test.go index 7cf37767b8..5779a27e6c 100644 --- a/p2p/net/nat/nat_test.go +++ b/p2p/net/nat/nat_test.go @@ -12,7 +12,7 @@ import ( "go.uber.org/mock/gomock" ) -//go:generate sh -c "go run go.uber.org/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT" +//go:generate sh -c "go run go.uber.org/mock/mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/net/nat/internal/nat NAT" func setupMockNAT(t *testing.T) (mockNAT *MockNAT, reset func()) { t.Helper() From 35088ba7c45595056515fd5f60b714ff9d08144c Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Fri, 24 Jan 2025 08:49:08 -0800 Subject: [PATCH 75/75] go mod tidy --- go.mod | 6 +++--- go.sum | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index a9e4a04d6c..228959510b 100644 --- a/go.mod +++ b/go.mod @@ -15,13 +15,16 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/hashicorp/golang-lru/arc/v2 v2.0.7 github.com/hashicorp/golang-lru/v2 v2.0.7 + github.com/huin/goupnp v1.3.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger v0.3.0 github.com/ipfs/go-ds-leveldb v0.5.0 github.com/ipfs/go-log/v2 v2.5.1 + github.com/jackpal/go-nat-pmp v1.0.2 github.com/jbenet/go-temp-err-catcher v0.1.0 github.com/klauspost/compress v1.17.11 + github.com/koron/go-ssdp v0.0.4 github.com/libp2p/go-buffer-pool v0.1.0 github.com/libp2p/go-flow-metrics v0.2.0 github.com/libp2p/go-libp2p-asn-util v0.4.1 @@ -89,11 +92,8 @@ require ( github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect github.com/google/uuid v1.6.0 // indirect - github.com/huin/goupnp v1.3.0 // indirect - github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/goprocess v0.1.4 // indirect github.com/klauspost/cpuid/v2 v2.2.9 // indirect - github.com/koron/go-ssdp v0.0.4 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/miekg/dns v1.1.62 // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect diff --git a/go.sum b/go.sum index 2d8fb16cf3..ca26d76a08 100644 --- a/go.sum +++ b/go.sum @@ -188,8 +188,6 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= -github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk= -github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk= github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8= github.com/libp2p/go-netroute v0.2.2/go.mod h1:Rntq6jUAH0l9Gg17w5bFGhcC9a+vk4KNXs6s7IljKYE= github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s=