Documentation
¶
Index ¶
- Constants
- Variables
- func Discover(ctx context.Context, conn []*DiscoveryClient, href string, ...) error
- func DiscoverDeviceOwnership(ctx context.Context, conn []*DiscoveryClient, status DiscoverOwnershipStatus, ...) error
- func DiscoverDevices(ctx context.Context, conn []*DiscoveryClient, handler DiscoverDevicesHandler, ...) error
- func GetResourceLink(links schema.ResourceLinks, href string) (schema.ResourceLink, error)
- func MakeAborted(e error) error
- func MakeAlreadyExists(e error) error
- func MakeCanceled(e error) error
- func MakeDataLoss(e error) error
- func MakeDeadlineExceeded(e error) error
- func MakeFailedPrecondition(e error) error
- func MakeInternal(e error) error
- func MakeInternalStr(str string, e error) error
- func MakeInvalidArgument(e error) error
- func MakeNotFound(e error) error
- func MakeOutOfRange(e error) error
- func MakePermissionDenied(e error) error
- func MakeResourceExhausted(e error) error
- func MakeSdkError(code codes.Code, err error) error
- func MakeUnauthenticated(e error) error
- func MakeUnavailable(e error) error
- func MakeUnimplemented(e error) error
- func MakeUnknown(e error) error
- type ActionDuringOwnFunc
- type CertificateSigner
- type Client
- func (c *Client) GetDeviceByIP(ctx context.Context, ip string) (*Device, error)
- func (c *Client) GetDeviceByMulticast(ctx context.Context, deviceID string, ...) (*Device, error)
- func (c *Client) GetDevices(ctx context.Context, handler DeviceHandler) error
- func (c *Client) GetDevicesV2(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, ...) error
- func (c *Client) GetOwnerships(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, ...) error
- func (c *Client) GetSdkOwnerID() (string, error)
- type Device
- func (d *Device) Close(ctx context.Context) error
- func (d *Device) DeleteResource(ctx context.Context, link schema.ResourceLink, response interface{}, ...) error
- func (d *Device) DeleteResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, ...) error
- func (d *Device) DeviceID() string
- func (d *Device) DeviceTypes() []string
- func (d *Device) Disown(ctx context.Context, links schema.ResourceLinks) error
- func (d *Device) FactoryReset(ctx context.Context, links schema.ResourceLinks) error
- func (d *Device) GetEndpoints() schema.Endpoints
- func (d *Device) GetOwnership(ctx context.Context, links schema.ResourceLinks) (schema.Doxm, error)
- func (d *Device) GetResource(ctx context.Context, link schema.ResourceLink, response interface{}, ...) error
- func (d *Device) GetResourceLinks(ctx context.Context, endpoints []schema.Endpoint, options ...coap.OptionFunc) (schema.ResourceLinks, error)
- func (d *Device) GetResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec coap.Codec, ...) error
- func (d *Device) GetResources(ctx context.Context, links schema.ResourceLinks) *ResourceIterator
- func (d *Device) GetSdkOwnerID() (string, error)
- func (d *Device) IsSecured() bool
- func (d *Device) ObserveResource(ctx context.Context, link schema.ResourceLink, handler ObservationHandler, ...) (observationID string, _ error)
- func (d *Device) ObserveResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, ...) (observationID string, _ error)
- func (d *Device) Own(ctx context.Context, links schema.ResourceLinks, otmClient OTMClient, ...) error
- func (d *Device) Provision(ctx context.Context, links schema.ResourceLinks) (*ProvisioningClient, error)
- func (d *Device) Reboot(ctx context.Context, links schema.ResourceLinks) error
- func (d *Device) StopObservingResource(ctx context.Context, observationID string) error
- func (d *Device) UpdateResource(ctx context.Context, link schema.ResourceLink, request interface{}, ...) error
- func (d *Device) UpdateResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, ...) error
- type DeviceHandler
- type DeviceHandlerV2
- type DialDTLS
- type DialTCP
- type DialTLS
- type DialUDP
- type DiscoverDeviceCodec
- type DiscoverDeviceOwnershipHandler
- type DiscoverDevicesHandler
- type DiscoverOwnershipStatus
- type DiscoveryClient
- type DiscoveryConfiguration
- type DiscoveryHandler
- type ErrFunc
- type GetCertificateAuthoritiesFunc
- type GetCertificateFunc
- type OTMClient
- type ObservationHandler
- type OptionFunc
- type OwnOption
- type OwnershipHandler
- type ProvisioningClient
- func (c *ProvisioningClient) AddCertificateAuthority(ctx context.Context, subject string, cert *x509.Certificate) error
- func (c *ProvisioningClient) AddCredentials(ctx context.Context, credential schema.CredentialUpdateRequest) error
- func (c *ProvisioningClient) Close(ctx context.Context) error
- func (c *ProvisioningClient) SetAccessControl(ctx context.Context, permission acl.Permission, subject acl.Subject, ...) error
- func (c *ProvisioningClient) SetCloudResource(ctx context.Context, r cloud.ConfigurationUpdateRequest) error
- type ResourceIterator
- type SdkError
- type TLSConfig
Constants ¶
const ( // DiscoverAllDevices discovers owned and disowned devices. DiscoverAllDevices = DiscoverOwnershipStatus(0) // DiscoverOwnedDevices discovers owned devices, DiscoverOwnedDevices = DiscoverOwnershipStatus(1) // DiscoverDisownedDevices discovers disowned devices, DiscoverDisownedDevices = DiscoverOwnershipStatus(2) )
const ANY_DEVICE = "anydevice"
Variables ¶
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 ...kitNetCoap.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 ¶
func GetResourceLink(links schema.ResourceLinks, href string) (schema.ResourceLink, error)
func MakeAborted ¶
func MakeAlreadyExists ¶
func MakeCanceled ¶
func MakeDataLoss ¶
func MakeDeadlineExceeded ¶
func MakeFailedPrecondition ¶
func MakeInternal ¶
func MakeInternalStr ¶
func MakeInvalidArgument ¶
func MakeNotFound ¶
func MakeOutOfRange ¶
func MakePermissionDenied ¶
func MakeResourceExhausted ¶
func MakeUnauthenticated ¶
func MakeUnavailable ¶
func MakeUnimplemented ¶
func MakeUnknown ¶
Types ¶
type ActionDuringOwnFunc ¶
type ActionDuringOwnFunc = func(ctx context.Context, client *kitNetCoap.ClientCloseHandler) (string, error)
type CertificateSigner ¶
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 (*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 ¶
GetSdkOwnerID returns sdk ownerID from sdk identity certificate.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func (*Device) DeleteResource ¶
func (d *Device) DeleteResource( ctx context.Context, link schema.ResourceLink, response interface{}, options ...kitNetCoap.OptionFunc, ) error
func (*Device) DeleteResourceWithCodec ¶
func (d *Device) DeleteResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, response interface{}, options ...kitNetCoap.OptionFunc, ) error
func (*Device) DeviceTypes ¶
func (*Device) FactoryReset ¶
func (*Device) GetEndpoints ¶
func (*Device) GetOwnership ¶
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 (*Device) GetResourceLinks ¶
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 ¶
GetSdkOwnerID returns sdk ownerID from sdk identity certificate.
func (*Device) ObserveResource ¶
func (d *Device) ObserveResource( ctx context.Context, link schema.ResourceLink, handler ObservationHandler, options ...kitNetCoap.OptionFunc, ) (observationID string, _ error)
func (*Device) ObserveResourceWithCodec ¶
func (d *Device) ObserveResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, handler ObservationHandler, options ...kitNetCoap.OptionFunc, ) (observationID string, _ error)
func (*Device) Own ¶
func (d *Device) Own( ctx context.Context, links schema.ResourceLinks, otmClient OTMClient, options ...OwnOption, ) error
Own set ownership of device
func (*Device) Provision ¶
func (d *Device) Provision(ctx context.Context, links schema.ResourceLinks) (*ProvisioningClient, error)
func (*Device) StopObservingResource ¶
func (*Device) UpdateResource ¶
func (d *Device) UpdateResource( ctx context.Context, link schema.ResourceLink, request interface{}, response interface{}, options ...kitNetCoap.OptionFunc, ) error
func (*Device) UpdateResourceWithCodec ¶
func (d *Device) UpdateResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec kitNetCoap.Codec, request interface{}, response interface{}, options ...kitNetCoap.OptionFunc, ) 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 ...kitNetCoap.DialOptionFunc) (*coap.ClientCloseHandler, error)
type DialTCP ¶
type DialTCP = func(ctx context.Context, addr string, opts ...kitNetCoap.DialOptionFunc) (*coap.ClientCloseHandler, error)
type DialTLS ¶
type DialTLS = func(ctx context.Context, addr string, tlsCfg *tls.Config, opts ...kitNetCoap.DialOptionFunc) (*coap.ClientCloseHandler, error)
type DialUDP ¶
type DialUDP = func(ctx context.Context, addr string, opts ...kitNetCoap.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 schema.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] (local.DiscoveryAddressUDP4), empty: don't use ipv4 multicast" MulticastAddressUDP6 []string // default: "[ff02::158]:5683", "[ff03::158]:5683", "[ff05::158]:5683]"] (local.DiscoveryAddressUDP6), empty: don't use ipv6 multicast" MulticastOptions []udp.MulticastOption }
DiscoveryConfiguration setup discovery configuration
func DefaultDiscoveryConfiguration ¶
func DefaultDiscoveryConfiguration() DiscoveryConfiguration
type DiscoveryHandler ¶
type DiscoveryHandler = func(conn *client.ClientConn, req *pool.Message)
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 OTMClient ¶
type OTMClient interface { Type() schema.OwnerTransferMethod Dial(ctx context.Context, addr kitNet.Addr, opts ...kitNetCoap.DialOptionFunc) (*kitNetCoap.ClientCloseHandler, error) ProvisionOwnerCredentials(ctx context.Context, client *kitNetCoap.ClientCloseHandler, ownerID, deviceID, psk string) error }
type ObservationHandler ¶
type ObservationHandler interface { Handle(ctx context.Context, body kitNetCoap.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 WithActionDuringOwn ¶
func WithActionDuringOwn(actionDuringOwn ActionDuringOwnFunc) OwnOption
WithActionDuringOwn allows to set deviceID of owned device and other staff over owner TLS. returns new deviceID
type OwnershipHandler ¶
type OwnershipHandler interface { // Handle gets a device ownership. Handle(ctx context.Context, doxm schema.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 (c *ProvisioningClient) AddCredentials(ctx context.Context, credential schema.CredentialUpdateRequest) 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 ¶
func (c *ProvisioningClient) SetCloudResource(ctx context.Context, r cloud.ConfigurationUpdateRequest) error
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 TLSConfig ¶
type TLSConfig struct { // User for communication with owned devices and cloud GetCertificate GetCertificateFunc GetCertificateAuthorities GetCertificateAuthoritiesFunc }
Source Files
¶
- certificateSigner.go
- client.go
- deleteResource.go
- device.go
- discover.go
- discoverDeviceCodec.go
- discoverDeviceOwnership.go
- discoverDevices.go
- disownDevice.go
- getDevice.go
- getDevices.go
- getEndpoints.go
- getOwnership.go
- getOwnerships.go
- getResource.go
- getResourceLinks.go
- getSdkOwnerID.go
- isSecured.go
- maintenance.go
- observeResource.go
- ownDevice.go
- provisionDevice.go
- sdkError.go
- updateResource.go