Skip to content

Commit

Permalink
Amend server
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru committed Oct 16, 2023
1 parent 3d3aa52 commit 40db759
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/server/coap/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Server struct {
handler mux.HandlerFunc
}

var enableDTLS = true

var _ server.Server = (*Server)(nil)

func New(ctx context.Context, cancel context.CancelFunc, name string, config server.Config, handler mux.HandlerFunc, logger logger.Logger) server.Server {
Expand Down Expand Up @@ -55,6 +57,23 @@ func (s *Server) Start() error {
go func() {
errCh <- gocoap.ListenAndServeTCPTLS("udp", s.Address, tlsConfig, s.handler)
}()

case enableDTLS:
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))


go func(){
errCh <- gocoap.ListenAndServeDTLS("udp", ":5688", &piondtls.Config{
PSK: func(hint []byte) ([]byte, error) {
fmt.Printf("Client's hint: %s \n", hint)
return []byte{0xAB, 0xC1, 0x23}, nil
},
PSKIdentityHint: []byte("Pion DTLS Client"),
CipherSuites: []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8},
}, 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() {
Expand Down

0 comments on commit 40db759

Please sign in to comment.