core

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 48 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DiscoverAllDevices discovers owned and disowned devices.
	DiscoverAllDevices = DiscoverOwnershipStatus(0)
	// DiscoverOwnedDevices discovers owned devices,
	DiscoverOwnedDevices = DiscoverOwnershipStatus(1)
	// DiscoverDisownedDevices discovers disowned devices,
	DiscoverDisownedDevices = DiscoverOwnershipStatus(2)
)
View Source
const ANY_DEVICE = "anydevice"

Variables

View Source
var (
	DiscoveryAddressUDP4 = []string{"224.0.1.187:5683"}
	DiscoveryAddressUDP6 = []string{"[ff02::158]:5683", "[ff03::158]:5683", "[ff05::158]:5683"}
)

See the section 10.4 on the line 2482 of the Core specification: https://openconnectivity.org/specs/OCF_Core_Specification_v2.0.0.pdf https://iotivity.org/documentation/linux/programmers-guide

Functions

func Discover

func Discover(
	ctx context.Context,
	conn []*DiscoveryClient,
	href string,
	handler DiscoveryHandler,
	options ...coap.OptionFunc,
) error

Discover discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled. Device resources can be queried in DiscoveryHandler. An empty typeFilter queries all resource types. Note: Iotivity 1.3 which responds with BadRequest if more than 1 resource type is queried.

func DiscoverDeviceOwnership

func DiscoverDeviceOwnership(
	ctx context.Context,
	conn []*DiscoveryClient,
	status DiscoverOwnershipStatus,
	handler DiscoverDeviceOwnershipHandler,
) error

DiscoverDeviceOwnership discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled.

func DiscoverDevices

func DiscoverDevices(
	ctx context.Context,
	conn []*DiscoveryClient,
	handler DiscoverDevicesHandler,
	options ...coap.OptionFunc,
) error

DiscoverDevices discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled. Device resources can be queried in DiscoveryHandler. An empty typeFilter queries all resource types. Note: Iotivity 1.3 which responds with BadRequest if more than 1 resource type is queried.

func GetResourceLink(links schema.ResourceLinks, href string) (schema.ResourceLink, error)

func MakeAborted

func MakeAborted(e error) error

func MakeAlreadyExists

func MakeAlreadyExists(e error) error

func MakeCanceled

func MakeCanceled(e error) error

func MakeDataLoss

func MakeDataLoss(e error) error

func MakeDeadlineExceeded

func MakeDeadlineExceeded(e error) error

func MakeFailedPrecondition

func MakeFailedPrecondition(e error) error

func MakeInternal

func MakeInternal(e error) error

func MakeInternalStr

func MakeInternalStr(str string, e error) error

func MakeInvalidArgument

func MakeInvalidArgument(e error) error

func MakeNotFound

func MakeNotFound(e error) error

func MakeOutOfRange

func MakeOutOfRange(e error) error

func MakePermissionDenied

func MakePermissionDenied(e error) error

func MakeResourceExhausted

func MakeResourceExhausted(e error) error

func MakeSdkError

func MakeSdkError(code codes.Code, err error) error

func MakeUnauthenticated

func MakeUnauthenticated(e error) error

func MakeUnavailable

func MakeUnavailable(e error) error

func MakeUnimplemented

func MakeUnimplemented(e error) error

func MakeUnknown

func MakeUnknown(e error) error

Types

type ActionAfterOwnFunc added in v1.2.0

type ActionAfterOwnFunc = func(ctx context.Context, client *coap.ClientCloseHandler) error

type ActionDuringOwnFunc

type ActionDuringOwnFunc = func(ctx context.Context, client *coap.ClientCloseHandler) (string, error)

type CertificateSigner

type CertificateSigner = interface {
	// csr is encoded by PEM and returns PEM
	Sign(ctx context.Context, csr []byte) ([]byte, error)
}

type Client

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

Client an OCF local client.

func NewClient

func NewClient(opts ...OptionFunc) *Client

func (*Client) GetDeviceByIP

func (c *Client) GetDeviceByIP(ctx context.Context, ip string) (*Device, error)

GetDeviceByIP gets the device directly via IP address and multicast listen port 5683.

func (*Client) GetDeviceByMulticast

func (c *Client) GetDeviceByMulticast(ctx context.Context, deviceID string, discoveryConfiguration DiscoveryConfiguration) (*Device, error)

GetDevice performs a multicast and returns a device object if the device responds.

func (*Client) GetDevices

func (c *Client) GetDevices(ctx context.Context, handler DeviceHandler) error

GetDevices discovers devices using a CoAP multicast request via UDP to default addresses. Device resources can be queried in DeviceHandler using device.Client, DEPRECATED

func (*Client) GetDevicesV2

