Skip to content

Commit

Permalink
MG-1963 - Remove TCP config from CoAP server (#2139)
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
  • Loading branch information
felixgateru authored Apr 11, 2024
1 parent 76788d3 commit cdf18dc
Showing 1 changed file with 4 additions and 21 deletions.
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

0 comments on commit cdf18dc

Please sign in to comment.