local

package
v0.0.0-...-d974290 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSDKIdentityCertificate

func GenerateSDKIdentityCertificate(ctx context.Context, signer core.CertificateSigner, sdkDeviceID string) (tls.Certificate, error)

func NewDeviceOwnershipBackendFromConfig

func NewDeviceOwnershipBackendFromConfig(app ApplicationCallback, cfg *DeviceOwnershipBackendConfig, disableDTLS bool, errorsFunc func(err error)) (*deviceOwnershipBackend, error)

func NewDeviceOwnershipNone

func NewDeviceOwnershipNone() *deviceOwnershipNone

func NewDeviceOwnershipSDK

func NewDeviceOwnershipSDK(app ApplicationCallback, sdkDeviceID string, signerCert *tls.Certificate, certExpiry time.Duration, disableDTLS bool) (*deviceOwnershipSDK, error)

func NewDeviceOwnershipSDKFromConfig

func NewDeviceOwnershipSDKFromConfig(app ApplicationCallback, cfg *DeviceOwnershipSDKConfig, disableDTLS bool) (*deviceOwnershipSDK, error)

func NewRefDeviceCache

func NewRefDeviceCache(cacheExpiration time.Duration, errors func(error)) *refDeviceCache

Types

type ApplicationCallback

type ApplicationCallback = interface {
	GetRootCertificateAuthorities() ([]*x509.Certificate, error)
	GetManufacturerCertificateAuthorities() ([]*x509.Certificate, error)
	GetManufacturerCertificate() (tls.Certificate, error)
}

type Client

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

Client uses the underlying OCF local client.

func NewClient

func NewClient(
	app ApplicationCallback,
	deviceOwner DeviceOwner,
	cacheExpiration time.Duration,
	observerPollingInterval time.Duration,
	disableUDPEndpoints bool,
	errors func(error),
	opt ...core.OptionFunc,
) (*Client, error)

NewClient constructs a new local client.

func NewClientFromConfig

func NewClientFromConfig(cfg *Config, app ApplicationCallback, errors func(error)) (*Client, error)

NewClientFromConfig constructs a new local client from the proto configuration.

func (*Client) Close

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

Close clears all connections and spawned goroutines by client.

func (*Client) CoreClient

func (c *Client) CoreClient() *core.Client

func (*Client) DisownDevice

func (c *Client) DisownDevice(ctx context.Context, deviceID string) error

DisownDevice disowns a device. For unsecure device it calls factory reset. For secure device it disowns.

func (*Client) FactoryReset

func (c *Client) FactoryReset(ctx context.Context, deviceID string) error

func (*Client) GetAccessTokenURL

func (c *Client) GetAccessTokenURL(ctx context.Context) (string, error)

GetAccessTokenURL returns access token url.

func (*Client) GetDevice

func (c *Client) GetDevice(ctx context.Context, deviceID string, opts ...GetDeviceOption) (DeviceDetails, error)

func (*Client) GetDevices

func (c *Client) GetDevices(
	ctx context.Context,
	opts ...GetDevicesOption,
) (map[string]DeviceDetails, error)

GetDevices discovers devices in the local mode. The deviceResourceType is applied on the client side, because len(deviceResourceType) > 1 does not work with Iotivity 1.3.

func (*Client) GetDevicesWithHandler

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

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

func (*Client) GetIdentityCertificate

func (c *Client) GetIdentityCertificate() (tls.Certificate, error)

GetIdentityCertificate returns certificate for connection

func (*Client) GetOnboardAuthorizationCodeURL

func (c *Client) GetOnboardAuthorizationCodeURL(ctx context.Context, deviceID string) (string, error)

GetOnboardAuthorizationCodeURL returns access auth code url.

func (*Client) GetRefDevice

func (c *Client) GetRefDevice(
	ctx context.Context,
	deviceID string,
) (*RefDevice, schema.ResourceLinks, error)

GetRefDevice returns device, after using call device.Release to free resources.

func (*Client) GetResource

func (c *Client) GetResource(
	ctx context.Context,
	deviceID string,
	href string,
	response interface{},
	opts ...GetOption,
) error

func (*Client) Initialization

func (c *Client) Initialization(ctx context.Context) (err error)

func (*Client) ObserveDeviceResources

func (c *Client) ObserveDeviceResources(ctx context.Context, deviceID string, handler DeviceResourcesObservationHandler) (string, error)

func (*Client) ObserveDevices

