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

MG-1963 - Remove TCP config from CoAP server #2139

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions internal/server/coap/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package coap

import (
"context"
"crypto/tls"
"fmt"
"log/slog"
"time"
Expand Down Expand Up @@ -44,26 +43,10 @@ func New(ctx context.Context, cancel context.CancelFunc, name string, config ser
func (s *Server) Start() error {
errCh := make(chan error)
s.Logger.Info(fmt.Sprintf("%s service started using http, exposed port %s", s.Name, s.Address))
switch {
case s.Config.CertFile != "" || s.Config.KeyFile != "":
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s with TLS cert %s and key %s", s.Name, s.Protocol, s.Address, s.Config.CertFile, s.Config.KeyFile))
certificate, err := tls.LoadX509KeyPair(s.Config.CertFile, s.Config.KeyFile)
if err != nil {
return fmt.Errorf("failed to load auth certificates: %w", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{certificate},
}

go func() {
errCh <- gocoap.ListenAndServeTCPTLS("udp", s.Address, tlsConfig, s.handler)
}()
default:
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address))
go func() {
errCh <- gocoap.ListenAndServe("udp", s.Address, s.handler)
}()
}
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address))
go func() {
errCh <- gocoap.ListenAndServe("udp", s.Address, s.handler)
}()

select {
case <-s.Ctx.Done():
Expand Down
Loading