client

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 23 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = func() Config {
	opts := Config{
		Common: config.NewCommon[*Conn](),
		CreateInactivityMonitor: func() InactivityMonitor {
			return inactivity.NewNilMonitor[*Conn]()
		},
		Dialer:              &net.Dialer{Timeout: time.Second * 3},
		Net:                 "tcp",
		ConnectionCacheSize: 2048,
	}
	opts.Handler = func(w *responsewriter.ResponseWriter[*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 {
				opts.Errors(fmt.Errorf("client handler: cannot set response: %w", err))
			}
		}
	}
	return opts
}()

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Common[*Conn]
	CreateInactivityMonitor         CreateInactivityMonitorFunc
	Net                             string
	Dialer                          *net.Dialer
	TLSCfg                          *tls.Config
	Handler                         HandlerFunc
	ConnectionCacheSize             uint16
	DisablePeerTCPSignalMessageCSMs bool
	CloseSocket                     bool
	DisableTCPSignalMessageCSM      bool
}

type Conn

type Conn struct {
	*client.Client[*Conn]
	// contains filtered or unexported fields
}

Conn represents a virtual connection to a conceptual endpoint, to perform COAPs commands.

func NewConn

func NewConn(
	connection *coapNet.Conn,
	createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn],
	inactivityMonitor InactivityMonitor,
	cfg *Config,
) *Conn

NewConn creates connection over session and observation.

func (*Conn) AcquireMessage

func (cc *Conn) AcquireMessage(ctx context.Context) *pool.Message

func (*Conn) AddOnClose

func (cc *Conn) AddOnClose(f EventFunc)

AddOnClose calls function on close connection event.

func (*Conn) AsyncPing

func (cc *Conn) AsyncPing(receivedPong func()) (func(), error)

AsyncPing sends ping and receivedPong will be called when pong arrives. It returns cancellation of ping operation.

func (*Conn) CheckExpirations

func (cc *Conn) CheckExpirations(now time.Time)

CheckExpirations checks and remove expired items from caches.

func (*Conn) Close

func (cc *Conn) Close() error

Close closes connection without wait of ends Run function.

func (*Conn) Context

func (cc *Conn) Context() context.Context

Context returns the client's context.

If connections was closed context is cancelled.

func (*Conn) Done

func (cc *Conn) Done() <-chan struct{}

Done signalizes that connection is not more processed.

func (*Conn) LocalAddr

func (cc *Conn) LocalAddr() net.Addr

func (*Conn) NetConn

func (cc *Conn) NetConn() net.Conn

NetConn returns the underlying connection that is wrapped by cc. The Conn returned is shared by all invocations of NetConn, so do not modify it.

func (*Conn) ReleaseMessage

func (cc *Conn) ReleaseMessage(m *pool.Message)

func (*Conn) RemoteAddr

func (cc *Conn) RemoteAddr() net.Addr

RemoteAddr gets remote address.

func (*Conn) Run

func (cc *Conn) Run() (err error)

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

func (*Conn) Sequence

func (cc *Conn) Sequence() uint64

Sequence acquires sequence number.

func (*Conn) Session

func (cc *Conn) Session() *Session

func (*Conn) SetContextValue

func (cc *Conn) SetContextValue(key interface{}, val interface{})

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

func (*Conn) WriteMessage

func (cc *Conn) WriteMessage(req *pool.Message) error

WriteMessage sends an coap message.

type CreateInactivityMonitorFunc

type CreateInactivityMonitorFunc = func() InactivityMonitor

type ErrorFunc

type ErrorFunc = func(error)

type EventFunc

type EventFunc = func()

type GetMIDFunc

type GetMIDFunc = func() int32

type GoPoolFunc

type GoPoolFunc = config.GoPoolFunc[*Conn]

type HandlerFunc

type HandlerFunc = func(*responsewriter.ResponseWriter[*Conn], *pool.Message)

type InactivityMonitor

type InactivityMonitor interface {
	Notify()
	CheckInactivity(now time.Time, cc *Conn)
}

type Notifier

type Notifier interface {
	Notify()
}

type Session

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

func NewSession

func NewSession(
	ctx context.Context,
	connection *coapNet.Conn,
	handler HandlerFunc,
	maxMessageSize uint32,
	goPool GoPoolFunc,
	errors ErrorFunc,
	blockwiseSZX blockwise.SZX,
	blockWise *blockwise.BlockWise[*Conn],
	disablePeerTCPSignalMessageCSMs bool,
	disableTCPSignalMessageCSM bool,
	closeSocket bool,
	inactivityMonitor InactivityMonitor,
	connectionCacheSize uint16,
	messagePool *pool.Pool,
) *Session

func (*Session) AcquireMessage

func (s *Session) AcquireMessage(ctx context.Context) *pool.Message

func (*Session) AddOnClose

func (s *Session) AddOnClose(f EventFunc)

func (*Session) CheckExpirations

func (s *Session) CheckExpirations(now time.Time, cc *Conn)

CheckExpirations checks and remove expired items from caches.

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) Handle

func (s *Session) Handle(w *responsewriter.ResponseWriter[*Conn], r *pool.Message)

func (*Session) LocalAddr

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

func (*Session) NetConn

func (s *Session) NetConn() net.Conn

NetConn returns the underlying connection that is wrapped by s. The Conn returned is shared by all invocations of NetConn, so do not modify it.

func (*Session) PeerBlockWiseTransferEnabled

func (s *Session) PeerBlockWiseTransferEnabled() bool

func (*Session) PeerMaxMessageSize

func (s *Session) PeerMaxMessageSize() uint32

func (*Session) ReleaseMessage

func (s *Session) ReleaseMessage(m *pool.Message)

func (*Session) RemoteAddr

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

RemoteAddr gets remote address.

func (*Session) Run

func (s *Session) Run(cc *Conn) (err error)

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

func (*Session) Sequence

func (s *Session) Sequence() uint64

func (*Session) SetContextValue

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

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

func (*Session) TokenHandler

func (s *Session) TokenHandler() *coapSync.Map[uint64, HandlerFunc]

func (*Session) WriteMessage

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

Jump to

Keyboard shortcuts

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