Skip to content

Commit

Permalink
Merge branch 'develop' into nft-trustline
Browse files Browse the repository at this point in the history
  • Loading branch information
seelabs authored Jun 18, 2024
2 parents d0fef14 + 8258640 commit fa2b678
Show file tree
Hide file tree
Showing 25 changed files with 141 additions and 90 deletions.
14 changes: 14 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ then you will need to choose the `libstdc++11` ABI:
conan profile update settings.compiler.libcxx=libstdc++11 default
```


Ensure inter-operability between `boost::string_view` and `std::string_view` types:

```
conan profile update 'conf.tools.build:cxxflags+=["-DBOOST_BEAST_USE_STD_STRING_VIEW"]' default
conan profile update 'env.CXXFLAGS="-DBOOST_BEAST_USE_STD_STRING_VIEW"' default
```

If you have other flags in the `conf.tools.build` or `env.CXXFLAGS` sections, make sure to retain the existing flags and append the new ones. You can check them with:
```
conan profile show default
```


**Windows** developers may need to use the x64 native build tools.
An easy way to do that is to run the shortcut "x64 Native Tools Command
Prompt" for the version of Visual Studio that you have installed.
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ this:
You can format individual files in place by running `clang-format -i <file>...`
from any directory within this project.

There is a Continuous Integration job that runs clang-format on pull requests. If the code doesn't comply, a patch file that corrects auto-fixable formatting issues is generated.

To download the patch file:

1. Next to `clang-format / check (pull_request) Failing after #s` -> click **Details** to open the details page.
2. Left menu -> click **Summary**
3. Scroll down to near the bottom-right under `Artifacts` -> click **clang-format.patch**
4. Download the zip file and extract it to your local git repository. Run `git apply [patch-file-name]`.
5. Commit and push.

