src/mist_api.c
static void clean_up_peers_db(mist_api_t *mist_api) {
    peers_list *elem = NULL;
    peers_list *tmp = NULL;
    
    /* Iterate through the peers list */
    LL_FOREACH_SAFE(mist_api->peers_db, elem, tmp) {
        bool ruid_known = false;
        bool luid_known = false;
        
        /* For each peer, check that we still known the remote party (ruid in identity list) */
        for (int i = 0; i < MIST_API_MAX_UIDS; i++) {
            if ( mist_api->identities[i].occupied ) { 
                if (memcmp(elem->peer.ruid, mist_api->identities[i].uid, 32) == 0) {
                    ruid_known = true;
                }
                if (memcmp(elem->peer.luid, mist_api->identities[i].uid, 32) == 0) {
                    luid_known = true;
                }
            }
        }
        
        /* If we encounter a peer, for which luid AND ruid are not known, they should be removed. */
        if ( (luid_known && ruid_known) == false ) {   
            if (!elem->peer.online) {
                /* Peer is offline, as expected */
                /*
                WISHDEBUG(LOG_CRITICAL, "clean_up_peers_db:%s%s unknown, removing peer! (luid %x %x %x... ruid: %x %x %x...)", luid_known?"":" luid", ruid_known?"":" ruid", 
                        elem->peer.luid[0], elem->peer.luid[1], elem->peer.luid[2], 
                        elem->peer.ruid[0], elem->peer.ruid[1], elem->peer.ruid[2]);
                */
                
                //  we should remove all peers from all sandboxes that have this identity as a ruid
                mist_sandbox_remove_peers_by_uid(mist_api, elem->peer.ruid);
                /* Remove the peer from peers_db */
                LL_DELETE(mist_api->peers_db, elem);
                wish_platform_free(elem);
                /* persist peers list now */
                mist_api_peers_db_save(mist_api);
            }
            else {
                /* Identity not in identity list, but still online? This is an anomaly that can occur when identity is removed on the fly. 
                 * The 'identity' signal is triggered first, and only then 'connections'. We solve the issue by performing peers db cleanup also at 'offline' signal. */
                /*
                WISHDEBUG(LOG_CRITICAL, "clean_up_peers_db:%s%s unknown, but peer is online, this is unexpected! (luid %x %x %x... ruid: %x %x %x...)", luid_known?"":" luid", ruid_known?"":" ruid", 
                        elem->peer.luid[0], elem->peer.luid[1], elem->peer.luid[2], 
                        elem->peer.ruid[0], elem->peer.ruid[1], elem->peer.ruid[2]);
                */
            }
        }
        
    }
            
}
/**
 * This function iterates through the peers list of a mist_api, and removes any peer whose luid and ruid is no longer in the identities list of mist_api.
 * In order to function correctly, this function should be run after the mist_api identity list is updated.
 * Both luid and ruid identities must known, if not the peer is removed from list (but only if it is marked as offline).
 * 
 * @param mist_api the mist_api on which to act.
 */
This function iterates through the peers list of a mist_api, and removes any peer whose luid and ruid is no longer in the identities list of mist_api.
In order to function correctly, this function should be run after the mist_api identity list is updated.
Both luid and ruid identities must known, if not the peer is removed from list (but only if it is marked as offline).

@param mist_api the mist_api on which to act.
This function iterates through the peers list of a mist_api and removes any peer whose luid and ruid is no longer in the identities list of mist_api . In order to function correctly this function should be run after the mist_api identity list is updated . Both luid and ruid identities must known if not the peer is removed from list ( but only if it is marked as offline ) . @param mist_api the mist_api on which to act .
static void clean_up_peers_db(mist_api_t *mist_api) {
    peers_list *elem = NULL;
    peers_list *tmp = NULL;
    LL_FOREACH_SAFE(mist_api->peers_db, elem, tmp) {
        bool ruid_known = false;
        bool luid_known = false;
        for (int i = 0; i < MIST_API_MAX_UIDS; i++) {
            if ( mist_api->identities[i].occupied ) { 
                if (memcmp(elem->peer.ruid, mist_api->identities[i].uid, 32) == 0) {
                    ruid_known = true;
                }
                if (memcmp(elem->peer.luid, mist_api->identities[i].uid, 32) == 0) {
                    luid_known = true;
                }
            }
        }
        if ( (luid_known && ruid_known) == false ) {   
            if (!elem->peer.online) {
                mist_sandbox_remove_peers_by_uid(mist_api, elem->peer.ruid);
                LL_DELETE(mist_api->peers_db, elem);
                wish_platform_free(elem);
                mist_api_peers_db_save(mist_api);
            }
            else {
            }
        }
    }
}
static void clean_up_peers_db ( mist_api_t * mist_api ) { peers_list * elem = NULL ; peers_list * tmp = NULL ; LL_FOREACH_SAFE ( mist_api -> peers_db , elem , tmp ) { bool ruid_known = false ; bool luid_known = false ; for ( int i = 0 ; i < MIST_API_MAX_UIDS ; i ++ ) { if ( mist_api -> identities [ i ] . occupied ) { if ( memcmp ( elem -> peer . ruid , mist_api -> identities [ i ] . uid , 32 ) == 0 ) { ruid_known = true ; } if ( memcmp ( elem -> peer . luid , mist_api -> identities [ i ] . uid , 32 ) == 0 ) { luid_known = true ; } } } if ( ( luid_known && ruid_known ) == false ) { if ( ! elem -> peer . online ) { mist_sandbox_remove_peers_by_uid ( mist_api , elem -> peer . ruid ) ; LL_DELETE ( mist_api -> peers_db , elem ) ; wish_platform_free ( elem ) ; mist_api_peers_db_save ( mist_api ) ; } else { } } } }
This function iterates through the peers list of a mist_api, and removes any peer whose luid and ruid is no longer in the identities list of mist_api.
This function iterates through the peers list of a mist_api and removes any peer whose luid and ruid is no longer in the identities list of mist_api .
/* Iterate through the peers list */ /* For each peer, check that we still known the remote party (ruid in identity list) */ /* If we encounter a peer, for which luid AND ruid are not known, they should be removed. */ /* Peer is offline, as expected */ /*
                WISHDEBUG(LOG_CRITICAL, "clean_up_peers_db:%s%s unknown, removing peer! (luid %x %x %x... ruid: %x %x %x...)", luid_known?"":" luid", ruid_known?"":" ruid", 
                        elem->peer.luid[0], elem->peer.luid[1], elem->peer.luid[2], 
                        elem->peer.ruid[0], elem->peer.ruid[1], elem->peer.ruid[2]);
                */ //  we should remove all peers from all sandboxes that have this identity as a ruid /* Remove the peer from peers_db */ /* persist peers list now */ /* Identity not in identity list, but still online? This is an anomaly that can occur when identity is removed on the fly. 
                 * The 'identity' signal is triggered first, and only then 'connections'. We solve the issue by performing peers db cleanup also at 'offline' signal. */ /*
                WISHDEBUG(LOG_CRITICAL, "clean_up_peers_db:%s%s unknown, but peer is online, this is unexpected! (luid %x %x %x... ruid: %x %x %x...)", luid_known?"":" luid", ruid_known?"":" ruid", 
                        elem->peer.luid[0], elem->peer.luid[1], elem->peer.luid[2], 
                        elem->peer.ruid[0], elem->peer.ruid[1], elem->peer.ruid[2]);
                */