func (c *Client) ObserveDevices(ctx context.Context, handler DevicesObservationHandler) (string, error)

func (*Client) ObserveResource

func (c *Client) ObserveResource(
	ctx context.Context,
	deviceID string,
	href string,
	handler core.ObservationHandler,
	opts ...ObserveOption,
) (observationID string, _ error)

func (*Client) OffboardDevice

func (c *Client) OffboardDevice(ctx context.Context, deviceID string) error

OffboardDevice is not supported by OCF spec(https://openconnectivity.org/specs/OCF_Device_To_Cloud_Services_Specification_v2.2.0.pdf)

func (*Client) OnboardDevice

func (c *Client) OnboardDevice(
	ctx context.Context,
	deviceID, authorizationProvider, cloudURL, authCode, cloudID string,
) error

func (*Client) OwnDevice

func (c *Client) OwnDevice(ctx context.Context, deviceID string, opts ...OwnOption) error

func (*Client) PatchResourceLinksEndpoints

func (c *Client) PatchResourceLinksEndpoints(links schema.ResourceLinks) schema.ResourceLinks

func (*Client) Reboot

func (c *Client) Reboot(ctx context.Context, deviceID string) error

func (*Client) StopObservingDeviceResources

func (c *Client) StopObservingDeviceResources(ctx context.Context, observationID string) error

func (*Client) StopObservingDevices

func (c *Client) StopObservingDevices(ctx context.Context, observationID string) error

func (*Client) StopObservingResource

func (c *Client) StopObservingResource(ctx context.Context, observationID string) error

func (*Client) UpdateResource

func (c *Client) UpdateResource(
	ctx context.Context,
	deviceID string,
	href string,
	request interface{},
	response interface{},
	opts ...UpdateOption,
) error

type CodecOption

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

func WithCodec

func WithCodec(codec kitNetCoap.Codec) CodecOption

type Config

type Config struct {
	DeviceCacheExpirationSeconds      int64
	KeepAliveConnectionTimeoutSeconds uint64 // 0 means keepalive is disabled
	ObserverPollingIntervalSeconds    uint64 // 0 means 3 seconds
	DisableDTLS                       bool
	DisablePeerTCPSignalMessageCSMs   bool
	DisableUDPEndpoints               bool
	MaxMessageSize                    int

	// specify one of:
	DeviceOwnershipSDK     *DeviceOwnershipSDKConfig     `yaml:",omitempty"`
	DeviceOwnershipBackend *DeviceOwnershipBackendConfig `yaml:",omitempty"`
}

type DeviceDetails

type DeviceDetails struct {
	// ID of the device
	ID string
	// Device basic content(oic.wk.d) of /oic/d resource.
	Device schema.Device
	// Details result of function which can be set via option WithGetDetails(), by default it is nil.
	Details interface{}
	// IsSecured is secured.
	IsSecured bool
	// Ownership describes ownership of the device, for unsecure device it is nil.
	Ownership *schema.Doxm
	// Resources list of the device resources.
	Resources []schema.ResourceLink
	// Resources list of the device endpoints.
	Endpoints []schema.Endpoint
}

DeviceDetails describes a device.

type DeviceOwner

type DeviceOwner interface {
	Initialization(ctx context.Context) error
	OwnDevice(ctx context.Context, deviceID string, own ownFunc, opts ...core.OwnOption) error

	GetAccessTokenURL(ctx context.Context) (string, error)
	GetOnboardAuthorizationCodeURL(ctx context.Context, deviceID string) (string, error)
	GetIdentityCertificate() (tls.Certificate, error)
	Close(ctx context.Context) error
}

func NewDeviceOwnerFromConfig

func NewDeviceOwnerFromConfig(cfg *Config, app ApplicationCallback, errors func(error)) (DeviceOwner, error)

type DeviceOwnershipBackendConfig

type DeviceOwnershipBackendConfig struct {
	SigningServerAddress string
	AuthCodeURL          string
	AccessTokenURL       string
	JWTClaimOwnerID      string
}

type DeviceOwnershipSDKConfig

type DeviceOwnershipSDKConfig struct {
	ID         string
	Cert       []byte
	CertKey    []byte
	CertExpiry *string
}

type DeviceResourcesObservationEvent

type DeviceResourcesObservationEvent struct {
	Link  schema.ResourceLink
	Event DeviceResourcesObservationEvent_type
}

type DeviceResourcesObservationEvent_type

type DeviceResourcesObservationEvent_type uint8
const DeviceResourcesObservationEvent_ADDED DeviceResourcesObservationEvent_type = 0
const DeviceResourcesObservationEvent_REMOVED DeviceResourcesObservationEvent_type = 1

type DeviceResourcesObservationHandler

type DeviceResourcesObservationHandler = interface {
	Handle(ctx context.Context, event DeviceResourcesObservationEvent) error
	OnClose()
	Error(err error)
}

type DevicesObservationEvent

type DevicesObservationEvent struct {
	DeviceID string
	Event    DevicesObservationEvent_type
}

type DevicesObservationEvent_type

type DevicesObservationEvent_type uint8
const DevicesObservationEvent_OFFLINE DevicesObservationEvent_type = 1
const DevicesObservationEvent_ONLINE DevicesObservationEvent_type = 0

type DevicesObservationHandler

type DevicesObservationHandler = interface {
	Handle(ctx context.Context, event DevicesObservationEvent) error
	OnClose()
	Error(err error)
}

type ErrorOption

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

func WithError

func WithError(err func(error)) ErrorOption

type GetDetailsFunc

type GetDetailsFunc = func(context.Context, *core.Device, schema.ResourceLinks) (interface{}, error)

type GetDetailsOption

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

func WithGetDetails

func WithGetDetails(getDetails func(ctx context.Context, d *core.Device, links schema.ResourceLinks) (interface{}, error)) GetDetailsOption

type GetDeviceOption

type GetDeviceOption = interface {
	// contains filtered or unexported methods
}

GetDeviceOption option definition.

type GetDevicesOption

type GetDevicesOption = interface {
	// contains filtered or unexported methods
}

GetDevicesOption option definition.

type GetOption

type GetOption = interface {
	// contains filtered or unexported methods
}

GetOption option definition.

type IotivityHackOption

type IotivityHackOption struct{}

func WithIotivityHack

func WithIotivityHack() IotivityHackOption

WithIotivityHack set this option when device with iotivity 2.0 will be onboarded.

type ObserveOption

type ObserveOption = interface {
	// contains filtered or unexported methods
}

ObserveOption option definition.

type OwnOption

type OwnOption = interface {
	// contains filtered or unexported methods
}

OwnOption option definition.

type RefDevice

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

func NewRefDevice

func NewRefDevice(dev *core.Device) *RefDevice

func (*RefDevice) Acquire

func (d *RefDevice) Acquire()

func (*RefDevice) Device

func (d *RefDevice) Device() *core.Device

func (*RefDevice) DeviceID

func (d *RefDevice) DeviceID() string

func (*RefDevice) Disown

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

func (*RefDevice) FactoryReset

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

func (*RefDevice) GetDeviceDetails

func (d *RefDevice) GetDeviceDetails(ctx context.Context, links schema.ResourceLinks, getDetails GetDetailsFunc) (out DeviceDetails, _ error)

func (*RefDevice) GetEndpoints

func (d *RefDevice) GetEndpoints(ctx context.Context) ([]schema.Endpoint, error)

func (*RefDevice) GetOwnership

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

func (*RefDevice) GetResourceWithCodec

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

func (*RefDevice) IsSecured

func (d *RefDevice) IsSecured(ctx context.Context, links schema.ResourceLinks) (bool, error)

func (*RefDevice) ObserveResource

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

func (*RefDevice) ObserveResourceWithCodec

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

func (*RefDevice) Own

func (d *RefDevice) Own(
	ctx context.Context,
	links schema.ResourceLinks,
	otmClient core.OTMClient,
	ownOptions ...core.OwnOption,
) error

func (*RefDevice) Provision

func (*RefDevice) Reboot

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

func (*RefDevice) Release

func (d *RefDevice) Release(ctx context.Context) error

func (*RefDevice) StopObservingResource

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

func (*RefDevice) UpdateResource

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

func (*RefDevice) UpdateResourceWithCodec

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

type ResourceInterfaceOption

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

func WithInterface

func WithInterface(resourceInterface string) ResourceInterfaceOption

WithInterface updates/gets resource with interface directly from a device.

type ResourceTypesOption

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

func WithResourceTypes

func WithResourceTypes(resourceTypes ...string) ResourceTypesOption

type UpdateOption

type UpdateOption = interface {
	// contains filtered or unexported methods
}

UpdateOption option definition.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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