For DOV: LCR random number generator
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 28 Jun 2014 07:14:44 +0000 (09:14 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Tue, 15 Dec 2015 13:26:56 +0000 (14:26 +0100)
Generate random number from jitter of all messages inside LCR.

message.c
message.h

index 1e4d37d..cfda36b 100644 (file)
--- a/message.c
+++ b/message.c
@@ -30,10 +30,19 @@ void cleanup_message(void)
        del_work(&message_work);
 }
 
+unsigned int lcr_random = 0;
+
 /* creates a new message with the given attributes. the message must be filled then. after filling, the message_put must be called */
 struct lcr_msg *message_create(int id_from, int id_to, int flow, int type)
 {
        struct lcr_msg *message;
+       struct timeval now_tv;
+       struct timezone now_tz;
+
+       gettimeofday(&now_tv, &now_tz);
+       lcr_random = (lcr_random << 1) | (lcr_random >> 31);
+       lcr_random ^= now_tv.tv_sec;
+       lcr_random ^= now_tv.tv_usec;
 
        message = (struct lcr_msg *)MALLOC(sizeof(struct lcr_msg));
        if (!message)
index 8a8bc44..38ee5da 100644 (file)
--- a/message.h
+++ b/message.h
@@ -489,6 +489,7 @@ enum { /* messages between entities */
 };
 
 
+extern unsigned int lcr_random;
 struct lcr_msg *message_create(int id_from, int id_to, int flow, int type);
 #define message_put(m) _message_put(m, __FILE__, __LINE__)
 void _message_put(struct lcr_msg *message, const char *file, int line);