From 291eff1aa347e275735520541d051a42cf0f2dce Mon Sep 17 00:00:00 2001 From: dyhkwong <50692134+dyhkwong@users.noreply.github.com> Date: Thu, 17 Dec 2020 08:50:13 +0800 Subject: [PATCH] Refine Android build (#525) Co-authored-by: ghost --- infra/conf/trojan.go | 2 +- infra/conf/vless.go | 2 +- testing/scenarios/transport_test.go | 4 ++-- transport/internet/domainsocket/listener_test.go | 1 + transport/internet/system_listener.go | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/infra/conf/trojan.go b/infra/conf/trojan.go index 673a24757..e9e23c61e 100644 --- a/infra/conf/trojan.go +++ b/infra/conf/trojan.go @@ -144,7 +144,7 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) { switch fb.Dest[0] { case '@', '/': fb.Type = "unix" - if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && runtime.GOOS == "linux" { + if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") { fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy copy(fullAddr, fb.Dest[1:]) fb.Dest = string(fullAddr) diff --git a/infra/conf/vless.go b/infra/conf/vless.go index 6ef387d42..df589394f 100644 --- a/infra/conf/vless.go +++ b/infra/conf/vless.go @@ -93,7 +93,7 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) { switch fb.Dest[0] { case '@', '/': fb.Type = "unix" - if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && runtime.GOOS == "linux" { + if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") { fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy copy(fullAddr, fb.Dest[1:]) fb.Dest = string(fullAddr) diff --git a/testing/scenarios/transport_test.go b/testing/scenarios/transport_test.go index b61db43d1..e60c2868e 100644 --- a/testing/scenarios/transport_test.go +++ b/testing/scenarios/transport_test.go @@ -136,8 +136,8 @@ func TestHTTPConnectionHeader(t *testing.T) { } func TestDomainSocket(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Not supported on windows") + if runtime.GOOS == "windows" || runtime.GOOS == "android" { + t.Skip("Not supported on windows and android") return } tcpServer := tcp.Server{ diff --git a/transport/internet/domainsocket/listener_test.go b/transport/internet/domainsocket/listener_test.go index 8ffdc3497..43285898a 100644 --- a/transport/internet/domainsocket/listener_test.go +++ b/transport/internet/domainsocket/listener_test.go @@ -1,4 +1,5 @@ // +build !windows +// +build !android package domainsocket_test diff --git a/transport/internet/system_listener.go b/transport/internet/system_listener.go index e5426b781..48f233ddf 100644 --- a/transport/internet/system_listener.go +++ b/transport/internet/system_listener.go @@ -54,7 +54,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S lc.Control = nil network = addr.Network() address = addr.Name - if runtime.GOOS == "linux" && address[0] == '@' { + if (runtime.GOOS == "linux" || runtime.GOOS == "android") && address[0] == '@' { // linux abstract unix domain socket is lockfree if len(address) > 1 && address[1] == '@' { // but may need padding to work with haproxy