Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClashAPI (Rule Provider) For RuleSet #1266

Open
wants to merge 25 commits into
base: dev-next
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ad93b45
Migrate to independent cache file
nekohasekai Nov 28, 2023
340e74e
Allow nested logical rules
nekohasekai Nov 28, 2023
411f02e
Update buffer usage
nekohasekai Nov 29, 2023
bb70e82
Add rule-set
nekohasekai Dec 1, 2023
3a9b787
Independent `source_ip_is_private` and `ip_is_private` rules
nekohasekai Dec 1, 2023
3041f34
Update documentation
nekohasekai Dec 1, 2023
80cc0cd
Migrate contentjson and badjson to library &
nekohasekai Dec 1, 2023
d1ad342
Skip internal fake-ip queries
nekohasekai Dec 1, 2023
fc9804b
Add `idle_timeout` for URLTest outbound
nekohasekai Dec 3, 2023
f998cce
Update documentation
nekohasekai Dec 3, 2023
abd4d8b
Avoid opening log output before start &
nekohasekai Dec 4, 2023
bc2d73b
Remove comparable limit for Listable
nekohasekai Dec 4, 2023
2f4f4e1
Make type check strict
nekohasekai Dec 5, 2023
a99c310
Improve read wait interface &
nekohasekai Dec 15, 2023
b0cd7af
Remove unnecessary context wrappers
nekohasekai Dec 16, 2023
2b518d3
Update cloudflare-tls to go1.21.5
nekohasekai Dec 8, 2023
9dedf8b
Update gomobile and add tag
nekohasekai Dec 8, 2023
0732b63
Update tfo-go
nekohasekai Dec 9, 2023
5052e86
Update uTLS to 1.5.4
nekohasekai Dec 9, 2023
7740293
Improve configuration merge
nekohasekai Dec 10, 2023
6d4f54d
Refactor inbound/outbound options struct
nekohasekai Dec 11, 2023
285278b
Make generated files have `SUDO_USER`'s permissions if possible.
nekohasekai Dec 17, 2023
7340793
documentation: Fix link format
nekohasekai Dec 14, 2023
bdfe6ec
documentation: Bump version
nekohasekai Dec 7, 2023
ac28333
Add RuleSet ClashAPI (Rule Provider)
0xffffharry Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve configuration merge
nekohasekai committed Dec 18, 2023
commit 7740293a66d0f0202941de5d07e28d31780334a8
13 changes: 9 additions & 4 deletions cmd/sing-box/cmd_run.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import (
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"
"github.com/sagernet/sing/common/json/badjson"

"github.com/spf13/cobra"
@@ -56,8 +57,7 @@ func readConfigAt(path string) (*OptionsEntry, error) {
if err != nil {
return nil, E.Cause(err, "read config at ", path)
}
var options option.Options
err = options.UnmarshalJSON(configContent)
options, err := json.UnmarshalExtended[option.Options](configContent)
if err != nil {
return nil, E.Cause(err, "decode config at ", path)
}
@@ -107,13 +107,18 @@ func readConfigAndMerge() (option.Options, error) {
if len(optionsList) == 1 {
return optionsList[0].options, nil
}
var mergedOptions option.Options
var mergedMessage json.RawMessage
for _, options := range optionsList {
mergedOptions, err = badjson.Merge(options.options, mergedOptions)
mergedMessage, err = badjson.MergeJSON(options.options.RawMessage, mergedMessage)
if err != nil {
return option.Options{}, E.Cause(err, "merge config at ", options.path)
}
}
var mergedOptions option.Options
err = mergedOptions.UnmarshalJSON(mergedMessage)
if err != nil {
return option.Options{}, E.Cause(err, "unmarshal merged config")
}
return mergedOptions, nil
}

5 changes: 2 additions & 3 deletions experimental/libbox/config.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package libbox
import (
"bytes"
"context"
"encoding/json"
"net/netip"
"os"

@@ -15,13 +14,13 @@ import (
"github.com/sagernet/sing-tun"
"github.com/sagernet/sing/common/control"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"
"github.com/sagernet/sing/common/logger"
"github.com/sagernet/sing/common/x/list"
)

func parseConfig(configContent string) (option.Options, error) {
var options option.Options
err := options.UnmarshalJSON([]byte(configContent))
options, err := json.UnmarshalExtended[option.Options]([]byte(configContent))
if err != nil {
return option.Options{}, E.Cause(err, "decode config")
}
18 changes: 6 additions & 12 deletions option/config.go
Original file line number Diff line number Diff line change
@@ -2,13 +2,12 @@ package option

import (
"bytes"
"strings"

E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"
)

type _Options struct {
RawMessage json.RawMessage `json:"-"`
Schema string `json:"$schema,omitempty"`
Log *LogOptions `json:"log,omitempty"`
DNS *DNSOptions `json:"dns,omitempty"`
@@ -22,19 +21,14 @@ type _Options struct {
type Options _Options

func (o *Options) UnmarshalJSON(content []byte) error {
decoder := json.NewDecoder(json.NewCommentFilter(bytes.NewReader(content)))
decoder := json.NewDecoder(bytes.NewReader(content))
decoder.DisallowUnknownFields()
err := decoder.Decode((*_Options)(o))
if err == nil {
return nil
if err != nil {
return err
}
if syntaxError, isSyntaxError := err.(*json.SyntaxError); isSyntaxError {
prefix := string(content[:syntaxError.Offset])
row := strings.Count(prefix, "\n") + 1
column := len(prefix) - strings.LastIndex(prefix, "\n") - 1
return E.Extend(syntaxError, "row ", row, ", column ", column)
}
return err
o.RawMessage = content
return nil
}

type LogOptions struct {