Пример #1
0
void find_user(
        n::connection_manager& con, 
        sc::encrypted_channels& sec, 
        const n::endpoint& ep, 
        const ms::greet_find_request& r, 
        user_info_map& users)
{
    //find from user
    auto fup = users.find(r.from_id());
    if(fup == users.end()) return;
    if(fup->second.tcp_ep.protocol.empty()) return;

    //find search user
    auto up = users.find(r.search_id());
    if(up == users.end()) return;
    if(up->second.tcp_ep.protocol.empty()) return;

    auto& f = fup->second;
    auto& i = up->second;

    //don't send match if either is disconnected
    auto f_addr = n::make_address_str(f.tcp_ep);
    if(is_disconnected_and_cleanup(f_addr, con, sec)) return;

    auto i_addr = n::make_address_str(i.tcp_ep);
    if(is_disconnected_and_cleanup(i_addr, con, sec)) return;

    //send response to both clients
    ms::greet_find_response fr{true, i.id, i.local,  i.ext};
    send_response(con, sec, fr, f);

    ms::greet_find_response ir{true, f.id, f.local,  f.ext};
    send_response(con, sec, ir, i);
}
Пример #2
0
void find_user(
        n::connection_manager& con, 
        sc::session_library& sec, 
        const n::endpoint& ep, 
        const ms::greet_find_request& r, 
        user_info_map& users)
{
    //find from user
    auto fup = users.find(r.from_id());
    if(fup == users.end()) return;

    //find search user
    auto up = users.find(r.search_id());
    if(up == users.end()) return;

    auto& f = fup->second;
    if(con.is_disconnected(n::make_address_str(ep))) return;
    f.ep = ep;

    auto& i = up->second;

    LOG << "found match " << f.id << " " << f.ext.ip << ":" << f.ext.port << " <==> " <<  i.id << " " << i.ext.ip << ":" << i.ext.port << std::endl;

    //send response to both clients
    ms::greet_find_response fr{true, i.id, i.local,  i.ext};
    send_response(con, sec, fr, f);

    ms::greet_find_response ir{true, f.id, f.local,  f.ext};
    send_response(con, sec, ir, i);
}