Skip to content

Commit

Permalink
v3.7.0 release
Browse files Browse the repository at this point in the history
1. Fix a bug that `mita apply config` command can fail when there are too many users (bug #166).
2. When proxy is running, `mieru check update` will use proxy to access GitHub API.
3. When proxy is started, mieru client may check for updates.
  • Loading branch information
enfein committed Oct 12, 2024
1 parent d035bcc commit 04bab7f
Show file tree
Hide file tree
Showing 27 changed files with 855 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
go-version-file: go.mod
- name: Create vendor directory
run: make vendor
- name: Run benchmark
run: make bench
- name: Build binaries
run: make build
- name: Upload artifacts
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.0"
VERSION="3.7.0"

# Build binaries and installation packages.
.PHONY: build
Expand Down Expand Up @@ -428,6 +428,11 @@ protobuf:
--proto_path="${ROOT}/pkg" \
"${ROOT}/pkg/metrics/proto/metrics.proto"

PATH=${PATH}:"${ROOT}/tools/build" ${ROOT}/tools/build/protoc -I="${ROOT}/pkg/version/updater/proto" \
--go_out="${ROOT}/pkg/version/updater" --go_opt=module="github.com/enfein/mieru/v3/pkg/version/updater" \
--proto_path="${ROOT}/pkg" \
"${ROOT}/pkg/version/updater/proto/history.proto"

# Package source code.
.PHONY: src
src: clean
Expand Down
2 changes: 1 addition & 1 deletion build/package/mieru/amd64/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: mieru
Version: 3.6.0
Version: 3.7.0
Section: net
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion build/package/mieru/amd64/rpm/mieru.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: mieru
Version: 3.6.0
Version: 3.7.0
Release: 1%{?dist}
Summary: Mieru proxy client
License: GPLv3+
Expand Down
2 changes: 1 addition & 1 deletion build/package/mieru/arm64/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: mieru
Version: 3.6.0
Version: 3.7.0
Section: net
Priority: optional
Architecture: arm64
Expand Down
2 changes: 1 addition & 1 deletion build/package/mieru/arm64/rpm/mieru.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: mieru
Version: 3.6.0
Version: 3.7.0
Release: 1%{?dist}
Summary: Mieru proxy client
License: GPLv3+
Expand Down
2 changes: 1 addition & 1 deletion build/package/mita/amd64/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: mita
Version: 3.6.0
Version: 3.7.0
Section: net
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion build/package/mita/amd64/rpm/mita.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: mita
Version: 3.6.0
Version: 3.7.0
Release: 1%{?dist}
Summary: Mieru proxy server
License: GPLv3+
Expand Down
2 changes: 1 addition & 1 deletion build/package/mita/arm64/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: mita
Version: 3.6.0
Version: 3.7.0
Section: net
Priority: optional
Architecture: arm64
Expand Down
2 changes: 1 addition & 1 deletion build/package/mita/arm64/rpm/mita.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: mita
Version: 3.6.0
Version: 3.7.0
Release: 1%{?dist}
Summary: Mieru proxy server
License: GPLv3+
Expand Down
16 changes: 8 additions & 8 deletions docs/server-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.0/mita_3.6.0_amd64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita_3.7.0_amd64.deb

# Debian / Ubuntu - ARM 64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita_3.6.0_arm64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita_3.7.0_arm64.deb

# RedHat / CentOS / Rocky Linux - X86_64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita-3.6.0-1.x86_64.rpm
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita-3.7.0-1.x86_64.rpm

# RedHat / CentOS / Rocky Linux - ARM 64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita-3.6.0-1.aarch64.rpm
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita-3.7.0-1.aarch64.rpm
```

## Install mita package

```sh
# Debian / Ubuntu - X86_64
sudo dpkg -i mita_3.6.0_amd64.deb
sudo dpkg -i mita_3.7.0_amd64.deb

# Debian / Ubuntu - ARM 64
sudo dpkg -i mita_3.6.0_arm64.deb
sudo dpkg -i mita_3.7.0_arm64.deb

# RedHat / CentOS / Rocky Linux - X86_64
sudo rpm -Uvh --force mita-3.6.0-1.x86_64.rpm
sudo rpm -Uvh --force mita-3.7.0-1.x86_64.rpm

# RedHat / CentOS / Rocky Linux - ARM 64
sudo rpm -Uvh --force mita-3.6.0-1.aarch64.rpm
sudo rpm -Uvh --force mita-3.7.0-1.aarch64.rpm
```

Those instructions can also be used to upgrade the version of mita software package.
Expand Down
16 changes: 8 additions & 8 deletions docs/server-install.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@

```sh
# Debian / Ubuntu - X86_64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita_3.6.0_amd64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita_3.7.0_amd64.deb

# Debian / Ubuntu - ARM 64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita_3.6.0_arm64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita_3.7.0_arm64.deb

# RedHat / CentOS / Rocky Linux - X86_64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita-3.6.0-1.x86_64.rpm
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita-3.7.0-1.x86_64.rpm

# RedHat / CentOS / Rocky Linux - ARM 64
curl -LSO https://github.com/enfein/mieru/releases/download/v3.6.0/mita-3.6.0-1.aarch64.rpm
curl -LSO https://github.com/enfein/mieru/releases/download/v3.7.0/mita-3.7.0-1.aarch64.rpm
```

## 安装 mita 软件包

```sh
# Debian / Ubuntu - X86_64
sudo dpkg -i mita_3.6.0_amd64.deb
sudo dpkg -i mita_3.7.0_amd64.deb

# Debian / Ubuntu - ARM 64
sudo dpkg -i mita_3.6.0_arm64.deb
sudo dpkg -i mita_3.7.0_arm64.deb

# RedHat / CentOS / Rocky Linux - X86_64
sudo rpm -Uvh --force mita-3.6.0-1.x86_64.rpm
sudo rpm -Uvh --force mita-3.7.0-1.x86_64.rpm

# RedHat / CentOS / Rocky Linux - ARM 64
sudo rpm -Uvh --force mita-3.6.0-1.aarch64.rpm
sudo rpm -Uvh --force mita-3.7.0-1.aarch64.rpm
```

上述指令也可以用来升级 mita 软件包的版本。
Expand Down
29 changes: 20 additions & 9 deletions pkg/appctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/enfein/mieru/v3/pkg/stderror"
"github.com/enfein/mieru/v3/pkg/util"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -163,7 +164,7 @@ func NewClientLifecycleService() *clientLifecycleService {

// NewClientLifecycleRPCClient creates a new ClientLifecycleService RPC client.
// It loads client config to find the server address.
func NewClientLifecycleRPCClient(ctx context.Context) (appctlgrpc.ClientLifecycleServiceClient, error) {
func NewClientLifecycleRPCClient() (appctlgrpc.ClientLifecycleServiceClient, error) {
config, err := LoadClientConfig()
if err != nil {
return nil, fmt.Errorf("LoadClientConfig() failed: %w", err)
Expand All @@ -175,17 +176,18 @@ func NewClientLifecycleRPCClient(ctx context.Context) (appctlgrpc.ClientLifecycl
return nil, fmt.Errorf("RPC port number %d is invalid", config.GetRpcPort())
}
rpcAddr := "localhost:" + strconv.Itoa(int(config.GetRpcPort()))
return newClientLifecycleRPCClient(ctx, rpcAddr)
return newClientLifecycleRPCClient(rpcAddr)
}

// IsClientDaemonRunning detects if client daemon is running by using ClientLifecycleService.GetStatus() RPC.
// IsClientDaemonRunning detects if client daemon is running by using
// ClientLifecycleService.GetStatus() RPC.
func IsClientDaemonRunning(ctx context.Context) error {
timedctx, cancelFunc := context.WithTimeout(ctx, RPCTimeout)
defer cancelFunc()
client, err := NewClientLifecycleRPCClient(timedctx)
client, err := NewClientLifecycleRPCClient()
if err != nil {
return fmt.Errorf("NewClientLifecycleRPCClient() failed: %w", err)
}
timedctx, cancelFunc := context.WithTimeout(ctx, RPCTimeout)
defer cancelFunc()
if _, err = client.GetStatus(timedctx, &pb.Empty{}); err != nil {
return fmt.Errorf("ClientLifecycleService.GetStatus() failed: %w", err)
}
Expand Down Expand Up @@ -489,12 +491,21 @@ func GetActiveProfileFromConfig(config *pb.ClientConfig, name string) (*pb.Clien
return nil, fmt.Errorf("profile %q is not found", name)
}

// ClientUpdaterHistoryPath returns the file path to retrieve
// client updater history.
func ClientUpdaterHistoryPath() (string, error) {
if err := prepareClientConfigDir(); err != nil {
return "", err
}
return filepath.Join(cachedClientConfigDir, "client.updater.pb"), nil
}

// newClientLifecycleRPCClient creates a new ClientLifecycleService RPC client
// and connects to the given server address.
func newClientLifecycleRPCClient(ctx context.Context, serverAddr string) (appctlgrpc.ClientLifecycleServiceClient, error) {
conn, err := grpc.DialContext(ctx, serverAddr, grpc.WithInsecure())
func newClientLifecycleRPCClient(serverAddr string) (appctlgrpc.ClientLifecycleServiceClient, error) {
conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxRecvMsgSize)))
if err != nil {
return nil, fmt.Errorf("grpc.DialContext() failed: %w", err)
return nil, fmt.Errorf("grpc.NewClient() failed: %w", err)
}
return appctlgrpc.NewClientLifecycleServiceClient(conn), nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/appctl/rpc_timeout.go → pkg/appctl/rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package appctl

import (
"math"
"time"
)

Expand All @@ -24,4 +25,8 @@ const (
// We use a very large timeout that works for embedded computer
// and anti-virus sandbox environment.
RPCTimeout = time.Second * 10

// MaxRecvMsgSize is the maximum message size in bytes that
// can be received in gRPC.
MaxRecvMsgSize = math.MaxInt32
)
13 changes: 5 additions & 8 deletions pkg/appctl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/enfein/mieru/v3/pkg/stderror"
"github.com/enfein/mieru/v3/pkg/util"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -288,11 +289,9 @@ func NewServerLifecycleService() *serverLifecycleService {
// NewServerLifecycleRPCClient creates a new ServerLifecycleService RPC client.
func NewServerLifecycleRPCClient() (appctlgrpc.ServerLifecycleServiceClient, error) {
rpcAddr := "unix://" + ServerUDS()
timedctx, cancelFunc := context.WithTimeout(context.Background(), RPCTimeout)
defer cancelFunc()
conn, err := grpc.DialContext(timedctx, rpcAddr, grpc.WithInsecure())
conn, err := grpc.NewClient(rpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxRecvMsgSize)))
if err != nil {
return nil, fmt.Errorf("grpc.DialContext() failed: %w", err)
return nil, fmt.Errorf("grpc.NewClient() failed: %w", err)
}
return appctlgrpc.NewServerLifecycleServiceClient(conn), nil
}
Expand Down Expand Up @@ -329,11 +328,9 @@ func NewServerConfigService() *serverConfigService {
// NewServerConfigRPCClient creates a new ServerConfigService RPC client.
func NewServerConfigRPCClient() (appctlgrpc.ServerConfigServiceClient, error) {
rpcAddr := "unix://" + ServerUDS()
timedctx, cancelFunc := context.WithTimeout(context.Background(), RPCTimeout)
defer cancelFunc()
conn, err := grpc.DialContext(timedctx, rpcAddr, grpc.WithInsecure())
conn, err := grpc.NewClient(rpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxRecvMsgSize)))
if err != nil {
return nil, fmt.Errorf("grpc.DialContext() failed: %w", err)
return nil, fmt.Errorf("grpc.NewClient() failed: %w", err)
}
return appctlgrpc.NewServerConfigServiceClient(conn), nil
}
Expand Down
65 changes: 62 additions & 3 deletions pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/enfein/mieru/v3/pkg/stderror"
"github.com/enfein/mieru/v3/pkg/util"
"github.com/enfein/mieru/v3/pkg/util/sockopts"
"github.com/enfein/mieru/v3/pkg/version/updater"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -175,7 +176,7 @@ func RegisterClientCommands() {
func(s []string) error {
return unexpectedArgsError(s, 3)
},
checkUpdateFunc,
clientCheckUpdateFunc,
)
RegisterCallback(
[]string{"", "get", "metrics"},
Expand Down Expand Up @@ -382,6 +383,14 @@ var clientStartFunc = func(s []string) error {
} else {
log.Infof("mieru client is started, listening to socks5://127.0.0.1:%d", config.GetSocks5Port())
}

if should, _ := clientShouldCheckUpdate(); should {
msg, _ := clientCheckUpdateAndUpdateHistory(fmt.Sprintf("socks5://127.0.0.1:%d", config.GetSocks5Port()))
if msg != updater.UpToDateMessage {
log.Infof("")
log.Infof(msg)
}
}
return nil
}
time.Sleep(100 * time.Millisecond)
Expand Down Expand Up @@ -444,7 +453,7 @@ var clientRunFunc = func(s []string) error {
if err != nil {
log.Fatalf("listen on RPC address tcp %q failed: %v", rpcAddr, err)
}
grpcServer := grpc.NewServer()
grpcServer := grpc.NewServer(grpc.MaxRecvMsgSize(appctl.MaxRecvMsgSize))
appctl.SetClientRPCServerRef(grpcServer)
appctlgrpc.RegisterClientLifecycleServiceServer(grpcServer, appctl.NewClientLifecycleService())
close(appctl.ClientRPCServerStarted)
Expand Down Expand Up @@ -785,6 +794,29 @@ var clientDeleteSocks5AuthenticationFunc = func(_ []string) error {
return nil
}

var clientCheckUpdateFunc = func(s []string) error {
var socks5ProxyURI string
if err := appctl.IsClientDaemonRunning(context.Background()); err == nil {
// Client is running. Use the socks5 proxy to check update.
config, err := appctl.LoadClientConfig()
if err == nil {
socks5ProxyURI = fmt.Sprintf("socks5://127.0.0.1:%d", config.GetSocks5Port())
}
// Otherwise, sliently drop the error.
}

msg, err := clientCheckUpdateAndUpdateHistory(socks5ProxyURI)
if err != nil {
if socks5ProxyURI == "" {
return fmt.Errorf("check update without proxy failed: %w; please start mieru proxy client and try again", err)
} else {
return fmt.Errorf("check update with proxy %s failed: %w", socks5ProxyURI, err)
}
}
log.Infof("%s", msg)
return nil
}

var clientGetMetricsFunc = func(s []string) error {
ctx, cancelFunc := context.WithTimeout(context.Background(), appctl.RPCTimeout)
defer cancelFunc()
Expand Down Expand Up @@ -921,9 +953,36 @@ func newClientLifecycleRPCClient(ctx context.Context) (client appctlgrpc.ClientL
return nil, false, nil
}
running = true
client, err = appctl.NewClientLifecycleRPCClient(ctx)
client, err = appctl.NewClientLifecycleRPCClient()
if err != nil {
return nil, true, fmt.Errorf(stderror.CreateClientLifecycleRPCClientFailedErr, err)
}
return
}

func clientShouldCheckUpdate() (bool, error) {
historyFile, err := appctl.ClientUpdaterHistoryPath()
if err != nil {
return false, fmt.Errorf("failed to get client updater history file path")
}
h := updater.NewHistory()
if err := h.LoadFrom(historyFile); err != nil {
// History file doesn't exist or is corrupted.
return true, nil
}
return h.ShouldCheckUpdate(), nil
}

func clientCheckUpdateAndUpdateHistory(socks5ProxyURI string) (string, error) {
historyFile, err := appctl.ClientUpdaterHistoryPath()
if err != nil {
return "", fmt.Errorf("failed to get client updater history file path")
}
h := updater.NewHistory()
h.LoadFrom(historyFile) // OK to fail. No side effect.
record, msg, checkErr := updater.CheckUpdate(socks5ProxyURI)
h.Insert(record)
h.Trim()
h.StoreTo(historyFile) // OK to fail.
return msg, checkErr
}
Loading

0 comments on commit 04bab7f

Please sign in to comment.