feat: improve WireGuard client management and framework initialization

- Improve WireGuard client IP calculation logic (find next available IP)
- Add local wireguard-clients directory for storing client configs
- Integrate Redis pool into CacheInitializer
- Improve ContainerBootstrapper with better imports and Redis pool
- Add monitoring role tags for better task organization
- Update WireGuard documentation
- Store generated WireGuard client configs locally
This commit is contained in:
2025-11-02 03:29:23 +01:00
parent f56d53d873
commit e598309c48
12 changed files with 183 additions and 37 deletions

View File

@@ -19,6 +19,7 @@ use App\Framework\DI\Initializer;
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
use App\Framework\Redis\RedisConfig;
use App\Framework\Redis\RedisConnection;
use App\Framework\Redis\RedisConnectionPool;
use App\Framework\Serializer\Json\JsonSerializer;
use App\Framework\Serializer\Php\PhpSerializer;
@@ -27,10 +28,9 @@ final readonly class CacheInitializer
public function __construct(
private PerformanceCollectorInterface $performanceCollector,
private Container $container,
private ?AsyncService $asyncService = null,
#private CacheMetricsInterface $cacheMetrics,
private string $redisHost = 'redis',
private int $redisPort = 6379,
private RedisConnectionPool $redisConnectionPool,
private ?AsyncService $asyncService = null,
private int $compressionLevel = -1,
private int $minCompressionLength = 1024,
private bool $enableAsync = true
@@ -61,12 +61,8 @@ final readonly class CacheInitializer
throw new \RuntimeException('Redis extension is not loaded. Please install php-redis extension or use alternative cache drivers.');
}
$redisConfig = new RedisConfig(
host: $this->redisHost,
port: $this->redisPort,
database: 1 // Use DB 1 for cache
);
$redisConnection = new RedisConnection($redisConfig, 'cache');
$redisConnection = $this->redisConnectionPool->getCacheConnection();
#$redisConnection = new RedisConnection($redisConfig, 'cache');
$redisCache = new GeneralCache(new RedisCache($redisConnection), $serializer, $compression);
} catch (\Throwable $e) {
// Fallback to file cache if Redis is not available

View File

@@ -13,12 +13,21 @@ use App\Framework\DI\ContainerCompiler;
use App\Framework\DI\DefaultContainer;
use App\Framework\DI\DependencyResolver;
use App\Framework\Discovery\DiscoveryServiceBootstrapper;
use App\Framework\Http\Parser\HttpRequestParser;
use App\Framework\Http\Parser\ParserCache;
use App\Framework\Http\Request;
use App\Framework\Http\RequestFactory;
use App\Framework\Http\ResponseEmitter;
use App\Framework\Logging\DefaultLogger;
use App\Framework\Logging\Formatter\DevelopmentFormatter;
use App\Framework\Logging\Handlers\ConsoleHandler;
use App\Framework\Logging\Logger;
use App\Framework\Logging\LoggerInitializer;
use App\Framework\Logging\LogLevel;
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
use App\Framework\Reflection\CachedReflectionProvider;
use App\Framework\Redis\RedisPoolInitializer;
use App\Framework\Config\Environment;
final readonly class ContainerBootstrapper
{
@@ -149,19 +158,20 @@ final readonly class ContainerBootstrapper
$container->instance(Logger::class, $logger);
$container->instance(PerformanceCollectorInterface::class, $collector);
$container->instance(Cache::class, new CacheInitializer($collector, $container)());
$pool = new RedisPoolInitializer($container, $container->get(Environment::class))->initialize();
$container->instance(Cache::class, new CacheInitializer($collector, $container, $pool)());
$container->instance(ResponseEmitter::class, new ResponseEmitter());
// TEMPORARY FIX: Manual RequestFactory binding until Discovery issue is resolved
$container->singleton(\App\Framework\Http\Request::class, function ($container) {
$container->singleton(Request::class, function ($container) {
error_log("ContainerBootstrapper: Creating Request singleton");
// Get Cache from container (it was just registered above)
$frameworkCache = $container->get(\App\Framework\Cache\Cache::class);
$parserCache = new \App\Framework\Http\Parser\ParserCache($frameworkCache);
$parser = new \App\Framework\Http\Parser\HttpRequestParser($parserCache);
$factory = new \App\Framework\Http\RequestFactory($parser);
$frameworkCache = $container->get(Cache::class);
$parserCache = new ParserCache($frameworkCache);
$parser = new HttpRequestParser($parserCache);
$factory = new RequestFactory($parser);
error_log("ContainerBootstrapper: About to call factory->createFromGlobals()");
$request = $factory->createFromGlobals();
@@ -232,15 +242,15 @@ final readonly class ContainerBootstrapper
$handlers = $isMcpMode
? [new \App\Framework\Logging\Handlers\NullHandler()]
: [
new \App\Framework\Logging\Handlers\ConsoleHandler(
new \App\Framework\Logging\Formatter\DevelopmentFormatter(),
\App\Framework\Logging\LogLevel::DEBUG
new ConsoleHandler(
new DevelopmentFormatter(),
LogLevel::DEBUG
)
];
$logger = new \App\Framework\Logging\DefaultLogger(
clock: $clock,
minLevel: \App\Framework\Logging\LogLevel::DEBUG,
minLevel: LogLevel::DEBUG,
handlers: $handlers,
processorManager: new \App\Framework\Logging\ProcessorManager(),
contextManager: new \App\Framework\Logging\LogContextManager()

View File

@@ -15,12 +15,14 @@ use App\Framework\Random\RandomGenerator;
use App\Framework\Random\SecureRandomGenerator;
use App\Framework\Redis\RedisConfig;
use App\Framework\Redis\RedisConnection;
use App\Framework\Redis\RedisConnectionPool;
use App\Framework\Security\CsrfTokenGenerator;
final readonly class SessionInitializer
{
public function __construct(
private Container $container
private Container $container,
private RedisConnectionPool $redisConnectionPool,
) {
}
@@ -47,8 +49,7 @@ final readonly class SessionInitializer
throw new \RuntimeException('Redis extension not loaded');
}
$redisConfig = new RedisConfig(host: 'redis', database: 3);
$redisConnection = new RedisConnection($redisConfig, 'session');
$redisConnection = $this->redisConnectionPool->getSessionConnection();
$storage = new RedisSessionStorage($redisConnection);
} catch (\Throwable $e) {
// Fallback to file-based storage if Redis is not available