diff --git a/src/beast/Builds/VisualStudio2012/beast.vcxproj b/src/beast/Builds/VisualStudio2012/beast.vcxproj index cdaea28a8..cdf07854e 100644 --- a/src/beast/Builds/VisualStudio2012/beast.vcxproj +++ b/src/beast/Builds/VisualStudio2012/beast.vcxproj @@ -82,6 +82,8 @@ + + @@ -401,6 +403,13 @@ + + + true + true + true + true + diff --git a/src/beast/Builds/VisualStudio2012/beast.vcxproj.filters b/src/beast/Builds/VisualStudio2012/beast.vcxproj.filters index 1f927cb51..21a8498eb 100644 --- a/src/beast/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/src/beast/Builds/VisualStudio2012/beast.vcxproj.filters @@ -297,6 +297,12 @@ {d7ec873a-d1e7-4341-9d20-a1be8f8ddd88} + + {f73fedee-2efb-431b-9f4f-d2fd405454f6} + + + {30b0fdfb-02b6-47dd-bdd9-ffc1f57e1f2c} + @@ -1251,6 +1257,12 @@ beast\net + + beast + + + beast\asio + @@ -1799,6 +1811,12 @@ beast\net\impl + + beast\asio + + + beast\asio\impl + diff --git a/src/beast/beast/Asio.h b/src/beast/beast/Asio.h new file mode 100644 index 000000000..d4e8c590f --- /dev/null +++ b/src/beast/beast/Asio.h @@ -0,0 +1,25 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_H_INCLUDED +#define BEAST_ASIO_H_INCLUDED + +#include "asio/IPAddressConversion.h" + +#endif diff --git a/src/beast/beast/asio/Asio.cpp b/src/beast/beast/asio/Asio.cpp new file mode 100644 index 000000000..5aa88c74a --- /dev/null +++ b/src/beast/beast/asio/Asio.cpp @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include "BeastConfig.h" + +#include "impl/IPAddressConversion.cpp" diff --git a/src/beast/beast/asio/IPAddressConversion.h b/src/beast/beast/asio/IPAddressConversion.h new file mode 100644 index 000000000..0776e4c30 --- /dev/null +++ b/src/beast/beast/asio/IPAddressConversion.h @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_IPADDRESSCONVERSION_H_INCLUDED +#define BEAST_ASIO_IPADDRESSCONVERSION_H_INCLUDED + +#include "../net/IPAddress.h" + +#include + +namespace beast { + +struct IPAddressConversion +{ + /** Convert to IPAddress. + The port is set to zero. + */ + static IPAddress from_asio (boost::asio::ip::address const& address); + + /** Convert to IPAddress, including port. */ + static IPAddress from_asio (boost::asio::ip::tcp::endpoint const& endpoint); + + /** Convert to asio::ip::address. + The port is ignored. + */ + static boost::asio::ip::address to_asio_address (IPAddress const& address); + + /** Convert to asio::ip::tcp::endpoint. */ + static boost::asio::ip::tcp::endpoint to_asio_endpoint (IPAddress const& address); +}; + +} + +#endif diff --git a/src/beast/beast/asio/impl/IPAddressConversion.cpp b/src/beast/beast/asio/impl/IPAddressConversion.cpp new file mode 100644 index 000000000..32c8cba86 --- /dev/null +++ b/src/beast/beast/asio/impl/IPAddressConversion.cpp @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include "../IPAddressConversion.h" + +namespace beast { + +IPAddress IPAddressConversion::from_asio (boost::asio::ip::address const& address) +{ + if (address.is_v4 ()) + { + boost::asio::ip::address_v4::bytes_type const bytes ( + address.to_v4().to_bytes()); + return IPAddress (IPAddress::V4 ( + bytes [0], bytes [1], bytes [2], bytes [3])); + } + + // VFALCO TODO IPv6 support + bassertfalse; + return IPAddress(); +} + +IPAddress IPAddressConversion::from_asio (boost::asio::ip::tcp::endpoint const& endpoint) +{ + return from_asio (endpoint.address()).withPort (endpoint.port()); +} + +boost::asio::ip::address IPAddressConversion::to_asio_address (IPAddress const& address) +{ + if (address.isV4 ()) + { + return boost::asio::ip::address ( + boost::asio::ip::address_v4 ( + address.v4().value)); + } + + // VFALCO TODO IPv6 support + bassertfalse; + return boost::asio::ip::address ( + boost::asio::ip::address_v6 ()); +} + +boost::asio::ip::tcp::endpoint IPAddressConversion::to_asio_endpoint (IPAddress const& address) +{ + return boost::asio::ip::tcp::endpoint ( + to_asio_address (address), address.port()); +} + +} diff --git a/src/beast/modules/beast_asio/beast_asio.h b/src/beast/modules/beast_asio/beast_asio.h index f66d966e2..0fd6b21b4 100644 --- a/src/beast/modules/beast_asio/beast_asio.h +++ b/src/beast/modules/beast_asio/beast_asio.h @@ -17,8 +17,8 @@ */ //============================================================================== -#ifndef BEAST_ASIO_H_INCLUDED -#define BEAST_ASIO_H_INCLUDED +#ifndef BEAST_ASIO_MODULE_H_INCLUDED +#define BEAST_ASIO_MODULE_H_INCLUDED //------------------------------------------------------------------------------ @@ -53,6 +53,7 @@ # define BEAST_SOCKET_VIRTUAL #endif +#include "../../beast/Asio.h" #include "../../beast/MPL.h" #include "../../beast/Utility.h" #include "../../beast/HTTP.h" diff --git a/src/ripple/beast/ripple_beast.cpp b/src/ripple/beast/ripple_beast.cpp index 9cf2e4ada..b4a691264 100644 --- a/src/ripple/beast/ripple_beast.cpp +++ b/src/ripple/beast/ripple_beast.cpp @@ -38,6 +38,7 @@ #include "../beast/modules/beast_db/beast_db.cpp" #include "../beast/modules/beast_sqdb/beast_sqdb.cpp" +#include "../beast/beast/asio/Asio.cpp" #include "../beast/beast/boost/Boost.cpp" #include "../beast/beast/chrono/Chrono.cpp" #include "../beast/beast/crypto/Crypto.cpp" diff --git a/src/ripple_app/ripple_app.cpp b/src/ripple_app/ripple_app.cpp index 8a06dd1b9..f79dfeb9f 100644 --- a/src/ripple_app/ripple_app.cpp +++ b/src/ripple_app/ripple_app.cpp @@ -40,8 +40,9 @@ #include "../ripple/rpc/ripple_rpc.h" #include "../ripple/validators/ripple_validators.h" -namespace ripple -{ +#include "beast/beast/Asio.h" + +namespace ripple { // // Application diff --git a/src/ripple_app/websocket/WSConnection.h b/src/ripple_app/websocket/WSConnection.h index 4e3acc8cc..89fb40abd 100644 --- a/src/ripple_app/websocket/WSConnection.h +++ b/src/ripple_app/websocket/WSConnection.h @@ -92,19 +92,12 @@ public: typedef WSServerHandler server_type; public: - static IPAddress from_address (boost::asio::ip::address const& addr) - { - boost::asio::ip::address_v4::bytes_type bytes (addr.to_v4().to_bytes()); - IPAddress ep (IPAddress::V4 (bytes[0], bytes[1], bytes[2], bytes[3]), 0); - return ep; - } - WSConnectionType (Resource::Manager& resourceManager, InfoSub::Source& source, server_type& serverHandler, connection_ptr const& cpConnection) : WSConnection ( resourceManager, - resourceManager.newInboundEndpoint (from_address ( + resourceManager.newInboundEndpoint (IPAddressConversion::from_asio ( cpConnection->get_socket ().lowest_layer ().remote_endpoint ().address ())), source, serverHandler.getPublic (),