Tor  0.4.7.0-alpha-dev
Data Structures | Enumerations | Functions
shared_random_state.h File Reference

Header for shared_random_state.c. More...

#include "feature/dirauth/shared_random.h"

Go to the source code of this file.

Data Structures

struct  sr_state_t
 
struct  sr_disk_state_t
 

Enumerations

enum  sr_state_action_t {
  SR_STATE_ACTION_GET = 1 , SR_STATE_ACTION_PUT = 2 , SR_STATE_ACTION_DEL = 3 , SR_STATE_ACTION_DEL_ALL = 4 ,
  SR_STATE_ACTION_SAVE = 5
}
 
enum  sr_state_object_t {
  SR_STATE_OBJ_COMMIT , SR_STATE_OBJ_COMMITS , SR_STATE_OBJ_CURSRV , SR_STATE_OBJ_PREVSRV ,
  SR_STATE_OBJ_PHASE , SR_STATE_OBJ_VALID_AFTER
}
 

Functions

void sr_state_update (time_t valid_after)
 
void sr_state_set_valid_after (time_t valid_after)
 
sr_phase_t sr_state_get_phase (void)
 
const sr_srv_tsr_state_get_previous_srv (void)
 
const sr_srv_tsr_state_get_current_srv (void)
 
void sr_state_set_previous_srv (const sr_srv_t *srv)
 
void sr_state_set_current_srv (const sr_srv_t *srv)
 
void sr_state_clean_srvs (void)
 
digestmap_t * sr_state_get_commits (void)
 
sr_commit_tsr_state_get_commit (const char *rsa_fpr)
 
void sr_state_add_commit (sr_commit_t *commit)
 
void sr_state_delete_commits (void)
 
void sr_state_copy_reveal_info (sr_commit_t *saved_commit, const sr_commit_t *commit)
 
unsigned int sr_state_srv_is_fresh (void)
 
void sr_state_set_fresh_srv (void)
 
void sr_state_unset_fresh_srv (void)
 
int sr_state_init (int save_to_disk, int read_from_disk)
 
int sr_state_is_initialized (void)
 
void sr_state_save (void)
 
void sr_state_free_all (void)
 

Detailed Description

Header for shared_random_state.c.

Definition in file shared_random_state.h.

Enumeration Type Documentation

◆ sr_state_action_t

Action that can be performed on the state for any objects.

Definition at line 15 of file shared_random_state.h.

◆ sr_state_object_t

Object in the state that can be queried through the state API.

Enumerator
SR_STATE_OBJ_COMMIT 

Will return a single commit using an authority identity key.

SR_STATE_OBJ_COMMITS 

Returns the entire list of commits from the state.

SR_STATE_OBJ_CURSRV 

Return the current SRV object pointer.

SR_STATE_OBJ_PREVSRV 

Return the previous SRV object pointer.

SR_STATE_OBJ_PHASE 

Return the phase.

SR_STATE_OBJ_VALID_AFTER 

Get or Put the valid after time.

Definition at line 24 of file shared_random_state.h.

Function Documentation

◆ sr_state_add_commit()

void sr_state_add_commit ( sr_commit_t commit)

Add commit to the permanent state. The commit object ownership is transferred to the state so the caller MUST not free it.

Definition at line 1193 of file shared_random_state.c.

Referenced by save_commit_to_state().

◆ sr_state_clean_srvs()

void sr_state_clean_srvs ( void  )

Clean all the SRVs in our state.

Definition at line 1094 of file shared_random_state.c.

◆ sr_state_copy_reveal_info()

void sr_state_copy_reveal_info ( sr_commit_t saved_commit,
const sr_commit_t commit 
)

Copy the reveal information from commit into saved_commit. This saved_commit MUST come from our current SR state. Once modified, the disk state is updated.

Definition at line 1216 of file shared_random_state.c.

Referenced by save_commit_during_reveal_phase().

◆ sr_state_delete_commits()

void sr_state_delete_commits ( void  )

Remove all commits from our state.

Definition at line 1207 of file shared_random_state.c.

◆ sr_state_free_all()

void sr_state_free_all ( void  )

Cleanup and free our disk and memory state.

