mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-09 05:49:54 +00:00
feat: custom resolver
This commit is contained in:
parent
b68af5cbe2
commit
c09edb6e53
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"io"
|
"io"
|
||||||
@ -27,6 +28,16 @@ import (
|
|||||||
|
|
||||||
func client(config *clientConfig) {
|
func client(config *clientConfig) {
|
||||||
logrus.WithField("config", config.String()).Info("Client configuration loaded")
|
logrus.WithField("config", config.String()).Info("Client configuration loaded")
|
||||||
|
// Resolver
|
||||||
|
if len(config.Resolver) > 0 {
|
||||||
|
net.DefaultResolver = &net.Resolver{
|
||||||
|
PreferGo: true,
|
||||||
|
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
d := net.Dialer{}
|
||||||
|
return d.DialContext(ctx, "udp", config.Resolver)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
// TLS
|
// TLS
|
||||||
tlsConfig := &tls.Config{
|
tlsConfig := &tls.Config{
|
||||||
ServerName: config.ServerName,
|
ServerName: config.ServerName,
|
||||||
|
@ -48,6 +48,7 @@ type serverConfig struct {
|
|||||||
MaxConnClient int `json:"max_conn_client"`
|
MaxConnClient int `json:"max_conn_client"`
|
||||||
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
||||||
IPv6Only bool `json:"ipv6_only"`
|
IPv6Only bool `json:"ipv6_only"`
|
||||||
|
Resolver string `json:"resolver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *serverConfig) Check() error {
|
func (c *serverConfig) Check() error {
|
||||||
@ -146,6 +147,7 @@ type clientConfig struct {
|
|||||||
ReceiveWindowConn uint64 `json:"recv_window_conn"`
|
ReceiveWindowConn uint64 `json:"recv_window_conn"`
|
||||||
ReceiveWindow uint64 `json:"recv_window"`
|
ReceiveWindow uint64 `json:"recv_window"`
|
||||||
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
||||||
|
Resolver string `json:"resolver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientConfig) Check() error {
|
func (c *clientConfig) Check() error {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"github.com/lucas-clemente/quic-go/congestion"
|
"github.com/lucas-clemente/quic-go/congestion"
|
||||||
@ -22,6 +23,16 @@ import (
|
|||||||
|
|
||||||
func server(config *serverConfig) {
|
func server(config *serverConfig) {
|
||||||
logrus.WithField("config", config.String()).Info("Server configuration loaded")
|
logrus.WithField("config", config.String()).Info("Server configuration loaded")
|
||||||
|
// Resolver
|
||||||
|
if len(config.Resolver) > 0 {
|
||||||
|
net.DefaultResolver = &net.Resolver{
|
||||||
|
PreferGo: true,
|
||||||
|
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
d := net.Dialer{}
|
||||||
|
return d.DialContext(ctx, "udp", config.Resolver)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
// Load TLS config
|
// Load TLS config
|
||||||
var tlsConfig *tls.Config
|
var tlsConfig *tls.Config
|
||||||
if len(config.ACME.Domains) > 0 {
|
if len(config.ACME.Domains) > 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user