dtls

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(conn *dtls.Conn, opts ...DialOption) *client.ClientConn

Client creates client over dtls connection.

func Dial

func Dial(target string, dtlsCfg *dtls.Config, opts ...DialOption) (*client.ClientConn, error)

Dial creates a client connection to the given target.

Types

type BlockwiseFactoryFunc

type BlockwiseFactoryFunc = func(getSentRequest func(token message.Token) (blockwise.Message, bool)) *blockwise.BlockWise

type BlockwiseOpt

type BlockwiseOpt struct {
	// contains filtered or unexported fields
}

BlockwiseOpt network option.

func WithBlockwise

func WithBlockwise(enable bool, szx blockwise.SZX, transferTimeout time.Duration) BlockwiseOpt

WithBlockwise configure's blockwise transfer.

type CloseSocketOpt

type CloseSocketOpt struct{}

CloseSocketOpt close socket option.

func WithCloseSocket

func WithCloseSocket() CloseSocketOpt

WithCloseSocket closes socket at the close connection.

type ContextOpt

type ContextOpt struct {
	// contains filtered or unexported fields
}

ContextOpt handler function option.

func WithContext

func WithContext(ctx context.Context) ContextOpt

WithContext set's parent context of server.

type DialOption

type DialOption interface {
	// contains filtered or unexported methods
}

A DialOption sets options such as credentials, keepalive parameters, etc.

type DialerOpt

type DialerOpt struct {
	// contains filtered or unexported fields
}

DialerOpt dialer option.

func WithDialer

func WithDialer(dialer *net.Dialer) DialerOpt

WithDialer set dialer for dial.

type ErrorFunc

type ErrorFunc = func(error)

type ErrorsOpt

type ErrorsOpt struct {
	// contains filtered or unexported fields
}

ErrorsOpt errors option.

func WithErrors

func WithErrors(errors ErrorFunc) ErrorsOpt

WithErrors set function for logging error.

type EventFunc

type EventFunc = func()

type GetMIDFunc

type GetMIDFunc = func() uint16

type GoPoolFunc

type GoPoolFunc = func(func()) error

type GoPoolOpt

type GoPoolOpt struct {
	// contains filtered or unexported fields
}

GoPoolOpt gopool option.

func WithGoPool

func WithGoPool(goPool GoPoolFunc) GoPoolOpt

WithGoPool sets function for managing spawning go routines for handling incoming request's. Eg: https://github.com/panjf2000/ants.

type HandlerFunc

type HandlerFunc = func(*client.ResponseWriter, *pool.Message)

The HandlerFunc type is an adapter to allow the use of ordinary functions as COAP handlers.

type HandlerFuncOpt

type HandlerFuncOpt struct {
	// contains filtered or unexported fields
}

HandlerFuncOpt handler function option.

func WithHandlerFunc

func WithHandlerFunc(h HandlerFunc) HandlerFuncOpt

WithHandlerFunc set handle for handling request's.

func WithMux

func WithMux(m mux.Handler) HandlerFuncOpt

WithMux set's multiplexer for handle requests.

type InactivityMonitorOpt

type InactivityMonitorOpt struct {
	// contains filtered or unexported fields
}

InactivityMonitorOpt notifies when a connection was inactive for a given duration.

func WithInactivityMonitor

func WithInactivityMonitor(duration time.Duration, onInactive inactivity.OnInactiveFunc) InactivityMonitorOpt

WithInactivityMonitor set deadline's for read operations over client connection.

type KeepAliveOpt

type KeepAliveOpt struct {
	// contains filtered or unexported fields
}

KeepAliveOpt keepalive option.

func WithKeepAlive

func WithKeepAlive(maxRetries uint32, timeout time.Duration, onInactive inactivity.OnInactiveFunc) KeepAliveOpt

WithKeepAlive monitoring's client connection's.

type Listener

type Listener interface {
	Close() error
	AcceptWithContext(ctx context.Context) (net.Conn, error)
}

Listener defined used by coap

type MaxMessageSizeOpt

type MaxMessageSizeOpt struct {
	// contains filtered or unexported fields
}

MaxMessageSizeOpt handler function option.

func WithMaxMessageSize

func WithMaxMessageSize(maxMessageSize uint32) MaxMessageSizeOpt

WithMaxMessageSize limit size of processed message.

type MessagePoolOpt

type MessagePoolOpt struct {
	// contains filtered or unexported fields
}

MessagePoolOpt network option.

