diff --git a/modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java b/modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java index 55da82c4301..a224c102c35 100644 --- a/modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java +++ b/modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.dcache.pool.repository.RepositoryChannel; @@ -112,6 +113,11 @@ public abstract class Mode extends AbstractMultiplexerListener { private String _lastFailure; + /** + * Local endpoint used for transfer. + */ + private volatile InetSocketAddress _localEndpoint; + /** * Constructs a new mode for outgoing connections. */ @@ -427,6 +433,7 @@ public void accept(Multiplexer multiplexer, SelectionKey key) _opened++; LOGGER.debug("Opened {}", socket); _addresses.add((InetSocketAddress) socket.getRemoteSocketAddress()); + _localEndpoint = (InetSocketAddress) socket.getLocalSocketAddress(); channel.configureBlocking(false); if (_bufferSize > 0) { channel.socket().setSendBufferSize(_bufferSize); @@ -453,6 +460,7 @@ public void connect(Multiplexer multiplexer, SelectionKey key) _opened++; LOGGER.debug("Opened {}", socket); _addresses.add((InetSocketAddress) socket.getLocalSocketAddress()); + _localEndpoint = (InetSocketAddress) socket.getLocalSocketAddress(); newConnection(multiplexer, channel); } } catch (IOException e) { @@ -591,6 +599,13 @@ public void getInfo(PrintWriter pw) { } } + /** + * Returns local endpoint used for the transfer, if known. + */ + public Optional localEndpoint() { + return Optional.ofNullable(_localEndpoint); + } + abstract public String name(); abstract public boolean hasCompletedSuccessfully(); diff --git a/modules/dcache-ftp/src/main/java/org/dcache/pool/movers/GFtpProtocol_2_nio.java b/modules/dcache-ftp/src/main/java/org/dcache/pool/movers/GFtpProtocol_2_nio.java index b17486ff8c7..31d95506e7c 100644 --- a/modules/dcache-ftp/src/main/java/org/dcache/pool/movers/GFtpProtocol_2_nio.java +++ b/modules/dcache-ftp/src/main/java/org/dcache/pool/movers/GFtpProtocol_2_nio.java @@ -721,4 +721,12 @@ public void setCellArgs(Args args) { _blockSize = args.getIntOption("gsiftpBlockSize"); } } + + @Override + public Optional getLocalEndpoint() { + if (_mode == null) { + return Optional.empty(); + } + return _mode.localEndpoint(); + } }