Showing 7 of 26 total issues

Function handleDNSQuery has 9 return statements (exceeds 4 allowed).
Open

func handleDNSQuery(w http.ResponseWriter, r *http.Request) {
    var body []byte
    var err error

    switch r.Method {
Severity: Major
Found in cmd/web/main.go - About 55 mins to fix

    Method Client.IsBad has 8 return statements (exceeds 4 allowed).
    Open

    func (client *Client) IsBad(parent context.Context, msg *queue.DomainAccessMessage) bool {
        ctx, cancel := context.WithTimeout(parent, timeout)
        defer cancel()
    
        request, err := http.NewRequestWithContext(ctx, "POST", url+"/v1/host", bytes.NewBuffer([]byte("host="+msg.Domain)))
    Severity: Major
    Found in pkg/urlhaus/api.go - About 50 mins to fix

      Function resolve has 7 return statements (exceeds 4 allowed).
      Open

      func resolve(ctx context.Context, question dnsmessage.Question, request []byte) []byte {
          if err := sem.Acquire(ctx, 1); err != nil {
              return nil
          }
          defer sem.Release(1)
      Severity: Major
      Found in cmd/web/main.go - About 45 mins to fix

        Function resolve has 7 return statements (exceeds 4 allowed).
        Open

        func resolve(ctx context.Context, request []byte) []byte {
            post, err := http.NewRequestWithContext(ctx, "POST", server, bytes.NewBuffer(request))
            if err != nil {
                log.Println("Resolving failed: ", err)
                return nil
        Severity: Major
        Found in cmd/stub/main.go - About 45 mins to fix

          Method Cache.Set has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func (c *Cache) Set(ctx context.Context, domain string, requestType dnsmessage.Type, response []byte, expiry int) {
          Severity: Minor
          Found in pkg/cache/cache.go - About 35 mins to fix

            Function ReplaceTTLInResponse has 5 return statements (exceeds 4 allowed).
            Open

            func ReplaceTTLInResponse(response []byte, TTL uint32) ([]byte, error) {
                var p dnsmessage.Parser
            
                header, err := p.Start(response)
                if err != nil {
            Severity: Major
            Found in pkg/dns/ttl.go - About 35 mins to fix

              Function main has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
              Open

              func main() {
                  flag.StringVar(&server, "server", "https://dohli.herokuapp.com/dns-query", "DoH server to use")
                  flag.Parse()
              
                  l, err := net.ListenPacket("udp4", ":53")
              Severity: Minor
              Found in cmd/stub/main.go - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Severity
              Category
              Status
              Source
              Language