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: Added translation unit for synced enforcer #93

Merged
merged 2 commits into from
Apr 2, 2021

Conversation

EmperorYP7
Copy link
Member

Signed-off-by: Yash Pandey (YP) yash.btech.cs19@iiitranchi.ac.in

This PR fixes #38

Reference: #90

Description

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)


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.

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
@hsluoyz
Copy link
Member

hsluoyz commented Apr 1, 2021

@xcaptain

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.

Looks good to me, would be better you provide some tests so I can test the code. you can provide the tests in the next pull request if you want.

casbin/enforcer_synced.cpp Show resolved Hide resolved
casbin/enforcer_synced.cpp Outdated Show resolved Hide resolved
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
@hsluoyz hsluoyz merged commit b84ed34 into casbin:master Apr 2, 2021
@github-actions
Copy link

github-actions bot commented Apr 2, 2021

🎉 This PR is included in version 1.15.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@EmperorYP7 EmperorYP7 deleted the synced-enforcer branch April 2, 2021 13:19
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