tourze/quic-packets 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/quic-packets

Composer 安装命令:

composer require tourze/quic-packets

包简介

QUIC协议包处理库

README 文档

README

English | 中文

[Latest Version] (https://packagist.org/packages/tourze/quic-packets) [PHP Version] (https://packagist.org/packages/tourze/quic-packets) [Total Downloads] (https://packagist.org/packages/tourze/quic-packets) License Coverage Status

A comprehensive QUIC packet handling library implementing RFC 9000 specifications for PHP 8.1+.

Table of Contents

Features

  • RFC 9000 Compliant: Full support for QUIC packet format specifications
  • Complete Packet Types: Initial, Handshake, and 1-RTT packets
  • Efficient Encoding/Decoding: Optimized binary packet serialization
  • Packet Number Management: Automatic numbering with loss detection
  • Type-Safe Design: Modern PHP 8.1+ with enums and readonly properties
  • Comprehensive Testing: 215 tests with 591 assertions across 19 test files

Requirements

  • PHP 8.1 or higher
  • No external dependencies for core functionality

Installation

Install via Composer:

composer require tourze/quic-packets

Quick Start

Basic Packet Creation and Encoding

<?php

use Tourze\QUIC\Packets\InitialPacket;
use Tourze\QUIC\Packets\PacketEncoder;
use Tourze\QUIC\Packets\PacketDecoder;

// Create an Initial packet
$packet = new InitialPacket(
    version: 0x00000001,
    destinationConnectionId: 'destination_id',
    sourceConnectionId: 'source_id_12',
    token: 'auth_token',
    packetNumber: 123,
    payload: 'Hello QUIC'
);

// Encode to binary format
$encoder = new PacketEncoder();
$binaryData = $encoder->encode($packet);

// Decode back to packet object
$decoder = new PacketDecoder();
$decodedPacket = $decoder->decode($binaryData);

echo "Packet type: " . $decodedPacket->getType()->getName();
echo "Payload: " . $decodedPacket->getPayload();

Packet Number Space Management

use Tourze\QUIC\Packets\PacketNumberSpace;
use Tourze\QUIC\Packets\PacketType;

// Create packet number space for Initial packets
$space = new PacketNumberSpace(PacketType::INITIAL);

// Get next packet numbers
$packetNum1 = $space->getNext(); // 0
$packetNum2 = $space->getNext(); // 1

// Record received packets
$space->recordReceived(100);

// Acknowledge sent packets
$space->acknowledge($packetNum1);

// Check for lost packets
$lostPackets = $space->detectLoss();

Handshake Packets

use Tourze\QUIC\Packets\HandshakePacket;

$handshakePacket = new HandshakePacket(
    version: 0x00000001,
    destinationConnectionId: 'dest_conn_id',
    sourceConnectionId: 'src_conn_id_',
    packetNumber: 456,
    payload: 'TLS handshake data'
);

$encoded = $encoder->encode($handshakePacket);

1-RTT Data Packets

use Tourze\QUIC\Packets\ShortHeaderPacket;

$dataPacket = new ShortHeaderPacket(
    destinationConnectionId: 'conn12345',
    packetNumber: 789,
    payload: 'Application data',
    keyPhase: true
);

$encoded = $encoder->encode($dataPacket);

API Reference

Core Classes

  • PacketType: Enum defining QUIC packet types (Initial, Handshake, 1-RTT, etc.)
  • Packet: Abstract base class for all packet types
  • LongHeaderPacket: Base class for Initial and Handshake packets
  • ShortHeaderPacket: For 1-RTT encrypted data packets
  • PacketEncoder: Encodes packet objects to binary data
  • PacketDecoder: Decodes binary data to packet objects
  • PacketNumberSpace: Manages packet numbering and acknowledgments

Supported Packet Types

Type Class Description Status
Initial InitialPacket Connection establishment ✅ Complete
Handshake HandshakePacket TLS handshake completion ✅ Complete
1-RTT ShortHeaderPacket Encrypted data transmission ✅ Complete
0-RTT ZeroRTTPacket Early data ✅ Complete
Retry RetryPacket Stateless retry ✅ Complete
Version Negotiation VersionNegotiationPacket Version agreement ✅ Complete
Stateless Reset StatelessResetPacket Connection reset ✅ Complete

Advanced Usage

Batch Processing

$packets = [
    new InitialPacket(1, 'dest1', 'src1', 'token1', 1, 'data1'),
    new HandshakePacket(1, 'dest2', 'src2', 2, 'data2'),
];

// Batch encode
$encodedPackets = $encoder->encodeBatch($packets);

// Batch decode
$decodedPackets = $decoder->decodeBatch($encodedPackets);

Packet Type Detection

$packetType = $decoder->detectPacketType($binaryData);
if ($packetType === PacketType::INITIAL) {
    // Handle Initial packet
}

Validation

if ($decoder->validatePacketFormat($binaryData)) {
    $packet = $decoder->decode($binaryData);
}

Testing

Run the test suite:

vendor/bin/phpunit

From project root:

./vendor/bin/phpunit packages/quic-packets/tests

Architecture

The library follows a clean, object-oriented design:

┌─────────────────┐    ┌──────────────────┐
│   PacketType    │    │     Packet       │
│    (enum)       │    │   (abstract)     │
└─────────────────┘    └──────────────────┘
                              │
                    ┌─────────┴─────────┐
                    │                   │
         ┌──────────▼─────────┐  ┌──────▼──────┐
         │  LongHeaderPacket  │  │ShortHeader │
         │    (abstract)      │  │   Packet   │
         └────────┬───────────┘  └─────────────┘
                  │
         ┌────────┴────────┐
         │                 │
    ┌────▼─────┐    ┌─────▼──────┐
    │ Initial  │    │ Handshake  │
    │ Packet   │    │  Packet    │
    └──────────┘    └────────────┘

Performance

  • Memory Efficient: Readonly properties minimize memory usage
  • Fast Encoding: Optimized binary serialization
  • Type Safety: Compile-time type checking prevents runtime errors

Security

This library is designed for QUIC packet handling and follows security best practices:

  • Input Validation: All packet data is validated during decoding
  • Type Safety: Strong typing prevents common security vulnerabilities
  • No External Dependencies: Minimal attack surface for core functionality
  • Memory Safe: Readonly properties prevent unintended modifications

For security vulnerabilities, please email security@tourze.com instead of using the issue tracker.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

git clone https://github.com/tourze/quic-packets
cd quic-packets
composer install
vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

Roadmap

  • 0-RTT packet support
  • Retry packet implementation
  • Version negotiation packets
  • Stateless reset packets
  • Packet encryption integration
  • Performance optimizations
  • Packet fragmentation support

References

tourze/quic-packets 适用场景与选型建议

tourze/quic-packets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 147 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/quic-packets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/quic-packets 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/quic-packets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 147
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-03