Definition at line 1258 of file shared_random_state.c.

Referenced by sr_cleanup().

◆ sr_state_get_commit()

sr_commit_t* sr_state_get_commit ( const char *  rsa_identity)

Return commit object from the given authority digest rsa_identity. Return NULL if not found.

Definition at line 1179 of file shared_random_state.c.

Referenced by save_commit_during_reveal_phase().

◆ sr_state_get_commits()

digestmap_t* sr_state_get_commits ( void  )

Return a pointer to the commits map from our state. CANNOT be NULL.

Definition at line 1103 of file shared_random_state.c.

◆ sr_state_get_current_srv()

const sr_srv_t* sr_state_get_current_srv ( void  )

Return the current SRV value from our state. Value CAN be NULL. The state object owns the SRV, so the calling code should not free the SRV. Use sr_srv_dup() if you want to keep a copy of the SRV.

Definition at line 1075 of file shared_random_state.c.

Referenced by state_rotate_srv().

◆ sr_state_get_phase()

sr_phase_t sr_state_get_phase ( void  )

Return the phase we are currently in according to our state.

Definition at line 1042 of file shared_random_state.c.

Referenced by save_commit_to_state(), and sr_handle_received_commits().

◆ sr_state_get_previous_srv()

const sr_srv_t* sr_state_get_previous_srv ( void  )

Return the previous SRV value from our state. Value CAN be NULL. The state object owns the SRV, so the calling code should not free the SRV. Use sr_srv_dup() if you want to keep a copy of the SRV.

Definition at line 1054 of file shared_random_state.c.

◆ sr_state_init()

int sr_state_init ( int  save_to_disk,
int  read_from_disk 
)

Initialize the disk and memory state.

If save_to_disk is set to 1, the state is immediately saved to disk after creation else it's not thus only kept in memory. If read_from_disk is set to 1, we try to load the state from the disk and if not found, a new state is created.

Return 0 on success else a negative value on error.

Definition at line 1293 of file shared_random_state.c.

Referenced by sr_init().

◆ sr_state_is_initialized()

int sr_state_is_initialized ( void  )

Return 1 iff the state has been initialized that is it exists in memory. Return 0 otherwise.

Definition at line 1279 of file shared_random_state.c.

Referenced by sr_act_post_consensus().

◆ sr_state_save()

void sr_state_save ( void  )

Save our current state in memory to disk.

Definition at line 1270 of file shared_random_state.c.

Referenced by sr_save_and_cleanup().

◆ sr_state_set_current_srv()

void sr_state_set_current_srv ( const sr_srv_t srv)

Set the current SRV value from our state. Value CAN be NULL. The srv object ownership is transferred to the state object.

Definition at line 1086 of file shared_random_state.c.

Referenced by state_rotate_srv().

◆ sr_state_set_fresh_srv()

void sr_state_set_fresh_srv ( void  )

Set the fresh SRV flag from our state. This doesn't need to trigger a disk state synchronization so we directly change the state.

Definition at line 1236 of file shared_random_state.c.

◆ sr_state_set_previous_srv()

void sr_state_set_previous_srv ( const sr_srv_t srv)

Set the current SRV value from our state. Value CAN be NULL. The srv object ownership is transferred to the state object.

Definition at line 1065 of file shared_random_state.c.

Referenced by state_rotate_srv().

◆ sr_state_set_valid_after()

void sr_state_set_valid_after ( time_t  valid_after)

Set valid after time in the our state.

Definition at line 1034 of file shared_random_state.c.

◆ sr_state_srv_is_fresh()

unsigned int sr_state_srv_is_fresh ( void  )

Return the value of the fresh SRV flag.

Definition at line 1251 of file shared_random_state.c.

◆ sr_state_unset_fresh_srv()

void sr_state_unset_fresh_srv ( void  )

Unset the fresh SRV flag from our state. This doesn't need to trigger a disk state synchronization so we directly change the state.

Definition at line 1244 of file shared_random_state.c.

◆ sr_state_update()

void sr_state_update ( time_t  valid_after)

Update the current SR state as needed for the upcoming voting round at valid_after.

Definition at line 1115 of file shared_random_state.c.

Referenced by sr_state_init().