mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-28 19:41: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@$(git -C $PROJECTS/sing rev-parse HEAD)
|
||||||
go get -x github.com/sagernet/sing-shadowsocks@$(git -C $PROJECTS/sing-shadowsocks rev-parse HEAD)
|
go get -x github.com/sagernet/sing-shadowsocks@$(git -C $PROJECTS/sing-shadowsocks rev-parse HEAD)
|
||||||
go mod tidy
|
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": [],
|
"servers": [],
|
||||||
"rules": [],
|
"rules": [],
|
||||||
"final": "",
|
"final": "",
|
||||||
"strategy": "prefer_ipv6",
|
"strategy": "",
|
||||||
"disable_cache": false,
|
"disable_cache": false,
|
||||||
"disable_expire": false
|
"disable_expire": false
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@
|
||||||
|
|
||||||
#### final
|
#### 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
|
#### strategy
|
||||||
|
|
||||||
|
|
|
@ -140,4 +140,6 @@ Included default rules.
|
||||||
|
|
||||||
#### server
|
#### server
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Tag of the target dns server.
|
Tag of the target dns server.
|
||||||
|
|
|
@ -25,6 +25,8 @@ The tag of the dns server.
|
||||||
|
|
||||||
#### address
|
#### address
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The address of the dns server.
|
The address of the dns server.
|
||||||
|
|
||||||
| Protocol | Format |
|
| Protocol | Format |
|
||||||
|
@ -41,6 +43,8 @@ The address of the dns server.
|
||||||
|
|
||||||
#### address_resolver
|
#### address_resolver
|
||||||
|
|
||||||
|
==Required if address contains domain==
|
||||||
|
|
||||||
Tag of a another server to resolve the domain name in the address.
|
Tag of a another server to resolve the domain name in the address.
|
||||||
|
|
||||||
#### address_strategy
|
#### 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.
|
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
|
#### listen
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen address.
|
Listen address.
|
||||||
|
|
||||||
#### listen_port
|
#### listen_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen port.
|
Listen port.
|
||||||
|
|
||||||
#### tcp_fast_open
|
#### tcp_fast_open
|
||||||
|
|
|
@ -31,10 +31,14 @@
|
||||||
|
|
||||||
#### listen
|
#### listen
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen address.
|
Listen address.
|
||||||
|
|
||||||
#### listen_port
|
#### listen_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen port.
|
Listen port.
|
||||||
|
|
||||||
#### tcp_fast_open
|
#### tcp_fast_open
|
||||||
|
|
|
@ -31,10 +31,14 @@
|
||||||
|
|
||||||
#### listen
|
#### listen
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen address.
|
Listen address.
|
||||||
|
|
||||||
#### listen_port
|
#### listen_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen port.
|
Listen port.
|
||||||
|
|
||||||
#### tcp_fast_open
|
#### tcp_fast_open
|
||||||
|
|
|
@ -29,10 +29,14 @@
|
||||||
|
|
||||||
#### listen
|
#### listen
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen address.
|
Listen address.
|
||||||
|
|
||||||
#### listen_port
|
#### listen_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen port.
|
Listen port.
|
||||||
|
|
||||||
#### tcp_fast_open
|
#### tcp_fast_open
|
||||||
|
@ -75,6 +79,8 @@ Both if empty.
|
||||||
|
|
||||||
#### method
|
#### method
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
| Method | Key Length |
|
| Method | Key Length |
|
||||||
|-------------------------------|------------|
|
|-------------------------------|------------|
|
||||||
| 2022-blake3-aes-128-gcm | 16 |
|
| 2022-blake3-aes-128-gcm | 16 |
|
||||||
|
@ -89,6 +95,8 @@ Both if empty.
|
||||||
|
|
||||||
#### password
|
#### password
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
| Method | Password Format |
|
| Method | Password Format |
|
||||||
|---------------|-------------------------------------|
|
|---------------|-------------------------------------|
|
||||||
| none | / |
|
| none | / |
|
||||||
|
|
|
@ -31,10 +31,14 @@
|
||||||
|
|
||||||
#### listen
|
#### listen
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen address.
|
Listen address.
|
||||||
|
|
||||||
#### listen_port
|
#### listen_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Listen port.
|
Listen port.
|
||||||
|
|
||||||
#### tcp_fast_open
|
#### tcp_fast_open
|
||||||
|
|
|
@ -31,10 +31,14 @@
|
||||||
|
|
||||||
#### server
|
#### server
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server address.
|
The server address.
|
||||||
|
|
||||||
#### server_port
|
#### server_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server port.
|
The server port.
|
||||||
|
|
||||||
#### username
|
#### username
|
||||||
|
|
|
@ -32,14 +32,20 @@
|
||||||
|
|
||||||
#### server
|
#### server
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server address.
|
The server address.
|
||||||
|
|
||||||
#### server_port
|
#### server_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server port.
|
The server port.
|
||||||
|
|
||||||
#### method
|
#### method
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
Encryption methods:
|
Encryption methods:
|
||||||
|
|
||||||
* `2022-blake3-aes-128-gcm`
|
* `2022-blake3-aes-128-gcm`
|
||||||
|
@ -66,6 +72,8 @@ Legacy encryption methods:
|
||||||
|
|
||||||
#### password
|
#### password
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The shadowsocks password.
|
The shadowsocks password.
|
||||||
|
|
||||||
#### network
|
#### network
|
||||||
|
|
|
@ -33,10 +33,14 @@
|
||||||
|
|
||||||
#### server
|
#### server
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server address.
|
The server address.
|
||||||
|
|
||||||
#### server_port
|
#### server_port
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
The server port.
|
The server port.
|
||||||
|
|
||||||
#### version
|
#### version
|
||||||
|
|
|
@ -63,8 +63,13 @@ markdown_extensions:
|
||||||
- pymdownx.inlinehilite
|
- pymdownx.inlinehilite
|
||||||
- pymdownx.snippets
|
- pymdownx.snippets
|
||||||
- pymdownx.superfences
|
- pymdownx.superfences
|
||||||
- admonition
|
|
||||||
- pymdownx.details
|
- pymdownx.details
|
||||||
|
- pymdownx.critic
|
||||||
|
- pymdownx.caret
|
||||||
|
- pymdownx.keys
|
||||||
|
- pymdownx.mark
|
||||||
|
- pymdownx.tilde
|
||||||
|
- admonition
|
||||||
- attr_list
|
- attr_list
|
||||||
- md_in_html
|
- md_in_html
|
||||||
- footnotes
|
- footnotes
|
||||||
|
|
|
@ -34,7 +34,7 @@ type DNSServerOptions struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
AddressResolver string `json:"address_resolver,omitempty"`
|
AddressResolver string `json:"address_resolver,omitempty"`
|
||||||
AddressStrategy DomainStrategy `json:"address_strategy,omitempty"`
|
AddressStrategy DomainStrategy `json:"address_strategy,omitempty"`
|
||||||
DialerOptions
|
Detour string `json:"detour,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type _DNSRule struct {
|
type _DNSRule struct {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -116,7 +117,18 @@ func NewRouter(ctx context.Context, logger log.Logger, options option.RouteOptio
|
||||||
if _, exists := dummyTransportMap[tag]; exists {
|
if _, exists := dummyTransportMap[tag]; exists {
|
||||||
continue
|
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 server.AddressResolver != "" {
|
||||||
if !transportTagMap[server.AddressResolver] {
|
if !transportTagMap[server.AddressResolver] {
|
||||||
return nil, E.New("parse dns server[", tag, "]: address resolver not found: ", 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 {
|
} else {
|
||||||
continue
|
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)
|
transport, err := dns.NewTransport(ctx, detour, logger, server.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue