OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dirent.h> | 5 #include <dirent.h> |
6 #include <netinet/tcp.h> // For TCP_NODELAY | 6 #include <netinet/tcp.h> // For TCP_NODELAY |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 #include <openssl/err.h> | 10 #include <openssl/err.h> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // If true, then encode url to filename); | 79 // If true, then encode url to filename); |
80 bool FLAGS_need_to_encode_url = false; | 80 bool FLAGS_need_to_encode_url = false; |
81 | 81 |
82 // If set to false a single socket will be used. If set to true | 82 // If set to false a single socket will be used. If set to true |
83 // then a new socket will be created for each accept thread. | 83 // then a new socket will be created for each accept thread. |
84 // Note that this only works with kernels that support | 84 // Note that this only works with kernels that support |
85 // SO_REUSEPORT); | 85 // SO_REUSEPORT); |
86 bool FLAGS_reuseport = false; | 86 bool FLAGS_reuseport = false; |
87 | 87 |
| 88 // Flag to force spdy, even if NPN is not negotiated. |
| 89 bool FLAGS_force_spdy = false; |
| 90 |
88 // The amount of time the server delays before sending back the | 91 // The amount of time the server delays before sending back the |
89 // reply); | 92 // reply); |
90 double FLAGS_server_think_time_in_s = 0; | 93 double FLAGS_server_think_time_in_s = 0; |
91 | 94 |
92 // Does the server send X-Subresource headers); | 95 // Does the server send X-Subresource headers); |
93 bool FLAGS_use_xsub = false; | 96 bool FLAGS_use_xsub = false; |
94 | 97 |
95 // Does the server send X-Associated-Content headers); | 98 // Does the server send X-Associated-Content headers); |
96 bool FLAGS_use_xac = false; | 99 bool FLAGS_use_xac = false; |
97 | 100 |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 << "Reusing HTTP interface."; | 1146 << "Reusing HTTP interface."; |
1144 } | 1147 } |
1145 sm_interface_ = sm_http_interface_; | 1148 sm_interface_ = sm_http_interface_; |
1146 } else if (ssl_) { | 1149 } else if (ssl_) { |
1147 protocol_detected_ = true; | 1150 protocol_detected_ = true; |
1148 if (SSL_session_reused(ssl_) == 0) { | 1151 if (SSL_session_reused(ssl_) == 0) { |
1149 VLOG(1) << "Session status: renegotiated"; | 1152 VLOG(1) << "Session status: renegotiated"; |
1150 } else { | 1153 } else { |
1151 VLOG(1) << "Session status: resumed"; | 1154 VLOG(1) << "Session status: resumed"; |
1152 } | 1155 } |
1153 const unsigned char *npn_proto; | 1156 bool spdy_negotiated = FLAGS_force_spdy; |
1154 unsigned int npn_proto_len; | 1157 if (!spdy_negotiated) { |
1155 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len); | 1158 const unsigned char *npn_proto; |
1156 if (npn_proto_len > 0) { | 1159 unsigned int npn_proto_len; |
1157 string npn_proto_str((const char *)npn_proto, npn_proto_len); | 1160 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len); |
1158 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 1161 if (npn_proto_len > 0) { |
1159 << "NPN protocol detected: " << npn_proto_str; | 1162 string npn_proto_str((const char *)npn_proto, npn_proto_len); |
1160 } else { | |
1161 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | |
1162 << "NPN protocol detected: none"; | |
1163 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { | |
1164 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 1163 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
1165 << "NPN protocol: Could not negotiate SPDY protocol."; | 1164 << "NPN protocol detected: " << npn_proto_str; |
1166 goto error_or_close; | 1165 } else { |
| 1166 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
| 1167 << "NPN protocol detected: none"; |
| 1168 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { |
| 1169 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
| 1170 << "NPN protocol: Could not negotiate SPDY protocol."; |
| 1171 goto error_or_close; |
| 1172 } |
| 1173 } |
| 1174 if (npn_proto_len > 0 && |
| 1175 !strncmp((char *)npn_proto, "spdy/2", npn_proto_len)) { |
| 1176 spdy_negotiated = true; |
1167 } | 1177 } |
1168 } | 1178 } |
1169 if (npn_proto_len > 0 && | 1179 if (spdy_negotiated) { |
1170 !strncmp((char *)npn_proto, "spdy/2", npn_proto_len)) { | |
1171 if (!sm_spdy_interface_) { | 1180 if (!sm_spdy_interface_) { |
1172 sm_spdy_interface_ = NewSpdySM(this, NULL, epoll_server_, | 1181 sm_spdy_interface_ = NewSpdySM(this, NULL, epoll_server_, |
1173 memory_cache_, acceptor_); | 1182 memory_cache_, acceptor_); |
1174 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 1183 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
1175 << "Created SPDY interface."; | 1184 << "Created SPDY interface."; |
1176 } else { | 1185 } else { |
1177 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 1186 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
1178 << "Reusing SPDY interface."; | 1187 << "Reusing SPDY interface."; |
1179 } | 1188 } |
1180 sm_interface_ = sm_spdy_interface_; | 1189 sm_interface_ = sm_spdy_interface_; |
(...skipping 1898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3079 | 3088 |
3080 if (cl.HasSwitch("ssl-session-expiry")) { | 3089 if (cl.HasSwitch("ssl-session-expiry")) { |
3081 string session_expiry = cl.GetSwitchValueASCII("ssl-session-expiry"); | 3090 string session_expiry = cl.GetSwitchValueASCII("ssl-session-expiry"); |
3082 g_proxy_config.ssl_session_expiry_ = atoi( session_expiry.c_str() ); | 3091 g_proxy_config.ssl_session_expiry_ = atoi( session_expiry.c_str() ); |
3083 } | 3092 } |
3084 | 3093 |
3085 if (cl.HasSwitch("ssl-disable-compression")) { | 3094 if (cl.HasSwitch("ssl-disable-compression")) { |
3086 g_proxy_config.ssl_disable_compression_ = true; | 3095 g_proxy_config.ssl_disable_compression_ = true; |
3087 } | 3096 } |
3088 | 3097 |
| 3098 if (cl.HasSwitch("force_spdy")) |
| 3099 FLAGS_force_spdy = true; |
| 3100 |
3089 InitLogging(g_proxy_config.log_filename_.c_str(), | 3101 InitLogging(g_proxy_config.log_filename_.c_str(), |
3090 g_proxy_config.log_destination_, | 3102 g_proxy_config.log_destination_, |
3091 logging::DONT_LOCK_LOG_FILE, | 3103 logging::DONT_LOCK_LOG_FILE, |
3092 logging::APPEND_TO_OLD_LOG_FILE, | 3104 logging::APPEND_TO_OLD_LOG_FILE, |
3093 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 3105 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
3094 | 3106 |
3095 LOG(INFO) << "Flip SPDY proxy started with configuration:"; | 3107 LOG(INFO) << "Flip SPDY proxy started with configuration:"; |
3096 LOG(INFO) << "Logging destination : " << g_proxy_config.log_destination_; | 3108 LOG(INFO) << "Logging destination : " << g_proxy_config.log_destination_; |
3097 LOG(INFO) << "Log file : " << g_proxy_config.log_filename_; | 3109 LOG(INFO) << "Log file : " << g_proxy_config.log_filename_; |
3098 LOG(INFO) << "Forward IP Header : " | 3110 LOG(INFO) << "Forward IP Header : " |
3099 << (g_proxy_config.forward_ip_header_enabled_ ? | 3111 << (g_proxy_config.forward_ip_header_enabled_ ? |
3100 g_proxy_config.forward_ip_header_ : "(disabled)"); | 3112 g_proxy_config.forward_ip_header_ : "(disabled)"); |
3101 LOG(INFO) << "Wait for interfaces : " << (wait_for_iface?"true":"false"); | 3113 LOG(INFO) << "Wait for interfaces : " << (wait_for_iface?"true":"false"); |
3102 LOG(INFO) << "Accept backlog size : " << FLAGS_accept_backlog_size; | 3114 LOG(INFO) << "Accept backlog size : " << FLAGS_accept_backlog_size; |
3103 LOG(INFO) << "Accepts per wake : " << FLAGS_accepts_per_wake; | 3115 LOG(INFO) << "Accepts per wake : " << FLAGS_accepts_per_wake; |
3104 LOG(INFO) << "Disable nagle : " | 3116 LOG(INFO) << "Disable nagle : " |
3105 << (FLAGS_disable_nagle?"true":"false"); | 3117 << (FLAGS_disable_nagle?"true":"false"); |
3106 LOG(INFO) << "Reuseport : " << (FLAGS_reuseport?"true":"false"); | 3118 LOG(INFO) << "Reuseport : " << (FLAGS_reuseport?"true":"false"); |
| 3119 LOG(INFO) << "Force SPDY : " |
| 3120 << (FLAGS_force_spdy?"true":"false"); |
3107 LOG(INFO) << "SSL session expiry : " | 3121 LOG(INFO) << "SSL session expiry : " |
3108 << g_proxy_config.ssl_session_expiry_; | 3122 << g_proxy_config.ssl_session_expiry_; |
3109 LOG(INFO) << "SSL disable compression : " | 3123 LOG(INFO) << "SSL disable compression : " |
3110 << g_proxy_config.ssl_disable_compression_; | 3124 << g_proxy_config.ssl_disable_compression_; |
3111 | 3125 |
3112 // Proxy Acceptors | 3126 // Proxy Acceptors |
3113 while (true) { | 3127 while (true) { |
3114 i += 1; | 3128 i += 1; |
3115 std::stringstream name; | 3129 std::stringstream name; |
3116 name << "proxy" << i; | 3130 name << "proxy" << i; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3202 for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { | 3216 for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { |
3203 sm_worker_threads_[i]->Join(); | 3217 sm_worker_threads_[i]->Join(); |
3204 } | 3218 } |
3205 return 0; | 3219 return 0; |
3206 } | 3220 } |
3207 usleep(1000*10); // 10 ms | 3221 usleep(1000*10); // 10 ms |
3208 } | 3222 } |
3209 | 3223 |
3210 return 0; | 3224 return 0; |
3211 } | 3225 } |
OLD | NEW |