Skip to content

NOISSUE - Add dtls config to CoAP cli#7

Closed
felixgateru wants to merge 6 commits intoabsmach:masterfrom
felixgateru:dtls_support
Closed

NOISSUE - Add dtls config to CoAP cli#7
felixgateru wants to merge 6 commits intoabsmach:masterfrom
felixgateru:dtls_support

Conversation

@felixgateru
Copy link
Contributor

@felixgateru felixgateru commented Sep 27, 2023

What does this do?

Add dtls config to CoAP cli

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

None

List any changes that modify/break current functionality

Refactor coap.go to include DTLS dial.
Refactor main.go Changed functionality of New function.

Have you included tests for your changes?

No

Did you document any new/modified functionality?

Updated the README with new instructions on building.

Notes

Signed-off-by: 1998-felix <felix.gateru@gmail.com>
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
Signed-off-by: felix.gateru <felix.gateru@gmail.com>
Signed-off-by: felix.gateru <felix.gateru@gmail.com>
@felixgateru felixgateru marked this pull request as ready for review October 9, 2023 09:16
clientCrtBytes := make([]byte, 2048)
caBytes := make([]byte, 2048)

kb, err := os.Open("../certs/client.key")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use os.ReadFile and make file paths configurable.

coap/client.go Outdated
c, err := udp.Dial(addr)
if err != nil {
log.Fatalf("Error dialing: %v", err)
func New(addr string, to_dtls bool) (Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using snake_case. Also, use switch instead of if-else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Try using cert and key paths to determine DTLS. If the cert path is set, try establishing DTLS connection with cert on that path.

coap/client.go Outdated
"github.com/plgd-dev/go-coap/v2/udp"
"github.com/plgd-dev/go-coap/v2/udp/client"
"github.com/plgd-dev/go-coap/v2/udp/message/pool"
cert_utility "github.com/mainflux/coap-cli/cert_utility"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to certutil.

README.md Outdated
| p | port | "5683" |
| d | data to be sent in POST or PUT | "" |
| cf | content format | 50 (JSON format) |
|tls | dtls support | false |
Copy link
Contributor

Choose a reason for hiding this comment

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

align


```bash
coap-cli get channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -o
coap-cli get channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -o -tls
Copy link
Contributor

Choose a reason for hiding this comment

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

Add seperate example for dtls

@@ -0,0 +1,145 @@
package cert_utility
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename package name to follow guidelines https://go.dev/blog/package-names

coap/client.go Outdated

// Receive receives a message.
func (c Client) Receive(path string, opts ...message.Option) (*client.Observation, error) {
func (c Client) Receive(path string, opts ...message.Option) (interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Declare the returned interface somewhere first for readability

log.Fatal(err)
}
defer kb.Close()
kb.Read(clientKeyBytes)

Choose a reason for hiding this comment

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

handle errors

cmd/main.go Outdated

go func() {
c := make(chan os.Signal)
c := make(chan os.Signal, 1) // make the channel buffered

Choose a reason for hiding this comment

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

remove comment

cmd/main.go Outdated
log.Fatal("Error observing resource: ", err)
}
errs := make(chan error, 2)
errs := make(chan error, 1) // make the channel buffered

Choose a reason for hiding this comment

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

remove comment

coap/client.go Outdated
Comment on lines +67 to +70
func (c Client) Receive(path string, opts ...message.Option) (interface {
Cancel(ctx context.Context, opts ...message.Option) error
Canceled() bool
}, error) {

Choose a reason for hiding this comment

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

Suggested change
func (c Client) Receive(path string, opts ...message.Option) (interface {
Cancel(ctx context.Context, opts ...message.Option) error
Canceled() bool
}, error) {
func (c Client) Receive(path string, opts ...message.Option) (client.Observation, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont think the Conn type has an implementation of Observation.

Signed-off-by: felix.gateru <felix.gateru@gmail.com>
Signed-off-by: felix.gateru <felix.gateru@gmail.com>
@rodneyosodo
Copy link
Contributor

@dborovcanin Should we close this one in favour of #11?

@dborovcanin dborovcanin closed this Sep 5, 2025
@dborovcanin dborovcanin reopened this Sep 5, 2025
@dborovcanin
Copy link
Contributor

Closing in favor of #11.

@dborovcanin dborovcanin closed this Sep 5, 2025
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.

4 participants