diff options
-rw-r--r-- | toxcore/Messenger.c | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 10e36746..3617d554 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1455,7 +1455,7 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length) | |||
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | /* Function to filter out some friend requests*/ | 1457 | /* Function to filter out some friend requests*/ |
1458 | static int friend_already_added(uint8_t * client_id, void * data) | 1458 | static int friend_already_added(uint8_t *client_id, void *data) |
1459 | { | 1459 | { |
1460 | Messenger *m = data; | 1460 | Messenger *m = data; |
1461 | 1461 | ||
@@ -1948,7 +1948,30 @@ void do_messenger(Messenger *m) | |||
1948 | 1948 | ||
1949 | loglog(" = = = = = = = = \n"); | 1949 | loglog(" = = = = = = = = \n"); |
1950 | 1950 | ||
1951 | uint32_t num_friends = MIN(m->numfriends, m->dht->num_friends); | 1951 | uint32_t friend, dhtfriend; |
1952 | |||
1953 | /* dht contains additional "friends" (requests) */ | ||
1954 | uint32_t num_dhtfriends = m->dht->num_friends; | ||
1955 | int32_t m2dht[num_dhtfriends]; | ||
1956 | int32_t dht2m[num_dhtfriends]; | ||
1957 | |||
1958 | for (friend = 0; friend < num_dhtfriends; friend++) { | ||
1959 | m2dht[friend] = -1; | ||
1960 | dht2m[friend] = -1; | ||
1961 | |||
1962 | if (friend >= m->numfriends) | ||
1963 | continue; | ||
1964 | |||
1965 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) | ||
1966 | if (id_equal(m->friendlist[friend].client_id, m->dht->friends_list[dhtfriend].client_id)) { | ||
1967 | m2dht[friend] = dhtfriend; | ||
1968 | break; | ||
1969 | } | ||
1970 | } | ||
1971 | |||
1972 | for (friend = 0; friend < num_dhtfriends; friend++) | ||
1973 | if (m2dht[friend] >= 0) | ||
1974 | dht2m[m2dht[friend]] = friend; | ||
1952 | 1975 | ||
1953 | if (m->numfriends != m->dht->num_friends) { | 1976 | if (m->numfriends != m->dht->num_friends) { |
1954 | sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n", | 1977 | sprintf(logbuffer, "Friend num in DHT %u != friend num in msger %u\n", |
@@ -1956,33 +1979,33 @@ void do_messenger(Messenger *m) | |||
1956 | loglog(logbuffer); | 1979 | loglog(logbuffer); |
1957 | } | 1980 | } |
1958 | 1981 | ||
1959 | uint32_t friend, ping_lastrecv; | 1982 | uint32_t ping_lastrecv; |
1983 | Friend *msgfptr; | ||
1984 | DHT_Friend *dhtfptr; | ||
1960 | 1985 | ||
1961 | for (friend = 0; friend < num_friends; friend++) { | 1986 | for (friend = 0; friend < num_dhtfriends; friend++) { |
1962 | Friend *msgfptr = &m->friendlist[friend]; | 1987 | if (dht2m[friend] >= 0) |
1963 | DHT_Friend *dhtfptr = &m->dht->friends_list[friend]; | 1988 | msgfptr = &m->friendlist[dht2m[friend]]; |
1989 | else | ||
1990 | msgfptr = NULL; | ||
1964 | 1991 | ||
1965 | if (memcmp(msgfptr->client_id, dhtfptr->client_id, CLIENT_ID_SIZE)) { | 1992 | dhtfptr = &m->dht->friends_list[friend]; |
1966 | if (sizeof(logbuffer) > 2 * CLIENT_ID_SIZE + 64) { | ||
1967 | sprintf(logbuffer, "F[%2u] ID(m) %s != ID(d) ", friend, | ||
1968 | ID2String(msgfptr->client_id)); | ||
1969 | strcat(logbuffer + strlen(logbuffer), ID2String(dhtfptr->client_id)); | ||
1970 | strcat(logbuffer + strlen(logbuffer), "\n"); | ||
1971 | } else | ||
1972 | sprintf(logbuffer, "F[%2u] ID(m) != ID(d) ", friend); | ||
1973 | 1993 | ||
1974 | loglog(logbuffer); | 1994 | if (msgfptr) { |
1975 | } | 1995 | ping_lastrecv = lastdump - msgfptr->ping_lastrecv; |
1976 | 1996 | ||
1977 | ping_lastrecv = lastdump - msgfptr->ping_lastrecv; | 1997 | if (ping_lastrecv > 999) |
1998 | ping_lastrecv = 999; | ||
1978 | 1999 | ||
1979 | if (ping_lastrecv > 999) | 2000 | snprintf(logbuffer, sizeof(logbuffer), "F[%2u:%2u] <%s> %02i [%03u] %s\n", |
1980 | ping_lastrecv = 999; | 2001 | dht2m[friend], friend, msgfptr->name, msgfptr->crypt_connection_id, |
1981 | 2002 | ping_lastrecv, ID2String(msgfptr->client_id)); | |
1982 | snprintf(logbuffer, sizeof(logbuffer), "F[%2u] <%s> %02u [%03u] %s\n", | 2003 | loglog(logbuffer); |
1983 | friend, msgfptr->name, msgfptr->crypt_connection_id, | 2004 | } else { |
1984 | ping_lastrecv, ID2String(msgfptr->client_id)); | 2005 | snprintf(logbuffer, sizeof(logbuffer), "F[--:%2u] %s\n", |
1985 | loglog(logbuffer); | 2006 | friend, ID2String(dhtfptr->client_id)); |
2007 | loglog(logbuffer); | ||
2008 | } | ||
1986 | 2009 | ||
1987 | for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { | 2010 | for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { |
1988 | Client_data *cptr = &dhtfptr->client_list[client]; | 2011 | Client_data *cptr = &dhtfptr->client_list[client]; |