Package org.apache.sshd.common.forward
Class DefaultForwarder
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,Closeable
,Forwarder
,PortForwardingEventListenerManager
,PortForwardingEventListenerManagerHolder
,PortForwardingInformationProvider
,PortForwardingManager
,SessionContextHolder
,SessionHolder<Session>
public class DefaultForwarder extends AbstractInnerCloseable implements Forwarder, SessionHolder<Session>, PortForwardingEventListenerManager
Requests a "tcpip-forward" action
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
DefaultForwarder.StaticIoHandler
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
-
Field Summary
-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description DefaultForwarder(ConnectionService service)
-
Method Summary
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingInformationProvider
isRemotePortForwardingStartedForPort
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingManager
startLocalPortForwarding
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
STATIC_IO_MSG_RECEIVED_EVENTS
public static final java.util.Set<ClientChannelEvent> STATIC_IO_MSG_RECEIVED_EVENTS
-
service
private final ConnectionService service
-
socksProxyIoHandlerFactory
private final IoHandlerFactory socksProxyIoHandlerFactory
-
sessionInstance
private final Session sessionInstance
-
localLock
private final java.lang.Object localLock
-
localToRemote
private final java.util.Map<SshdSocketAddress,SshdSocketAddress> localToRemote
-
boundLocals
private final java.util.Map<SshdSocketAddress,java.net.InetSocketAddress> boundLocals
-
dynamicLock
private final java.lang.Object dynamicLock
-
remoteToLocal
private final java.util.Map<java.lang.Integer,SshdSocketAddress> remoteToLocal
-
dynamicLocal
private final java.util.Map<java.lang.Integer,SocksProxy> dynamicLocal
-
boundDynamic
private final java.util.Map<java.lang.Integer,java.net.InetSocketAddress> boundDynamic
-
localForwards
private final java.util.Set<LocalForwardingEntry> localForwards
-
staticIoHandlerFactory
private final IoHandlerFactory staticIoHandlerFactory
-
listeners
private final java.util.Collection<PortForwardingEventListener> listeners
-
managersHolder
private final java.util.Collection<PortForwardingEventListenerManager> managersHolder
-
listenerProxy
private final PortForwardingEventListener listenerProxy
-
localAcceptor
private IoAcceptor localAcceptor
-
dynamicAcceptor
private IoAcceptor dynamicAcceptor
-
-
Constructor Detail
-
DefaultForwarder
public DefaultForwarder(ConnectionService service)
-
-
Method Detail
-
getPortForwardingEventListenerProxy
public PortForwardingEventListener getPortForwardingEventListenerProxy()
- Specified by:
getPortForwardingEventListenerProxy
in interfacePortForwardingEventListenerManager
- Returns:
- A proxy listener representing all the currently registered listener through this manager
-
addPortForwardingEventListener
public void addPortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManager
Add a port forwarding listener- Specified by:
addPortForwardingEventListener
in interfacePortForwardingEventListenerManager
- Parameters:
listener
- ThePortForwardingEventListener
to add - nevernull
-
removePortForwardingEventListener
public void removePortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManager
Remove a port forwarding listener- Specified by:
removePortForwardingEventListener
in interfacePortForwardingEventListenerManager
- Parameters:
listener
- ThePortForwardingEventListener
to remove - ignored ifnull
-
getRegisteredManagers
public java.util.Collection<PortForwardingEventListenerManager> getRegisteredManagers()
- Specified by:
getRegisteredManagers
in interfacePortForwardingEventListenerManagerHolder
- Returns:
- The currently registered managers. Note: it is highly recommended that implementors return either an un-modifiable collection or a copy of the current one. Callers, should avoid modifying the retrieved value.
-
addPortForwardingEventListenerManager
public boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
addPortForwardingEventListenerManager
in interfacePortForwardingEventListenerManagerHolder
-
removePortForwardingEventListenerManager
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
removePortForwardingEventListenerManager
in interfacePortForwardingEventListenerManagerHolder
-
getSession
public Session getSession()
- Specified by:
getSession
in interfaceSessionHolder<Session>
-
getConnectionService
public final ConnectionService getConnectionService()
-
getDefaultListeners
protected java.util.Collection<PortForwardingEventListener> getDefaultListeners()
-
startLocalPortForwarding
public SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws java.io.IOException
Description copied from interface:PortForwardingManager
Start forwarding the given local address on the client to the given address on the server.- Specified by:
startLocalPortForwarding
in interfacePortForwardingManager
- Parameters:
local
- The local addressremote
- The remote address- Returns:
- The bound
SshdSocketAddress
- Throws:
java.io.IOException
- If failed to create the requested binding
-
stopLocalPortForwarding
public void stopLocalPortForwarding(SshdSocketAddress local) throws java.io.IOException
Description copied from interface:PortForwardingManager
Stop forwarding the given local address.- Specified by:
stopLocalPortForwarding
in interfacePortForwardingManager
- Parameters:
local
- The local address- Throws:
java.io.IOException
- If failed to cancel the requested binding
-
unbindLocalForwarding
protected void unbindLocalForwarding(SshdSocketAddress local, SshdSocketAddress remote, java.net.InetSocketAddress bound) throws java.io.IOException
- Throws:
java.io.IOException
-
startRemotePortForwarding
public SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws java.io.IOException
Description copied from interface:PortForwardingManager
Start forwarding tcpip from the given address on the server to the given address on the client.
The remote host name is the address to bind to on the server:- "" means that connections are to be accepted on all protocol families supported by the SSH implementation
- "0.0.0.0" means to listen on all IPv4 addresses
- "::" means to listen on all IPv6 addresses
- "localhost" means to listen on all protocol families supported by the SSH implementation on loopback addresses only, [RFC3330] and RFC3513]
- "127.0.0.1" and "::1" indicate listening on the loopback interfaces for IPv4 and IPv6 respectively
- Specified by:
startRemotePortForwarding
in interfacePortForwardingManager
- Parameters:
remote
- The remote addresslocal
- The local address- Returns:
- The bound
SshdSocketAddress
- Throws:
java.io.IOException
- If failed to create the requested binding
-
stopRemotePortForwarding
public void stopRemotePortForwarding(SshdSocketAddress remote) throws java.io.IOException
Description copied from interface:PortForwardingManager
Stop forwarding of the given remote address.- Specified by:
stopRemotePortForwarding
in interfacePortForwardingManager
- Parameters:
remote
- The remote address- Throws:
java.io.IOException
- If failed to cancel the requested binding
-
signalTearingDownExplicitTunnel
protected void signalTearingDownExplicitTunnel(SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remote) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTearingDownExplicitTunnel
protected void signalTearingDownExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTornDownExplicitTunnel
protected void signalTornDownExplicitTunnel(SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTornDownExplicitTunnel
protected void signalTornDownExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
startDynamicPortForwarding
public SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws java.io.IOException
Description copied from interface:PortForwardingManager
Start dynamic local port forwarding using a SOCKS proxy.- Specified by:
startDynamicPortForwarding
in interfacePortForwardingManager
- Parameters:
local
- The local address- Returns:
- The bound
SshdSocketAddress
- Throws:
java.io.IOException
- If failed to create the requested binding
-
signalEstablishedDynamicTunnel
protected void signalEstablishedDynamicTunnel(SshdSocketAddress local, SshdSocketAddress boundAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishedDynamicTunnel
protected void signalEstablishedDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress boundAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishingDynamicTunnel
protected void signalEstablishingDynamicTunnel(SshdSocketAddress local) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishingDynamicTunnel
protected void signalEstablishingDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress local) throws java.io.IOException
- Throws:
java.io.IOException
-
stopDynamicPortForwarding
public void stopDynamicPortForwarding(SshdSocketAddress local) throws java.io.IOException
Description copied from interface:PortForwardingManager
Stop a previously started dynamic port forwarding.- Specified by:
stopDynamicPortForwarding
in interfacePortForwardingManager
- Parameters:
local
- The local address- Throws:
java.io.IOException
- If failed to cancel the requested binding
-
unbindDynamicForwarding
protected void unbindDynamicForwarding(SshdSocketAddress local, SocksProxy proxy, java.net.InetSocketAddress bound) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTearingDownDynamicTunnel
protected void signalTearingDownDynamicTunnel(SshdSocketAddress address) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTearingDownDynamicTunnel
protected void signalTearingDownDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress address) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTornDownDynamicTunnel
protected void signalTornDownDynamicTunnel(SshdSocketAddress address, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
signalTornDownDynamicTunnel
protected void signalTornDownDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress address, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
getForwardedPort
public SshdSocketAddress getForwardedPort(int remotePort)
- Specified by:
getForwardedPort
in interfaceForwarder
- Parameters:
remotePort
- The remote port- Returns:
- The local
SshdSocketAddress
that the remote port is forwarded to
-
localPortForwardingRequested
public SshdSocketAddress localPortForwardingRequested(SshdSocketAddress local) throws java.io.IOException
Description copied from interface:Forwarder
Called when the other side requested a remote port forward.- Specified by:
localPortForwardingRequested
in interfaceForwarder
- Parameters:
local
- The request address- Returns:
- The bound local
SshdSocketAddress
-null
if not allowed to forward - Throws:
java.io.IOException
- If failed to handle request
-
localPortForwardingCancelled
public void localPortForwardingCancelled(SshdSocketAddress local) throws java.io.IOException
Description copied from interface:Forwarder
Called when the other side cancelled a remote port forward.- Specified by:
localPortForwardingCancelled
in interfaceForwarder
- Parameters:
local
- The localSshdSocketAddress
- Throws:
java.io.IOException
- If failed to handle request
-
signalEstablishingExplicitTunnel
protected void signalEstablishingExplicitTunnel(SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishingExplicitTunnel
protected void signalEstablishingExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishedExplicitTunnel
protected void signalEstablishedExplicitTunnel(SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding, SshdSocketAddress boundAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
signalEstablishedExplicitTunnel
protected void signalEstablishedExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding, SshdSocketAddress boundAddress, java.lang.Throwable reason) throws java.io.IOException
- Throws:
java.io.IOException
-
invokePortEventListenerSignaller
protected void invokePortEventListenerSignaller(Invoker<PortForwardingEventListener,java.lang.Void> invoker) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
invokePortEventListenerSignallerListeners
protected void invokePortEventListenerSignallerListeners(java.util.Collection<? extends PortForwardingEventListener> listeners, Invoker<PortForwardingEventListener,java.lang.Void> invoker) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
invokePortEventListenerSignallerHolders
protected void invokePortEventListenerSignallerHolders(java.util.Collection<? extends PortForwardingEventListenerManager> holders, Invoker<PortForwardingEventListener,java.lang.Void> invoker) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseable
in classAbstractInnerCloseable
-
preClose
protected void preClose()
Description copied from class:AbstractCloseable
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClose
in classAbstractCloseable
-
createIoAcceptor
protected IoAcceptor createIoAcceptor(Factory<? extends IoHandler> handlerFactory)
-
getLocalIoAcceptor
protected IoAcceptor getLocalIoAcceptor()
-
getDynamicIoAcceptor
protected IoAcceptor getDynamicIoAcceptor()
-
doBind
protected java.net.InetSocketAddress doBind(SshdSocketAddress address, IoAcceptor acceptor) throws java.io.IOException
- Parameters:
address
- The request bind addressacceptor
- AnIoAcceptor
to bind addresses- Returns:
- The
InetSocketAddress
to which the binding occurred - Throws:
java.io.IOException
- If failed to bind
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getBoundLocalPortForwards
public java.util.List<SshdSocketAddress> getBoundLocalPortForwards(int port)
- Specified by:
getBoundLocalPortForwards
in interfacePortForwardingInformationProvider
- Parameters:
port
- The port number- Returns:
- The local bound
SshdSocketAddress
-es for the port - See Also:
isLocalPortForwardingStartedForPort
,PortForwardingInformationProvider.getStartedLocalPortForwards()
-
isLocalPortForwardingStartedForPort
public boolean isLocalPortForwardingStartedForPort(int port)
Description copied from interface:PortForwardingInformationProvider
Test if local port forwarding is started- Specified by:
isLocalPortForwardingStartedForPort
in interfacePortForwardingInformationProvider
- Parameters:
port
- The local port- Returns:
true
if local port forwarding is started- See Also:
getBoundLocalPortForwards
-
getLocalForwardsBindings
public java.util.List<java.util.Map.Entry<SshdSocketAddress,SshdSocketAddress>> getLocalForwardsBindings()
- Specified by:
getLocalForwardsBindings
in interfacePortForwardingInformationProvider
- Returns:
- A snapshot of the currently bound forwarded local ports as "pairs" of local/remote
SshdSocketAddress
-es
-
getStartedLocalPortForwards
public java.util.List<SshdSocketAddress> getStartedLocalPortForwards()
- Specified by:
getStartedLocalPortForwards
in interfacePortForwardingInformationProvider
- Returns:
- A
List
snapshot of the currently started local port forward bindings
-
getRemoteForwardsBindings
public java.util.List<java.util.Map.Entry<java.lang.Integer,SshdSocketAddress>> getRemoteForwardsBindings()
- Specified by:
getRemoteForwardsBindings
in interfacePortForwardingInformationProvider
- Returns:
- A snapshot of the currently bound forwarded remote ports as "pairs" of port + bound
SshdSocketAddress
-
getBoundRemotePortForward
public SshdSocketAddress getBoundRemotePortForward(int port)
- Specified by:
getBoundRemotePortForward
in interfacePortForwardingInformationProvider
- Parameters:
port
- The port number- Returns:
- The remote bound
SshdSocketAddress
for the port -null
if none bound - See Also:
isRemotePortForwardingStartedForPort
,PortForwardingInformationProvider.getStartedRemotePortForwards()
-
getStartedRemotePortForwards
public java.util.NavigableSet<java.lang.Integer> getStartedRemotePortForwards()
- Specified by:
getStartedRemotePortForwards
in interfacePortForwardingInformationProvider
- Returns:
- A
NavigableSet
snapshot of the currently started remote port forwards
-
-