-
Notifications
You must be signed in to change notification settings - Fork 673
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
MF-928 - Change CoAP lib #1233
Conversation
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 Report
@@ 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
Continue to review full report at Codecov.
|
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to remove this map? can it be reused here https://github.com/mainflux/mainflux/pull/1233/files#diff-a9745ffe405cfa25fb4f36761ce61eefR137
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
_, err := svc.auth.CanAccessByKey(ctx, ar) | ||
if err != nil { | ||
return errors.Wrap(ErrUnauthorized, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can inline this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
c.logger.Error(fmt.Sprintf("Can't set content format: %s.", err)) | ||
return errors.Wrap(ErrOption, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this logged latter?
There was a problem hiding this comment.
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
err = c.client.WriteMessage(&m) | ||
if err != nil { | ||
c.logger.Error(fmt.Sprintf("Error sending message: %s.", err)) | ||
} | ||
return err |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* 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>
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.