#ifndef _DHT_H_ #define _DHT_H_ #include #include #include #include "key.h" #include "message.h" using namespace std; // message types #define SEND_MESSAGE 50 #define HELLO_MESSAGE 51 #define PUT_COMMAND 52 #define DHT_PUT_ROOT 53 #define DHT_PUT_NONROOT 54 #define DHT_GET_ROOT 55 #define GET_COMMAND 56 #define DHT_GET_NONROOT 57 #define DHT_DUMP_STATE 58 #define DHT_REPORT_TO_ROOT 59 #define DHT_REMOVE_ENTRY 60 // this randomwalk is used only for putting hints in bluemoon #define RANDOMWALK_PUT_ROOT 61 #define RANDOMWALK_KEEPALIVE_ROOT 62 #define DHT_KEEPALIVE_ROOT 63 #define DHT_KEEPALIVE_NONROOT 64 // excluding the root of the block; this is the replicaiton factor; totally, dht_replication+1 replicas of the obj will be stored in network #define DHT_REPLICATION 4 // test specific details #define HOSTS_FILE "./hosts" #define BLOCKS_FILE "./blocks" #define TEST_NETWORK_SIZE 100 #define BLOCKS_PER_FILE 10 #define FILES_PER_NODE 10 #define ENTRY_SIZE 100 #define DHT_MAINTAIN_PERIOD 20 #define DHT_REMOVE_DEADENTRY_PERIOD 10 // by default objects in dht live for 100 secs in there #define DEFAULT_DHT_ENTRY_LIFETIME 300 #define CONNECTION_ID_LENGTH (KEY_SIZE/BASE_B) // keep the connectionid length same as that of the key_length -- this is how its used in some places #define SYMMETRIC_KEY_LENGTH 16 #define IV_LENGTH 16 typedef enum hc { NOTUSED = 0, // so that default value doesn't mean shit FORWARD, // this is to indicate that the node should just forward and nothing else should be done DECRYPT, // it is assumed that they forward too after this ENCRYPT, DELIVER, BATCH, DELAY, RENDEZVOUS } HintCommand; typedef struct hintvalue{ //what are the fields you need for bluemoon unsigned char symmetricKey[SYMMETRIC_KEY_LENGTH]; // binary data unsigned char symmetricIV[IV_LENGTH]; // binary data // hash table is indexed based on the entry CID char entryCID[CONNECTION_ID_LENGTH + 1]; // should be treated as a normal string (not binary data) to use as the key for the hash table (and hashmap); char exitCID[CONNECTION_ID_LENGTH + 1]; // should be treated as a normal string (not binary data) to use as the key for the hash table (and hashmap); HintCommand hintCommand; char nextHop[KEY_SIZE/BASE_B + 1]; // the next random point address bool connectionHint; // to indicate if this is a connection hint or a communication hint bool endOfReversePath; }HintValue; typedef struct DhtMessage { char blockId[ENTRY_SIZE]; int hops; bool root; char putPoint[KEY_SIZE/BASE_B + 1]; // indicates the source id of the message char source[KEY_SIZE/BASE_B + 1]; HintValue value; // this dht is tailored specifically for bluemoon; this will have to be replaced with something else if you need to use it for some other project }DhtMessage; typedef struct htEntry { char key[KEY_SIZE/BASE_B+1]; bool root; char putPoint[KEY_SIZE/BASE_B+1]; double insertTime; HintValue value; }HashTableEntry; typedef map HashMap; // dhtmessage creation and deletion code DhtMessage* get_new_dhtmessage(char *blockId, char *putpoint, char *source, char* value); void free_dhtmessage(DhtMessage *msg); // block is the key of the dht entry; // root indicates if this node is the root of the object -- can change dynamically; // putpoint is the random point around which the object should be replicated // value is the content stored in the dht, which is returned later by dht_get void dht_put(ChimeraState *state, char *block, bool root, char *putpoint, char* value);// put abstraction char* dht_get(ChimeraState *state, char *block); void dht_keepalive(ChimeraState *state, char *block); // key here is the key(nodeid) of the local node int dhtlayer_init(ChimeraState * state, char *key); #endif /* _DHT_H_ */