func (c *Client) GetDevicesV2(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, handler DeviceHandlerV2) error

GetDevices discovers devices using a CoAP multicast request via UDP. Device resources can be queried in DeviceHandler using device.Client,

func (*Client) GetOwnerships

func (c *Client) GetOwnerships(
	ctx context.Context,
	discoveryConfiguration DiscoveryConfiguration,
	status DiscoverOwnershipStatus,
	handler OwnershipHandler,
) error

GetOwnerships discovers device's ownerships using a CoAP multicast request via UDP. It waits for device responses until the context is canceled.

func (*Client) GetSdkOwnerID

func (c *Client) GetSdkOwnerID() (string, error)

GetSdkOwnerID returns sdk ownerID from sdk identity certificate.

type Device

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

func NewDevice

func NewDevice(
	cfg DeviceConfiguration,
	deviceID string,
	deviceTypes []string,
	getEndpoints func() schema.Endpoints,
) *Device

func (*Device) Close

func (d *Device) Close(ctx context.Context) error

Close closes open connections to the device.

func (*Device) DeleteResource

func (d *Device) DeleteResource(
	ctx context.Context,
	link schema.ResourceLink,
	response interface{},
	options ...coap.OptionFunc,
) error

func (*Device) DeleteResourceWithCodec

func (d *Device) DeleteResourceWithCodec(
	ctx context.Context,
	link schema.ResourceLink,
	codec coap.Codec,
	response interface{},
	options ...coap.OptionFunc,
) error

func (*Device) DeviceID

func (d *Device) DeviceID() string

func (*Device) DeviceTypes

func (d *Device) DeviceTypes() []string

func (*Device) Disown

func (d *Device) Disown(
	ctx context.Context,
	links schema.ResourceLinks,
) error

DisownDevice removes ownership of device

func (*Device) FactoryReset

func (d *Device) FactoryReset(
	ctx context.Context,
	links schema.ResourceLinks,
) error

func (*Device) FoundByIP added in v1.3.0

func (d *Device) FoundByIP() string

func (*Device) GetEndpoints

func (d *Device) GetEndpoints() schema.Endpoints

func (*Device) GetOwnership

func (d *Device) GetOwnership(ctx context.Context, links schema.ResourceLinks) (doxm.Doxm, error)

GetOwnership gets device's ownership resource.

func (*Device) GetResource

func (d *Device) GetResource(
	ctx context.Context,
	link schema.ResourceLink,
	response interface{},
	options ...coap.OptionFunc,
) error

GetResource queries a device for a resource value in CBOR.

func (d *Device) GetResourceLinks(ctx context.Context, endpoints []schema.Endpoint, options ...coap.OptionFunc) (schema.ResourceLinks, error)

func (*Device) GetResourceWithCodec

func (d *Device) GetResourceWithCodec(
	ctx context.Context,
	link schema.ResourceLink,
	codec coap.Codec,
	response interface{},
	options ...coap.OptionFunc,
) error

GetResourceWithCodec queries a device for a resource value.

func (*Device) GetResources

func (d *Device) GetResources(ctx context.Context, links schema.ResourceLinks) *ResourceIterator

GetResources resolves URIs and returns an iterator for querying resources of given resource types.

func (*Device) GetSdkOwnerID

func (d *Device) GetSdkOwnerID() (string, error)

GetSdkOwnerID returns sdk ownerID

func (*Device) IsConnected added in v1.3.0

func (d *Device) IsConnected() bool

func (*Device) IsSecured

func (d *Device) IsSecured() bool

IsSecured returns if device serves secure ports.

func (*Device) ObserveResource

func (d *Device) ObserveResource(
	ctx context.Context,
	link schema.ResourceLink,
	handler ObservationHandler,
	options ...coap.OptionFunc,
) (observationID string, _ error)

func (*Device) ObserveResourceWithCodec

func (d *Device) ObserveResourceWithCodec(
	ctx context.Context,
	link schema.ResourceLink,
	codec coap.Codec,
	handler ObservationHandler,
	options ...coap.OptionFunc,
) (observationID string, _ error)

func (*Device) Own

func (d *Device) Own(
	ctx context.Context,
	links schema.ResourceLinks,
	otmClients []otm.Client,
	options ...OwnOption,
) error

Own set ownership of device. For owning, the first match in order of otmClients with the device will be used.

func (*Device) Provision

func (d *Device) Provision(ctx context.Context, links schema.ResourceLinks) (*ProvisioningClient, error)

func (*Device) Reboot

func (d *Device) Reboot(
	ctx context.Context,
	links schema.ResourceLinks,
) error

func (*Device) SetDeviceID added in v1.3.4

func (d *Device) SetDeviceID(deviceID string)

func (*Device) SetEndpoints added in v1.3.4

