Skip to content

Commit

Permalink
pool: Report correct client IP to billing for passive FTP transfers
Browse files Browse the repository at this point in the history
The pool incorrectly reported the FTP proxy address of the FTP door
even when a direct connection between the client and the pool was
established.

I am undecided how far back to fix this. Please advice.

Target: trunk
Request: 2.9
Request: 2.8
Request: 2.7
Request: 2.6
Require-notes: yes
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: http://rb.dcache.org/r/6940/
  • Loading branch information
gbehrmann committed Apr 25, 2014
1 parent 942035a commit 7e6e2ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Expand Up @@ -285,6 +285,10 @@ public ProtocolFamily getProtocolFamily()
return _protocolFamily;
}

public void setSocketAddress(InetSocketAddress address) {
_addr = address;
}

@Override
public InetSocketAddress getSocketAddress() {
return _addr;
Expand Down
15 changes: 15 additions & 0 deletions modules/dcache-ftp/src/main/java/org/dcache/ftp/data/Mode.java
Expand Up @@ -9,8 +9,12 @@
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.UnresolvedAddressException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.dcache.pool.repository.RepositoryChannel;

Expand Down Expand Up @@ -63,6 +67,9 @@ public abstract class Mode extends AbstractMultiplexerListener
/** Number of connections that have been closed. */
protected int _closed;

/** Remote addresses of data channels connected by this class. */
private final Set<InetSocketAddress> _remoteAddresses = new HashSet<>();

/** Constructs a new mode for outgoing connections. */
public Mode(Role role, RepositoryChannel file, ConnectionMonitor monitor)
throws IOException
Expand Down Expand Up @@ -156,6 +163,12 @@ public long getSize()
return _size;
}

/** Returns the remote addresses the mode connected with. */
public Collection<InetSocketAddress> getRemoteAddresses()
{
return Collections.unmodifiableCollection(_remoteAddresses);
}

/**
* Like calling _file.transferTo().
*
Expand Down Expand Up @@ -358,6 +371,7 @@ public void accept(Multiplexer multiplexer, SelectionKey key)
Socket socket = channel.socket();
_opened++;
multiplexer.say("Opened " + socket);
_remoteAddresses.add((InetSocketAddress) socket.getRemoteSocketAddress());
channel.configureBlocking(false);
if (_bufferSize > 0) {
channel.socket().setSendBufferSize(_bufferSize);
Expand Down Expand Up @@ -386,6 +400,7 @@ public void connect(Multiplexer multiplexer, SelectionKey key)
Socket socket = channel.socket();
_opened++;
multiplexer.say("Opened " + socket);
_remoteAddresses.add((InetSocketAddress) socket.getRemoteSocketAddress());
newConnection(multiplexer, channel);
}
} catch (IOException e) {
Expand Down
@@ -1,5 +1,6 @@
package org.dcache.pool.movers;

import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -587,6 +588,10 @@ public void runIO(FileAttributes fileAttributes,
*/
gftpProtocolInfo.setBytesTransferred(getBytesTransferred());
gftpProtocolInfo.setTransferTime(getTransferTime());
if (passive) {
gftpProtocolInfo.setSocketAddress(
Iterables.getFirst(mode.getRemoteAddresses(), gftpProtocolInfo.getSocketAddress()));
}
}
}

Expand Down

0 comments on commit 7e6e2ef

Please sign in to comment.