Skip to content

Commit

Permalink
Temporary fix to allow evc-sim connections on LAN
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarBLG committed Aug 2, 2023
1 parent 5e215a5 commit cc3639f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
url = https://github.com/libsdl-org/SDL
[submodule "libs/liborts"]
path = libs/liborts
url = https://github.com/Milek7/liborts
url = https://github.com/cesarBLG/liborts
2 changes: 1 addition & 1 deletion EVC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NationalFN/nationalfn.cpp NationalFN/asfa.cpp
add_definitions(-DNO_THREADS)

if (NOT WASM)
list(APPEND SOURCES ../platform/console_platform.cpp ../platform/console_fd_poller.cpp ../platform/tcp_socket.cpp ../platform/bus_socket_impl.cpp ../platform/tcp_listener.cpp ../platform/libc_time_impl.cpp ../platform/fstream_file_impl.cpp ../platform/bus_socket_server.cpp ../platform/bus_tcp_bridge.cpp)
list(APPEND SOURCES ../platform/console_platform.cpp ../platform/console_fd_poller.cpp ../platform/tcp_socket.cpp ../platform/bus_socket_impl.cpp ../platform/tcp_listener.cpp ../platform/libc_time_impl.cpp ../platform/fstream_file_impl.cpp ../platform/bus_socket_server.cpp ../platform/bus_tcp_bridge.cpp ../libs/liborts/client.cpp)
else()
list(APPEND SOURCES ../platform/simrail_platform.cpp)
add_definitions(-DJSON_TEST_KEEP_MACROS=1 -DJSON_HAS_FILESYSTEM=0 -DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0)
Expand Down
2 changes: 1 addition & 1 deletion libs/liborts
21 changes: 15 additions & 6 deletions platform/bus_tcp_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <map>
#include "bus_tcp_bridge.h"

void BusTcpBridge::BridgedTcpSocket::tcp_rx(std::string &&data)
void BridgedTcpSocket::tcp_rx(std::string &&data)
{
if (data.empty()) {
alive = false;
Expand Down Expand Up @@ -48,7 +48,7 @@ void BusTcpBridge::BridgedTcpSocket::tcp_rx(std::string &&data)
}
}

void BusTcpBridge::BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResult &&result)
void BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResult &&result)
{
if (!alive)
return;
Expand All @@ -65,14 +65,14 @@ void BusTcpBridge::BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResu
tcp_socket->send(msg.data);
}

BusTcpBridge::BridgedTcpSocket::BridgedTcpSocket(std::unique_ptr<BasePlatform::BusSocket> &&bus, std::unique_ptr<TcpSocket> &&tcp, std::optional<uint32_t> tid, bool nl) :
BridgedTcpSocket::BridgedTcpSocket(std::unique_ptr<BasePlatform::BusSocket> &&bus, std::unique_ptr<TcpSocket> &&tcp, std::optional<uint32_t> tid, bool nl) :
bus_socket(std::move(bus)), tcp_socket(std::move(tcp)), bus_tid(tid), newline_framing(nl), alive(true)
{
tcp_rx_promise = tcp_socket->receive().then(std::bind(&BridgedTcpSocket::tcp_rx, this, std::placeholders::_1));
bus_rx_promise = bus_socket->receive().then(std::bind(&BridgedTcpSocket::bus_rx, this, std::placeholders::_1));
}

bool BusTcpBridge::BridgedTcpSocket::is_alive() const {
bool BridgedTcpSocket::is_alive() const {
return alive;
}

Expand All @@ -93,7 +93,7 @@ BusTcpBridge::BusTcpBridge(const std::string_view bus, uint32_t rx_tid, std::opt
{
accept_promise = listener.accept().then(std::bind(&BusTcpBridge::on_new_client, this, std::placeholders::_1));
}

#include <orts/clientext.h>
BusTcpBridgeManager::BusTcpBridgeManager(const std::string_view load_path, FdPoller &fd, BusSocketImpl &impl)
{
std::ifstream file(std::string(load_path) + "tcp_bus_bridge.conf", std::ios::binary);
Expand Down Expand Up @@ -125,6 +125,15 @@ BusTcpBridgeManager::BusTcpBridgeManager(const std::string_view load_path, FdPol
if (tx_tid != "*")
txt = BasePlatform::BusSocket::PeerId::fourcc(tx_tid);
bool newline_framing = (!nl.empty() && nl[0] == 'n');
bridges.push_back(std::make_unique<BusTcpBridge>(busname, rxt, txt, newline_framing, tcphost, std::stoi(tcpport), fd, impl));
if (busname == "evc_sim") {
std::unique_ptr<BasePlatform::BusSocket> bus_socket = impl.open_bus_socket(busname, rxt);
if (!bus_socket)
continue;
tcphost = ORserver::TCPclient::discover_server_ip();
auto sock = std::make_unique<TcpSocket>(tcphost, std::stoi(tcpport), fd);
client_bridges.push_back(std::make_unique<BridgedTcpSocket>(std::move(bus_socket), std::move(sock), txt, newline_framing));
} else {
server_bridges.push_back(std::make_unique<BusTcpBridge>(busname, rxt, txt, newline_framing, tcphost, std::stoi(tcpport), fd, impl));
}
}
}
10 changes: 5 additions & 5 deletions platform/bus_tcp_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

#include "tcp_listener.h"
#include "bus_socket_impl.h"

class BusTcpBridge : private PlatformUtil::NoCopy {
private:
class BridgedTcpSocket : private PlatformUtil::NoCopy {
class BridgedTcpSocket : private PlatformUtil::NoCopy {
private:
std::unique_ptr<BasePlatform::BusSocket> bus_socket;
PlatformUtil::Promise<BasePlatform::BusSocket::ReceiveResult> bus_rx_promise;
Expand All @@ -32,6 +29,8 @@ class BusTcpBridge : private PlatformUtil::NoCopy {
BridgedTcpSocket(std::unique_ptr<BasePlatform::BusSocket> &&bus, std::unique_ptr<TcpSocket> &&tcp, std::optional<uint32_t> tid, bool nl);
bool is_alive() const;
};
class BusTcpBridge : private PlatformUtil::NoCopy {
private:

void on_new_client(std::unique_ptr<TcpSocket> &&sock);

Expand All @@ -51,7 +50,8 @@ class BusTcpBridge : private PlatformUtil::NoCopy {

class BusTcpBridgeManager : private PlatformUtil::NoCopy {
private:
std::vector<std::unique_ptr<BusTcpBridge>> bridges;
std::vector<std::unique_ptr<BridgedTcpSocket>> client_bridges;
std::vector<std::unique_ptr<BusTcpBridge>> server_bridges;
public:
BusTcpBridgeManager(const std::string_view load_path, FdPoller &fd, BusSocketImpl &impl);
};

0 comments on commit cc3639f

Please sign in to comment.