예제 #1
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);
}
예제 #2
0
bool is_disconnected_and_cleanup(const std::string& addr,
        n::connection_manager& con, 
        sc::encrypted_channels& sec) 
{
    if(con.is_disconnected(addr))
    {
        sec.remove_channel(addr);
        return true;
    }
    return false;
}
예제 #3
0
void register_user(
        n::connection_manager& con, 
        sc::session_library& sec, 
        const n::endpoint& ep, 
        const ms::greet_register& r, 
        user_info_map& m)
{
    auto address = n::make_address_str(ep);
    if(r.id().empty()) return;
    if(con.is_disconnected(address)) return;

    //use user specified ip, otherwise use socket ip
    ms::greet_endpoint local = r.local();
    ms::greet_endpoint ext = {ep.address, ep.port};

    user_info i = {r.id(), local, ext, r.response_service_address(), ep};
    m[i.id] = i;

    sec.create_session(address, r.pub_key());

    LOG << "registered " << i.id << " " << i.ext.ip << ":" << i.ext.port << std::endl;
}