diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-31 14:52:41 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-31 14:52:41 +0000 |
commit | f941bca886b577fd14235686c3100accc2beb03c (patch) | |
tree | 7e6d2916ee51deeb14106f56df1d22d4f91efe50 /src/testbed/testbed_api_peers.c | |
parent | 7e2e6f55d1bf7ab87c9df180bfa6841480f99ab8 (diff) | |
download | gnunet-f941bca886b577fd14235686c3100accc2beb03c.tar.gz gnunet-f941bca886b577fd14235686c3100accc2beb03c.zip |
peer create with new operations handling
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r-- | src/testbed/testbed_api_peers.c | 106 |
1 files changed, 75 insertions, 31 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 4571b78df..3ecb38325 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -29,6 +29,65 @@ | |||
29 | #include "testbed_api.h" | 29 | #include "testbed_api.h" |
30 | #include "testbed.h" | 30 | #include "testbed.h" |
31 | #include "testbed_api_hosts.h" | 31 | #include "testbed_api_hosts.h" |
32 | #include "testbed_api_operations.h" | ||
33 | |||
34 | /** | ||
35 | * Function to call to start a peer_create type operation once all | ||
36 | * queues the operation is part of declare that the | ||
37 | * operation can be activated. | ||
38 | * | ||
39 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
40 | */ | ||
41 | static void | ||
42 | opstart_peer_create (void *cls) | ||
43 | { | ||
44 | struct OperationContext *opc = cls; | ||
45 | struct PeerCreateData *data; | ||
46 | struct GNUNET_TESTBED_PeerCreateMessage *msg; | ||
47 | char *config; | ||
48 | char *xconfig; | ||
49 | size_t c_size; | ||
50 | size_t xc_size; | ||
51 | uint16_t msize; | ||
52 | |||
53 | GNUNET_assert (OP_PEER_CREATE == opc->type); | ||
54 | data = opc->data; | ||
55 | GNUNET_assert (NULL != data); | ||
56 | GNUNET_assert (NULL != data->peer); | ||
57 | config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size); | ||
58 | xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); | ||
59 | GNUNET_free (config); | ||
60 | msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); | ||
61 | msg = GNUNET_realloc (xconfig, msize); | ||
62 | memmove (&msg[1], msg, xc_size); | ||
63 | msg->header.size = htons (msize); | ||
64 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); | ||
65 | msg->operation_id = GNUNET_htonll (opc->id); | ||
66 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); | ||
67 | msg->peer_id = htonl (data->peer->unique_id); | ||
68 | msg->config_size = htonl (c_size); | ||
69 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, | ||
70 | opc->c->ocq_tail, opc); | ||
71 | GNUNET_TESTBED_queue_message_ (opc->c, | ||
72 | (struct GNUNET_MessageHeader *) msg); | ||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Callback which will be called when peer_create type operation is released | ||
78 | * | ||
79 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
80 | */ | ||
81 | static void | ||
82 | oprelease_peer_create (void *cls) | ||
83 | { | ||
84 | struct OperationContext *opc = cls; | ||
85 | |||
86 | GNUNET_assert (NULL != opc->data); | ||
87 | GNUNET_free (opc->data); | ||
88 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
89 | GNUNET_free (opc); | ||
90 | } | ||
32 | 91 | ||
33 | 92 | ||
34 | /** | 93 | /** |
@@ -71,7 +130,8 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) | |||
71 | * @param unique_id unique ID for this peer | 130 | * @param unique_id unique ID for this peer |
72 | * @param controller controller process to use | 131 | * @param controller controller process to use |
73 | * @param host host to run the peer on | 132 | * @param host host to run the peer on |
74 | * @param cfg configuration to use for the peer | 133 | * @param cfg Template configuration to use for the peer. Should exist until |
134 | * operation is cancelled or GNUNET_TESTBED_operation_done() is called | ||
75 | * @param cb the callback to call when the peer has been created | 135 | * @param cb the callback to call when the peer has been created |
76 | * @param cls the closure to the above callback | 136 | * @param cls the closure to the above callback |
77 | * @return the operation handle | 137 | * @return the operation handle |
@@ -86,13 +146,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, | |||
86 | { | 146 | { |
87 | struct GNUNET_TESTBED_Peer *peer; | 147 | struct GNUNET_TESTBED_Peer *peer; |
88 | struct PeerCreateData *data; | 148 | struct PeerCreateData *data; |
89 | struct GNUNET_TESTBED_Operation *op; | 149 | struct OperationContext *opc; |
90 | struct GNUNET_TESTBED_PeerCreateMessage *msg; | ||
91 | char *config; | ||
92 | char *xconfig; | ||
93 | size_t c_size; | ||
94 | size_t xc_size; | ||
95 | uint16_t msize; | ||
96 | 150 | ||
97 | peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer)); | 151 | peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer)); |
98 | peer->controller = controller; | 152 | peer->controller = controller; |
@@ -100,31 +154,20 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, | |||
100 | peer->unique_id = unique_id; | 154 | peer->unique_id = unique_id; |
101 | peer->state = PS_INVALID; | 155 | peer->state = PS_INVALID; |
102 | data = GNUNET_malloc (sizeof (struct PeerCreateData)); | 156 | data = GNUNET_malloc (sizeof (struct PeerCreateData)); |
157 | data->host = host; | ||
158 | data->cfg = cfg; | ||
103 | data->cb = cb; | 159 | data->cb = cb; |
104 | data->cls = cls; | 160 | data->cls = cls; |
105 | data->peer = peer; | 161 | data->peer = peer; |
106 | op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); | 162 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
107 | op->controller = controller; | 163 | opc->c = controller; |
108 | op->operation_id = controller->operation_counter++; | 164 | opc->data = data; |
109 | op->type = OP_PEER_CREATE; | 165 | opc->id = controller->operation_counter++; |
110 | op->data = data; | 166 | opc->type = OP_PEER_CREATE; |
111 | config = GNUNET_CONFIGURATION_serialize (cfg, &c_size); | 167 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, |
112 | xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); | 168 | &oprelease_peer_create); |
113 | GNUNET_free (config); | 169 | GNUNET_TESTBED_operation_queue_insert_ (controller->opq_peer_create, opc->op); |
114 | msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); | 170 | return opc->op; |
115 | msg = GNUNET_realloc (xconfig, msize); | ||
116 | memmove (&msg[1], msg, xc_size); /* Move the compressed config */ | ||
117 | msg->header.size = htons (msize); | ||
118 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); | ||
119 | msg->operation_id = GNUNET_htonll (op->operation_id); | ||
120 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host)); | ||
121 | msg->peer_id = htonl (peer->unique_id); | ||
122 | msg->config_size = htonl (c_size); | ||
123 | GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head, | ||
124 | peer->controller->op_tail, op); | ||
125 | GNUNET_TESTBED_queue_message_ (controller, | ||
126 | (struct GNUNET_MessageHeader *) msg); | ||
127 | return op; | ||
128 | } | 171 | } |
129 | 172 | ||
130 | 173 | ||
@@ -151,7 +194,8 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, | |||
151 | * | 194 | * |
152 | * @param controller controller process to use | 195 | * @param controller controller process to use |
153 | * @param host host to run the peer on | 196 | * @param host host to run the peer on |
154 | * @param cfg configuration to use for the peer | 197 | * @param cfg Template configuration to use for the peer. Should exist until |
198 | * operation is cancelled or GNUNET_TESTBED_operation_done() is called | ||
155 | * @param cb the callback to call when the peer has been created | 199 | * @param cb the callback to call when the peer has been created |
156 | * @param cls the closure to the above callback | 200 | * @param cls the closure to the above callback |
157 | * @return the operation handle | 201 | * @return the operation handle |