This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mesa-platform-quic/src/gquic.h

192 lines
5.2 KiB
C
Raw Normal View History

2020-05-12 12:18:02 +08:00
/*
* quic.h
*
* Created on: 2019-4-4
* Author: root
*/
#ifndef _GQUIC_H_
#define _GQUIC_H_
2020-05-12 12:18:02 +08:00
//https://github.com/quicwg/base-drafts/wiki/QUIC-Versions
enum _QUIC_VERSION
{
QUIC_VERSION_UNKNOWN=0,
//google
GQUIC_VERSION_Q001=0x51303031,
GQUIC_VERSION_Q002=0x51303032,
GQUIC_VERSION_Q003=0x51303033,
GQUIC_VERSION_Q004=0x51303034,
GQUIC_VERSION_Q005=0x51303035,
GQUIC_VERSION_Q006=0x51303036,
GQUIC_VERSION_Q007=0x51303037,
GQUIC_VERSION_Q008=0x51303038,
GQUIC_VERSION_Q009=0x51303039,
GQUIC_VERSION_Q010=0x51303130,
GQUIC_VERSION_Q011=0x51303131,
GQUIC_VERSION_Q012=0x51303132,
GQUIC_VERSION_Q013=0x51303133,
GQUIC_VERSION_Q014=0x51303134,
GQUIC_VERSION_Q015=0x51303135,
GQUIC_VERSION_Q016=0x51303136,
GQUIC_VERSION_Q017=0x51303137,
GQUIC_VERSION_Q018=0x51303138,
GQUIC_VERSION_Q019=0x51303139,
GQUIC_VERSION_Q020=0x51303230,
GQUIC_VERSION_Q021=0x51303231,
GQUIC_VERSION_Q022=0x51303332,
GQUIC_VERSION_Q023=0x51303333,
GQUIC_VERSION_Q024=0x51303234,
GQUIC_VERSION_Q025=0x51303235,
GQUIC_VERSION_Q026=0x51303236,
GQUIC_VERSION_Q027=0x51303237,
GQUIC_VERSION_Q028=0x51303238,
GQUIC_VERSION_Q029=0x51303239,
GQUIC_VERSION_Q030=0x51303330,
GQUIC_VERSION_Q031=0x51303331,
GQUIC_VERSION_Q032=0x51303332,
GQUIC_VERSION_Q033=0x51303333,
GQUIC_VERSION_Q034=0x51303334,
GQUIC_VERSION_Q035=0x51303335,
GQUIC_VERSION_Q036=0x51303336,
GQUIC_VERSION_Q037=0x51303337,
GQUIC_VERSION_Q038=0x51303338,
GQUIC_VERSION_Q039=0x51303339,
GQUIC_VERSION_Q040=0x51303430,
GQUIC_VERSION_Q041=0x51303431,
GQUIC_VERSION_Q042=0x51303432,
GQUIC_VERSION_Q043=0x51303433,
GQUIC_VERSION_Q044=0x51303434,
GQUIC_VERSION_Q045=0x51303435,
GQUIC_VERSION_Q046=0x51303436,
GQUIC_VERSION_Q047=0x51303437,
GQUIC_VERSION_Q048=0x51303438, //Google QUIC with TLS
GQUIC_VERSION_Q049=0x51303439, //Google QUIC with TLS
GQUIC_VERSION_Q050=0x51303530,
GQUIC_VERSION_Q051=0x51303531,
GQUIC_VERSION_Q052=0x51303532,
GQUIC_VERSION_Q053=0x51303533,
GQUIC_VERSION_Q054=0x51303534,
GQUIC_VERSION_Q055=0x51303535,
GQUIC_VERSION_Q056=0x51303536,
GQUIC_VERSION_Q057=0x51303537,
GQUIC_VERSION_Q058=0x51303538,
GQUIC_VERSION_Q059=0x51303539,
GQUIC_VERSION_Q099=0x51303939,
//Google Proxied QUIC
PQUIC_VERSION_PROX=0x50524f58
//GOQUIC_VERSION_GO=0x51474f[0-255],
//quicly
//QUICKLY_VERSION_QUICLY=0x91c170[0-255]
//IETF
//IQUIC_VERSION_=0xf10000
};
2020-05-12 12:18:02 +08:00
#define QUIC_INTEREST_KEY (1<<QUIC_INTEREST_KEY_MASK)
#define QUIC_CLIENT_HELLO (1<<QUIC_CLIENT_HELLO_MASK)
#define QUIC_SERVER_HELLO (1<<QUIC_SERVER_HELLO_MASK)
#define QUIC_CACHED_CERT (1<<QUIC_CACHED_CERT_MASK)
#define QUIC_COMM_CERT (1<<QUIC_COMM_CERT_MASK)
#define QUIC_CERT_CHAIN (1<<QUIC_CERT_CHAIN_MASK)
#define QUIC_APPLICATION_DATA (1<<QUIC_APPLICATION_DATA_MASK)
2020-06-01 17:16:23 +08:00
#define QUIC_USEING_VERSION (1<<QUIC_USEING_VERSION_MASK)
#define QUIC_NEGOTIATION_VERSION (1<<QUIC_NEGOTIATION_VERSION_MASK)
#define QUIC_REJECTION (1<<QUIC_REJECTION_MASK)
2020-05-12 12:18:02 +08:00
2020-06-01 17:16:23 +08:00
enum quic_interested_region
{
2020-05-12 12:18:02 +08:00
QUIC_INTEREST_KEY_MASK = 0,
QUIC_CLIENT_HELLO_MASK,
QUIC_SERVER_HELLO_MASK,
QUIC_CACHED_CERT_MASK,
QUIC_COMM_CERT_MASK,
QUIC_CERT_CHAIN_MASK,
QUIC_APPLICATION_DATA_MASK,
2020-06-01 17:16:23 +08:00
QUIC_USEING_VERSION_MASK,
QUIC_NEGOTIATION_VERSION_MASK,
QUIC_REJECTION_MASK
2020-05-12 12:18:02 +08:00
};
2020-05-29 15:10:01 +08:00
typedef struct _quic_tlv
{
2020-05-12 12:18:02 +08:00
unsigned int type;
unsigned int length;
2020-05-29 15:10:01 +08:00
void *value;
2020-05-12 12:18:02 +08:00
}quic_tlv_t;
2020-05-29 15:10:01 +08:00
#define MAX_CONNECT_ID_LEN 18
struct _quic_public_header
2020-05-12 12:18:02 +08:00
{
2020-05-29 15:10:01 +08:00
unsigned char public_flags;
2020-06-01 17:16:23 +08:00
unsigned char is_reset;
unsigned char is_sepcial_packet; // special Packets
unsigned char is_version_negotiation;
unsigned char server_CID_len;
unsigned char client_CID_len;
unsigned char negotiation_version_num;
unsigned int quic_version;
2020-05-29 15:10:01 +08:00
unsigned long long packet_number;
unsigned char server_CID[MAX_CONNECT_ID_LEN]; ////use first 8 bytes if GQUIC version 1~43
2020-06-01 17:16:23 +08:00
unsigned char client_CID[MAX_CONNECT_ID_LEN]; // no used if GQUIC version 1~43
unsigned int *negotiation_version_list;
2020-05-12 12:18:02 +08:00
};
2020-05-29 15:10:01 +08:00
struct _gquic_frame_header
{
unsigned char frame_type;
unsigned char fin_state;
unsigned short data_len;
unsigned int stream_id;
unsigned long long offset;
2020-05-12 12:18:02 +08:00
};
2020-05-29 15:10:01 +08:00
struct _quic_stream
{
unsigned char count;
unsigned char sni_idx;
unsigned char ua_idx;
unsigned char ver_idx;
unsigned int ext_tag_num; //number of extensions or tags
quic_tlv_t *ext_tags; //extensions or tags
};
2020-05-12 12:18:02 +08:00
2020-05-29 15:10:01 +08:00
struct _quic_info
{
2020-06-01 17:16:23 +08:00
struct _quic_stream *rejection;
2020-05-29 15:10:01 +08:00
struct _quic_stream *client_hello;
struct _quic_stream *server_hello;
struct _gquic_frame_header frame_hdr;
struct _quic_public_header quic_hdr;
2020-05-12 12:18:02 +08:00
};
struct _quic_context
{
int is_quic;
int link_state;
2020-06-01 17:44:32 +08:00
int call_business;
void *business_pme;
struct _quic_info quic_info;
};
2020-05-29 15:10:01 +08:00
//buff_len minimun 32bytes
int quic_version_int2string(unsigned int version, char *buff, int buff_len);
2020-06-01 17:16:23 +08:00
int quic_process(struct streaminfo *pstream, struct _quic_context* _context, int thread_seq, void* a_packet);
2020-05-29 15:10:01 +08:00
int quic_init_stream(void **pme, int thread_seq); // **pme=(struct _quic_context* )
void quic_release_stream(struct streaminfo *a_tcp, void **pme, int thread_seq);
enum _QUIC_VERSION is_quic_protocol(struct streaminfo *pstream, struct _quic_context* _context, char *payload, int payload_len, int *used_len);
2020-05-12 12:18:02 +08:00
#endif /* SRC_GQUIC_H_ */