]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Do not use random contract IDs
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 24 Jun 2010 22:41:01 +0000 (00:41 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 24 Jun 2010 22:43:40 +0000 (00:43 +0200)
Instead use a counter in FCB which is used as a value of a contracts ID.
Currently, we have a centralized FCB, so this is no harm for us and we get
a more readable log output as well as repeatable ID for testing.

fres/cbroker/fcb.c
fres/contract/fres_contract.h
fres/contract/fres_contract_idl.idl

index 6d587926a4d11dde9e489c3378086fcdadf6b23a..1e65541b7dda875dac529b36cbb99e95be9d569c 100644 (file)
 #include <forb/proto_inet.h>
 #endif
 
+#define COMPILE_TIME_ASSERT(cond, msg) \
+       typedef char msg[(cond) ? 1 : -1]
+
+
 UL_LOG_CUST(ulogd_fcb);
 ul_log_domain_t ulogd_fcb = {UL_LOGL_MSG, "main"};
 UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(init_ulogd_fcb, ulogd_fcb);
@@ -142,6 +146,7 @@ struct fcb_contract {
  * Contract broker data
  */
 struct fcb {
+       fres_contract_id_t contract_counter;
        gavl_cust_root_field_t resources; /**< Registered resources */
        gavl_cust_root_field_t contracts; /**< Contracts negotiated by this FCB */
 };
@@ -343,7 +348,9 @@ prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[],
 
                if (fres_contract_id_is_empty(&c->id)) {
                        /* Normal negotiation request */
-                       forb_uuid_generate((forb_uuid_t *)&c->id);
+                       COMPILE_TIME_ASSERT(sizeof(c->id) == sizeof(fcb->contract_counter),
+                                           wrong_size_of_contract_id);
+                       c->id = ++fcb->contract_counter;
                        fc = fcb_contract_new(&c->id);
                        if (!fc)
                                return errno;
@@ -1304,6 +1311,7 @@ int main(int argc, char *argv[])
                }
        }
 
+       memset(&fcb_data, 0, sizeof(fcb_data));
        fosa_clock_get_time(CLOCK_REALTIME, &start_time);
 
        if (opt_daemon)
index 15087077ac425f9795148c1096722b8b6afb4b51..74e5306e8628658db10295bc61e7cbf1bd0722e2 100644 (file)
@@ -62,6 +62,7 @@
 #include <fres_contract_type.h>
 #include <fres_contract_idl.h>
 #include <forb/server_id.h>
+#include <stdio.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -85,23 +86,26 @@ static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
 
 static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id)
 {
-       bool empty = true;
-       unsigned i;
-
-       for (i=0; i<sizeof(id->byte); i++) {
-               if (id->byte[i] != 0) {
-                       empty = false;
-                       break;
-               }
-       }
-       return empty;
+/*     bool empty = true; */
+/*     unsigned i; */
+
+/*     for (i=0; i<sizeof(id->byte); i++) { */
+/*             if (id->byte[i] != 0) { */
+/*                     empty = false; */
+/*                     break; */
+/*             } */
+/*     } */
+/*     return empty; */
+       return *id == 0;
 }
 
 static inline char *fres_contract_id_to_string(char *dest,
                                               const fres_contract_id_t *id,
                                               size_t n)
 {
-       return forb_server_id_to_string(dest, (forb_server_id*)id, n);
+       snprintf(dest, n, "%llx", *id);
+/*     return forb_server_id_to_string(dest, (forb_server_id*)id, n); */
+       return dest;
 }
 
 struct fres_contract *fres_contract_new(void);
index 336ef0ba241de567d62ac672a08cb6be6f08367b..c2cdc085b067946e597116326eadbc94f72c57a5 100644 (file)
@@ -73,9 +73,10 @@ module fres {
                typedef sequence<ptr> ptr_seq;
                
                /// Globaly unique contract ID
-               struct id_t {
-                       char byte[8];
-               };
+               typedef unsigned long long id_t;
+//             struct id_t {
+//                     char byte[8];
+//             };
 
                typedef sequence<id_t> id_seq;