DROP A TRAIN ON IT

This commit is contained in:
malloc 2018-11-05 16:26:55 -06:00
parent 9b3487d567
commit fff2db63b6
5 changed files with 91 additions and 32 deletions

View file

@ -25,7 +25,8 @@ bool sosc::db::init_databases(std::string* error) {
int32_t lastMig = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
if(lastMig > _hard_db_sql.size()) {
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
if(error != nullptr)
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
return false;
}
@ -41,7 +42,8 @@ bool sosc::db::init_databases(std::string* error) {
std::string hash = getMigration.ScalarText();
if(hash.empty()) {
if(id < lastMig) {
*error = "HARD DB: MIGRATION RECORDS NOT CONTINUOUS";
if(error != nullptr)
*error = "HARD DB: MIGRATION RECORDS NOT CONTINUOUS";
return false;
}
@ -52,7 +54,8 @@ bool sosc::db::init_databases(std::string* error) {
insertMigration.NonQuery();
} else {
if(hash != cgc::sha1(_hard_db_sql[id])) {
*error = "HARD DB: MIGRATION SQL HASH MISMATCH";
if(error != nullptr)
*error = "HARD DB: MIGRATION SQL HASH MISMATCH";
return false;
}
}

View file

@ -26,8 +26,6 @@ public:
~MasterClient() { this->Close(); };
private:
bool IsAuthed();
bool ProcessLogin(Packet& pck);
bool ProcessRegistration(Packet& pck);
bool ListServers(Packet& pck);

View file

@ -83,8 +83,9 @@ bool sosc::MasterClient::Process(const db::Queries *queries) {
}
}
bool sosc::MasterClient::IsAuthed() {
bool sosc::MasterClient::ProcessLogin(Packet &pck) {
return true;
}
bool sosc::MasterClient::Close() {

View file

@ -2,37 +2,75 @@
#include <string>
#include <ctime>
#include <thread>
#include "sock/tcpsock.hpp"
#include "utils/string.hpp"
#include "utils/net.hpp"
#include "utils/time.hpp"
#include "sock/tcpsock.hpp"
#include "crypto/sha1.hpp"
#include "crypto/base64.hpp"
#include "crypto/bfish.hpp"
#include "utils/csprng.hpp"
#include "crypto/bcrypt.hpp"
#include "utils/bigint.hpp"
#include "sock/scapesock.hpp"
#include "sock/pool.hpp"
#include "utils/string.hpp"
#include "db/database.hpp"
#include "hosts/master.hpp"
#include "hosts/slave.hpp"
static struct _slave_ctx {
sosc::ScapeServer server;
sosc::SlaveClientPool pool;
};
static struct {
struct {
sosc::IntraServer server;
sosc::MasterIntraPool pool;
} master_intra;
struct {
sosc::ScapeServer server;
sosc::MasterIntraPool pool;
} master_client;
_slave_ctx* slaves;
bool running;
} _ctx;
bool master_intra(uint16_t port, const sosc::poolinfo_t& info);
bool master_client(uint16_t port, const sosc::poolinfo_t& info);
bool slave(uint16_t port, const sosc::poolinfo_t& info);
int main(int argc, char **argv) {
using namespace sosc;
if(argc < 2)
return -1;
if(argv[1][0] == 'm') {
_ctx.running = true;
std::vector<std::thread*> threads;
master_client(8008, sosc::poolinfo_t());
//master_intra(1234, sosc::poolinfo_t());
if(argv[1][0] == 'm') {
if(!db::init_databases(nullptr))
return -1;
threads.push_back(new std::thread([&] {
master_client(8008, poolinfo_t());
}));
threads.push_back(new std::thread([&] {
master_intra(1234, poolinfo_t());
}));
} else {
slave(1234, sosc::poolinfo_t());
threads.push_back(new std::thread([&] {
slave(1234, poolinfo_t());
}));
}
std::cout << "Server threads started. Type STOP to cancel." << std::endl;
std::string input;
while(true) {
std::cin >> input;
str::tolower(str::trim(&input));
if(input == "stop")
break;
}
_ctx.running = false;
for(const auto& thread : threads) {
thread->join();
delete thread;
}
return 0;
@ -49,11 +87,18 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) {
MasterIntraPool pool;
pool.Configure(info);
pool.Start();
while(server.Accept(&client))
pool.AddClient(new MasterIntra(client));
auto listenThread = std::thread([&] {
while (server.Accept(&client))
pool.AddClient(new MasterIntra(client));
});
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true;
}
@ -69,10 +114,17 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) {
pool.Configure(info);
pool.Start();
while(server.Accept(&client))
pool.AddClient(new MasterClient(client));
auto listenThread = std::thread([&] {
while(server.Accept(&client))
pool.AddClient(new MasterClient(client));
});
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true;
}
@ -88,9 +140,16 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) {
pool.Configure(info);
pool.Start();
while(server.Accept(&client))
pool.AddClient(new SlaveClient(client));
auto listenThread = std::thread([&] {
while (server.Accept(&client))
pool.AddClient(new SlaveClient(client));
});
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true;
}

View file

@ -127,8 +127,6 @@ function pack(id, regions) {
body_ptr += length;
}
console.log(regions);
console.log(pck);
return pck;
}