mirror of
https://github.com/EvernodeXRPL/sashimono.git
synced 2026-04-29 15:38:00 +00:00
Allow more ports per instance (#381)
This commit is contained in:
committed by
GitHub
parent
946b7dae36
commit
d258f2ebae
@@ -22,26 +22,26 @@ namespace sqlite
|
||||
|
||||
constexpr const char *INSERT_INTO_HP_INSTANCE = "INSERT INTO instances("
|
||||
"owner_pubkey, time, username, status, name, ip,"
|
||||
"peer_port, user_port, pubkey, contract_id, image_name"
|
||||
") VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||
"peer_port, user_port, init_gp_tcp_port, init_gp_udp_port, pubkey, contract_id, image_name"
|
||||
") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
constexpr const char *GET_VACANT_PORTS_FROM_HP = "SELECT DISTINCT peer_port, user_port FROM "
|
||||
constexpr const char *GET_VACANT_PORTS_FROM_HP = "SELECT DISTINCT peer_port, user_port, init_gp_tcp_port, init_gp_udp_port FROM "
|
||||
"instances WHERE status == ? AND user_port NOT IN"
|
||||
"(SELECT user_port FROM instances WHERE status != ?)";
|
||||
|
||||
constexpr const char *GET_MAX_PORTS_FROM_HP = "SELECT max(peer_port), max(user_port) FROM instances WHERE status != ?";
|
||||
constexpr const char *GET_MAX_PORTS_FROM_HP = "SELECT max(peer_port), max(user_port), max(init_gp_tcp_port), max(init_gp_udp_port) FROM instances WHERE status != ?";
|
||||
|
||||
constexpr const char *UPDATE_STATUS_IN_HP = "UPDATE instances SET status = ? WHERE name = ?";
|
||||
|
||||
constexpr const char *IS_CONTAINER_EXISTS = "SELECT username, status, peer_port, user_port FROM instances WHERE name = ?";
|
||||
constexpr const char *IS_CONTAINER_EXISTS = "SELECT username, status, peer_port, user_port, init_gp_tcp_port, init_gp_udp_port FROM instances WHERE name = ?";
|
||||
|
||||
constexpr const char *GET_ALOCATED_INSTANCE_COUNT = "SELECT COUNT(name) FROM instances WHERE status != ?";
|
||||
|
||||
constexpr const char *GET_RUNNING_INSTANCE_NAMES = "SELECT name FROM instances WHERE status = ?";
|
||||
|
||||
constexpr const char *GET_INSTANCE_LIST = "SELECT name, username, user_port, peer_port, status, image_name, contract_id FROM instances WHERE status != ?";
|
||||
constexpr const char *GET_INSTANCE_LIST = "SELECT name, username, user_port, peer_port, init_gp_tcp_port, init_gp_udp_port, status, image_name, contract_id FROM instances WHERE status != ?";
|
||||
|
||||
constexpr const char *GET_INSTANCE = "SELECT name, username, user_port, peer_port, status, image_name FROM instances WHERE name == ? AND status != ?";
|
||||
constexpr const char *GET_INSTANCE = "SELECT name, username, user_port, peer_port, init_gp_tcp_port, init_gp_udp_port, status, image_name FROM instances WHERE name == ? AND status != ?";
|
||||
|
||||
constexpr const char *IS_TABLE_EXISTS = "SELECT * FROM sqlite_master WHERE type='table' AND name = ?";
|
||||
|
||||
@@ -303,6 +303,8 @@ namespace sqlite
|
||||
table_column_info("ip", COLUMN_DATA_TYPE::TEXT),
|
||||
table_column_info("peer_port", COLUMN_DATA_TYPE::INT),
|
||||
table_column_info("user_port", COLUMN_DATA_TYPE::INT),
|
||||
table_column_info("init_gp_tcp_port", COLUMN_DATA_TYPE::INT),
|
||||
table_column_info("init_gp_udp_port", COLUMN_DATA_TYPE::INT),
|
||||
table_column_info("pubkey", COLUMN_DATA_TYPE::TEXT),
|
||||
table_column_info("contract_id", COLUMN_DATA_TYPE::TEXT),
|
||||
table_column_info("image_name", COLUMN_DATA_TYPE::TEXT)};
|
||||
@@ -333,9 +335,11 @@ namespace sqlite
|
||||
sqlite3_bind_text(stmt, 6, info.ip.data(), info.ip.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_int64(stmt, 7, info.assigned_ports.peer_port) == SQLITE_OK &&
|
||||
sqlite3_bind_int64(stmt, 8, info.assigned_ports.user_port) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 9, info.pubkey.data(), info.pubkey.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 10, info.contract_id.data(), info.contract_id.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 11, info.image_name.data(), info.image_name.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_int64(stmt, 9, info.assigned_ports.gp_tcp_port_start) == SQLITE_OK &&
|
||||
sqlite3_bind_int64(stmt, 10, info.assigned_ports.gp_udp_port_start) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 11, info.pubkey.data(), info.pubkey.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 12, info.contract_id.data(), info.contract_id.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 13, info.image_name.data(), info.image_name.length(), SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_step(stmt) == SQLITE_DONE)
|
||||
{
|
||||
sqlite3_finalize(stmt);
|
||||
@@ -366,6 +370,8 @@ namespace sqlite
|
||||
info.status = std::string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)));
|
||||
info.assigned_ports.peer_port = sqlite3_column_int64(stmt, 2);
|
||||
info.assigned_ports.user_port = sqlite3_column_int64(stmt, 3);
|
||||
info.assigned_ports.gp_tcp_port_start = sqlite3_column_int64(stmt, 4);
|
||||
info.assigned_ports.gp_udp_port_start = sqlite3_column_int64(stmt, 5);
|
||||
|
||||
// Finalize and distroys the statement.
|
||||
sqlite3_finalize(stmt);
|
||||
@@ -414,13 +420,15 @@ namespace sqlite
|
||||
{
|
||||
const uint16_t peer_port = sqlite3_column_int64(stmt, 0);
|
||||
const uint16_t user_port = sqlite3_column_int64(stmt, 1);
|
||||
const uint16_t gp_tcp_port_start = sqlite3_column_int64(stmt, 2);
|
||||
const uint16_t gp_udp_port_start = sqlite3_column_int64(stmt, 3);
|
||||
|
||||
max_ports = {peer_port, user_port};
|
||||
max_ports = {peer_port, user_port, gp_tcp_port_start, gp_udp_port_start};
|
||||
}
|
||||
// Initialize with default config values if either of the ports are zero.
|
||||
if (max_ports.peer_port == 0 || max_ports.user_port == 0)
|
||||
if (max_ports.peer_port == 0 || max_ports.user_port == 0 || max_ports.gp_tcp_port_start == 0 || max_ports.gp_udp_port_start == 0)
|
||||
{
|
||||
max_ports = {(uint16_t)(conf::cfg.hp.init_peer_port - 1), (uint16_t)(conf::cfg.hp.init_user_port - 1)};
|
||||
max_ports = {(uint16_t)(conf::cfg.hp.init_peer_port - 1), (uint16_t)(conf::cfg.hp.init_user_port - 1), (uint16_t)(conf::cfg.hp.init_gp_tcp_port - 2), (uint16_t)(conf::cfg.hp.init_gp_udp_port - 2)};
|
||||
}
|
||||
|
||||
// Finalize and distroys the statement.
|
||||
@@ -446,7 +454,9 @@ namespace sqlite
|
||||
{
|
||||
const uint16_t peer_port = sqlite3_column_int64(stmt, 0);
|
||||
const uint16_t user_port = sqlite3_column_int64(stmt, 1);
|
||||
vacant_ports.push_back({peer_port, user_port});
|
||||
const uint16_t gp_tcp_port = sqlite3_column_int64(stmt, 2);
|
||||
const uint16_t gp_udp_port = sqlite3_column_int64(stmt, 3);
|
||||
vacant_ports.push_back({peer_port, user_port, gp_tcp_port, gp_udp_port});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,9 +510,11 @@ namespace sqlite
|
||||
info.username = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1));
|
||||
info.assigned_ports.user_port = sqlite3_column_int64(stmt, 2);
|
||||
info.assigned_ports.peer_port = sqlite3_column_int64(stmt, 3);
|
||||
info.status = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 4));
|
||||
info.image_name = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 5));
|
||||
info.contract_id = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 6));
|
||||
info.assigned_ports.gp_tcp_port_start = sqlite3_column_int64(stmt, 4);
|
||||
info.assigned_ports.gp_udp_port_start = sqlite3_column_int64(stmt, 5);
|
||||
info.status = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 6));
|
||||
info.image_name = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 7));
|
||||
info.contract_id = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 8));
|
||||
instances.push_back(info);
|
||||
}
|
||||
}
|
||||
@@ -558,8 +570,10 @@ namespace sqlite
|
||||
instance.username = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1));
|
||||
instance.assigned_ports.user_port = sqlite3_column_int64(stmt, 2);
|
||||
instance.assigned_ports.peer_port = sqlite3_column_int64(stmt, 3);
|
||||
instance.status = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 4));
|
||||
instance.image_name = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 5));
|
||||
instance.assigned_ports.gp_tcp_port_start = sqlite3_column_int64(stmt, 4);
|
||||
instance.assigned_ports.gp_udp_port_start = sqlite3_column_int64(stmt, 5);
|
||||
instance.status = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 6));
|
||||
instance.image_name = reinterpret_cast<const char *>(sqlite3_column_text(stmt, 7));
|
||||
|
||||
// Finalize and distroys the statement.
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
Reference in New Issue
Block a user