mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 01:51:29 +00:00
Declare required fields in the documentation
This commit is contained in:
parent
8fa953a516
commit
211d97ff8a
3
.github/update_dependencies.sh
vendored
3
.github/update_dependencies.sh
vendored
|
@ -5,3 +5,6 @@ PROJECTS=$(dirname "$0")/../..
|
|||
go get -x github.com/sagernet/sing@$(git -C $PROJECTS/sing rev-parse HEAD)
|
||||
go get -x github.com/sagernet/sing-shadowsocks@$(git -C $PROJECTS/sing-shadowsocks rev-parse HEAD)
|
||||
go mod tidy
|
||||
pushd test
|
||||
go mod tidy
|
||||
popd
|
||||
|
|
31
common/dialer/router.go
Normal file
31
common/dialer/router.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package dialer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
type RouterDialer struct {
|
||||
router adapter.Router
|
||||
}
|
||||
|
||||
func NewRouter(router adapter.Router) N.Dialer {
|
||||
return &RouterDialer{router: router}
|
||||
}
|
||||
|
||||
func (d *RouterDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
return d.router.DefaultOutbound(network).DialContext(ctx, network, destination)
|
||||
}
|
||||
|
||||
func (d *RouterDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
return d.router.DefaultOutbound(C.NetworkUDP).ListenPacket(ctx, destination)
|
||||
}
|
||||
|
||||
func (d *RouterDialer) Upstream() any {
|
||||
return d.router
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"servers": [],
|
||||
"rules": [],
|
||||
"final": "",
|
||||
"strategy": "prefer_ipv6",
|
||||
"strategy": "",
|
||||
"disable_cache": false,
|
||||
"disable_expire": false
|
||||
}
|
||||
|
@ -23,7 +23,9 @@
|
|||
|
||||
#### final
|
||||
|
||||
Default dns server tag. the first server will be used if empty.
|
||||
Default dns server tag.
|
||||
|
||||
The first server will be used if empty.
|
||||
|
||||
#### strategy
|
||||
|
||||
|
|
|
@ -140,4 +140,6 @@ Included default rules.
|
|||
|
||||
#### server
|
||||
|
||||
==Required==
|
||||
|
||||
Tag of the target dns server.
|
||||
|
|
|
@ -25,6 +25,8 @@ The tag of the dns server.
|
|||
|
||||
#### address
|
||||
|
||||
==Required==
|
||||
|
||||
The address of the dns server.
|
||||
|
||||
| Protocol | Format |
|
||||
|
@ -41,6 +43,8 @@ The address of the dns server.
|
|||
|
||||
#### address_resolver
|
||||
|
||||
==Required if address contains domain==
|
||||
|
||||
Tag of a another server to resolve the domain name in the address.
|
||||
|
||||
#### address_strategy
|
||||
|
@ -55,4 +59,4 @@ One of `prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`.
|
|||
|
||||
Tag of an outbound for connecting to the dns server.
|
||||
|
||||
Requests will be sent directly if the empty.
|
||||
Default outbound will be used if empty.
|
|
@ -29,10 +29,14 @@
|
|||
|
||||
#### listen
|
||||
|
||||
==Required==
|
||||
|
||||
Listen address.
|
||||
|
||||
#### listen_port
|
||||
|
||||
==Required==
|
||||
|
||||
Listen port.
|
||||
|
||||
#### tcp_fast_open
|
||||
|
|
|
@ -31,10 +31,14 @@
|
|||
|
||||
#### listen
|
||||
|
||||
==Required==
|
||||
|
||||
Listen address.
|
||||
|
||||
#### listen_port
|
||||
|
||||
==Required==
|
||||
|
||||
Listen port.
|
||||
|
||||
#### tcp_fast_open
|
||||
|
|
|
@ -31,10 +31,14 @@
|
|||
|
||||
#### listen
|
||||
|
||||
==Required==
|
||||
|
||||
Listen address.
|
||||
|
||||
#### listen_port
|
||||
|
||||
==Required==
|
||||
|
||||
Listen port.
|
||||
|
||||
#### tcp_fast_open
|
||||
|
|
|
@ -29,10 +29,14 @@
|
|||
|
||||
#### listen
|
||||
|
||||
==Required==
|
||||
|
||||
Listen address.
|
||||
|
||||
#### listen_port
|
||||
|
||||
==Required==
|
||||
|
||||
Listen port.
|
||||
|
||||
#### tcp_fast_open
|
||||
|
@ -75,6 +79,8 @@ Both if empty.
|
|||
|
||||
#### method
|
||||
|
||||
==Required==
|
||||
|
||||
| Method | Key Length |
|
||||
|-------------------------------|------------|
|
||||
| 2022-blake3-aes-128-gcm | 16 |
|
||||
|
@ -89,6 +95,8 @@ Both if empty.
|
|||
|
||||
#### password
|
||||
|
||||
==Required==
|
||||
|
||||
| Method | Password Format |
|
||||
|---------------|-------------------------------------|
|
||||
| none | / |
|
||||
|
|
|
@ -31,10 +31,14 @@
|
|||
|
||||
#### listen
|
||||
|
||||
==Required==
|
||||
|
||||
Listen address.
|
||||
|
||||
#### listen_port
|
||||
|
||||
==Required==
|
||||
|
||||
Listen port.
|
||||
|
||||
#### tcp_fast_open
|
||||
|
|
|
@ -31,10 +31,14 @@
|
|||
|
||||
#### server
|
||||
|
||||
==Required==
|
||||
|
||||
The server address.
|
||||
|
||||
#### server_port
|
||||
|
||||
==Required==
|
||||
|
||||
The server port.
|
||||
|
||||
#### username
|
||||
|
|
|
@ -32,14 +32,20 @@
|
|||
|
||||
#### server
|
||||
|
||||
==Required==
|
||||
|
||||
The server address.
|
||||
|
||||
#### server_port
|
||||
|
||||
==Required==
|
||||
|
||||
The server port.
|
||||
|
||||
#### method
|
||||
|
||||
==Required==
|
||||
|
||||
Encryption methods:
|
||||
|
||||
* `2022-blake3-aes-128-gcm`
|
||||
|
@ -66,6 +72,8 @@ Legacy encryption methods:
|
|||
|
||||
#### password
|
||||
|
||||
==Required==
|
||||
|
||||
The shadowsocks password.
|
||||
|
||||
#### network
|
||||
|
|
|
@ -33,10 +33,14 @@
|
|||
|
||||
#### server
|
||||
|
||||
==Required==
|
||||
|
||||
The server address.
|
||||
|
||||
#### server_port
|
||||
|
||||
==Required==
|
||||
|
||||
The server port.
|
||||
|
||||
#### version
|
||||
|
|
|
@ -63,8 +63,13 @@ markdown_extensions:
|
|||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.superfences
|
||||
- admonition
|
||||
- pymdownx.details
|
||||
- pymdownx.critic
|
||||
- pymdownx.caret
|
||||
- pymdownx.keys
|
||||
- pymdownx.mark
|
||||
- pymdownx.tilde
|
||||
- admonition
|
||||
- attr_list
|
||||
- md_in_html
|
||||
- footnotes
|
||||
|
|
|
@ -34,7 +34,7 @@ type DNSServerOptions struct {
|
|||
Address string `json:"address"`
|
||||
AddressResolver string `json:"address_resolver,omitempty"`
|
||||
AddressStrategy DomainStrategy `json:"address_strategy,omitempty"`
|
||||
DialerOptions
|
||||
Detour string `json:"detour,omitempty"`
|
||||
}
|
||||
|
||||
type _DNSRule struct {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -116,7 +117,18 @@ func NewRouter(ctx context.Context, logger log.Logger, options option.RouteOptio
|
|||
if _, exists := dummyTransportMap[tag]; exists {
|
||||
continue
|
||||
}
|
||||
detour := dialer.New(router, server.DialerOptions)
|
||||
var detour N.Dialer
|
||||
if server.Detour == "" {
|
||||
detour = dialer.NewRouter(router)
|
||||
} else {
|
||||
detour = dialer.NewDetour(router, server.Detour)
|
||||
}
|
||||
serverURL, err := url.Parse(server.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
serverAddress := serverURL.Hostname()
|
||||
_, notIpAddress := netip.ParseAddr(serverAddress)
|
||||
if server.AddressResolver != "" {
|
||||
if !transportTagMap[server.AddressResolver] {
|
||||
return nil, E.New("parse dns server[", tag, "]: address resolver not found: ", server.AddressResolver)
|
||||
|
@ -126,6 +138,8 @@ func NewRouter(ctx context.Context, logger log.Logger, options option.RouteOptio
|
|||
} else {
|
||||
continue
|
||||
}
|
||||
} else if notIpAddress != nil {
|
||||
return nil, E.New("parse dns server[", tag, "]: missing address_resolver")
|
||||
}
|
||||
transport, err := dns.NewTransport(ctx, detour, logger, server.Address)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue