Skip to content

Commit

Permalink
pool: include local endpoint for ftp transfers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kofemann committed Sep 11, 2023
1 parent effabfe commit a1140fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -591,6 +599,13 @@ public void getInfo(PrintWriter pw) {
}
}

/**
* Returns local endpoint used for the transfer, if known.
*/
public Optional<InetSocketAddress> localEndpoint() {
return Optional.ofNullable(_localEndpoint);
}

abstract public String name();

abstract public boolean hasCompletedSuccessfully();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,12 @@ public void setCellArgs(Args args) {
_blockSize = args.getIntOption("gsiftpBlockSize");
}
}

@Override
public Optional<InetSocketAddress> getLocalEndpoint() {
if (_mode == null) {
return Optional.empty();
}
return _mode.localEndpoint();
}
}

0 comments on commit a1140fc

Please sign in to comment.