Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ InsertBraces: true
MaxEmptyLinesToKeep: 2
RequiresClausePosition: OwnLine
IncludeCategories:
- Regex: ^<zpp_bits\.h>
Priority: 9
- Regex: <[[:alnum:]_]+>
Priority: 1
- Regex: <[[:alnum:]_]+[.]h>
Expand All @@ -89,6 +91,6 @@ IncludeCategories:
- Regex: ^<range
Priority: 8
- Regex: ^"openvic-simulation/
Priority: 9
- Regex: .*
Priority: 10
- Regex: .*
Priority: 11
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
path = deps/memory
url = https://github.com/foonathan/memory
ignore = dirty
[submodule "deps/reliable"]
path = deps/reliable
url = https://github.com/mas-bandwidth/reliable
[submodule "deps/zpp_bits"]
path = deps/zpp_bits
url = https://github.com/eyalz800/zpp_bits
19 changes: 19 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ Comment: plf::colony
Copyright: 2019, mattreecebentley
License: Zlib

Files: deps/reliable/*
Comment: reliable
Copyright: 2017-2024, Mas Bandwidth LLC
License: BSD-3-Clause

Files: deps/zpp_bits/*
Comment: zpp_bits
Copyright: 2021, Eyal Z
License: Expat

Files: src/openvic-simulation/types/Signal.hpp
Comment: sigslot
Copyright: 2017, Pierre-Antoine Lacaze
Expand All @@ -53,6 +63,15 @@ Comment: nanobench
Copyright: 2019-2023 Martin Leitner-Ankerl
License: Expat

License: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
.
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

License: BSL-1.0
Boost Software License - Version 1.0 - August 17th, 2003
.
Expand Down
46 changes: 46 additions & 0 deletions deps/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ def build_memory(env):

env.exposed_includes += env.memory["INCPATH"]

def build_reliable(env):
import os

if env["optimize"] in ["none", "debug"]:
env.Append(CPPDEFINES=["RELIABLE_DEBUG"])
else:
env.Append(CPPDEFINES=["RELIABLE_RELEASE"])
reliable_env = env.Clone()

include_path = "reliable"
include_dir = reliable_env.Dir(include_path)
sources = [os.path.join(include_path, "reliable.c")]
env.reliable_sources = sources
library_name = "libreliable" + env["LIBSUFFIX"]
library = reliable_env.StaticLibrary(target=os.path.join(include_path, library_name), source=sources)
Default(library)

env.reliable = {}
env.reliable["INCPATH"] = [include_dir]

env.Append(CPPPATH=env.reliable["INCPATH"])
if env.get("is_msvc", False):
env.Append(CXXFLAGS=["/external:I", include_dir, "/external:W0"])
else:
env.Append(CXXFLAGS=["-isystem", include_dir])
env.Append(LIBPATH=include_dir)
env.Prepend(LIBS=[library_name])

env.exposed_includes += env.reliable["INCPATH"]

def build_zpp_bits(env):
if env["optimize"] in ["none", "debug"]:
env.Append(CPPDEFINES=[("ZPP_BITS_INLINE_MODE", 0)])
elif env["optimize"] == "speed":
env.Append(CPPDEFINES=[("ZPP_BITS_INLINE_DECODE_VARINT", 1)])

include_path = "zpp_bits"
include_dir = env.Dir(include_path)

env.zpp_bits = {}
env.zpp_bits["INCPATH"] = [include_dir]

env.Append(CPPPATH=env.zpp_bits["INCPATH"])

def link_tbb(env):
import sys
if not env.get("is_msvc", False) and not env.get("use_mingw", False) and sys.platform != "darwin":
Expand All @@ -123,4 +167,6 @@ build_colony(env)
build_function2(env)
build_std_function(env)
build_memory(env)
build_reliable(env)
build_zpp_bits(env)
link_tbb(env)
1 change: 1 addition & 0 deletions deps/reliable
Submodule reliable added at 57b0c9
1 change: 1 addition & 0 deletions deps/zpp_bits
Submodule zpp_bits added at e5ff2b
30 changes: 30 additions & 0 deletions src/openvic-simulation/multiplayer/lowlevel/HostnameAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#include "HostnameAddress.hpp"

#include <charconv>
#include <system_error>

#include "openvic-simulation/multiplayer/lowlevel/IpAddress.hpp"
#include "openvic-simulation/multiplayer/lowlevel/NetworkResolver.hpp"

using namespace OpenVic;

HostnameAddress::HostnameAddress() = default;

HostnameAddress::HostnameAddress(IpAddress const& address) : _resolved_address(address) {}

HostnameAddress::HostnameAddress(std::string_view name_or_address) : HostnameAddress() {
std::from_chars_result result =
_resolved_address.from_chars(name_or_address.data(), name_or_address.data() + name_or_address.size());
if (result.ec != std::errc {}) {
_resolved_address = NetworkResolver::singleton().resolve_hostname(name_or_address);
}
}

IpAddress const& HostnameAddress::resolved_address() const {
return _resolved_address;
}

void HostnameAddress::set_resolved_address(IpAddress const& address) {
_resolved_address = address;
}
19 changes: 19 additions & 0 deletions src/openvic-simulation/multiplayer/lowlevel/HostnameAddress.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string_view>

#include "openvic-simulation/multiplayer/lowlevel/IpAddress.hpp"

namespace OpenVic {
struct HostnameAddress {
HostnameAddress();
HostnameAddress(IpAddress const& address);
HostnameAddress(std::string_view name_or_address);

IpAddress const& resolved_address() const;
void set_resolved_address(IpAddress const& address);

private:
IpAddress _resolved_address;
};
}
18 changes: 18 additions & 0 deletions src/openvic-simulation/multiplayer/lowlevel/IpAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "IpAddress.hpp"

#include "openvic-simulation/utility/Containers.hpp"

using namespace OpenVic;

memory::string IpAddress::to_string(bool prefer_ipv4, to_chars_option option) const {
stack_string result = to_array(prefer_ipv4, option);
if (OV_unlikely(result.empty())) {
return {};
}

return result;
}

IpAddress::operator memory::string() const {
return to_string();
}
Loading