- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ConnectionOrientedTransportMapping<UdpAddress>,TlsTransportMappingConfig<java.security.cert.X509Certificate>,X509TlsTransportMappingConfig,TransportMapping<UdpAddress>
public class DTLSTM extends DefaultUdpTransportMapping implements X509TlsTransportMappingConfig, ConnectionOrientedTransportMapping<UdpAddress>
TheDTLSTMimplements the Datagram Transport Layer Security Transport Mapping (TLS-TM) as defined by RFC 5953 with the new IO API andSSLEngine.It uses a single thread for processing incoming and outgoing messages. The thread is started when the
listenmethod is called, or when an outgoing request is sent using thesendMessagemethod.- Since:
- 3.0
- Version:
- 3.3.2
- Author:
- Frank Fock
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.snmp4j.transport.DefaultUdpTransportMapping
DefaultUdpTransportMapping.ListenThread
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECTION_TIMEOUTstatic java.lang.StringDEFAULT_DTLSTM_PROTOCOLSstatic intDEFAULT_HANDSHAKE_TIMEOUTstatic intDEFAULT_SOCKET_TIMEOUTstatic intMAX_HANDSHAKE_LOOPSstatic intMAX_TLS_PAYLOAD_SIZE-
Fields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, maxInboundMessageSize, transportListener
-
Fields inherited from class org.snmp4j.transport.DefaultUdpTransportMapping
listener, listenerThread, socket
-
Fields inherited from class org.snmp4j.transport.UdpTransportMapping
udpAddress
-
-
Constructor Summary
Constructors Constructor Description DTLSTM()Creates a default UDP transport mapping with the server for incoming messages disabled.DTLSTM(DtlsAddress address)Creates a TLS transport mapping with the server for incoming messages bind to the given DTLS address.DTLSTM(DtlsAddress address, boolean serverEnabled)Creates a TLS transport mapping with the server for incoming messages bind to the given address.DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress)Creates a DTLS transport mapping that binds to the given address (interface) on the local host.DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress, CounterSupport counterSupport)Creates a TLS transport mapping that binds to the given address (interface) on the local host and runs as a server.DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress, CounterSupport counterSupport, boolean serverEnabled)Creates a TLS transport mapping that binds to the given address (interface) on the local host.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTransportStateListener(TransportStateListener l)Adds a transport state listener that is to be informed about connection state changes.voidclose()Closes the socket and stops the listener thread and socket cleaner timer (ifDefaultUdpTransportMapping.getSocketTimeout()is greater than zero).booleanclose(UdpAddress remoteAddress)Closes a connection to the supplied remote address, if it is open.protected java.net.DatagramPacketcreateHandshakePacket(byte[] buf, java.net.SocketAddress socketAddr)protected SSLEngineConfiguratorensureSslEngineConfigurator()Returns the configuredsetSslEngineConfigurator(SSLEngineConfigurator)or theDefaultSSLEngineConfigurationwhich will then become the configured SSL engine configurator.protected voidfireConnectionStateChanged(TransportStateEvent change)protected voidfireProcessMessage(java.net.DatagramPacket packet, java.nio.ByteBuffer bis, TransportStateReference stateReference)longgetConnectionTimeout()Gets the connection timeout.CounterSupportgetCounterSupport()intgetDtlsHandshakeThreadPoolSize()intgetHandshakeTimeout()Gets the maximum number of milliseconds to wait for the DTLS handshake operation to succeed.java.lang.StringgetKeyStore()java.lang.StringgetKeyStorePassword()UdpAddressgetListenAddress()Returns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.java.lang.StringgetLocalCertificateAlias()Gets the certificate alias used for client and server authentication.intgetMaxInboundMessageSize()Gets the inbound buffer size for incoming requests.MessageLengthDecodergetMessageLengthDecoder()Returns theMessageLengthDecoderused by this transport mapping.java.lang.StringgetProtocolVersionPropertyName()Returns the property name that is used by this transport mapping to determine the protocol versions from system properties.java.lang.String[]getProtocolVersions()Return the (D)TLS protocol versions used by this transport mapping.TlsTmSecurityCallback<java.security.cert.X509Certificate>getSecurityCallback()Gets theTlsTmSecurityCallbackassociated with thisTransportMappinghook which is called by the transport mapping to lookup TLS security parameters from external configuration.CommonTimergetSocketCleaner()Gets theCommonTimerthat controls socket cleanup operations.SSLEngineConfiguratorgetSslEngineConfigurator()java.lang.Class<? extends Address>getSupportedAddressClass()Gets the primaryAddressclass that is supported by this transport mapping.java.util.Set<java.lang.Class<? extends Address>>getSupportedAddressClasses()Returns a set ofDtlsAddressandUdpAddress.TransportTypegetSupportedTransportType()TLSTMTrustManagerFactorygetTrustManagerFactory()java.lang.StringgetTrustStore()java.lang.StringgetTrustStorePassword()booleanisAsyncMsgProcessingSupported()Returnstrueif asynchronous (multi-threaded) message processing may be implemented.booleanisServerEnabled()Checks whether a server for incoming requests is enabled.voidlisten()Starts the listener thread that accepts incoming messages.protected java.util.List<java.net.DatagramPacket>onReceiveTimeout(javax.net.ssl.SSLEngine engine, java.net.SocketAddress socketAddr)protected java.nio.ByteBufferprepareInPacket(java.net.DatagramPacket packet, byte[] buf, TransportStateReference tmStateReference)Prepare an network packet for the application.protected java.util.List<java.net.DatagramPacket>prepareOutPackets(UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference, java.net.DatagramSocket socket, long timeoutMillis, int maxRetries)Prepare an application message for sending over the network to the specified target address.protected java.util.List<java.net.DatagramPacket>produceHandshakePackets(javax.net.ssl.SSLEngine sslEngine, java.net.SocketAddress socketAddress)voidremoveTransportStateListener(TransportStateListener l)Removes the supplied transport state listener.voidsetAsyncMsgProcessingSupported(boolean asyncMsgProcessingSupported)Specifies whether this transport mapping has to support asynchronous messages processing or not.voidsetConnectionTimeout(long connectionTimeout)Sets the connection timeout.voidsetDtlsHandshakeThreadPoolSize(int dtlsHandshakeThreadPoolSize)Sets the maximum number of threads reserved for DTLS inbound connection handshake processing.voidsetHandshakeTimeout(int handshakeTimeout)Sets the maximum number of milliseconds to wait for the DTLS handshake operation to succeed.voidsetKeyStore(java.lang.String keyStore)voidsetKeyStorePassword(java.lang.String keyStorePassword)voidsetLocalCertificateAlias(java.lang.String localCertificateAlias)Sets the certificate alias used for client and server authentication by this TLSTM.voidsetMaxInboundMessageSize(int maxInboundMessageSize)Sets the maximum buffer size for incoming requests.voidsetMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.voidsetProtocolVersions(java.lang.String[] dtlsProtocols)Sets the DTLS protocols/versions that DTLSTM should use during handshake.voidsetSecurityCallback(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback)Sets theTlsTmSecurityCallbackassociated with thisTransportMappinghook.voidsetServerEnabled(boolean serverEnabled)Sets whether a server for incoming requests should be created when the transport is set into listen state.voidsetSslEngineConfigurator(SSLEngineConfigurator sslEngineConfigurator)voidsetTrustManagerFactory(TLSTMTrustManagerFactory trustManagerFactory)Set the TLSTM trust manager factory.voidsetTrustStore(java.lang.String trustStore)voidsetTrustStorePassword(java.lang.String trustStorePassword)-
Methods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, fireProcessMessage, removeTransportListener
-
Methods inherited from class org.snmp4j.transport.DefaultUdpTransportMapping
ensureSocket, getPriority, getReceiveBufferSize, getSocketTimeout, getThreadName, isListening, renewSocketAfterException, sendMessage, setPriority, setReceiveBufferSize, setSocketTimeout, setThreadName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.snmp4j.TransportMapping
addTransportListener, isAddressSupported, isAddressSupported, isListening, removeTransportListener, sendMessage
-
Methods inherited from class org.snmp4j.transport.UdpTransportMapping
getAddress
-
-
-
-
Field Detail
-
MAX_HANDSHAKE_LOOPS
public static final int MAX_HANDSHAKE_LOOPS
- See Also:
- Constant Field Values
-
DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_SOCKET_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_HANDSHAKE_TIMEOUT
public static final int DEFAULT_HANDSHAKE_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_DTLSTM_PROTOCOLS
public static final java.lang.String DEFAULT_DTLSTM_PROTOCOLS
- See Also:
- Constant Field Values
-
MAX_TLS_PAYLOAD_SIZE
public static final int MAX_TLS_PAYLOAD_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DTLSTM
public DTLSTM() throws java.io.IOExceptionCreates a default UDP transport mapping with the server for incoming messages disabled.- Throws:
java.net.UnknownHostException- if the local host cannot be determined.java.io.IOException
-
DTLSTM
public DTLSTM(DtlsAddress address) throws java.io.IOException
Creates a TLS transport mapping with the server for incoming messages bind to the given DTLS address. ThesecurityCallbackneeds to be specified beforelisten()is called.- Parameters:
address- server address to bind.- Throws:
java.io.IOException- on failure of binding a local port.- Since:
- 3.3.2
-
DTLSTM
public DTLSTM(DtlsAddress address, boolean serverEnabled) throws java.io.IOException
Creates a TLS transport mapping with the server for incoming messages bind to the given address. ThesecurityCallbackneeds to be specified beforelisten()is called.- Parameters:
address- server address to bind.serverEnabled- defines the role of the underlyingSSLEngine. Setting this tofalseenables theSSLEngine.setUseClientMode(boolean).- Throws:
java.io.IOException- on failure of binding a local port.- Since:
- 3.2.0
-
DTLSTM
public DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress) throws java.io.IOException
Creates a DTLS transport mapping that binds to the given address (interface) on the local host.- Parameters:
securityCallback- a security name callback to resolve X509 certificates to tmSecurityNames.serverAddress- the UdpAddress instance that describes the server address to listen on incoming connection requests.- Throws:
java.io.IOException- if the given address cannot be bound.
-
DTLSTM
public DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress, CounterSupport counterSupport) throws java.io.IOException
Creates a TLS transport mapping that binds to the given address (interface) on the local host and runs as a server.- Parameters:
securityCallback- a security name callback to resolve X509 certificates to tmSecurityNames.serverAddress- the UdpAddress instance that describes the server address to listen on incoming connection requests.counterSupport- The CounterSupport instance to be used to count events created by this TLSTM instance. To get a default instance, useCounterSupport.getInstance().- Throws:
java.io.IOException- if the given address cannot be bound.
-
DTLSTM
public DTLSTM(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback, DtlsAddress serverAddress, CounterSupport counterSupport, boolean serverEnabled) throws java.io.IOException
Creates a TLS transport mapping that binds to the given address (interface) on the local host.- Parameters:
securityCallback- a security name callback to resolve X509 certificates to tmSecurityNames.serverAddress- the UdpAddress instance that describes the server address to listen on incoming connection requests.counterSupport- The CounterSupport instance to be used to count events created by this TLSTM instance. To get a default instance, useCounterSupport.getInstance().serverEnabled- defines the role of the underlyingSSLEngine. Setting this tofalseenables theSSLEngine.setUseClientMode(boolean).- Throws:
java.io.IOException- if the given address cannot be bound.- Since:
- 3.2.0
-
-
Method Detail
-
listen
public void listen() throws java.io.IOExceptionStarts the listener thread that accepts incoming messages. The thread is started in daemon mode and thus it will not block application terminated. Nevertheless, theclose()method should be called to stop the listen thread gracefully and free associated ressources.- Specified by:
listenin interfaceTransportMapping<UdpAddress>- Overrides:
listenin classDefaultUdpTransportMapping- Throws:
java.io.IOException- if the listen port could not be bound to the server thread.
-
close
public void close() throws java.io.IOExceptionCloses the socket and stops the listener thread and socket cleaner timer (ifDefaultUdpTransportMapping.getSocketTimeout()is greater than zero).- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTransportMapping<UdpAddress>- Overrides:
closein classDefaultUdpTransportMapping- Throws:
java.io.IOException- if the socket cannot be closed.
-
getSupportedTransportType
public TransportType getSupportedTransportType()
- Specified by:
getSupportedTransportTypein interfaceTransportMapping<UdpAddress>- Returns:
TransportType.receiverifisServerEnabled()istrueandTransportType.senderotherwise.- Since:
- 3.2.0
-
getDtlsHandshakeThreadPoolSize
public int getDtlsHandshakeThreadPoolSize()
-
setDtlsHandshakeThreadPoolSize
public void setDtlsHandshakeThreadPoolSize(int dtlsHandshakeThreadPoolSize)
Sets the maximum number of threads reserved for DTLS inbound connection handshake processing.- Parameters:
dtlsHandshakeThreadPoolSize- the thread pool size that gets effective whenlisten()is called. Default isDEFAULT_DTLS_HANDSHAKE_THREADPOOL_SIZE.
-
getLocalCertificateAlias
public java.lang.String getLocalCertificateAlias()
Description copied from interface:TlsTransportMappingConfigGets the certificate alias used for client and server authentication. See alsoTlsTransportMappingConfig.setLocalCertificateAlias(java.lang.String)- Specified by:
getLocalCertificateAliasin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Returns:
- the certificate alias selecting the local certificate.
-
getProtocolVersions
public java.lang.String[] getProtocolVersions()
Description copied from interface:TlsTransportMappingConfigReturn the (D)TLS protocol versions used by this transport mapping.- Specified by:
getProtocolVersionsin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Returns:
- an array of SunJSSE TLS/DTLS provider (depending on the transport mapping type).
-
getProtocolVersionPropertyName
public java.lang.String getProtocolVersionPropertyName()
Returns the property name that is used by this transport mapping to determine the protocol versions from system properties.- Specified by:
getProtocolVersionPropertyNamein interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Returns:
- a property name like
SnmpConfigurator.P_TLS_VERSIONorSnmpConfigurator.P_DTLS_VERSION.
-
setProtocolVersions
public void setProtocolVersions(java.lang.String[] dtlsProtocols)
Sets the DTLS protocols/versions that DTLSTM should use during handshake. The default is defined byDEFAULT_DTLSTM_PROTOCOLS.- Specified by:
setProtocolVersionsin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Parameters:
dtlsProtocols- an array of TLS protocol (version) names supported by the SunJSSE provider. The order in the array defines which protocol is tried during handshake first.- Since:
- 3.0
-
getKeyStore
public java.lang.String getKeyStore()
- Specified by:
getKeyStorein interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
setKeyStore
public void setKeyStore(java.lang.String keyStore)
- Specified by:
setKeyStorein interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
getKeyStorePassword
public java.lang.String getKeyStorePassword()
- Specified by:
getKeyStorePasswordin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
setKeyStorePassword
public void setKeyStorePassword(java.lang.String keyStorePassword)
- Specified by:
setKeyStorePasswordin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
getTrustStore
public java.lang.String getTrustStore()
- Specified by:
getTrustStorein interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
setTrustStore
public void setTrustStore(java.lang.String trustStore)
- Specified by:
setTrustStorein interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
getTrustStorePassword
public java.lang.String getTrustStorePassword()
- Specified by:
getTrustStorePasswordin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
setTrustStorePassword
public void setTrustStorePassword(java.lang.String trustStorePassword)
- Specified by:
setTrustStorePasswordin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>
-
setLocalCertificateAlias
public void setLocalCertificateAlias(java.lang.String localCertificateAlias)
Sets the certificate alias used for client and server authentication by this TLSTM. Setting this property to a value other thannullfilters out any certificates which are not in the chain of the given alias.- Specified by:
setLocalCertificateAliasin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Parameters:
localCertificateAlias- a certificate alias which filters a single certification chain from thejavax.net.ssl.keyStorekey store to be used to authenticate this TLS transport mapping. Ifnullno filtering appears, which could lead to more than a single chain available for authentication by the peer, which would violate the TLSTM standard requirements.
-
getCounterSupport
public CounterSupport getCounterSupport()
-
getSupportedAddressClass
public java.lang.Class<? extends Address> getSupportedAddressClass()
Description copied from interface:TransportMappingGets the primaryAddressclass that is supported by this transport mapping.- Specified by:
getSupportedAddressClassin interfaceTransportMapping<UdpAddress>- Overrides:
getSupportedAddressClassin classUdpTransportMapping- Returns:
- a subclass of
Address.
-
getSupportedAddressClasses
public java.util.Set<java.lang.Class<? extends Address>> getSupportedAddressClasses()
Returns a set ofDtlsAddressandUdpAddress.- Specified by:
getSupportedAddressClassesin interfaceTransportMapping<UdpAddress>- Returns:
- a set of address classes with at least one element (see
getSupportedAddressClass().
-
getSecurityCallback
public TlsTmSecurityCallback<java.security.cert.X509Certificate> getSecurityCallback()
Description copied from interface:TlsTransportMappingConfigGets theTlsTmSecurityCallbackassociated with thisTransportMappinghook which is called by the transport mapping to lookup TLS security parameters from external configuration.- Specified by:
getSecurityCallbackin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Returns:
- a
TlsTmSecurityCallbackinstance.
-
setSecurityCallback
public void setSecurityCallback(TlsTmSecurityCallback<java.security.cert.X509Certificate> securityCallback)
Description copied from interface:TlsTransportMappingConfigSets theTlsTmSecurityCallbackassociated with thisTransportMappinghook. This hook will be called to lookup the security name based on the TLS peer certificate, for example. SeeTlsTmSecurityCallbackfor details.- Specified by:
setSecurityCallbackin interfaceTlsTransportMappingConfig<java.security.cert.X509Certificate>- Parameters:
securityCallback- aTlsTmSecurityCallbackinstance. Setting this hook tonullwill disable incoming request processing because these request will be rejected due to an authorization error (no mathing SNMPv3 view).
-
getTrustManagerFactory
public TLSTMTrustManagerFactory getTrustManagerFactory()
-
setTrustManagerFactory
public void setTrustManagerFactory(TLSTMTrustManagerFactory trustManagerFactory)
Set the TLSTM trust manager factory. Using a trust manager factory other than the default allows to add support for Java 1.7 X509ExtendedTrustManager.- Parameters:
trustManagerFactory- a X.509 trust manager factory implementing the interfaceTLSTMTrustManagerFactory.- Since:
- 3.0.0
-
getListenAddress
public UdpAddress getListenAddress()
Description copied from interface:TransportMappingReturns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.- Specified by:
getListenAddressin interfaceTransportMapping<UdpAddress>- Overrides:
getListenAddressin classDefaultUdpTransportMapping- Returns:
- the address for incoming packets or
nullthis transport mapping is not configured to listen for incoming packets.
-
close
public boolean close(UdpAddress remoteAddress) throws java.io.IOException
Closes a connection to the supplied remote address, if it is open. This method is particularly useful when not using a timeout for remote connections.- Specified by:
closein interfaceConnectionOrientedTransportMapping<UdpAddress>- Parameters:
remoteAddress- the address of the peer socket.- Returns:
trueif the connection has been closed andfalseif there was nothing to close.- Throws:
java.io.IOException- if the remote address cannot be closed due to an IO exception.
-
getConnectionTimeout
public long getConnectionTimeout()
Gets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
getConnectionTimeoutin interfaceConnectionOrientedTransportMapping<UdpAddress>- Returns:
- long the idle timeout in milliseconds.
-
getMessageLengthDecoder
public MessageLengthDecoder getMessageLengthDecoder()
Returns theMessageLengthDecoderused by this transport mapping.- Specified by:
getMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<UdpAddress>- Returns:
- a MessageLengthDecoder instance.
-
setMessageLengthDecoder
public void setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)
Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.- Specified by:
setMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<UdpAddress>- Parameters:
messageLengthDecoder- a MessageLengthDecoder instance.
-
setConnectionTimeout
public void setConnectionTimeout(long connectionTimeout)
Sets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
setConnectionTimeoutin interfaceConnectionOrientedTransportMapping<UdpAddress>- Parameters:
connectionTimeout- the idle timeout in milliseconds. A zero or negative value will disable any timeout and connections opened by this transport mapping will stay opened until they are explicitly closed.
-
addTransportStateListener
public void addTransportStateListener(TransportStateListener l)
Adds a transport state listener that is to be informed about connection state changes.- Specified by:
addTransportStateListenerin interfaceConnectionOrientedTransportMapping<UdpAddress>- Parameters:
l- a TransportStateListener.
-
removeTransportStateListener
public void removeTransportStateListener(TransportStateListener l)
Removes the supplied transport state listener.- Specified by:
removeTransportStateListenerin interfaceConnectionOrientedTransportMapping<UdpAddress>- Parameters:
l- a TransportStateListener.
-
getSocketCleaner
public CommonTimer getSocketCleaner()
Gets theCommonTimerthat controls socket cleanup operations.- Specified by:
getSocketCleanerin interfaceConnectionOrientedTransportMapping<UdpAddress>- Returns:
- a socket cleaner timer.
- Since:
- 3.0
-
isServerEnabled
public boolean isServerEnabled()
Checks whether a server for incoming requests is enabled.- Returns:
- boolean
-
setServerEnabled
public void setServerEnabled(boolean serverEnabled)
Sets whether a server for incoming requests should be created when the transport is set into listen state. Setting this value has no effect until thelisten()method is called (if the transport is already listening,close()has to be called before).- Parameters:
serverEnabled- iftrueif the transport will listens for incoming requests afterlisten()has been called.
-
getMaxInboundMessageSize
public int getMaxInboundMessageSize()
Gets the inbound buffer size for incoming requests. When SNMP packets are received that are longer than this maximum size, the messages will be silently dropped and the connection will be closed.- Specified by:
getMaxInboundMessageSizein interfaceTransportMapping<UdpAddress>- Overrides:
getMaxInboundMessageSizein classAbstractTransportMapping<UdpAddress>- Returns:
- the maximum inbound buffer size in bytes.
-
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int maxInboundMessageSize)
Sets the maximum buffer size for incoming requests. When SNMP packets are received that are longer than this maximum size, the messages will be silently dropped and the connection will be closed.- Overrides:
setMaxInboundMessageSizein classDefaultUdpTransportMapping- Parameters:
maxInboundMessageSize- the length of the inbound buffer in bytes.
-
getHandshakeTimeout
public int getHandshakeTimeout()
Gets the maximum number of milliseconds to wait for the DTLS handshake operation to succeed.- Returns:
- the handshake timeout millis.
-
setHandshakeTimeout
public void setHandshakeTimeout(int handshakeTimeout)
Sets the maximum number of milliseconds to wait for the DTLS handshake operation to succeed.- Parameters:
handshakeTimeout- the new handshake timeout millis.
-
fireConnectionStateChanged
protected void fireConnectionStateChanged(TransportStateEvent change)
-
prepareOutPackets
protected java.util.List<java.net.DatagramPacket> prepareOutPackets(UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference, java.net.DatagramSocket socket, long timeoutMillis, int maxRetries) throws java.io.IOException
Description copied from class:DefaultUdpTransportMappingPrepare an application message for sending over the network to the specified target address.- Overrides:
prepareOutPacketsin classDefaultUdpTransportMapping- Parameters:
targetAddress- the UDP address the message will be sent to.message- the application message to send.tmStateReference- the transport state reference associated with this message.socket- the socket that will send the message over the network. @return an ByteBuffer that contains the network representation of the message (i.e. encrypted).timeoutMillis- maximum number of milli seconds the connection creation might take (if connection based). Use 0 for responses or transport mappings that do not require connection establishment.maxRetries- maximum retries during connection creation. Use 0 for responses.- Returns:
- a list of prepared
DatagramPacketinstances. By default this is a singleton list. - Throws:
java.io.IOException- if the preparation of the network message fails (e.g. because the encryption handshake fails).
-
onReceiveTimeout
protected java.util.List<java.net.DatagramPacket> onReceiveTimeout(javax.net.ssl.SSLEngine engine, java.net.SocketAddress socketAddr) throws java.io.IOException- Throws:
java.io.IOException
-
isAsyncMsgProcessingSupported
public boolean isAsyncMsgProcessingSupported()
Description copied from class:AbstractTransportMappingReturnstrueif asynchronous (multi-threaded) message processing may be implemented. The default istrue.- Overrides:
isAsyncMsgProcessingSupportedin classAbstractTransportMapping<UdpAddress>- Returns:
- if
falseis returned theMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)method must not return before the message has been entirely processed.
-
setAsyncMsgProcessingSupported
public void setAsyncMsgProcessingSupported(boolean asyncMsgProcessingSupported)
Description copied from class:AbstractTransportMappingSpecifies whether this transport mapping has to support asynchronous messages processing or not.- Overrides:
setAsyncMsgProcessingSupportedin classAbstractTransportMapping<UdpAddress>- Parameters:
asyncMsgProcessingSupported- iffalsetheMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)method must not return before the message has been entirely processed, because the incoming message buffer is not copied before the message is being processed. Iftruethe message buffer is copied for each call, so that the message processing can be implemented asynchronously.
-
fireProcessMessage
protected void fireProcessMessage(java.net.DatagramPacket packet, java.nio.ByteBuffer bis, TransportStateReference stateReference)- Overrides:
fireProcessMessagein classDefaultUdpTransportMapping
-
prepareInPacket
protected java.nio.ByteBuffer prepareInPacket(java.net.DatagramPacket packet, byte[] buf, TransportStateReference tmStateReference) throws java.io.IOExceptionDescription copied from class:DefaultUdpTransportMappingPrepare an network packet for the application.- Overrides:
prepareInPacketin classDefaultUdpTransportMapping- Parameters:
packet- the incoming network datagram packet.buf- the buffer of the packet.tmStateReference- the transport state reference.- Returns:
- a byte buffer with the application data of the packet.
- Throws:
java.io.IOException- if there occurs an IO exception during preparation.
-
produceHandshakePackets
protected java.util.List<java.net.DatagramPacket> produceHandshakePackets(javax.net.ssl.SSLEngine sslEngine, java.net.SocketAddress socketAddress) throws java.io.IOException- Throws:
java.io.IOException
-
createHandshakePacket
protected java.net.DatagramPacket createHandshakePacket(byte[] buf, java.net.SocketAddress socketAddr)
-
getSslEngineConfigurator
public SSLEngineConfigurator getSslEngineConfigurator()
-
setSslEngineConfigurator
public void setSslEngineConfigurator(SSLEngineConfigurator sslEngineConfigurator)
-
ensureSslEngineConfigurator
protected SSLEngineConfigurator ensureSslEngineConfigurator()
Returns the configuredsetSslEngineConfigurator(SSLEngineConfigurator)or theDefaultSSLEngineConfigurationwhich will then become the configured SSL engine configurator. This method is not synchronized against concurrent execution ofsetSslEngineConfigurator(SSLEngineConfigurator).- Returns:
- a non-null
SSLEngineConfigurator. - Since:
- 3.0.5
-
-