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

feat: Implemented synced enforcer #83

Closed
wants to merge 9 commits into from

Conversation

EmperorYP7
Copy link
Member

@EmperorYP7 EmperorYP7 commented Mar 14, 2021

Signed-off-by: Yash Pandey (YP) [email protected]

This PR fixes #38

Most of the functions of SyncedEnforcer were straight-forward to implement but the AutoLoadPolicy needed a workaround since it utilized GoLang's ticker from the "time" module and concurrency. For this, I created a custom concurrent ticker that takes in the duration and a function<void()> for a callback. Then passed in the following to callback of ticker which is called at every tick:

[this]() {
    Enforcer::LoadPolicy();
    ++n;
};

Note that n is an atomic_int which is thread-safe.
When StopAutoLoad() is called, the ticker stops all worker threads deployed by the ticker. However, this won't destroy the instance of the ticker. I also created test files to verify everything is implemented correctly. (The test policy won't change in real-time during a test)

Overheads involved:

Apart from the futures obtained from ticker threads, ticker also collects futures from callback at each tick since they're called asynchronously as well. This might lead to a pile of useless data given enough uptime of AutoLoadPolicy() and scope of SyncedEnforcer.


Tasks remaining

  • BatchEnforcer, BatchWithMatcher yet to be implemented in Enforcer.
  • UpdatePolicy, UpdateNamedPolicy, UpdatePolicies and UpdateNamedPolicies yet to be implemented in Enforcer.
  • UpdateGroupingPolicy, UpdateNamedGroupingPolicy yet to be implemented in Enforcer.

I'll implement this in another PR 'cause this is enormous already.

Signed-off-by: Yash Pandey (YP) <[email protected]>
Signed-off-by: Yash Pandey (YP) <[email protected]>
Signed-off-by: Yash Pandey (YP) <[email protected]>
Signed-off-by: Yash Pandey (YP) <[email protected]>
@EmperorYP7
Copy link
Member Author

@bokket feel free to commit on this branch. I am sure there's a lot of room for improvement here.

Signed-off-by: EmperorYP7 <[email protected]>
Signed-off-by: EmperorYP7 <[email protected]>
@EmperorYP7 EmperorYP7 marked this pull request as ready for review March 15, 2021 15:08
Signed-off-by: EmperorYP7 <[email protected]>
Copy link
Member Author

@EmperorYP7 EmperorYP7 left a comment

Choose a reason for hiding this comment

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

So, SetWatcher() will be invoked whenever there's a change in the database(policy)?

// SetWatcher sets the current watcher.
void SyncedEnforcer ::SetWatcher(shared_ptr<Watcher> w){
watcher = w;
return watcher->SetUpdateCallback(&SyncedEnforcer::UpdateWrapper);
Copy link
Member Author

Choose a reason for hiding this comment

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

@xcaptain I think this would be of some context to #38 (comment).

Choose a reason for hiding this comment

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

@EmperorYP7 Nice, and I think you can also add SetWatcher to enforcer

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing!

@EmperorYP7
Copy link
Member Author

@hsluoyz I think this is ready for review and testing.
Now that I am aware of #7, should I create some PRs with relatively smaller patches and close this one?

@hsluoyz hsluoyz requested a review from divy9881 March 23, 2021 08:14
@hsluoyz
Copy link
Member

hsluoyz commented Mar 23, 2021

@divy9881 @xcaptain please review.

Copy link

@xcaptain xcaptain left a comment

Choose a reason for hiding this comment

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

LGTM

@hsluoyz
Copy link
Member

hsluoyz commented Mar 30, 2021

Plz provide smaller PRs.

@github-actions
Copy link

🎉 This issue has been resolved in version 1.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@EmperorYP7 EmperorYP7 deleted the EmperorYP7/enforcer branch April 1, 2021 07:05
@EmperorYP7 EmperorYP7 restored the EmperorYP7/enforcer branch April 1, 2021 07:05
@EmperorYP7 EmperorYP7 deleted the EmperorYP7/enforcer branch April 10, 2021 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add synced and cached enforcer
3 participants