Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Extract loading and saving certificates; certificate caching improvements #516

Merged
merged 3 commits into from
Nov 5, 2018
Merged

Extract loading and saving certificates; certificate caching improvements #516

merged 3 commits into from
Nov 5, 2018

Conversation

antrv
Copy link
Contributor

@antrv antrv commented Oct 31, 2018

Hi!

I need the ability to have my own certificate disk cache, so I did the following:

  • abstracted loading and saving certificates through interface ICertificateCache
  • extracted loading and saving certificates into separate class DefaultCertificateDiskCache with the same behavior as before
  • added Cache property into CertificateManager class
  • by default CertificateManager uses DefaultCertificateDiskCache class as a ICertificateCache implementation

Also I did some certificate caching improvements:

  • certificate creation tasks moved from separate ConcurrentDictionary to CachedCertificate class
  • ClearIdleCertificates method now uses CancellationToken to stop the loop
  • added lock into the CreateRootCertificate method to prevent parallel creation of several root certificates

Doneness:

  • Build is okay - I made sure that this change is building successfully.
  • No Bugs - I made sure that this change is working properly as expected. It doesn't have any bugs that you are aware of.
  • Branching - If this is not a hotfix, I am making this request against master branch

@AppVeyorBot
Copy link

Build Titanium-Web-Proxy 3.0.732 failed (commit 4bbb42366c by @)

@AppVeyorBot
Copy link

Build Titanium-Web-Proxy 3.0.733 completed (commit bfbd97e736 by @)

// why Thread.MemoryBarrier is used here and below
cached.Certificate = certificate;
Thread.MemoryBarrier();
cached.CreationTask = null;
Copy link
Owner

Choose a reason for hiding this comment

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

Why are we setting the Task to null.

Copy link
Contributor Author

@antrv antrv Nov 5, 2018

Choose a reason for hiding this comment

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

This is the task that creates a certificate. The task assigns Certificate property to the generated certificate and cleans CreationTask property to allow the Task memory to be released by GC.

task = Task.Run(() =>
item.LastAccess = DateTime.Now;

if (item.Certificate != null)
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this be just item!=null ?

Copy link
Contributor Author

@antrv antrv Nov 5, 2018

Choose a reason for hiding this comment

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

item is always not null.
Actually this condition checks if the certificate creation task is completed, If the certificate creation task is not completed then the Certificate property of the item is null.

Copy link
Owner

Choose a reason for hiding this comment

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

Okay. I refactored it removing locking while also preventing multiple tasks for same certificate.

@justcoding121 justcoding121 merged commit 4966b6f into justcoding121:master Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants