Showing 400 of 400 total issues
Method MembershipFetcher.HandleGroupUpdates
has 5 return statements (exceeds 4 allowed). Open
Open
func (mf *MembershipFetcher) HandleGroupUpdates(ctx context.Context, handler RegistrationEventHandler) error {
fromBlock := mf.web3Config.RLNContract.DeployedBlockNumber
metadata, err := mf.GetMetadata()
if err != nil {
mf.log.Warn("could not load last processed block from metadata. Starting onchain sync from deployment block", zap.Error(err), zap.Uint64("deploymentBlock", mf.web3Config.RLNContract.DeployedBlockNumber))
Function main
has 5 return statements (exceeds 4 allowed). Open
Open
func main() {
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
key, err := randomHex(32)
if err != nil {
log.Error("Could not generate random key", zap.Error(err))
Function Migrations
has 5 return statements (exceeds 4 allowed). Open
Open
func Migrations(db *sql.DB, logger *zap.Logger) error {
migrationDriver, err := migrationDriver(db)
if err != nil {
return err
}
Method PeerManager.SelectRandom
has 5 return statements (exceeds 4 allowed). Open
Open
func (pm *PeerManager) SelectRandom(criteria PeerSelectionCriteria) (peer.IDSlice, error) {
// @TODO We need to be more strategic about which peers we dial. Right now we just set one on the service.
// Ideally depending on the query and our set of peers we take a subset of ideal peers.
// This will require us to check for various factors such as:
// - which topics they track
Method DB.Discover
has 5 return statements (exceeds 4 allowed). Open
Open
func (db *DB) Discover(ns string, cookie []byte, limit int) ([]dbi.RegistrationRecord, []byte, error) {
now := time.Now().Unix()
var (
counter int64
Method WakuNode.startRlnRelay
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *WakuNode) startRlnRelay(ctx context.Context) error {
rlnRelay := w.rlnRelay.(*rln.WakuRLNRelay)
err := rlnRelay.Start(ctx)
if err != nil {
Method Chat._doRequestMissingMessageFromStore
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Chat) _doRequestMissingMessageFromStore(messageID string) error {
ctx, cancel := context.WithTimeout(c.ctx, 10*time.Second)
defer cancel()
hash, err := base64.URLEncoding.DecodeString(messageID)
Function TestNetworkPartition
has 5 return statements (exceeds 4 allowed). Open
Open
func TestNetworkPartition(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
t.Log("Starting TestMessageRecovery")
Method PeerManager.checkAndUpdateTopicHealth
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) checkAndUpdateTopicHealth(topic *NodeTopicDetails) int {
if topic == nil {
return 0
}
- 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
Function New
has 5 return statements (exceeds 4 allowed). Open
Open
func New(path string, appInfo AppInfo, logger *zap.Logger) (*AppKeystore, error) {
logger = logger.Named("rln-keystore")
_, err := os.Stat(path)
if err != nil {
Method MembershipFetcher.loadOldEvents
has 5 return statements (exceeds 4 allowed). Open
Open
func (mf *MembershipFetcher) loadOldEvents(ctx context.Context, fromBlock, toBlock uint64, handler RegistrationEventHandler) error {
for ; fromBlock+maxBatchSize < toBlock; fromBlock += maxBatchSize + 1 { // check if the end of the batch is within the toBlock range
t1 := time.Now()
events, err := mf.getEvents(ctx, fromBlock, fromBlock+maxBatchSize)
if err != nil {
Function GenerateRandomSQLInsert
has 5 return statements (exceeds 4 allowed). Open
Open
func GenerateRandomSQLInsert(maxLength int) (string, error) {
// Random table name
tableName, err := GenerateRandomASCIIString(10)
if err != nil {
return "", err
Method WakuNode.getENRAddresses
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *WakuNode) getENRAddresses(ctx context.Context, addrs []ma.Multiaddr) (extAddr *net.TCPAddr, multiaddr []ma.Multiaddr, err error) {
extAddr, err = selectMostExternalAddress(addrs)
if err != nil {
return nil, nil, err
}
Method Config.Build
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *Config) Build(ctx context.Context) error {
if w.configured {
return errors.New("already configured")
}
Method DBStore.Query
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, error) {
start := time.Now()
defer func() {
elapsed := time.Since(start)
d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed))
Method PeerConnectionStrategy.consumeSubscription
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *PeerConnectionStrategy) consumeSubscription(s subscription) {
for {
// for returning from the loop when peerConnector is paused.
select {
case <-c.Context().Done():
Method Chat.publish
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Chat) publish(ctx context.Context, message string) error {
msg := &pb.Chat2Message{
Timestamp: uint64(c.node.Timesource().Now().Unix()),
Nick: c.nick,
Payload: []byte(message),
Method Chat.requestMessageFromPeer
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Chat) requestMessageFromPeer(peerID peer.ID, messageID string) (*pb.Message, error) {
ctx, cancel := context.WithTimeout(c.ctx, 30*time.Second)
defer cancel()
stream, err := c.node.Host().NewStream(ctx, peerID, messageRequestProtocolID)
Method Chat.publish
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Chat) publish(ctx context.Context, message *pb.Message) error {
msgBytes, err := proto.Marshal(message)
if err != nil {
return err
}
Method criteriaInterest.equals
has 5 return statements (exceeds 4 allowed). Open
Open
func (c criteriaInterest) equals(other criteriaInterest) bool {
if c.peerID != other.peerID {
return false
}