You can install a pre-commit hook to automatically run `clang-format` before every commit:
```
pip3 install pre-commit
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ class ValidatorList
*/
std::optional<Json::Value>
getAvailable(
boost::beast::string_view const& pubKey,
std::string_view pubKey,
std::optional<std::uint32_t> forceVersion = {});

/** Return the number of configured validator list sites. */
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <boost/regex.hpp>

#include <cmath>
#include <mutex>
#include <numeric>
#include <shared_mutex>

Expand Down Expand Up @@ -215,7 +214,8 @@ ValidatorList::load(
return false;
}

auto const id = parseBase58<PublicKey>(TokenType::NodePublic, match[1]);
auto const id =
parseBase58<PublicKey>(TokenType::NodePublic, match[1].str());

if (!id)
{
Expand Down Expand Up @@ -1707,7 +1707,7 @@ ValidatorList::for_each_available(

std::optional<Json::Value>
ValidatorList::getAvailable(
boost::beast::string_view const& pubKey,
std::string_view pubKey,
std::optional<std::uint32_t> forceVersion /* = {} */)
{
std::shared_lock read_lock{mutex_};
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/basics/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ strUnHex(std::string const& strSrc)
}

inline std::optional<Blob>
strViewUnHex(boost::string_view const& strSrc)
strViewUnHex(std::string_view strSrc)
{
return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend());
}
Expand Down Expand Up @@ -150,7 +150,7 @@ to_uint64(std::string const& s);
doesn't check whether the TLD is valid.
*/
bool
isProperlyFormedTomlDomain(std::string const& domain);
isProperlyFormedTomlDomain(std::string_view domain);

} // namespace ripple

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/basics/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ base64_encode(std::string const& s)
}

std::string
base64_decode(std::string const& data);
base64_decode(std::string_view data);

} // namespace ripple

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/basics/impl/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ to_uint64(std::string const& s)
}

bool
isProperlyFormedTomlDomain(std::string const& domain)
isProperlyFormedTomlDomain(std::string_view domain)
{
// The domain must be between 4 and 128 characters long
if (domain.size() < 4 || domain.size() > 128)
Expand All @@ -143,7 +143,7 @@ isProperlyFormedTomlDomain(std::string const& domain)
,
boost::regex_constants::optimize);

return boost::regex_match(domain, re);
return boost::regex_match(domain.begin(), domain.end(), re);
}

} // namespace ripple
2 changes: 1 addition & 1 deletion src/ripple/basics/impl/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ base64_encode(std::uint8_t const* data, std::size_t len)
}

std::string
base64_decode(std::string const& data)
base64_decode(std::string_view data)
{
std::string dest;
dest.resize(base64::decoded_size(data.size()));
Expand Down
61 changes: 48 additions & 13 deletions src/ripple/beast/core/LexicalCast.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef BEAST_MODULE_CORE_TEXT_LEXICALCAST_H_INCLUDED
#define BEAST_MODULE_CORE_TEXT_LEXICALCAST_H_INCLUDED

#include <boost/core/detail/string_view.hpp>
#include <algorithm>
#include <cassert>
#include <cerrno>
Expand Down Expand Up @@ -64,9 +65,9 @@ struct LexicalCast<std::string, In>
}
};

// Parse std::string to number
template <class Out>
struct LexicalCast<Out, std::string>
// Parse a std::string_view into a number
template <typename Out>
struct LexicalCast<Out, std::string_view>
{
explicit LexicalCast() = default;

Expand All @@ -78,7 +79,7 @@ struct LexicalCast<Out, std::string>
std::enable_if_t<
std::is_integral_v<Integral> && !std::is_same_v<Integral, bool>,
bool>
operator()(Integral& out, std::string const& in) const
operator()(Integral& out, std::string_view in) const
{
auto first = in.data();
auto last = in.data() + in.size();
Expand All @@ -92,20 +93,23 @@ struct LexicalCast<Out, std::string>
}

bool
operator()(bool& out, std::string in) const
operator()(bool& out, std::string_view in) const
{
std::string result;

// Convert the input to lowercase
std::transform(in.begin(), in.end(), in.begin(), [](auto c) {
return std::tolower(static_cast<unsigned char>(c));
});
std::transform(
in.begin(), in.end(), std::back_inserter(result), [](auto c) {
return std::tolower(static_cast<unsigned char>(c));
});

if (in == "1" || in == "true")
if (result == "1" || result == "true")
{
out = true;
return true;
}

if (in == "0" || in == "false")
if (result == "0" || result == "false")
{
out = false;
return true;
Expand All @@ -114,9 +118,38 @@ struct LexicalCast<Out, std::string>
return false;
}
};

//------------------------------------------------------------------------------

// Parse boost library's string_view to number or boolean value
// Note: As of Jan 2024, Boost contains three different types of string_view
// (boost::core::basic_string_view<char>, boost::string_ref and
// boost::string_view). The below template specialization is included because
// it is used in the handshake.cpp file
template <class Out>
struct LexicalCast<Out, boost::core::basic_string_view<char>>
{
explicit LexicalCast() = default;

bool
operator()(Out& out, boost::core::basic_string_view<char> in) const
{
return LexicalCast<Out, std::string_view>()(out, in);
}
};

// Parse std::string to number or boolean value
template <class Out>
struct LexicalCast<Out, std::string>
{
explicit LexicalCast() = default;

bool
operator()(Out& out, std::string in) const
{
return LexicalCast<Out, std::string_view>()(out, in);
}
};

// Conversion from null terminated char const*
template <class Out>
struct LexicalCast<Out, char const*>
Expand All @@ -126,7 +159,8 @@ struct LexicalCast<Out, char const*>
bool
operator()(Out& out, char const* in) const
{
return LexicalCast<Out, std::string>()(out, in);
assert(in);
return LexicalCast<Out, std::string_view>()(out, in);
}
};

Expand All @@ -140,7 +174,8 @@ struct LexicalCast<Out, char*>
bool
operator()(Out& out, char* in) const
{
return LexicalCast<Out, std::string>()(out, in);
assert(in);
return LexicalCast<Out, std::string_view>()(out, in);
}
};

Expand Down
1 change: 1 addition & 0 deletions src/ripple/json/Output.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/beast/core/string.hpp>
#include <functional>
#include <string>

namespace Json {

Expand Down
5 changes: 2 additions & 3 deletions src/ripple/overlay/impl/Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
//==============================================================================

#include <ripple/app/main/Application.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/core/Config.h>
Expand All @@ -27,7 +26,6 @@
#include <ripple/protocol/jss.h>
#include <ripple/protocol/tokens.h>
#include <boost/regex.hpp>
#include <memory.h>

namespace ripple {

Expand Down Expand Up @@ -113,7 +111,8 @@ Cluster::load(Section const& nodes)
return false;
}

auto const id = parseBase58<PublicKey>(TokenType::NodePublic, match[1]);
auto const id =
parseBase58<PublicKey>(TokenType::NodePublic, match[1].str());

if (!id)
{
Expand Down
13 changes: 4 additions & 9 deletions src/ripple/overlay/impl/Handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/main/Application.h>
#include <ripple/basics/base64.h>
#include <ripple/basics/safe_cast.h>
#include <ripple/beast/core/LexicalCast.h>
#include <ripple/beast/rfc2616.h>
#include <ripple/overlay/impl/Handshake.h>
#include <ripple/protocol/digest.h>

#include <boost/regex.hpp>

#include <algorithm>
#include <chrono>

// VFALCO Shouldn't we have to include the OpenSSL
// headers or something for SSL_get_finished?
Expand All @@ -46,8 +42,8 @@ getFeatureValue(
return {};
boost::smatch match;
boost::regex rx(feature + "=([^;\\s]+)");
std::string const value = header->value();
if (boost::regex_search(value, match, rx))
std::string const allFeatures(header->value());
if (boost::regex_search(allFeatures, match, rx))
return {match[1]};
return {};
}
Expand Down Expand Up @@ -243,7 +239,7 @@ verifyHandshake(
{
std::uint32_t nid;

if (!beast::lexicalCastChecked(nid, std::string(iter->value())))
if (!beast::lexicalCastChecked(nid, iter->value()))
throw std::runtime_error("Invalid peer network identifier");

if (networkID && nid != *networkID)
Expand All @@ -252,8 +248,7 @@ verifyHandshake(

if (auto const iter = headers.find("Network-Time"); iter != headers.end())
{
auto const netTime =
[str = std::string(iter->value())]() -> TimeKeeper::time_point {
auto const netTime = [str = iter->value()]() -> TimeKeeper::time_point {
TimeKeeper::duration::rep val;

if (beast::lexicalCastChecked(val, str))
Expand Down
7 changes: 3 additions & 4 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <ripple/server/SimpleWriter.h>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/utility/in_place_factory.hpp>

namespace ripple {

Expand Down Expand Up @@ -826,7 +825,7 @@ OverlayImpl::getOverlayInfo()
auto version{sp->getVersion()};
if (!version.empty())
// Could move here if Json::value supported moving from strings
pv[jss::version] = version;
pv[jss::version] = std::string{version};
}

std::uint32_t minSeq, maxSeq;
Expand Down Expand Up @@ -994,9 +993,9 @@ OverlayImpl::processValidatorList(
return true;
};

auto key = req.target().substr(prefix.size());
std::string_view key = req.target().substr(prefix.size());

if (auto slash = key.find('/'); slash != boost::string_view::npos)
if (auto slash = key.find('/'); slash != std::string_view::npos)
{
auto verString = key.substr(0, slash);
if (!boost::conversion::try_lexical_convert(verString, version))
Expand Down
Loading

0 comments on commit fa2b678

Please sign in to comment.