Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINIFICPP-558: initial provisioning for CoAP #437

Closed
wants to merge 2 commits into from

Conversation

phrocker
Copy link
Contributor

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.

@phrocker
Copy link
Contributor Author

Adding tests presently, but providing a wip view.


set(BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/extensions/coap")
if (APPLE)
set(BYPRODUCT "${BASE_DIR}/extensions/coap/thirdparty/libcoap-src/.libs/libcoap-2-gnutls.a")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may need a little modification as artifacts can vary depending on what is used for building TLS

@@ -42,6 +42,8 @@ def __init__(self, output_validator):

self.segfault = False

self.segfault = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already there two lines above.

// initialization mutex.
std::mutex initialization_mutex_;

std::atomic<bool> initialized_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we plan to have multiple instances of COAPConnectorSerivce?


void no_acknowledgement(struct coap_context_t *ctx, coap_session_t *session, coap_pdu_t *sent, coap_nack_reason_t reason, const coap_tid_t id){
if (global_ptrs.received_error){
global_ptrs.received_error(receiver, ctx, -1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

}

int coap_event(struct coap_context_t *ctx, coap_event_t event, struct coap_session_t *session){
if (event == COAP_EVENT_SESSION_FAILED && global_ptrs.received_error){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent with 2 spaces

size_t data_len;
coap_opt_iterator_t opt_iter;
coap_opt_t * block_opt = coap_check_option(received, COAP_OPTION_BLOCK1, &opt_iter);
if (block_opt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

if(!block_opt)

?

return -1;
}

int8_t CoapProtocol::getString(const C2ContentResponse * const cmp, const std::string &name, std::string *value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's C++, why value is a pointer (ref would be fine)?
Moreover I don't see why to have 0 or -1 return codes, empty string would be fine as well to indicate the lack of existence.

}

const C2Payload * const CoapProtocol::getPayload(const std::string &name, const C2Payload &payload) {
if (payload.getLabel() == name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return getPayLoad(&payload);

As the pointer version exists, why to duplicate?


coap_str_const_t pld;
pld.length = size;
pld.s = payload;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given .s is const uint8_t* ( https://github.com/obgm/libcoap/blob/develop/include/coap2/str.h ), could you change the signature of the function to handle the payload as const?

Copy link
Contributor Author

@phrocker phrocker Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look what it is now, but we'll probably keep with that the outer facing types are and translate as needed/ I don't know if we can move to const as we'll probably be taking ownership of that buffer in the next commit. that is what the initial version did per libcoap did ( not sure if they do that in coap 2 ) . It ultimately depends on what we end up with ( coap vs coap2 ), but appreciate the request!


coap_address_t dst_addr, src_addr;
coap_uri_t uri;
uri.host.s = reinterpret_cast<unsigned char *>(const_cast<char*>(host_.c_str()));
Copy link
Contributor

@arpadboda arpadboda Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uri.host is coap_str_const_t, which has "s" as const uint8_t*, so there is no need of const cast here, just reinterpret cast to "const uint8_t*".

Copy link
Contributor Author

@phrocker phrocker Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for the diligence. This was changed last minute ( from coap to coap2 ) and I may return back to coap1 ( in libcoap) where the signature is unsigned char. I posted this early for someone to take a gander from an integration perspective, so this is a WIP.

@phrocker phrocker force-pushed the MINIFICPP-558 branch 2 times, most recently from ff26f81 to 4a667b7 Compare November 20, 2018 03:31
test framework still under dev

MINIFICPP-683: Remove extraneous std::move
@phrocker phrocker force-pushed the MINIFICPP-558 branch 2 times, most recently from 3d07f09 to 77d6c08 Compare November 21, 2018 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants