How to use the ip.cidr function in ip

To help you get started, we’ve selected a few ip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArkEcosystem / core / packages / core-p2p / src / socket-server / worker.ts View on Github external
            client => cidr(`${client.remoteAddress}/24`) === cidrRemoteAddress,
        );
github ArkEcosystem / core / packages / core-p2p / src / socket-server / worker.ts View on Github external
private async handleHandshake(req, next): Promise {
        const ip = req.socket.remoteAddress;
        if (this.ipLastError[ip] && this.ipLastError[ip] > Date.now() - MINUTE_IN_MILLISECONDS) {
            req.socket.destroy();
            return;
        }

        const isBlocked = await this.rateLimiter.isBlocked(ip);
        const isBlacklisted = (this.config.blacklist || []).includes(ip);
        if (isBlocked || isBlacklisted) {
            next(this.createError(SocketErrors.Forbidden, "Blocked due to rate limit or blacklisted."));
            return;
        }

        const cidrRemoteAddress = cidr(`${ip}/24`);
        const sameSubnetSockets = Object.values({ ...this.scServer.clients, ...this.scServer.pendingClients }).filter(
            client => cidr(`${client.remoteAddress}/24`) === cidrRemoteAddress,
        );
        if (sameSubnetSockets.length > this.config.maxSameSubnetPeers) {
            req.socket.destroy();
            return;
        }

        next();
    }
github ArkEcosystem / core / packages / core-p2p / src / peer-storage.ts View on Github external
        return this.getPeers().filter(peer => cidr(`${peer.ip}/24`) === cidr(`${ip}/24`));
    }