xjasonlyu/tun2socks

View on GitHub

Showing 25 of 39 total issues

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

    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

          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

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

            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

              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

                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

                Function getConnections has 6 return statements (exceeds 4 allowed).
                Open

                func getConnections(w http.ResponseWriter, r *http.Request) {
                    if !websocket.IsWebSocketUpgrade(r) {
                        render.JSON(w, r, statistic.DefaultManager.Snapshot())
                        return
                    }
                Severity: Major
                Found in restapi/connections.go - About 40 mins to fix

                  Method Reader.read has 6 return statements (exceeds 4 allowed).
                  Open

                  func (r *Reader) read(p []byte) (int, error) {
                      nonce := r.nonce[:r.NonceSize()]
                      tag := r.Overhead()
                  
                      // decrypt payload size
                  Severity: Major
                  Found in transport/shadowsocks/shadowaead/stream.go - About 40 mins to fix

                    Function ReadAddr has 6 return statements (exceeds 4 allowed).
                    Open

                    func ReadAddr(r io.Reader, b []byte) (Addr, error) {
                        if len(b) < MaxAddrLen {
                            return nil, io.ErrShortBuffer
                        }
                    
                    
                    Severity: Major
                    Found in transport/socks5/socks5.go - About 40 mins to fix

                      Function Open has 6 return statements (exceeds 4 allowed).
                      Open

                      func Open(name string, mtu uint32) (device.Device, error) {
                          t := &TUN{name: name, mtu: mtu}
                      
                          if len(t.name) >= unix.IFNAMSIZ {
                              return nil, fmt.Errorf("interface name too long: %s", t.name)
                      Severity: Major
                      Found in core/device/tun/tun_netstack.go - About 40 mins to fix

                        Method emitter.Emit has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (emitter) Emit(depth int, level glog.Level, _ time.Time, format string, args ...any) {
                        Severity: Minor
                        Found in log/emitter.go - About 35 mins to fix

                          Method Addr.Valid has 5 return statements (exceeds 4 allowed).
                          Open

                          func (a Addr) Valid() bool {
                              if len(a) < 1+1+2 /* minimum length */ {
                                  return false
                              }
                          
                          
                          Severity: Major
                          Found in transport/socks5/socks5.go - About 35 mins to fix

                            Function setSocketOptions has 5 return statements (exceeds 4 allowed).
                            Open

                            func setSocketOptions(network, address string, c syscall.RawConn, opts *Options) (err error) {
                                if opts == nil || !isTCPSocket(network) && !isUDPSocket(network) {
                                    return
                                }
                            
                            
                            Severity: Major
                            Found in dialer/sockopt_linux.go - About 35 mins to fix

                              Method TLSObfs.read has 5 return statements (exceeds 4 allowed).
                              Open

                              func (to *TLSObfs) read(b []byte, discardN int) (int, error) {
                                  buf := pool.Get(discardN)
                                  _, err := io.ReadFull(to.Conn, buf)
                                  if err != nil {
                                      return 0, err
                              Severity: Major
                              Found in transport/simple-obfs/tls.go - About 35 mins to fix

                                Function ClientHandshake has 5 return statements (exceeds 4 allowed).
                                Open

                                func ClientHandshake(rw io.ReadWriter, addr string, command Command, userID string) (err error) {
                                    var (
                                        host string
                                        port uint16
                                    )
                                Severity: Major
                                Found in transport/socks4/socks4.go - About 35 mins to fix

                                  Method relayConn.Read has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (rc *relayConn) Read(b []byte) (n int, err error) {
                                      rc.once.Do(func() {
                                          if rc.wbuf != nil {
                                              err = readRelayResponse(rc.Conn)
                                          }
                                  Severity: Major
                                  Found in proxy/relay.go - About 35 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language