2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <hicn/http-proxy/http_proxy.h>
18 using namespace transport;
20 int usage(char* program) {
21 std::cerr << "USAGE: " << program << "\n"
22 << "[HTTP_PREFIX] -a [SERVER_IP_ADDRESS] "
23 "-p [SERVER_PORT] -c [CACHE_SIZE] -m [MTU] -l [DEFAULT_LIFETIME "
24 "(seconds)] -P [FIRST_IPv6_WORD_HEX] -M (enable manifest)"
29 struct Params : HTTPProxy::ClientParams, HTTPProxy::ServerParams {
30 void printParams() override {
32 HTTPProxy::ClientParams::printParams();
34 HTTPProxy::ServerParams::printParams();
36 throw std::runtime_error(
37 "Proxy configured as client and server at the same time.");
41 << "N Threads: " << n_thread << std::endl;
44 HTTPProxy* instantiateProxyAsValue() {
46 HTTPProxy::ClientParams* p = dynamic_cast<HTTPProxy::ClientParams*>(this);
47 return new transport::HTTPProxy(*p, n_thread);
49 HTTPProxy::ServerParams* p = dynamic_cast<HTTPProxy::ServerParams*>(this);
50 return new transport::HTTPProxy(*p, n_thread);
52 throw std::runtime_error(
53 "Proxy configured as client and server at the same time.");
59 std::uint16_t n_thread = 1;
62 int main(int argc, char** argv) {
65 params.prefix = "http://hicn-http-proxy";
66 params.origin_address = "127.0.0.1";
67 params.origin_port = "80";
68 params.cache_size = "50000";
70 params.first_ipv6_word = "b001";
71 params.content_lifetime = "7200;"; // seconds
72 params.manifest = false;
73 params.tcp_listen_port = 8080;
76 while ((opt = getopt(argc, argv, "CSa:p:c:m:P:l:ML:t:")) != -1) {
80 std::cerr << "Cannot be both client and server (both -C anc -S "
81 "options specified.)."
83 return usage(argv[0]);
89 std::cerr << "Cannot be both client and server (both -C anc -S "
90 "options specified.)."
92 return usage(argv[0]);
97 params.origin_address = optarg;
100 params.origin_port = optarg;
103 params.cache_size = optarg;
109 params.first_ipv6_word = optarg;
112 params.content_lifetime = optarg;
115 params.tcp_listen_port = std::stoul(optarg);
118 params.manifest = true;
121 params.n_thread = std::stoul(optarg);
125 return usage(argv[0]);
130 if (argv[optind] == 0) {
131 std::cerr << "Using default prefix " << params.prefix << std::endl;
133 params.prefix = argv[optind];
136 params.printParams();
137 auto proxy = params.instantiateProxyAsValue();