Package org.jivesoftware.openfire.net
Class VirtualConnection
- java.lang.Object
-
- org.jivesoftware.openfire.net.VirtualConnection
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Connection
- Direct Known Subclasses:
ClientSessionConnection,HttpSession.HttpVirtualConnection,WebSocketConnection
public abstract class VirtualConnection extends Object implements Connection
Abstract implementation of the Connection interface that models abstract connections. Abstract connections are connections that don't have a physical connection counterpart. Instead they can be seen as conceptual or just 'abstract' connections.Default values and common behavior of virtual connections are modeled in this class. Subclasses should just need to specify how packets are delivered and what means closing the connection.
- Author:
- Gaston Dombiak
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.State, Connection.TLSPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected LocalSessionsession-
Fields inherited from interface org.jivesoftware.openfire.Connection
additionalNamespaces
-
-
Constructor Summary
Constructors Constructor Description VirtualConnection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCompression()Adds the compression filter to the connection but only filter incoming traffic.voidclose()Closes the session, the virtual connection and notifies listeners that the connection has been closed.voidclose(org.xmpp.packet.StreamError error)Closes the session, the virtual connection and notifies listeners that the connection has been closed.abstract voidcloseVirtualConnection(org.xmpp.packet.StreamError error)Closes the virtual connection.Certificate[]getLocalCertificates()Returns the local underlyingX509Certificatechain for the connection.intgetMajorXMPPVersion()Returns the major version of XMPP being used by this connection (major_version.minor_version.intgetMinorXMPPVersion()Returns the minor version of XMPP being used by this connection (major_version.minor_version.PacketDeliverergetPacketDeliverer()Returns the packet deliverer to use when delivering a packet over the socket fails.Certificate[]getPeerCertificates()Returns the underlyingX509Certificatefor the connection of the peer.voidinit(LocalSession session)Initializes the connection with it's owning session.booleanisClosed()Returns true if the connection/session is closed.booleanisCompressed()Returns true if the connection is using compression.booleanisEncrypted()Returns true if this connection is encrypted.booleanisInitialized()Checks if the connection has finished initialization.booleanisSecure()Deprecated.booleanisUsingSelfSignedCertificate()Returns true if the other peer of this session presented a self-signed certificate.voidregisterCloseListener(ConnectionCloseListener listener, Object handbackMessage)Registers a listener for close event notification.voidreinit(LocalSession session)Reinitializes the connection to switch to a different session.voidremoveCloseListener(ConnectionCloseListener listener)Removes a registered close event listener.voidsetUsingSelfSignedCertificate(boolean isSelfSigned)Keeps track if the other peer of this session presented a self-signed certificate.voidsetXMPPVersion(int majorVersion, int minorVersion)Sets the XMPP version information.voidstartCompression()Start compressing outgoing traffic for this connection.voidstartTLS(boolean clientMode, boolean directTLS)Encrypts the plain connection by negotiating TLS with the other peer.booleanvalidate()Verifies that the connection is still live.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.Connection
deliver, deliverRawText, getAdditionalNamespaces, getAddress, getCipherSuiteName, getConfiguration, getHostAddress, getHostName, getTLSProtocolName, setAdditionalNamespaces, systemShutdown
-
-
-
-
Field Detail
-
session
protected LocalSession session
-
-
Method Detail
-
getMajorXMPPVersion
public int getMajorXMPPVersion()
Description copied from interface:ConnectionReturns the major version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
getMajorXMPPVersionin interfaceConnection- Returns:
- the major XMPP version being used by this connection.
-
getMinorXMPPVersion
public int getMinorXMPPVersion()
Description copied from interface:ConnectionReturns the minor version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
getMinorXMPPVersionin interfaceConnection- Returns:
- the minor XMPP version being used by this connection.
-
getLocalCertificates
public Certificate[] getLocalCertificates()
Description copied from interface:ConnectionReturns the local underlyingX509Certificatechain for the connection.- Specified by:
getLocalCertificatesin interfaceConnection- Returns:
- an ordered array of certificates, with the local certificate
first followed by any certificate authorities. If no certificates
is present for the connection, then
nullis returned.
-
getPeerCertificates
public Certificate[] getPeerCertificates()
Description copied from interface:ConnectionReturns the underlyingX509Certificatefor the connection of the peer.- Specified by:
getPeerCertificatesin interfaceConnection- Returns:
- an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities.
-
setUsingSelfSignedCertificate
public void setUsingSelfSignedCertificate(boolean isSelfSigned)
Description copied from interface:ConnectionKeeps track if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Specified by:
setUsingSelfSignedCertificatein interfaceConnection- Parameters:
isSelfSigned- true if the other peer presented a self-signed certificate.
-
isUsingSelfSignedCertificate
public boolean isUsingSelfSignedCertificate()
Description copied from interface:ConnectionReturns true if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Specified by:
isUsingSelfSignedCertificatein interfaceConnection- Returns:
- true if the other peer of this session presented a self-signed certificate.
-
isClosed
public boolean isClosed()
Description copied from interface:ConnectionReturns true if the connection/session is closed.- Specified by:
isClosedin interfaceConnection- Returns:
- true if the connection is closed.
-
isCompressed
public boolean isCompressed()
Description copied from interface:ConnectionReturns true if the connection is using compression.- Specified by:
isCompressedin interfaceConnection- Returns:
- true if the connection is using compression.
-
setXMPPVersion
public void setXMPPVersion(int majorVersion, int minorVersion)Description copied from interface:ConnectionSets the XMPP version information. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
setXMPPVersionin interfaceConnection- Parameters:
majorVersion- the major version.minorVersion- the minor version.
-
getPacketDeliverer
@Nullable public PacketDeliverer getPacketDeliverer()
Description copied from interface:ConnectionReturns the packet deliverer to use when delivering a packet over the socket fails. The packet deliverer will retry to send the packet using some other connection or will store the packet offline for later retrieval. When null, packets will just be dropped.- Specified by:
getPacketDelivererin interfaceConnection- Returns:
- the packet deliverer to use when delivering a packet over the socket fails.
-
startTLS
public void startTLS(boolean clientMode, boolean directTLS) throws ExceptionDescription copied from interface:ConnectionEncrypts the plain connection by negotiating TLS with the other peer. In a server-2-server connection the server requesting the TLS negotiation will be the client and the other server will be the server during the TLS negotiation. Therefore, the server requesting the TLS negotiation must passtruein theclientModeparameter and the server receiving the TLS request must passfalsein theclientModeparameter.In the case of client-2-server the XMPP server must pass
falsein theclientModeparameter since it will behave as the server in the TLS negotiation.- Specified by:
startTLSin interfaceConnection- Parameters:
clientMode- boolean indicating if this entity is a client or a server in the TLS negotiation.directTLS- boolean indicating if the negotiation is directTLS (true) or startTLS (false).- Throws:
Exception- if an error occurred while encrypting the connection.
-
addCompression
public void addCompression()
Description copied from interface:ConnectionAdds the compression filter to the connection but only filter incoming traffic. Do not filter outgoing traffic since we still need to send an uncompressed stanza to the client indicating that he can start compressing the traffic. After we sent the uncompresses stanza we can start compression outgoing traffic as well.- Specified by:
addCompressionin interfaceConnection
-
startCompression
public void startCompression()
Description copied from interface:ConnectionStart compressing outgoing traffic for this connection. Compression will only be available after TLS has been negotiated. This means that a connection can never be using compression before TLS. However, it is possible to use compression without TLS.- Specified by:
startCompressionin interfaceConnection
-
isSecure
@Deprecated public boolean isSecure()
Deprecated.Description copied from interface:ConnectionReturns true if this connection is secure.- Specified by:
isSecurein interfaceConnection- Returns:
- true if the connection is secure (e.g. TLS)
-
isEncrypted
public boolean isEncrypted()
Description copied from interface:ConnectionReturns true if this connection is encrypted.- Specified by:
isEncryptedin interfaceConnection- Returns:
- true if the connection is encrypted (e.g. uses TLS)
-
validate
public boolean validate()
Description copied from interface:ConnectionVerifies that the connection is still live. Typically this is done by sending a whitespace character between packets.- Specified by:
validatein interfaceConnection- Returns:
- true if the socket remains valid, false otherwise.
-
init
public void init(LocalSession session)
Description copied from interface:ConnectionInitializes the connection with it's owning session. Allows the connection class to configure itself with session related information (e.g. stream ID).- Specified by:
initin interfaceConnection- Parameters:
session- the session that owns this connection
-
reinit
public void reinit(LocalSession session)
Description copied from interface:ConnectionReinitializes the connection to switch to a different session. This allows for XEP-0198 resumption and transport-switching.- Specified by:
reinitin interfaceConnection- Parameters:
session- The new session now owning the connection.
-
isInitialized
public boolean isInitialized()
Description copied from interface:ConnectionChecks if the connection has finished initialization.- Specified by:
isInitializedin interfaceConnection- Returns:
- true if connection has finished initialization.
-
close
public void close()
Closes the session, the virtual connection and notifies listeners that the connection has been closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection
-
close
public void close(@Nullable org.xmpp.packet.StreamError error)Closes the session, the virtual connection and notifies listeners that the connection has been closed.- Specified by:
closein interfaceConnection- Parameters:
error- If non-null, the end-stream tag will be preceded with this error.
-
registerCloseListener
public void registerCloseListener(ConnectionCloseListener listener, Object handbackMessage)
Description copied from interface:ConnectionRegisters a listener for close event notification. Registrations after the Session is closed will be immediately notified before the registration call returns (within the context of the registration call). An optional handback object can be associated with the registration if the same listener is registered to listen for multiple connection closures.- Specified by:
registerCloseListenerin interfaceConnection- Parameters:
listener- the listener to register for events.handbackMessage- the object to send in the event notification.
-
removeCloseListener
public void removeCloseListener(ConnectionCloseListener listener)
Description copied from interface:ConnectionRemoves a registered close event listener. Registered listeners must be able to receive close events up until the time this method returns. (i.e. it is possible to call unregister, receive a close event registration, and then have the unregister call return.)- Specified by:
removeCloseListenerin interfaceConnection- Parameters:
listener- the listener to deregister for close events.
-
closeVirtualConnection
public abstract void closeVirtualConnection(@Nullable org.xmpp.packet.StreamError error)Closes the virtual connection. Subclasses should indicate what closing a virtual connection means. At this point the session has a CLOSED state.- Parameters:
error- If non-null, this error will be sent to the peer before the connection is disconnected.
-
-