Add resetIP() method, need impl
This commit is contained in:
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16)
|
|||||||
# If MAJOR is 0, and MINOR > 0, Version is BETA
|
# If MAJOR is 0, and MINOR > 0, Version is BETA
|
||||||
|
|
||||||
project(ColumnLynx
|
project(ColumnLynx
|
||||||
VERSION 0.1.0
|
VERSION 0.2.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ namespace ColumnLynx::Net {
|
|||||||
bool configureIP(uint32_t clientIP, uint32_t serverIP,
|
bool configureIP(uint32_t clientIP, uint32_t serverIP,
|
||||||
uint8_t prefixLen, uint16_t mtu);
|
uint8_t prefixLen, uint16_t mtu);
|
||||||
|
|
||||||
|
void resetIP();
|
||||||
|
|
||||||
std::vector<uint8_t> readPacket();
|
std::vector<uint8_t> readPacket();
|
||||||
void writePacket(const std::vector<uint8_t>& packet);
|
void writePacket(const std::vector<uint8_t>& packet);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace ColumnLynx::Net::TCP {
|
|||||||
// Set callback for disconnects
|
// Set callback for disconnects
|
||||||
void setDisconnectCallback(std::function<void(std::shared_ptr<TCPConnection>)> cb);
|
void setDisconnectCallback(std::function<void(std::shared_ptr<TCPConnection>)> cb);
|
||||||
// Disconnect the client
|
// Disconnect the client
|
||||||
void disconnect();
|
void disconnect(bool echo = true);
|
||||||
|
|
||||||
// Get the assigned session ID
|
// Get the assigned session ID
|
||||||
uint64_t getSessionID() const;
|
uint64_t getSessionID() const;
|
||||||
|
|||||||
@@ -269,6 +269,12 @@ namespace ColumnLynx::Net::TCP {
|
|||||||
disconnect(false);
|
disconnect(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ServerMessageType::KILL_CONNECTION:
|
||||||
|
Utils::warn("Server is killing the connection: " + data);
|
||||||
|
if (mConnected) {
|
||||||
|
disconnect(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Utils::log("Received unknown message type from server.");
|
Utils::log("Received unknown message type from server.");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace ColumnLynx::Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string getVersion() {
|
std::string getVersion() {
|
||||||
return "b0.1";
|
return "b0.2";
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short serverPort() {
|
unsigned short serverPort() {
|
||||||
|
|||||||
@@ -238,6 +238,37 @@ namespace ColumnLynx::Net {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VirtualInterface::resetIP() {
|
||||||
|
#if defined(__linux__)
|
||||||
|
char cmd[512];
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"ip addr flush dev %s",
|
||||||
|
mIfName.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
char cmd[512];
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"ifconfig %s inet 0.0.0.0 delete",
|
||||||
|
mIfName.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"ifconfig %s inet6 :: delete",
|
||||||
|
mIfName.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
char cmd[256];
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"netsh interface ip set address name=\"%s\" dhcp",
|
||||||
|
mIfName.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// Linux
|
// Linux
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|||||||
@@ -32,14 +32,23 @@ namespace ColumnLynx::Net::TCP {
|
|||||||
mOnDisconnect = std::move(cb);
|
mOnDisconnect = std::move(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPConnection::disconnect() {
|
void TCPConnection::disconnect(bool echo) {
|
||||||
std::string ip = mHandler->socket().remote_endpoint().address().to_string();
|
std::string ip = mHandler->socket().remote_endpoint().address().to_string();
|
||||||
|
|
||||||
|
if (echo) {
|
||||||
mHandler->sendMessage(ServerMessageType::GRACEFUL_DISCONNECT, "Server initiated disconnect.");
|
mHandler->sendMessage(ServerMessageType::GRACEFUL_DISCONNECT, "Server initiated disconnect.");
|
||||||
|
}
|
||||||
mHeartbeatTimer.cancel();
|
mHeartbeatTimer.cancel();
|
||||||
asio::error_code ec;
|
asio::error_code ec;
|
||||||
mHandler->socket().shutdown(asio::ip::tcp::socket::shutdown_both, ec);
|
mHandler->socket().shutdown(asio::ip::tcp::socket::shutdown_both, ec);
|
||||||
|
if (ec) {
|
||||||
|
Utils::error("Error during socket shutdown: " + ec.message());
|
||||||
|
}
|
||||||
|
|
||||||
mHandler->socket().close(ec);
|
mHandler->socket().close(ec);
|
||||||
|
if (ec) {
|
||||||
|
Utils::error("Error during socket close: " + ec.message());
|
||||||
|
}
|
||||||
|
|
||||||
SessionRegistry::getInstance().erase(mConnectionSessionID);
|
SessionRegistry::getInstance().erase(mConnectionSessionID);
|
||||||
SessionRegistry::getInstance().deallocIP(mConnectionSessionID);
|
SessionRegistry::getInstance().deallocIP(mConnectionSessionID);
|
||||||
@@ -272,6 +281,11 @@ namespace ColumnLynx::Net::TCP {
|
|||||||
disconnect();
|
disconnect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ClientMessageType::KILL_CONNECTION: {
|
||||||
|
Utils::warn("Received KILL_CONNECTION from " + reqAddr + ": " + data);
|
||||||
|
disconnect();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Utils::warn("Unhandled message type from " + reqAddr);
|
Utils::warn("Unhandled message type from " + reqAddr);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user