dtls

package
v3.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 13 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultConfig = func() udpClient.Config {
	cfg := udpClient.DefaultConfig
	cfg.Handler = func(w *responsewriter.ResponseWriter[*udpClient.Conn], r *pool.Message) {
		switch r.Code() {
		case codes.POST, codes.PUT, codes.GET, codes.DELETE:
			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 Client

func Client(conn *dtls.Conn, opts ...udp.Option) *udpClient.Conn

Client creates client over dtls connection.

func Dial

func Dial[T DTLSClientConfig](target string, cfg T, opts ...udp.Option) (*udpClient.Conn, error)

Dial creates a client connection to the given target. 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)
}

func NewServer

func NewServer(opt ...server.Option) *server.Server

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL