1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.proxy.configuration;
21
22 import io.netty.bootstrap.ServerBootstrap;
23 import io.netty.channel.ChannelFuture;
24 import io.netty.channel.group.DefaultChannelGroup;
25 import org.waarp.common.database.exception.WaarpDatabaseSqlException;
26 import org.waarp.common.logging.WaarpLogger;
27 import org.waarp.common.logging.WaarpLoggerFactory;
28 import org.waarp.common.utility.WaarpNettyUtil;
29 import org.waarp.common.utility.WaarpShutdownHook;
30 import org.waarp.common.utility.WaarpSystemUtil;
31 import org.waarp.openr66.protocol.configuration.Configuration;
32 import org.waarp.openr66.protocol.configuration.Messages;
33 import org.waarp.openr66.proxy.network.NetworkServerInitializerProxy;
34 import org.waarp.openr66.proxy.network.ProxyBridge;
35 import org.waarp.openr66.proxy.network.ProxyEntry;
36 import org.waarp.openr66.proxy.network.ssl.NetworkSslServerInitializerProxy;
37 import org.waarp.openr66.proxy.protocol.http.HttpInitializer;
38 import org.waarp.openr66.proxy.protocol.http.adminssl.HttpSslInitializer;
39
40 import java.net.InetSocketAddress;
41 import java.util.ArrayList;
42 import java.util.List;
43
44
45
46
47 public class ConfigurationProxyR66 extends Configuration {
48
49
50
51 private static final WaarpLogger logger =
52 WaarpLoggerFactory.getLogger(ConfigurationProxyR66.class);
53
54
55
56
57 public ConfigurationProxyR66() {
58
59 }
60
61 @Override
62 public final void computeNbThreads() {
63 final int nb = Runtime.getRuntime().availableProcessors() + 1;
64 setServerThread(nb);
65 setClientThread(getServerThread() + 1);
66 setRunnerThread(10);
67 }
68
69 @Override
70 public final void serverStartup() {
71 setServer(true);
72 getShutdownConfiguration().timeout = getTimeoutCon();
73 WaarpShutdownHook.addShutdownHook();
74 if (!isUseNOSSL() && !isUseSSL()) {
75 logger.error(
76 "OpenR66 has neither NOSSL nor SSL support included! Stop here!");
77 WaarpSystemUtil.systemExit(-1);
78 return;
79 }
80 pipelineInit();
81 serverPipelineInit();
82 r66Startup();
83 startHttpSupport();
84 try {
85 startMonitoring();
86 } catch (final WaarpDatabaseSqlException ignored) {
87
88 }
89 logger.warn(toString());
90 }
91
92 @Override
93 public final void r66Startup() {
94 logger.debug("Start R66: {}", getHostSslId());
95
96 getConstraintLimitHandler().setServer(true);
97
98 serverChannelGroup =
99 new DefaultChannelGroup("OpenR66", subTaskGroup.next());
100 if (isUseNOSSL()) {
101 serverBootstrap = new ServerBootstrap();
102 WaarpNettyUtil.setServerBootstrap(serverBootstrap, serverGroup,
103 workerGroup, (int) getTimeoutCon(),
104 getBlockSize() + 64, false);
105 networkServerInitializer = new NetworkServerInitializerProxy(true);
106 serverBootstrap.childHandler(networkServerInitializer);
107
108 final List<ChannelFuture> futures = new ArrayList<ChannelFuture>();
109 for (final ProxyEntry entry : ProxyEntry.proxyEntries.values()) {
110 if (!entry.isLocalSsl()) {
111 logger.debug("Future Activation: {}", entry.getLocalSocketAddress());
112 futures.add(serverBootstrap.bind(entry.getLocalSocketAddress()));
113 }
114 }
115 for (final ChannelFuture future : futures) {
116 future.syncUninterruptibly();
117 if (future.isSuccess()) {
118 bindNoSSL = future.channel();
119 serverChannelGroup.add(bindNoSSL);
120 logger.debug("Activation: {}", bindNoSSL.localAddress());
121 } else {
122 logger.warn(
123 Messages.getString("Configuration.NOSSLDeactivated") + " for " +
124 bindNoSSL.localAddress());
125 }
126 }
127 } else {
128 networkServerInitializer = null;
129 logger.warn(
130 Messages.getString("Configuration.NOSSLDeactivated"));
131 }
132
133 if (isUseSSL() && getHostSslId() != null) {
134 serverSslBootstrap = new ServerBootstrap();
135 WaarpNettyUtil.setServerBootstrap(serverSslBootstrap, serverGroup,
136 workerGroup, (int) getTimeoutCon(),
137 getBlockSize() + 64, false);
138 networkSslServerInitializer = new NetworkSslServerInitializerProxy(false);
139 serverSslBootstrap.childHandler(networkSslServerInitializer);
140
141 final List<ChannelFuture> futures = new ArrayList<ChannelFuture>();
142 for (final ProxyEntry entry : ProxyEntry.proxyEntries.values()) {
143 if (entry.isLocalSsl()) {
144 logger.debug(
145 "Future SslActivation: " + entry.getLocalSocketAddress());
146 futures.add(serverSslBootstrap.bind(entry.getLocalSocketAddress()));
147 }
148 }
149 for (final ChannelFuture future : futures) {
150 future.syncUninterruptibly();
151 if (future.isSuccess()) {
152 bindSSL = future.channel();
153 serverChannelGroup.add(bindSSL);
154 logger.debug("SslActivation: {}", bindSSL.localAddress());
155 } else {
156 logger.warn(
157 Messages.getString("Configuration.SSLMODEDeactivated") + " for " +
158 bindSSL.localAddress());
159 }
160 }
161 } else {
162 networkSslServerInitializer = null;
163 logger.warn(
164 Messages.getString("Configuration.SSLMODEDeactivated"));
165 }
166
167
168 setupLimitHandler();
169 ProxyBridge.initialize();
170 setThriftService(null);
171 }
172
173 @Override
174 public final void startHttpSupport() {
175
176 logger.info(
177 Messages.getString("Configuration.HTTPStart") + getServerHttpport() +
178
179 " HTTPS: " + getServerHttpsPort());
180 httpChannelGroup =
181 new DefaultChannelGroup("HttpOpenR66", subTaskGroup.next());
182 if (getServerHttpport() > 0) {
183
184 httpBootstrap = new ServerBootstrap();
185 WaarpNettyUtil.setServerBootstrap(httpBootstrap, httpWorkerGroup,
186 httpWorkerGroup, (int) getTimeoutCon());
187
188 httpBootstrap.childHandler(new HttpInitializer(isUseHttpCompression()));
189
190 final ChannelFuture future =
191 httpBootstrap.bind(new InetSocketAddress(getServerHttpport()))
192 .awaitUninterruptibly();
193 if (future.isSuccess()) {
194 httpChannelGroup.add(future.channel());
195 }
196 }
197
198 if (getServerHttpsPort() > 0) {
199
200 httpsBootstrap = new ServerBootstrap();
201
202 WaarpNettyUtil.setServerBootstrap(httpsBootstrap, httpWorkerGroup,
203 httpWorkerGroup, (int) getTimeoutCon());
204 httpsBootstrap.childHandler(
205 new HttpSslInitializer(isUseHttpCompression()));
206
207 final ChannelFuture future =
208 httpsBootstrap.bind(new InetSocketAddress(getServerHttpsPort()))
209 .awaitUninterruptibly();
210 if (future.isSuccess()) {
211 httpChannelGroup.add(future.channel());
212 }
213 }
214 }
215
216 @Override
217 public final void serverStop() {
218 super.serverStop();
219 ProxyBridge.transaction.closeAll();
220 }
221
222 }