feat: add flag disable-timestamp; check empty node list after subscription resolving

This commit is contained in:
mzz2017 2023-02-04 22:02:37 +08:00
parent 5118a80bca
commit a6d2628505
4 changed files with 21 additions and 15 deletions

View File

@ -15,7 +15,8 @@ import (
)
var (
cfgFile string
cfgFile string
disableTimestamp bool
runCmd = &cobra.Command{
Use: "run",
@ -24,7 +25,9 @@ var (
if cfgFile == "" {
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
}
if err := Run(); err != nil {
logrus.SetLevel(logrus.DebugLevel)
log := logger.NewLogger(2, disableTimestamp)
if err := Run(log); err != nil {
logrus.Fatalln(err)
}
},
@ -33,11 +36,10 @@ var (
func init() {
runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
}
func Run() (err error) {
logrus.SetLevel(logrus.DebugLevel)
log := logger.NewLogger(2)
func Run(log *logrus.Logger) (err error) {
// Require "sudo" if necessary.
internal.AutoSu()
@ -58,6 +60,9 @@ func Run() (err error) {
}
nodeList = append(nodeList, nodes...)
}
if len(nodeList) == 0 {
return fmt.Errorf("no node found, which could because all subscription resolving failed")
}
if len(param.Global.LanInterface) == 0 && len(param.Global.WanInterface) == 0 {
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")

View File

@ -24,7 +24,7 @@ import (
var (
SuspectedRushAnswerError = fmt.Errorf("suspected DNS rush-answer")
NotAdapableQuestionTypeError = fmt.Errorf("not adaptable question type")
UnsupportedQuestionTypeError = fmt.Errorf("unsupported question type")
)
type dnsCache struct {
@ -145,13 +145,13 @@ func FlipDnsQuestionCase(dm *dnsmessage.Message) {
func EnsureAdditionalOpt(dm *dnsmessage.Message, isReqAdd bool) (bool, error) {
// Check healthy resp.
if isReqAdd == dm.Response || dm.RCode != dnsmessage.RCodeSuccess || len(dm.Questions) == 0 {
return false, NotAdapableQuestionTypeError
return false, UnsupportedQuestionTypeError
}
q := dm.Questions[0]
switch q.Type {
case dnsmessage.TypeA, dnsmessage.TypeAAAA:
default:
return false, NotAdapableQuestionTypeError
return false, UnsupportedQuestionTypeError
}
for _, ad := range dm.Additionals {
@ -186,7 +186,7 @@ func (c *ControlPlane) DnsRespHandler(data []byte) (newData []byte, err error) {
defer func() {
if err == nil {
exist, e := EnsureAdditionalOpt(&msg, false)
if e != nil && !errors.Is(e, NotAdapableQuestionTypeError) {
if e != nil && !errors.Is(e, UnsupportedQuestionTypeError) {
c.log.Warnf("EnsureAdditionalOpt: %v", e)
}
if e == nil && !exist {

View File

@ -1,15 +1,15 @@
[Unit]
Description=dae Service
Documentation=https://github.com/v2rayA/dae
After=network.target
Wants=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
LimitNPROC=500
LimitNOFILE=1000000
ExecStart=/usr/bin/dae run -c /etc/dae/config.dae
ExecStart=/usr/bin/dae run --disable-timestamp -c /etc/dae/config.dae
Restart=on-failure
[Install]

View File

@ -10,7 +10,7 @@ import (
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
func NewLogger(verbose int) *logrus.Logger {
func NewLogger(verbose int, disableTimestamp bool) *logrus.Logger {
log := logrus.New()
var level logrus.Level
@ -27,8 +27,9 @@ func NewLogger(verbose int) *logrus.Logger {
log.SetLevel(level)
log.SetFormatter(&prefixed.TextFormatter{
FullTimestamp: true,
TimestampFormat: "Jan 02 15:04:05",
DisableTimestamp: disableTimestamp,
FullTimestamp: true,
TimestampFormat: "Jan 02 15:04:05",
})
return log