func (d *Device) SetEndpoints(getEndpoints func() schema.Endpoints)

func (*Device) StopObservingResource

func (d *Device) StopObservingResource(
	ctx context.Context,
	observationID string,
) (bool, error)

func (*Device) UpdateBy added in v1.3.0

func (d *Device) UpdateBy(v *Device)

func (*Device) UpdateResource

func (d *Device) UpdateResource(
	ctx context.Context,
	link schema.ResourceLink,
	request interface{},
	response interface{},
	options ...coap.OptionFunc,
) error

func (*Device) UpdateResourceWithCodec

func (d *Device) UpdateResourceWithCodec(
	ctx context.Context,
	link schema.ResourceLink,
	codec coap.Codec,
	request interface{},
	response interface{},
	options ...coap.OptionFunc,
) error

type DeviceConfiguration added in v1.3.0

type DeviceConfiguration struct {
	DialDTLS   DialDTLS
	DialTLS    DialTLS
	DialUDP    DialUDP
	DialTCP    DialTCP
	ErrFunc    ErrFunc
	TLSConfig  *TLSConfig
	GetOwnerID func() (string, error)
}

type DeviceHandler

type DeviceHandler interface {
	// Handle gets a device connection and is responsible for closing it.
	Handle(ctx context.Context, device *Device, deviceLinks schema.ResourceLinks)
	// Error gets errors during discovery.
	Error(err error)
}

DeviceHandler conveys device connections and errors during discovery.

type DeviceHandlerV2

type DeviceHandlerV2 interface {
	// Handle gets a device connection and is responsible for closing it.
	Handle(ctx context.Context, device *Device)
	// Error gets errors during discovery.
	Error(err error)
}

DeviceHandler conveys device connections and errors during discovery.

type DialDTLS

type DialDTLS = func(ctx context.Context, addr string, dtlsCfg *dtls.Config, opts ...coap.DialOptionFunc) (*coap.ClientCloseHandler, error)

type DialTCP

type DialTCP = func(ctx context.Context, addr string, opts ...coap.DialOptionFunc) (*coap.ClientCloseHandler, error)

type DialTLS

type DialTLS = func(ctx context.Context, addr string, tlsCfg *tls.Config, opts ...coap.DialOptionFunc) (*coap.ClientCloseHandler, error)

type DialUDP

type DialUDP = func(ctx context.Context, addr string, opts ...coap.DialOptionFunc) (*coap.ClientCloseHandler, error)

type DiscoverDeviceCodec

type DiscoverDeviceCodec struct{}

func (DiscoverDeviceCodec) ContentFormat

func (c DiscoverDeviceCodec) ContentFormat() message.MediaType

ContentFormat propagates the CoAP media type.

func (DiscoverDeviceCodec) Decode

func (c DiscoverDeviceCodec) Decode(msg *message.Message, v interface{}) error

Decode validates the content format and propagates the payload to v as *schema.ResourceLinks

func (DiscoverDeviceCodec) Encode

func (c DiscoverDeviceCodec) Encode(v interface{}) ([]byte, error)

Encode propagates the payload without any conversions.

type DiscoverDeviceOwnershipHandler

type DiscoverDeviceOwnershipHandler interface {
	Handle(ctx context.Context, client *client.ClientConn, device doxm.Doxm)
	Error(err error)
}

DiscoverDeviceOwnershipHandler receives devices ownership info.

type DiscoverDevicesHandler

type DiscoverDevicesHandler interface {
	Handle(ctx context.Context, client *client.ClientConn, device schema.ResourceLinks)
	Error(err error)
}

DiscoverDevicesHandler receives device links and errors from the discovery multicast request.

type DiscoverOwnershipStatus

type DiscoverOwnershipStatus int

DiscoverOwnershipStatus type of discover ownership status.

type DiscoveryClient

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

func DialDiscoveryAddresses

func DialDiscoveryAddresses(ctx context.Context, cfg DiscoveryConfiguration, errors func(error)) ([]*DiscoveryClient, error)

DialDiscoveryAddresses connects to discovery endpoints.

func (*DiscoveryClient) Close

func (d *DiscoveryClient) Close() error

func (*DiscoveryClient) PublishMsgWithContext

func (d *DiscoveryClient) PublishMsgWithContext(req *pool.Message, discoveryHandler DiscoveryHandler) error

type DiscoveryConfiguration

type DiscoveryConfiguration struct {
	MulticastHopLimit    int      // default: 2, min value: 1 - don't pass through router, max value: 255, https://tools.ietf.org/html/rfc2460#section-3
	MulticastAddressUDP4 []string // default: "[224.0.1.187:5683] (client.DiscoveryAddressUDP4), empty: don't use ipv4 multicast"
	MulticastAddressUDP6 []string // default: "[ff02::158]:5683", "[ff03::158]:5683", "[ff05::158]:5683]"] (client.DiscoveryAddressUDP6), empty: don't use ipv6 multicast"
	MulticastOptions     []coapNet.MulticastOption
}

