Package ch.ethz.inf.vs.californium.coap

Examples of ch.ethz.inf.vs.californium.coap.EmptyMessage


          request = parser.parseRequest();
        } catch (IllegalStateException e) {
          String log = "message format error caused by " + raw.getInetSocketAddress();
          if (!parser.isReply()) {
            // manually build RST from raw information
            EmptyMessage rst = new EmptyMessage(Type.RST);
            rst.setDestination(raw.getAddress());
            rst.setDestinationPort(raw.getPort());
            rst.setMID(parser.getMID());
            for (MessageInterceptor interceptor:interceptors)
              interceptor.sendEmptyMessage(rst);
            connector.send(serializer.serialize(rst));
            log += " and reseted";
          }
          LOGGER.info(log);
          return;
        }
        request.setSource(raw.getAddress());
        request.setSourcePort(raw.getPort());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */
       
        for (MessageInterceptor interceptor:interceptors)
          interceptor.receiveRequest(request);

        // MessageInterceptor might have canceled
        if (!request.isCanceled()) {
          Exchange exchange = matcher.receiveRequest(request);
          if (exchange != null) {
            exchange.setEndpoint(CoAPEndpoint.this);
            coapstack.receiveRequest(exchange, request);
          }
        }
       
      } else if (parser.isResponse()) {
        // This is a response
        Response response = parser.parseResponse();
        response.setSource(raw.getAddress());
        response.setSourcePort(raw.getPort());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */
       
        for (MessageInterceptor interceptor:interceptors)
          interceptor.receiveResponse(response);

        // MessageInterceptor might have canceled
        if (!response.isCanceled()) {
          Exchange exchange = matcher.receiveResponse(response);
          if (exchange != null) {
            exchange.setEndpoint(CoAPEndpoint.this);
            response.setRTT(System.currentTimeMillis() - exchange.getTimestamp());
            coapstack.receiveResponse(exchange, response);
          }
        }
       
      } else if (parser.isEmpty()) {
        // This is an empty message
        EmptyMessage message = parser.parseEmptyMessage();
        message.setSource(raw.getAddress());
        message.setSourcePort(raw.getPort());
       
        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */
       
        for (MessageInterceptor interceptor:interceptors)
          interceptor.receiveEmptyMessage(message);

        // MessageInterceptor might have canceled
        if (!message.isCanceled()) {
          // CoAP Ping
          if (message.getType() == Type.CON || message.getType() == Type.NON) {
            EmptyMessage rst = EmptyMessage.newRST(message);
           
            LOGGER.info("Responding to ping by " + raw.getInetSocketAddress());
           
            for (MessageInterceptor interceptor:interceptors)
              interceptor.sendEmptyMessage(rst);
View Full Code Here


    return response;
  }
 
  public EmptyMessage parseEmptyMessage() {
    assert(!isRequest() && !isResponse());
    EmptyMessage message = new EmptyMessage(Type.valueOf(type));
    parseMessage(message);
    return message;
  }
View Full Code Here

        // Do not restart retransmission cycle
        super.sendResponse(exchange, exchange.getCurrentResponse());
       
      } else if (exchange.getCurrentRequest().isAcknowledged()) {
        LOGGER.fine("The duplicate request was acknowledged but no response computed yet. Retransmit ACK");
        EmptyMessage ack = EmptyMessage.newACK(request);
        sendEmptyMessage(exchange, ack);
     
      } else if (exchange.getCurrentRequest().isRejected()) {
        LOGGER.fine("The duplicate request was rejected. Reject again");
        EmptyMessage rst = EmptyMessage.newRST(request);
        sendEmptyMessage(exchange, rst);

      } else {
        LOGGER.fine("The server has not yet decided what to do with the request. We ignore the duplicate.");
        // The server has not yet decided, whether to acknowledge or
View Full Code Here

    LOGGER.finest("Cancel any retransmission");
    exchange.setRetransmissionHandle(null);
   
    if (response.getType() == Type.CON && !exchange.getRequest().isCanceled()) {
      LOGGER.finer("Response is confirmable, send ACK");
      EmptyMessage ack = EmptyMessage.newACK(response);
      sendEmptyMessage(exchange, ack);
    }
   
    if (response.isDuplicate()) {
      LOGGER.fine("Response is duplicate, ignore it");
View Full Code Here

  public void receiveResponse(Exchange exchange, Response response) {
    if (response.getOptions().hasObserve()) {
      if (exchange.getRequest().isCanceled()) {
        // The request was canceled and we no longer want notifications
        LOGGER.finer("ObserveLayer rejecting notification for canceled Exchange");
        EmptyMessage rst = EmptyMessage.newRST(response);
        sendEmptyMessage(exchange, rst);
      } else {
        prepareReregistration(exchange, response, new ReregistrationTask(exchange));
        super.receiveResponse(exchange, response);
      }
View Full Code Here

   */
  public void sendAccept() {
    assert(origin == Origin.REMOTE);
    if (request.getType() == Type.CON && !request.isAcknowledged()) {
      request.setAcknowledged(true);
      EmptyMessage ack = EmptyMessage.newACK(request);
      endpoint.sendEmptyMessage(this, ack);
    }
  }
View Full Code Here

   * client.
   */
  public void sendReject() {
    assert(origin == Origin.REMOTE);
    request.setRejected(true);
    EmptyMessage rst = EmptyMessage.newRST(request);
    endpoint.sendEmptyMessage(this, rst);
  }
View Full Code Here

    } else {
      // There is no exchange with the given token.
      if (response.getType() != Type.ACK) {
        LOGGER.info("Response with unknown Token "+idByTok+": Rejecting "+response);
        // This is a totally unexpected response.
        EmptyMessage rst = EmptyMessage.newRST(response);
        sendEmptyMessage(exchange, rst);
      }
      // ignore response
      return null;
    }
View Full Code Here

        // ERROR, wrong block number (server error)
        // TODO: This scenario is not specified in the draft.
        // Currently, we reject it and cancel the request.
        LOGGER.warning("Wrong block number. Expected "+status.getCurrentNum()+" but received "+block2.getNum()+". Reject response; exchange has failed.");
        if (response.getType()==Type.CON) {
          EmptyMessage rst = EmptyMessage.newRST(response);
          super.sendEmptyMessage(exchange, rst);
        }
        exchange.getRequest().cancel();
      }
    }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.coap.EmptyMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.