src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SSLFlowDelegate.java
equal
deleted
inserted
replaced
90 final SSLEngine engine; |
90 final SSLEngine engine; |
91 final String tubeName; // hack |
91 final String tubeName; // hack |
92 final CompletableFuture<Void> cf; |
92 final CompletableFuture<Void> cf; |
93 final CompletableFuture<String> alpnCF; // completes on initial handshake |
93 final CompletableFuture<String> alpnCF; // completes on initial handshake |
94 final static ByteBuffer SENTINEL = Utils.EMPTY_BYTEBUFFER; |
94 final static ByteBuffer SENTINEL = Utils.EMPTY_BYTEBUFFER; |
|
95 volatile boolean close_notify_received; |
95 |
96 |
96 /** |
97 /** |
97 * Creates an SSLFlowDelegate fed from two Flow.Subscribers. Each |
98 * Creates an SSLFlowDelegate fed from two Flow.Subscribers. Each |
98 * Flow.Subscriber requires an associated {@link CompletableFuture} |
99 * Flow.Subscriber requires an associated {@link CompletableFuture} |
99 * for errors that need to be signaled from downstream to upstream. |
100 * for errors that need to be signaled from downstream to upstream. |
116 // connect the Reader to the downReader and the |
117 // connect the Reader to the downReader and the |
117 // Writer to the downWriter. |
118 // Writer to the downWriter. |
118 connect(downReader, downWriter); |
119 connect(downReader, downWriter); |
119 |
120 |
120 //Monitor.add(this::monitor); |
121 //Monitor.add(this::monitor); |
|
122 } |
|
123 |
|
124 /** |
|
125 * Returns true if the SSLFlowDelegate has detected a TLS |
|
126 * close_notify from the server. |
|
127 * @return true, if a close_notify was detected. |
|
128 */ |
|
129 public boolean closeNotifyReceived() { |
|
130 return close_notify_received; |
121 } |
131 } |
122 |
132 |
123 /** |
133 /** |
124 * Connects the read sink (downReader) to the SSLFlowDelegate Reader, |
134 * Connects the read sink (downReader) to the SSLFlowDelegate Reader, |
125 * and the write sink (downWriter) to the SSLFlowDelegate Writer. |
135 * and the write sink (downWriter) to the SSLFlowDelegate Writer. |
459 void stop() { |
469 void stop() { |
460 debugw.log(Level.DEBUG, "stop"); |
470 debugw.log(Level.DEBUG, "stop"); |
461 scheduler.stop(); |
471 scheduler.stop(); |
462 } |
472 } |
463 |
473 |
|
474 @Override |
|
475 public boolean closing() { |
|
476 return closeNotifyReceived(); |
|
477 } |
|
478 |
464 private boolean isCompleting() { |
479 private boolean isCompleting() { |
465 synchronized(writeList) { |
480 synchronized(writeList) { |
466 int lastIndex = writeList.size() - 1; |
481 int lastIndex = writeList.size() - 1; |
467 if (lastIndex < 0) |
482 if (lastIndex < 0) |
468 return false; |
483 return false; |
690 dst.flip(); |
705 dst.flip(); |
691 b.put(dst); |
706 b.put(dst); |
692 dst = b; |
707 dst = b; |
693 break; |
708 break; |
694 case CLOSED: |
709 case CLOSED: |
695 doClosure(); |
710 return doClosure(new EngineResult(sslResult)); |
696 return new EngineResult(sslResult); |
|
697 case BUFFER_UNDERFLOW: |
711 case BUFFER_UNDERFLOW: |
698 // handled implicitly by compaction/reallocation of readBuf |
712 // handled implicitly by compaction/reallocation of readBuf |
699 return new EngineResult(sslResult); |
713 return new EngineResult(sslResult); |
700 case OK: |
714 case OK: |
701 dst.flip(); |
715 dst.flip(); |
703 } |
717 } |
704 } |
718 } |
705 } |
719 } |
706 |
720 |
707 // FIXME: acknowledge a received CLOSE request from peer |
721 // FIXME: acknowledge a received CLOSE request from peer |
708 void doClosure() throws IOException { |
722 EngineResult doClosure(EngineResult r) throws IOException { |
709 //while (!wrapAndSend(emptyArray)) |
723 debug.log(Level.DEBUG, |
710 //; |
724 "doClosure(%s): %s [isOutboundDone: %s, isInboundDone: %s]", |
|
725 r.result, engine.getHandshakeStatus(), |
|
726 engine.isOutboundDone(), engine.isInboundDone()); |
|
727 if (engine.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) { |
|
728 // we have received TLS close_notify and need to send |
|
729 // an acknowledgement back. We're calling doHandshake |
|
730 // to finish the close handshake. |
|
731 if (engine.isInboundDone() && !engine.isOutboundDone()) { |
|
732 debug.log(Level.DEBUG, "doClosure: close_notify received"); |
|
733 close_notify_received = true; |
|
734 doHandshake(r, READER); |
|
735 } |
|
736 } |
|
737 return r; |
711 } |
738 } |
712 |
739 |
713 /** |
740 /** |
714 * Returns the upstream Flow.Subscriber of the reading (incoming) side. |
741 * Returns the upstream Flow.Subscriber of the reading (incoming) side. |
715 * This flow must be given the encrypted data read from upstream (eg socket) |
742 * This flow must be given the encrypted data read from upstream (eg socket) |