summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-09-14 12:42:17 -0400
committerirungentoo <irungentoo@gmail.com>2013-09-14 12:42:17 -0400
commit12d1c5199bd2feecd93424ff57f44fab4bbb02ad (patch)
treecd5a20e0c995199a383efd0a77ca0efb0033cfb6 /toxcore/Messenger.c
parent64d000cdfaed710d3e22fa5444b8c2883b9f09d6 (diff)
astyled everything.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c159
1 files changed, 87 insertions, 72 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 55b27353..eb18e3a3 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1225,11 +1225,13 @@ static time_t lastdump = 0;
1225static char IDString[CLIENT_ID_SIZE * 2 + 1]; 1225static char IDString[CLIENT_ID_SIZE * 2 + 1];
1226static char *ID2String(uint8_t *client_id) 1226static char *ID2String(uint8_t *client_id)
1227{ 1227{
1228 uint32_t i; 1228 uint32_t i;
1229 for(i = 0; i < CLIENT_ID_SIZE; i++) 1229
1230 sprintf(&IDString[i], "%02X", client_id[i]); 1230 for (i = 0; i < CLIENT_ID_SIZE; i++)
1231 IDString[CLIENT_ID_SIZE * 2] = 0; 1231 sprintf(&IDString[i], "%02X", client_id[i]);
1232 return IDString; 1232
1233 IDString[CLIENT_ID_SIZE * 2] = 0;
1234 return IDString;
1233} 1235}
1234#endif 1236#endif
1235 1237
@@ -1246,73 +1248,85 @@ void doMessenger(Messenger *m)
1246 LANdiscovery(m); 1248 LANdiscovery(m);
1247 1249
1248#ifdef LOGGING 1250#ifdef LOGGING
1249 if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { 1251
1250 loglog(" = = = = = = = = \n"); 1252 if (now() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
1251 1253 loglog(" = = = = = = = = \n");
1252 lastdump = now(); 1254
1253 uint32_t client, last_pinged; 1255 lastdump = now();
1254 for(client = 0; client < LCLIENT_LIST; client++) { 1256 uint32_t client, last_pinged;
1255 Client_data *cptr = &m->dht->close_clientlist[client]; 1257
1256 if (ip_isset(&cptr->ip_port.ip)) { 1258 for (client = 0; client < LCLIENT_LIST; client++) {
1257 last_pinged = lastdump - cptr->last_pinged; 1259 Client_data *cptr = &m->dht->close_clientlist[client];
1258 if (last_pinged > 999) 1260
1259 last_pinged = 999; 1261 if (ip_isset(&cptr->ip_port.ip)) {
1260 snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n", 1262 last_pinged = lastdump - cptr->last_pinged;
1261 client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port), 1263
1262 last_pinged, ID2String(cptr->client_id)); 1264 if (last_pinged > 999)
1263 loglog(logbuffer); 1265 last_pinged = 999;
1264 } 1266
1265 } 1267 snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
1266 1268 client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port),
1267 loglog(" = = = = = = = = \n"); 1269 last_pinged, ID2String(cptr->client_id));
1268 1270 loglog(logbuffer);
1269 uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends); 1271 }
1270 if (m->numfriends != m->dht->num_friends) { 1272 }
1271 sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n", 1273
1272 m->dht->num_friends, m->numfriends); 1274 loglog(" = = = = = = = = \n");
1273 loglog(logbuffer); 1275
1274 } 1276 uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends);
1275 1277
1276 uint32_t friend, ping_lastrecv; 1278 if (m->numfriends != m->dht->num_friends) {
1277 for(friend = 0; friend < num_friends; friend++) { 1279 sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n",
1278 Friend *msgfptr = &m->friendlist[friend]; 1280 m->dht->num_friends, m->numfriends);
1279 DHT_Friend *dhtfptr = &m->dht->friends_list[friend]; 1281 loglog(logbuffer);
1280 if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) { 1282 }
1281 if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) { 1283
1282 sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend, 1284 uint32_t friend, ping_lastrecv;
1283 ID2String(msgfptr->client_id)); 1285
1284 strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id)); 1286 for (friend = 0; friend < num_friends; friend++) {
1285 strcat(logbuffer + strlen(logbuffer), "\n"); 1287 Friend *msgfptr = &m->friendlist[friend];
1286 } 1288 DHT_Friend *dhtfptr = &m->dht->friends_list[friend];
1287 else 1289
1288 sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend); 1290 if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) {
1289 1291 if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) {
1290 loglog(logbuffer); 1292 sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend,
1291 } 1293 ID2String(msgfptr->client_id));
1292 1294 strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id));
1293 ping_lastrecv = lastdump - msgfptr->ping_lastrecv; 1295 strcat(logbuffer + strlen(logbuffer), "\n");
1294 if (ping_lastrecv > 999) 1296 } else
1295 ping_lastrecv = 999; 1297 sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend);
1296 snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n", 1298
1297 friend, msgfptr->name, msgfptr->crypt_connection_id, 1299 loglog(logbuffer);
1298 ping_lastrecv, ID2String(msgfptr->client_id)); 1300 }
1299 loglog(logbuffer); 1301
1300 1302 ping_lastrecv = lastdump - msgfptr->ping_lastrecv;
1301 for(client = 0; client < MAX_FRIEND_CLIENTS; client++) { 1303
1302 Client_data *cptr = &dhtfptr->client_list[client]; 1304 if (ping_lastrecv > 999)
1303 last_pinged = lastdump - cptr->last_pinged; 1305 ping_lastrecv = 999;
1304 if (last_pinged > 999) 1306
1305 last_pinged = 999; 1307 snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n",
1306 snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n", 1308 friend, msgfptr->name, msgfptr->crypt_connection_id,
1307 friend, client, ip_ntoa(&cptr->ip_port.ip), 1309 ping_lastrecv, ID2String(msgfptr->client_id));
1308 ntohs(cptr->ip_port.port), last_pinged, 1310 loglog(logbuffer);
1309 ID2String(cptr->client_id)); 1311
1310 loglog(logbuffer); 1312 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
1311 } 1313 Client_data *cptr = &dhtfptr->client_list[client];
1312 } 1314 last_pinged = lastdump - cptr->last_pinged;
1313 1315
1314 loglog(" = = = = = = = = \n"); 1316 if (last_pinged > 999)
1315 } 1317 last_pinged = 999;
1318
1319 snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
1320 friend, client, ip_ntoa(&cptr->ip_port.ip),
1321 ntohs(cptr->ip_port.port), last_pinged,
1322 ID2String(cptr->client_id));
1323 loglog(logbuffer);
1324 }
1325 }
1326
1327 loglog(" = = = = = = = = \n");
1328 }
1329
1316#endif 1330#endif
1317} 1331}
1318 1332
@@ -1410,6 +1424,7 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
1410 memcpy(temp, data, size); 1424 memcpy(temp, data, size);
1411 1425
1412 uint32_t i; 1426 uint32_t i;
1427
1413 for (i = 0; i < num; ++i) { 1428 for (i = 0; i < num; ++i) {
1414 if (temp[i].status >= 3) { 1429 if (temp[i].status >= 3) {
1415 int fnum = m_addfriend_norequest(m, temp[i].client_id); 1430 int fnum = m_addfriend_norequest(m, temp[i].client_id);