![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
A TokenStore in a private folder: one token file and one lock file per identity. POSIX only; not provided on Windows. More...
#include <algotradelib/src/network/file_token_store.hpp>
Public Member Functions | |
| FileTokenStore (std::string folder, std::chrono::milliseconds lock_wait=std::chrono::seconds(30)) | |
| Constructs a store; nothing is created or opened until the first call. | |
| Result< std::unique_ptr< Lock > > | lock (const std::string &identity) override |
| Takes the identity's lock, opening its lock file anew, so two callers in one process exclude each other as two processes do. | |
| Result< std::optional< StoredToken > > | load (const std::string &identity) override |
| Reads the identity's token file. | |
| std::optional< BrokerError > | publish (const std::string &identity, const StoredToken &token) override |
| Replaces the identity's token file, unless the stored token expires later. | |
| std::optional< BrokerError > | discard (const std::string &identity, const std::string &access_token) override |
| Removes the identity's token file if it holds the given token. | |
| std::optional< BrokerError > | remove (const std::string &identity) override |
| Removes the identity's token file; its lock file stays. | |
A TokenStore in a private folder: one token file and one lock file per identity. POSIX only; not provided on Windows.
The folder is created (mode 0700) if it does not exist; its parent must. For identity ID the store keeps ID.token (JSON: the token and its expiry in nanoseconds since the epoch, replaced by writing ID.tmp, flushing it and renaming it) and ID.lock (an flock lock, never removed). The folder and every file must be owned by the user running the program and give no permission to group or others; a store that finds otherwise refuses and leaves the file as it was. A symbolic link at the folder's path or at a file's is not followed. Descriptors are closed on exec. A token file that is not well formed reads as no token.
Keep the folder on a local disk: flock over a network file system is unreliable. A lock held when the process forks without exec is held by the child too, until the child closes the descriptor or exits. The token is a bearer credential; the folder is as sensitive as the app secret.
Definition at line 43 of file file_token_store.hpp.
|
inlineexplicit |
Constructs a store; nothing is created or opened until the first call.
| folder | The folder. |
| lock_wait | How long lock waits for another holder before it fails. |
Definition at line 50 of file file_token_store.hpp.
|
inlineoverridevirtual |
Removes the identity's token file if it holds the given token.
| identity | The identity. |
| access_token | The token. |
Implements algotradelib::network::TokenStore.
Definition at line 133 of file file_token_store.hpp.
|
inlineoverridevirtual |
Reads the identity's token file.
| identity | The identity. |
Implements algotradelib::network::TokenStore.
Definition at line 92 of file file_token_store.hpp.
|
inlineoverridevirtual |
Takes the identity's lock, opening its lock file anew, so two callers in one process exclude each other as two processes do.
| identity | The identity. |
Implements algotradelib::network::TokenStore.
Definition at line 59 of file file_token_store.hpp.
|
inlineoverridevirtual |
Replaces the identity's token file, unless the stored token expires later.
| identity | The identity. |
| token | The token. |
Implements algotradelib::network::TokenStore.
Definition at line 110 of file file_token_store.hpp.
|
inlineoverridevirtual |
Removes the identity's token file; its lock file stays.
| identity | The identity. |
Implements algotradelib::network::TokenStore.
Definition at line 156 of file file_token_store.hpp.