WriteyourownQUICapplication
TowriteanapplicationthatusesQUIC,youwillhavetosubclasssomeoftheQUICclassesaswellascreatingsomenew
classes.ThisdocumenttriestoprovideanintroductiononhowtouseQUICinyourownapplication,byusingtheQUIC
performancetestclientandserverasexample.
Intheexample,epollisusedtogetnotifiedonavailableincomingpacketsorwhennewdatacanbewrittentothe
connection.ThisisbecauseperformancetestclientandserverarebasedontheexampleintheChromiumprojectinthe
net/tools/quicfolder.ItisnotnecessarytouseepollwhenwritinganapplicationthatusesQUIC.
Newclasses
TofacilitatethehandlingofalltheQUICclasses,youwillprobablywanttocreateclassesthatwraptheclientandthe
serverfunctionality.Also,youneedtocreateatleasttheQuicPacketWriterhelperclass.
QUICclientapplication
Youwillneedaclassthatwillcreateasession(e.g.QuicClient),connectionandapacketwriterandconnectsallthose
classes.Itmustalsoreadthenetworkpackagesanddispatchesthemtothesession.
CreatingaQUICclientanbedividedintoseveralsteps.FirstyouhavetodeterminetheIPaddresstoconnectto,theserver
idandtheQUICversionsyouwanttouse.Theserverididentifiestheservertoconnecttoandconsistsofascheme(http
orhttps),ahostandaport.Theexampleclientreceivesthoseintheconstructorandstorestheminhisattributes
(includingtheepollserver).
QuicClient::QuicClient(IPEndPointserver_address,
constQuicServerId&server_id,
constQuicVersionVector&supported_versions,
EpollServer*epoll_server)
:server_address_(server_address),
server_id_(server_id),
epoll_server_(epoll_server),
...
supported_versions_(supported_versions){
}
ThenyouneedtoopentheUDPsocketanregisteritwiththeepollserver.
boolQuicClient::Initialize(){
...
if(!CreateUDPSocket()){
returnfalse;
}
epoll_server_->RegisterFD(fd_,this,kEpollFlags);
initialized_=true;
returntrue;
}
WiththeUDPsocketopen,wecanopentheQUICconnection.WeneedtofirstcreateaQuickPacketWriterandapacket
writerfactoryandinitializeanewQuicConnectionwithit.ThenwecancreateanewQuicClientSessionusingthe
connection.Thesessionmustthenbeinitializedandfinallywecanstartthecryptohandshakeandwaitforittofinish.
boolQuicClient::Connect(){
QuicPacketWriter*writer=newQuicDefaultPacketWriter(fd_);
DummyPacketWriterFactoryfactory(writer);
session_.reset(newQuicClientSession(