Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android crash by using maddrs sent via kotlin #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sakul-budhathoki/go-store v0.0.0-20240330051705-f41a0c8527b1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sakul-budhathoki/go-store v0.0.0-20240330051705-f41a0c8527b1 h1:YLToMqJ5m2EII1wh/U0HW3oRa7nXcSgMnbk09rEDjAM=
github.com/sakul-budhathoki/go-store v0.0.0-20240330051705-f41a0c8527b1/go.mod h1:g5fvnZOJj32v/bGqKydjBVyGudq+bElvbsjySrPsL40=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
18 changes: 18 additions & 0 deletions net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"context"
"fmt"
"net"
"runtime"

ma "github.com/multiformats/go-multiaddr"
globalstore "github.com/sakul-budhathoki/go-store"
)

// Conn is the equivalent of a net.Conn object. It is the
Expand Down Expand Up @@ -387,6 +389,22 @@ func WrapPacketConn(pc net.PacketConn) (PacketConn, error) {

// InterfaceMultiaddrs will return the addresses matching net.InterfaceAddrs
func InterfaceMultiaddrs() ([]ma.Multiaddr, error) {

if runtime.GOOS == "android" {
addrStrings := globalstore.GetGlobalStore().Get("multiaddr")
var maddrs []ma.Multiaddr
if addrStringsSlice, ok := addrStrings.([]string); ok {
for _, addrStr := range addrStringsSlice {
addr, err := ma.NewMultiaddr(addrStr)
if err == nil {
maddrs = append(maddrs, addr)
}
}

return maddrs, nil
}
}

addrs, err := net.InterfaceAddrs()
if err != nil {
return nil, err
Expand Down