summaryrefslogtreecommitdiff
path: root/chromium/net/tools/flip_server/flip_config.cc
blob: 3de302856f12f96a993a88c9c2811f38d0cf2e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/tools/flip_server/flip_config.h"

#include <unistd.h>

namespace net {

FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type,
                           std::string listen_ip,
                           std::string listen_port,
                           std::string ssl_cert_filename,
                           std::string ssl_key_filename,
                           std::string http_server_ip,
                           std::string http_server_port,
                           std::string https_server_ip,
                           std::string https_server_port,
                           int spdy_only,
                           int accept_backlog_size,
                           bool disable_nagle,
                           int accepts_per_wake,
                           bool reuseport,
                           bool wait_for_iface,
                           void *memory_cache)
    : flip_handler_type_(flip_handler_type),
      listen_ip_(listen_ip),
      listen_port_(listen_port),
      ssl_cert_filename_(ssl_cert_filename),
      ssl_key_filename_(ssl_key_filename),
      http_server_ip_(http_server_ip),
      http_server_port_(http_server_port),
      https_server_ip_(https_server_ip),
      https_server_port_(https_server_port),
      spdy_only_(spdy_only),
      accept_backlog_size_(accept_backlog_size),
      disable_nagle_(disable_nagle),
      accepts_per_wake_(accepts_per_wake),
      memory_cache_(memory_cache),
      ssl_session_expiry_(300),  // TODO(mbelshe):  Hook these up!
      ssl_disable_compression_(false),
      idle_socket_timeout_s_(300) {
  VLOG(1) << "Attempting to listen on " << listen_ip_.c_str() << ":"
          << listen_port_.c_str();
  if (!https_server_ip_.size())
    https_server_ip_ = http_server_ip_;
  if (!https_server_port_.size())
    https_server_port_ = http_server_port_;

  while (1) {
    int ret = CreateListeningSocket(listen_ip_,
                                    listen_port_,
                                    true,
                                    accept_backlog_size_,
                                    true,
                                    reuseport,
                                    wait_for_iface,
                                    disable_nagle_,
                                    &listen_fd_);
    if ( ret == 0 ) {
      break;
    } else if ( ret == -3 && wait_for_iface ) {
      // Binding error EADDRNOTAVAIL was encounted. We need
      // to wait for the interfaces to raised. try again.
      usleep(200000);
    } else {
      LOG(ERROR) << "Unable to create listening socket for: ret = " << ret
                 << ": " << listen_ip_.c_str() << ":"
                 << listen_port_.c_str();
      return;
    }
  }

  FlipSetNonBlocking(listen_fd_);
  VLOG(1) << "Listening on socket: ";
  if (flip_handler_type == FLIP_HANDLER_PROXY)
    VLOG(1) << "\tType         : Proxy";
  else if (FLIP_HANDLER_SPDY_SERVER)
    VLOG(1) << "\tType         : SPDY Server";
  else if (FLIP_HANDLER_HTTP_SERVER)
    VLOG(1) << "\tType         : HTTP Server";
  VLOG(1) << "\tIP           : " << listen_ip_;
  VLOG(1) << "\tPort         : " << listen_port_;
  VLOG(1) << "\tHTTP Server  : " << http_server_ip_ << ":"
          << http_server_port_;
  VLOG(1) << "\tHTTPS Server : " << https_server_ip_ << ":"
          << https_server_port_;
  VLOG(1) << "\tSSL          : "
          << (ssl_cert_filename.size()?"true":"false");
  VLOG(1) << "\tCertificate  : " << ssl_cert_filename;
  VLOG(1) << "\tKey          : " << ssl_key_filename;
  VLOG(1) << "\tSpdy Only    : " << (spdy_only?"true":"flase");
}

FlipAcceptor::~FlipAcceptor() {}

FlipConfig::FlipConfig()
    : server_think_time_in_s_(0),
      log_destination_(logging::LOG_TO_SYSTEM_DEBUG_LOG),
      wait_for_iface_(false) {
}

FlipConfig::~FlipConfig() {}

void FlipConfig::AddAcceptor(enum FlipHandlerType flip_handler_type,
                             std::string listen_ip,
                             std::string listen_port,
                             std::string ssl_cert_filename,
                             std::string ssl_key_filename,
                             std::string http_server_ip,
                             std::string http_server_port,
                             std::string https_server_ip,
                             std::string https_server_port,
                             int spdy_only,
                             int accept_backlog_size,
                             bool disable_nagle,
                             int accepts_per_wake,
                             bool reuseport,
                             bool wait_for_iface,
                             void *memory_cache) {
  // TODO(mbelshe): create a struct FlipConfigArgs{} for the arguments.
  acceptors_.push_back(new FlipAcceptor(flip_handler_type,
                                        listen_ip,
                                        listen_port,
                                        ssl_cert_filename,
                                        ssl_key_filename,
                                        http_server_ip,
                                        http_server_port,
                                        https_server_ip,
                                        https_server_port,
                                        spdy_only,
                                        accept_backlog_size,
                                        disable_nagle,
                                        accepts_per_wake,
                                        reuseport,
                                        wait_for_iface,
                                        memory_cache));
}

}  // namespace