org.eclipse.californium.core.coap.CoAP Java Examples

The following examples show how to use org.eclipse.californium.core.coap.CoAP. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoapTransportResource.java    From Groza with Apache License 2.0 6 votes vote down vote up
@Override
public void handleGET(CoapExchange exchange) {
    if (quotaService.isQuotaExceeded(exchange.getSourceAddress().getHostAddress())){
        log.warn("COAP Quota exceeded for [{}:{}] . Disconnect", exchange.getSourceAddress().getHostAddress(), exchange.getSourcePort());
        exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
        return;
    }
    Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
    if (!featureType.isPresent()) {
        log.trace("Missing feature type parameter");
        exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
    } else if (featureType.get() == FeatureType.TELEMETRY) {
        log.trace("Can't fetch/subscribe to timeseries updates");
        exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
    } else if (exchange.getRequestOptions().hasObserve()) {
        processExchangeGetRequest(exchange, featureType.get());
    } else if (featureType.get() == FeatureType.ATTRIBUTES) {
        processRequest(exchange, SessionMsgType.GET_ATTRIBUTES_REQUEST);
    } else {
        log.trace("Invalid feature type parameter");
        exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
    }
}
 
Example #2
Source File: CoapClient.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns the effective endpoint that the specified request is supposed to
 * be sent over. If an endpoint has explicitly been set to this CoapClient,
 * this endpoint will be used. If no endpoint has been set, the client will
 * effectively use a default endpoint of the {@link EndpointManager}.
 * 
 * @param request the request to be sent
 * @return the effective endpoint that the request is going o be sent over.
 */
protected Endpoint getEffectiveEndpoint(Request request) {
	Endpoint myEndpoint = getEndpoint();
	
	// custom endpoint
	if (myEndpoint != null) return myEndpoint;
	
	// default endpoints
	if (CoAP.COAP_SECURE_URI_SCHEME.equals(request.getScheme())) {
		// this is the case when secure coap is supposed to be used
		return EndpointManager.getEndpointManager().getDefaultSecureEndpoint();
	} else {
		// this is the normal case
		return EndpointManager.getEndpointManager().getDefaultEndpoint();
	}
}
 
Example #3
Source File: CoapResource.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method is used to apply resource-specific knowledge on the exchange.
 * If the request was successful, it sets the Observe option for the
 * response. It is important to use the notificationOrderer of the resource
 * here. Further down the layer, race conditions could cause local
 * reordering of notifications. If the response has an error code, no
 * observe relation can be established and if there was one previously it is
 * canceled. When this resource allows to be observed by clients and the
 * request is a GET request with an observe option, the
 * {@link ServerMessageDeliverer} already created the relation, as it
 * manages the observing endpoints globally.
 * 
 * @param exchange the exchange
 * @param response the response
 */
public void checkObserveRelation(Exchange exchange, Response response) {
	/*
	 * If the request for the specified exchange tries to establish an observer
	 * relation, then the ServerMessageDeliverer must have created such a relation
	 * and added to the exchange. Otherwise, there is no such relation.
	 * Remember that different paths might lead to this resource.
	 */
	
	ObserveRelation relation = exchange.getRelation();
	if (relation == null) return; // because request did not try to establish a relation
	
	if (CoAP.ResponseCode.isSuccess(response.getCode())) {
		response.getOptions().setObserve(notificationOrderer.getCurrent());
		
		if (!relation.isEstablished()) {
			relation.setEstablished(true);
			addObserveRelation(relation);
		} else if (observeType != null) {
			// The resource can control the message type of the notification
			response.setType(observeType);
		}
	} // ObserveLayer takes care of the else case
}
 
Example #4
Source File: TestCoapClientTarget.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  int port =  TestHttpClientTarget.getFreePort();
  coapServer = new CoapServer(NetworkConfig.createStandardWithoutFile(), port);
  coapServer.add(new CoapResource("test") {
    @Override
    public void handlePOST(CoapExchange exchange) {
      serverRequested = true;
      if (returnErrorResponse) {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        return;
      }
      requestPayload = new String(exchange.getRequestPayload());
      exchange.respond(CoAP.ResponseCode.VALID);
    }
  });
  resourceURl = "coap://localhost:" + port + "/test";
  coapServer.start();
}
 
