|
16 | 16 |
|
17 | 17 | import diskCacheV111.util.CacheException; |
18 | 18 | import diskCacheV111.util.ThirdPartyTransferFailedCacheException; |
| 19 | +import diskCacheV111.vehicles.IpProtocolInfo; |
19 | 20 | import diskCacheV111.vehicles.ProtocolInfo; |
20 | 21 | import diskCacheV111.vehicles.RemoteHttpDataTransferProtocolInfo; |
21 | 22 | import java.io.IOException; |
|
39 | 40 | import java.util.function.Consumer; |
40 | 41 | import java.util.stream.Collectors; |
41 | 42 | import javax.annotation.concurrent.GuardedBy; |
| 43 | +import javax.security.auth.Subject; |
42 | 44 | import org.apache.http.Header; |
43 | 45 | import org.apache.http.HttpEntity; |
44 | 46 | import org.apache.http.HttpInetConnection; |
@@ -213,9 +215,18 @@ private enum HeaderFlags { |
213 | 215 | private Long _expectedTransferSize; |
214 | 216 |
|
215 | 217 | private InetSocketAddress _localEndpoint; |
| 218 | + private final TransferLifeCycle _transferLifeCycle; |
| 219 | + private Subject _subject; |
| 220 | + private boolean _startMarkerSent; |
216 | 221 |
|
217 | | - public RemoteHttpDataTransferProtocol(CloseableHttpClient client) { |
| 222 | + public RemoteHttpDataTransferProtocol(CloseableHttpClient client, |
| 223 | + TransferLifeCycle transferLifeCycle) { |
218 | 224 | _client = requireNonNull(client); |
| 225 | + _transferLifeCycle = requireNonNull(transferLifeCycle); |
| 226 | + } |
| 227 | + |
| 228 | + public void setSubject(Subject subject) { |
| 229 | + _subject = subject; |
219 | 230 | } |
220 | 231 |
|
221 | 232 | private static void checkThat(boolean isOk, String message) throws CacheException { |
@@ -540,6 +551,7 @@ private CloseableHttpResponse doGet(final RemoteHttpDataTransferProtocolInfo inf |
540 | 551 | CloseableHttpResponse response = _client.execute(get, context); |
541 | 552 |
|
542 | 553 | _localEndpoint = localAddress().orElse(null); |
| 554 | + startFlowMarker(); |
543 | 555 |
|
544 | 556 | boolean isSuccessful = false; |
545 | 557 | try { |
@@ -605,6 +617,7 @@ private void sendFile(RemoteHttpDataTransferProtocolInfo info) |
605 | 617 |
|
606 | 618 | try (CloseableHttpResponse response = _client.execute(put, context)) { |
607 | 619 | _localEndpoint = localAddress().orElse(null); |
| 620 | + startFlowMarker(); |
608 | 621 | StatusLine status = response.getStatusLine(); |
609 | 622 | switch (status.getStatusCode()) { |
610 | 623 | case 200: /* OK (not actually a valid response from PUT) */ |
@@ -981,6 +994,26 @@ public Long getBytesExpected() { |
981 | 994 | return _expectedTransferSize; |
982 | 995 | } |
983 | 996 |
|
| 997 | + private void startFlowMarker() { |
| 998 | + if (_startMarkerSent || _localEndpoint == null || _subject == null) { |
| 999 | + return; |
| 1000 | + } |
| 1001 | + |
| 1002 | + ProtocolInfo protocolInfo = _channel.getProtocolInfo(); |
| 1003 | + if (!(protocolInfo instanceof IpProtocolInfo ipInfo)) { |
| 1004 | + return; |
| 1005 | + } |
| 1006 | + |
| 1007 | + InetSocketAddress remoteEndpoint = ipInfo.getSocketAddress(); |
| 1008 | + if (remoteEndpoint == null) { |
| 1009 | + return; |
| 1010 | + } |
| 1011 | + |
| 1012 | + _transferLifeCycle.onStart(remoteEndpoint, _localEndpoint, |
| 1013 | + protocolInfo, _subject); |
| 1014 | + _startMarkerSent = true; |
| 1015 | + } |
| 1016 | + |
984 | 1017 | @Override |
985 | 1018 | public Optional<InetSocketAddress> getLocalEndpoint() { |
986 | 1019 | return Optional.ofNullable(_localEndpoint); |
|
0 commit comments