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

NOISSUE - Add dtls config to CoAP cli #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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
@@ -15,11 +15,13 @@ When running, please provide following format:
| p | port | "5683" |
| d | data to be sent in POST or PUT | "" |
| cf | content format | 50 (JSON format) |
|tls | dtls support | false |
Copy link
Member

Choose a reason for hiding this comment

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

align

## Examples:

```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
Member

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
Member

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
Member

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
@@ -123,9 +126,10 @@ func main() {
if err != nil {
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>
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