Skip to content

Commit

Permalink
v3.8.0 release
Browse files Browse the repository at this point in the history
1. Allow applications to read data after network connection is closed (issue #168).
2. Update dependency versions.

Breaking change: the MTU value in client and server configuration now represent
the maximum transmission unit in UDP layer or nested network connection, rather
than in data-link layer. We don't recommend setting MTU value bigger than 1440.
TCP protocol is not affected.
  • Loading branch information
enfein committed Nov 13, 2024
1 parent 1cca911 commit cc3f4c7
Show file tree
Hide file tree
Showing 30 changed files with 440 additions and 453 deletions.
2 changes: 1 addition & 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.7.0"
VERSION="3.8.0"

# Build binaries and installation packages.
.PHONY: build
Expand Down
4 changes: 3 additions & 1 deletion apis/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"net"

apicommon "github.com/enfein/mieru/v3/apis/common"
"github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
)

Expand Down Expand Up @@ -79,7 +80,8 @@ type ClientNetworkService interface {

// ClientConfig stores proxy client configuration.
type ClientConfig struct {
Profile *appctlpb.ClientProfile
Profile *appctlpb.ClientProfile
Resolver apicommon.DNSResolver
}

// NewClient creates a blank mieru client with no client config.
Expand Down
58 changes: 44 additions & 14 deletions apis/client/mieru.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"time"

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"
Expand Down Expand Up @@ -97,6 +98,15 @@ func (mc *mieruClient) Start() error {
mc.mux = protocol.NewMux(true)
activeProfile := mc.config.Profile

// Set DNS resolver.
var resolver apicommon.DNSResolver
if mc.config.Resolver != nil {
resolver = mc.config.Resolver
} else {
resolver = &net.Resolver{} // Default DNS resolver.
}
mc.mux.SetResolver(resolver)

// Set user name and password.
user := activeProfile.GetUser()
var hashedPassword []byte
Expand Down Expand Up @@ -130,16 +140,19 @@ func (mc *mieruClient) Start() error {
mtu = int(activeProfile.GetMtu())
}
endpoints := make([]protocol.UnderlayProperties, 0)
resolver := &common.DNSResolver{}
for _, serverInfo := range activeProfile.GetServers() {
var proxyHost string
var proxyIP net.IP
if serverInfo.GetDomainName() != "" {
proxyHost = serverInfo.GetDomainName()
proxyIP, err = resolver.LookupIP(context.Background(), proxyHost)
proxyIPs, err := resolver.LookupIP(context.Background(), "ip", proxyHost)
if err != nil {
return fmt.Errorf(stderror.LookupIPFailedErr, err)
}
if len(proxyIPs) == 0 {
return fmt.Errorf(stderror.IPAddressNotFound, proxyHost)
}
proxyIP = proxyIPs[0]
} else {
proxyHost = serverInfo.GetIpAddress()
proxyIP = net.ParseIP(proxyHost)
Expand Down Expand Up @@ -197,14 +210,8 @@ func (mc *mieruClient) DialContext(ctx context.Context, addr net.Addr) (net.Conn

// Check destination address.
var netAddrSpec model.NetAddrSpec
if nas, ok := addr.(model.NetAddrSpec); ok {
netAddrSpec = nas
} else if nas, ok := addr.(*model.NetAddrSpec); ok {
netAddrSpec = *nas
} else {
if err := netAddrSpec.From(addr); err != nil {
return nil, fmt.Errorf("invalid destination address: %w", err)
}
if err := netAddrSpec.From(addr); err != nil {
return nil, fmt.Errorf("invalid destination address: %w", err)
}
if !strings.HasPrefix(netAddrSpec.Network(), "tcp") {
return nil, fmt.Errorf("only tcp network is supported")
Expand All @@ -214,6 +221,33 @@ func (mc *mieruClient) DialContext(ctx context.Context, addr net.Addr) (net.Conn
if err != nil {
return nil, err
}
return mc.dialPostHandshake(conn, netAddrSpec)
}

func (mc *mieruClient) DialContextWithConn(ctx context.Context, conn net.Conn, addr net.Addr) (net.Conn, error) {
mc.mu.RLock()
defer mc.mu.RUnlock()
if !mc.running {
return nil, ErrClientIsNotRunning
}

// Check destination address.
var netAddrSpec model.NetAddrSpec
if err := netAddrSpec.From(addr); err != nil {
return nil, fmt.Errorf("invalid destination address: %w", err)
}
if !strings.HasPrefix(netAddrSpec.Network(), "tcp") {
return nil, fmt.Errorf("only tcp network is supported")
}

subConn, err := mc.mux.DialContextWithConn(ctx, conn)
if err != nil {
return nil, err
}
return mc.dialPostHandshake(subConn, netAddrSpec)
}

func (mc *mieruClient) dialPostHandshake(conn net.Conn, netAddrSpec model.NetAddrSpec) (net.Conn, error) {
var req bytes.Buffer
req.Write([]byte{constant.Socks5Version, constant.Socks5ConnectCmd, 0})
if err := netAddrSpec.WriteToSocks5(&req); err != nil {
Expand Down Expand Up @@ -241,7 +275,3 @@ func (mc *mieruClient) DialContext(ctx context.Context, addr net.Addr) (net.Conn
}
return conn, nil
}

func (mc *mieruClient) DialContextWithConn(ctx context.Context, conn net.Conn, addr net.Addr) (net.Conn, error) {
return nil, fmt.Errorf("not implemented")
}
9 changes: 9 additions & 0 deletions apis/common/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ func ResolveUDPAddr(r DNSResolver, network, address string) (*net.UDPAddr, error

return &net.UDPAddr{IP: ips[0], Port: port}, nil
}

// ForbidDefaultResolver causes the process to panic if
// net.DefaultResolver object is used.
func ForbidDefaultResolver() {
net.DefaultResolver.PreferGo = true
net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) {
panic("Using net.DefaultResolver is forbidden")
}
}
11 changes: 11 additions & 0 deletions apis/model/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ func (n NetAddrSpec) Network() string {

// From modifies the NetAddrSpec object with the given network address.
func (n *NetAddrSpec) From(addr net.Addr) error {
if nas, ok := addr.(NetAddrSpec); ok {
n.AddrSpec = nas.AddrSpec
n.Net = nas.Net
return nil
}
if nas, ok := addr.(*NetAddrSpec); ok {
n.AddrSpec = nas.AddrSpec
n.Net = nas.Net
return nil
}

n.Net = addr.Network()

host, portStr, err := net.SplitHostPort(addr.String())
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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.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.7.0
Version: 3.8.0
Release: 1%{?dist}
Summary: Mieru proxy server
License: GPLv3+
Expand Down
2 changes: 1 addition & 1 deletion docs/client-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Please use a text editor to modify the following fields.
3. In the `profiles` -> `servers` -> `ipAddress` property, fill in the public address of the proxy server. Both IPv4 and IPv6 addresses are supported.
4. If you have registered a domain name for the proxy server, please fill in the domain name in `profiles` -> `servers` -> `domainName`. Otherwise, do not modify this property.
5. Fill in `profiles` -> `servers` -> `portBindings` -> `port` with the TCP or UDP port number that mita is listening to. The port number must be the same as the one set in the proxy server. If you want to listen to a range of consecutive port numbers, you can also use the `portRange` property instead.
6. Specify a value between 1280 and 1500 for the `profiles` -> `mtu` property. The default value is 1400. This value can be different from the setting in the proxy server.
6. Specify a value between 1280 and 1400 for the `profiles` -> `mtu` property. The default value is 1400. This value can be different from the setting in the proxy server.
7. If you want to adjust the frequency of multiplexing, you can set a value for the `profiles` -> `multiplexing` -> `level` property. The values you can use here include `MULTIPLEXING_OFF`, `MULTIPLEXING_LOW`, `MULTIPLEXING_MIDDLE`, and `MULTIPLEXING_HIGH`. `MULTIPLEXING_OFF` will disable multiplexing, and the default value is `MULTIPLEXING_LOW`.
8. Please specify a value between 1025 and 65535 for the `rpcPort` property.
9. Please specify a value between 1025 and 65535 for the `socks5Port` property. This port cannot be the same as `rpcPort`.
Expand Down
2 changes: 1 addition & 1 deletion docs/client-install.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mieru apply config <FILE>
3.`profiles` -> `servers` -> `ipAddress` 属性中,填写代理服务器的公网地址。支持 IPv4 和 IPv6 地址。
4. 如果你为代理服务器注册了域名,请在 `profiles` -> `servers` -> `domainName` 中填写域名。否则,请勿修改这个属性。
5.`profiles` -> `servers` -> `portBindings` -> `port` 中填写 mita 监听的 TCP 或 UDP 端口号。这个端口号必须与代理服务器中的设置相同。如果想要监听连续的端口号,也可以改为使用 `portRange` 属性。
6. 请为 `profiles` -> `mtu` 属性中指定一个从 1280 到 1500 之间的值。默认值为 1400。这个值可以与代理服务器中的设置不同。
6. 请为 `profiles` -> `mtu` 属性中指定一个从 1280 到 1400 之间的值。默认值为 1400。这个值可以与代理服务器中的设置不同。
7. 如果想要调整多路复用的频率,是更多地创建新连接,还是更多地重用旧连接,可以为 `profiles` -> `multiplexing` -> `level` 属性设定一个值。这里可以使用的值包括 `MULTIPLEXING_OFF`, `MULTIPLEXING_LOW`, `MULTIPLEXING_MIDDLE`, `MULTIPLEXING_HIGH`。其中 `MULTIPLEXING_OFF` 会关闭多路复用功能。默认值为 `MULTIPLEXING_LOW`
8. 请为 `rpcPort` 属性指定一个从 1025 到 65535 之间的数值。
9. 请为 `socks5Port` 属性指定一个从 1025 到 65535 之间的数值。该端口不能与 `rpcPort` 相同。
Expand Down
18 changes: 9 additions & 9 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.7.0/mita_3.7.0_amd64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.0/mita_3.8.0_amd64.deb

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

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

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

## Install mita package

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

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

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

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

Those instructions can also be used to upgrade the version of mita software package.
Expand Down Expand Up @@ -106,7 +106,7 @@ to modify the proxy server settings. `<FILE>` is a JSON formatted configuration
2. The `portBindings` -> `protocol` property can be set to `TCP` or `UDP`.
3. Fill in the `users` -> `name` property with the user name.
4. Fill in the `users` -> `password` property with the user's password.
5. The `mtu` property is the maximum data link layer payload size when using the UDP proxy protocol. The default value is 1400. You can choose a value between 1280 and 1500.
5. The `mtu` property is the maximum transport layer payload size when using the UDP proxy protocol. The default value is 1400. The minimum value is 1280.

In addition to this, mita can listen to several different ports. We recommend using multiple ports in both server and client configurations.

Expand Down
18 changes: 9 additions & 9 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.7.0/mita_3.7.0_amd64.deb
curl -LSO https://github.com/enfein/mieru/releases/download/v3.8.0/mita_3.8.0_amd64.deb

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

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

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

## 安装 mita 软件包

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

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

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

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

上述指令也可以用来升级 mita 软件包的版本。
Expand Down Expand Up @@ -106,7 +106,7 @@ mita apply config <FILE>
2. `portBindings` -> `protocol` 属性可以使用 `TCP` 或者 `UDP`
3.`users` -> `name` 属性中填写用户名。
4.`users` -> `password` 属性中填写该用户的密码。
5. `mtu` 属性是使用 UDP 代理协议时,数据链路层最大的载荷大小。默认值是 1400,可以选择 1280 到 1500 之间的值
5. `mtu` 属性是使用 UDP 代理协议时,传输层最大的载荷大小。默认值是 1400,最小值是 1280。

除此之外,mita 可以监听多个不同的端口。我们建议在服务器和客户端配置中使用多个端口。

Expand Down
Loading

0 comments on commit cc3f4c7

Please sign in to comment.