|
TNL::ClientPuzzleManager class Reference
TNL::ClientPuzzleManager Class Reference#include <tnlClientPuzzle.h>
Detailed Description
The ClientPuzzleManager class issues, solves and validates client puzzles for connection authentication.
|
Public Types |
enum | ErrorCode {
Success,
InvalidSolution,
InvalidServerNonce,
InvalidClientNonce,
InvalidPuzzleDifficulty,
ErrorCodeCount
} |
| Error codes that can be returned by checkSolution. More...
|
enum | {
PuzzleRefreshTime = 30000,
InitialPuzzleDifficulty = 17,
MaxPuzzleDifficulty = 26,
MaxSolutionComputeFragment = 30,
SolutionFragmentIterations = 50000
} |
| Difficulty levels of puzzles. More...
|
Public Member Functions |
| ClientPuzzleManager () |
| ~ClientPuzzleManager () |
void | tick (U32 currentTime) |
| Checks to see if a new nonce needs to be created, and if so generates one and tosses out the current list of accepted nonces.
|
ErrorCode | checkSolution (U32 solution, Nonce &clientNonce, Nonce &serverNonce, U32 puzzleDifficulty, U32 clientIdentity) |
| Checks a puzzle solution submitted by a client to see if it is a valid solution for the current or previous puzzle nonces.
|
Nonce | getCurrentNonce () |
| Returns the current server nonce.
|
U32 | getCurrentDifficulty () |
| Returns the current client puzzle difficulty.
|
Static Public Member Functions |
bool | solvePuzzle (U32 *solution, Nonce &clientNonce, Nonce &serverNonce, U32 puzzleDifficulty, U32 clientIdentity) |
| Computes a puzzle solution value for the given puzzle difficulty and server nonce.
|
Static Private Member Functions |
bool | checkOneSolution (U32 solution, Nonce &clientNonce, Nonce &serverNonce, U32 puzzleDifficulty, U32 clientIdentity) |
Private Attributes |
U32 | mCurrentDifficulty |
U32 | mLastUpdateTime |
U32 | mLastTickTime |
Nonce | mCurrentNonce |
Nonce | mLastNonce |
NonceTable * | mCurrentNonceTable |
NonceTable * | mLastNonceTable |
Member Enumeration Documentation
|
Error codes that can be returned by checkSolution.
- Enumeration values:
-
Success |
|
InvalidSolution |
|
InvalidServerNonce |
|
InvalidClientNonce |
|
InvalidPuzzleDifficulty |
|
ErrorCodeCount |
|
|
|
Difficulty levels of puzzles.
- Enumeration values:
-
PuzzleRefreshTime |
Refresh the server puzzle every 30 seconds. |
InitialPuzzleDifficulty |
Initial puzzle difficulty is set so clients do approx 2-3x the shared secret generation of the server. |
MaxPuzzleDifficulty |
Maximum puzzle difficulty is approx 1 minute to solve on ~2004 hardware. |
MaxSolutionComputeFragment |
Number of milliseconds spent computing solution per call to solvePuzzle. |
SolutionFragmentIterations |
Number of attempts to spend on the client puzzle per call to solvePuzzle. |
|
Constructor & Destructor Documentation
TNL::ClientPuzzleManager::ClientPuzzleManager |
( |
|
) |
|
|
Member Function Documentation
bool TNL::ClientPuzzleManager::checkOneSolution |
( |
U32 |
solution, |
|
|
Nonce & |
clientNonce, |
|
|
Nonce & |
serverNonce, |
|
|
U32 |
puzzleDifficulty, |
|
|
U32 |
clientIdentity |
|
) |
[static, private] |
|
void TNL::ClientPuzzleManager::tick |
( |
U32 |
currentTime |
) |
|
|
|
Checks to see if a new nonce needs to be created, and if so generates one and tosses out the current list of accepted nonces.
|
ErrorCode TNL::ClientPuzzleManager::checkSolution |
( |
U32 |
solution, |
|
|
Nonce & |
clientNonce, |
|
|
Nonce & |
serverNonce, |
|
|
U32 |
puzzleDifficulty, |
|
|
U32 |
clientIdentity |
|
) |
|
|
|
Checks a puzzle solution submitted by a client to see if it is a valid solution for the current or previous puzzle nonces.
|
bool TNL::ClientPuzzleManager::solvePuzzle |
( |
U32 * |
solution, |
|
|
Nonce & |
clientNonce, |
|
|
Nonce & |
serverNonce, |
|
|
U32 |
puzzleDifficulty, |
|
|
U32 |
clientIdentity |
|
) |
[static] |
|
|
Computes a puzzle solution value for the given puzzle difficulty and server nonce.
If the execution time of this function exceeds MaxSolutionComputeFragment milliseconds, it will return the current trail solution in the solution variable and a return value of false.
- Note:
- Although the behavior of this function can be tweaked using MaxSolutionComputeFragment and SolutionFragmentIterations, it's important to bias these settings in favor of rapid puzzle completion. A client puzzle is only valid for two times PuzzleRefreshTime, so for about a minute, maximum. Most of the time the puzzle can be solved in only a few hundred milliseconds. It's better to solve the puzzle fast than to let it drag out, (ie, it's better to let your application hitch for a moment whilst calculating than to make the user endure many seconds of lag) so reducing the timeout or iterations should be done only if you know what you're doing.
|
Nonce TNL::ClientPuzzleManager::getCurrentNonce |
( |
|
) |
[inline] |
|
|
Returns the current server nonce.
|
U32 TNL::ClientPuzzleManager::getCurrentDifficulty |
( |
|
) |
[inline] |
|
|
Returns the current client puzzle difficulty.
|
Field Documentation
|