Example #5
Source File: CoapReceiverResource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
public void handle(CoapExchange exchange) {
  if (shuttingDown) {
    LOG.debug("Shutting down, discarding incoming request from '{}'", exchange.getSourceAddress());
    exchange.respond(CoAP.ResponseCode.SERVICE_UNAVAILABLE);
  } else {
    long start = System.currentTimeMillis();
    LOG.debug("Request accepted from '{}'", exchange.getSourceAddress());
    try {
      if (receiver.process(exchange.getRequestPayload())) {
        exchange.respond(CoAP.ResponseCode.VALID);
        exchange.accept();
        requestMeter.mark();
      } else {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        exchange.accept();
        errorRequestMeter.mark();
      }
    } catch (IOException ex) {
      exchange.reject();
      errorQueue.offer(ex);
      errorRequestMeter.mark();
    } finally {
      requestTimer.update(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS);
    }
  }
}
 
Example #6
Source File: CoapClient.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns the effective endpoint that the specified request is supposed to
 * be sent over. If an endpoint has explicitly been set to this CoapClient,
 * this endpoint will be used. If no endpoint has been set, the client will
 * effectively use a default endpoint of the {@link EndpointManager}.
 * 
 * @param request the request to be sent
 * @return the effective endpoint that the request is going o be sent over.
 */
protected Endpoint getEffectiveEndpoint(Request request) {
	Endpoint myEndpoint = getEndpoint();
	
	// custom endpoint
	if (myEndpoint != null) return myEndpoint;
	
	// default endpoints
	if (CoAP.COAP_SECURE_URI_SCHEME.equals(request.getScheme())) {
		// this is the case when secure coap is supposed to be used
		return EndpointManager.getEndpointManager().getDefaultSecureEndpoint();
	} else {
		// this is the normal case
		return EndpointManager.getEndpointManager().getDefaultEndpoint();
	}
}
 
Example #7
Source File: CoapResource.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method is used to apply resource-specific knowledge on the exchange.
 * If the request was successful, it sets the Observe option for the
 * response. It is important to use the notificationOrderer of the resource
 * here. Further down the layer, race conditions could cause local
 * reordering of notifications. If the response has an error code, no
 * observe relation can be established and if there was one previously it is
 * canceled. When this resource allows to be observed by clients and the
 * request is a GET request with an observe option, the
 * {@link ServerMessageDeliverer} already created the relation, as it
 * manages the observing endpoints globally.
 * 
 * @param exchange the exchange
 * @param response the response
 */
public void checkObserveRelation(Exchange exchange, Response response) {
	/*
	 * If the request for the specified exchange tries to establish an observer
	 * relation, then the ServerMessageDeliverer must have created such a relation
	 * and added to the exchange. Otherwise, there is no such relation.
	 * Remember that different paths might lead to this resource.
	 */
	
	ObserveRelation relation = exchange.getRelation();
	if (relation == null) return; // because request did not try to establish a relation
	
	if (CoAP.ResponseCode.isSuccess(response.getCode())) {
		response.getOptions().setObserve(notificationOrderer.getCurrent());
		
		if (!relation.isEstablished()) {
			relation.setEstablished(true);
			addObserveRelation(relation);
		} else if (observeType != null) {
			// The resource can control the message type of the notification
			response.setType(observeType);
		}
	} // ObserveLayer takes care of the else case
}
 
