From 9f6a7bbb59bfe64c56967b9e3a3ed75faf5ee464 Mon Sep 17 00:00:00 2001 From: enfein <83481737+enfein@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:37:51 +0000 Subject: [PATCH] v3.8.4 release 1. Optimize mihomo executable file size. --- .github/workflows/mihomo.yaml | 24 ++++++ Makefile | 2 +- apis/client/mieru.go | 9 ++- .../package/mieru/amd64/debian/DEBIAN/control | 2 +- build/package/mieru/amd64/rpm/mieru.spec | 2 +- .../package/mieru/arm64/debian/DEBIAN/control | 2 +- build/package/mieru/arm64/rpm/mieru.spec | 2 +- .../package/mita/amd64/debian/DEBIAN/control | 2 +- build/package/mita/amd64/rpm/mita.spec | 2 +- .../package/mita/arm64/debian/DEBIAN/control | 2 +- build/package/mita/arm64/rpm/mita.spec | 2 +- docs/server-install.md | 16 ++-- docs/server-install.zh_CN.md | 16 ++-- pkg/appctl/appctlcommon/client.go | 76 +++++++++++++++++++ pkg/appctl/appctlcommon/doc.go | 19 +++++ pkg/appctl/{ => appctlcommon}/port_binding.go | 2 +- pkg/appctl/client.go | 57 +------------- pkg/appctl/server.go | 5 +- pkg/cli/client.go | 3 +- pkg/version/current.go | 2 +- 20 files changed, 159 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/mihomo.yaml create mode 100644 pkg/appctl/appctlcommon/client.go create mode 100644 pkg/appctl/appctlcommon/doc.go rename pkg/appctl/{ => appctlcommon}/port_binding.go (99%) diff --git a/.github/workflows/mihomo.yaml b/.github/workflows/mihomo.yaml new file mode 100644 index 00000000..73b7a968 --- /dev/null +++ b/.github/workflows/mihomo.yaml @@ -0,0 +1,24 @@ +name: 'mihomo test' +on: [workflow_dispatch] +jobs: + run-test: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Check out mieru repository code + uses: actions/checkout@v4 + with: + path: mieru + - name: Check out mihomo repository code + uses: actions/checkout@v4 + with: + ref: Alpha + path: mihomo + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Update mieru reference + run: echo "replace github.com/enfein/mieru/v3 => ../mieru" >> go.mod + - name: Build mihomo + run: make linux-amd64-compatible diff --git a/Makefile b/Makefile index 2440cb2a..e810daa7 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ PROJECT_NAME=$(shell basename "${ROOT}") # - pkg/version/current.go # # Use `tools/bump_version.sh` script to change all those files at one shot. -VERSION="3.8.3" +VERSION="3.8.4" # Build binaries and installation packages. .PHONY: build diff --git a/apis/client/mieru.go b/apis/client/mieru.go index 143c2f64..98a786d7 100644 --- a/apis/client/mieru.go +++ b/apis/client/mieru.go @@ -29,7 +29,7 @@ import ( apicommon "github.com/enfein/mieru/v3/apis/common" "github.com/enfein/mieru/v3/apis/constant" "github.com/enfein/mieru/v3/apis/model" - "github.com/enfein/mieru/v3/pkg/appctl" + "github.com/enfein/mieru/v3/pkg/appctl/appctlcommon" "github.com/enfein/mieru/v3/pkg/appctl/appctlpb" "github.com/enfein/mieru/v3/pkg/cipher" "github.com/enfein/mieru/v3/pkg/common" @@ -38,6 +38,9 @@ import ( "github.com/enfein/mieru/v3/pkg/stderror" ) +// This package should not depends on github.com/enfein/mieru/v3/pkg/appctl, +// which introduces gRPC dependency. + // mieruClient is the official implementation of mieru client APIs. type mieruClient struct { initTask sync.Once @@ -80,7 +83,7 @@ func (mc *mieruClient) Store(config *ClientConfig) error { if mc.running { return ErrStoreClientConfigAfterStart } - if err := appctl.ValidateClientConfigSingleProfile(config.Profile); err != nil { + if err := appctlcommon.ValidateClientConfigSingleProfile(config.Profile); err != nil { return fmt.Errorf("%w: %s", ErrInvalidConfigConfig, err.Error()) } mc.config = config @@ -168,7 +171,7 @@ func (mc *mieruClient) Start() error { return fmt.Errorf(stderror.ParseIPFailed) } } - portBindings, err := appctl.FlatPortBindings(serverInfo.GetPortBindings()) + portBindings, err := appctlcommon.FlatPortBindings(serverInfo.GetPortBindings()) if err != nil { return fmt.Errorf(stderror.InvalidPortBindingsErr, err) } diff --git a/build/package/mieru/amd64/debian/DEBIAN/control b/build/package/mieru/amd64/debian/DEBIAN/control index 33825b35..18cec8cc 100755 --- a/build/package/mieru/amd64/debian/DEBIAN/control +++ b/build/package/mieru/amd64/debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: mieru -Version: 3.8.3 +Version: 3.8.4 Section: net Priority: optional Architecture: amd64 diff --git a/build/package/mieru/amd64/rpm/mieru.spec b/build/package/mieru/amd64/rpm/mieru.spec index 5b176ffc..f996dc8f 100644 --- a/build/package/mieru/amd64/rpm/mieru.spec +++ b/build/package/mieru/amd64/rpm/mieru.spec @@ -1,5 +1,5 @@ Name: mieru -Version: 3.8.3 +Version: 3.8.4 Release: 1%{?dist} Summary: Mieru proxy client License: GPLv3+ diff --git a/build/package/mieru/arm64/debian/DEBIAN/control b/build/package/mieru/arm64/debian/DEBIAN/control index ad056bd6..85748cc2 100755 --- a/build/package/mieru/arm64/debian/DEBIAN/control +++ b/build/package/mieru/arm64/debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: mieru -Version: 3.8.3 +Version: 3.8.4 Section: net Priority: optional Architecture: arm64 diff --git a/build/package/mieru/arm64/rpm/mieru.spec b/build/package/mieru/arm64/rpm/mieru.spec index 5b176ffc..f996dc8f 100644 --- a/build/package/mieru/arm64/rpm/mieru.spec +++ b/build/package/mieru/arm64/rpm/mieru.spec @@ -1,5 +1,5 @@ Name: mieru -Version: 3.8.3 +Version: 3.8.4 Release: 1%{?dist} Summary: Mieru proxy client License: GPLv3+ diff --git a/build/package/mita/amd64/debian/DEBIAN/control b/build/package/mita/amd64/debian/DEBIAN/control index 53d81e74..457be796 100755 --- a/build/package/mita/amd64/debian/DEBIAN/control +++ b/build/package/mita/amd64/debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: mita -Version: 3.8.3 +Version: 3.8.4 Section: net Priority: optional Architecture: amd64 diff --git a/build/package/mita/amd64/rpm/mita.spec b/build/package/mita/amd64/rpm/mita.spec index 1278c3f1..cd78da6a 100644 --- a/build/package/mita/amd64/rpm/mita.spec +++ b/build/package/mita/amd64/rpm/mita.spec @@ -1,5 +1,5 @@ Name: mita -Version: 3.8.3 +Version: 3.8.4 Release: 1%{?dist} Summary: Mieru proxy server License: GPLv3+ diff --git a/build/package/mita/arm64/debian/DEBIAN/control b/build/package/mita/arm64/debian/DEBIAN/control index cb0d4aa6..62573062 100755 --- a/build/package/mita/arm64/debian/DEBIAN/control +++ b/build/package/mita/arm64/debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: mita -Version: 3.8.3 +Version: 3.8.4 Section: net Priority: optional Architecture: arm64 diff --git a/build/package/mita/arm64/rpm/mita.spec b/build/package/mita/arm64/rpm/mita.spec index 5a82869b..9678a70f 100644 --- a/build/package/mita/arm64/rpm/mita.spec +++ b/build/package/mita/arm64/rpm/mita.spec @@ -1,5 +1,5 @@ Name: mita -Version: 3.8.3 +Version: 3.8.4 Release: 1%{?dist} Summary: Mieru proxy server License: GPLv3+ diff --git a/docs/server-install.md b/docs/server-install.md index d5dd1496..1b401e0b 100644 --- a/docs/server-install.md +++ b/docs/server-install.md @@ -8,32 +8,32 @@ Before installation and configuration, connect to the server via SSH and then ex ```sh # Debian / Ubuntu - X86_64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita_3.8.3_amd64.deb +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita_3.8.4_amd64.deb # Debian / Ubuntu - ARM 64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita_3.8.3_arm64.deb +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita_3.8.4_arm64.deb # RedHat / CentOS / Rocky Linux - X86_64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita-3.8.3-1.x86_64.rpm +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita-3.8.4-1.x86_64.rpm # RedHat / CentOS / Rocky Linux - ARM 64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita-3.8.3-1.aarch64.rpm +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita-3.8.4-1.aarch64.rpm ``` ## Install mita package ```sh # Debian / Ubuntu - X86_64 -sudo dpkg -i mita_3.8.3_amd64.deb +sudo dpkg -i mita_3.8.4_amd64.deb # Debian / Ubuntu - ARM 64 -sudo dpkg -i mita_3.8.3_arm64.deb +sudo dpkg -i mita_3.8.4_arm64.deb # RedHat / CentOS / Rocky Linux - X86_64 -sudo rpm -Uvh --force mita-3.8.3-1.x86_64.rpm +sudo rpm -Uvh --force mita-3.8.4-1.x86_64.rpm # RedHat / CentOS / Rocky Linux - ARM 64 -sudo rpm -Uvh --force mita-3.8.3-1.aarch64.rpm +sudo rpm -Uvh --force mita-3.8.4-1.aarch64.rpm ``` Those instructions can also be used to upgrade the version of mita software package. diff --git a/docs/server-install.zh_CN.md b/docs/server-install.zh_CN.md index b809e94b..f84f71f6 100644 --- a/docs/server-install.zh_CN.md +++ b/docs/server-install.zh_CN.md @@ -8,32 +8,32 @@ ```sh # Debian / Ubuntu - X86_64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita_3.8.3_amd64.deb +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita_3.8.4_amd64.deb # Debian / Ubuntu - ARM 64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita_3.8.3_arm64.deb +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita_3.8.4_arm64.deb # RedHat / CentOS / Rocky Linux - X86_64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita-3.8.3-1.x86_64.rpm +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita-3.8.4-1.x86_64.rpm # RedHat / CentOS / Rocky Linux - ARM 64 -curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.3/mita-3.8.3-1.aarch64.rpm +curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.4/mita-3.8.4-1.aarch64.rpm ``` ## 安装 mita 软件包 ```sh # Debian / Ubuntu - X86_64 -sudo dpkg -i mita_3.8.3_amd64.deb +sudo dpkg -i mita_3.8.4_amd64.deb # Debian / Ubuntu - ARM 64 -sudo dpkg -i mita_3.8.3_arm64.deb +sudo dpkg -i mita_3.8.4_arm64.deb # RedHat / CentOS / Rocky Linux - X86_64 -sudo rpm -Uvh --force mita-3.8.3-1.x86_64.rpm +sudo rpm -Uvh --force mita-3.8.4-1.x86_64.rpm # RedHat / CentOS / Rocky Linux - ARM 64 -sudo rpm -Uvh --force mita-3.8.3-1.aarch64.rpm +sudo rpm -Uvh --force mita-3.8.4-1.aarch64.rpm ``` 上述指令也可以用来升级 mita 软件包的版本。 diff --git a/pkg/appctl/appctlcommon/client.go b/pkg/appctl/appctlcommon/client.go new file mode 100644 index 00000000..a655d77f --- /dev/null +++ b/pkg/appctl/appctlcommon/client.go @@ -0,0 +1,76 @@ +// Copyright (C) 2024 mieru authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package appctlcommon + +import ( + "fmt" + "net" + + pb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb" +) + +// ValidateClientConfigSingleProfile validates +// a single client config profile. +// +// It validates +// 1. profile name is not empty +// 2. user name is not empty +// 3. user has either a password or a hashed password +// 4. user has no quota +// 5. it has at least 1 server, and for each server +// 5.1. the server has either IP address or domain name +// 5.2. if set, server's IP address is parsable +// 5.3. the server has at least 1 port binding, and all port bindings are valid +// 6. if set, MTU is valid +func ValidateClientConfigSingleProfile(profile *pb.ClientProfile) error { + name := profile.GetProfileName() + if name == "" { + return fmt.Errorf("profile name is not set") + } + user := profile.GetUser() + if user.GetName() == "" { + return fmt.Errorf("user name is not set") + } + if user.GetPassword() == "" && user.GetHashedPassword() == "" { + return fmt.Errorf("user password is not set") + } + if len(user.GetQuotas()) != 0 { + return fmt.Errorf("user quota is not supported by proxy client") + } + servers := profile.GetServers() + if len(servers) == 0 { + return fmt.Errorf("servers are not set") + } + for _, server := range servers { + if server.GetIpAddress() == "" && server.GetDomainName() == "" { + return fmt.Errorf("neither server IP address nor domain name is set") + } + if server.GetIpAddress() != "" && net.ParseIP(server.GetIpAddress()) == nil { + return fmt.Errorf("failed to parse IP address %q", server.GetIpAddress()) + } + portBindings := server.GetPortBindings() + if len(portBindings) == 0 { + return fmt.Errorf("server port binding is not set") + } + if _, err := FlatPortBindings(portBindings); err != nil { + return err + } + } + if profile.GetMtu() != 0 && (profile.GetMtu() < 1280 || profile.GetMtu() > 1500) { + return fmt.Errorf("MTU value %d is out of range, valid range is [1280, 1500]", profile.GetMtu()) + } + return nil +} diff --git a/pkg/appctl/appctlcommon/doc.go b/pkg/appctl/appctlcommon/doc.go new file mode 100644 index 00000000..46a861b5 --- /dev/null +++ b/pkg/appctl/appctlcommon/doc.go @@ -0,0 +1,19 @@ +// Copyright (C) 2024 mieru authors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// Package appctlcommon contains selected functions +// that don't have gRPC dependency. This helps to remove gRPC dependency +// from API consumers. +package appctlcommon diff --git a/pkg/appctl/port_binding.go b/pkg/appctl/appctlcommon/port_binding.go similarity index 99% rename from pkg/appctl/port_binding.go rename to pkg/appctl/appctlcommon/port_binding.go index 9466d750..e8814f59 100644 --- a/pkg/appctl/port_binding.go +++ b/pkg/appctl/appctlcommon/port_binding.go @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package appctl +package appctlcommon import ( "fmt" diff --git a/pkg/appctl/client.go b/pkg/appctl/client.go index e9bd0d06..ea819e4f 100644 --- a/pkg/appctl/client.go +++ b/pkg/appctl/client.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "net" "os" "path/filepath" "sort" @@ -27,6 +26,7 @@ import ( "sync" "sync/atomic" + "github.com/enfein/mieru/v3/pkg/appctl/appctlcommon" "github.com/enfein/mieru/v3/pkg/appctl/appctlgrpc" pb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb" "github.com/enfein/mieru/v3/pkg/common" @@ -358,7 +358,7 @@ func DeleteClientConfigProfile(profileName string) error { // 3. for each socks5 authentication, the user and password are not empty func ValidateClientConfigPatch(patch *pb.ClientConfig) error { for _, profile := range patch.GetProfiles() { - if err := ValidateClientConfigSingleProfile(profile); err != nil { + if err := appctlcommon.ValidateClientConfigSingleProfile(profile); err != nil { return err } } @@ -373,59 +373,6 @@ func ValidateClientConfigPatch(patch *pb.ClientConfig) error { return nil } -// ValidateClientConfigSingleProfile validates -// a single client config profile. -// -// It validates -// 1. profile name is not empty -// 2. user name is not empty -// 3. user has either a password or a hashed password -// 4. user has no quota -// 5. it has at least 1 server, and for each server -// 5.1. the server has either IP address or domain name -// 5.2. if set, server's IP address is parsable -// 5.3. the server has at least 1 port binding, and all port bindings are valid -// 6. if set, MTU is valid -func ValidateClientConfigSingleProfile(profile *pb.ClientProfile) error { - name := profile.GetProfileName() - if name == "" { - return fmt.Errorf("profile name is not set") - } - user := profile.GetUser() - if user.GetName() == "" { - return fmt.Errorf("user name is not set") - } - if user.GetPassword() == "" && user.GetHashedPassword() == "" { - return fmt.Errorf("user password is not set") - } - if len(user.GetQuotas()) != 0 { - return fmt.Errorf("user quota is not supported by proxy client") - } - servers := profile.GetServers() - if len(servers) == 0 { - return fmt.Errorf("servers are not set") - } - for _, server := range servers { - if server.GetIpAddress() == "" && server.GetDomainName() == "" { - return fmt.Errorf("neither server IP address nor domain name is set") - } - if server.GetIpAddress() != "" && net.ParseIP(server.GetIpAddress()) == nil { - return fmt.Errorf("failed to parse IP address %q", server.GetIpAddress()) - } - portBindings := server.GetPortBindings() - if len(portBindings) == 0 { - return fmt.Errorf("server port binding is not set") - } - if _, err := FlatPortBindings(portBindings); err != nil { - return err - } - } - if profile.GetMtu() != 0 && (profile.GetMtu() < 1280 || profile.GetMtu() > 1500) { - return fmt.Errorf("MTU value %d is out of range, valid range is [1280, 1500]", profile.GetMtu()) - } - return nil -} - // ValidateFullClientConfig validates the full client config. // // In addition to ValidateClientConfigPatch, it also validates: diff --git a/pkg/appctl/server.go b/pkg/appctl/server.go index 50ccbf42..96e3db13 100644 --- a/pkg/appctl/server.go +++ b/pkg/appctl/server.go @@ -27,6 +27,7 @@ import ( "sync/atomic" "time" + "github.com/enfein/mieru/v3/pkg/appctl/appctlcommon" "github.com/enfein/mieru/v3/pkg/appctl/appctlgrpc" pb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb" "github.com/enfein/mieru/v3/pkg/common" @@ -551,7 +552,7 @@ func DeleteServerUsers(names []string) error { // 5.3. the action must be "PROXY" // 5.4. the proxy name is defined func ValidateServerConfigPatch(patch *pb.ServerConfig) error { - if _, err := FlatPortBindings(patch.GetPortBindings()); err != nil { + if _, err := appctlcommon.FlatPortBindings(patch.GetPortBindings()); err != nil { return err } for _, user := range patch.GetUsers() { @@ -657,7 +658,7 @@ func PortBindingsToUnderlayProperties(portBindings []*pb.PortBinding, mtu int) ( if listenIP == nil { return endpoints, fmt.Errorf(stderror.ParseIPFailed) } - portBindings, err := FlatPortBindings(portBindings) + portBindings, err := appctlcommon.FlatPortBindings(portBindings) if err != nil { return endpoints, fmt.Errorf(stderror.InvalidPortBindingsErr, err) } diff --git a/pkg/cli/client.go b/pkg/cli/client.go index ee6de0c4..31e4bcdc 100644 --- a/pkg/cli/client.go +++ b/pkg/cli/client.go @@ -34,6 +34,7 @@ import ( apicommon "github.com/enfein/mieru/v3/apis/common" "github.com/enfein/mieru/v3/apis/constant" "github.com/enfein/mieru/v3/pkg/appctl" + "github.com/enfein/mieru/v3/pkg/appctl/appctlcommon" "github.com/enfein/mieru/v3/pkg/appctl/appctlgrpc" "github.com/enfein/mieru/v3/pkg/appctl/appctlpb" "github.com/enfein/mieru/v3/pkg/cipher" @@ -533,7 +534,7 @@ var clientRunFunc = func(s []string) error { return fmt.Errorf(stderror.ParseIPFailed) } } - portBindings, err := appctl.FlatPortBindings(serverInfo.GetPortBindings()) + portBindings, err := appctlcommon.FlatPortBindings(serverInfo.GetPortBindings()) if err != nil { return fmt.Errorf(stderror.InvalidPortBindingsErr, err) } diff --git a/pkg/version/current.go b/pkg/version/current.go index 324bd4c4..9b02f564 100644 --- a/pkg/version/current.go +++ b/pkg/version/current.go @@ -16,5 +16,5 @@ package version const ( - AppVersion = "3.8.3" + AppVersion = "3.8.4" )