Search in sources :

Example 1 with RelaxedDtlsEndpointContextMatcher

use of org.eclipse.californium.elements.RelaxedDtlsEndpointContextMatcher in project californium by eclipse.

the class EndpointContextMatcherFactory method create.

/**
 * Create endpoint context matcher related to connector according the
 * configuration.
 *
 * If connector supports "coaps:", RESPONSE_MATCHING is used to determine,
 * if {@link StrictDtlsEndpointContextMatcher},
 * {@link RelaxedDtlsEndpointContextMatcher}, or
 * {@link PrincipalEndpointContextMatcher} is used.
 *
 * If connector supports "coap:", RESPONSE_MATCHING is used to determine, if
 * {@link UdpEndpointContextMatcher} is used with disabled
 * ({@link MatcherMode#RELAXED}) or enabled address check (otherwise).
 *
 * For other protocol flavors the corresponding matcher is used.
 *
 * @param connector connector to create related endpoint context matcher.
 * @param config configuration.
 * @return endpoint context matcher
 * @since 3.0 (changed parameter to Configuration)
 */
public static EndpointContextMatcher create(Connector connector, Configuration config) {
    String protocol = null;
    if (null != connector) {
        protocol = connector.getProtocol();
        if (CoAP.PROTOCOL_TCP.equalsIgnoreCase(protocol)) {
            return new TcpEndpointContextMatcher();
        } else if (CoAP.PROTOCOL_TLS.equalsIgnoreCase(protocol)) {
            return new TlsEndpointContextMatcher();
        }
    }
    MatcherMode mode = config.get(CoapConfig.RESPONSE_MATCHING);
    switch(mode) {
        case RELAXED:
            if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
                return new UdpEndpointContextMatcher(false);
            } else {
                return new RelaxedDtlsEndpointContextMatcher();
            }
        case PRINCIPAL:
            if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
                return new UdpEndpointContextMatcher(true);
            } else {
                return new PrincipalEndpointContextMatcher();
            }
        case PRINCIPAL_IDENTITY:
            if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
                return new UdpEndpointContextMatcher(true);
            } else {
                return new PrincipalEndpointContextMatcher(true);
            }
        case STRICT:
        default:
            if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
                return new UdpEndpointContextMatcher(true);
            } else {
                return new StrictDtlsEndpointContextMatcher();
            }
    }
}
Also used : PrincipalEndpointContextMatcher(org.eclipse.californium.elements.PrincipalEndpointContextMatcher) TlsEndpointContextMatcher(org.eclipse.californium.elements.TlsEndpointContextMatcher) MatcherMode(org.eclipse.californium.core.config.CoapConfig.MatcherMode) TcpEndpointContextMatcher(org.eclipse.californium.elements.TcpEndpointContextMatcher) RelaxedDtlsEndpointContextMatcher(org.eclipse.californium.elements.RelaxedDtlsEndpointContextMatcher) StrictDtlsEndpointContextMatcher(org.eclipse.californium.elements.StrictDtlsEndpointContextMatcher) UdpEndpointContextMatcher(org.eclipse.californium.elements.UdpEndpointContextMatcher)

Aggregations

MatcherMode (org.eclipse.californium.core.config.CoapConfig.MatcherMode)1 PrincipalEndpointContextMatcher (org.eclipse.californium.elements.PrincipalEndpointContextMatcher)1 RelaxedDtlsEndpointContextMatcher (org.eclipse.californium.elements.RelaxedDtlsEndpointContextMatcher)1 StrictDtlsEndpointContextMatcher (org.eclipse.californium.elements.StrictDtlsEndpointContextMatcher)1 TcpEndpointContextMatcher (org.eclipse.californium.elements.TcpEndpointContextMatcher)1 TlsEndpointContextMatcher (org.eclipse.californium.elements.TlsEndpointContextMatcher)1 UdpEndpointContextMatcher (org.eclipse.californium.elements.UdpEndpointContextMatcher)1