69 volatile Decoder hpackIn; |
69 volatile Decoder hpackIn; |
70 volatile SettingsFrame clientSettings; |
70 volatile SettingsFrame clientSettings; |
71 final SettingsFrame serverSettings; |
71 final SettingsFrame serverSettings; |
72 final ExecutorService exec; |
72 final ExecutorService exec; |
73 final boolean secure; |
73 final boolean secure; |
|
74 final Properties properties; |
74 volatile boolean stopping; |
75 volatile boolean stopping; |
75 volatile int nextPushStreamId = 2; |
76 volatile int nextPushStreamId = 2; |
76 ConcurrentLinkedQueue<PingRequest> pings = new ConcurrentLinkedQueue<>(); |
77 ConcurrentLinkedQueue<PingRequest> pings = new ConcurrentLinkedQueue<>(); |
77 |
78 |
78 final static ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0); |
79 final static ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0); |
130 this.streams = Collections.synchronizedMap(new HashMap<>()); |
132 this.streams = Collections.synchronizedMap(new HashMap<>()); |
131 this.outStreams = Collections.synchronizedMap(new HashMap<>()); |
133 this.outStreams = Collections.synchronizedMap(new HashMap<>()); |
132 this.outputQ = new Queue<>(sentinel); |
134 this.outputQ = new Queue<>(sentinel); |
133 this.random = new Random(); |
135 this.random = new Random(); |
134 this.socket = socket; |
136 this.socket = socket; |
|
137 this.properties = properties; |
135 this.socket.setTcpNoDelay(true); |
138 this.socket.setTcpNoDelay(true); |
136 this.serverSettings = SettingsFrame.getDefaultSettings(); |
139 this.serverSettings = getServerSettingProperties(); |
137 this.exec = server.exec; |
140 this.exec = server.exec; |
138 this.secure = server.secure; |
141 this.secure = server.secure; |
139 this.pushStreams = new HashSet<>(); |
142 this.pushStreams = new HashSet<>(); |
140 is = new BufferedInputStream(socket.getInputStream()); |
143 is = new BufferedInputStream(socket.getInputStream()); |
141 os = new BufferedOutputStream(socket.getOutputStream()); |
144 os = new BufferedOutputStream(socket.getOutputStream()); |
|
145 } |
|
146 |
|
147 static final String propPrefix = "http2server.settings."; |
|
148 |
|
149 static final String[][] propIDs = { |
|
150 {"header_table_size", Integer.toString(SettingsFrame.HEADER_TABLE_SIZE)}, |
|
151 {"enable_push", Integer.toString(SettingsFrame.ENABLE_PUSH)}, |
|
152 {"max_concurrent_streams", Integer.toString(SettingsFrame.MAX_CONCURRENT_STREAMS)}, |
|
153 {"initial_window_size", Integer.toString(SettingsFrame.INITIAL_WINDOW_SIZE)}, |
|
154 {"max_frame_size", Integer.toString(SettingsFrame.MAX_FRAME_SIZE)}, |
|
155 {"max_header_list_size", Integer.toString(SettingsFrame.MAX_HEADER_LIST_SIZE)} |
|
156 }; |
|
157 |
|
158 private SettingsFrame getServerSettingProperties() { |
|
159 SettingsFrame s = SettingsFrame.getDefaultSettings(); |
|
160 if (properties == null) |
|
161 return s; |
|
162 for (int i=0; i<propIDs.length; i++) { |
|
163 String key = propIDs[i][0]; |
|
164 String numS = propIDs[i][1]; |
|
165 String prop = properties.getProperty(propPrefix + key); |
|
166 if (prop != null) { |
|
167 try { |
|
168 System.err.println("TestServer: setting " + key + " property to: " + |
|
169 prop); |
|
170 int num = Integer.parseInt(numS); |
|
171 System.err.println("TestServer: num = " + num); |
|
172 s.setParameter(num, Integer.parseInt(prop)); |
|
173 } catch (NumberFormatException e) {/* ignore errors */} |
|
174 } |
|
175 } |
|
176 return s; |
142 } |
177 } |
143 |
178 |
144 /** |
179 /** |
145 * Sends a PING frame on this connection, and completes the returned |
180 * Sends a PING frame on this connection, and completes the returned |
146 * CF when the PING ack is received. The CF is given |
181 * CF when the PING ack is received. The CF is given |