QUIC接收包处理

接收包处理:
quic_process_packet_interface.h
这个头文件中有个只包含一个类
// A class to process each incoming packet. 意思是一个处理所有到来包的类

class ProcessPacketInterface {
 public:
  virtual ~ProcessPacketInterface() {}
  virtual void ProcessPacket(const QuicSocketAddress& server_address,
                             const QuicSocketAddress& client_address,
                             const QuicReceivedPacket& packet) = 0;
};

quic_client_epoll_network_helper.h中继承这个类
// From ProcessPacketInterface. This will be called for each received
// packet.
意思为接收到包后便会调用这个函数

  void ProcessPacket(const QuicSocketAddress& self_address,
                     const QuicSocketAddress& peer_address,
                     const QuicReceivedPacket& packet) override;

该函数调用 client_->session()->ProcessUdpPacket(self_address, peer_address, packet);

跳转到

void QuicSession::ProcessUdpPacket(const QuicSocketAddress& self_address,
                                   const QuicSocketAddress& peer_address,
                                   const QuicReceivedPacket& packet) {
  connection_->ProcessUdpPacket(self_address, peer_address, packet);
}

再次跳转到QuicConnection::ProcessUdpPacket

其中调用framer_.ProcessPacket(packet)
// Pass a UDP packet into the framer for parsing.
// Return true if the packet was processed succesfully. |packet| must be a
// single, complete UDP packet (not a frame of a packet). This packet
// might be null padded past the end of the payload, which will be correctly
// ignored.
意思是处理一个完整的udp包,处理成功返回true

bool ProcessPacket(const QuicEncryptedPacket& packet);
处理流程
为创建一个reader对象
QuicDataReader reader(packet.data(), packet.length(), perspective_,
endianness());

首先处理包头
创建包头对象 QuicPacketPublicHeader public_header;
调用ProcessPublicHeader(&reader, &public_header)处理
流程:
其中处理为先处理包类型
判断如果为客户端传来的信息则进行版本判断和兼容
然后处理nonce包,这个包只能由服务端发给客户端
之后调用rv = ProcessDataPacket(&reader, public_header, packet, buffer,
kMaxPacketSize);
跳转到bool QuicFramer::ProcessDataPacket
首先将包头未验证的部分进行加入header
ProcessUnauthenticatedHeader(encrypted_reader, &header)
然后解密包
DecryptPayload(encrypted_reader, header, packet, decrypted_buffer,
buffer_length, &decrypted_length)
再设置最后的packet number
SetLastPacketNumber(header);
处理数据
ProcessFrameData
bool QuicFramer::ProcessFrameData
其中QuicStringPiece data;
reader->ReadStringPiece(&data, data_len)
读取数据内容

读取完后一直跳转到 QuicFramer::ProcessFrameData的ProcessStreamFrame执行完
然后会处理ACK 帧 ProcessAckFrame(reader, frame_type, &frame)
处理完后根据frame_type进行对应的数据处理

假如是 CONNECTION_CLOSE_FRAME会调用ProcessConnectionCloseFrame(reader, &frame)

其中QuicStringPiece error_details;
if (!reader->ReadStringPiece16(&error_details)) {
将close的原因提取出来打印
然后调用OnConnectionCloseFrame,这个和发送 CONNECTION_CLOSE_FRAME的客户端采取的操作是一样的

几个帧的type值

enum QuicFrameType {

  // Regular frame types. The values set here cannot change without the
  // introduction of a new QUIC version.
  PADDING_FRAME = 0,
  RST_STREAM_FRAME = 1,
  CONNECTION_CLOSE_FRAME = 2,
  GOAWAY_FRAME = 3,
  WINDOW_UPDATE_FRAME = 4,
  BLOCKED_FRAME = 5,
  STOP_WAITING_FRAME = 6,
  PING_FRAME = 7,

  // STREAM and ACK frames are special frames. They are encoded differently on
  // the wire and their values do not need to be stable.
  STREAM_FRAME,
  ACK_FRAME,
  // The path MTU discovery frame is encoded as a PING frame on the wire.
  MTU_DISCOVERY_FRAME,
  NUM_FRAME_TYPES
};

PADDING_FRAME:为填充字节帧,接收到这个包时会将包剩余部分填充字节

RST_STREAM_FRAME:当由流的创建者发送时,表示创建者希望关闭流,当由接收者发送时,表示发生错误或者不想接收流,因此流应该被关闭

CONNECTION_CLOSE_FRAME:连接关闭

GOAWAY_FRAME:表示流应该被停止使用,因为之后将会被关闭,在使用的流将被继续处理,但是发送者不会在接收流

WINDOW_UPDATE_FRAME:用于通知对端流量控制端口接收窗口大小的更新

BLOCKED_FRAME:表示已经准备好发送数据且有数据要发送,但是被阻塞了

STOP_WAITING_FRAME:通知对端不需要等待包号小于特定值的包

STREAM_FRAME:用于发送数据

ACK_FRAME:通知对端哪些包被接收到了

以上皆为初学者的理解,仅供参考。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值