Skip to content

Commit

Permalink
Remove stun Fixes #849
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Nov 28, 2024
1 parent a96e794 commit bda3dcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
30 changes: 11 additions & 19 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"math"
"math/big"
"net"
"net/http"
"os"
"path"
"path/filepath"
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit bda3dcc

Please sign in to comment.