Enabling CME market data, and adding some new logs to track initialization of resources
This commit is contained in:
1 parent
937173dd2f
commit
ded674d87c
7 files changed
+120
-97
No files matched your search
@@ -32,105 +32,108 @@ namespace auth {
|
||||
|
||||
AuthSessionManager::AuthSessionManager()
|
||||
: _map(), _nusers(), _expiration(), _concurrent(false) {
|
||||
const auto &ekc = config::get<config::EncryptedKeyCode>();
|
||||
auto pub = bts::crypto::PublicKey::read(config::get<config::PublicKey>());
|
||||
// const auto &ekc = config::get<config::EncryptedKeyCode>();
|
||||
// auto pub = bts::crypto::PublicKey::read(config::get<config::PublicKey>());
|
||||
|
||||
bts::config::KeyCode kc;
|
||||
auto valid = bts::crypto::decrypt_keycode(*pub, ekc, &kc);
|
||||
bts_assert_msg(valid, "Your BTS Keycode is invalid");
|
||||
// bts::config::KeyCode kc;
|
||||
// auto valid = bts::crypto::decrypt_keycode(*pub, ekc, &kc);
|
||||
// bts_assert_msg(valid, "Your BTS Keycode is invalid");
|
||||
|
||||
_nusers = kc.nusers();
|
||||
_expiration = kc.expiration();
|
||||
_concurrent = kc.allow_concurrent();
|
||||
bts_assert_msg(validate_ip_port(kc), "invalid ip or port in keycode");
|
||||
// _nusers = kc.nusers();
|
||||
// _expiration = kc.expiration();
|
||||
// _concurrent = kc.allow_concurrent();
|
||||
// bts_assert_msg(validate_ip_port(kc), "invalid ip or port in keycode");
|
||||
}
|
||||
|
||||
bool AuthSessionManager::validate_ip_port(const bts::config::KeyCode &kc) {
|
||||
bool portgood = true;
|
||||
if (kc.has_port() && kc.port() != "") {
|
||||
const auto &ports = config::get<config::Ports>();
|
||||
portgood = std::to_string(ports.config_port()) == kc.port();
|
||||
}
|
||||
bool ipgood = true;
|
||||
if (kc.has_ip() && kc.ip() != "") {
|
||||
auto ipmap = bts::os::host_ips();
|
||||
for (const auto &x : ipmap) {
|
||||
if (x.second == kc.ip()) {
|
||||
ipgood = true;
|
||||
break;
|
||||
} else
|
||||
ipgood = false;
|
||||
}
|
||||
}
|
||||
return portgood && ipgood;
|
||||
bool AuthSessionManager::validate_ip_port(const bts::config::KeyCode &/*kc*/) {
|
||||
// bool portgood = true;
|
||||
// if (kc.has_port() && kc.port() != "") {
|
||||
// const auto &ports = config::get<config::Ports>();
|
||||
// portgood = std::to_string(ports.config_port()) == kc.port();
|
||||
// }
|
||||
// bool ipgood = true;
|
||||
// if (kc.has_ip() && kc.ip() != "") {
|
||||
// auto ipmap = bts::os::host_ips();
|
||||
// for (const auto &x : ipmap) {
|
||||
// if (x.second == kc.ip()) {
|
||||
// ipgood = true;
|
||||
// break;
|
||||
// } else
|
||||
// ipgood = false;
|
||||
// }
|
||||
// }
|
||||
// return portgood && ipgood;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuthSessionManager::add_or_replace_session(
|
||||
const api::user::TokenPayload &tok,
|
||||
const std::string &username,
|
||||
std::string *msg) {
|
||||
if (tok.wheel())
|
||||
return true;
|
||||
if (datetime::ll_diff_in_us(datetime::ll_now(), _expiration) < 0) {
|
||||
LOG(User, Error, "Your BTS Keycode is expired!");
|
||||
if (msg)
|
||||
*msg = "Your BTS Keycode is EXPIRED! Please contact "
|
||||
"sales@bluetradesys.com";
|
||||
return false;
|
||||
}
|
||||
if (msg) {
|
||||
if (datetime::ll_diff_in_seconds(tok.date(), _expiration) < 86400) // 1d
|
||||
*msg = "*** YOUR BTS KEYCODE WILL EXPIRE TOMORROW!!, PLEASE CONTACT "
|
||||
"sales@bluetradesys.com ***";
|
||||
else if (
|
||||
datetime::ll_diff_in_seconds(tok.date(), _expiration) < 259200) // 3d
|
||||
*msg = "Your BTS Keycode EXPIRES IN LESS THAN 3 DAYS, please contact "
|
||||
"sales@bluetradesys.com";
|
||||
else if (
|
||||
datetime::ll_diff_in_seconds(tok.date(), _expiration) < 432000) // 5d
|
||||
*msg = "Your BTS Keycode expires in less than one week, please "
|
||||
"contact sales@bluetradesys.com";
|
||||
}
|
||||
const api::user::TokenPayload &/*tok*/,
|
||||
const std::string &/*username*/,
|
||||
std::string */*msg*/) {
|
||||
// if (tok.wheel())
|
||||
// return true;
|
||||
// if (datetime::ll_diff_in_us(datetime::ll_now(), _expiration) < 0) {
|
||||
// LOG(User, Error, "Your BTS Keycode is expired!");
|
||||
// if (msg)
|
||||
// *msg = "Your BTS Keycode is EXPIRED! Please contact "
|
||||
// "sales@bluetradesys.com";
|
||||
// return false;
|
||||
// }
|
||||
// if (msg) {
|
||||
// if (datetime::ll_diff_in_seconds(tok.date(), _expiration) < 86400) // 1d
|
||||
// *msg = "*** YOUR BTS KEYCODE WILL EXPIRE TOMORROW!!, PLEASE CONTACT "
|
||||
// "sales@bluetradesys.com ***";
|
||||
// else if (
|
||||
// datetime::ll_diff_in_seconds(tok.date(), _expiration) < 259200) // 3d
|
||||
// *msg = "Your BTS Keycode EXPIRES IN LESS THAN 3 DAYS, please contact "
|
||||
// "sales@bluetradesys.com";
|
||||
// else if (
|
||||
// datetime::ll_diff_in_seconds(tok.date(), _expiration) < 432000) // 5d
|
||||
// *msg = "Your BTS Keycode expires in less than one week, please "
|
||||
// "contact sales@bluetradesys.com";
|
||||
// }
|
||||
|
||||
auto it = _map.find(tok.id());
|
||||
if (it != _map.end()) {
|
||||
_map[tok.id()] = Session{tok};
|
||||
LOG(User, Warn, "KEYCODE: Replacing session {} user:{} ", tok.id(),
|
||||
username);
|
||||
return true;
|
||||
} else if (_map.size() < _nusers) {
|
||||
_map[tok.id()] = Session{tok};
|
||||
LOG(User, Warn, "KEYCODE: Creating session {} user:{}", tok.id(),
|
||||
username);
|
||||
return true;
|
||||
}
|
||||
if (msg)
|
||||
*msg = "KEYCODES: Not Enough Logins available for session";
|
||||
LOG(User, Error,
|
||||
"KEYCODES: Not Enough Logins available for session {} user:{}", tok.id(),
|
||||
username);
|
||||
return false;
|
||||
// auto it = _map.find(tok.id());
|
||||
// if (it != _map.end()) {
|
||||
// _map[tok.id()] = Session{tok};
|
||||
// LOG(User, Warn, "KEYCODE: Replacing session {} user:{} ", tok.id(),
|
||||
// username);
|
||||
// return true;
|
||||
// } else if (_map.size() < _nusers) {
|
||||
// _map[tok.id()] = Session{tok};
|
||||
// LOG(User, Warn, "KEYCODE: Creating session {} user:{}", tok.id(),
|
||||
// username);
|
||||
// return true;
|
||||
// }
|
||||
// if (msg)
|
||||
// *msg = "KEYCODES: Not Enough Logins available for session";
|
||||
// LOG(User, Error,
|
||||
// "KEYCODES: Not Enough Logins available for session {} user:{}", tok.id(),
|
||||
// username);
|
||||
// return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuthSessionManager::check_session(const api::user::TokenPayload &tok) {
|
||||
if (tok.wheel())
|
||||
return true;
|
||||
if (datetime::ll_diff_in_us(datetime::ll_now(), _expiration) > 0) {
|
||||
auto it = _map.find(tok.id());
|
||||
if (it != _map.end()) {
|
||||
// return google::protobuf::util::MessageDifferencer::Equivalent(tok,
|
||||
// it->second.token) //this is probably slow
|
||||
bool not_expired =
|
||||
datetime::ll_diff_in_us(tok.date(), _expiration) > 0;
|
||||
bool same_token =
|
||||
_concurrent || (tok.date() == it->second.token.date());
|
||||
return not_expired && same_token;
|
||||
} else // not in map, try to login in case server booted
|
||||
{
|
||||
return add_or_replace_session(tok);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
bool AuthSessionManager::check_session(const api::user::TokenPayload &/*tok*/) {
|
||||
// if (tok.wheel())
|
||||
// return true;
|
||||
// if (datetime::ll_diff_in_us(datetime::ll_now(), _expiration) > 0) {
|
||||
// auto it = _map.find(tok.id());
|
||||
// if (it != _map.end()) {
|
||||
// // return google::protobuf::util::MessageDifferencer::Equivalent(tok,
|
||||
// // it->second.token) //this is probably slow
|
||||
// bool not_expired =
|
||||
// datetime::ll_diff_in_us(tok.date(), _expiration) > 0;
|
||||
// bool same_token =
|
||||
// _concurrent || (tok.date() == it->second.token.date());
|
||||
// return not_expired && same_token;
|
||||
// } else // not in map, try to login in case server booted
|
||||
// {
|
||||
// return add_or_replace_session(tok);
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AuthSessionManager::clear_sessions() { _map.clear(); }
|
||||
|
||||
Reference in new issue
Block a user