Example #8
Source File: CoapTransportResource.java    From Groza with Apache License 2.0 6 votes vote down vote up
@Override
public void handlePOST(CoapExchange exchange) {
    Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
    if (!featureType.isPresent()) {
        log.trace("Missing feature type parameter");
        exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
    } else {
        switch (featureType.get()) {
            case ATTRIBUTES:
                processRequest(exchange, SessionMsgType.POST_ATTRIBUTES_REQUEST);
                break;
            case TELEMETRY:
                processRequest(exchange, SessionMsgType.POST_TELEMETRY_REQUEST);
                break;
            case RPC:
                Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest());
                if (requestId.isPresent()) {
                    processRequest(exchange, SessionMsgType.TO_DEVICE_RPC_RESPONSE);
                } else {
                    processRequest(exchange, SessionMsgType.TO_SERVER_RPC_REQUEST);
                }
                break;
        }
    }
}
 
Example #9
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 6 votes vote down vote up
private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) {
    CoAP.ResponseCode status = CoAP.ResponseCode.INTERNAL_SERVER_ERROR;
    switch (msg.getError()) {
        case QUEUE_PUT_TIMEOUT:
            status = CoAP.ResponseCode.GATEWAY_TIMEOUT;
            break;
        default:
            if (msg.getInSessionMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) {
                status = CoAP.ResponseCode.BAD_REQUEST;
            }
            break;
    }
    Response response = new Response(status);
    response.setPayload(JsonConverter.toErrorJson(msg.getErrorMsg()).toString());
    return response;
}
 
Example #10
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 5 votes vote down vote up
private Response convertGetAttributesResponse(GetAttributesResponse msg) {
    if (msg.isSuccess()) {
        Optional<AttributesKVMsg> payload = msg.getData();
        if (!payload.isPresent() || (payload.get().getClientAttributes().isEmpty() && payload.get().getSharedAttributes().isEmpty())) {
            return new Response(CoAP.ResponseCode.NOT_FOUND);
        } else {
            Response response = new Response(CoAP.ResponseCode.CONTENT);
            JsonObject result = JsonConverter.toJson(payload.get(), false);
            response.setPayload(result.toString());
            return response;
        }
    } else {
        return convertError(msg.getError());
    }
}
 
Example #11
Source File: CoapSessionCtx.java    From Groza with Apache License 2.0 5 votes vote down vote up
private void onSessionClose(SessionCloseMsg msg) {
    if (msg.isTimeout()) {
        exchange.respond(CoAP.ResponseCode.SERVICE_UNAVAILABLE);
    } else if (msg.isCredentialsRevoked()) {
        exchange.respond(CoAP.ResponseCode.UNAUTHORIZED);
    } else {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
    }
}
 
Example #12
Source File: CoapTransportResource.java    From Groza with Apache License 2.0 5 votes vote down vote up
private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) {
    boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
    SessionMsgType sessionMsgType;
    if (featureType == FeatureType.RPC) {
        sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
    } else {
        sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
    }
    Optional<SessionId> sessionId = processRequest(exchange, sessionMsgType);
    if (sessionId.isPresent()) {
        if (exchange.getRequestOptions().getObserve() == 1) {
            exchange.respond(CoAP.ResponseCode.VALID);
        }
    }
}
 
Example #13
Source File: TestCoapServerPushSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void testSource() throws Exception {
  CoapServerConfigs coapServerConfigs = new CoapServerConfigs();
  coapServerConfigs.resourceName = () -> "sdc";
  coapServerConfigs.port = NetworkUtils.getRandomPort();
  coapServerConfigs.maxConcurrentRequests = 1;
  CoapServerPushSource source =
      new CoapServerPushSource(coapServerConfigs, DataFormat.TEXT, new DataParserFormatConfig());
  final PushSourceRunner runner =
      new PushSourceRunner.Builder(CoapServerDPushSource.class, source).addOutputLane("a").build();
  runner.runInit();
  try {
    final List<Record> records = new ArrayList<>();
    runner.runProduce(Collections.<String, String>emptyMap(), 1, new PushSourceRunner.Callback() {
      @Override
      public void processBatch(StageRunner.Output output) {
        records.clear();
        records.addAll(output.getRecords().get("a"));
        runner.setStop();
      }
    });

    URI coapURI = new URI("coap://localhost:" + coapServerConfigs.port + "/" + coapServerConfigs.resourceName.get());
    CoapClient client = new CoapClient(coapURI);
    CoapResponse response = client.post("Hello", MediaTypeRegistry.TEXT_PLAIN);
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getCode(), CoAP.ResponseCode.VALID);

    runner.waitOnProduce();
    Assert.assertEquals(1, records.size());
    Assert.assertEquals("Hello", records.get(0).get("/text").getValue());

  } finally {
    runner.runDestroy();
  }
}
 
