Package org.apache.sshd.common.forward
Class DefaultForwarder
-
- All Implemented Interfaces:
Closeable,AutoCloseable,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- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
-
Field Summary
Fields Modifier and Type Field Description static Set<ClientChannelEvent>STATIC_IO_MSG_RECEIVED_EVENTS-
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 Set<ClientChannelEvent> STATIC_IO_MSG_RECEIVED_EVENTS
-
-
Constructor Detail
-
DefaultForwarder
public DefaultForwarder(ConnectionService service)
-
-
Method Detail
-
getPortForwardingEventListenerProxy
public PortForwardingEventListener getPortForwardingEventListenerProxy()
- Specified by:
getPortForwardingEventListenerProxyin interfacePortForwardingEventListenerManager- Returns:
- A proxy listener representing all the currently registered listener through this manager
-
addPortForwardingEventListener
public void addPortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManagerAdd a port forwarding listener- Specified by:
addPortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto add - nevernull
-
removePortForwardingEventListener
public void removePortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManagerRemove a port forwarding listener- Specified by:
removePortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto remove - ignored ifnull
-
getRegisteredManagers
public Collection<PortForwardingEventListenerManager> getRegisteredManagers()
- Specified by:
getRegisteredManagersin 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:
addPortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
removePortForwardingEventListenerManager
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
removePortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
getSession
public Session getSession()
- Specified by:
getSessionin interfaceSessionHolder<Session>
-
getConnectionService
public final ConnectionService getConnectionService()
-
getDefaultListeners
protected Collection<PortForwardingEventListener> getDefaultListeners()
-
startLocalPortForwarding
public SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
Description copied from interface:PortForwardingManagerStart forwarding the given local address on the client to the given address on the server.- Specified by:
startLocalPortForwardingin interfacePortForwardingManager- Parameters:
local- The local addressremote- The remote address- Returns:
- The bound
SshdSocketAddress - Throws:
IOException- If failed to create the requested binding
-
stopLocalPortForwarding
public void stopLocalPortForwarding(SshdSocketAddress local) throws IOException
Description copied from interface:PortForwardingManagerStop forwarding the given local address.- Specified by:
stopLocalPortForwardingin interfacePortForwardingManager- Parameters:
local- The local address- Throws:
IOException- If failed to cancel the requested binding
-
unbindLocalForwarding
protected void unbindLocalForwarding(SshdSocketAddress local, SshdSocketAddress remote, InetSocketAddress bound) throws IOException
- Throws:
IOException
-
startRemotePortForwarding
public SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException
Description copied from interface:PortForwardingManagerStart 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:
startRemotePortForwardingin interfacePortForwardingManager- Parameters:
remote- The remote addresslocal- The local address- Returns:
- The bound
SshdSocketAddress - Throws:
IOException- If failed to create the requested binding
-
stopRemotePortForwarding
public void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException
Description copied from interface:PortForwardingManagerStop forwarding of the given remote address.- Specified by:
stopRemotePortForwardingin interfacePortForwardingManager- Parameters:
remote- The remote address- Throws:
IOException- If failed to cancel the requested binding
-
signalTearingDownExplicitTunnel
protected void signalTearingDownExplicitTunnel(SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remote) throws IOException
- Throws:
IOException
-
signalTearingDownExplicitTunnel
protected void signalTearingDownExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress) throws IOException
- Throws:
IOException
-
signalTornDownExplicitTunnel
protected void signalTornDownExplicitTunnel(SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason) throws IOException
- Throws:
IOException
-
signalTornDownExplicitTunnel
protected void signalTornDownExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason) throws IOException
- Throws:
IOException
-
startDynamicPortForwarding
public SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException
Description copied from interface:PortForwardingManagerStart dynamic local port forwarding using a SOCKS proxy.- Specified by:
startDynamicPortForwardingin interfacePortForwardingManager- Parameters:
local- The local address- Returns:
- The bound
SshdSocketAddress - Throws:
IOException- If failed to create the requested binding
-
signalEstablishedDynamicTunnel
protected void signalEstablishedDynamicTunnel(SshdSocketAddress local, SshdSocketAddress boundAddress, Throwable reason) throws IOException
- Throws:
IOException
-
signalEstablishedDynamicTunnel
protected void signalEstablishedDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress boundAddress, Throwable reason) throws IOException
- Throws:
IOException
-
signalEstablishingDynamicTunnel
protected void signalEstablishingDynamicTunnel(SshdSocketAddress local) throws IOException
- Throws:
IOException
-
signalEstablishingDynamicTunnel
protected void signalEstablishingDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress local) throws IOException
- Throws:
IOException
-
stopDynamicPortForwarding
public void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
Description copied from interface:PortForwardingManagerStop a previously started dynamic port forwarding.- Specified by:
stopDynamicPortForwardingin interfacePortForwardingManager- Parameters:
local- The local address- Throws:
IOException- If failed to cancel the requested binding
-
unbindDynamicForwarding
protected void unbindDynamicForwarding(SshdSocketAddress local, SocksProxy proxy, InetSocketAddress bound) throws IOException
- Throws:
IOException
-
signalTearingDownDynamicTunnel
protected void signalTearingDownDynamicTunnel(SshdSocketAddress address) throws IOException
- Throws:
IOException
-
signalTearingDownDynamicTunnel
protected void signalTearingDownDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress address) throws IOException
- Throws:
IOException
-
signalTornDownDynamicTunnel
protected void signalTornDownDynamicTunnel(SshdSocketAddress address, Throwable reason) throws IOException
- Throws:
IOException
-
signalTornDownDynamicTunnel
protected void signalTornDownDynamicTunnel(PortForwardingEventListener listener, SshdSocketAddress address, Throwable reason) throws IOException
- Throws:
IOException
-
getForwardedPort
public SshdSocketAddress getForwardedPort(int remotePort)
- Specified by:
getForwardedPortin interfaceForwarder- Parameters:
remotePort- The remote port- Returns:
- The local
SshdSocketAddressthat the remote port is forwarded to
-
localPortForwardingRequested
public SshdSocketAddress localPortForwardingRequested(SshdSocketAddress local) throws IOException
Description copied from interface:ForwarderCalled when the other side requested a remote port forward.- Specified by:
localPortForwardingRequestedin interfaceForwarder- Parameters:
local- The request address- Returns:
- The bound local
SshdSocketAddress-nullif not allowed to forward - Throws:
IOException- If failed to handle request
-
localPortForwardingCancelled
public void localPortForwardingCancelled(SshdSocketAddress local) throws IOException
Description copied from interface:ForwarderCalled when the other side cancelled a remote port forward.- Specified by:
localPortForwardingCancelledin interfaceForwarder- Parameters:
local- The localSshdSocketAddress- Throws:
IOException- If failed to handle request
-
signalEstablishingExplicitTunnel
protected void signalEstablishingExplicitTunnel(SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding) throws IOException
- Throws:
IOException
-
signalEstablishingExplicitTunnel
protected void signalEstablishingExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding) throws IOException
- Throws:
IOException
-
signalEstablishedExplicitTunnel
protected void signalEstablishedExplicitTunnel(SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding, SshdSocketAddress boundAddress, Throwable reason) throws IOException
- Throws:
IOException
-
signalEstablishedExplicitTunnel
protected void signalEstablishedExplicitTunnel(PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding, SshdSocketAddress boundAddress, Throwable reason) throws IOException
- Throws:
IOException
-
invokePortEventListenerSignaller
protected void invokePortEventListenerSignaller(Invoker<PortForwardingEventListener,Void> invoker) throws Throwable
- Throws:
Throwable
-
invokePortEventListenerSignallerListeners
protected void invokePortEventListenerSignallerListeners(Collection<? extends PortForwardingEventListener> listeners, Invoker<PortForwardingEventListener,Void> invoker) throws Throwable
- Throws:
Throwable
-
invokePortEventListenerSignallerHolders
protected void invokePortEventListenerSignallerHolders(Collection<? extends PortForwardingEventListenerManager> holders, Invoker<PortForwardingEventListener,Void> invoker) throws Throwable
- Throws:
Throwable
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
preClose
protected void preClose()
- Overrides:
preClosein classAbstractCloseable
-
createIoAcceptor
protected IoAcceptor createIoAcceptor(Factory<? extends IoHandler> handlerFactory)
-
getLocalIoAcceptor
protected IoAcceptor getLocalIoAcceptor()
-
getDynamicIoAcceptor
protected IoAcceptor getDynamicIoAcceptor()
-
doBind
protected InetSocketAddress doBind(SshdSocketAddress address, IoAcceptor acceptor) throws IOException
- Parameters:
address- The request bind addressacceptor- AnIoAcceptorto bind addresses- Returns:
- The
InetSocketAddressto which the binding occurred - Throws:
IOException- If failed to bind
-
getBoundLocalPortForwards
public List<SshdSocketAddress> getBoundLocalPortForwards(int port)
- Specified by:
getBoundLocalPortForwardsin 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:PortForwardingInformationProviderTest if local port forwarding is started- Specified by:
isLocalPortForwardingStartedForPortin interfacePortForwardingInformationProvider- Parameters:
port- The local port- Returns:
trueif local port forwarding is started- See Also:
getBoundLocalPortForwards
-
getLocalForwardsBindings
public List<Map.Entry<SshdSocketAddress,SshdSocketAddress>> getLocalForwardsBindings()
- Specified by:
getLocalForwardsBindingsin interfacePortForwardingInformationProvider- Returns:
- A snapshot of the currently bound forwarded local ports as "pairs" of local/remote
SshdSocketAddress-es
-
getStartedLocalPortForwards
public List<SshdSocketAddress> getStartedLocalPortForwards()
- Specified by:
getStartedLocalPortForwardsin interfacePortForwardingInformationProvider- Returns:
- A
Listsnapshot of the currently started local port forward bindings
-
getRemoteForwardsBindings
public List<Map.Entry<Integer,SshdSocketAddress>> getRemoteForwardsBindings()
- Specified by:
getRemoteForwardsBindingsin 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:
getBoundRemotePortForwardin interfacePortForwardingInformationProvider- Parameters:
port- The port number- Returns:
- The remote bound
SshdSocketAddressfor the port -nullif none bound - See Also:
isRemotePortForwardingStartedForPort,PortForwardingInformationProvider.getStartedRemotePortForwards()
-
getStartedRemotePortForwards
public NavigableSet<Integer> getStartedRemotePortForwards()
- Specified by:
getStartedRemotePortForwardsin interfacePortForwardingInformationProvider- Returns:
- A
NavigableSetsnapshot of the currently started remote port forwards
-
-