Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = func() udpClient.Config { cfg := udpClient.DefaultConfig cfg.Handler = func(w *responsewriter.ResponseWriter[*udpClient.Conn], r *pool.Message) { switch r.Code() { case codes.GET, codes.POST, codes.PUT, codes.DELETE, codes.FETCH, codes.PATCH, codes.IPATCH: if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil { cfg.Errors(fmt.Errorf("dtls client: cannot set response: %w", err)) } } } return cfg }()
Functions ¶
func Dial ¶
Dial creates a client connection to the given target. Unless cfg sets a ServerName, the host part of target is used as the ServerName, so the server certificate is verified against it. For a target with an empty host, the server name defaults to "localhost". DTLSClientOptions.WithoutHostnameVerification disables the hostname check and SNI, while retaining certificate chain verification by default. cfg accepts either a *dtls.Config (backward-compatible legacy path) or a DTLSClientOptions value built with NewDTLSClientOptions (recommended).
Example (WithOptions) ¶
package main
import (
"context"
"fmt"
"io"
"log"
"time"
piondtls "github.com/pion/dtls/v3"
"github.com/plgd-dev/go-coap/v3/dtls"
)
func main() {
conn, err := dtls.Dial("pluggedin.cloud:5684", dtls.NewDTLSClientOptions(
piondtls.WithPSK(func(hint []byte) ([]byte, error) {
fmt.Printf("Hint: %s \n", hint)
return []byte{0xAB, 0xC1, 0x23}, nil
}),
piondtls.WithPSKIdentityHint([]byte("Pion DTLS Server")),
piondtls.WithCipherSuites(piondtls.TLS_PSK_WITH_AES_128_CCM_8),
))
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
res, err := conn.Get(ctx, "/oic/res")
if err != nil {
log.Fatal(err)
}
data, err := io.ReadAll(res.Body())
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v", data)
}
Output:
Types ¶
type DTLSClientConfig ¶ added in v3.5.0
type DTLSClientConfig interface {
*piondtls.Config | DTLSClientOptions
}
DTLSClientConfig is a type constraint accepted by Dial. It allows callers to pass either the legacy *piondtls.Config (backward-compatible) or the recommended DTLSClientOptions wrapper (built via NewDTLSClientOptions).
type DTLSClientOptions ¶ added in v3.5.0
type DTLSClientOptions struct {
// contains filtered or unexported fields
}
DTLSClientOptions holds DTLS client-side configuration options for use with Dial. It wraps the options-based API of pion/dtls, keeping pion/dtls option types out of go-coap function signatures.
func NewDTLSClientOptions ¶ added in v3.5.0
func NewDTLSClientOptions(opts ...piondtls.ClientOption) DTLSClientOptions
NewDTLSClientOptions creates a DTLSClientOptions from the provided pion/dtls ClientOption values (e.g. piondtls.WithPSK, piondtls.WithCertificates, …).
Most pion/dtls options implement the shared piondtls.Option interface, which satisfies both ServerOption and ClientOption, so they can be passed here directly.
func (DTLSClientOptions) WithoutHostnameVerification ¶ added in v3.9.1
func (o DTLSClientOptions) WithoutHostnameVerification() DTLSClientOptions
WithoutHostnameVerification disables server certificate hostname verification in Dial. Certificate chain verification remains enabled unless disabled separately in the Pion options. This also disables SNI, even if a server name was supplied with piondtls.WithServerName. Without hostname verification, any certificate trusted by the configured roots can identify the server.