diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-13 17:06:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-13 17:06:48 +0000 |
commit | 007c852f2e43e658cb2581a62c03cd0ccbfd08f4 (patch) | |
tree | ef607b90e766c66602b7b6aaa025960eee635a21 /src/transport/plugin_transport_tcp.c | |
parent | d1c8ff7199e0b992d7aad432319a2d5833b55dce (diff) | |
download | gnunet-007c852f2e43e658cb2581a62c03cd0ccbfd08f4.tar.gz gnunet-007c852f2e43e658cb2581a62c03cd0ccbfd08f4.zip |
-move tcp session check into extra checks condition
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index e0572d5d0..5193551de 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -43,6 +43,8 @@ | |||
43 | 43 | ||
44 | #define PLUGIN_NAME "tcp" | 44 | #define PLUGIN_NAME "tcp" |
45 | 45 | ||
46 | #define EXTRA_CHECKS ALLOW_EXTRA_CHECKS | ||
47 | |||
46 | /** | 48 | /** |
47 | * How long until we give up on establishing an NAT connection? | 49 | * How long until we give up on establishing an NAT connection? |
48 | * Must be > 4 RTT | 50 | * Must be > 4 RTT |
@@ -1108,21 +1110,41 @@ tcp_disconnect_session (void *cls, | |||
1108 | } | 1110 | } |
1109 | 1111 | ||
1110 | 1112 | ||
1113 | #if EXTRA_CHECKS | ||
1114 | /** | ||
1115 | * Closure for #session_it(). | ||
1116 | */ | ||
1111 | struct FindSessionContext | 1117 | struct FindSessionContext |
1112 | { | 1118 | { |
1119 | /** | ||
1120 | * Session we are looking for. | ||
1121 | */ | ||
1113 | struct Session *s; | 1122 | struct Session *s; |
1123 | |||
1124 | /** | ||
1125 | * Set to #GNUNET_OK if we found the session. | ||
1126 | */ | ||
1114 | int res; | 1127 | int res; |
1115 | }; | 1128 | }; |
1116 | 1129 | ||
1117 | 1130 | ||
1131 | /** | ||
1132 | * Function called to check if a session is in our maps. | ||
1133 | * | ||
1134 | * @param cls the `struct FindSessionContext` | ||
1135 | * @param key peer identity | ||
1136 | * @param value session in the map | ||
1137 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | ||
1138 | */ | ||
1118 | static int | 1139 | static int |
1119 | session_it (void *cls, | 1140 | session_it (void *cls, |
1120 | const struct GNUNET_PeerIdentity * key, | 1141 | const struct GNUNET_PeerIdentity *key, |
1121 | void *value) | 1142 | void *value) |
1122 | { | 1143 | { |
1123 | struct FindSessionContext *res = cls; | 1144 | struct FindSessionContext *res = cls; |
1145 | struct Session *session = value; | ||
1124 | 1146 | ||
1125 | if (res->s == value) | 1147 | if (res->s == session) |
1126 | { | 1148 | { |
1127 | res->res = GNUNET_OK; | 1149 | res->res = GNUNET_OK; |
1128 | return GNUNET_NO; | 1150 | return GNUNET_NO; |
@@ -1131,27 +1153,37 @@ session_it (void *cls, | |||
1131 | } | 1153 | } |
1132 | 1154 | ||
1133 | 1155 | ||
1156 | /** | ||
1157 | * Check that the given session is known to the plugin and | ||
1158 | * is in one of our maps. | ||
1159 | * | ||
1160 | * @param plugin the plugin to check against | ||
1161 | * @param session the session to check | ||
1162 | * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid | ||
1163 | */ | ||
1134 | static int | 1164 | static int |
1135 | find_session (struct Plugin *plugin, struct Session *session) | 1165 | find_session (struct Plugin *plugin, |
1166 | struct Session *session) | ||
1136 | { | 1167 | { |
1137 | struct FindSessionContext session_map_res; | 1168 | struct FindSessionContext session_map_res; |
1138 | struct FindSessionContext nat_map_res; | 1169 | struct FindSessionContext nat_map_res; |
1139 | 1170 | ||
1140 | session_map_res.s = session; | 1171 | session_map_res.s = session; |
1141 | session_map_res.res = GNUNET_SYSERR; | 1172 | session_map_res.res = GNUNET_SYSERR; |
1142 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it, &session_map_res); | 1173 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
1143 | 1174 | &session_it, &session_map_res); | |
1175 | if (GNUNET_SYSERR != session_map_res.res) | ||
1176 | return GNUNET_OK; | ||
1144 | nat_map_res.s = session; | 1177 | nat_map_res.s = session; |
1145 | nat_map_res.res = GNUNET_SYSERR; | 1178 | nat_map_res.res = GNUNET_SYSERR; |
1146 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it, &nat_map_res); | 1179 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, |
1147 | 1180 | &session_it, &nat_map_res); | |
1148 | if ((session_map_res.res == GNUNET_SYSERR) && (nat_map_res.res == GNUNET_SYSERR)) | 1181 | if (GNUNET_SYSERR != nat_map_res.res) |
1149 | { | 1182 | return GNUNET_OK; |
1150 | GNUNET_break (0); | 1183 | GNUNET_break (0); |
1151 | return GNUNET_SYSERR; | 1184 | return GNUNET_SYSERR; |
1152 | } | ||
1153 | return GNUNET_OK; | ||
1154 | } | 1185 | } |
1186 | #endif | ||
1155 | 1187 | ||
1156 | 1188 | ||
1157 | /** | 1189 | /** |
@@ -1183,25 +1215,23 @@ find_session (struct Plugin *plugin, struct Session *session) | |||
1183 | */ | 1215 | */ |
1184 | static ssize_t | 1216 | static ssize_t |
1185 | tcp_plugin_send (void *cls, | 1217 | tcp_plugin_send (void *cls, |
1186 | struct Session *session, | 1218 | struct Session *session, |
1187 | const char *msgbuf, size_t msgbuf_size, | 1219 | const char *msgbuf, size_t msgbuf_size, |
1188 | unsigned int priority, | 1220 | unsigned int priority, |
1189 | struct GNUNET_TIME_Relative to, | 1221 | struct GNUNET_TIME_Relative to, |
1190 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 1222 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1191 | { | 1223 | { |
1192 | struct Plugin * plugin = cls; | 1224 | struct Plugin * plugin = cls; |
1193 | struct PendingMessage *pm; | 1225 | struct PendingMessage *pm; |
1194 | 1226 | ||
1195 | GNUNET_assert (NULL != plugin); | 1227 | #if EXTRA_CHECKS |
1196 | GNUNET_assert (NULL != session); | 1228 | if (GNUNET_SYSERR == find_session (plugin, session)) |
1197 | |||
1198 | if (GNUNET_SYSERR == find_session(plugin, session)) | ||
1199 | { | 1229 | { |
1200 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1230 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1201 | _("Trying to send with invalid session %p\n")); | 1231 | _("Trying to send with invalid session %p\n")); |
1202 | return GNUNET_SYSERR; | 1232 | return GNUNET_SYSERR; |
1203 | } | 1233 | } |
1204 | 1234 | #endif | |
1205 | /* create new message entry */ | 1235 | /* create new message entry */ |
1206 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); | 1236 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); |
1207 | pm->msg = (const char *) &pm[1]; | 1237 | pm->msg = (const char *) &pm[1]; |