diff --git a/src/lib/orderman/actors/ilink3/ILinkGW.cpp b/src/lib/orderman/actors/ilink3/ILinkGW.cpp index 850d0c9db..644211083 100644 --- a/src/lib/orderman/actors/ilink3/ILinkGW.cpp +++ b/src/lib/orderman/actors/ilink3/ILinkGW.cpp @@ -46,7 +46,7 @@ ILinkGW::ILinkGW(IL3Connection& con, const Session& session, const Config& conf) void ILinkGW::connect() { bts_assert(state() == State::INIT); - state(State::CONNECTING); + set_state(State::CONNECTING); _connection.connect(*this); // -> on_connect_success } @@ -287,7 +287,7 @@ const char* state_string(State s) { } log::CharPtrWrapper wstate_string(State s) { return wrap(state_string(s)); } -void ILinkGW::state(State s) { +void ILinkGW::set_state(State s) { LOG(OrderMan, Diag, "ILinkGW {}: {}->{}", _session.uuid, wstate_string(_x_state), wstate_string(s)); _x_state = s; @@ -300,7 +300,7 @@ void ILinkGW::state(State s) { void ILinkGW::on_connect_success() { if (_session.from_sequence == 1) { LOG(OrderMan, Info, "Creating new iLink session. {}", _session.uuid); - state(State::NEGOTATING); + set_state(State::NEGOTATING); // Sequence = 1 indicates a new session // so we have to go through a negotiate // to create the session at CME @@ -309,14 +309,14 @@ void ILinkGW::on_connect_success() { else { // We only need to establish the current sequence number LOG(OrderMan, Info, "re-establishing existing iLink session. {}", _session.uuid); - state(State::ESTABLISHING); + set_state(State::ESTABLISHING); send_establish(); } flush(); } void ILinkGW::on_disconnect() { LOG(OrderMan, Error, "Disconnected."); - state(State::ERROR); + set_state(State::ERROR); if (_config.failover_on_disconnect) { LOG(OrderMan, Error, "Attempting failover"); _connection.failover(); @@ -356,7 +356,7 @@ void ILinkGW::handle(const iLinkBinary::NegotiationResponse501& msg) { // There is a previous session and we knew about it // Replay any missing messages if (my_session.from_sequence < cme_prev_seq) { - state(State::RETRANSMISSING_LAST); + set_state(State::RETRANSMISSING_LAST); send_retransmit_request(cme_prev_uuid, my_session.from_sequence); } } @@ -364,7 +364,7 @@ void ILinkGW::handle(const iLinkBinary::NegotiationResponse501& msg) { // there is a previous session we didn't know about // It could be an automatically created start of week session // replay all messages - state(State::RETRANSMISSING_LAST); + set_state(State::RETRANSMISSING_LAST); send_retransmit_request(cme_prev_uuid, 0); } } @@ -379,7 +379,7 @@ void ILinkGW::handle(const iLinkBinary::NegotiationReject502& msg) { msg.errorCodes(), std::string(translate_negotiation_reject(msg.errorCodes())), to_string(msg)); - state(State::ERROR); + set_state(State::ERROR); _connection.disconnect(); } void ILinkGW::handle(const iLinkBinary::EstablishmentAck504&) { @@ -387,6 +387,7 @@ void ILinkGW::handle(const iLinkBinary::EstablishmentAck504&) { // If no missed messagse send the Sequence send_sequence(); flush(); + set_state(State::READY); } void ILinkGW::handle(const iLinkBinary::EstablishmentReject505& msg) { LOG(OrderMan, Error, "Establishment Reject: {} '{}'. NextSeq: {}.\nRaw: \"{}\"", @@ -394,7 +395,7 @@ void ILinkGW::handle(const iLinkBinary::EstablishmentReject505& msg) { std::string(translate_establish_reject(msg.errorCodes())), msg.nextSeqNo(), to_string(msg)); - state(State::ERROR); + set_state(State::ERROR); _connection.disconnect(); } void ILinkGW::handle(const iLinkBinary::Sequence506& s) { @@ -408,7 +409,7 @@ void ILinkGW::handle(const iLinkBinary::Terminate507& msg) { msg.errorCodes(), wrap(msg.reason()) ); - state(State::ERROR); + set_state(State::ERROR); _connection.disconnect(); } void ILinkGW::handle(const iLinkBinary::Retransmission509&) { @@ -429,7 +430,7 @@ void ILinkGW::handle(const iLinkBinary::BusinessReject521& msg) { msg.businessRejectReason(), wrap(translate_business_reject_reason(msg.businessRejectReason())), to_string(msg)); - state(State::ERROR); + set_state(State::ERROR); } void ILinkGW::handle(const iLinkBinary::ExecutionReportNew522& msg) { if (msg.uUID() != _session.uuid) { diff --git a/src/lib/orderman/actors/ilink3/ILinkGW.h b/src/lib/orderman/actors/ilink3/ILinkGW.h index 28606517c..26ffa585d 100644 --- a/src/lib/orderman/actors/ilink3/ILinkGW.h +++ b/src/lib/orderman/actors/ilink3/ILinkGW.h @@ -89,7 +89,7 @@ public: } private: // Functions - void state(State); + void set_state(State); uint32_t next_seq() { return ++_session.to_sequence; } void on_connect_success() override; diff --git a/src/lib/utils/SecureLogon.cpp b/src/lib/utils/SecureLogon.cpp index 7dd164d63..342b542e2 100644 --- a/src/lib/utils/SecureLogon.cpp +++ b/src/lib/utils/SecureLogon.cpp @@ -114,7 +114,7 @@ LogonData calculate_hmac(const std::string& session_id, const std::vector&) { // Typically a timestamp - uint64_t session_id = 1111; + uint64_t session_id = 1111222333; Session session { session_id, 1, 1 }; Config config { std::nullopt, "NGG", "004", false }; Reactor reactor; @@ -53,4 +55,71 @@ std::string CMECert::help() { return "Tool to drive CME Cert"; } +////////////////////////////////////////// +// This code worked once... +////////////////////////////////////////// + +// uint64_t determine_session() { +// // this is fairly complex +// // see session_name.h +// return utils::TimeStamp::now().to_uint64(); +// } + +// template +// std::array mkbuffer() { +// static_assert(sizeof(FramingHeader) == 4); +// return std::array {}; +// } + +// template +// Msg frame_message(std::array& buffer) { +// static_assert(Sz >= 4+iLinkBinary::MessageHeader::encodedLength()+Msg::sbeBlockLength()); +// static_assert(sizeof(FramingHeader) == 4); +// FramingHeader* fhead = reinterpret_cast(&buffer[0]); +// fhead->message_size = buffer.size(); +// fhead->encoding_type = 0xCAFE; +// Msg msg; +// msg.wrapAndApplyHeader((char*)&buffer, sizeof(FramingHeader), buffer.size()); +// return msg; +// } + +// void do_negotiate() { +// // add 2 bytes for empty 'credentials' (39008) length +// auto buffer = mkbuffer(); +// auto msg = frame_message(buffer); + +// // msg.customerFlow(); // constant +// // msg.hMACVersion(); // constant +// msg.uUID(1111); +// msg.requestTimestamp(9999); +// msg.putSession("NGG"); +// // sets the length of the credential block to ushort 00 +// msg.putCredentials(""); +// // pad with 0 at the front *and* null at the back +// const std::string_view firm = "004"; +// // this must use the std::string_view overload +// // the char* overload does not pad correctly +// msg.putFirm(firm); +// const auto ld = glbx::calculate_hmac( +// msg.getSessionAsString(), +// std::to_string(msg.requestTimestamp()), +// std::to_string(msg.uUID()), +// msg.getSessionAsString(), +// firm.data() +// ); +// msg.putAccessKeyID(ld.access_key); +// msg.putHMACSignature(ld.hmac); + +// // connection->send({ buffer.data(), buffer.size() }); + +// auto fd = fopen("/home/eric/old.bin", "wb"); +// if (fd) { +// fwrite(buffer.data(), 1, buffer.size(), fd); +// fclose(fd); +// } +// } + +////////////////////////////////////////// +// This code worked once +////////////////////////////////////////// }}//namespace \ No newline at end of file