Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bindings and subscriptions #58

Merged
merged 7 commits into from
Feb 21, 2025

Conversation

DerAndereAndi
Copy link
Member

@DerAndereAndi DerAndereAndi commented Feb 18, 2025

  • Refactor BindingManager and SubscriptionManager interface APIs
  • Add support for read requests to NodeManagementBindingData and NodeManagementSubscriptionData
  • Exclude sending notifications for updates on NodeManagementBindingData and NodeManagementSubscriptionData (see code comment in spine/feature_local.go method SetData on why this is done)
  • Store bindings and subscriptions in NodeManagement data structures
  • Store bindings and subscriptions for local client and server features
  • Only store a requested binding or subscription if the remote accepted it
  • Adding an already existing binding or subcription again will not return an error
  • On add requests, only check for proper roles, if the serverFeatureType is provided on request
  • Add support for deleting all bindings or subscriptions with the same role relation by omitting feature address or also entity address
  • Add support for delete requests from a server feature to a client feature
  • Fix a crash when incoming subscription requests where missing the optional serverFeatureType
  • Improve test cases to consider bindings and subscriptions of multiple remote devices, which should only get their corresponding bindings and subscriptions when read

Fixes #56

- Fix responding to read requests for `NodeManagementBindingData` and `NodeManagementSubscriptionData`
- Improve test cases to consider bindings and subscriptions of multiple remote devices, which should only get their corresponding bindings and subscriptions when read
- Add a comment that handling one binding per server feature is how it is now implemented, but should not be after all
- Refactor BindingManager and SubscriptionManager interface APIs
- Add support for read requests to NodeManagementBindingData and NodeManagementSubscriptionData
- Exclude sending notifications for updates on NodeManagementBindingData and NodeManagementSubscriptionData (see code comment in `spine/feature_local.go` method `SetData` on why this is done)
- Store bindings and subscriptions in NodeManagement data structures
- Store bindings and subscriptions for local client and server features
- Only store a requested binding or subscription if the remote accepted it
- Adding an already existing binding or subcription again will not return an error
- On add requests, only check for proper roles, if the `serverFeatureType` is provided on request
- Add support for deleting all bindings or subscriptions with the same role relation by omitting feature address or also entity address
- Add support for delete requests from a server feature to a client feature
- Fix a crash when incoming subscription requests where missing the optional `serverFeatureType`
@DerAndereAndi DerAndereAndi added this to the Version 0.8 milestone Feb 18, 2025
@DerAndereAndi DerAndereAndi added bug Something isn't working enhancement New feature or request labels Feb 18, 2025
@coveralls
Copy link

coveralls commented Feb 18, 2025

Coverage Status

coverage: 93.893% (+0.1%) from 93.773%
when pulling 130494a on feature/nodemanagment-improvements
into cd41007 on dev.

@DerAndereAndi DerAndereAndi changed the title Reactor bindings and subscriptions Refactor bindings and subscriptions Feb 18, 2025
@DerAndereAndi DerAndereAndi self-assigned this Feb 18, 2025
Copy link
Contributor

@sthelen-enqs sthelen-enqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through about half the files and looks good so far. I've added a few suggestions for some comments.

Is there a reason why deleting subscriptions that don't exist is now a success and not an error? I couldn't find anything explicit on this in the spec. If there's a reason we're changing this we might want to document the reason in a comment somewhere.

I'll check the other half of the PR either later today or tomorrow when I have some more time.

Co-authored-by: Simon Thelen <69789639+sthelen-enqs@users.noreply.github.com>
Copy link
Contributor

@sthelen-enqs sthelen-enqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through the rest of the files. Except for a potential logic bug in RemoveForEntity functions the changes look good to me.

I added the comment to RemoveSubscriptionsForRemoteEntity, but the changes would need to be applied to all 4

Comment on lines 168 to 178
// check if this subscription contains the remote device
if !reflect.DeepEqual(subscription.ClientAddress.Device, remoteDeviceAddress) &&
!reflect.DeepEqual(subscription.ServerAddress.Device, remoteDeviceAddress) {
continue
}

// check if this subscription contains the remote entity
if !reflect.DeepEqual(subscription.ClientAddress.Entity, remoteEntityAddress) &&
!reflect.DeepEqual(subscription.ServerAddress.Entity, remoteEntityAddress) {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this, but afaik we're trying to check if clientAddress == remoteEntity || serverAddress == remoteEntity, but are currently also allowing e.g. ClientAddress.Device == remoteDeviceAddress && ServerAddress.Entity == remoteEntityAddress

If we think of the resulting truth table [client device match, server device match, client entity match, server entity match], we're interested in [1, *, 1, *], and [*, 1, *, 1] but are currently also accepting [1, 0, 0, 1], and [0, 1, 1, 0]

I think we can use the following logic instead (even if it's not as pretty), unless the current logic is intended:

	// check if subscription matches ClientAddress or ServerAddress
	if (reflect.DeepEqual(subscription.ClientAddress.Device, remoteDeviceAddress) &&
		reflect.DeepEqual(subscription.ClientAddress.Entity, remoteEntityAddress)) ||
		(reflect.DeepEqual(subscription.ServerAddress.Device, remoteDeviceAddress) &&
			reflect.DeepEqual(subscription.ServerAddress.Entity, remoteEntityAddress)) {
		// process
	}

The same change would also need to be made in the binding_manager, and in Remove*ForLocalEntity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great review and identifying this issue! This should be fixed with the latest commit.

DerAndereAndi and others added 3 commits February 21, 2025 11:28
Co-authored-by: Simon Thelen <69789639+sthelen-enqs@users.noreply.github.com>
@sthelen-enqs sthelen-enqs self-requested a review February 21, 2025 13:26
Copy link
Contributor

@sthelen-enqs sthelen-enqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the last few changes, I think this looks good now

@DerAndereAndi
Copy link
Member Author

Thank you very much for the review @sthelen-enqs !

@DerAndereAndi DerAndereAndi merged commit 114e2d0 into dev Feb 21, 2025
6 checks passed
@DerAndereAndi DerAndereAndi deleted the feature/nodemanagment-improvements branch February 21, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with binding and subscription handling
3 participants