NOISSUE - Add dtls config to CoAP cli#7
Conversation
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>
cert_utility/utility.go
Outdated
| clientCrtBytes := make([]byte, 2048) | ||
| caBytes := make([]byte, 2048) | ||
|
|
||
| kb, err := os.Open("../certs/client.key") |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Avoid using snake_case. Also, use switch instead of if-else.
There was a problem hiding this comment.
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" |
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 | |
|
|
||
| ```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 |
There was a problem hiding this comment.
Add seperate example for dtls
cert_utility/utility.go
Outdated
| @@ -0,0 +1,145 @@ | |||
| package cert_utility | |||
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Declare the returned interface somewhere first for readability
cert_utility/utility.go
Outdated
| log.Fatal(err) | ||
| } | ||
| defer kb.Close() | ||
| kb.Read(clientKeyBytes) |
cmd/main.go
Outdated
|
|
||
| go func() { | ||
| c := make(chan os.Signal) | ||
| c := make(chan os.Signal, 1) // make the channel buffered |
cmd/main.go
Outdated
| log.Fatal("Error observing resource: ", err) | ||
| } | ||
| errs := make(chan error, 2) | ||
| errs := make(chan error, 1) // make the channel buffered |
coap/client.go
Outdated
| func (c Client) Receive(path string, opts ...message.Option) (interface { | ||
| Cancel(ctx context.Context, opts ...message.Option) error | ||
| Canceled() bool | ||
| }, error) { |
There was a problem hiding this comment.
| 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) { |
There was a problem hiding this comment.
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>
|
@dborovcanin Should we close this one in favour of #11? |
|
Closing in favor of #11. |
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