From 8c9722b2a02b19fd83c35c9ae05b2eaecd6181a3 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 26 Jun 2022 20:18:07 +0800 Subject: [PATCH] refactor --- go.mod | 2 +- libv2ray.go | 3 -- interact.go => libv2ray_main.go | 35 ++++++++++++++----- ...nservice_support.go => libv2ray_support.go | 2 +- ...upport_test.go => libv2ray_support_test.go | 2 +- v2logger.go | 31 ---------------- 6 files changed, 30 insertions(+), 45 deletions(-) delete mode 100644 libv2ray.go rename interact.go => libv2ray_main.go (90%) rename VPN/vpnservice_support.go => libv2ray_support.go (99%) rename VPN/vpnservice_support_test.go => libv2ray_support_test.go (99%) delete mode 100644 v2logger.go diff --git a/go.mod b/go.mod index 777b7a0..b2e5803 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/2dust/AndroidLibXrayLite go 1.18 require ( - github.com/xtls/xray-core v1.5.5 + github.com/xtls/xray-core v1.5.8 golang.org/x/mobile v0.0.0-20220414153400-ce6a79cf6a13 golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 ) diff --git a/libv2ray.go b/libv2ray.go deleted file mode 100644 index 8692373..0000000 --- a/libv2ray.go +++ /dev/null @@ -1,3 +0,0 @@ -package libv2ray - -//go:generate make all diff --git a/interact.go b/libv2ray_main.go similarity index 90% rename from interact.go rename to libv2ray_main.go index 5a1930d..2bace1a 100644 --- a/interact.go +++ b/libv2ray_main.go @@ -14,7 +14,6 @@ import ( "sync" "time" - "github.com/2dust/AndroidLibXrayLite/VPN" mobasset "golang.org/x/mobile/asset" v2core "github.com/xtls/xray-core/core" @@ -40,7 +39,7 @@ type V2RayPoint struct { SupportSet V2RayVPNServiceSupportsSet statsManager v2stats.Manager - dialer *VPN.ProtectedDialer + dialer *ProtectedDialer v2rayOP sync.Mutex closeChan chan struct{} @@ -232,7 +231,7 @@ func NewV2RayPoint(s V2RayVPNServiceSupportsSet, adns bool) *V2RayPoint { return v2commlog.NewLogger(createStdoutLogWriter()), nil }) - dialer := VPN.NewPreotectedDialer(s) + dialer := NewPreotectedDialer(s) v2internet.UseAlternativeSystemDialer(dialer) return &V2RayPoint{ SupportSet: s, @@ -241,15 +240,12 @@ func NewV2RayPoint(s V2RayVPNServiceSupportsSet, adns bool) *V2RayPoint { } } -func CheckVersion() int { - return 23 -} - /*CheckVersionX string This func will return libv2ray binding version and V2Ray version used. */ func CheckVersionX() string { - return fmt.Sprintf("Lib v%d, Xray-core v%s", CheckVersion(), v2core.Version()) + var version = 24 + return fmt.Sprintf("Lib v%d, Xray-core v%s", version, v2core.Version()) } func measureInstDelay(ctx context.Context, inst *v2core.Instance) (int64, error) { @@ -286,3 +282,26 @@ func measureInstDelay(ctx context.Context, inst *v2core.Instance) (int64, error) resp.Body.Close() return time.Since(start).Milliseconds(), nil } + +// This struct creates our own log writer without datatime stamp +// As Android adds time stamps on each line +type consoleLogWriter struct { + logger *log.Logger +} + +func (w *consoleLogWriter) Write(s string) error { + w.logger.Print(s) + return nil +} + +func (w *consoleLogWriter) Close() error { + return nil +} + +// This logger won't print data/time stamps +func createStdoutLogWriter() v2commlog.WriterCreator { + return func() v2commlog.Writer { + return &consoleLogWriter{ + logger: log.New(os.Stdout, "", 0)} + } +} \ No newline at end of file diff --git a/VPN/vpnservice_support.go b/libv2ray_support.go similarity index 99% rename from VPN/vpnservice_support.go rename to libv2ray_support.go index e24f768..52e4683 100644 --- a/VPN/vpnservice_support.go +++ b/libv2ray_support.go @@ -1,4 +1,4 @@ -package VPN +package libv2ray import ( "context" diff --git a/VPN/vpnservice_support_test.go b/libv2ray_support_test.go similarity index 99% rename from VPN/vpnservice_support_test.go rename to libv2ray_support_test.go index 7e2f740..d083777 100644 --- a/VPN/vpnservice_support_test.go +++ b/libv2ray_support_test.go @@ -1,4 +1,4 @@ -package VPN +package libv2ray import ( "bufio" diff --git a/v2logger.go b/v2logger.go deleted file mode 100644 index 3ab232b..0000000 --- a/v2logger.go +++ /dev/null @@ -1,31 +0,0 @@ -package libv2ray - -import ( - "log" - "os" - - v2commlog "github.com/xtls/xray-core/common/log" -) - -// This struct creates our own log writer without datatime stamp -// As Android adds time stamps on each line -type consoleLogWriter struct { - logger *log.Logger -} - -func (w *consoleLogWriter) Write(s string) error { - w.logger.Print(s) - return nil -} - -func (w *consoleLogWriter) Close() error { - return nil -} - -// This logger won't print data/time stamps -func createStdoutLogWriter() v2commlog.WriterCreator { - return func() v2commlog.Writer { - return &consoleLogWriter{ - logger: log.New(os.Stdout, "", 0)} - } -}