From a1140fceff66cb5e1430ee00fd9db596c3186de8 Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Fri, 8 Sep 2023 10:22:43 +0200 Subject: [PATCH] pool: include local endpoint for ftp transfers Motivation: billing information harmonization Modification: Update Ftp Mode to expose local endpoint. Result: ftp local endpoint info is available in billing logs Acked-by: Paul Millar Target: master Require-book: no Require-notes: yes --- .../src/main/java/org/dcache/ftp/data/Mode.java | 15 +++++++++++++++ .../dcache/pool/movers/GFtpProtocol_2_nio.java | 8 ++++++++ 2 files changed, 23 insertions(+) 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(); + } }