Example #14
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 5 votes vote down vote up
private Response convertStatusCodeResponse(StatusCodeResponse msg) {
    if (msg.isSuccess()) {
        Optional<Integer> code = msg.getData();
        if (code.isPresent() && code.get() == 200) {
            return new Response(CoAP.ResponseCode.VALID);
        } else {
            return new Response(CoAP.ResponseCode.CREATED);
        }
    } else {
        return convertError(msg.getError());
    }
}
 
Example #15
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 5 votes vote down vote up
private Response convertError(Optional<Exception> exception) {
    if (exception.isPresent()) {
        log.warn("Converting exception: {}", exception.get().getMessage(), exception.get());
        if (exception.get() instanceof ProcessingTimeoutException) {
            return new Response(CoAP.ResponseCode.SERVICE_UNAVAILABLE);
        } else {
            return new Response(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        }
    } else {
        return new Response(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
    }
}
 
Example #16
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 5 votes vote down vote up
private Response convertToServerRpcResponse(SessionContext ctx, ToServerRpcResponseMsg msg) {
    if (msg.isSuccess()) {
        Response response = new Response(CoAP.ResponseCode.CONTENT);
        JsonElement result = JsonConverter.toJson(msg);
        response.setPayload(result.toString());
        return response;
    } else {
        return convertError(Optional.of(new RuntimeException("Server RPC response is empty!")));
    }
}
 
Example #17
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean isReply() {
	return type > CoAP.Type.NON.value;
}
 
Example #18
Source File: NetworkConfigDefaults.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void setDefaults(NetworkConfig config) {

		final int CORES = Runtime.getRuntime().availableProcessors();
		final String OS = System.getProperty("os.name");
		final boolean WINDOWS = OS.startsWith("Windows");
		
		config.setInt(NetworkConfig.Keys.COAP_PORT, CoAP.DEFAULT_COAP_PORT);
		config.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, CoAP.DEFAULT_COAP_SECURE_PORT);
		
		config.setInt(NetworkConfig.Keys.ACK_TIMEOUT, 2000);
		config.setFloat(NetworkConfig.Keys.ACK_RANDOM_FACTOR, 1.5f);
		config.setFloat(NetworkConfig.Keys.ACK_TIMEOUT_SCALE, 2f);
		config.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4);
		config.setLong(NetworkConfig.Keys.EXCHANGE_LIFETIME, 247 * 1000); // ms
		config.setLong(NetworkConfig.Keys.NON_LIFETIME, 145 * 1000); // ms
		config.setLong(NetworkConfig.Keys.MAX_TRANSMIT_WAIT, 93 * 1000);
		config.setInt(NetworkConfig.Keys.NSTART, 1);
		config.setInt(NetworkConfig.Keys.LEISURE, 5000);
		config.setFloat(NetworkConfig.Keys.PROBING_RATE, 1f);

		config.setBoolean(NetworkConfig.Keys.USE_RANDOM_MID_START, true);
		config.setInt(NetworkConfig.Keys.TOKEN_SIZE_LIMIT, 8);

		config.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 512);
		config.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);
		config.setInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, 10 * 60 * 1000); // ms

		config.setLong(NetworkConfig.Keys.NOTIFICATION_CHECK_INTERVAL_TIME, 24 * 60 * 60 * 1000); // ms
		config.setInt(NetworkConfig.Keys.NOTIFICATION_CHECK_INTERVAL_COUNT, 100);
		config.setLong(NetworkConfig.Keys.NOTIFICATION_REREGISTRATION_BACKOFF, 2000); // ms
		
		config.setBoolean(NetworkConfig.Keys.USE_CONGESTION_CONTROL, false);
		config.setString(NetworkConfig.Keys.CONGESTION_CONTROL_ALGORITHM, "Cocoa"); // see org.eclipse.californium.core.network.stack.congestioncontrol
		
		config.setInt(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, CORES);
		config.setInt(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, WINDOWS ? CORES : 1);
		config.setInt(NetworkConfig.Keys.NETWORK_STAGE_SENDER_THREAD_COUNT, WINDOWS ? CORES : 1);
		
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_DATAGRAM_SIZE, 2048);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_RECEIVE_BUFFER, UDPConnector.UNDEFINED);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_SEND_BUFFER, UDPConnector.UNDEFINED);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_OUT_CAPACITY, Integer.MAX_VALUE); // unbounded

		config.setString(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.DEDUPLICATOR_MARK_AND_SWEEP);
		config.setLong(NetworkConfig.Keys.MARK_AND_SWEEP_INTERVAL, 10 * 1000);
		config.setInt(NetworkConfig.Keys.CROP_ROTATION_PERIOD, 2000);

		config.setInt(NetworkConfig.Keys.HTTP_PORT, 8080);
		config.setInt(NetworkConfig.Keys.HTTP_SERVER_SOCKET_TIMEOUT, 100000);
		config.setInt(NetworkConfig.Keys.HTTP_SERVER_SOCKET_BUFFER_SIZE, 8192);
		config.setInt(NetworkConfig.Keys.HTTP_CACHE_RESPONSE_MAX_AGE, 86400);
		config.setInt(NetworkConfig.Keys.HTTP_CACHE_SIZE, 32);
		
		config.setString(NetworkConfig.Keys.HEALTH_STATUS_PRINT_LEVEL, "FINEST");
		config.setInt(NetworkConfig.Keys.HEALTH_STATUS_INTERVAL, 60); // s
	}
 
