示例#1
0
void register_user(
        n::connection_manager& con, 
        sc::encrypted_channels& 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;

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

    //check to see if user already registers and
    //don't re-register if ip and port of local and external are the same
    bool is_udp = ep.protocol == "udp";
    if(m.count(r.id()))
    {
        auto& i = m[r.id()];
        update_address(i, local, ext, ep, is_udp);
    }
    else
    {
        n::endpoint tcp_ep;
        n::endpoint udp_ep;
        (is_udp ? udp_ep : tcp_ep) = ep;
        user_info i = {r.id(), local, ext, r.response_service_address(), tcp_ep, udp_ep};
        m[i.id] = i;
        LOG << "registered " << u::uuid() << std::endl;
    }

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

}
示例#2
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;
}