wish_app/wish_app.c
void wish_app_on_peer(wish_app_t *app, const uint8_t *peer_doc) {
    //WISHDEBUG(LOG_CRITICAL, "Peer information to app");
    //bson_visit(peer_doc, elem_visitor);

    bson_iterator it;
    
    if (bson_find_from_buffer(&it, peer_doc, "protocol") != BSON_STRING) {
        WISHDEBUG(LOG_CRITICAL, "Cannot get protocol elem from peer");
        return;
    }
    
    const char *protocol_name = bson_iterator_string(&it);

    bool protocol_online = false;
    
    if (bson_find_from_buffer(&it, peer_doc, "online") == BSON_BOOL) {
        protocol_online = bson_iterator_bool(&it);
    }
    
    /* We now know the protocol, lets lookup the protocol handler */

    wish_protocol_handler_t* protocol = NULL;
    
    int i = 0;
    for (i = 0; i < app->num_protocols; i++) {
        if (strncmp(app->protocols[i]->protocol_name, protocol_name, WISH_PROTOCOL_NAME_MAX_LEN) == 0) {
            /* Found protocol handler */
            if (app->protocols[i]->on_online != NULL || app->protocols[i]->on_offline != NULL) {
                protocol = app->protocols[i];
            } else {
                WISHDEBUG(LOG_CRITICAL, "There is no handler for online or offline messages for protocol %s, on: %p, off: %p", protocol_name, app->protocols[i]->on_online, app->protocols[i]->on_offline);
            }
            break;
        }
    }
    
    if(protocol) {
        // protocol handler found, get peer
        wish_protocol_peer_t peer;
        bool success = wish_protocol_peer_populate_from_bson(&peer, peer_doc);
        
        if(!success) { return; }
        
        if(protocol_online) {
            protocol->on_online(protocol->app_ctx, &peer);
        } else {
            protocol->on_offline(protocol->app_ctx, &peer);
        }
    }
}
/** Callback invoked when core has determined a change in the peer's
 * status */
Callback invoked when core has determined a change in the peer's
status
Callback invoked when core has determined a change in the peer ' s status
void wish_app_on_peer(wish_app_t *app, const uint8_t *peer_doc) {
    bson_iterator it;
    if (bson_find_from_buffer(&it, peer_doc, "protocol") != BSON_STRING) {
        WISHDEBUG(LOG_CRITICAL, "Cannot get protocol elem from peer");
        return;
    }
    const char *protocol_name = bson_iterator_string(&it);
    bool protocol_online = false;
    if (bson_find_from_buffer(&it, peer_doc, "online") == BSON_BOOL) {
        protocol_online = bson_iterator_bool(&it);
    }
    wish_protocol_handler_t* protocol = NULL;
    int i = 0;
    for (i = 0; i < app->num_protocols; i++) {
        if (strncmp(app->protocols[i]->protocol_name, protocol_name, WISH_PROTOCOL_NAME_MAX_LEN) == 0) {
            if (app->protocols[i]->on_online != NULL || app->protocols[i]->on_offline != NULL) {
                protocol = app->protocols[i];
            } else {
                WISHDEBUG(LOG_CRITICAL, "There is no handler for online or offline messages for protocol %s, on: %p, off: %p", protocol_name, app->protocols[i]->on_online, app->protocols[i]->on_offline);
            }
            break;
        }
    }
    if(protocol) {
        wish_protocol_peer_t peer;
        bool success = wish_protocol_peer_populate_from_bson(&peer, peer_doc);
        if(!success) { return; }
        if(protocol_online) {
            protocol->on_online(protocol->app_ctx, &peer);
        } else {
            protocol->on_offline(protocol->app_ctx, &peer);
        }
    }
}
void wish_app_on_peer ( wish_app_t * app , const uint8_t * peer_doc ) { bson_iterator it ; if ( bson_find_from_buffer ( & it , peer_doc , " " ) != BSON_STRING ) { WISHDEBUG ( LOG_CRITICAL , " " ) ; return ; } const char * protocol_name = bson_iterator_string ( & it ) ; bool protocol_online = false ; if ( bson_find_from_buffer ( & it , peer_doc , " " ) == BSON_BOOL ) { protocol_online = bson_iterator_bool ( & it ) ; } wish_protocol_handler_t * protocol = NULL ; int i = 0 ; for ( i = 0 ; i < app -> num_protocols ; i ++ ) { if ( strncmp ( app -> protocols [ i ] -> protocol_name , protocol_name , WISH_PROTOCOL_NAME_MAX_LEN ) == 0 ) { if ( app -> protocols [ i ] -> on_online != NULL || app -> protocols [ i ] -> on_offline != NULL ) { protocol = app -> protocols [ i ] ; } else { WISHDEBUG ( LOG_CRITICAL , " " , protocol_name , app -> protocols [ i ] -> on_online , app -> protocols [ i ] -> on_offline ) ; } break ; } } if ( protocol ) { wish_protocol_peer_t peer ; bool success = wish_protocol_peer_populate_from_bson ( & peer , peer_doc ) ; if ( ! success ) { return ; } if ( protocol_online ) { protocol -> on_online ( protocol -> app_ctx , & peer ) ; } else { protocol -> on_offline ( protocol -> app_ctx , & peer ) ; } } }
Callback invoked when core has determined a change in the peer's
 status
Callback invoked when core has determined a change in the peer ' s status
//WISHDEBUG(LOG_CRITICAL, "Peer information to app"); //bson_visit(peer_doc, elem_visitor); /* We now know the protocol, lets lookup the protocol handler */ /* Found protocol handler */ // protocol handler found, get peer