forked from luca-Serena/Lunes-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_definition.h
executable file
·84 lines (73 loc) · 3.68 KB
/
entity_definition.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ##############################################################################################
* Advanced RTI System, ARTÌS http://pads.cs.unibo.it
* Large Unstructured NEtwork Simulator (LUNES)
*
* Description:
* - In this file is defined the state of the simulated entitiesFORKI
*
* Authors:
* First version by Gabriele D'Angelo <[email protected]>
*
############################################################################################### */
#ifndef __ENTITY_DEFINITION_H
#define __ENTITY_DEFINITION_H
#include "lunes_constants.h"
/*---- E N T I T I E S D E F I N I T I O N ---------------------------------*/
/*! \brief Structure of "value" in the hash table of each node
* in LUNES used to implement neighbors and its properties
*/
typedef struct v_e {
unsigned int value; // Value
#ifdef DEGREE_DEPENDENT_GOSSIP_SUPPORT
unsigned int num_neighbors; // Number of neighbors of each neighbor of a given node
#endif
} value_element;
/*! \brief Records composing the local state (dynamic part) of each SE
* NOTE: no duplicated keys are allowed
*/
struct state_element {
unsigned int key; // Key
value_element elements; // Value
};
/*! \brief Structure of a transaction in each block */
typedef struct transaction_element {
int id; // ID of the transaction
} Transaction;
/*! \brief Structure of a block in each node */
typedef struct blockchain_element {
int id; // ID of the block
int latesttrans; // ID of the lastest transacation (used as index)
int prevId; // ID of the previoud block in the chain
int position; // position of the block in the blockchain
#ifdef TXDEBUG
Transaction trans[500]; // Mean # of transactions per block (less is better for performance)
#endif
} Block;
/*! \brief Static part of the SE state */
typedef struct static_data_t {
Block * heads[10]; // head blocks of the forks
char changed; // ON if there has been a state change in the last timestep
char freerider; // 1 if free-rider, 0 not free-rider
float time_of_next_trans; // Timestep in which the next new transaction will be created and sent
float time_of_next_check; // Timestep in which the next check for new block will be created and sent
Block blockchain[3000]; // Array of blocks
#ifdef DOS
short received; //0 not received anything, !=0 received the message, -1 received the message back in the fluff phase
#endif
} static_data_t;
/*! \brief SE state definition */
typedef struct hash_data_t {
int key; // SE identifier
int lp; // Logical Process ID (that is the SE container)
double hashrate; // Hashrate of the node (if a miner)
int attackerid; // ID of the attacker (equal to key)
int miner; // Boolean: is the node a miner?
int internal_timer; // Used to track mining activity
int latestblock; // ID of the latest block (used as index)
static_data_t s_state; // Static part of the SE local state
GHashTable * state; // Local state as an hash table (glib) (dynamic part)
// #ifdef DEGREE_DEPENDENT_GOSSIP_SUPPORT
unsigned int num_neighbors; // Number of SE's neighbors (dynamically updated)
//#endif
} hash_data_t;
#endif /* __ENTITY_DEFINITION_H */