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

(WIP) Cirrus: Mark cyclop linter as mandatory #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ task:
- name: "Go Lint $GOOS Mandatory$MODULES_NAME"
env:
# TODO: Re-enable varnamelen after golangci-lint v1.44 is released.
GOLANGCI_ARGS: "--disable=cyclop,deadcode,errorlint,exhaustivestruct,forbidigo,forcetypeassert,funlen,gci,gocognit,gocritic,godot,godox,goerr113,gofumpt,goimports,golint,gosec,gosimple,govet,ineffassign,lll,maligned,nakedret,nestif,nilerr,nlreturn,paralleltest,revive,scopelint,staticcheck,stylecheck,thelper,unconvert,unparam,unused,varnamelen,wastedassign,whitespace,wrapcheck,wsl"
GOLANGCI_ARGS: "--disable=deadcode,errorlint,exhaustivestruct,forbidigo,forcetypeassert,funlen,gci,gocognit,gocritic,godot,godox,goerr113,gofumpt,goimports,golint,gosec,gosimple,govet,ineffassign,lll,maligned,nakedret,nestif,nilerr,nlreturn,paralleltest,revive,scopelint,staticcheck,stylecheck,thelper,unconvert,unparam,unused,varnamelen,wastedassign,whitespace,wrapcheck,wsl"
- name: "Go Lint $GOOS$MODULES_NAME"
env:
GOLANGCI_ARGS: ""
Expand Down
125 changes: 65 additions & 60 deletions ncprop279.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ func (rw *prop279ResponseWriter) WriteMsg(res *dns.Msg) error {
*rw.result = StatusNxDomain
case dns.RcodeRefused:
*rw.result = StatusNotInZone

qname := ""
if len(res.Question) >= 1 {
qname = res.Question[0].Name
}

fmt.Printf("RESOLVED %d %d \"FQDN '%s' not in Namecoin zone\"\n", rw.queryID, *rw.result, qname)
case dns.RcodeSuccess:
if rw.parseOnion {
for _, answer := range res.Answer {
Expand Down Expand Up @@ -254,75 +247,87 @@ func (s *Server) doResolve(queryID int, qname string, qtype uint16, parseOnion b
return result
}

func runCommand(words []string, cfg *Config, s *Server) {
if len(words) < 1 {
func runResolveCommand(args []string, cfg *Config, s *Server) {
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "Not enough arguments to RESOLVE command.\n")
return
}

if words[0] == "RESOLVE" {
if len(words) < 3 {
fmt.Fprintf(os.Stderr, "Not enough arguments to RESOLVE command.\n")
return
}
queryIDStr := args[0]
queryID, err := strconv.Atoi(queryIDStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Query ID '%s' was not an integer.\n", queryIDStr)
return
}

queryIDStr := words[1]
queryID, err := strconv.Atoi(queryIDStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Query ID '%s' was not an integer.\n", queryIDStr)
return
}
name := args[1]
originalName := name
onlyOnion := cfg.OnlyOnion

name := words[2]
originalName := name
onlyOnion := cfg.OnlyOnion
if strings.HasSuffix(name, ".onion") {
name = strings.TrimSuffix(name, ".onion")
onlyOnion = true
}

if strings.HasSuffix(name, ".onion") {
name = strings.TrimSuffix(name, ".onion")
onlyOnion = true
}
streamID := ""
if len(args) >= 3 {
streamID = args[2]
}
if streamID == "" {
fmt.Fprintf(os.Stderr, "WARNING: Missing stream isolation ID from Prop279 client; stream isolation won't work properly. Maybe your Prop279 client is outdated?\n")
}

streamID := ""
if len(words) >= 4 {
streamID = words[3]
}
if streamID == "" {
fmt.Fprintf(os.Stderr, "WARNING: Missing stream isolation ID from Prop279 client; stream isolation won't work properly. Maybe your Prop279 client is outdated?\n")
}
result := StatusNxDomain

result := StatusNxDomain
if result == StatusNxDomain {
result = s.doResolve(queryID, "_tor."+name, dns.TypeTXT, true, streamID)
}

if !onlyOnion {
if result == StatusNxDomain {
result = s.doResolve(queryID, "_tor."+name, dns.TypeTXT, true, streamID)
}

if !onlyOnion {
if result == StatusNxDomain {
result = s.doResolve(queryID, name, dns.TypeA, false, streamID)
}
if result == StatusNxDomain {
result = s.doResolve(queryID, name, dns.TypeAAAA, false, streamID)
}
if result == StatusNxDomain {
result = s.doResolve(queryID, name, dns.TypeCNAME, false, streamID)
}
result = s.doResolve(queryID, name, dns.TypeA, false, streamID)
}
if result == StatusNxDomain {
fmt.Printf("RESOLVED %d %d \"%s is not registered\"\n", queryID, result, originalName)
result = s.doResolve(queryID, name, dns.TypeAAAA, false, streamID)
}
} else if words[0] == "CANCEL" {
if len(words) < 2 {
fmt.Fprintf(os.Stderr, "Not enough arguments to CANCEL command.\n")
return
if result == StatusNxDomain {
result = s.doResolve(queryID, name, dns.TypeCNAME, false, streamID)
}
}
if result == StatusNxDomain {
fmt.Printf("RESOLVED %d %d \"%s is not registered\"\n", queryID, result, originalName)
}

queryIDStr := words[1]
queryID, err := strconv.Atoi(queryIDStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Query ID '%s' was not an integer.\n", queryIDStr)
return
}
if result == StatusNotInZone {
fmt.Printf("RESOLVED %d %d \"%s is not a Namecoin domain\"\n", queryID, result, originalName)
}
}

func runCancelCommand(args []string, cfg *Config, s *Server) {
if len(args) < 1 {
fmt.Fprintf(os.Stderr, "Not enough arguments to CANCEL command.\n")
return
}

queryIDStr := args[0]
queryID, err := strconv.Atoi(queryIDStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Query ID '%s' was not an integer.\n", queryIDStr)
return
}

fmt.Printf("CANCELED %d\n", queryID)
}

func runCommand(words []string, cfg *Config, s *Server) {
if len(words) < 1 {
return
}

fmt.Printf("CANCELED %d\n", queryID)
if words[0] == "RESOLVE" {
runResolveCommand(words[1:], cfg, s)
} else if words[0] == "CANCEL" {
runCancelCommand(words[1:], cfg, s)
}
}

Expand Down