Skip to content

Commit

Permalink
Merge pull request #170 from HyNetwork/wip-ipv6-only-mode
Browse files Browse the repository at this point in the history
ipv6 only mode
  • Loading branch information
tobyxdd authored Dec 10, 2021
2 parents d7bda39 + a6c73b6 commit 3f598b8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ encryption. If you need a proxy, just use our proxy modes.
"recv_window_conn": 15728640, // QUIC stream receive window
"recv_window_client": 67108864, // QUIC connection receive window
"max_conn_client": 4096, // Max concurrent connections per client
"disable_mtu_discovery": false // Disable Path MTU Discovery (RFC 8899)
"disable_mtu_discovery": false, // Disable Path MTU Discovery (RFC 8899)
"ipv6_only": false // Only resolve domains to IPv6 address
}
```

Expand Down
3 changes: 2 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ Hysteria 是一个功能丰富的,专为恶劣网络环境进行优化的网
"recv_window_conn": 15728640, // QUIC stream receive window
"recv_window_client": 67108864, // QUIC connection receive window
"max_conn_client": 4096, // 单客户端最大活跃连接数
"disable_mtu_discovery": false // 禁用 MTU 探测 (RFC 8899)
"disable_mtu_discovery": false, // 禁用 MTU 探测 (RFC 8899)
"ipv6_only": false // 强制把域名解析成 IPv6 地址
}
```

Expand Down
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type serverConfig struct {
ReceiveWindowClient uint64 `json:"recv_window_client"`
MaxConnClient int `json:"max_conn_client"`
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
IPv6Only bool `json:"ipv6_only"`
}

func (c *serverConfig) Check() error {
Expand Down
4 changes: 4 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func server(config *serverConfig) {
if len(config.Obfs) > 0 {
obfuscator = obfs.NewXPlusObfuscator([]byte(config.Obfs))
}
// IPv6 only mode
if config.IPv6Only {
transport.DefaultTransport = transport.IPv6OnlyTransport
}
// ACL
var aclEngine *acl.Engine
if len(config.ACL) > 0 {
Expand Down
14 changes: 14 additions & 0 deletions pkg/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ var DefaultTransport Transport = &defaultTransport{
Timeout: 8 * time.Second,
}

var IPv6OnlyTransport Transport = &ipv6OnlyTransport{
defaultTransport{
Timeout: 8 * time.Second,
},
}

type defaultTransport struct {
Timeout time.Duration
}
Expand Down Expand Up @@ -67,3 +73,11 @@ func (t *defaultTransport) LocalListenTCP(laddr *net.TCPAddr) (*net.TCPListener,
func (t *defaultTransport) LocalListenUDP(laddr *net.UDPAddr) (*net.UDPConn, error) {
return net.ListenUDP("udp", laddr)
}

type ipv6OnlyTransport struct {
defaultTransport
}

func (t *ipv6OnlyTransport) LocalResolveIPAddr(address string) (*net.IPAddr, error) {
return net.ResolveIPAddr("ip6", address)
}

0 comments on commit 3f598b8

Please sign in to comment.