Showing 300 of 401 total issues
Method WakuStore.Request
has 77 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *WakuStore) Request(ctx context.Context, criteria Criteria, opts ...RequestOption) (Result, error) {
params := new(Parameters)
optList := DefaultOptions()
optList = append(optList, opts...)
Function TestDecoupledStoreFromRelay
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDecoupledStoreFromRelay(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// NODE1: Relay Node + Filter Server
Function TestStaticShardingLimits
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestStaticShardingLimits(t *testing.T) {
log := utils.Logger()
if os.Getenv("RUN_FLAKY_TESTS") != "true" {
Method WakuFilterLightNode.IncorrectSubscribe
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (wf *WakuFilterLightNode) IncorrectSubscribe(ctx context.Context, contentFilter protocol.ContentFilter, opts ...FilterSubscribeOption) ([]*subscription.SubscriptionDetails, error) {
wf.RLock()
defer wf.RUnlock()
if err := wf.ErrOnNotRunning(); err != nil {
return nil, err
Method WakuPeerExchange.Request
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (wakuPX *WakuPeerExchange) Request(ctx context.Context, numPeers int, opts ...RequestOption) error {
params := new(PeerExchangeRequestParameters)
params.host = wakuPX.h
params.log = wakuPX.log
params.pm = wakuPX.pm
Method PeerManager.prunePeerStore
has 74 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) prunePeerStore() {
peers := pm.host.Peerstore().Peers()
numPeers := len(peers)
if numPeers < pm.maxPeers {
pm.logger.Debug("peerstore size within capacity, not pruning", zap.Int("capacity", pm.maxPeers), zap.Int("numPeers", numPeers))
Method Pairing.responderHandshake
has 74 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (p *Pairing) responderHandshake(ctx context.Context, msgCh <-chan *pb.WakuMessage) (doneCh chan error) {
doneCh = make(chan error, 1)
func() {
defer close(doneCh)
Function TestWakuRelayAutoShard
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuRelayAutoShard(t *testing.T) {
testcTopic := "/toychat/2/huilong/proto"
testcTopic1 := "/toychat/1/huilong/proto"
port, err := tests.FindFreePort(t, "", 5)
Function main
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func main() {
// Removing noisy logs
lvl, err := logging.LevelFromString("error")
if err != nil {
panic(err)
Function TestWakuRLNOptions
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuRLNOptions(t *testing.T) {
topicHealthStatusChan := make(chan peermanager.TopicHealthStatus, 100)
key, err := tests.RandomHex(32)
require.NoError(t, err)
Function TestWakuStoreResult
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuStoreResult(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
Method WakuRLNRelay.ValidateMessage
has 70 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (rlnRelay *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time.Time) (messageValidationResult, error) {
if msg == nil {
return validationError, errors.New("nil message")
}
Method PeerManager.selectServicePeer
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) selectServicePeer(criteria PeerSelectionCriteria) (PeerSet, error) {
peers := make(PeerSet)
var err error
for retryCnt := 0; retryCnt < 1; retryCnt++ {
//Try to fetch from serviceSlot
- Read upRead up
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 WakuFilterLightNode.onRequest
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
Open
func (wf *WakuFilterLightNode) onRequest(ctx context.Context) func(network.Stream) {
return func(stream network.Stream) {
peerID := stream.Conn().RemotePeer()
logger := wf.log.With(logging.HostID("peerID", peerID))
- Read upRead up
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 DB.Discover
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (db *DB) Discover(ns string, cookie []byte, limit int) ([]dbi.RegistrationRecord, []byte, error) {
now := time.Now().Unix()
var (
counter int64
Method WakuRLNRelaySuite.TestValidateMessage
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *WakuRLNRelaySuite) TestValidateMessage() {
groupKeyPairs, _, err := r.CreateMembershipList(100)
s.Require().NoError(err)
ctx, cancel := context.WithCancel(context.Background())
Function TestDiscV5WithShardFilter
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDiscV5WithShardFilter(t *testing.T) {
// Following topic syntax for shard /waku/2/rs/<cluster_id>/<shard_number>
pubSubTopic := "/waku/2/rs/10/1"
Method WakuNode.Start
has 18 return statements (exceeds 4 allowed). Open
Open
func (w *WakuNode) Start(ctx context.Context) error {
connGater := peermanager.NewConnectionGater(w.opts.maxConnectionsPerIP, w.log)
ctx, cancel := context.WithCancel(ctx)
w.cancel = cancel
Method FastestPeerSelector.FastestPeer
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (r *FastestPeerSelector) FastestPeer(ctx context.Context, peers peer.IDSlice) (peer.ID, error) {
var peerRTT []pingResult
var peerRTTMutex sync.Mutex
wg := sync.WaitGroup{}
Function NewChat
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func NewChat(ctx context.Context, node *node.WakuNode, connNotifier <-chan node.PeerConnection, options Options) *Chat {
chat := &Chat{
ctx: ctx,
node: node,
options: options,