cn-uofbasel / ccn-lite

CCN-lite, a lightweight implementation of the CCNx protocol and its variations
ISC License
74 stars 63 forks source link

ccnl_i_prefixof_c: fix and use CMP_EXACT #367

Closed PeterKietzmann closed 4 years ago

PeterKietzmann commented 4 years ago

Contribution description

cmp > 0 && (uint32_t) cmp == prefix->compcnt; seems like the aim to do an exact match. This PR changes to simply use CMP_EXACT.

ccnl_i_prefixof_c can return different negative values which indicate error cases. Users of this function (see here for example) should not only fail if !ccnl_i_prefixof_c but rather when values are negative.

Please review with care! I'm not 100% sure I missed something.

Testing

w/o this PR (on current ccn-lite master)

main(): This is RIOT! (Version: 2020.01-devel-25-gcbee3-HEAD)
Basic CCN-Lite example
> ccnl_int /foo
ccnl_int /foo
> PKTDUMP: data received:
~~ SNIP  0 - size:   4 byte, type: GNRC_NETTYPE_CCN_CHUNK (2)
Content is: Bar!
~~ PKT    -  1 snips, total size:   4 byte
ccnl_int /a/b/c/d
ccnl_int /a/b/c/d
PKTDUMP: data received:
~~ SNIP  0 - size:   4 byte, type: GNRC_NETTYPE_CCN_CHUNK (2)
Content is: Bar!
~~ PKT    -  1 snips, total size:   4 byte

-> Second request is answered incorrectly from local CS

w/ this PR

See the requested content being received

main(): This is RIOT! (Version: 2020.01-devel-25-gcbee3-HEAD)
Basic CCN-Lite example
> ccnl_int /foo
ccnl_int /foo
>PKTDUMP: data received:
~~ SNIP  0 - size:   4 byte, type: GNRC_NETTYPE_CCN_CHUNK (2)
Content is: Bar!
~~ PKT    -  1 snips, total size:   4 byte
 ccnl_int /a/b/c/d
ccnl_int /a/b/c/d
> PKTDUMP: data received:
~~ SNIP  0 - size:  10 byte, type: GNRC_NETTYPE_CCN_CHUNK (2)
Content is: content123
~~ PKT    -  1 snips, total size:  10 byte

-> Both requests answered correctly.