zhuhaow/NEKit

View on GitHub

Showing 607 of 607 total issues

Function output has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

            public override func output(data: Data) {
                let fullBlockCount = data.count / DATA_BLOCK_SIZE
                var outputSize = fullBlockCount * (DATA_BLOCK_SIZE + 10 + 2)
                if data.count > fullBlockCount * DATA_BLOCK_SIZE {
                    outputSize += data.count - fullBlockCount * DATA_BLOCK_SIZE + 10 + 2
Severity: Minor
Found in src/Socket/AdapterSocket/Shadowsocks/StreamObfuscater.swift - About 1 hr to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    import Foundation
    
    /// Factory building HTTP adapter.
    open class HTTPAdapterFactory: HTTPAuthenticationAdapterFactory {
        required public init(serverHost: String, serverPort: Int, auth: HTTPAuthentication?) {
    Severity: Major
    Found in src/Socket/AdapterSocket/Factory/HTTPAdapterFactory.swift and 1 other location - About 1 hr to fix
    src/Socket/AdapterSocket/Factory/SecureHTTPAdapterFactory.swift on lines 1..21

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 105.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    import Foundation
    
    /// Factory building secured HTTP (HTTP with SSL) adapter.
    open class SecureHTTPAdapterFactory: HTTPAdapterFactory {
        required public init(serverHost: String, serverPort: Int, auth: HTTPAuthentication?) {
    src/Socket/AdapterSocket/Factory/HTTPAdapterFactory.swift on lines 1..21

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 105.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function readPackets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        fileprivate func readPackets() {
            packetFlow?.readPackets { packets, versions in
                QueueFactory.getQueue().async {
                    for (i, packet) in packets.enumerated() {
                        for stack in self.stacks {
    Severity: Minor
    Found in src/IPStack/TUNInterface.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 mask has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        func mask(baseIP: IPAddress) -> (IPAddress, IPAddress)? {
            switch (self, baseIP.address) {
            case (.IPv4(var m), .IPv4(let addr)):
                guard m <= 32 else {
                    return nil
    Severity: Minor
    Found in src/Utils/IPMask.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    import Foundation
    
    public class IPAddress: CustomStringConvertible, Comparable {
        public enum Family {
            case IPv4, IPv6
    Severity: Major
    Found in src/Utils/IPAddress.swift and 1 other location - About 1 hr to fix
    src/Utils/IPAddress.swift on lines 1..208

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 104.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        var digestLength: Int {
            var result: Int32 = 0
            switch self {
            case .MD5:      result = CC_MD5_DIGEST_LENGTH
            case .SHA1:     result = CC_SHA1_DIGEST_LENGTH
    Severity: Major
    Found in src/Crypto/CryptoEnum.swift and 1 other location - About 1 hr to fix
    src/Crypto/CryptoEnum.swift on lines 24..35

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        func setPayloadWithUInt32(_ value: UInt32, at: Int, swap: Bool = true) {
            var v: UInt32
            if swap {
                v = CFSwapInt32HostToBig(value)
            } else {
    Severity: Major
    Found in src/IPStack/Packet/IPPacket.swift and 3 other locations - About 1 hr to fix
    src/IPStack/DNS/DNSMessage.swift on lines 151..161
    src/IPStack/DNS/DNSMessage.swift on lines 163..173
    src/IPStack/Packet/IPPacket.swift on lines 295..305

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        func setPayloadWithUInt32(_ value: UInt32, at: Int, swap: Bool = false) {
            var v: UInt32
            if swap {
                v = NSSwapHostIntToBig(value)
            } else {
    Severity: Major
    Found in src/IPStack/DNS/DNSMessage.swift and 3 other locations - About 1 hr to fix
    src/IPStack/DNS/DNSMessage.swift on lines 151..161
    src/IPStack/Packet/IPPacket.swift on lines 295..305
    src/IPStack/Packet/IPPacket.swift on lines 307..317

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        func setPayloadWithUInt16(_ value: UInt16, at: Int, swap: Bool = true) {
            var v: UInt16
            if swap {
                v = CFSwapInt16HostToBig(value)
            } else {
    Severity: Major
    Found in src/IPStack/Packet/IPPacket.swift and 3 other locations - About 1 hr to fix
    src/IPStack/DNS/DNSMessage.swift on lines 151..161
    src/IPStack/DNS/DNSMessage.swift on lines 163..173
    src/IPStack/Packet/IPPacket.swift on lines 307..317

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        func setPayloadWithUInt16(_ value: UInt16, at: Int, swap: Bool = false) {
            var v: UInt16
            if swap {
                v = NSSwapHostShortToBig(value)
            } else {
    Severity: Major
    Found in src/IPStack/DNS/DNSMessage.swift and 3 other locations - About 1 hr to fix
    src/IPStack/DNS/DNSMessage.swift on lines 163..173
    src/IPStack/Packet/IPPacket.swift on lines 295..305
    src/IPStack/Packet/IPPacket.swift on lines 307..317

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        var HMACAlgorithm: CCHmacAlgorithm {
            var result: Int = 0
            switch self {
            case .MD5:      result = kCCHmacAlgMD5
            case .SHA1:     result = kCCHmacAlgSHA1
    Severity: Major
    Found in src/Crypto/CryptoEnum.swift and 1 other location - About 1 hr to fix
    src/Crypto/CryptoEnum.swift on lines 37..48

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function update has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        open func update(_ data: inout Data) {
            guard data.count > 0 else {
                return
            }
    
    
    Severity: Minor
    Found in src/Crypto/SodiumStreamCrypto.swift - About 1 hr to fix

      Function input has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func input(_ data: Data) throws -> Result {
              switch nextAction {
              case .readHeader:
                  let header: HTTPHeader
                  do {
      Severity: Minor
      Found in src/Utils/HTTPStreamScanner.swift - About 1 hr to fix

        Function mask has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func mask(baseIP: IPAddress) -> (IPAddress, IPAddress)? {
                switch (self, baseIP.address) {
                case (.IPv4(var m), .IPv4(let addr)):
                    guard m <= 32 else {
                        return nil
        Severity: Minor
        Found in src/Utils/IPMask.swift - About 1 hr to fix

          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 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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static func parseAllRule(_ config: Yaml, adapterFactoryManager: AdapterFactoryManager) throws -> AllRule {
                  guard let adapter_id = config["adapter"].stringOrIntString else {
                      throw ConfigurationParserError.ruleParsingError(errorInfo: "An adapter id (adapter_id) is required.")
                  }
          
          
          Severity: Major
          Found in src/Config/RuleParser.swift and 1 other location - About 1 hr to fix
          src/Config/RuleParser.swift on lines 130..140

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 93.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              static func parseDNSFailRule(_ config: Yaml, adapterFactoryManager: AdapterFactoryManager) throws -> DNSFailRule {
                  guard let adapter_id = config["adapter"].stringOrIntString else {
                      throw ConfigurationParserError.ruleParsingError(errorInfo: "An adapter id (adapter_id) is required.")
                  }
          
          
          Severity: Major
          Found in src/Config/RuleParser.swift and 1 other location - About 1 hr to fix
          src/Config/RuleParser.swift on lines 59..69

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 93.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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
            Severity
            Category
            Status
            Source
            Language