zhenkyle/shadowsocks_ruby

View on GitHub

Showing 37 of 37 total issues

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

      def tcp_receive_from_client_first_packet n
        # check version
        version = async_recv(1).unpack("C").first
        if version != SOCKS5
          raise PharseError, "SOCKS version not supported: #{version.inspect}"
Severity: Major
Found in lib/shadowsocks_ruby/protocols/packet/socks5.rb and 1 other location - About 3 hrs to fix
lib/shadowsocks_ruby/protocols/packet/socks5.rb on lines 86..130

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

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

      def tcp_receive_from_localbackend_first_packet n
        # check version
        version = async_recv(1).unpack("C").first
        if version != SOCKS5
          raise PharseError, "SOCKS version not supported: #{version.inspect}"
Severity: Major
Found in lib/shadowsocks_ruby/protocols/packet/socks5.rb and 1 other location - About 3 hrs to fix
lib/shadowsocks_ruby/protocols/packet/socks5.rb on lines 30..73

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

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

Method execute! has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def execute!
        # here sets default options
        options        = {
                           :port => 8388,
                           :local_addr => '0.0.0.0',
Severity: Major
Found in lib/shadowsocks_ruby/cli/sslocal_runner.rb - About 3 hrs to fix

    Method execute! has 83 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def execute!
            # here sets default options
            options        = {
                               :server => '0.0.0.0',
                               :port => 8388,
    Severity: Major
    Found in lib/shadowsocks_ruby/cli/ssserver_runner.rb - About 3 hrs to fix

      Method bytes_to_key1 has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def bytes_to_key1(salt, data, count, nkey, niv)
            key = ''
            iv = ''
            md_buf = ''
      
      
      Severity: Minor
      Found in lib/shadowsocks_ruby/cipher/cipher.rb - About 3 hrs 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

      Method build! has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def build! conn
              cipher = nil
      
              protocols = @cfg_ary.map do | klass, params|
                case klass.to_s
      Severity: Major
      Found in lib/shadowsocks_ruby/protocols/protocol_stack.rb - About 2 hrs to fix

        File tls_ticket.rb has 262 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'lrucache'
        
        module ShadowsocksRuby
          module Protocols
            # TLS 1.2 Obfuscation Protocol
        Severity: Minor
        Found in lib/shadowsocks_ruby/protocols/obfs/tls_ticket.rb - About 2 hrs to fix

          Method tcp_receive_from_localbackend_first_packet has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

                def tcp_receive_from_localbackend_first_packet n
                  data = async_recv 10
                  if (data =~ /^GET|^POST/) == nil
                    if @params[:compatible]
                      @buffer << data << async_recv(n - data.length)
          Severity: Minor
          Found in lib/shadowsocks_ruby/protocols/obfs/http_simple.rb - About 2 hrs 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

          Method recv_client_hello has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def recv_client_hello
                  data = async_recv 3
                  if data != [CTYPE_Handshake, *VERSION_TLS_1_0].pack("C3")
                    if @params[:compatible]
                      @buffer = data
          Severity: Minor
          Found in lib/shadowsocks_ruby/protocols/obfs/tls_ticket.rb - About 1 hr to fix

            Method recv_client_hello has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def recv_client_hello
                    data = async_recv 3
                    if data != [CTYPE_Handshake, *VERSION_TLS_1_0].pack("C3")
                      if @params[:compatible]
                        @buffer = data
            Severity: Minor
            Found in lib/shadowsocks_ruby/protocols/obfs/tls_ticket.rb - 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

            Method tcp_receive_from_localbackend_first_packet has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def tcp_receive_from_localbackend_first_packet n
                    # check version
                    version = async_recv(1).unpack("C").first
                    if version != SOCKS5
                      raise PharseError, "SOCKS version not supported: #{version.inspect}"
            Severity: Minor
            Found in lib/shadowsocks_ruby/protocols/packet/socks5.rb - About 1 hr to fix

              Method tcp_receive_from_client_first_packet has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def tcp_receive_from_client_first_packet n
                      # check version
                      version = async_recv(1).unpack("C").first
                      if version != SOCKS5
                        raise PharseError, "SOCKS version not supported: #{version.inspect}"
              Severity: Minor
              Found in lib/shadowsocks_ruby/protocols/packet/socks5.rb - About 1 hr to fix

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

                      def tcp_receive_from_remoteserver_in_buffer n
                        if n == -1
                          class << self
                            alias tcp_receive_from_remoteserver tcp_receive_from_remoteserver_other_packet
                          end
                Severity: Major
                Found in lib/shadowsocks_ruby/protocols/protocol.rb and 1 other location - About 1 hr to fix
                lib/shadowsocks_ruby/protocols/protocol.rb on lines 141..159

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

                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

                      def tcp_receive_from_localbackend_in_buffer n
                        if n == -1
                          class << self
                            alias tcp_receive_from_localbackend tcp_receive_from_localbackend_other_packet
                          end
                Severity: Major
                Found in lib/shadowsocks_ruby/protocols/protocol.rb and 1 other location - About 1 hr to fix
                lib/shadowsocks_ruby/protocols/protocol.rb on lines 101..119

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

                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

                Method tcp_send_to_remoteserver_first_packet has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def tcp_send_to_remoteserver_first_packet data
                        if data.length > 30 + 64
                          headlen = 30 + Random.rand(64 + 1)
                        else
                          headlen = data.length
                Severity: Minor
                Found in lib/shadowsocks_ruby/protocols/obfs/http_simple.rb - About 1 hr to fix

                  Method send_client_hello has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def send_client_hello
                          client_hello = ""
                          
                          client_hello << [*VERSION_TLS_1_2].pack("C2") # ProtocolVersion
                          client_hello << get_random # Random len 32
                  Severity: Minor
                  Found in lib/shadowsocks_ruby/protocols/obfs/tls_ticket.rb - About 1 hr to fix

                    Method execute! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def execute!
                            # here sets default options
                            options        = {
                                               :port => 8388,
                                               :local_addr => '0.0.0.0',
                    Severity: Minor
                    Found in lib/shadowsocks_ruby/cli/sslocal_runner.rb - 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

                    Method initialize has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def initialize
                          @options = @@options
                    
                          @totalcounter = 0
                          @maxcounter = 0
                    Severity: Minor
                    Found in lib/shadowsocks_ruby/app.rb - About 1 hr to fix

                      Method tcp_receive_from_localbackend_first_packet has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            def tcp_receive_from_localbackend_first_packet n
                              data = async_recv 10
                              if (data =~ /^GET|^POST/) == nil
                                if @params[:compatible]
                                  @buffer << data << async_recv(n - data.length)
                      Severity: Minor
                      Found in lib/shadowsocks_ruby/protocols/obfs/http_simple.rb - About 1 hr to fix

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

                              def tcp_receive_from_localbackend_other_packet_helper n
                                if n == -1
                                  return @buffer.slice!(0, @buffer.length)
                                elsif n < @buffer.length
                                  class << self
                        Severity: Major
                        Found in lib/shadowsocks_ruby/protocols/protocol.rb and 1 other location - About 1 hr to fix
                        lib/shadowsocks_ruby/protocols/protocol.rb on lines 83..98

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

                        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