@@ -70,7 +70,7 @@ private void init(String pathToStores) {
7070 protected static void deliver (SSLEngine ssle , SocketChannel sc )
7171 throws Exception {
7272
73- // create buufer .
73+ // create buffer .
7474 int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
7575 int netBufferMax = ssle .getSession ().getPacketBufferSize ();
7676 int length = appBufferMax * (Integer .SIZE / 8 );
@@ -128,7 +128,7 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)
128128 // maybe need to enlarge the local network packet buffer.
129129 int size = ssle .getSession ().getPacketBufferSize ();
130130 if (size > localNetData .capacity ()) {
131- System .out .println ("resize destination buffer upto " +
131+ System .out .println ("send: resize destination buffer upto " +
132132 size + " bytes for BUFFER_OVERFLOW" );
133133 localNetData = enlargeBuffer (localNetData , size );
134134 }
@@ -143,16 +143,14 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)
143143
144144
145145 // receive peer application data.
146- protected static void receive (SSLEngine ssle , SocketChannel sc )
147- throws Exception {
146+ protected static void receive (SSLEngine ssle , SocketChannel sc ,
147+ ByteBuffer peerNetData ) throws Exception {
148148
149- // create buufers .
149+ // create buffer .
150150 int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
151- int netBufferMax = ssle .getSession ().getPacketBufferSize ();
152151
153- // allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
152+ // allocate less in order to check BUFFER_OVERFLOW
154153 ByteBuffer peerAppData = ByteBuffer .allocate (appBufferMax /2 );
155- ByteBuffer peerNetData = ByteBuffer .allocate (netBufferMax /2 );
156154 int received = -1 ;
157155
158156 boolean needToReadMore = true ;
@@ -189,8 +187,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
189187
190188 System .out .println ("received " + peerAppData .position () +
191189 " bytes client application data" );
192- System .out .println ("\t comsumed " + res .bytesConsumed () +
193- " byes network data" );
190+ System .out .println ("\t consumed " + res .bytesConsumed () +
191+ " bytes network data" );
194192 peerAppData .clear ();
195193
196194 received -= res .bytesProduced ();
@@ -209,7 +207,7 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
209207 // maybe need to enlarge the peer application data buffer.
210208 int size = ssle .getSession ().getApplicationBufferSize ();
211209 if (size > peerAppData .capacity ()) {
212- System .out .println ("resize destination buffer upto " +
210+ System .out .println ("recv: resize destination buffer upto " +
213211 size + " bytes for BUFFER_OVERFLOW" );
214212 peerAppData = enlargeBuffer (peerAppData , size );
215213 }
@@ -219,8 +217,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
219217 // maybe need to enlarge the peer network packet data buffer.
220218 size = ssle .getSession ().getPacketBufferSize ();
221219 if (size > peerNetData .capacity ()) {
222- System .out .println ("resize source buffer upto " + size +
223- " bytes for BUFFER_UNDERFLOW" );
220+ System .out .println ("recv: resize source buffer upto " +
221+ size + " bytes for BUFFER_UNDERFLOW" );
224222 peerNetData = enlargeBuffer (peerNetData , size );
225223 }
226224
@@ -234,15 +232,16 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
234232 }
235233 }
236234
237- protected static void handshaking (SSLEngine ssle , SocketChannel sc ,
235+ protected static ByteBuffer handshaking (SSLEngine ssle , SocketChannel sc ,
238236 ByteBuffer additional ) throws Exception {
239237
240238 int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
241239 int netBufferMax = ssle .getSession ().getPacketBufferSize ();
242240
241+ // zero-byte app buffers - we do not want to exchange app data here
242+ ByteBuffer localAppData = ByteBuffer .allocate (0 );
243+ ByteBuffer peerAppData = ByteBuffer .allocate (0 );
243244 // allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
244- ByteBuffer localAppData = ByteBuffer .allocate (appBufferMax /10 );
245- ByteBuffer peerAppData = ByteBuffer .allocate (appBufferMax /10 );
246245 ByteBuffer localNetData = ByteBuffer .allocate (netBufferMax /10 );
247246 ByteBuffer peerNetData = ByteBuffer .allocate (netBufferMax /10 );
248247
@@ -272,15 +271,15 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
272271 } else {
273272 if (sc .read (peerNetData ) < 0 ) {
274273 ssle .closeInbound ();
275- return ;
274+ throw new EOFException () ;
276275 }
277276 }
278277 }
279278
280279 if (underflow ) {
281280 if (sc .read (peerNetData ) < 0 ) {
282281 ssle .closeInbound ();
283- return ;
282+ throw new EOFException () ;
284283 }
285284
286285 underflow = false ;
@@ -298,7 +297,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
298297 // maybe need to enlarge the peer network packet buffer.
299298 int size = ssle .getSession ().getPacketBufferSize ();
300299 if (size > peerNetData .capacity ()) {
301- System .out .println ("resize source buffer upto " +
300+ System .out .println ("hs recv: resize source buffer upto " +
302301 size + " bytes for BUFFER_UNDERFLOW" );
303302 peerNetData = enlargeBuffer (peerNetData , size );
304303 }
@@ -309,7 +308,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
309308 // maybe need to enlarge the peer application data buffer.
310309 size = ssle .getSession ().getApplicationBufferSize ();
311310 if (size > peerAppData .capacity ()) {
312- System .out .println ("resize destination buffer upto " +
311+ System .out .println ("hs recv: resize destination buffer upto " +
313312 size + " bytes for BUFFER_OVERFLOW" );
314313 peerAppData = enlargeBuffer (peerAppData , size );
315314 }
@@ -346,7 +345,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
346345 // maybe need to enlarge the local network packet buffer.
347346 int size = ssle .getSession ().getPacketBufferSize ();
348347 if (size > localNetData .capacity ()) {
349- System .out .println ("resize destination buffer upto " +
348+ System .out .println ("hs send: resize destination buffer upto " +
350349 size + " bytes for BUFFER_OVERFLOW" );
351350 localNetData = enlargeBuffer (localNetData , size );
352351 }
@@ -371,6 +370,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
371370 }
372371 } while (hs != SSLEngineResult .HandshakeStatus .FINISHED &&
373372 hs != SSLEngineResult .HandshakeStatus .NOT_HANDSHAKING );
373+ return peerNetData ;
374374 }
375375
376376 private static ByteBuffer enlargeBuffer (ByteBuffer buffer , int size ) {
0 commit comments