mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-08-03 17:17:36 +08:00
Compare commits
2 Commits
ec4d472912
...
b5d1ba19f1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b5d1ba19f1 | ||
![]() |
d8e41965e0 |
@ -232,10 +232,20 @@ func (c *Client) Exchange(ctx context.Context, transport adapter.DNSTransport, m
|
|||||||
record.Header().Ttl = timeToLive
|
record.Header().Ttl = timeToLive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.Id = messageId
|
|
||||||
if !disableCache {
|
if !disableCache {
|
||||||
c.storeCache(transport, question, response, timeToLive)
|
c.storeCache(transport, question, response, timeToLive)
|
||||||
}
|
}
|
||||||
|
response.Id = messageId
|
||||||
|
requestEDNSOpt := message.IsEdns0()
|
||||||
|
responseEDNSOpt := response.IsEdns0()
|
||||||
|
if responseEDNSOpt != nil && (requestEDNSOpt == nil || requestEDNSOpt.Version() < responseEDNSOpt.Version()) {
|
||||||
|
response.Extra = common.Filter(response.Extra, func(it dns.RR) bool {
|
||||||
|
return it.Header().Rrtype != dns.TypeOPT
|
||||||
|
})
|
||||||
|
if requestEDNSOpt != nil {
|
||||||
|
response.SetEdns0(responseEDNSOpt.UDPSize(), responseEDNSOpt.Do())
|
||||||
|
}
|
||||||
|
}
|
||||||
logExchangedResponse(c.logger, ctx, response, timeToLive)
|
logExchangedResponse(c.logger, ctx, response, timeToLive)
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
@ -27,6 +29,18 @@ type _RuleSet struct {
|
|||||||
type RuleSet _RuleSet
|
type RuleSet _RuleSet
|
||||||
|
|
||||||
func (r RuleSet) MarshalJSON() ([]byte, error) {
|
func (r RuleSet) MarshalJSON() ([]byte, error) {
|
||||||
|
if r.Type != C.RuleSetTypeInline {
|
||||||
|
var defaultFormat string
|
||||||
|
switch r.Type {
|
||||||
|
case C.RuleSetTypeLocal:
|
||||||
|
defaultFormat = ruleSetDefaultFormat(r.LocalOptions.Path)
|
||||||
|
case C.RuleSetTypeRemote:
|
||||||
|
defaultFormat = ruleSetDefaultFormat(r.RemoteOptions.URL)
|
||||||
|
}
|
||||||
|
if r.Format == defaultFormat {
|
||||||
|
r.Format = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
var v any
|
var v any
|
||||||
switch r.Type {
|
switch r.Type {
|
||||||
case "", C.RuleSetTypeInline:
|
case "", C.RuleSetTypeInline:
|
||||||
@ -62,7 +76,19 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
|||||||
default:
|
default:
|
||||||
return E.New("unknown rule-set type: " + r.Type)
|
return E.New("unknown rule-set type: " + r.Type)
|
||||||
}
|
}
|
||||||
|
err = badjson.UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if r.Type != C.RuleSetTypeInline {
|
if r.Type != C.RuleSetTypeInline {
|
||||||
|
if r.Format == "" {
|
||||||
|
switch r.Type {
|
||||||
|
case C.RuleSetTypeLocal:
|
||||||
|
r.Format = ruleSetDefaultFormat(r.LocalOptions.Path)
|
||||||
|
case C.RuleSetTypeRemote:
|
||||||
|
r.Format = ruleSetDefaultFormat(r.RemoteOptions.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
switch r.Format {
|
switch r.Format {
|
||||||
case "":
|
case "":
|
||||||
return E.New("missing format")
|
return E.New("missing format")
|
||||||
@ -73,13 +99,23 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
|||||||
} else {
|
} else {
|
||||||
r.Format = ""
|
r.Format = ""
|
||||||
}
|
}
|
||||||
err = badjson.UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ruleSetDefaultFormat(path string) string {
|
||||||
|
if pathURL, err := url.Parse(path); err == nil {
|
||||||
|
path = pathURL.Path
|
||||||
|
}
|
||||||
|
switch filepath.Ext(path) {
|
||||||
|
case ".json":
|
||||||
|
return C.RuleSetFormatSource
|
||||||
|
case ".srs":
|
||||||
|
return C.RuleSetFormatBinary
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type LocalRuleSet struct {
|
type LocalRuleSet struct {
|
||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user