diff options
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple.c')
-rw-r--r-- | src/transport/transport_api_cmd_send_simple.c | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index 4a60f1a12..f9e515c0f 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c | |||
@@ -26,21 +26,45 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "transport-testing.h" | 29 | #include "transport-testing2.h" |
30 | #include "transport-testing-cmds.h" | ||
30 | 31 | ||
32 | /** | ||
33 | * Struct to hold information for callbacks. | ||
34 | * | ||
35 | */ | ||
31 | struct SendSimpleState | 36 | struct SendSimpleState |
32 | { | 37 | { |
38 | /** | ||
39 | * The number of the local node of the actual network namespace. | ||
40 | * | ||
41 | */ | ||
33 | char *m; | 42 | char *m; |
34 | 43 | ||
44 | /** | ||
45 | * The number of the actual namespace. | ||
46 | * | ||
47 | */ | ||
35 | char *n; | 48 | char *n; |
36 | 49 | ||
50 | /** | ||
51 | * Number globally identifying the node. | ||
52 | * | ||
53 | */ | ||
37 | uint32_t num; | 54 | uint32_t num; |
38 | 55 | ||
39 | const char *peer1_label; | 56 | /** |
40 | 57 | * Label of the cmd to start a peer. | |
41 | const char *peer2_label; | 58 | * |
59 | */ | ||
60 | const char *start_peer_label; | ||
42 | }; | 61 | }; |
43 | 62 | ||
63 | |||
64 | /** | ||
65 | * Trait function of this cmd does nothing. | ||
66 | * | ||
67 | */ | ||
44 | static int | 68 | static int |
45 | send_simple_traits (void *cls, | 69 | send_simple_traits (void *cls, |
46 | const void **ret, | 70 | const void **ret, |
@@ -51,6 +75,10 @@ send_simple_traits (void *cls, | |||
51 | } | 75 | } |
52 | 76 | ||
53 | 77 | ||
78 | /** | ||
79 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
80 | * | ||
81 | */ | ||
54 | static void | 82 | static void |
55 | send_simple_cleanup (void *cls, | 83 | send_simple_cleanup (void *cls, |
56 | const struct GNUNET_TESTING_Command *cmd) | 84 | const struct GNUNET_TESTING_Command *cmd) |
@@ -61,6 +89,10 @@ send_simple_cleanup (void *cls, | |||
61 | } | 89 | } |
62 | 90 | ||
63 | 91 | ||
92 | /** | ||
93 | * The run method of this cmd will send a simple message to the connected peer. | ||
94 | * | ||
95 | */ | ||
64 | static void | 96 | static void |
65 | send_simple_run (void *cls, | 97 | send_simple_run (void *cls, |
66 | const struct GNUNET_TESTING_Command *cmd, | 98 | const struct GNUNET_TESTING_Command *cmd, |
@@ -70,21 +102,24 @@ send_simple_run (void *cls, | |||
70 | struct GNUNET_MQ_Envelope *env; | 102 | struct GNUNET_MQ_Envelope *env; |
71 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | 103 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; |
72 | struct GNUNET_MQ_Handle *mq; | 104 | struct GNUNET_MQ_Handle *mq; |
73 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; | 105 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; |
74 | struct GNUNET_PeerIdentity *id; | ||
75 | const struct GNUNET_TESTING_Command *peer1_cmd; | 106 | const struct GNUNET_TESTING_Command *peer1_cmd; |
76 | const struct GNUNET_TESTING_Command *peer2_cmd; | 107 | struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); |
108 | struct GNUNET_HashCode hc; | ||
109 | int node_number; | ||
77 | 110 | ||
78 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); | 111 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); |
79 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, | 112 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, |
80 | &connected_peers_map); | 113 | &connected_peers_map); |
81 | 114 | ||
82 | peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer2_label); | 115 | node_number = 1; |
83 | GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd, | 116 | GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); |
84 | &id); | 117 | memcpy (key, |
118 | &hc, | ||
119 | sizeof (*key)); | ||
85 | 120 | ||
86 | mq = GNUNET_CONTAINER_multipeermap_get (connected_peers_map, | 121 | mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, |
87 | id); | 122 | key); |
88 | 123 | ||
89 | env = GNUNET_MQ_msg_extra (test, | 124 | env = GNUNET_MQ_msg_extra (test, |
90 | 2600 - sizeof(*test), | 125 | 2600 - sizeof(*test), |
@@ -93,12 +128,9 @@ send_simple_run (void *cls, | |||
93 | memset (&test[1], | 128 | memset (&test[1], |
94 | sss->num, | 129 | sss->num, |
95 | 2600 - sizeof(*test)); | 130 | 2600 - sizeof(*test)); |
96 | /*GNUNET_MQ_notify_sent (env, | ||
97 | cont, | ||
98 | cont_cls);*/ | ||
99 | GNUNET_MQ_send (mq, | 131 | GNUNET_MQ_send (mq, |
100 | env); | 132 | env); |
101 | 133 | GNUNET_free (key); | |
102 | 134 | ||
103 | } | 135 | } |
104 | 136 | ||
@@ -107,15 +139,18 @@ send_simple_run (void *cls, | |||
107 | * Create command. | 139 | * Create command. |
108 | * | 140 | * |
109 | * @param label name for command. | 141 | * @param label name for command. |
142 | * @param m The number of the local node of the actual network namespace. | ||
143 | * @param n The number of the actual namespace. | ||
144 | * @param num Number globally identifying the node. | ||
145 | * @param start_peer_label Label of the cmd to start a peer. | ||
110 | * @return command. | 146 | * @return command. |
111 | */ | 147 | */ |
112 | struct GNUNET_TESTING_Command | 148 | struct GNUNET_TESTING_Command |
113 | GNUNET_TESTING_cmd_send_simple (const char *label, | 149 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, |
114 | char *m, | 150 | char *m, |
115 | char *n, | 151 | char *n, |
116 | uint32_t num, | 152 | uint32_t num, |
117 | const char *peer1_label, | 153 | const char *start_peer_label) |
118 | const char *peer2_label) | ||
119 | { | 154 | { |
120 | struct SendSimpleState *sss; | 155 | struct SendSimpleState *sss; |
121 | 156 | ||
@@ -123,6 +158,7 @@ GNUNET_TESTING_cmd_send_simple (const char *label, | |||
123 | sss->m = m; | 158 | sss->m = m; |
124 | sss->n = n; | 159 | sss->n = n; |
125 | sss->num = num; | 160 | sss->num = num; |
161 | sss->start_peer_label = start_peer_label; | ||
126 | 162 | ||
127 | struct GNUNET_TESTING_Command cmd = { | 163 | struct GNUNET_TESTING_Command cmd = { |
128 | .cls = sss, | 164 | .cls = sss, |