use of org.eclipse.californium.core.config.CoapConfig.MatcherMode 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();
}
}
}
Aggregations