Skip to content

Commit

Permalink
v0.0.2 - 进一步解耦
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 25, 2024
1 parent 42023a6 commit 631eff3
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 58 deletions.
43 changes: 27 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func main() {
flag.IntVar(&model.Verbose, "verbose", 0, "the verbosity level")
flag.IntVar(&model.Timeout, "timeout", 3, "the number of seconds to wait for STUN server's response")
flag.StringVar(&model.AddrStr, "server", "stun.voipgate.com:3478", "STUN server address")
flag.BoolVar(&model.EnableLoger, "e", true, "Enable logging")
flag.Parse()
go func() {
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fgostun&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false")
Expand All @@ -26,25 +27,31 @@ func main() {
fmt.Println(model.GoStunVersion)
return
}
var logLevel logging.LogLevel
switch model.Verbose {
case 0:
logLevel = logging.LogLevelWarn // default // my changes
case 1:
logLevel = logging.LogLevelInfo
case 2:
logLevel = logging.LogLevelDebug
case 3:
logLevel = logging.LogLevelTrace
if model.EnableLoger {
var logLevel logging.LogLevel
switch model.Verbose {
case 0:
logLevel = logging.LogLevelWarn // default
case 1:
logLevel = logging.LogLevelInfo
case 2:
logLevel = logging.LogLevelDebug
case 3:
logLevel = logging.LogLevelTrace
}
model.Log = logging.NewDefaultLeveledLoggerForScope("", logLevel, os.Stdout)
}
model.Log = logging.NewDefaultLeveledLoggerForScope("", logLevel, os.Stdout)
if model.AddrStr != "stun.voipgate.com:3478" {
if err := stuncheck.MappingTests(model.AddrStr); err != nil {
model.NatMappingBehavior = "inconclusive" // my changes
if model.EnableLoger {
model.NatMappingBehavior = "inconclusive"
}
model.Log.Warn("NAT mapping behavior: inconclusive")
}
if err := stuncheck.FilteringTests(model.AddrStr); err != nil {
model.NatFilteringBehavior = "inconclusive" // my changes
if model.EnableLoger {
model.NatFilteringBehavior = "inconclusive"
}
model.Log.Warn("NAT filtering behavior: inconclusive")
}
} else {
Expand All @@ -58,13 +65,17 @@ func main() {
err1 := stuncheck.MappingTests(addrStr)
if err1 != nil {
model.NatMappingBehavior = "inconclusive"
model.Log.Warn("NAT mapping behavior: inconclusive")
if model.EnableLoger {
model.Log.Warn("NAT mapping behavior: inconclusive")
}
checkStatus = false
}
err2 := stuncheck.FilteringTests(addrStr)
if err2 != nil {
model.NatFilteringBehavior = "inconclusive"
model.Log.Warn("NAT filtering behavior: inconclusive")
if model.EnableLoger {
model.Log.Warn("NAT filtering behavior: inconclusive")
}
checkStatus = false
}
if model.NatMappingBehavior == "inconclusive" || model.NatFilteringBehavior == "inconclusive" {
Expand All @@ -78,5 +89,5 @@ func main() {
}
}
res := stuncheck.CheckType()
fmt.Printf("NAT Type: %s", res)
fmt.Printf("NAT Type: %s\n", res)
}
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var (
Log logging.LeveledLogger
NatMappingBehavior string
NatFilteringBehavior string
EnableLoger = true
)
Loading

0 comments on commit 631eff3

Please sign in to comment.