zhuhaow/NEKit

View on GitHub

Showing 607 of 607 total issues

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

    open func forceDisconnect(becauseOf error: Error? = nil) {
        guard !isCancelled else {
            return
        }

Severity: Major
Found in src/Socket/ProxySocket/ProxySocket.swift and 1 other location - About 1 hr to fix
src/Socket/ProxySocket/ProxySocket.swift on lines 93..103

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

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

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

        public static func ^=(_ lhs: inout UInt128, _ rhs: UInt128) {
            let upperBits = lhs.value.upperBits ^ rhs.value.upperBits
            let lowerBits = lhs.value.lowerBits ^ rhs.value.lowerBits
            
            lhs = UInt128(upperBits: upperBits, lowerBits: lowerBits)
    Severity: Major
    Found in src/Utils/UInt128.swift and 2 other locations - About 1 hr to fix
    src/Utils/UInt128.swift on lines 523..528
    src/Utils/UInt128.swift on lines 531..536

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

    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 3 locations. Consider refactoring.
    Open

        public static func &=(_ lhs: inout UInt128, _ rhs: UInt128) {
            let upperBits = lhs.value.upperBits & rhs.value.upperBits
            let lowerBits = lhs.value.lowerBits & rhs.value.lowerBits
            
            lhs = UInt128(upperBits: upperBits, lowerBits: lowerBits)
    Severity: Major
    Found in src/Utils/UInt128.swift and 2 other locations - About 1 hr to fix
    src/Utils/UInt128.swift on lines 531..536
    src/Utils/UInt128.swift on lines 539..544

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

    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 3 locations. Consider refactoring.
    Open

        public static func |=(_ lhs: inout UInt128, _ rhs: UInt128) {
            let upperBits = lhs.value.upperBits | rhs.value.upperBits
            let lowerBits = lhs.value.lowerBits | rhs.value.lowerBits
            
            lhs = UInt128(upperBits: upperBits, lowerBits: lowerBits)
    Severity: Major
    Found in src/Utils/UInt128.swift and 2 other locations - About 1 hr to fix
    src/Utils/UInt128.swift on lines 523..528
    src/Utils/UInt128.swift on lines 539..544

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

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

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

            public static func peekSourceAddress(_ data: Data) -> IPAddress? {
                guard data.count >= 20 else {
                    return nil
                }
        
        
        Severity: Minor
        Found in src/IPStack/Packet/IPPacket.swift and 1 other location - About 55 mins to fix
        src/IPStack/Packet/IPPacket.swift on lines 69..75

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

        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

            public static func peekDestinationAddress(_ data: Data) -> IPAddress? {
                guard data.count >= 20 else {
                    return nil
                }
        
        
        Severity: Minor
        Found in src/IPStack/Packet/IPPacket.swift and 1 other location - About 55 mins to fix
        src/IPStack/Packet/IPPacket.swift on lines 54..60

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

        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

            open func disconnect(becauseOf error: Error? = nil) {
                _status = .disconnecting
                _cancelled = true
                session.disconnected(becauseOf: error, by: .adapter)
                observer?.signal(.disconnectCalled(self))
        Severity: Minor
        Found in src/Socket/AdapterSocket/AdapterSocket.swift and 1 other location - About 55 mins to fix
        src/Socket/AdapterSocket/AdapterSocket.swift on lines 105..111

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

        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

            open func forceDisconnect(becauseOf error: Error? = nil) {
                _status = .disconnecting
                _cancelled = true
                session.disconnected(becauseOf: error, by: .adapter)
                observer?.signal(.forceDisconnectCalled(self))
        Severity: Minor
        Found in src/Socket/AdapterSocket/AdapterSocket.swift and 1 other location - About 55 mins to fix
        src/Socket/AdapterSocket/AdapterSocket.swift on lines 94..100

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

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

        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 writeAllRecordAt has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            fileprivate func writeAllRecordAt(_ at: Int) -> Bool {
                var position = at
                for query in queries {
                    guard writeDNSQuery(query, at: position) else {
                        return false
        Severity: Minor
        Found in src/IPStack/DNS/DNSMessage.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 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

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

            enum SOCKS5ProxyWriteStatus: CustomStringConvertible {
                case invalid,
                sendingResponse,
                forwarding,
                stopped
        Severity: Minor
        Found in src/Socket/ProxySocket/SOCKS5ProxySocket.swift and 1 other location - About 55 mins to fix
        src/Socket/ProxySocket/HTTPProxySocket.swift on lines 30..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 64.

        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

            enum HTTPProxyWriteStatus: CustomStringConvertible {
                case invalid,
                sendingConnectResponse,
                forwarding,
                stopped
        Severity: Minor
        Found in src/Socket/ProxySocket/HTTPProxySocket.swift and 1 other location - About 55 mins to fix
        src/Socket/ProxySocket/SOCKS5ProxySocket.swift on lines 45..63

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

        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

                let rangeCorrectSamples = [
                    ("127.0.0.1+3", [IPAddress(fromString: "127.0.0.1")!]),
                    ("255.255.255.255+0", [IPAddress(fromString: "255.255.255.255")!]),
                    ("0.0.0.0+4294967295", [IPAddress(fromString: "0.0.0.0")!])
                ]
        Severity: Minor
        Found in test/Utils/IPRangeSpec.swift and 1 other location - About 50 mins to fix
        test/Utils/IPRangeSpec.swift on lines 15..19

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

        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

        Severity
        Category
        Status
        Source
        Language