xjasonlyu/tun2socks

View on GitHub

Showing 39 of 39 total issues

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

package dialer

import (
    "net"
    "syscall"
Severity: Major
Found in dialer/sockopt_freebsd.go and 1 other location - About 2 hrs to fix
dialer/sockopt_openbsd.go on lines 1..33

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

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

package dialer

import (
    "net"
    "syscall"
Severity: Major
Found in dialer/sockopt_openbsd.go and 1 other location - About 2 hrs to fix
dialer/sockopt_freebsd.go on lines 1..33

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

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 netstack has 64 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func netstack(k *Key) (err error) {
    if k.Proxy == "" {
        return errors.New("empty proxy")
    }
    if k.Device == "" {
Severity: Minor
Found in engine/engine.go - About 1 hr to fix

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

    func NewTCPTracker(conn net.Conn, metadata *M.Metadata, manager *Manager) net.Conn {
        id, _ := uuid.NewRandom()
    
        tt := &tcpTracker{
            Conn:    conn,
    Severity: Major
    Found in tunnel/statistic/tracker.go and 1 other location - About 1 hr to fix
    tunnel/statistic/tracker.go on lines 104..121

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

    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

    func NewUDPTracker(conn net.PacketConn, metadata *M.Metadata, manager *Manager) net.PacketConn {
        id, _ := uuid.NewRandom()
    
        ut := &udpTracker{
            PacketConn: conn,
    Severity: Major
    Found in tunnel/statistic/tracker.go and 1 other location - About 1 hr to fix
    tunnel/statistic/tracker.go on lines 34..51

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

    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 ClientHandshake has 14 return statements (exceeds 4 allowed).
    Open

    func ClientHandshake(rw io.ReadWriter, addr Addr, command Command, user *User) (Addr, error) {
        buf := make([]byte, MaxAddrLen)
    
        var method uint8
        if user != nil {
    Severity: Major
    Found in transport/socks5/socks5.go - About 1 hr to fix

      Method Relay.dialContext has 54 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (rl *Relay) dialContext(ctx context.Context, metadata *M.Metadata) (rc *relayConn, err error) {
          var c net.Conn
      
          c, err = dialer.DialContext(ctx, "tcp", rl.Addr())
          if err != nil {
      Severity: Minor
      Found in proxy/relay.go - About 1 hr to fix

        Function netstack has 10 return statements (exceeds 4 allowed).
        Open

        func netstack(k *Key) (err error) {
            if k.Proxy == "" {
                return errors.New("empty proxy")
            }
            if k.Device == "" {
        Severity: Major
        Found in engine/engine.go - About 1 hr to fix

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

          func WithTCPSendBufferSizeRange(a, b, c int) Option {
              return func(s *stack.Stack) error {
                  sndOpt := tcpip.TCPSendBufferSizeRangeOption{Min: a, Default: b, Max: c}
                  if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &sndOpt); err != nil {
                      return fmt.Errorf("set TCP send buffer size range: %s", err)
          Severity: Minor
          Found in core/option/option.go and 1 other location - About 1 hr to fix
          core/option/option.go on lines 196..204

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

          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

          func WithTCPReceiveBufferSizeRange(a, b, c int) Option {
              return func(s *stack.Stack) error {
                  rcvOpt := tcpip.TCPReceiveBufferSizeRangeOption{Min: a, Default: b, Max: c}
                  if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &rcvOpt); err != nil {
                      return fmt.Errorf("set TCP receive buffer size range: %s", err)
          Severity: Minor
          Found in core/option/option.go and 1 other location - About 1 hr to fix
          core/option/option.go on lines 174..182

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

          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

          func WithTCPReceiveBufferSize(size int) Option {
              return func(s *stack.Stack) error {
                  rcvOpt := tcpip.TCPReceiveBufferSizeRangeOption{Min: tcpMinBufferSize, Default: size, Max: tcpMaxBufferSize}
                  if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &rcvOpt); err != nil {
                      return fmt.Errorf("set TCP receive buffer size range: %s", err)
          Severity: Minor
          Found in core/option/option.go and 1 other location - About 55 mins to fix
          core/option/option.go on lines 163..171

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

          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

          func WithTCPSendBufferSize(size int) Option {
              return func(s *stack.Stack) error {
                  sndOpt := tcpip.TCPSendBufferSizeRangeOption{Min: tcpMinBufferSize, Default: size, Max: tcpMaxBufferSize}
                  if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &sndOpt); err != nil {
                      return fmt.Errorf("set TCP send buffer size range: %s", err)
          Severity: Minor
          Found in core/option/option.go and 1 other location - About 55 mins to fix
          core/option/option.go on lines 185..193

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

          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 Relay.dialContext has 7 return statements (exceeds 4 allowed).
          Open

          func (rl *Relay) dialContext(ctx context.Context, metadata *M.Metadata) (rc *relayConn, err error) {
              var c net.Conn
          
              c, err = dialer.DialContext(ctx, "tcp", rl.Addr())
              if err != nil {
          Severity: Major
          Found in proxy/relay.go - About 45 mins to fix

            Method Socks5.DialUDP has 7 return statements (exceeds 4 allowed).
            Open

            func (ss *Socks5) DialUDP(*M.Metadata) (_ net.PacketConn, err error) {
                if ss.unix {
                    return nil, fmt.Errorf("%w when unix domain socket is enabled", errors.ErrUnsupported)
                }
            
            
            Severity: Major
            Found in proxy/socks5.go - About 45 mins to fix

              Function setSocketOptions has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
              Open

              func setSocketOptions(network, address string, c syscall.RawConn, opts *Options) (err error) {
                  if opts == nil || !isTCPSocket(network) && !isUDPSocket(network) {
                      return
                  }
              
              
              Severity: Minor
              Found in dialer/sockopt_linux.go - About 45 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

              Avoid deeply nested control flow statements.
              Open

                                  if j < len(keys)-1 {
                                      b.WriteByte(',')
                                  }
              Severity: Major
              Found in restapi/netstats.go - About 45 mins to fix

                Function ClientHandshake has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                Open

                func ClientHandshake(rw io.ReadWriter, addr Addr, command Command, user *User) (Addr, error) {
                    buf := make([]byte, MaxAddrLen)
                
                    var method uint8
                    if user != nil {
                Severity: Minor
                Found in transport/socks5/socks5.go - About 45 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 setSocketOptions has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                Open

                func setSocketOptions(network, address string, c syscall.RawConn, opts *Options) (err error) {
                    if opts == nil || !isTCPSocket(network) && !isUDPSocket(network) {
                        return
                    }
                
                
                Severity: Minor
                Found in dialer/sockopt_windows.go - About 45 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 4 locations. Consider refactoring.
                Open

                func WithTCPModerateReceiveBuffer(v bool) Option {
                    return func(s *stack.Stack) error {
                        opt := tcpip.TCPModerateReceiveBufferOption(v)
                        if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &opt); err != nil {
                            return fmt.Errorf("set TCP moderate receive buffer: %s", err)
                Severity: Major
                Found in core/option/option.go and 3 other locations - About 45 mins to fix
                core/option/option.go on lines 207..215
                core/option/option.go on lines 218..226
                core/option/option.go on lines 240..248

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

                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 WithTCPDelay(v bool) Option {
                    return func(s *stack.Stack) error {
                        opt := tcpip.TCPDelayEnabled(v)
                        if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &opt); err != nil {
                            return fmt.Errorf("set TCP delay: %s", err)
                Severity: Major
                Found in core/option/option.go and 3 other locations - About 45 mins to fix
                core/option/option.go on lines 207..215
                core/option/option.go on lines 229..237
                core/option/option.go on lines 240..248

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

                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