First working alpha, version a0.4. #6

Merged
dcrubro merged 21 commits from dev into beta 2025-11-18 20:07:30 +00:00
7 changed files with 19 additions and 15 deletions
Showing only changes of commit c85f622a60 - Show all commits

View File

@@ -28,7 +28,7 @@ namespace ColumnLynx::Net::TCP {
std::array<uint8_t, 32>* aesKey,
uint64_t* sessionIDRef,
bool* insecureMode,
VirtualInterface* tun = nullptr)
std::shared_ptr<VirtualInterface> tun = nullptr)
:
mResolver(ioContext),
mSocket(ioContext),
@@ -74,6 +74,6 @@ namespace ColumnLynx::Net::TCP {
int mMissedHeartbeats = 0;
bool mIsHostDomain;
Protocol::TunConfig mTunConfig;
VirtualInterface* mTun = nullptr;
std::shared_ptr<VirtualInterface> mTun = nullptr;
};
}

View File

@@ -19,7 +19,7 @@ namespace ColumnLynx::Net::UDP {
const std::string& port,
std::array<uint8_t, 32>* aesKeyRef,
uint64_t* sessionIDRef,
VirtualInterface* tunRef = nullptr)
std::shared_ptr<VirtualInterface> tunRef = nullptr)
: mSocket(ioContext), mResolver(ioContext), mHost(host), mPort(port), mAesKeyRef(aesKeyRef), mSessionIDRef(sessionIDRef), mTunRef(tunRef) { mStartReceive(); }
void start();
@@ -37,7 +37,7 @@ namespace ColumnLynx::Net::UDP {
std::string mPort;
std::array<uint8_t, 32>* mAesKeyRef;
uint64_t* mSessionIDRef;
VirtualInterface* mTunRef;
std::shared_ptr<VirtualInterface> mTunRef = nullptr;
std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed
};
}

View File

@@ -13,7 +13,7 @@
namespace ColumnLynx::Net::UDP {
class UDPServer {
public:
UDPServer(asio::io_context& ioContext, uint16_t port, bool* hostRunning, bool ipv4Only = false, VirtualInterface* tun = nullptr)
UDPServer(asio::io_context& ioContext, uint16_t port, bool* hostRunning, bool ipv4Only = false, std::shared_ptr<VirtualInterface> tun = nullptr)
: mSocket(ioContext), mHostRunning(hostRunning), mTun(tun)
{
asio::error_code ec;
@@ -53,6 +53,6 @@ namespace ColumnLynx::Net::UDP {
asio::ip::udp::endpoint mRemoteEndpoint;
std::array<uint8_t, 2048> mRecvBuffer; // Adjust size as needed
bool* mHostRunning;
VirtualInterface* mTun;
std::shared_ptr<VirtualInterface> mTun;
};
}

1
panic_dump.txt Normal file
View File

@@ -0,0 +1 @@
=

View File

@@ -63,8 +63,8 @@ int main(int argc, char** argv) {
WintunInitialize();
#endif
VirtualInterface tun("utun1");
log("Using virtual interface: " + tun.getName());
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun0");
log("Using virtual interface: " + tun->getName());
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
@@ -72,8 +72,8 @@ int main(int argc, char** argv) {
uint64_t sessionID = 0;
asio::io_context io;
auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, &sodiumWrapper, &aesKey, &sessionID, &insecureMode, &tun);
auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, &aesKey, &sessionID, &tun);
auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, &sodiumWrapper, &aesKey, &sessionID, &insecureMode, tun);
auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, &aesKey, &sessionID, tun);
client->start();
udpClient->start();
@@ -89,7 +89,7 @@ int main(int argc, char** argv) {
// Client is running
// TODO: SIGINT or SIGTERM seems to not kill this instantly!
while ((client->isConnected() || !client->isHandshakeComplete()) && !done) {
auto packet = tun.readPacket();
auto packet = tun->readPacket();
Nonce nonce{};
randombytes_buf(nonce.data(), nonce.size());

View File

@@ -61,8 +61,8 @@ int main(int argc, char** argv) {
WintunInitialize();
#endif
VirtualInterface tun("utun0");
log("Using virtual interface: " + tun.getName());
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun0");
log("Using virtual interface: " + tun->getName());
// Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory)
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
@@ -74,7 +74,7 @@ int main(int argc, char** argv) {
asio::io_context io;
auto server = std::make_shared<TCPServer>(io, serverPort(), &sodiumWrapper, &hostRunning, ipv4Only);
auto udpServer = std::make_shared<UDPServer>(io, serverPort(), &hostRunning, ipv4Only, &tun);
auto udpServer = std::make_shared<UDPServer>(io, serverPort(), &hostRunning, ipv4Only, tun);
asio::signal_set signals(io, SIGINT, SIGTERM);
signals.async_wait([&](const std::error_code&, int) {
@@ -84,6 +84,8 @@ int main(int argc, char** argv) {
hostRunning = false;
server->stop();
udpServer->stop();
tun.reset();
tun = nullptr;
});
});
@@ -97,7 +99,7 @@ int main(int argc, char** argv) {
log("Server started on port " + std::to_string(serverPort()));
while (!done) {
auto packet = tun.readPacket();
auto packet = tun->readPacket();
if (packet.empty()) {
continue;
}

View File

@@ -62,6 +62,7 @@ namespace ColumnLynx::Net::UDP {
// For now, just log the decrypted payload
std::string payloadStr(plaintext.begin(), plaintext.end());
Utils::log("UDP: Received packet from " + mRemoteEndpoint.address().to_string() + " - Payload: " + payloadStr);
if (mTun) {
mTun->writePacket(plaintext); // Send to virtual interface
}