-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: master
Are you sure you want to change the base?
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.
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) { |
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.
Avoid using snake_case. Also, use switch
instead of if-else
.
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.
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" |
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.
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 | |
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.
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 |
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.
Add seperate example for dtls
cert_utility/utility.go
Outdated
@@ -0,0 +1,145 @@ | |||
package cert_utility |
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.
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.
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
cert_utility/utility.go
Outdated
log.Fatal(err) | ||
} | ||
defer kb.Close() | ||
kb.Read(clientKeyBytes) |
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.
handle errors
cmd/main.go
Outdated
go func() { | ||
c := make(chan os.Signal) | ||
c := make(chan os.Signal, 1) // make the channel buffered |
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 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 |
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 comment
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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>
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