1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #include "tscore/ink_string.h"
25 #include "tscore/ink_args.h"
26 #include "tscore/I_Layout.h"
27 #include "tscore/I_Version.h"
28 
29 #include "RecordsConfig.h"
30 #include "URL.h"
31 #include "MIME.h"
32 #include "HTTP.h"
33 #include "HuffmanCodec.h"
34 #include "Http3Config.h"
35 
36 #include "diags.h"
37 #include "quic_client.h"
38 
39 #define THREADS 1
40 
41 constexpr size_t stacksize = 1048576;
42 
43 // TODO: Support QUIC version, cipher suite ...etc
44 // TODO: Support qdrive tests
45 //   https://github.com/ekr/qdrive
46 //   https://github.com/mcmanus/mozquic/tree/master/tests/qdrive
47 int
main(int argc,const char ** argv)48 main(int argc, const char **argv)
49 {
50   // Before accessing file system initialize Layout engine
51   Layout::create();
52 
53   // Set up the application version info
54   AppVersionInfo appVersionInfo;
55   appVersionInfo.setup(PACKAGE_NAME, "traffic_quic", PACKAGE_VERSION, __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
56 
57   QUICClientConfig config;
58 
59   const ArgumentDescription argument_descriptions[] = {
60     {"addr", 'a', "Address", "S1023", config.addr, nullptr, nullptr},
61     {"output", 'o', "Write to FILE instead of stdout", "S1023", config.output, nullptr, nullptr},
62     {"port", 'p', "Port", "S15", config.port, nullptr, nullptr},
63     {"path", 'P', "Path", "S1017", config.path, nullptr, nullptr},
64     {"debug", 'T', "Vertical-bar-separated Debug Tags", "S1023", config.debug_tags, nullptr, nullptr},
65     {"close", 'c', "Enable connection close excercise", "F", &config.close, nullptr, nullptr},
66     {"http0_9", '-', "Enable HTTP/0.9", "T", &config.http0_9, nullptr, nullptr},
67     {"http3", '-', "Enable HTTP/3", "F", &config.http3, nullptr, nullptr},
68 
69     HELP_ARGUMENT_DESCRIPTION(),
70     VERSION_ARGUMENT_DESCRIPTION(),
71     RUNROOT_ARGUMENT_DESCRIPTION(),
72   };
73 
74   // Process command line arguments and dump into variables
75   process_args(&appVersionInfo, argument_descriptions, countof(argument_descriptions), argv);
76 
77   if (config.http3) {
78     config.http0_9 = false;
79   }
80 
81   init_diags(config.debug_tags, nullptr);
82   RecProcessInit(RECM_STAND_ALONE);
83   LibRecordsConfigInit();
84 
85   Debug("quic_client", "Load configs from %s", RecConfigReadConfigDir().c_str());
86 
87   Thread *main_thread = new EThread;
88   main_thread->set_specific();
89   net_config_poll_timeout = 10;
90   ink_net_init(ts::ModuleVersion(1, 0, ts::ModuleVersion::PRIVATE));
91 
92   SSLInitializeLibrary();
93   SSLConfig::startup();
94 
95   netProcessor.init();
96   quic_NetProcessor.init();
97 
98   ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
99   eventProcessor.start(THREADS);
100   udpNet.start(1, stacksize);
101   quic_NetProcessor.start(-1, stacksize);
102 
103   // Same to init_http_header(); in traffic_server.cc
104   url_init();
105   mime_init();
106   http_init();
107   hpack_huffman_init();
108 
109   Http3Config::startup();
110 
111   QUICClient client(&config);
112   eventProcessor.schedule_in(&client, 1, ET_NET);
113 
114   this_thread()->execute();
115 }
116 
117 // FIXME: remove stub
118 //
119 // stub
120 //
121 void
initialize_thread_for_http_sessions(EThread *,int)122 initialize_thread_for_http_sessions(EThread *, int)
123 {
124   ink_assert(false);
125 }
126 
127 #include "P_UnixNet.h"
128 #include "P_DNSConnection.h"
129 int
close()130 DNSConnection::close()
131 {
132   ink_assert(false);
133   return 0;
134 }
135 
136 void
trigger()137 DNSConnection::trigger()
138 {
139   ink_assert(false);
140 }
141 
142 #include "StatPages.h"
143 void
register_http(char const *,Action * (*)(Continuation *,HTTPHdr *))144 StatPagesManager::register_http(char const *, Action *(*)(Continuation *, HTTPHdr *))
145 {
146   //  ink_assert(false);
147 }
148 
149 #include "ParentSelection.h"
150 void
startup()151 SocksServerConfig::startup()
152 {
153   ink_assert(false);
154 }
155 
156 int SocksServerConfig::m_id = 0;
157 
158 void
findParent(HttpRequestData *,ParentResult *,unsigned int,unsigned int)159 ParentConfigParams::findParent(HttpRequestData *, ParentResult *, unsigned int, unsigned int)
160 {
161   ink_assert(false);
162 }
163 
164 void
nextParent(HttpRequestData *,ParentResult *,unsigned int,unsigned int)165 ParentConfigParams::nextParent(HttpRequestData *, ParentResult *, unsigned int, unsigned int)
166 {
167   ink_assert(false);
168 }
169 
170 #include "Log.h"
171 void
trace_in(sockaddr const *,unsigned short,char const *,...)172 Log::trace_in(sockaddr const *, unsigned short, char const *, ...)
173 {
174   ink_assert(false);
175 }
176 
177 void
trace_out(sockaddr const *,unsigned short,char const *,...)178 Log::trace_out(sockaddr const *, unsigned short, char const *, ...)
179 {
180   ink_assert(false);
181 }
182 
183 #include "InkAPIInternal.h"
184 
185 APIHook *
next() const186 APIHook::next() const
187 {
188   ink_assert(false);
189   return nullptr;
190 }
191 
192 void
clear()193 APIHooks::clear()
194 {
195   ink_abort("do not call stub");
196 }
197 
198 void
append(INKContInternal *)199 APIHooks::append(INKContInternal *)
200 {
201   ink_abort("do not call stub");
202 }
203 
204 int
invoke(int,void *) const205 APIHook::invoke(int, void *) const
206 {
207   ink_assert(false);
208   return 0;
209 }
210 
211 APIHook *
head() const212 APIHooks::head() const
213 {
214   return nullptr;
215 }
216 
HttpHookState()217 HttpHookState::HttpHookState() {}
218 
219 void
init(TSHttpHookID id,HttpAPIHooks const * global,HttpAPIHooks const * ssn,HttpAPIHooks const * txn)220 HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks const *ssn, HttpAPIHooks const *txn)
221 {
222 }
223 
224 APIHook const *
getNext()225 HttpHookState::getNext()
226 {
227   return nullptr;
228 }
229 
230 void
invoke(const char *)231 ConfigUpdateCbTable::invoke(const char * /* name ATS_UNUSED */)
232 {
233   ink_release_assert(false);
234 }
235 
236 #include "ControlMatcher.h"
237 char *
get_string()238 HttpRequestData::get_string()
239 {
240   ink_assert(false);
241   return nullptr;
242 }
243 
244 const char *
get_host()245 HttpRequestData::get_host()
246 {
247   ink_assert(false);
248   return nullptr;
249 }
250 
251 sockaddr const *
get_ip()252 HttpRequestData::get_ip()
253 {
254   ink_assert(false);
255   return nullptr;
256 }
257 
258 sockaddr const *
get_client_ip()259 HttpRequestData::get_client_ip()
260 {
261   ink_assert(false);
262   return nullptr;
263 }
264 
265 SslAPIHooks *ssl_hooks = nullptr;
266 StatPagesManager statPagesManager;
267 
268 #include "HttpDebugNames.h"
269 const char *
get_api_hook_name(TSHttpHookID t)270 HttpDebugNames::get_api_hook_name(TSHttpHookID t)
271 {
272   return "dummy";
273 }
274 
275 #include "HttpSM.h"
HttpSM()276 HttpSM::HttpSM() : Continuation(nullptr), vc_table(this) {}
277 
278 void
cleanup()279 HttpSM::cleanup()
280 {
281   ink_abort("do not call stub");
282 }
283 
284 void
destroy()285 HttpSM::destroy()
286 {
287   ink_abort("do not call stub");
288 }
289 
290 void
set_next_state()291 HttpSM::set_next_state()
292 {
293   ink_abort("do not call stub");
294 }
295 
296 void
handle_api_return()297 HttpSM::handle_api_return()
298 {
299   ink_abort("do not call stub");
300 }
301 
302 int
kill_this_async_hook(int,void *)303 HttpSM::kill_this_async_hook(int /* event ATS_UNUSED */, void * /* data ATS_UNUSED */)
304 {
305   return EVENT_DONE;
306 }
307 
308 void
attach_client_session(ProxyTransaction *,IOBufferReader *)309 HttpSM::attach_client_session(ProxyTransaction *, IOBufferReader *)
310 {
311   ink_abort("do not call stub");
312 }
313 
314 void
init()315 HttpSM::init()
316 {
317   ink_abort("do not call stub");
318 }
319 
320 ClassAllocator<HttpSM> httpSMAllocator("httpSMAllocator");
321 HttpAPIHooks *http_global_hooks;
322 
HttpVCTable(HttpSM *)323 HttpVCTable::HttpVCTable(HttpSM *) {}
324 
~PostDataBuffers()325 PostDataBuffers::~PostDataBuffers() {}
326 
327 #include "HttpTunnel.h"
HttpTunnel()328 HttpTunnel::HttpTunnel() : Continuation(nullptr) {}
HttpTunnelConsumer()329 HttpTunnelConsumer::HttpTunnelConsumer() {}
HttpTunnelProducer()330 HttpTunnelProducer::HttpTunnelProducer() {}
ChunkedHandler()331 ChunkedHandler::ChunkedHandler() {}
332 
333 #include "HttpCacheSM.h"
HttpCacheSM()334 HttpCacheSM::HttpCacheSM() {}
335 
HttpCacheAction()336 HttpCacheAction::HttpCacheAction() : sm(nullptr) {}
337 void
cancel(Continuation * c)338 HttpCacheAction::cancel(Continuation *c)
339 {
340 }
341