zhuhaow/NEKit

View on GitHub

Showing 70 of 607 total issues

Function readCallback has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    private func readCallback(data: Data?) {
        guard !cancelled else {
            return
        }

Severity: Minor
Found in src/RawSocket/NWTCPSocket.swift - About 1 hr 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

Function getNamefromData has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    static func getNamefromData(_ data: Data, offset: Int, base: Int = 0) -> (String, Int) {
        let scanner = BinaryDataScanner(data: data, littleEndian: false)
        scanner.skip(to: offset)

        var len: UInt8 = 0
Severity: Minor
Found in src/IPStack/DNS/DNSMessage.swift - About 1 hr 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

Function didRead has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    override public func didRead(data: Data, from: RawTCPSocketProtocol) {
        super.didRead(data: data, from: from)
        
        let result: HTTPStreamScanner.Result
        do {
Severity: Minor
Found in src/Socket/ProxySocket/HTTPProxySocket.swift - About 1 hr to fix

    Function getNamefromData has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static func getNamefromData(_ data: Data, offset: Int, base: Int = 0) -> (String, Int) {
            let scanner = BinaryDataScanner(data: data, littleEndian: false)
            scanner.skip(to: offset)
    
            var len: UInt8 = 0
    Severity: Minor
    Found in src/IPStack/DNS/DNSMessage.swift - About 1 hr to fix

      Function getCrypto has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              private func getCrypto(_ operation: CryptoOperation) -> StreamCryptoProtocol {
                  switch algorithm {
                  case .AES128CFB, .AES192CFB, .AES256CFB:
                      switch operation {
                      case .decrypt:
      Severity: Minor
      Found in src/Socket/AdapterSocket/Shadowsocks/CryptoStreamProcessor.swift - About 1 hr to fix

        Function didReceive has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            open func didReceive(rawResponse: Data) {
                guard let message = DNSMessage(payload: rawResponse) else {
                    DDLogError("Failed to parse response from remote DNS server.")
                    return
                }
        Severity: Minor
        Found in src/IPStack/DNS/DNSServer.swift - About 1 hr 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

        Function parseServerAdapterFactory has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            static func parseServerAdapterFactory(_ config: Yaml, type: HTTPAuthenticationAdapterFactory.Type) throws -> ServerAdapterFactory {
                guard let host = config["host"].string else {
                    throw ConfigurationParserError.adapterParsingError(errorInfo: "Host (host) is required.")
                }
        
        
        Severity: Minor
        Found in src/Config/AdapterFactoryParser.swift - About 1 hr 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

        Function outputSession has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            fileprivate func outputSession(_ session: DNSSession) {
                guard let result = session.matchResult else {
                    return
                }
        
        
        Severity: Minor
        Found in src/IPStack/DNS/DNSServer.swift - About 1 hr to fix

          Function checkReadData has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              fileprivate func checkReadData() {
                  if pendingReadData.count > 0 {
                      queueCall {
                          guard self.reading else {
                              // no queued read request
          Severity: Minor
          Found in src/RawSocket/TUNTCPSocket.swift - About 1 hr to fix

            Function spec has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                override func spec() {
                    let testCases: [(String, Bool, String?, String?, Int?, String)] = [
                        ("http://google.com/ncr", true, "http", "google.com", nil, "ncr"),
                        ("http://google.com/", true, "http", "google.com", nil, ""),
                        ("http://google.com:8080/", true, "http", "google.com", 8080, ""),
            Severity: Minor
            Found in test/Utils/HTTPURLSpec.swift - About 1 hr to fix

              Function parseAdapterFactoryManager has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static func parseAdapterFactoryManager(_ config: Yaml) throws -> AdapterFactoryManager {
                      var factoryDict: [String: AdapterFactory] = [:]
                      factoryDict["direct"] = DirectAdapterFactory()
                      guard let adapterConfigs = config.array else {
                          throw ConfigurationParserError.noAdapterDefined
              Severity: Minor
              Found in src/Config/AdapterFactoryParser.swift - About 1 hr to fix

                Function buildMessage has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    func buildMessage() -> Bool {
                        payload = Data(count: bytesLength)
                        if transactionID == 0 {
                            transactionID = UInt16(arc4random_uniform(UInt32(UInt16.max)))
                        }
                Severity: Minor
                Found in src/IPStack/DNS/DNSMessage.swift - About 1 hr to fix

                  Function rewritePacket has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public func rewritePacket(packet: IPMutablePacket) -> IPMutablePacket? {
                          // Support only TCP as for now
                          guard packet.proto == .TCP else {
                              return nil
                          }
                  Severity: Minor
                  Found in src/IPStack/Router.swift - About 1 hr 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

                  Function rewritePacket has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public func rewritePacket(packet: IPMutablePacket) -> IPMutablePacket? {
                          // Support only TCP as for now
                          guard packet.proto == .TCP else {
                              return nil
                          }
                  Severity: Minor
                  Found in src/IPStack/Router.swift - About 1 hr to fix

                    Function didReceive has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        open func didReceive(rawResponse: Data) {
                            guard let message = DNSMessage(payload: rawResponse) else {
                                DDLogError("Failed to parse response from remote DNS server.")
                                return
                            }
                    Severity: Minor
                    Found in src/IPStack/DNS/DNSServer.swift - About 1 hr to fix

                      Function readAndProcessPackets has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          func readAndProcessPackets() {
                              NetworkInterface.TunnelProvider.packetFlow.readPacketsWithCompletionHandler() {
                                  var outputPackets = [IPMutablePacket]()
                                  let packets = $0.0.map { data in
                                      IPMutablePacket(payload: data)
                      Severity: Minor
                      Found in src/IPStack/Router.swift - About 1 hr to fix

                        Function readAndProcessPackets has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            func readAndProcessPackets() {
                                NetworkInterface.TunnelProvider.packetFlow.readPacketsWithCompletionHandler() {
                                    var outputPackets = [IPMutablePacket]()
                                    let packets = $0.0.map { data in
                                        IPMutablePacket(payload: data)
                        Severity: Minor
                        Found in src/IPStack/Router.swift - About 55 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

                        Function findSocket has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            fileprivate func findSocket(connectInfo: ConnectInfo?, socket: NWUDPSocket?) -> (ConnectInfo, NWUDPSocket)? {
                                var result: (ConnectInfo, NWUDPSocket)?
                        
                                queue.sync {
                                    if connectInfo != nil {
                        Severity: Minor
                        Found in src/IPStack/UDPDirectStack.swift - About 55 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

                        Function input has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                                    public override func input(data: Data) throws {
                                        if readingFakeHeader {
                                            buffer.append(data: data)
                                            if buffer.get(to: Utils.HTTPData.DoubleCRLF) != nil {
                                                readingFakeHeader = false
                        Severity: Minor
                        Found in src/Socket/AdapterSocket/Shadowsocks/ProtocolObfuscater.swift - About 55 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

                        Function getCrypto has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                                private func getCrypto(_ operation: CryptoOperation) -> StreamCryptoProtocol {
                                    switch algorithm {
                                    case .AES128CFB, .AES192CFB, .AES256CFB:
                                        switch operation {
                                        case .decrypt:
                        Severity: Minor
                        Found in src/Socket/AdapterSocket/Shadowsocks/CryptoStreamProcessor.swift - About 55 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