mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-06 00:09:37 +07:00
feat: add flag disable-timestamp; check empty node list after subscription resolving
This commit is contained in:
15
cmd/run.go
15
cmd/run.go
@ -15,7 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
|
disableTimestamp bool
|
||||||
|
|
||||||
runCmd = &cobra.Command{
|
runCmd = &cobra.Command{
|
||||||
Use: "run",
|
Use: "run",
|
||||||
@ -24,7 +25,9 @@ var (
|
|||||||
if cfgFile == "" {
|
if cfgFile == "" {
|
||||||
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
|
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)
|
logrus.Fatalln(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -33,11 +36,10 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
|
runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
|
||||||
|
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run() (err error) {
|
func Run(log *logrus.Logger) (err error) {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
log := logger.NewLogger(2)
|
|
||||||
|
|
||||||
// Require "sudo" if necessary.
|
// Require "sudo" if necessary.
|
||||||
internal.AutoSu()
|
internal.AutoSu()
|
||||||
@ -58,6 +60,9 @@ func Run() (err error) {
|
|||||||
}
|
}
|
||||||
nodeList = append(nodeList, nodes...)
|
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 {
|
if len(param.Global.LanInterface) == 0 && len(param.Global.WanInterface) == 0 {
|
||||||
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")
|
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
SuspectedRushAnswerError = fmt.Errorf("suspected DNS rush-answer")
|
SuspectedRushAnswerError = fmt.Errorf("suspected DNS rush-answer")
|
||||||
NotAdapableQuestionTypeError = fmt.Errorf("not adaptable question type")
|
UnsupportedQuestionTypeError = fmt.Errorf("unsupported question type")
|
||||||
)
|
)
|
||||||
|
|
||||||
type dnsCache struct {
|
type dnsCache struct {
|
||||||
@ -145,13 +145,13 @@ func FlipDnsQuestionCase(dm *dnsmessage.Message) {
|
|||||||
func EnsureAdditionalOpt(dm *dnsmessage.Message, isReqAdd bool) (bool, error) {
|
func EnsureAdditionalOpt(dm *dnsmessage.Message, isReqAdd bool) (bool, error) {
|
||||||
// Check healthy resp.
|
// Check healthy resp.
|
||||||
if isReqAdd == dm.Response || dm.RCode != dnsmessage.RCodeSuccess || len(dm.Questions) == 0 {
|
if isReqAdd == dm.Response || dm.RCode != dnsmessage.RCodeSuccess || len(dm.Questions) == 0 {
|
||||||
return false, NotAdapableQuestionTypeError
|
return false, UnsupportedQuestionTypeError
|
||||||
}
|
}
|
||||||
q := dm.Questions[0]
|
q := dm.Questions[0]
|
||||||
switch q.Type {
|
switch q.Type {
|
||||||
case dnsmessage.TypeA, dnsmessage.TypeAAAA:
|
case dnsmessage.TypeA, dnsmessage.TypeAAAA:
|
||||||
default:
|
default:
|
||||||
return false, NotAdapableQuestionTypeError
|
return false, UnsupportedQuestionTypeError
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ad := range dm.Additionals {
|
for _, ad := range dm.Additionals {
|
||||||
@ -186,7 +186,7 @@ func (c *ControlPlane) DnsRespHandler(data []byte) (newData []byte, err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
exist, e := EnsureAdditionalOpt(&msg, false)
|
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)
|
c.log.Warnf("EnsureAdditionalOpt: %v", e)
|
||||||
}
|
}
|
||||||
if e == nil && !exist {
|
if e == nil && !exist {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=dae Service
|
Description=dae Service
|
||||||
Documentation=https://github.com/v2rayA/dae
|
Documentation=https://github.com/v2rayA/dae
|
||||||
After=network.target
|
After=network-online.target
|
||||||
Wants=network.target
|
Wants=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=root
|
User=root
|
||||||
LimitNPROC=500
|
LimitNPROC=500
|
||||||
LimitNOFILE=1000000
|
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
|
Restart=on-failure
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
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()
|
log := logrus.New()
|
||||||
|
|
||||||
var level logrus.Level
|
var level logrus.Level
|
||||||
@ -27,8 +27,9 @@ func NewLogger(verbose int) *logrus.Logger {
|
|||||||
|
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
log.SetFormatter(&prefixed.TextFormatter{
|
log.SetFormatter(&prefixed.TextFormatter{
|
||||||
FullTimestamp: true,
|
DisableTimestamp: disableTimestamp,
|
||||||
TimestampFormat: "Jan 02 15:04:05",
|
FullTimestamp: true,
|
||||||
|
TimestampFormat: "Jan 02 15:04:05",
|
||||||
})
|
})
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
Reference in New Issue
Block a user