From 583a471c0615c103d80f10d6d03d7f87e3cce2b7 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 24 Dec 2024 13:21:01 +0100 Subject: [PATCH] Update register remote service API Change `RegisterRemoteSKI` api call with a 2nd argument to provide the SHIP-ID if known. If provided (as a non empty string), upon SHIP handshake it will check the reported SHIP-ID from the remote service, and if it differs, will close the connection. The SHIP-ID is also made available via mDNS, and therefor should be known at all times. Requires https://github.com/enbility/ship-go/pull/46 --- api/api.go | 15 ++++++++++++--- examples/ced/main.go | 2 +- examples/controlbox/main.go | 2 +- examples/evse/main.go | 2 +- examples/heatpump/main.go | 2 +- examples/hems/main.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- mocks/DeviceConfigurationClientInterface.go | 16 ++++++++-------- mocks/DeviceConfigurationCommonInterface.go | 16 ++++++++-------- mocks/DeviceConfigurationServerInterface.go | 16 ++++++++-------- mocks/ElectricalConnectionCommonInterface.go | 16 ++++++++-------- mocks/ElectricalConnectionServerInterface.go | 16 ++++++++-------- mocks/IdentificationCommonInterface.go | 14 +++++++------- mocks/LoadControlCommonInterface.go | 16 ++++++++-------- mocks/MeasurementCommonInterface.go | 16 ++++++++-------- mocks/ServiceInterface.go | 19 ++++++++++--------- service/service.go | 16 ++++++++++++---- service/service_hub.go | 2 +- service/service_test.go | 4 ++-- 20 files changed, 108 insertions(+), 90 deletions(-) diff --git a/api/api.go b/api/api.go index c9647f7b..31f868f3 100644 --- a/api/api.go +++ b/api/api.go @@ -62,8 +62,17 @@ type ServiceInterface interface { // Returns the Service detail of a remote SKI RemoteServiceForSKI(ski string) *shipapi.ServiceDetails - // Sets the SKI as being paired - RegisterRemoteSKI(ski string) + // Pair a remote service based on the SKI + // + // Parameters: + // - ski: the SKI of the remote service (required) + // - shipID: the SHIP ID of the remote service (optional) + // + // Note: The SHIP ID is optional, but should be provided if available. + // if provided, it will be used to validate the remote service is + // providing this SHIP ID during the handshake process and will reject + // the connection if it does not match. + RegisterRemoteSKI(ski, shipID string) // Sets the SKI as not being paired UnregisterRemoteSKI(ski string) @@ -105,7 +114,7 @@ type ServiceReaderInterface interface { // Provides the SHIP ID the remote service reported during the handshake process // This needs to be persisted and passed on for future remote service connections - // when using `PairRemoteService` + // when using `RegisterRemoteSKI` ServiceShipIDUpdate(ski string, shipdID string) // Provides the current pairing state for the remote service diff --git a/examples/ced/main.go b/examples/ced/main.go index 978b3271..718368b1 100644 --- a/examples/ced/main.go +++ b/examples/ced/main.go @@ -110,7 +110,7 @@ func (h *controlbox) run() { os.Exit(0) } - h.myService.RegisterRemoteSKI(remoteSki) + h.myService.RegisterRemoteSKI(remoteSki, "") h.myService.Start() // defer h.myService.Shutdown() diff --git a/examples/controlbox/main.go b/examples/controlbox/main.go index 9965915d..28c395cc 100644 --- a/examples/controlbox/main.go +++ b/examples/controlbox/main.go @@ -104,7 +104,7 @@ func (h *controlbox) run() { os.Exit(0) } - h.myService.RegisterRemoteSKI(remoteSki) + h.myService.RegisterRemoteSKI(remoteSki, "") h.myService.Start() // defer h.myService.Shutdown() diff --git a/examples/evse/main.go b/examples/evse/main.go index 8dc17592..26256724 100644 --- a/examples/evse/main.go +++ b/examples/evse/main.go @@ -108,7 +108,7 @@ func (h *evse) run() { os.Exit(0) } - h.myService.RegisterRemoteSKI(remoteSki) + h.myService.RegisterRemoteSKI(remoteSki, "") h.myService.Start() // defer h.myService.Shutdown() diff --git a/examples/heatpump/main.go b/examples/heatpump/main.go index 59ebf660..962ea2a5 100644 --- a/examples/heatpump/main.go +++ b/examples/heatpump/main.go @@ -94,7 +94,7 @@ func (h *heatpump) run() { h.AddFeatures() _ = spine.Events.Subscribe(h) - h.myService.RegisterRemoteSKI(remoteSki) + h.myService.RegisterRemoteSKI(remoteSki, "") h.myService.Start() // defer h.myService.Shutdown() diff --git a/examples/hems/main.go b/examples/hems/main.go index 4c6e2a4f..b645f848 100644 --- a/examples/hems/main.go +++ b/examples/hems/main.go @@ -139,7 +139,7 @@ func (h *hems) run() { os.Exit(0) } - h.myService.RegisterRemoteSKI(remoteSki) + h.myService.RegisterRemoteSKI(remoteSki, "") h.myService.Start() // defer h.myService.Shutdown() diff --git a/go.mod b/go.mod index 03d7f085..802ddd9c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/enbility/eebus-go go 1.22.0 require ( - github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0 + github.com/enbility/ship-go v0.0.0-20241224121428-45edf34c56e4 github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7 github.com/stretchr/testify v1.9.0 golang.org/x/exp/jsonrpc2 v0.0.0-20240909161429-701f63a606c0 diff --git a/go.sum b/go.sum index 6d1f5822..dd14089c 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/enbility/go-avahi v0.0.0-20240909195612-d5de6b280d7a h1:foChWb8lhzqa6lWDRs6COYMdp649YlUirFP8GqoT0JQ= github.com/enbility/go-avahi v0.0.0-20240909195612-d5de6b280d7a/go.mod h1:H64mhYcAQUGUUnVqMdZQf93kPecH4M79xwH95Lddt3U= -github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0 h1:Z8j/N4DgUL8T8mINkHdq0bUbKcWtwDpno0bsKOGahPo= -github.com/enbility/ship-go v0.0.0-20241118145930-d68708c5f1c0/go.mod h1:JJp8EQcJhUhTpZ2LSEU4rpdaM3E2n08tswWFWtmm/wU= +github.com/enbility/ship-go v0.0.0-20241224121428-45edf34c56e4 h1:FYVDfqWdEv/ua+NGw+9Eynt6JPt1X0HPQaOI5QysaZY= +github.com/enbility/ship-go v0.0.0-20241224121428-45edf34c56e4/go.mod h1:JJp8EQcJhUhTpZ2LSEU4rpdaM3E2n08tswWFWtmm/wU= github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7 h1:Pq1L3U/aoSg8qQj4CfSEUCh9fxgB3G/skUNQI32zQeg= github.com/enbility/spine-go v0.0.0-20241209160856-1aed917e83e7/go.mod h1:ZoI9TaJO/So/677uknrli8sc6iryD7wC5iWhVIre+MI= github.com/enbility/zeroconf/v2 v2.0.0-20240920094356-be1cae74fda6 h1:XOYvxKtT1oxT37w/5oEiRLuPbm9FuJPt3fiYhX0h8Po= diff --git a/mocks/DeviceConfigurationClientInterface.go b/mocks/DeviceConfigurationClientInterface.go index a55ed0f3..6374f9a3 100644 --- a/mocks/DeviceConfigurationClientInterface.go +++ b/mocks/DeviceConfigurationClientInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -21,7 +21,7 @@ func (_m *DeviceConfigurationClientInterface) EXPECT() *DeviceConfigurationClien } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *DeviceConfigurationClientInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *DeviceConfigurationClientInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -29,7 +29,7 @@ func (_m *DeviceConfigurationClientInterface) CheckEventPayloadDataForFilter(pay } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -44,15 +44,15 @@ type DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call stru } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *DeviceConfigurationClientInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { return &DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -62,7 +62,7 @@ func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call return _c } -func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/DeviceConfigurationCommonInterface.go b/mocks/DeviceConfigurationCommonInterface.go index e10b3e7a..181919f0 100644 --- a/mocks/DeviceConfigurationCommonInterface.go +++ b/mocks/DeviceConfigurationCommonInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -21,7 +21,7 @@ func (_m *DeviceConfigurationCommonInterface) EXPECT() *DeviceConfigurationCommo } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *DeviceConfigurationCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *DeviceConfigurationCommonInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -29,7 +29,7 @@ func (_m *DeviceConfigurationCommonInterface) CheckEventPayloadDataForFilter(pay } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -44,15 +44,15 @@ type DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call stru } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *DeviceConfigurationCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { return &DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -62,7 +62,7 @@ func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call return _c } -func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/DeviceConfigurationServerInterface.go b/mocks/DeviceConfigurationServerInterface.go index ad7a0972..06b26c16 100644 --- a/mocks/DeviceConfigurationServerInterface.go +++ b/mocks/DeviceConfigurationServerInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -69,7 +69,7 @@ func (_c *DeviceConfigurationServerInterface_AddKeyValueDescription_Call) RunAnd } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *DeviceConfigurationServerInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *DeviceConfigurationServerInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -77,7 +77,7 @@ func (_m *DeviceConfigurationServerInterface) CheckEventPayloadDataForFilter(pay } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -92,15 +92,15 @@ type DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call stru } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *DeviceConfigurationServerInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { return &DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -110,7 +110,7 @@ func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call return _c } -func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { +func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ElectricalConnectionCommonInterface.go b/mocks/ElectricalConnectionCommonInterface.go index 6fb44028..c1acb9cb 100644 --- a/mocks/ElectricalConnectionCommonInterface.go +++ b/mocks/ElectricalConnectionCommonInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -68,7 +68,7 @@ func (_c *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValu } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *ElectricalConnectionCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *ElectricalConnectionCommonInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -76,7 +76,7 @@ func (_m *ElectricalConnectionCommonInterface) CheckEventPayloadDataForFilter(pa } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -91,15 +91,15 @@ type ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call str } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *ElectricalConnectionCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { return &ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -109,7 +109,7 @@ func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Cal return _c } -func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ElectricalConnectionServerInterface.go b/mocks/ElectricalConnectionServerInterface.go index 54f21735..5ec2bed3 100644 --- a/mocks/ElectricalConnectionServerInterface.go +++ b/mocks/ElectricalConnectionServerInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.45.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -222,7 +222,7 @@ func (_c *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValu } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *ElectricalConnectionServerInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *ElectricalConnectionServerInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -230,7 +230,7 @@ func (_m *ElectricalConnectionServerInterface) CheckEventPayloadDataForFilter(pa } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -245,15 +245,15 @@ type ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call str } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *ElectricalConnectionServerInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { return &ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { +func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -263,7 +263,7 @@ func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Cal return _c } -func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { +func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/IdentificationCommonInterface.go b/mocks/IdentificationCommonInterface.go index fa18d8ae..3a3494dc 100644 --- a/mocks/IdentificationCommonInterface.go +++ b/mocks/IdentificationCommonInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -21,7 +21,7 @@ func (_m *IdentificationCommonInterface) EXPECT() *IdentificationCommonInterface } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData -func (_m *IdentificationCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}) bool { +func (_m *IdentificationCommonInterface) CheckEventPayloadDataForFilter(payloadData any) bool { ret := _m.Called(payloadData) if len(ret) == 0 { @@ -29,7 +29,7 @@ func (_m *IdentificationCommonInterface) CheckEventPayloadDataForFilter(payloadD } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any) bool); ok { r0 = rf(payloadData) } else { r0 = ret.Get(0).(bool) @@ -44,14 +44,14 @@ type IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call struct { } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} +// - payloadData any func (_e *IdentificationCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { return &IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData)} } -func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{})) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any)) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{})) + run(args[0].(any)) }) return _c } @@ -61,7 +61,7 @@ func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) Ret return _c } -func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}) bool) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any) bool) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/LoadControlCommonInterface.go b/mocks/LoadControlCommonInterface.go index 6796a96a..920dd722 100644 --- a/mocks/LoadControlCommonInterface.go +++ b/mocks/LoadControlCommonInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -21,7 +21,7 @@ func (_m *LoadControlCommonInterface) EXPECT() *LoadControlCommonInterface_Expec } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *LoadControlCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *LoadControlCommonInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -29,7 +29,7 @@ func (_m *LoadControlCommonInterface) CheckEventPayloadDataForFilter(payloadData } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -44,15 +44,15 @@ type LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call struct { } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *LoadControlCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { return &LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -62,7 +62,7 @@ func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) Return return _c } -func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/MeasurementCommonInterface.go b/mocks/MeasurementCommonInterface.go index ab2ee75e..18113462 100644 --- a/mocks/MeasurementCommonInterface.go +++ b/mocks/MeasurementCommonInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -21,7 +21,7 @@ func (_m *MeasurementCommonInterface) EXPECT() *MeasurementCommonInterface_Expec } // CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter -func (_m *MeasurementCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { +func (_m *MeasurementCommonInterface) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { ret := _m.Called(payloadData, filter) if len(ret) == 0 { @@ -29,7 +29,7 @@ func (_m *MeasurementCommonInterface) CheckEventPayloadDataForFilter(payloadData } var r0 bool - if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + if rf, ok := ret.Get(0).(func(any, any) bool); ok { r0 = rf(payloadData, filter) } else { r0 = ret.Get(0).(bool) @@ -44,15 +44,15 @@ type MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call struct { } // CheckEventPayloadDataForFilter is a helper method to define mock.On call -// - payloadData interface{} -// - filter interface{} +// - payloadData any +// - filter any func (_e *MeasurementCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { return &MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} } -func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData any, filter any)) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{}), args[1].(interface{})) + run(args[0].(any), args[1].(any)) }) return _c } @@ -62,7 +62,7 @@ func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) Return return _c } -func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { +func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(any, any) bool) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ServiceInterface.go b/mocks/ServiceInterface.go index 868ead26..2086ec48 100644 --- a/mocks/ServiceInterface.go +++ b/mocks/ServiceInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.45.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -450,9 +450,9 @@ func (_c *ServiceInterface_QRCodeText_Call) RunAndReturn(run func() string) *Ser return _c } -// RegisterRemoteSKI provides a mock function with given fields: ski -func (_m *ServiceInterface) RegisterRemoteSKI(ski string) { - _m.Called(ski) +// RegisterRemoteSKI provides a mock function with given fields: ski, shipID +func (_m *ServiceInterface) RegisterRemoteSKI(ski string, shipID string) { + _m.Called(ski, shipID) } // ServiceInterface_RegisterRemoteSKI_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterRemoteSKI' @@ -462,13 +462,14 @@ type ServiceInterface_RegisterRemoteSKI_Call struct { // RegisterRemoteSKI is a helper method to define mock.On call // - ski string -func (_e *ServiceInterface_Expecter) RegisterRemoteSKI(ski interface{}) *ServiceInterface_RegisterRemoteSKI_Call { - return &ServiceInterface_RegisterRemoteSKI_Call{Call: _e.mock.On("RegisterRemoteSKI", ski)} +// - shipID string +func (_e *ServiceInterface_Expecter) RegisterRemoteSKI(ski interface{}, shipID interface{}) *ServiceInterface_RegisterRemoteSKI_Call { + return &ServiceInterface_RegisterRemoteSKI_Call{Call: _e.mock.On("RegisterRemoteSKI", ski, shipID)} } -func (_c *ServiceInterface_RegisterRemoteSKI_Call) Run(run func(ski string)) *ServiceInterface_RegisterRemoteSKI_Call { +func (_c *ServiceInterface_RegisterRemoteSKI_Call) Run(run func(ski string, shipID string)) *ServiceInterface_RegisterRemoteSKI_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(string)) }) return _c } @@ -478,7 +479,7 @@ func (_c *ServiceInterface_RegisterRemoteSKI_Call) Return() *ServiceInterface_Re return _c } -func (_c *ServiceInterface_RegisterRemoteSKI_Call) RunAndReturn(run func(string)) *ServiceInterface_RegisterRemoteSKI_Call { +func (_c *ServiceInterface_RegisterRemoteSKI_Call) RunAndReturn(run func(string, string)) *ServiceInterface_RegisterRemoteSKI_Call { _c.Call.Return(run) return _c } diff --git a/service/service.go b/service/service.go index 7542250a..06811126 100644 --- a/service/service.go +++ b/service/service.go @@ -246,10 +246,18 @@ func (s *Service) QRCodeText() string { return s.mdns.QRCodeText() } -// Sets the SKI as being paired -// and connect it if paired and not currently being connected -func (s *Service) RegisterRemoteSKI(ski string) { - s.connectionsHub.RegisterRemoteSKI(ski) +// Pair a remote service based on the SKI +// +// Parameters: +// - ski: the SKI of the remote service (required) +// - shipID: the SHIP ID of the remote service (optional) +// +// Note: The SHIP ID is optional, but should be provided if available. +// if provided, it will be used to validate the remote service is +// providing this SHIP ID during the handshake process and will reject +// the connection if it does not match. +func (s *Service) RegisterRemoteSKI(ski, shipID string) { + s.connectionsHub.RegisterRemoteSKI(ski, shipID) } // Sets the SKI as not being paired diff --git a/service/service_hub.go b/service/service_hub.go index 90745b96..a4298606 100644 --- a/service/service_hub.go +++ b/service/service_hub.go @@ -39,7 +39,7 @@ func (s *Service) VisibleRemoteServicesUpdated(entries []shipapi.RemoteService) // Provides the SHIP ID the remote service reported during the handshake process // This needs to be persisted and passed on for future remote service connections -// when using `PairRemoteService` +// when using `RegisterRemoteSKI` func (s *Service) ServiceShipIDUpdate(ski string, shipdID string) { s.serviceHandler.ServiceShipIDUpdate(ski, shipdID) } diff --git a/service/service_test.go b/service/service_test.go index fa64e8da..44f6dda9 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -132,8 +132,8 @@ func (s *ServiceSuite) Test_ConnectionsHub() { s.mdns.EXPECT().QRCodeText().Return("text") assert.Equal(s.T(), "text", s.sut.QRCodeText()) - s.conHub.EXPECT().RegisterRemoteSKI(mock.Anything).Return() - s.sut.RegisterRemoteSKI(testSki) + s.conHub.EXPECT().RegisterRemoteSKI(mock.Anything, mock.Anything).Return() + s.sut.RegisterRemoteSKI(testSki, "") s.conHub.EXPECT().UnregisterRemoteSKI(mock.Anything).Return() s.sut.UnregisterRemoteSKI(testSki)