Exemplo n.º 1
0
bool
OverlayImpl::isPeerUpgrade(beast::http::message const& request)
{
    if (! request.upgrade())
        return false;
    auto const versions = parse_ProtocolVersions(
        request.headers["Upgrade"]);
    if (versions.size() == 0)
        return false;
    if (! request.request() && request.status() != 101)
        return false;
    return true;
}
Exemplo n.º 2
0
std::pair<protocol::TMHello, bool>
parseHello (beast::http::message const& m, beast::Journal journal)
{
    auto const& h = m.headers;
    std::pair<protocol::TMHello, bool> result = { {}, false };
    protocol::TMHello& hello = result.first;

    // protocol version in TMHello is obsolete,
    // it is supplanted by the values in the headers.

    {
        // Required
        auto const iter = h.find ("Upgrade");
        if (iter == h.end())
            return result;
        auto const versions = parse_ProtocolVersions(iter->second);
        if (versions.empty())
            return result;
        hello.set_protoversion(
            (static_cast<std::uint32_t>(versions.back().first) << 16) |
            (static_cast<std::uint32_t>(versions.back().second)));
        hello.set_protoversionmin(
            (static_cast<std::uint32_t>(versions.front().first) << 16) |
            (static_cast<std::uint32_t>(versions.front().second)));
    }

    {
        // Required
        auto const iter = h.find ("Public-Key");
        if (iter == h.end())
            return result;
        RippleAddress addr;
        addr.setNodePublic (iter->second);
        if (! addr.isValid())
            return result;
        hello.set_nodepublic (iter->second);
    }

    {
        // Required
        auto const iter = h.find ("Session-Signature");
        if (iter == h.end())
            return result;
        // TODO Security Review
        hello.set_nodeproof (beast::base64_decode (iter->second));
    }

    {
        auto const iter = h.find (m.request() ?
                                  "User-Agent" : "Server");
        if (iter != h.end())
            hello.set_fullversion (iter->second);
    }

    {
        auto const iter = h.find ("Network-Time");
        if (iter != h.end())
        {
            std::uint64_t nettime;
            if (! beast::lexicalCastChecked(nettime, iter->second))
                return result;
            hello.set_nettime (nettime);
        }
    }

    {
        auto const iter = h.find ("Ledger");
        if (iter != h.end())
        {
            LedgerIndex ledgerIndex;
            if (! beast::lexicalCastChecked(ledgerIndex, iter->second))
                return result;
            hello.set_ledgerindex (ledgerIndex);
        }
    }

    {
        auto const iter = h.find ("Closed-Ledger");
        if (iter != h.end())
            hello.set_ledgerclosed (beast::base64_decode (iter->second));
    }

    {
        auto const iter = h.find ("Previous-Ledger");
        if (iter != h.end())
            hello.set_ledgerprevious (beast::base64_decode (iter->second));
    }

    result.second = true;
    return result;
}