Skip to content

Commit bda3dcc

Browse files
committed
Remove stun Fixes #849
1 parent a96e794 commit bda3dcc

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ require (
1717
github.com/schollz/pake/v3 v3.0.5
1818
github.com/schollz/peerdiscovery v1.7.5
1919
github.com/schollz/progressbar/v3 v3.17.1
20+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
2021
github.com/stretchr/testify v1.9.0
2122
golang.org/x/crypto v0.29.0
2223
golang.org/x/net v0.31.0
2324
golang.org/x/sys v0.27.0
2425
golang.org/x/term v0.26.0
2526
golang.org/x/time v0.8.0
26-
gortc.io/stun v1.23.0
2727
)
2828

2929
require (
@@ -33,10 +33,7 @@ require (
3333
github.com/pmezard/go-difflib v1.0.0 // indirect
3434
github.com/rivo/uniseg v0.4.7 // indirect
3535
github.com/russross/blackfriday/v2 v2.1.0 // indirect
36-
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
3736
github.com/tscholl2/siec v0.0.0-20240310163802-c2c6f6198406 // indirect
3837
github.com/twmb/murmur3 v1.1.8 // indirect
3938
gopkg.in/yaml.v3 v3.0.1 // indirect
4039
)
41-
42-
replace gortc.io/stun => github.com/gortc/stun v1.23.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
2020
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
2121
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
2222
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
23-
github.com/gortc/stun v1.23.0 h1:/hkB8P0DeDfiVf3khHSMSTRpldFMqiuddn2XhaUPOkM=
24-
github.com/gortc/stun v1.23.0/go.mod h1:XD5lpONVyjvV3BgOyJFNo0iv6R2oZB4L+weMqxts+zg=
2523
github.com/kalafut/imohash v1.1.0 h1:Lldcmx0SXgMSoABB2WBD8mTgf0OlVnISn2Dyrfg2Ep8=
2624
github.com/kalafut/imohash v1.1.0/go.mod h1:6cn9lU0Sj8M4eu9UaQm1kR/5y3k/ayB68yntRhGloL4=
2725
github.com/magisterquis/connectproxy v0.0.0-20200725203833-3582e84f0c9b h1:xZ59n7Frzh8CwyfAapUZLSg+gXH5m63YEaFCMpDHhpI=

src/utils/utils.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"math"
1515
"math/big"
1616
"net"
17+
"net/http"
1718
"os"
1819
"path"
1920
"path/filepath"
@@ -27,7 +28,6 @@ import (
2728
"github.com/schollz/croc/v10/src/mnemonicode"
2829
log "github.com/schollz/logger"
2930
"github.com/schollz/progressbar/v3"
30-
"gortc.io/stun"
3131
)
3232

3333
const NbPinNumbers = 4
@@ -246,29 +246,21 @@ func SHA256(s string) string {
246246

247247
// PublicIP returns public ip address
248248
func PublicIP() (ip string, err error) {
249-
// Create a "connection" to the STUN server
250-
conn, err := stun.Dial("udp", "stun.l.google.com:19302")
249+
// ask ipv4.icanhazip.com for the public ip
250+
// by making http request
251+
// if the request fails, return nothing
252+
resp, err := http.Get("http://ipv4.icanhazip.com")
251253
if err != nil {
252254
return
253255
}
256+
defer resp.Body.Close()
254257

255-
// Build and send a binding request to the STUN server
256-
message := stun.MustBuild(stun.TransactionID, stun.BindingRequest)
257-
if err = conn.Do(message, func(res stun.Event) {
258-
if res.Error != nil {
259-
return
260-
}
258+
// read the body of the response
259+
// and return the ip address
260+
buf := new(bytes.Buffer)
261+
buf.ReadFrom(resp.Body)
262+
ip = strings.TrimSpace(buf.String())
261263

262-
// Process the binding response
263-
var xorAddr stun.XORMappedAddress
264-
if err := xorAddr.GetFrom(res.Message); err != nil {
265-
return
266-
}
267-
268-
ip = xorAddr.IP.String()
269-
}); err != nil {
270-
return
271-
}
272264
return
273265
}
274266

0 commit comments

Comments
 (0)