From c11a292f51a16987d44d47e017fc0ec1c06aea94 Mon Sep 17 00:00:00 2001 From: dongl <2725096176@qq.com> Date: Thu, 11 May 2023 18:26:47 +0800 Subject: [PATCH] =?UTF-8?q?test=20init=20request=E5=8C=85=20=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=20?= =?UTF-8?q?=E4=BC=9A=E5=A4=9A=E5=87=BA=E5=AD=97=E8=8A=82=20=E6=B5=AE?= =?UTF-8?q?=E7=82=B9=E5=9E=8Bserver=E8=A7=A3=E6=9E=90=E4=B8=8D=E5=87=BA?= =?UTF-8?q?=E6=9D=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MC/api/CMakeLists.txt | 7 +- MC/api/core/Client.cpp | 130 ++++++++++++++++ MC/api/core/Client.h | 39 +++++ MC/api/main.cpp | 93 +++++++++--- MC/api/user/UserOperation.cpp | 58 ++++++++ MC/api/user/UserOperation.h | 38 +++++ MP/Request.cpp | 28 ++-- MP/Response.cpp | 35 ++--- MP/proto/mp.body.pb.cc | 75 +--------- MP/proto/mp.request.pb.cc | 30 ++-- MP/proto/mp.response.pb.cc | 14 +- MS/MS.cpp | 8 +- MS/mmm/analysis.h | 4 +- MS/mmm/handler.cpp | 14 +- MS/mmm/handler.h | 5 +- MS/mmm/management.cpp | 104 ++++++++++--- MS/mmm/mapping.cpp | 4 +- MS/mmm/session.cpp | 3 +- MS/pool/thread/ev_pool.cpp | 18 ++- MS/pool/thread/ev_pool.h | 2 +- MS/works/controller/PEVerifCodeController.cpp | 2 +- MS/works/controller/PEVerifCodeController.h | 4 +- MS/works/controller/UserProveController.cpp | 11 +- include/mp/Body.h | 2 +- include/mp/Cqi.h | 4 +- include/mp/Request.h | 3 +- include/mp/Response.h | 2 - include/mp/Sri.h | 4 + include/mp/proto/mp.body.pb.h | 139 ------------------ include/mp/proto/mp.request.pb.h | 12 +- include/mp/proto/mp.response.pb.h | 6 +- include/mp/protohuf/mp.body.proto | 2 - include/mp/protohuf/mp.request.proto | 4 +- include/mp/protohuf/mp.response.proto | 2 +- 34 files changed, 555 insertions(+), 351 deletions(-) create mode 100644 MC/api/core/Client.cpp create mode 100644 MC/api/core/Client.h create mode 100644 MC/api/user/UserOperation.cpp create mode 100644 MC/api/user/UserOperation.h diff --git a/MC/api/CMakeLists.txt b/MC/api/CMakeLists.txt index 1096651..0344979 100644 --- a/MC/api/CMakeLists.txt +++ b/MC/api/CMakeLists.txt @@ -5,8 +5,13 @@ include_directories(${CMAKE_SOURCE_DIR}/include/mp) link_directories(${CMAKE_SOURCE_DIR}/lib/libevent) +aux_source_directory(user DIR_USER) +aux_source_directory(core DIR_CORE) -add_executable(MC main.cpp) +add_executable(MC main.cpp + ${DIR_USER} + ${DIR_CORE} + ) target_link_libraries(MC event diff --git a/MC/api/core/Client.cpp b/MC/api/core/Client.cpp new file mode 100644 index 0000000..71157db --- /dev/null +++ b/MC/api/core/Client.cpp @@ -0,0 +1,130 @@ +// +// Created by dongl on 23-5-10. +// + +#include +#include +#include "Client.h" +#include "Mph.h" +#include "Response.h" + + +Client::Client(const std::string& ip, int port) { + std::thread thread([&]() { + init(ip, port); + }); + thread.join(); +} + +void Client::init(const std::string &ip, int port) { + // 初始化时间集合 + base = event_base_new(); + // init socket 初始化socket + bev = bufferevent_socket_new(base, -1, BEV_OPT_CLOSE_ON_FREE); + + // 添加事件 + bufferevent_setcb(bev, readcb, writecb, eventcb, base); + // 启用事件 + bufferevent_enable(bev, EV_READ | EV_WRITE); + + // 服务器地址 + auto c_sin = addr(ip, port); + // 连接 + int ret = bufferevent_socket_connect(bev, (sockaddr *)&c_sin, sizeof(c_sin)); + // 是否链接成功 + if (ret == 0) { + printf("server connected success!\n"); + fflush(stdout); + } +} + +sockaddr_in Client::addr(const std::string &ip, int port) { + sockaddr_in c_sin = {0}; + memset(&c_sin, 0, sizeof(c_sin)); + c_sin = { + AF_INET, + htons(port), + + }; + evutil_inet_pton(AF_INET, ip.c_str(), &c_sin.sin_addr.s_addr); + return c_sin; +} + +void Client::run() { + event_base_dispatch(base); +} + + +Client::~Client() { + bufferevent_free(bev); + event_base_free(base); +} + +void Client::send_data(const std::string &data) { + bufferevent_write(bev, data.c_str(), data.size()); +} + +/// ************ 三个回调 **************//// +void Client::readcb(struct bufferevent *bev, void *ctx) { + printf("[read]: "); + // read L 读包长度 + uint8_t packetLen; + bufferevent_read(bev, &packetLen, 1); + // read V 读包头 + char data_h[256] = {0}; + bufferevent_read(bev, data_h, packetLen); + + auto mph = std::make_shared(mp::mph()); + mph->ParseFromString(data_h); + printf("mph->mpb_size: %d\n", mph->mpb_size()); + + + // read V 读包体 包头内含有包体长度 + char data_b[256] = {0}; + bufferevent_read(bev, data_b, mph->mpb_size()); + printf("data_b: %s\n", data_b); + + mp::response* resp = new mp::response(); + resp->ParseFromString(data_b); + printf("%s\n", resp->sri().sri_msg().c_str()); + + fflush(stdout); +} + +void Client::writecb(struct bufferevent *bev, void *ctx) { + printf("[write]: %p\n", ctx); +} + +void Client::eventcb(struct bufferevent *bev, short what, void *ctx) { + printf("[event]: %p\n", ctx); + + if (what == BEV_EVENT_ERROR) { + printf("[BEV_EVENT_ERROR]: %p\n", ctx); + } + else if (what == BEV_EVENT_EOF) { + printf("[BEV_EVENT_ERROR]\n"); + } + else if (what == BEV_EVENT_CONNECTED) { + printf("[BEV_EVENT_ERROR]\n"); + } +} + + + + + + + + + + + + + + + + + + + + diff --git a/MC/api/core/Client.h b/MC/api/core/Client.h new file mode 100644 index 0000000..889f38b --- /dev/null +++ b/MC/api/core/Client.h @@ -0,0 +1,39 @@ +// +// Created by dongl on 23-5-10. +// + +#ifndef IM2_CLIENT_H +#define IM2_CLIENT_H + +#include +#include +#include "event2/event.h" +#include "event2/bufferevent.h" + +class Client { +public: + Client(const std::string& ip, int port); + virtual ~Client(); + void run(); +private: + void init(const std::string& ip, int port); + sockaddr_in addr(const std::string& ip, int port); + + /// 用户操作函数 +public: + void send_data(const std::string& data); + + // 三个回调 +public: + static void readcb(struct bufferevent *bev, void *ctx); + static void writecb(struct bufferevent *bev, void *ctx); + static void eventcb(struct bufferevent *bev, short what, void *ctx); + +private: + event_base* base; + bufferevent* bev; + event* ev; +}; + + +#endif //IM2_CLIENT_H diff --git a/MC/api/main.cpp b/MC/api/main.cpp index e82676e..589af24 100644 --- a/MC/api/main.cpp +++ b/MC/api/main.cpp @@ -2,6 +2,24 @@ // Created by dongl on 23-4-15. // +//#include "core/Client.h" +//#include "user/UserOperation.h" +// +//int main() { +// auto client = Client("127.0.0.1", 9999); +// client.run(); +// +// auto user = new UserOperation(&client); +// user->login("783556037", "Aa316216"); +// +// +//} + + +// +// Created by dongl on 23-4-15. +// + #include #include #include "Request.h" @@ -11,6 +29,7 @@ void client_read_cb(struct bufferevent *bev, void *ctx); void client_write_cb(struct bufferevent *bev, void *ctx); +void event_cb(struct bufferevent *bev, short what, void *ctx); int main(int argc, char **argv) { event_base *base = event_base_new(); @@ -25,7 +44,7 @@ int main(int argc, char **argv) { evutil_inet_pton(AF_INET, "127.0.0.1", &c_sin.sin_addr.s_addr); - bufferevent_setcb(bev, client_read_cb, client_write_cb, nullptr, nullptr); + bufferevent_setcb(bev, client_read_cb, client_write_cb, event_cb, nullptr); bufferevent_enable(bev, EV_READ | EV_WRITE); int ret = bufferevent_socket_connect(bev, (sockaddr *) &c_sin, sizeof(c_sin)); if (ret == 0) { @@ -34,20 +53,31 @@ int main(int argc, char **argv) { } auto request = new Request(mp::MP_REQUEST_LOGIN, mp::MP_REQUEST_LOGIN_ACCOUNT, "783556037", "Aa316216"); - auto packet = request->operator()(); + auto packet = request->packet(); + bufferevent_write(bev, packet.c_str(), packet.size()); + delete request; + uint8_t l; memcpy(&l, packet.c_str(), 1); memcpy((void *) packet.c_str(), packet.c_str() + 1, packet.size() - 1); - std::string h; - memcpy((void *) h.c_str(), packet.c_str(), l); + char h[256]; + memcpy(h, packet.c_str(), l); + char b[257]; + strncpy(b, packet.c_str() + strlen(h), packet.size() - strlen(h)); auto mph = new mp::mph(); mph->ParseFromString(h); - printf("packet size: %u\n", mph->mpb_size()); - printf("packet size: %zu\n", packet.size()); + printf("h size: %hhu\n", l); + printf("b size: %hhu\n", mph->mpb_size()); + printf("total size: %hhu\n", 1 + l + mph->mpb_size()); + printf("str size: %zu\n", packet.size()); + + std::string temp; + temp.assign(packet.c_str(), packet.length()); + printf("temp str: %s\n", packet.c_str()); fflush(stdout); @@ -57,26 +87,31 @@ int main(int argc, char **argv) { void client_read_cb(struct bufferevent *bev, void *ctx) { printf("[read]: "); - // read L 读包长度 - uint8_t packetLen; - bufferevent_read(bev, &packetLen, 1); - // read V 读包头 - char data_h[256] = {0}; - bufferevent_read(bev, data_h, packetLen); + int i = 0; + while (i < 3) { + i++; + // read L 读包长度 + uint8_t packetLen; + size_t len = bufferevent_read(bev, &packetLen, 1); - auto mph = std::make_shared(mp::mph()); - mph->ParseFromString(data_h); - printf("mph->mpb_size: %d\n", mph->mpb_size()); + // read V 读包头 + char data_h[256] = {0}; + bufferevent_read(bev, data_h, packetLen); + + auto mph = std::make_shared(mp::mph()); + mph->ParseFromString(data_h); + printf("mph->mpb_size: %d\n", mph->mpb_size()); - // read V 读包体 包头内含有包体长度 - char data_b[256] = {0}; - bufferevent_read(bev, data_b, mph->mpb_size()); - printf("data_b: %s\n", data_b); + // read V 读包体 包头内含有包体长度 + char data_b[256] = {0}; + bufferevent_read(bev, data_b, mph->mpb_size()); + printf("data_b: %s\n", data_b); - mp::response* resp = new mp::response(); - resp->ParseFromString(data_b); - printf("%s\n", resp->sri().sri_msg().c_str()); + mp::response* resp = new mp::response(); + resp->ParseFromString(data_b); + printf("%s\n", resp->sri().sri_msg().c_str()); + } fflush(stdout); } @@ -86,4 +121,18 @@ void client_write_cb(struct bufferevent *bev, void *ctx) { // uint32_t len = login(2725096176, "Aa316216", data, sizeof(data)); // bufferevent_write(bev, data, len); // sleep(3); +} + +void event_cb(struct bufferevent *bev, short what, void *ctx) { + printf("[event]\n"); + + if (what == BEV_EVENT_ERROR) { + printf("[BEV_EVENT_ERROR]: %p\n", ctx); + } + else if (what == BEV_EVENT_EOF) { + printf("[BEV_EVENT_ERROR]: %s\n",/* strerror(EVUTIL_SOCKET_ERROR())*/ "xx"); + } + else if (what == BEV_EVENT_CONNECTED) { + printf("[BEV_EVENT_ERROR]\n"); + } } \ No newline at end of file diff --git a/MC/api/user/UserOperation.cpp b/MC/api/user/UserOperation.cpp new file mode 100644 index 0000000..f32f5bf --- /dev/null +++ b/MC/api/user/UserOperation.cpp @@ -0,0 +1,58 @@ +// +// Created by dongl on 23-5-10. +// + +#include +#include "UserOperation.h" + +UserOperation::UserOperation(Client *client) { + this->client = client; +} + +UserOperation::~UserOperation() { + +} + +//// packet +std::string UserOperation::packet_base(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string &account, const std::string &password) { + auto request = new Request(type, subType, account, password); + std::string temp = request->packet(); + delete request; + return temp; +} + +//// login +std::string UserOperation::login_packet(mp::MP_SUB_TYPE subType, const std::string &account, const std::string &password) { + return packet_base(mp::MP_REQUEST_LOGIN, subType, account, password); +} + +std::optional UserOperation::login(const std::string &account, const std::string &password) { + std::regex pattern_email(R"(\w+@(\w+\.)+\w+)"); + std::regex pattern_account("[1-9](\\d{5,11})"); + std::regex pattern_phone("1(3\\d|47|5([0-3]|[5-9])|8(0|2|[5-9]))\\d{8}$"); + + std::string packet; + if (std::regex_match(account, pattern_email)) { + packet = login_packet(LOGIN_EMAIL, account, password); + } else if (std::regex_match(account, pattern_account)) { + packet = login_packet(LOGIN_ACCOUNT, account, password); + } else if (std::regex_match(account, pattern_phone)) { + packet = login_packet(LOGIN_PHONE, account, password); + } else { + return std::nullopt; + } + + client->send_data(packet); + + return packet; +} + + +//// login + + + + + + + diff --git a/MC/api/user/UserOperation.h b/MC/api/user/UserOperation.h new file mode 100644 index 0000000..c3d49e8 --- /dev/null +++ b/MC/api/user/UserOperation.h @@ -0,0 +1,38 @@ +// +// Created by dongl on 23-5-10. +// + +#ifndef IM2_USEROPERATION_H +#define IM2_USEROPERATION_H + + +#include +#include +#include "Request.h" +#include "event2/bufferevent.h" +#include "../core/Client.h" + + +#define LOGIN_ACCOUNT mp::MP_REQUEST_LOGIN_ACCOUNT +#define LOGIN_PHONE mp::MP_REQUEST_LOGIN_PHONE +#define LOGIN_EMAIL mp::MP_REQUEST_LOGIN_EMAIL + + +class UserOperation { +public: + explicit UserOperation(Client* bev); + virtual ~UserOperation(); + +public: + std::optional login(const std::string& account, const std::string& password); + +private: + std::string packet_base(mp::MP_TYPE, mp::MP_SUB_TYPE, const std::string &account, const std::string &password); + std::string login_packet(mp::MP_SUB_TYPE subType, const std::string &account, const std::string &password); + +private: + Client* client; +}; + + +#endif //IM2_USEROPERATION_H diff --git a/MP/Request.cpp b/MP/Request.cpp index 0641f8d..740d6a9 100644 --- a/MP/Request.cpp +++ b/MP/Request.cpp @@ -16,30 +16,34 @@ Mph(type), Body(target, source, data), Cqi() { } +Request::~Request() { + delete request; +} + void Request::init() { - memset(temp, 0 , 256); request = new mp::request(); request->set_allocated_body(body); request->set_allocated_cqi(cqi); mph->set_mpb_size(body->ByteSizeLong() + cqi->ByteSizeLong()); } -std::string Request::operator()() { +std::string Request::packet() { init(); - std::string temp_mph; - std::string temp_request; - mph->SerializeToString(&temp_mph); - request->SerializeToString(&temp_request); + std::string temp; + + temp.push_back(mph->ByteSizeLong()); + std::cout << temp << std::endl; + mph->AppendToString(&temp); + std::cout << temp << std::endl; + request->AppendToString(&temp); + std::cout << temp << std::endl; - auto L = (uint8_t )temp_mph.size(); - sprintf(temp, "%c", L); - sprintf(temp, "%s%s%s", temp, temp_mph.c_str(), temp_request.c_str()); return temp; } -Request::~Request() { - delete request; -} + + + diff --git a/MP/Response.cpp b/MP/Response.cpp index 4a9e208..9d4d872 100644 --- a/MP/Response.cpp +++ b/MP/Response.cpp @@ -14,38 +14,27 @@ Response::~Response() { } void Response::init() { - memset(temp, 0 , 256); response = new mp::response(); response->set_allocated_sri(sri); mph->set_mpb_size( response->ByteSizeLong()); } -std::string Response::operator()() { - init(); - std::string temp_mph; - std::string temp_request; - - mph->SerializeToString(&temp_mph); - response->SerializeToString(&temp_request); - - uint8_t size = mph->ByteSizeLong(); - sprintf(temp, "%c", size); - sprintf(temp, "%s%s%s", temp, temp_mph.c_str(), temp_request.c_str()); - // time: 0426 19:54 debug return 这里反复执行 然后temp 字符串就乱了 变了 ? 原因不明确 - return temp; -} - std::string Response::packet () { init(); - std::string temp_mph; - std::string temp_request; + std::string temp; - mph->SerializeToString(&temp_mph); - response->SerializeToString(&temp_request); + temp.push_back(mph->ByteSizeLong()); + std::cout << temp << std::endl; + mph->AppendToString(&temp); + std::cout << temp << std::endl; + response->AppendToString(&temp); + std::cout << temp << std::endl; - uint8_t size = mph->ByteSizeLong(); - sprintf(temp, "%c", size); - sprintf(temp, "%s%s%s", temp, temp_mph.c_str(), temp_request.c_str()); + + printf("h size: %zu\n", mph->ByteSizeLong()); + printf("b size: %hhu\n", mph->mpb_size()); + printf("total size: %zu\n", 1 + mph->ByteSizeLong() + mph->mpb_size()); + printf("str size: %zu\n", temp.size()); return temp; } diff --git a/MP/proto/mp.body.pb.cc b/MP/proto/mp.body.pb.cc index e13beb9..605a8f8 100644 --- a/MP/proto/mp.body.pb.cc +++ b/MP/proto/mp.body.pb.cc @@ -50,8 +50,6 @@ const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_mp_2ebody_2eproto::offsets[] P PROTOBUF_FIELD_OFFSET(::mp::body, target_), PROTOBUF_FIELD_OFFSET(::mp::body, source_), PROTOBUF_FIELD_OFFSET(::mp::body, data_), - PROTOBUF_FIELD_OFFSET(::mp::body, email_), - PROTOBUF_FIELD_OFFSET(::mp::body, phone_), }; static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(::mp::body)}, @@ -62,11 +60,11 @@ static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = }; const char descriptor_table_protodef_mp_2ebody_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = - "\n\rmp.body.proto\022\002mp\032\014mp.mph.proto\"\232\001\n\004bo" - "dy\022#\n\nsubcommand\030\001 \001(\0162\017.mp.MP_SUB_TYPE\022" - "\017\n\007account\030\002 \001(\t\022\020\n\010password\030\003 \001(\t\022\016\n\006ta" - "rget\030\004 \001(\004\022\016\n\006source\030\005 \001(\004\022\014\n\004data\030\006 \001(\t" - "\022\r\n\005email\030\007 \001(\t\022\r\n\005phone\030\010 \001(\004b\006proto3" + "\n\rmp.body.proto\022\002mp\032\014mp.mph.proto\"|\n\004bod" + "y\022#\n\nsubcommand\030\001 \001(\0162\017.mp.MP_SUB_TYPE\022\017" + "\n\007account\030\002 \001(\t\022\020\n\010password\030\003 \001(\t\022\016\n\006tar" + "get\030\004 \001(\004\022\016\n\006source\030\005 \001(\004\022\014\n\004data\030\006 \001(\tb" + "\006proto3" ; static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_mp_2ebody_2eproto_deps[1] = { &::descriptor_table_mp_2emph_2eproto, @@ -76,7 +74,7 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_mp_ }; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_mp_2ebody_2eproto_once; const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_mp_2ebody_2eproto = { - false, false, descriptor_table_protodef_mp_2ebody_2eproto, "mp.body.proto", 198, + false, false, descriptor_table_protodef_mp_2ebody_2eproto, "mp.body.proto", 167, &descriptor_table_mp_2ebody_2eproto_once, descriptor_table_mp_2ebody_2eproto_sccs, descriptor_table_mp_2ebody_2eproto_deps, 1, 1, schemas, file_default_instances, TableStruct_mp_2ebody_2eproto::offsets, file_level_metadata_mp_2ebody_2eproto, 1, file_level_enum_descriptors_mp_2ebody_2eproto, file_level_service_descriptors_mp_2ebody_2eproto, @@ -118,11 +116,6 @@ body::body(const body& from) data_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_data(), GetArena()); } - email_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_email().empty()) { - email_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_email(), - GetArena()); - } ::memcpy(&target_, &from.target_, static_cast(reinterpret_cast(&subcommand_) - reinterpret_cast(&target_)) + sizeof(subcommand_)); @@ -134,7 +127,6 @@ void body::SharedCtor() { account_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); password_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); data_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - email_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); ::memset(&target_, 0, static_cast( reinterpret_cast(&subcommand_) - reinterpret_cast(&target_)) + sizeof(subcommand_)); @@ -151,7 +143,6 @@ void body::SharedDtor() { account_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); password_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); data_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - email_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } void body::ArenaDtor(void* object) { @@ -178,7 +169,6 @@ void body::Clear() { account_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); password_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); data_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - email_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); ::memset(&target_, 0, static_cast( reinterpret_cast(&subcommand_) - reinterpret_cast(&target_)) + sizeof(subcommand_)); @@ -242,22 +232,6 @@ const char* body::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inter CHK_(ptr); } else goto handle_unusual; continue; - // string email = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - auto str = _internal_mutable_email(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "mp.body.email")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint64 phone = 8; - case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 64)) { - phone_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; default: { handle_unusual: if ((tag & 7) == 4 || tag == 0) { @@ -335,22 +309,6 @@ failure: 6, this->_internal_data(), target); } - // string email = 7; - if (this->email().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_email().data(), static_cast(this->_internal_email().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "mp.body.email"); - target = stream->WriteStringMaybeAliased( - 7, this->_internal_email(), target); - } - - // uint64 phone = 8; - if (this->phone() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt64ToArray(8, this->_internal_phone(), target); - } - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); @@ -388,13 +346,6 @@ size_t body::ByteSizeLong() const { this->_internal_data()); } - // string email = 7; - if (this->email().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_email()); - } - // uint64 target = 4; if (this->target() != 0) { total_size += 1 + @@ -409,13 +360,6 @@ size_t body::ByteSizeLong() const { this->_internal_source()); } - // uint64 phone = 8; - if (this->phone() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt64Size( - this->_internal_phone()); - } - // .mp.MP_SUB_TYPE subcommand = 1; if (this->subcommand() != 0) { total_size += 1 + @@ -462,18 +406,12 @@ void body::MergeFrom(const body& from) { if (from.data().size() > 0) { _internal_set_data(from._internal_data()); } - if (from.email().size() > 0) { - _internal_set_email(from._internal_email()); - } if (from.target() != 0) { _internal_set_target(from._internal_target()); } if (from.source() != 0) { _internal_set_source(from._internal_source()); } - if (from.phone() != 0) { - _internal_set_phone(from._internal_phone()); - } if (from.subcommand() != 0) { _internal_set_subcommand(from._internal_subcommand()); } @@ -503,7 +441,6 @@ void body::InternalSwap(body* other) { account_.Swap(&other->account_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); password_.Swap(&other->password_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); data_.Swap(&other->data_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - email_.Swap(&other->email_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); ::PROTOBUF_NAMESPACE_ID::internal::memswap< PROTOBUF_FIELD_OFFSET(body, subcommand_) + sizeof(body::subcommand_) diff --git a/MP/proto/mp.request.pb.cc b/MP/proto/mp.request.pb.cc index 3d60605..48c1ceb 100644 --- a/MP/proto/mp.request.pb.cc +++ b/MP/proto/mp.request.pb.cc @@ -1,7 +1,7 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: mp.request.proto -#include "mp.request.pb.h" +#include "proto/mp.request.pb.h" #include @@ -61,8 +61,8 @@ static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = const char descriptor_table_protodef_mp_2erequest_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = "\n\020mp.request.proto\022\002mp\032\rmp.body.proto\032\014m" - "p.cqi.proto\"7\n\007request\022\026\n\004body\030\002 \001(\0132\010.m" - "p.body\022\024\n\003cqi\030\003 \001(\0132\007.mp.cqib\006proto3" + "p.cqi.proto\"7\n\007request\022\026\n\004body\030\001 \001(\0132\010.m" + "p.body\022\024\n\003cqi\030\002 \001(\0132\007.mp.cqib\006proto3" ; static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_mp_2erequest_2eproto_deps[2] = { &::descriptor_table_mp_2ebody_2eproto, @@ -198,16 +198,16 @@ const char* request::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); CHK_(ptr); switch (tag >> 3) { - // .mp.body body = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { + // .mp.body body = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { ptr = ctx->ParseMessage(_internal_mutable_body(), ptr); CHK_(ptr); } else goto handle_unusual; continue; - // .mp.cqi cqi = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { + // .mp.cqi cqi = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { ptr = ctx->ParseMessage(_internal_mutable_cqi(), ptr); CHK_(ptr); } else goto handle_unusual; @@ -240,20 +240,20 @@ failure: ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - // .mp.body body = 2; + // .mp.body body = 1; if (this->has_body()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessage( - 2, _Internal::body(this), target, stream); + 1, _Internal::body(this), target, stream); } - // .mp.cqi cqi = 3; + // .mp.cqi cqi = 2; if (this->has_cqi()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessage( - 3, _Internal::cqi(this), target, stream); + 2, _Internal::cqi(this), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -272,14 +272,14 @@ size_t request::ByteSizeLong() const { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - // .mp.body body = 2; + // .mp.body body = 1; if (this->has_body()) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( *body_); } - // .mp.cqi cqi = 3; + // .mp.cqi cqi = 2; if (this->has_cqi()) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( diff --git a/MP/proto/mp.response.pb.cc b/MP/proto/mp.response.pb.cc index 381ae42..7c61c38 100644 --- a/MP/proto/mp.response.pb.cc +++ b/MP/proto/mp.response.pb.cc @@ -58,7 +58,7 @@ static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = const char descriptor_table_protodef_mp_2eresponse_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = "\n\021mp.response.proto\022\002mp\032\014mp.sri.proto\" \n" - "\010response\022\024\n\003sri\030\003 \001(\0132\007.mp.srib\006proto3" + "\010response\022\024\n\003sri\030\001 \001(\0132\007.mp.srib\006proto3" ; static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_mp_2eresponse_2eproto_deps[1] = { &::descriptor_table_mp_2esri_2eproto, @@ -168,9 +168,9 @@ const char* response::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); CHK_(ptr); switch (tag >> 3) { - // .mp.sri sri = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { + // .mp.sri sri = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { ptr = ctx->ParseMessage(_internal_mutable_sri(), ptr); CHK_(ptr); } else goto handle_unusual; @@ -203,12 +203,12 @@ failure: ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - // .mp.sri sri = 3; + // .mp.sri sri = 1; if (this->has_sri()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessage( - 3, _Internal::sri(this), target, stream); + 1, _Internal::sri(this), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -227,7 +227,7 @@ size_t response::ByteSizeLong() const { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - // .mp.sri sri = 3; + // .mp.sri sri = 1; if (this->has_sri()) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( diff --git a/MS/MS.cpp b/MS/MS.cpp index 19c40af..4f40470 100644 --- a/MS/MS.cpp +++ b/MS/MS.cpp @@ -57,7 +57,6 @@ void MS::link(struct evconnlistener *e, int fd, struct sockaddr *addr, int sockl printf("listen_cb\n"); pool->add_buffer_event(fd, read_cb, write_cb, event_cb, BEV_OPT_CLOSE_ON_FREE, (sockaddr_in*)addr); - fflush(stdout); } @@ -85,12 +84,15 @@ void MS::write_cb(struct bufferevent *bev, void *ctx) { } void MS::event_cb(struct bufferevent *bev, short what, void *ctx) { - printf("[event]: %p\n", ctx); + BBCA* bbca = (BBCA*) ctx; + auto addr = bbca->addr; + auto base = bbca->base; + + printf("[event]: %p\n", base); if (what == BEV_EVENT_EOF || BEV_EVENT_ERROR || BEV_EVENT_TIMEOUT) { printf("客户端退出\n"); handler::remove_user(bev); } - fflush(stdout); } diff --git a/MS/mmm/analysis.h b/MS/mmm/analysis.h index 4960b85..834eb7c 100644 --- a/MS/mmm/analysis.h +++ b/MS/mmm/analysis.h @@ -19,11 +19,11 @@ public: std::shared_ptr operator () (bufferevent* bev, sockaddr_in* addr) { // agreement_request - auto type = m_mph->mp_type(); auto agreementRequest = std::make_shared(agreement_request()); // request auto request = std::make_shared(mp::request()); + request->ParseFromString(m_data); agreementRequest->set(m_mph, request, bev, addr); @@ -31,7 +31,7 @@ public: } private: std::shared_ptr m_mph; - char* m_data = nullptr; + char* m_data; }; diff --git a/MS/mmm/handler.cpp b/MS/mmm/handler.cpp index ef0cf57..2d4a8e4 100644 --- a/MS/mmm/handler.cpp +++ b/MS/mmm/handler.cpp @@ -2,12 +2,11 @@ // Created by dongl on 23-4-28. // -#include #include "handler.h" #include "Response.h" // handler 保有 session -session* handler::g_session = new session(); +session* handler::session = new class session(); /// resp im void handler::resp(const std::shared_ptr& request, @@ -15,8 +14,8 @@ void handler::resp(const std::shared_ptr& request, /// 用户操作逻辑包 // 定义100序号一下的为操作逻辑业务逻辑 请求与响应 +20 就能一一对应 // 例如 login包类型为 request login==0 那么响应这个登陆信息就是 response login==0+20 - // 100 以上 为im msg 通讯的包类型序号 - if (request->m_mph->mp_type() < 100) { + // 200 以上 为im msg 通讯的包类型序号 + if (request->m_mph->mp_type() < 200) { auto resp = new Response((mp::MP_TYPE) (request->m_mph->mp_type() + 20), response->m_sri.sri_code(), response->m_sri.sri_username(), response->m_sri.sri_msg(), response->m_sri.sri_token()); @@ -31,10 +30,11 @@ void handler::resp(const std::shared_ptr& request, } } /// end resp im + // 聊天消息包 void handler::send(const std::shared_ptr &request, const std::shared_ptr &response) { // 查询在线的用户信息 - auto ret = g_session->find_user_fd(request->m_body.target()); + auto ret = session->find_user_fd(request->m_body.target()); // 用户信息结构体 userinfo *user; if (ret.has_value()) { @@ -50,6 +50,10 @@ handler::ccp2p(const std::shared_ptr &request, const std::sha } +void handler::remove_user(bufferevent* bev) { + session->remove_user(bev); +} + diff --git a/MS/mmm/handler.h b/MS/mmm/handler.h index 8db9ff9..cc56c1a 100644 --- a/MS/mmm/handler.h +++ b/MS/mmm/handler.h @@ -20,8 +20,11 @@ public: static void send(const std::shared_ptr& request, const std::shared_ptr& response); static void ccp2p(const std::shared_ptr& request, const std::shared_ptr& response); +public: + static void remove_user(bufferevent* bev); + protected: - static session* g_session; + static class session* session; }; diff --git a/MS/mmm/management.cpp b/MS/mmm/management.cpp index 87ef3d7..076b71c 100644 --- a/MS/mmm/management.cpp +++ b/MS/mmm/management.cpp @@ -6,7 +6,6 @@ #include "Response.h" - management::management() { } @@ -20,29 +19,96 @@ void management::send_packet(bufferevent *bev) { } -void management::read_packet(bufferevent *bev, sockaddr_in* addr) { - // read L 读包长度 - uint8_t packetLen; - bufferevent_read(bev, &packetLen, 1); - // read V 读包头 - char data_h[256] = {0}; - bufferevent_read(bev, data_h, packetLen); +void management::read_packet(bufferevent *bev, sockaddr_in *addr) { +// while (true) { +// // read L 读包长度 +// uint8_t packetLen; +// size_t len1 = bufferevent_read(bev, &packetLen, 1); +// if (len1 == 0) { +// break; +// } +// +// // read V 读包头 +// char data_h[256] = {0}; +// size_t len2 = bufferevent_read(bev, data_h, packetLen); +// if (len2 == 0) { +// break; +// } +// +// auto mph = std::make_shared(mp::mph()); +// mph->ParseFromString(data_h); +// +// // read V 读包体 包头内含有包体长度 +// char data_b[256] = {0}; +// size_t len3 = bufferevent_read(bev, data_b, mph->mpb_size()); +// if (len3 == 0) { +// break; +// } +// +// // 请求 +// auto request = analysis(mph, data_b)(bev, addr); +// // 响应 +// auto response= std::make_shared(agreement_response()); +// // 执行逻辑 自定义 +// mapping::run(mph->mp_type(), request, response); +// } - auto mph = std::make_shared(mp::mph()); - mph->ParseFromString(data_h); + char buff[2048] = {0}; + std::atomic len_index = bufferevent_read(bev, buff, 2048); - // read V 读包体 包头内含有包体长度 - char data_b[256] = {0}; - bufferevent_read(bev, data_b, mph->mpb_size()); + // 处理粘包 + char packet_h[50] = {0}; + char packet_b[256] = {0}; + while (len_index > 0) { + memset(packet_h, 0, sizeof(packet_h)); + memset(packet_b, 0, sizeof(packet_b)); - // 请求 - auto request = analysis(mph, data_b)(bev, addr); - // 响应 - auto response= std::make_shared(agreement_response()); - // 执行逻辑 自定义 - mapping::run(mph->mp_type(), request, response); + std::cout << len_index << std::endl; + std::cout << buff << std::endl; + + /// read L 读包长度 + uint8_t packetLen; + // 取包长度 + memcpy(&packetLen, buff, 1); + // 更新buffer + memcpy(buff, buff + 1, strlen(buff) - 1); + // 更新buffer长度 + len_index -= 1; + + /// read V 读包头 + // 取包头 + memcpy(packet_h, buff, packetLen); + // 更新buffer + memcpy(buff, buff + packetLen, strlen(buff) - packetLen); + // 更新buffer长度 + len_index -= packetLen; + + // 解包 + auto mph = std::make_shared(mp::mph()); + mph->ParseFromString(packet_h); + + /// read V 读包体 包头内含有包体长度 + // 取包体 + memcpy(packet_b, buff, mph->mpb_size()); + // 更新buffer + memcpy(buff, buff + mph->mpb_size(), strlen(buff) - mph->mpb_size()); + // 更新buffer长度 + len_index -= mph->mpb_size(); + + std::cout << buff << std::endl; + + // 请求 + auto request = analysis(mph, packet_b)(bev, addr); + // 响应 + auto response = std::make_shared(agreement_response()); + // 执行逻辑 自定义 + mapping::run(mph->mp_type(), request, response); + } } + + + diff --git a/MS/mmm/mapping.cpp b/MS/mmm/mapping.cpp index 338466c..2833487 100644 --- a/MS/mmm/mapping.cpp +++ b/MS/mmm/mapping.cpp @@ -36,9 +36,9 @@ void mapping::run(const mp::MP_TYPE mpTYpe, std::shared_ptr& printf("[packet type]:%s\n", myenumToString(mpTYpe)); // 取出需要的执行对象 auto fun = map.find(mpTYpe)->second; - // 开始执行 请求 + // 开始执行 处理请求的数据 fun->run(request, response); - // 发送 响应 + // 发送 响应数据 handler::resp(request, response); } diff --git a/MS/mmm/session.cpp b/MS/mmm/session.cpp index 71d5d40..4be891a 100644 --- a/MS/mmm/session.cpp +++ b/MS/mmm/session.cpp @@ -30,11 +30,12 @@ void session::remove_user(bufferevent *bev) { } user_fd.erase(target_ele); + bufferevent_free(bev); } void session::remove_user(const std::shared_ptr& request) { - bufferevent_free(request->m_bev); user_fd.erase(strtol(request->m_body.account().c_str(), nullptr, 0)); + bufferevent_free(request->m_bev); } bool session::is_user(const std::string& account) { diff --git a/MS/pool/thread/ev_pool.cpp b/MS/pool/thread/ev_pool.cpp index c5e977b..6a6dc2c 100644 --- a/MS/pool/thread/ev_pool.cpp +++ b/MS/pool/thread/ev_pool.cpp @@ -51,13 +51,27 @@ void read(evutil_socket_t, short, void *) { fflush(stdout); } -void ev_pool::add_buffer_event(evutil_socket_t fd, bufferevent_data_cb readcb, bufferevent_data_cb writecb, +bufferevent* ev_pool::add_buffer_event(evutil_socket_t fd, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, short events, sockaddr_in* addr) { // 调度一个base集合; event_base* base = dispatching(); // 创建socket链接监听 bufferevent* bev = bufferevent_socket_new(base, fd, events); + /// 设置水位 + // 读取缓冲水位 + bufferevent_setwatermark(bev, + EV_READ, + 1, // 低水位 0 就是无限制 最小取出量 + 10240 // 高水位 0 就是无限制 当前最大容量 直接取出 + ); + // 输出缓冲区水位 + bufferevent_setwatermark(bev, + EV_WRITE, + 39, // 低水位 输出缓冲区数据低于1024 才会继续向缓冲写入数据 写入回调被发送 设置 输出缓冲区的大小 就是? + 0 // 高水位无效 + ); + BBCA* bbca = new BBCA(); bbca->base = base; bbca->addr = addr; @@ -68,6 +82,8 @@ void ev_pool::add_buffer_event(evutil_socket_t fd, bufferevent_data_cb readcb, b bufferevent_enable(bev, EV_READ | EV_WRITE); m_bevs.insert(std::pair(base, bev)); printf("event_base: %p, fd: %d\n", base, fd); + + return bev; } void ev_pool::add_event(evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg) { diff --git a/MS/pool/thread/ev_pool.h b/MS/pool/thread/ev_pool.h index 880c998..282b892 100644 --- a/MS/pool/thread/ev_pool.h +++ b/MS/pool/thread/ev_pool.h @@ -23,7 +23,7 @@ public: void add_event_base(const std::function& function); void add_event_bases(int num); bool polling(bool poll = false); - void add_buffer_event(evutil_socket_t fd, bufferevent_data_cb readcb, bufferevent_data_cb writecb, + bufferevent* add_buffer_event(evutil_socket_t fd, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, short events, sockaddr_in* addr); void add_event(evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg); event_base* dispatching(); diff --git a/MS/works/controller/PEVerifCodeController.cpp b/MS/works/controller/PEVerifCodeController.cpp index ef3dcef..604566b 100644 --- a/MS/works/controller/PEVerifCodeController.cpp +++ b/MS/works/controller/PEVerifCodeController.cpp @@ -13,7 +13,7 @@ void PEVerifCodeController::run(std::shared_ptr request, std: // 发送验证码至邮 bool state = peVerifCodeService.send_email(request->m_body.account(), code); // 设置session 字段 - g_session->set_session(request->m_bev, "code", code); + session->set_session(request->m_bev, "code", code); if (state) { sri->set_sri_code(mp::MP_PE_CODE_SUCCESS); diff --git a/MS/works/controller/PEVerifCodeController.h b/MS/works/controller/PEVerifCodeController.h index 0fad11e..f208ed1 100644 --- a/MS/works/controller/PEVerifCodeController.h +++ b/MS/works/controller/PEVerifCodeController.h @@ -15,8 +15,8 @@ public: private: PEVerifCodeService peVerifCodeService = PEVerifCodeService(); - static std::map session; // 客户端 fd 与 code 绑定的 session - static std::map time_wheel; // 时间轮定时容器 看验证码超时的 +// static std::map session; // 客户端 fd 与 code 绑定的 session +// static std::map time_wheel; // 时间轮定时容器 看验证码超时的 }; diff --git a/MS/works/controller/UserProveController.cpp b/MS/works/controller/UserProveController.cpp index 8f8cfbe..0a865af 100644 --- a/MS/works/controller/UserProveController.cpp +++ b/MS/works/controller/UserProveController.cpp @@ -5,6 +5,9 @@ #include "UserProveController.h" void UserProveController::run(std::shared_ptr request, std::shared_ptr response) { + printf("客户端版本:%f", request->m_cqi.cqi_version()); + printf("account:%s", request->m_body.account().c_str()); + // 登陆 if (request->m_mph->mp_type() == mp::MP_REQUEST_LOGIN) { auto sri = service.login(request->m_body.subcommand(), @@ -12,22 +15,22 @@ void UserProveController::run(std::shared_ptr request, std::s response->set(sri, request->m_bev); // 登陆的用户 直接在全局 注册 在map中 直接存入服务器内存 - handler::add_user(sri, request); + session->add_user(sri, request); } // 注册 else if (request->m_mph->mp_type() == mp::MP_REQUEST_REGISTER) { auto sri = service.register_(request->m_body.subcommand(), - request->m_body.email(), request->m_body.password()); + request->m_body.account(), request->m_body.password()); response->set(sri, request->m_bev); } // 退出登陆 else if (request->m_mph->mp_type() == mp::MP_REQUEST_LOGOUT) { // 查看当前用户是否在线 - bool state = handler::is_user(request->m_body.account()); + bool state = session->is_user(request->m_body.account()); // current user list used redis 在优化 if (state) { - handler::remove_user(request); + session->remove_user(request); auto sri = service.logout(request->m_body.account(), state); response->set(sri, request->m_bev); } else { diff --git a/include/mp/Body.h b/include/mp/Body.h index cd6d834..2194540 100644 --- a/include/mp/Body.h +++ b/include/mp/Body.h @@ -41,7 +41,7 @@ public: } virtual ~Body() { - delete body; + } protected: diff --git a/include/mp/Cqi.h b/include/mp/Cqi.h index 680c543..ec7a8ec 100644 --- a/include/mp/Cqi.h +++ b/include/mp/Cqi.h @@ -17,11 +17,11 @@ public: #else cqi->set_cqi_type(mp::MC_TYPE_LINUX); #endif - cqi->set_cqi_version(0.01); + cqi->set_cqi_version(3.01); } virtual ~Cqi() { - delete cqi; + } protected: diff --git a/include/mp/Request.h b/include/mp/Request.h index 011014d..50eec2c 100644 --- a/include/mp/Request.h +++ b/include/mp/Request.h @@ -18,12 +18,11 @@ public: ~Request() override; public: - std::string operator ()(); + std::string packet(); private: void init(); private: mp::request* request = nullptr; - char temp[256]{}; }; diff --git a/include/mp/Response.h b/include/mp/Response.h index f87e93c..e8e5298 100644 --- a/include/mp/Response.h +++ b/include/mp/Response.h @@ -18,14 +18,12 @@ public: ~Response() override; - std::string operator () (); std::string packet (); private: void init(); private: mp::response* response = nullptr; - char temp[256]{}; }; diff --git a/include/mp/Sri.h b/include/mp/Sri.h index bbf0881..0fbdc3a 100644 --- a/include/mp/Sri.h +++ b/include/mp/Sri.h @@ -20,6 +20,10 @@ public: Sri() {} + virtual ~Sri() { + + } + public: mp::sri* sri = nullptr; }; diff --git a/include/mp/proto/mp.body.pb.h b/include/mp/proto/mp.body.pb.h index e6d8098..6e5b022 100644 --- a/include/mp/proto/mp.body.pb.h +++ b/include/mp/proto/mp.body.pb.h @@ -183,10 +183,8 @@ class body PROTOBUF_FINAL : kAccountFieldNumber = 2, kPasswordFieldNumber = 3, kDataFieldNumber = 6, - kEmailFieldNumber = 7, kTargetFieldNumber = 4, kSourceFieldNumber = 5, - kPhoneFieldNumber = 8, kSubcommandFieldNumber = 1, }; // string account = 2; @@ -264,31 +262,6 @@ class body PROTOBUF_FINAL : std::string* _internal_mutable_data(); public: - // string email = 7; - void clear_email(); - const std::string& email() const; - void set_email(const std::string& value); - void set_email(std::string&& value); - void set_email(const char* value); - void set_email(const char* value, size_t size); - std::string* mutable_email(); - std::string* release_email(); - void set_allocated_email(std::string* email); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - std::string* unsafe_arena_release_email(); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - void unsafe_arena_set_allocated_email( - std::string* email); - private: - const std::string& _internal_email() const; - void _internal_set_email(const std::string& value); - std::string* _internal_mutable_email(); - public: - // uint64 target = 4; void clear_target(); ::PROTOBUF_NAMESPACE_ID::uint64 target() const; @@ -307,15 +280,6 @@ class body PROTOBUF_FINAL : void _internal_set_source(::PROTOBUF_NAMESPACE_ID::uint64 value); public: - // uint64 phone = 8; - void clear_phone(); - ::PROTOBUF_NAMESPACE_ID::uint64 phone() const; - void set_phone(::PROTOBUF_NAMESPACE_ID::uint64 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint64 _internal_phone() const; - void _internal_set_phone(::PROTOBUF_NAMESPACE_ID::uint64 value); - public: - // .mp.MP_SUB_TYPE subcommand = 1; void clear_subcommand(); ::mp::MP_SUB_TYPE subcommand() const; @@ -335,10 +299,8 @@ class body PROTOBUF_FINAL : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr account_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr password_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr data_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr email_; ::PROTOBUF_NAMESPACE_ID::uint64 target_; ::PROTOBUF_NAMESPACE_ID::uint64 source_; - ::PROTOBUF_NAMESPACE_ID::uint64 phone_; int subcommand_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; friend struct ::TableStruct_mp_2ebody_2eproto; @@ -657,107 +619,6 @@ inline void body::unsafe_arena_set_allocated_data( // @@protoc_insertion_point(field_unsafe_arena_set_allocated:mp.body.data) } -// string email = 7; -inline void body::clear_email() { - email_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& body::email() const { - // @@protoc_insertion_point(field_get:mp.body.email) - return _internal_email(); -} -inline void body::set_email(const std::string& value) { - _internal_set_email(value); - // @@protoc_insertion_point(field_set:mp.body.email) -} -inline std::string* body::mutable_email() { - // @@protoc_insertion_point(field_mutable:mp.body.email) - return _internal_mutable_email(); -} -inline const std::string& body::_internal_email() const { - return email_.Get(); -} -inline void body::_internal_set_email(const std::string& value) { - - email_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void body::set_email(std::string&& value) { - - email_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:mp.body.email) -} -inline void body::set_email(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - email_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:mp.body.email) -} -inline void body::set_email(const char* value, - size_t size) { - - email_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:mp.body.email) -} -inline std::string* body::_internal_mutable_email() { - - return email_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* body::release_email() { - // @@protoc_insertion_point(field_release:mp.body.email) - return email_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void body::set_allocated_email(std::string* email) { - if (email != nullptr) { - - } else { - - } - email_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), email, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:mp.body.email) -} -inline std::string* body::unsafe_arena_release_email() { - // @@protoc_insertion_point(field_unsafe_arena_release:mp.body.email) - GOOGLE_DCHECK(GetArena() != nullptr); - - return email_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - GetArena()); -} -inline void body::unsafe_arena_set_allocated_email( - std::string* email) { - GOOGLE_DCHECK(GetArena() != nullptr); - if (email != nullptr) { - - } else { - - } - email_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - email, GetArena()); - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:mp.body.email) -} - -// uint64 phone = 8; -inline void body::clear_phone() { - phone_ = PROTOBUF_ULONGLONG(0); -} -inline ::PROTOBUF_NAMESPACE_ID::uint64 body::_internal_phone() const { - return phone_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint64 body::phone() const { - // @@protoc_insertion_point(field_get:mp.body.phone) - return _internal_phone(); -} -inline void body::_internal_set_phone(::PROTOBUF_NAMESPACE_ID::uint64 value) { - - phone_ = value; -} -inline void body::set_phone(::PROTOBUF_NAMESPACE_ID::uint64 value) { - _internal_set_phone(value); - // @@protoc_insertion_point(field_set:mp.body.phone) -} - #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ diff --git a/include/mp/proto/mp.request.pb.h b/include/mp/proto/mp.request.pb.h index 26a51cd..6ac1fc2 100644 --- a/include/mp/proto/mp.request.pb.h +++ b/include/mp/proto/mp.request.pb.h @@ -181,10 +181,10 @@ class request PROTOBUF_FINAL : // accessors ------------------------------------------------------- enum : int { - kBodyFieldNumber = 2, - kCqiFieldNumber = 3, + kBodyFieldNumber = 1, + kCqiFieldNumber = 2, }; - // .mp.body body = 2; + // .mp.body body = 1; bool has_body() const; private: bool _internal_has_body() const; @@ -202,7 +202,7 @@ class request PROTOBUF_FINAL : ::mp::body* body); ::mp::body* unsafe_arena_release_body(); - // .mp.cqi cqi = 3; + // .mp.cqi cqi = 2; bool has_cqi() const; private: bool _internal_has_cqi() const; @@ -243,7 +243,7 @@ class request PROTOBUF_FINAL : #endif // __GNUC__ // request -// .mp.body body = 2; +// .mp.body body = 1; inline bool request::_internal_has_body() const { return this != internal_default_instance() && body_ != nullptr; } @@ -318,7 +318,7 @@ inline void request::set_allocated_body(::mp::body* body) { // @@protoc_insertion_point(field_set_allocated:mp.request.body) } -// .mp.cqi cqi = 3; +// .mp.cqi cqi = 2; inline bool request::_internal_has_cqi() const { return this != internal_default_instance() && cqi_ != nullptr; } diff --git a/include/mp/proto/mp.response.pb.h b/include/mp/proto/mp.response.pb.h index 8d5ed10..1779880 100644 --- a/include/mp/proto/mp.response.pb.h +++ b/include/mp/proto/mp.response.pb.h @@ -180,9 +180,9 @@ class response PROTOBUF_FINAL : // accessors ------------------------------------------------------- enum : int { - kSriFieldNumber = 3, + kSriFieldNumber = 1, }; - // .mp.sri sri = 3; + // .mp.sri sri = 1; bool has_sri() const; private: bool _internal_has_sri() const; @@ -222,7 +222,7 @@ class response PROTOBUF_FINAL : #endif // __GNUC__ // response -// .mp.sri sri = 3; +// .mp.sri sri = 1; inline bool response::_internal_has_sri() const { return this != internal_default_instance() && sri_ != nullptr; } diff --git a/include/mp/protohuf/mp.body.proto b/include/mp/protohuf/mp.body.proto index 77b48d5..6d7c103 100644 --- a/include/mp/protohuf/mp.body.proto +++ b/include/mp/protohuf/mp.body.proto @@ -10,6 +10,4 @@ message body { uint64 target = 4; uint64 source = 5; string data = 6; - string email = 7; - uint64 phone = 8; } \ No newline at end of file diff --git a/include/mp/protohuf/mp.request.proto b/include/mp/protohuf/mp.request.proto index ee79d62..83bcb8a 100644 --- a/include/mp/protohuf/mp.request.proto +++ b/include/mp/protohuf/mp.request.proto @@ -5,6 +5,6 @@ import "mp.body.proto"; import "mp.cqi.proto"; message request { - body body = 2; - cqi cqi = 3; + body body = 1; + cqi cqi = 2; } \ No newline at end of file diff --git a/include/mp/protohuf/mp.response.proto b/include/mp/protohuf/mp.response.proto index 0f660c4..8eb4763 100644 --- a/include/mp/protohuf/mp.response.proto +++ b/include/mp/protohuf/mp.response.proto @@ -4,5 +4,5 @@ package mp; import "mp.sri.proto"; message response { - sri sri = 3; + sri sri = 1; } \ No newline at end of file