DiscoveryConfiguration setup discovery configuration

func DefaultDiscoveryConfiguration

func DefaultDiscoveryConfiguration() DiscoveryConfiguration

type DiscoveryHandler

type DiscoveryHandler = func(conn *client.ClientConn, req *pool.Message)

type ErrFunc

type ErrFunc = func(err error)

ErrFunc to log errors in goroutines

type GetCertificateAuthoritiesFunc

type GetCertificateAuthoritiesFunc func() ([]*x509.Certificate, error)

GetCertificateAuthoritiesFunc returns certificate authorities to verify peers

type GetCertificateFunc

type GetCertificateFunc func() (tls.Certificate, error)

GetCertificateFunc returns certificate for connection

type ObservationHandler

type ObservationHandler interface {
	Handle(ctx context.Context, body coap.DecodeFunc)
	OnClose()
	Error(err error)
}

type OptionFunc

type OptionFunc func(config) config

func WithDialDTLS

func WithDialDTLS(dial DialDTLS) OptionFunc

func WithDialTCP

func WithDialTCP(dial DialTCP) OptionFunc

func WithDialTLS

func WithDialTLS(dial DialTLS) OptionFunc

func WithDialUDP

func WithDialUDP(dial DialUDP) OptionFunc

func WithErr

func WithErr(errFunc ErrFunc) OptionFunc

func WithTLS

func WithTLS(tlsConfig *TLSConfig) OptionFunc

type OwnOption

type OwnOption = func(ownCfg) ownCfg

func WithActionAfterOwn added in v1.2.0

func WithActionAfterOwn(actionAfterOwn ActionAfterOwnFunc) OwnOption

WithActionAfterOwn allows initialize configuration at the device via DTLS connection with preshared key. For example setup time / NTP. if it returns error device will be disowned.

func WithActionDuringOwn

func WithActionDuringOwn(actionDuringOwn ActionDuringOwnFunc) OwnOption

WithActionDuringOwn allows to set deviceID of owned device and other staff over owner TLS. returns new deviceID, if it returns error device will be disowned.

func WithPresharedKey added in v1.2.0

func WithPresharedKey(psk []byte) OwnOption

WithPresharedKey allows to set preshared key for owner. It is not set, it will be randomized.

func WithSetupCertificates added in v1.2.0

func WithSetupCertificates(sign otm.SignFunc) OwnOption

WithSetupCertificates signs identity ceriticates and install root ca.

type OwnershipHandler

type OwnershipHandler interface {
	// Handle gets a device ownership.
	Handle(ctx context.Context, doxm doxm.Doxm)
	// Error gets errors during discovery.
	Error(err error)
}

OwnershipHandler conveys device ownership and errors during discovery.

type ProvisioningClient

type ProvisioningClient struct {
	*Device
	// contains filtered or unexported fields
}

func (*ProvisioningClient) AddCertificateAuthority

func (c *ProvisioningClient) AddCertificateAuthority(ctx context.Context, subject string, cert *x509.Certificate) error

func (*ProvisioningClient) AddCredentials

func (*ProvisioningClient) Close

func (c *ProvisioningClient) Close(ctx context.Context) error

func (*ProvisioningClient) SetAccessControl

func (c *ProvisioningClient) SetAccessControl(
	ctx context.Context,
	permission acl.Permission,
	subject acl.Subject,
	resources ...acl.Resource,
) error

Usage: SetAccessControl(ctx, schema.AllPermissions, schema.TLSConnection, schema.AllResources)

func (*ProvisioningClient) SetCloudResource

type ResourceIterator

type ResourceIterator struct {
	Err error
	// contains filtered or unexported fields
}

ResourceIterator queries resource values.

func (*ResourceIterator) Next

func (it *ResourceIterator) Next(ctx context.Context, v interface{}) bool

Next queries the next resource value. Returns false when failed or having no more items. Check it.Err for errors. Usage:

for {
	var v MyStruct
	if !it.Next(ctx, &v) {
		break
	}
}
if it.Err != nil {
}

type SdkError

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

func (SdkError) Error

func (e SdkError) Error() string

func (SdkError) GetCode

func (e SdkError) GetCode() codes.Code

func (SdkError) Unwrap

func (e SdkError) Unwrap() error

type TLSConfig

type TLSConfig struct {
	// User for communication with owned devices and cloud
	GetCertificate            GetCertificateFunc
	GetCertificateAuthorities GetCertificateAuthoritiesFunc
}

Directories

Path Synopsis
otm

Jump to

Keyboard shortcuts

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