Example #19
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean isWellFormed() {
	return version == CoAP.VERSION;
}
 
Example #20
Source File: JsonCoapAdaptor.java    From Groza with Apache License 2.0 4 votes vote down vote up
private Response getObserveNotification(CoapSessionCtx ctx, JsonObject json) {
    Response response = new Response(CoAP.ResponseCode.CONTENT);
    response.getOptions().setObserve(ctx.nextSeqNumber());
    response.setPayload(json.toString());
    return response;
}
 
Example #21
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public String toString() {
	return "[Ver="+version+"|T="+CoAP.Type.valueOf(type)+"|TKL="+tokenlength+"|Code="+code+"|MID="+mid+"]";
}
 
Example #22
Source File: AbstractVertxBasedCoapAdapter.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return {@link CoAP#DEFAULT_COAP_PORT}
 */
@Override
public final int getInsecurePortDefaultValue() {
    return CoAP.DEFAULT_COAP_PORT;
}
 
Example #23
Source File: AbstractVertxBasedCoapAdapter.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return {@link CoAP#DEFAULT_COAP_SECURE_PORT}
 */
@Override
public final int getPortDefaultValue() {
    return CoAP.DEFAULT_COAP_SECURE_PORT;
}
 
Example #24
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public String toString() {
	return "[Ver="+version+"|T="+CoAP.Type.valueOf(type)+"|TKL="+tokenlength+"|Code="+code+"|MID="+mid+"]";
}
 
Example #25
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean isWellFormed() {
	return version == CoAP.VERSION;
}
 
Example #26
Source File: DataParser.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean isReply() {
	return type > CoAP.Type.NON.value;
}
 
Example #27
Source File: NetworkConfigDefaults.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void setDefaults(NetworkConfig config) {

		final int CORES = Runtime.getRuntime().availableProcessors();
		final String OS = System.getProperty("os.name");
		final boolean WINDOWS = OS.startsWith("Windows");
		
		config.setInt(NetworkConfig.Keys.COAP_PORT, CoAP.DEFAULT_COAP_PORT);
		config.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, CoAP.DEFAULT_COAP_SECURE_PORT);
		
		config.setInt(NetworkConfig.Keys.ACK_TIMEOUT, 2000);
		config.setFloat(NetworkConfig.Keys.ACK_RANDOM_FACTOR, 1.5f);
		config.setFloat(NetworkConfig.Keys.ACK_TIMEOUT_SCALE, 2f);
		config.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4);
		config.setLong(NetworkConfig.Keys.EXCHANGE_LIFETIME, 247 * 1000); // ms
		config.setLong(NetworkConfig.Keys.NON_LIFETIME, 145 * 1000); // ms
		config.setLong(NetworkConfig.Keys.MAX_TRANSMIT_WAIT, 93 * 1000);
		config.setInt(NetworkConfig.Keys.NSTART, 1);
		config.setInt(NetworkConfig.Keys.LEISURE, 5000);
		config.setFloat(NetworkConfig.Keys.PROBING_RATE, 1f);

		config.setBoolean(NetworkConfig.Keys.USE_RANDOM_MID_START, true);
		config.setInt(NetworkConfig.Keys.TOKEN_SIZE_LIMIT, 8);

		config.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 512);
		config.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);
		config.setInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, 10 * 60 * 1000); // ms

		config.setLong(NetworkConfig.Keys.NOTIFICATION_CHECK_INTERVAL_TIME, 24 * 60 * 60 * 1000); // ms
		config.setInt(NetworkConfig.Keys.NOTIFICATION_CHECK_INTERVAL_COUNT, 100);
		config.setLong(NetworkConfig.Keys.NOTIFICATION_REREGISTRATION_BACKOFF, 2000); // ms
		
		config.setBoolean(NetworkConfig.Keys.USE_CONGESTION_CONTROL, false);
		config.setString(NetworkConfig.Keys.CONGESTION_CONTROL_ALGORITHM, "Cocoa"); // see org.eclipse.californium.core.network.stack.congestioncontrol
		
		config.setInt(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, CORES);
		config.setInt(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, WINDOWS ? CORES : 1);
		config.setInt(NetworkConfig.Keys.NETWORK_STAGE_SENDER_THREAD_COUNT, WINDOWS ? CORES : 1);
		
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_DATAGRAM_SIZE, 2048);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_RECEIVE_BUFFER, UDPConnector.UNDEFINED);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_SEND_BUFFER, UDPConnector.UNDEFINED);
		config.setInt(NetworkConfig.Keys.UDP_CONNECTOR_OUT_CAPACITY, Integer.MAX_VALUE); // unbounded

		config.setString(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.DEDUPLICATOR_MARK_AND_SWEEP);
		config.setLong(NetworkConfig.Keys.MARK_AND_SWEEP_INTERVAL, 10 * 1000);
		config.setInt(NetworkConfig.Keys.CROP_ROTATION_PERIOD, 2000);

		config.setInt(NetworkConfig.Keys.HTTP_PORT, 8080);
		config.setInt(NetworkConfig.Keys.HTTP_SERVER_SOCKET_TIMEOUT, 100000);
		config.setInt(NetworkConfig.Keys.HTTP_SERVER_SOCKET_BUFFER_SIZE, 8192);
		config.setInt(NetworkConfig.Keys.HTTP_CACHE_RESPONSE_MAX_AGE, 86400);
		config.setInt(NetworkConfig.Keys.HTTP_CACHE_SIZE, 32);
		
		config.setString(NetworkConfig.Keys.HEALTH_STATUS_PRINT_LEVEL, "FINEST");
		config.setInt(NetworkConfig.Keys.HEALTH_STATUS_INTERVAL, 60); // s
	}
 
Example #28
Source File: CoapResponse.java    From SI with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Checks if the response code is a successful code.
 *
 * @return true, if is success
 */
public boolean isSuccess() {
	return CoAP.ResponseCode.isSuccess(response.getCode());
}
 
Example #29
Source File: CoapResponse.java    From SI with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Checks if the response code is a successful code.
 *
 * @return true, if is success
 */
public boolean isSuccess() {
	return CoAP.ResponseCode.isSuccess(response.getCode());
}