From bda3dcc670a5ba4886d0495e40992b700ab4677d Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 28 Nov 2024 03:01:12 -0800 Subject: [PATCH] Remove stun Fixes #849 --- go.mod | 5 +---- go.sum | 2 -- src/utils/utils.go | 30 +++++++++++------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 102535dca..0a91923a7 100644 --- a/go.mod +++ b/go.mod @@ -17,13 +17,13 @@ require ( github.com/schollz/pake/v3 v3.0.5 github.com/schollz/peerdiscovery v1.7.5 github.com/schollz/progressbar/v3 v3.17.1 + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/stretchr/testify v1.9.0 golang.org/x/crypto v0.29.0 golang.org/x/net v0.31.0 golang.org/x/sys v0.27.0 golang.org/x/term v0.26.0 golang.org/x/time v0.8.0 - gortc.io/stun v1.23.0 ) require ( @@ -33,10 +33,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/tscholl2/siec v0.0.0-20240310163802-c2c6f6198406 // indirect github.com/twmb/murmur3 v1.1.8 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace gortc.io/stun => github.com/gortc/stun v1.23.0 diff --git a/go.sum b/go.sum index 28f7e3f6b..64056308f 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/gortc/stun v1.23.0 h1:/hkB8P0DeDfiVf3khHSMSTRpldFMqiuddn2XhaUPOkM= -github.com/gortc/stun v1.23.0/go.mod h1:XD5lpONVyjvV3BgOyJFNo0iv6R2oZB4L+weMqxts+zg= github.com/kalafut/imohash v1.1.0 h1:Lldcmx0SXgMSoABB2WBD8mTgf0OlVnISn2Dyrfg2Ep8= github.com/kalafut/imohash v1.1.0/go.mod h1:6cn9lU0Sj8M4eu9UaQm1kR/5y3k/ayB68yntRhGloL4= github.com/magisterquis/connectproxy v0.0.0-20200725203833-3582e84f0c9b h1:xZ59n7Frzh8CwyfAapUZLSg+gXH5m63YEaFCMpDHhpI= diff --git a/src/utils/utils.go b/src/utils/utils.go index 3aa588c8f..32d0a650d 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -14,6 +14,7 @@ import ( "math" "math/big" "net" + "net/http" "os" "path" "path/filepath" @@ -27,7 +28,6 @@ import ( "github.com/schollz/croc/v10/src/mnemonicode" log "github.com/schollz/logger" "github.com/schollz/progressbar/v3" - "gortc.io/stun" ) const NbPinNumbers = 4 @@ -246,29 +246,21 @@ func SHA256(s string) string { // PublicIP returns public ip address func PublicIP() (ip string, err error) { - // Create a "connection" to the STUN server - conn, err := stun.Dial("udp", "stun.l.google.com:19302") + // ask ipv4.icanhazip.com for the public ip + // by making http request + // if the request fails, return nothing + resp, err := http.Get("http://ipv4.icanhazip.com") if err != nil { return } + defer resp.Body.Close() - // Build and send a binding request to the STUN server - message := stun.MustBuild(stun.TransactionID, stun.BindingRequest) - if err = conn.Do(message, func(res stun.Event) { - if res.Error != nil { - return - } + // read the body of the response + // and return the ip address + buf := new(bytes.Buffer) + buf.ReadFrom(resp.Body) + ip = strings.TrimSpace(buf.String()) - // Process the binding response - var xorAddr stun.XORMappedAddress - if err := xorAddr.GetFrom(res.Message); err != nil { - return - } - - ip = xorAddr.IP.String() - }); err != nil { - return - } return }