Skip to content

Commit

Permalink
Merge branch 'main' into 0.43.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	composer.lock
  • Loading branch information
abnegate committed Jan 13, 2025
2 parents 2f5d9dc + 4214cd6 commit ba83ba8
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 289 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
"phpstan/phpstan": "^1.9",
"laravel/pint": "1.5.*",
"phpbench/phpbench": "^1.2"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"tbachert/spi": true
}
}
}
65 changes: 62 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
mysql:
image: mysql:8
Expand All @@ -10,6 +8,15 @@ services:
ports:
- "9307:3306"

adminer:
image: adminer
container_name: abuse-adminer
restart: always
ports:
- 9506:8080
networks:
- abuse

redis:
image: redis:6.0-alpine
container_name: redis
Expand All @@ -30,5 +37,57 @@ services:
- ./src:/code/src
- ./tests:/code/tests

redis-insight:
image: redis/redisinsight:latest
restart: unless-stopped
networks:
- abuse
environment:
- REDIS_HOSTS=redis-cluster-0:6379
ports:
- "8081:5540"
volumes:
- redisinsight:/data

redis-cluster-0:
image: docker.io/bitnami/redis-cluster:7.4
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3
- REDIS_CLUSTER_CREATOR=yes
- REDIS_CLUSTER_REPLICAS=0
networks:
- abuse
depends_on:
- redis-cluster-1
- redis-cluster-2
- redis-cluster-3

redis-cluster-1:
image: docker.io/bitnami/redis-cluster:7.4
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3
networks:
- abuse

redis-cluster-2:
image: docker.io/bitnami/redis-cluster:7.4
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3
networks:
- abuse

redis-cluster-3:
image: docker.io/bitnami/redis-cluster:7.4
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3
networks:
- abuse

networks:
abuse:
abuse:
volumes:
redisinsight:
6 changes: 3 additions & 3 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema":"vendor/phpbench/phpbench/phpbench.schema.json",
"$schema": "vendor/phpbench/phpbench/phpbench.schema.json",
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "tests",
"runner.file_pattern": "*Bench.php"
"runner.path": "tests/Abuse/Bench",
"runner.file_pattern": "*.php"
}
8 changes: 4 additions & 4 deletions src/Abuse/Abuse.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public function getLogs(?int $offset = null, ?int $limit = 25): array
}

/**
* Delete all logs older than $datetime
* Delete all logs older than $timestamp
*
* @param string $datetime
* @param int $timestamp
* @return bool
*/
public function cleanup(string $datetime): bool
public function cleanup(int $timestamp): bool
{
return $this->adapter->cleanup($datetime);
return $this->adapter->cleanup($timestamp);
}
}
4 changes: 2 additions & 2 deletions src/Abuse/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ abstract public function getLogs(?int $offset = null, ?int $limit = 25): array;
/**
* Delete all logs older than $datetime
*
* @param string $datetime
* @param int $timestamp
* @return bool
*/
abstract public function cleanup(string $datetime): bool;
abstract public function cleanup(int $timestamp): bool;
}
6 changes: 3 additions & 3 deletions src/Abuse/Adapters/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public function check(float $score = 0.5): bool
}

/**
* Delete logs older than $datetime
* Delete logs older than $timestamp
*
* @param string $datetime
* @param int $timestamp
* @return bool
*
* @throws Exception
*/
public function cleanup(string $datetime): bool
public function cleanup(int $timestamp): bool
{
throw new Exception('Method not supported');
}
Expand Down
139 changes: 0 additions & 139 deletions src/Abuse/Adapters/Redis/TimeLimit.php

This file was deleted.

26 changes: 12 additions & 14 deletions src/Abuse/Adapters/TimeLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ abstract class TimeLimit extends Adapter
protected ?int $count = null;

/**
* @var string
* @var int
*/
protected string $time;
protected int $timestamp;

/**
* Check
*
* Checks if number of counts is bigger or smaller than current limit
*
* @param string $key
* @param string $datetime
* @param int $timestamp
* @return int
*
* @throws \Exception
*/
abstract protected function count(string $key, string $datetime): int;

abstract protected function hit(string $key, string $datetime): void;

abstract protected function count(string $key, int $timestamp): int;

abstract protected function hit(string $key, int $timestamp): void;

/**
* Check
Expand All @@ -56,8 +54,8 @@ public function check(): bool

$key = $this->parseKey();

if ($this->limit > $this->count($key, $this->time)) {
$this->hit($key, $this->time);
if ($this->limit > $this->count($key, $this->timestamp)) {
$this->hit($key, $this->timestamp);

return false;
}
Expand All @@ -76,7 +74,7 @@ public function check(): bool
*/
public function remaining(): int
{
$left = $this->limit - ($this->count($this->parseKey(), $this->time) + 1); // Add one because we need to say how many left not how many done
$left = $this->limit - ($this->count($this->parseKey(), $this->timestamp) + 1); // Add one because we need to say how many left not how many done

return (0 > $left) ? 0 : $left;
}
Expand All @@ -96,12 +94,12 @@ public function limit(): int
/**
* Time
*
* Return the Datetime
* Return the timestamp
*
* @return string
* @return int
*/
public function time(): string
public function time(): int
{
return $this->time;
return $this->timestamp;
}
}
Loading

0 comments on commit ba83ba8

Please sign in to comment.