waku-org/go-waku

View on GitHub

Showing 299 of 400 total issues

Method WakuPeerExchange.onRequest has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
Open

func (wakuPX *WakuPeerExchange) onRequest() func(network.Stream) {
    return func(stream network.Stream) {
        logger := wakuPX.log.With(logging.HostID("peer", stream.Conn().RemotePeer()))

        if wakuPX.limiter != nil && !wakuPX.limiter.Allow() {
Severity: Minor
Found in waku/v2/protocol/peer_exchange/protocol.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 waku_filter_subscribe has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

func waku_filter_subscribe(ctx unsafe.Pointer, filterJSON *C.char, peerID *C.char, ms C.int, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
Severity: Minor
Found in library/c/api_filter.go - About 45 mins to fix

    Function waku_filter_unsubscribe has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    func waku_filter_unsubscribe(ctx unsafe.Pointer, filterJSON *C.char, peerID *C.char, ms C.int, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
    Severity: Minor
    Found in library/c/api_filter.go - About 45 mins to fix

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

      func main() {
          // Removing noisy logs
          lvl, err := logging.LevelFromString("error")
          if err != nil {
              panic(err)
      Severity: Major
      Found in examples/noise/main.go - About 40 mins to fix

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

        func Execute() error {
        
            var cTopic, err = protocol.NewContentTopic("basic-light-client", "1", "test", "proto")
            if err != nil {
                return errors.New("invalid contentTopic")
        Severity: Major
        Found in examples/basic-light-client/main.go - About 40 mins to fix

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

          func Execute() error {
          
              var cTopic, err = protocol.NewContentTopic("basic-relay", "1", "test", "proto")
              if err != nil {
                  fmt.Println("Invalid contentTopic")
          Severity: Major
          Found in examples/basic-relay/main.go - About 40 mins to fix

            Method DynamicGroupManager.loadCredential has 6 return statements (exceeds 4 allowed).
            Open

            func (gm *DynamicGroupManager) loadCredential(ctx context.Context) error {
                if gm.appKeystore == nil {
                    gm.log.Warn("no credentials were loaded. Node will only validate messages, but wont be able to generate proofs and attach them to messages")
                    return nil
                }
            Severity: Major
            Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.go - About 40 mins to fix

              Method DynamicGroupManager.Start has 6 return statements (exceeds 4 allowed).
              Open

              func (gm *DynamicGroupManager) Start(ctx context.Context) error {
                  if gm.cancel != nil {
                      return errors.New("already started")
                  }
              
              
              Severity: Major
              Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.go - About 40 mins to fix

                Method AppKeystore.AddMembershipCredentials has 6 return statements (exceeds 4 allowed).
                Open

                func (k *AppKeystore) AddMembershipCredentials(newCredential MembershipCredentials, password string) error {
                    credentials, err := k.GetMembershipCredentials(password, &newCredential.TreeIndex, newCredential.MembershipContractInfo)
                    if err != nil {
                        return err
                    }
                Severity: Major
                Found in waku/v2/protocol/rln/keystore/keystore.go - About 40 mins to fix

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

                  func StringToContentTopic(s string) (ContentTopic, error) {
                      p := strings.Split(s, "/")
                      switch len(p) {
                      case 5:
                          if len(p[1]) == 0 || len(p[2]) == 0 || len(p[3]) == 0 || len(p[4]) == 0 {
                  Severity: Major
                  Found in waku/v2/protocol/content_topic.go - About 40 mins to fix

                    Method WakuStore.Find has 6 return statements (exceeds 4 allowed).
                    Open

                    func (store *WakuStore) Find(ctx context.Context, query Query, cb CriteriaFN, opts ...HistoryRequestOption) (*wpb.WakuMessage, error) {
                        if cb == nil {
                            return nil, errors.New("callback can't be null")
                        }
                    
                    
                    Severity: Major
                    Found in waku/v2/protocol/legacy_store/waku_store_client.go - About 40 mins to fix

                      Method WakuStore.queryFrom has 6 return statements (exceeds 4 allowed).
                      Open

                      func (store *WakuStore) queryFrom(ctx context.Context, historyRequest *pb.HistoryRPC, selectedPeer peer.ID) (*pb.HistoryResponse, error) {
                          logger := store.log.With(logging.HostID("peer", selectedPeer))
                          logger.Info("querying message history")
                      
                          stream, err := store.h.NewStream(ctx, selectedPeer, StoreID_v20beta4)
                      Severity: Major
                      Found in waku/v2/protocol/legacy_store/waku_store_client.go - About 40 mins to fix

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

                        func validateAndParse(input []byte) (*DecodedPayload, error) {
                            end := len(input)
                            if end < 1 {
                                return nil, errors.New("invalid message length")
                            }
                        Severity: Major
                        Found in waku/v2/payload/waku_payload.go - About 40 mins to fix

                          Method WakuFilterLightNode.incorrectSubscribeRequest has 6 return statements (exceeds 4 allowed).
                          Open

                          func (wf *WakuFilterLightNode) incorrectSubscribeRequest(ctx context.Context, params *FilterSubscribeParameters,
                              reqType pb.FilterSubscribeRequest_FilterSubscribeType, contentFilter protocol.ContentFilter) error {
                          
                              const FilterSubscribeID_Incorrect1 = libp2pProtocol.ID("/vac/waku/filter-subscribe/abcd")
                          
                          
                          Severity: Major
                          Found in waku/v2/protocol/filter/filter_proto_ident_test.go - About 40 mins to fix

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

                            func SetBootnodes(instance *WakuInstance, bootnodes string) error {
                                if err := validateInstance(instance, MustBeStarted); err != nil {
                                    return err
                                }
                            
                            
                            Severity: Major
                            Found in library/discovery.go - About 40 mins to fix

                              Method FilterSubscribeRequest.Validate has 6 return statements (exceeds 4 allowed).
                              Open

                              func (x *FilterSubscribeRequest) Validate() error {
                                  if x.RequestId == "" {
                                      return errMissingRequestID
                                  }
                              
                              
                              Severity: Major
                              Found in waku/v2/protocol/filter/pb/validation.go - About 40 mins to fix

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

                                func generateSecureRandomData(length int) ([]byte, error) {
                                    x := make([]byte, length)
                                    y := make([]byte, length)
                                    res := make([]byte, length)
                                
                                
                                Severity: Major
                                Found in waku/v2/payload/waku_payload.go - About 40 mins to fix

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

                                  func DecodeSymmetric(messageJSON string, symmetricKey string) (string, error) {
                                      var msg pb.WakuMessage
                                      err := json.Unmarshal([]byte(messageJSON), &msg)
                                      if err != nil {
                                          return "", err
                                  Severity: Major
                                  Found in library/encoding.go - About 40 mins to fix

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

                                    func buildTransactor(ctx context.Context, membershipFee *big.Int, chainID *big.Int) (*bind.TransactOpts, error) {
                                        auth, err := bind.NewKeyedTransactorWithChainID(options.ETHPrivateKey, chainID)
                                        if err != nil {
                                            return nil, err
                                        }
                                    Severity: Major
                                    Found in cmd/waku/rlngenerate/web3.go - About 40 mins to fix

                                      Method WakuLightPush.request has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func (wakuLP *WakuLightPush) request(ctx context.Context, req *pb.PushRequest, params *lightPushRequestParameters, peerID peer.ID) (*pb.PushResponse, error) {
                                      
                                          logger := wakuLP.log.With(logging.HostID("peer", peerID))
                                      
                                          stream, err := wakuLP.h.NewStream(ctx, peerID, LightPushID_v20beta1)
                                      Severity: Major
                                      Found in waku/v2/protocol/lightpush/waku_lightpush.go - About 40 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language