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

MF-928 - Change CoAP lib #1233

Merged
merged 17 commits into from
Sep 22, 2020
Merged

MF-928 - Change CoAP lib #1233

merged 17 commits into from
Sep 22, 2020

Conversation

dborovcanin
Copy link
Collaborator

What does this do?

This pull request changes the lib used for CoAP protocol

Which issue(s) does this PR fix/relate to?

This pull request resolves #928 and partially #1144.

List any changes that modify/break current functionality

There are no such changes.

Have you included tests for your changes?

No, tests will be added in a separate pull request.

Did you document any new/modified functionality?

Yes.

Notes

The authorization option is changed to auth to be shorter.

@dborovcanin dborovcanin marked this pull request as ready for review September 14, 2020 16:51
@dborovcanin dborovcanin requested a review from a team as a code owner September 14, 2020 16:51
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2020

Codecov Report

Merging #1233 into master will decrease coverage by 1.70%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1233      +/-   ##
==========================================
- Coverage   76.18%   74.48%   -1.71%     
==========================================
  Files         106      106              
  Lines        6983     6149     -834     
==========================================
- Hits         5320     4580     -740     
+ Misses       1278     1188      -90     
+ Partials      385      381       -4     
Impacted Files Coverage Δ
twins/redis/twins.go 41.46% <0.00%> (-14.10%) ⬇️
things/postgres/database.go 59.09% <0.00%> (-9.88%) ⬇️
things/redis/channels.go 64.70% <0.00%> (-9.21%) ⬇️
pkg/errors/errors.go 67.64% <0.00%> (-5.53%) ⬇️
authn/api/http/requests.go 75.00% <0.00%> (-5.00%) ⬇️
things/redis/things.go 66.66% <0.00%> (-4.77%) ⬇️
writers/cassandra/init.go 66.66% <0.00%> (-4.77%) ⬇️
writers/influxdb/messages.go 69.23% <0.00%> (-4.11%) ⬇️
pkg/sdk/go/version.go 42.85% <0.00%> (-3.81%) ⬇️
bootstrap/service.go 74.34% <0.00%> (-3.78%) ⬇️
... and 96 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f18f2c1...c27082a. Read the comment docs.

cmd/coap/main.go Outdated
p := fmt.Sprintf(":%s", cfg.port)
l.Info(fmt.Sprintf("CoAP adapter service started, exposed port %s", cfg.port))
errs <- gocoap.ListenAndServe("udp", p, api.MakeCOAPHandler(svc, auth, l, respChan, cfg.pingPeriod))
r := api.MakeCoAPHandler(svc, l)
// errs <- gocoap.ListenAndServe("udp", p, api.MakeCOAPHandler(svc, auth, l, respChan, cfg.pingPeriod))
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove dead code

coap/adapter.go Outdated
Token: key,
ChanID: chanID,
}
_, err := svc.auth.CanAccessByKey(ctx, ar)
Copy link
Contributor

Choose a reason for hiding this comment

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

If var is not used, maybe you can embed error check.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
cmd/coap/main.go Outdated Show resolved Hide resolved
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
manuio
manuio previously approved these changes Sep 16, 2020
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

delete(obs, token)
// If there are no observers left for the endpint, remove the map.
if len(obs) == 0 {
delete(svc.observers, endpoint)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can do it, but it's a potential memory leak. If we don't remove it and nobody actually adds the observer for the corresponding topic, we'll likely end up flooded with empty maps.

coap/observer.go Outdated
if err := proto.Unmarshal(m.Data, &msg); err != nil {
return
}
if err := c.SendMessage(msg); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nothing happens on error?

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
coap/adapter.go Outdated
Comment on lines 94 to 97
_, err := svc.auth.CanAccessByKey(ctx, ar)
if err != nil {
return errors.Wrap(ErrUnauthorized, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can inline this

manuio
manuio previously approved these changes Sep 18, 2020
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

blokovi
blokovi previously approved these changes Sep 18, 2020
@dborovcanin dborovcanin dismissed stale reviews from blokovi and manuio via 7ca088b September 18, 2020 12:56
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Comment on lines +75 to +76
c.logger.Error(fmt.Sprintf("Can't set content format: %s.", err))
return errors.Wrap(ErrOption, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this logged latter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this is logged here. There is no convenient way to handle errors here since this is only a handler for the Nats subscription.

coap/client.go Outdated
Comment on lines 79 to 83
err = c.client.WriteMessage(&m)
if err != nil {
c.logger.Error(fmt.Sprintf("Error sending message: %s.", err))
}
return err
Copy link
Contributor

@manuio manuio Sep 18, 2020

Choose a reason for hiding this comment

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

You can inline this. And same question, is this logged later?

drasko
drasko previously approved these changes Sep 20, 2020
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

manuio
manuio previously approved these changes Sep 21, 2020
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

@dborovcanin dborovcanin dismissed stale reviews from manuio and drasko via c27082a September 21, 2020 07:28
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit f10e49e into absmach:master Sep 22, 2020
manuio pushed a commit that referenced this pull request Oct 12, 2020
* Switch CoAP lib

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Revert removed adapter code

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* WIP CoAP refactor

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Add auth key

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix observers map

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix reading message body

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix subtopic parsing

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix error handling

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix multi-protocol communication

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Separate client from observer

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Remove unused config

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Remove TCP option

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Inline error check

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Add logging client errors

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Replace RWMutex since we're not using RLock

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Inline error handling

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Inline error handling

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
@dborovcanin dborovcanin deleted the MF-928 branch June 13, 2022 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change CoAP lib
6 participants