func WithMessagePool

func WithMessagePool(messagePool *pool.Pool) MessagePoolOpt

WithMessagePool configure's message pool for acquire/releasing coap messages

type NetOpt

type NetOpt struct {
	// contains filtered or unexported fields
}

NetOpt network option.

func WithNetwork

func WithNetwork(net string) NetOpt

WithNetwork define's udp version (udp4, udp6, udp) for client.

type OnNewClientConnFunc

type OnNewClientConnFunc = func(cc *client.ClientConn, dtlsConn *dtls.Conn)

OnNewClientConnFunc is the callback for new connections.

Note: Calling `dtlsConn.Close()` is forbidden, and `dtlsConn` should be treated as a "read-only" parameter, mainly used to get the peer certificate from the underlining connection

type OnNewClientConnOpt

type OnNewClientConnOpt struct {
	// contains filtered or unexported fields
}

OnNewClientConnOpt network option.

func WithOnNewClientConn

func WithOnNewClientConn(onNewClientConn OnNewClientConnFunc) OnNewClientConnOpt

WithOnNewClientConn server's notify about new client connection.

Note: Calling `dtlsConn.Close()` is forbidden, and `dtlsConn` should be treated as a "read-only" parameter, mainly used to get the peer certificate from the underlining connection

type PeriodicRunnerOpt

type PeriodicRunnerOpt struct {
	// contains filtered or unexported fields
}

PeriodicRunnerOpt function which is executed in every ticks

func WithPeriodicRunner

func WithPeriodicRunner(periodicRunner periodic.Func) PeriodicRunnerOpt

WithPeriodicRunner set function which is executed in every ticks.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opt ...ServerOption) *Server

func (*Server) Serve

func (s *Server) Serve(l Listener) error
Example
package main

import (
	"fmt"
	"log"

	piondtls "github.com/pion/dtls/v2"
	"github.com/plgd-dev/go-coap/v2/dtls"
	"github.com/plgd-dev/go-coap/v2/net"
)

func main() {
	dtlsCfg := &piondtls.Config{
		PSK: func(hint []byte) ([]byte, error) {
			fmt.Printf("Hint: %s \n", hint)
			return []byte{0xAB, 0xC1, 0x23}, nil
		},
		PSKIdentityHint: []byte("Pion DTLS Server"),
		CipherSuites:    []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8},
	}
	l, err := net.NewDTLSListener("udp", "0.0.0.0:5683", dtlsCfg)
	if err != nil {
		log.Fatal(err)
	}
	defer l.Close()
	s := dtls.NewServer()
	defer s.Stop()
	log.Fatal(s.Serve(l))
}
Output:

func (*Server) Stop

func (s *Server) Stop()

Stop stops server without wait of ends Serve function.

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

A ServerOption sets options such as credentials, codec and keepalive parameters, etc.

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(
	ctx context.Context,
	connection *coapNet.Conn,
	maxMessageSize uint32,
	closeSocket bool,
) *Session

func (*Session) AddOnClose

func (s *Session) AddOnClose(f EventFunc)

func (*Session) Close

func (s *Session) Close() error

func (*Session) Context

func (s *Session) Context() context.Context

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done signalizes that connection is not more processed.

func (*Session) LocalAddr

func (s *Session) LocalAddr() net.Addr

func (*Session) MaxMessageSize

func (s *Session) MaxMessageSize() uint32

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

func (*Session) Run

func (s *Session) Run(cc *client.ClientConn) (err error)

Run reads and process requests from a connection, until the connection is not closed.

func (*Session) SetContextValue

func (s *Session) SetContextValue(key interface{}, val interface{})

SetContextValue stores the value associated with key to context of connection.

func (*Session) WriteMessage

func (s *Session) WriteMessage(req *pool.Message) error

func (*Session) WriteMulticastMessage

func (s *Session) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, opts ...coapNet.MulticastOption) error

WriteMulticastMessage sends multicast to the remote multicast address. Currently it is not implemented - is is just satisfy golang udp/client/Session interface.

type TransmissionOpt

type TransmissionOpt struct {
	// contains filtered or unexported fields
}

TransmissionOpt transmission options.

func WithTransmission

func WithTransmission(transmissionNStart time.Duration,
	transmissionAcknowledgeTimeout time.Duration,
	transmissionMaxRetransmit uint32,
) TransmissionOpt

WithTransmission set options for (re)transmission for Confirmable message-s.

Jump to

Keyboard shortcuts

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