├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── base ├── base_zrpc_service.cc ├── base_zrpc_service.h └── message_handler_util.h ├── cmake ├── FindDoubleConversion.cmake ├── FindFolly.cmake ├── FindGFlags.cmake ├── FindGlog.cmake ├── FindMySQL.cmake ├── FindProxygen.cmake ├── FindWangle.cmake └── NebulaCompilerOptions.cmake ├── frontend ├── CMakeLists.txt ├── auth_client_handler.cc ├── auth_client_handler.h ├── client_base_handler.cc ├── client_base_handler.h ├── frontend_server.cc ├── frontend_server.h ├── frontend_server_handler.cc ├── frontend_server_handler.h ├── handshake_handler.cc ├── handshake_handler.h ├── messenger_client_handler.cc └── messenger_client_handler.h ├── nebula ├── CMakeLists.txt ├── README.md ├── base │ ├── CMakeLists.txt │ ├── README.md │ ├── base_daemon.cc │ ├── base_daemon.h │ ├── basictypes.h │ ├── config │ │ ├── IOBufUtil.cpp │ │ ├── IOBufUtil.h │ │ ├── README.md │ │ ├── config_preprocessor.cc │ │ ├── config_preprocessor.h │ │ ├── file_data_provider.cc │ │ ├── file_data_provider.h │ │ ├── file_observer.cc │ │ ├── file_observer.h │ │ ├── import_resolver_if.h │ │ ├── rendezvous_hash.cc │ │ └── rendezvous_hash.h │ ├── config_manager.cc │ ├── config_manager.h │ ├── configurable.h │ ├── crypto_util │ │ ├── auth_key_manager.cc │ │ ├── auth_key_manager.h │ │ ├── base64.cc │ │ ├── base64.h │ │ ├── base64_unittest.cc │ │ ├── big_number.cc │ │ ├── big_number.h │ │ ├── crypto_util.cc │ │ ├── crypto_util.h │ │ ├── dh_util.cc │ │ ├── dh_util.h │ │ ├── md5.cc │ │ ├── md5.h │ │ ├── md5_unittest.cc │ │ ├── modp_b64 │ │ │ ├── BUILD.gn │ │ │ ├── DEPS │ │ │ ├── LICENSE │ │ │ ├── OWNERS │ │ │ ├── README.chromium │ │ │ ├── modp_b64.cc │ │ │ ├── modp_b64.h │ │ │ └── modp_b64_data.h │ │ ├── sha1.cc │ │ ├── sha1.h │ │ └── sha1_unittest.cc │ ├── dyn_lib.cc │ ├── dyn_lib.h │ ├── dyn_lib_manager.cc │ ├── dyn_lib_manager.h │ ├── exception.h │ ├── fiber_context_manager.cc │ ├── fiber_context_manager.h │ ├── func_factory_manager.h │ ├── id_util.cc │ ├── id_util.h │ ├── initializer.cc │ ├── initializer.h │ ├── io_buf_util.cc │ ├── io_buf_util.h │ ├── iterator.h │ ├── json │ │ ├── README.txt │ │ ├── dynamic_converter.h │ │ ├── json.cc │ │ └── json.h │ ├── linked_hash_map.h │ ├── linked_list.h │ ├── linked_list_unittest.cc │ ├── linked_map.h │ ├── logger │ │ ├── glog_util.cc │ │ └── glog_util.h │ ├── lru_cache.h │ ├── map_util.h │ ├── mru_cache.h │ ├── mru_cache_unittest.cc │ ├── plugin.h │ ├── readline_gets.cc │ ├── readline_gets.h │ ├── reflection_util.h │ ├── self_register_factory_manager.h │ ├── snowflake4cxx │ │ ├── id.cc │ │ ├── id.h │ │ └── id_test.cc │ ├── stl_util.h │ ├── string_builder.h │ ├── string_builder_test.cc │ ├── test │ │ ├── CMakeLists.txt │ │ ├── base_test.cc │ │ ├── factory_test.cc │ │ ├── fibers_test.cc │ │ ├── futures_test.cc │ │ └── json_test.cc │ ├── testing │ │ ├── testing_util.cc │ │ └── testing_util.h │ ├── time_syncor.h │ ├── time_util.cc │ ├── time_util.h │ ├── timer_manager.h │ ├── traits.h │ ├── zlib_util.cc │ └── zlib_util.h ├── mysql_client │ ├── CMakeLists.txt │ ├── dump.rdb │ ├── mysql_client.cc │ ├── mysql_client.h │ ├── mysql_client_util.cc │ ├── mysql_client_util.h │ ├── mysql_conn.cc │ ├── mysql_conn.h │ ├── mysql_conn_pool.cc │ ├── mysql_conn_pool.h │ ├── mysql_query_util.cc │ ├── mysql_query_util.h │ ├── mysql_result_set.cc │ ├── mysql_result_set.h │ └── test │ │ ├── CMakeLists.txt │ │ └── mysql_client_test.cc ├── net │ ├── CMakeLists.txt │ ├── README.md │ ├── base │ │ ├── client_bootstrap2.h │ │ ├── ip_addr_info.cc │ │ ├── ip_addr_info.h │ │ ├── nebula_pipeline.cc │ │ ├── nebula_pipeline.h │ │ ├── service_base.h │ │ ├── service_config.cc │ │ ├── service_config.h │ │ ├── service_plugin.h │ │ └── tcp_conn_event_callback.h │ ├── base_server.cc │ ├── base_server.h │ ├── benchmark │ │ ├── CMakeLists.txt │ │ ├── bench_asio.cc │ │ ├── bench_asio.h │ │ ├── benchmark.cc │ │ ├── multiple_thread.sh │ │ └── single_thread.sh │ ├── engine │ │ ├── http_server.cc │ │ ├── http_server.h │ │ ├── rpc_client.h │ │ ├── rpc_server.h │ │ ├── tcp_client.h │ │ ├── tcp_client_group.cc │ │ ├── tcp_client_group.h │ │ ├── tcp_client_pool.h │ │ ├── tcp_server.h │ │ ├── tcp_service_base.cc │ │ ├── tcp_service_base.h │ │ └── udp_server.h │ ├── handler │ │ ├── README.md │ │ ├── echo │ │ │ ├── echo_handler.cc │ │ │ ├── echo_handler.h │ │ │ ├── udp_echo_handler.cc │ │ │ └── udp_echo_handler.h │ │ ├── http │ │ │ ├── http_request_handler.cc │ │ │ └── http_request_handler.h │ │ ├── module_install.cc │ │ ├── module_install.h │ │ ├── mtproto │ │ │ ├── mtproto_handler.cc │ │ │ ├── mtproto_handler.h │ │ │ ├── mtproto_pipeline_factory.cc │ │ │ ├── mtproto_pipeline_factory.h │ │ │ ├── mtproto_transport_handler.cc │ │ │ └── mtproto_transport_handler.h │ │ ├── nebula_base_handler.cc │ │ ├── nebula_base_handler.h │ │ ├── nebula_event_callback.h │ │ ├── nebula_handler_util.cc │ │ ├── nebula_handler_util.h │ │ ├── pingpong │ │ │ ├── pingpong_handler.cc │ │ │ └── pingpong_handler.h │ │ ├── telegram │ │ │ ├── mtproto_codec.cc │ │ │ ├── mtproto_codec.h │ │ │ ├── mtproto_message_handler.cc │ │ │ ├── mtproto_message_handler.h │ │ │ ├── mtproto_object_handler.cc │ │ │ ├── mtproto_object_handler.h │ │ │ ├── mtproto_transport_handler.cc │ │ │ ├── mtproto_transport_handler.h │ │ │ ├── tcp_transport_codec.cc │ │ │ ├── tcp_transport_codec.h │ │ │ ├── telegram_handler.cc │ │ │ ├── telegram_handler.h │ │ │ ├── telegram_handshake_handler.cc │ │ │ ├── telegram_handshake_handler.h │ │ │ ├── telegram_pipeline_factory.cc │ │ │ ├── telegram_pipeline_factory.h │ │ │ ├── telegram_rpc_handler.cc │ │ │ ├── telegram_rpc_handler.h │ │ │ └── tl_object_handler.h │ │ └── zproto │ │ │ ├── README.md │ │ │ ├── authorization_manager.cc │ │ │ ├── authorization_manager.h │ │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ ├── api_message_box.h │ │ │ ├── build.sh │ │ │ ├── zproto_test.cc │ │ │ ├── zrpc_client_test.cc │ │ │ ├── zrpc_server_test.cc │ │ │ ├── zrpc_test.pb.cc │ │ │ ├── zrpc_test.pb.h │ │ │ ├── zrpc_test.proto │ │ │ ├── zrpc_test_dispatcher.cc │ │ │ ├── zrpc_test_dispatcher.h │ │ │ ├── zrpc_test_service.cc │ │ │ ├── zrpc_test_service.h │ │ │ ├── zrpc_test_service_impl.cc │ │ │ └── zrpc_test_service_impl.h │ │ │ ├── zproto_frame_handler.cc │ │ │ ├── zproto_frame_handler.h │ │ │ ├── zproto_handler.cc │ │ │ ├── zproto_handler.h │ │ │ ├── zproto_package_handler.cc │ │ │ ├── zproto_package_handler.h │ │ │ ├── zproto_pipeline_factory.cc │ │ │ └── zproto_pipeline_factory.h │ ├── http │ │ ├── http_client_lib.cc │ │ ├── http_client_lib.h │ │ ├── http_server_lib.cc │ │ ├── http_server_lib.h │ │ ├── http_server_lib_acceptor.cc │ │ └── http_server_lib_acceptor.h │ ├── net_engine_manager.cc │ ├── net_engine_manager.h │ ├── rpc │ │ ├── README.md │ │ ├── zrpc_client_dispatcher.cc │ │ ├── zrpc_client_dispatcher.h │ │ ├── zrpc_client_handler.cc │ │ ├── zrpc_client_handler.h │ │ ├── zrpc_module.cc │ │ ├── zrpc_pipeline_factory.cc │ │ ├── zrpc_pipeline_factory.h │ │ ├── zrpc_server_handler.cc │ │ ├── zrpc_server_handler.h │ │ ├── zrpc_service.cc │ │ ├── zrpc_service.h │ │ ├── zrpc_service_util.cc │ │ └── zrpc_service_util.h │ ├── test │ │ ├── CMakeLists.txt │ │ ├── async_udp_socket_test.cc │ │ ├── http_client_test.cc │ │ ├── net_engine_client_test.cc │ │ ├── net_engine_server_test.cc │ │ ├── pingpong_server_test.cc │ │ ├── pingpong_server_test.json │ │ ├── telegram_handshake_test.cc │ │ ├── telegram_server_test.cc │ │ ├── test_service.json │ │ ├── thread_util_test.cc │ │ ├── udp_echo_client_test.py │ │ ├── udp_echo_server_test.cc │ │ ├── udp_echo_server_test.json │ │ ├── udp_server_test.py │ │ └── udp_test.cc │ ├── thread_group_list_manager.cc │ ├── thread_group_list_manager.h │ ├── thread_local_conn_manager.cc │ ├── thread_local_conn_manager.h │ └── zproto │ │ ├── api_message_box.h │ │ ├── zproto_api_message_box.h │ │ ├── zproto_frame_data.cc │ │ ├── zproto_frame_data.h │ │ ├── zproto_package_data.cc │ │ └── zproto_package_data.h ├── redis_client │ ├── CMakeLists.txt │ ├── redis.json │ ├── redis_client.cc │ ├── redis_client.h │ ├── redis_conn.cc │ ├── redis_conn.h │ ├── redis_conn_pool.cc │ └── redis_conn_pool.h ├── scriptengine │ ├── CMakeLists.txt │ ├── README.md │ ├── lua-5.2.3 │ │ ├── Makefile │ │ ├── README │ │ ├── doc │ │ │ ├── contents.html │ │ │ ├── logo.gif │ │ │ ├── lua.1 │ │ │ ├── lua.css │ │ │ ├── luac.1 │ │ │ ├── manual.css │ │ │ ├── manual.html │ │ │ ├── osi-certified-72x60.png │ │ │ └── readme.html │ │ └── src │ │ │ ├── Makefile │ │ │ ├── lapi.c │ │ │ ├── lapi.h │ │ │ ├── lauxlib.c │ │ │ ├── lauxlib.h │ │ │ ├── lbaselib.c │ │ │ ├── lbitlib.c │ │ │ ├── lcode.c │ │ │ ├── lcode.h │ │ │ ├── lcorolib.c │ │ │ ├── lctype.c │ │ │ ├── lctype.h │ │ │ ├── ldblib.c │ │ │ ├── ldebug.c │ │ │ ├── ldebug.h │ │ │ ├── ldo.c │ │ │ ├── ldo.h │ │ │ ├── ldump.c │ │ │ ├── lfunc.c │ │ │ ├── lfunc.h │ │ │ ├── lgc.c │ │ │ ├── lgc.h │ │ │ ├── linit.c │ │ │ ├── liolib.c │ │ │ ├── llex.c │ │ │ ├── llex.h │ │ │ ├── llimits.h │ │ │ ├── lmathlib.c │ │ │ ├── lmem.c │ │ │ ├── lmem.h │ │ │ ├── loadlib.c │ │ │ ├── lobject.c │ │ │ ├── lobject.h │ │ │ ├── lopcodes.c │ │ │ ├── lopcodes.h │ │ │ ├── loslib.c │ │ │ ├── lparser.c │ │ │ ├── lparser.h │ │ │ ├── lstate.c │ │ │ ├── lstate.h │ │ │ ├── lstring.c │ │ │ ├── lstring.h │ │ │ ├── lstrlib.c │ │ │ ├── ltable.c │ │ │ ├── ltable.h │ │ │ ├── ltablib.c │ │ │ ├── ltm.c │ │ │ ├── ltm.h │ │ │ ├── lua.c │ │ │ ├── lua.h │ │ │ ├── lua.hpp │ │ │ ├── luac.c │ │ │ ├── luaconf.h │ │ │ ├── lualib.h │ │ │ ├── lundump.c │ │ │ ├── lundump.h │ │ │ ├── lvm.c │ │ │ ├── lvm.h │ │ │ ├── lzio.c │ │ │ └── lzio.h │ ├── lua_include.hpp │ ├── lua_util.cc │ ├── lua_util.h │ ├── luabind_register_func.h │ ├── luabind_register_manager.h │ ├── luatinker │ │ ├── lua_tinker.cpp │ │ ├── lua_tinker.h │ │ ├── sample1.cpp │ │ ├── sample1.lua │ │ ├── sample2.cpp │ │ ├── sample2.lua │ │ ├── sample3.cpp │ │ ├── sample3.lua │ │ ├── sample4.cpp │ │ ├── sample4.lua │ │ ├── sample5.cpp │ │ ├── sample5.lua │ │ ├── sample6.cpp │ │ └── sample6.lua │ ├── script_engine.cc │ ├── script_engine.h │ └── scriptengine_test │ │ ├── CMakeLists.txt │ │ └── scriptegine_test.cc └── zorm │ ├── CMakeLists.txt │ ├── zorm_template.cc │ └── zorm_template.h ├── proto ├── CMakeLists.txt ├── api │ ├── cc │ │ ├── api_method_ids.pb.cc │ │ ├── api_method_ids.pb.h │ │ ├── auth.pb.cc │ │ ├── auth.pb.h │ │ ├── configs.pb.cc │ │ ├── configs.pb.h │ │ ├── counters.pb.cc │ │ ├── counters.pb.h │ │ ├── device.pb.cc │ │ ├── device.pb.h │ │ ├── dialogs.pb.cc │ │ ├── dialogs.pb.h │ │ ├── files.pb.cc │ │ ├── files.pb.h │ │ ├── group_base.pb.cc │ │ ├── group_base.pb.h │ │ ├── groups.pb.cc │ │ ├── groups.pb.h │ │ ├── invites.pb.cc │ │ ├── invites.pb.h │ │ ├── messaging.pb.cc │ │ ├── messaging.pb.h │ │ ├── messaging_base.pb.cc │ │ ├── messaging_base.pb.h │ │ ├── misc.pb.cc │ │ ├── misc.pb.h │ │ ├── peers.pb.cc │ │ ├── peers.pb.h │ │ ├── privacy.pb.cc │ │ ├── privacy.pb.h │ │ ├── sequence.pb.cc │ │ ├── sequence.pb.h │ │ ├── stats.pb.cc │ │ ├── stats.pb.h │ │ ├── types.pb.cc │ │ ├── types.pb.h │ │ ├── users.pb.cc │ │ ├── users.pb.h │ │ ├── weak.pb.cc │ │ └── weak.pb.h │ ├── error_codes.h │ └── proto │ │ ├── README.md │ │ ├── api_method_ids.proto │ │ ├── auth.proto │ │ ├── build.sh │ │ ├── check_method_types.py │ │ ├── configs.proto │ │ ├── counters.proto │ │ ├── device.proto │ │ ├── dialogs.proto │ │ ├── files.proto │ │ ├── group_base.proto │ │ ├── groups.proto │ │ ├── invites.proto │ │ ├── messaging.proto │ │ ├── messaging_base.proto │ │ ├── misc.proto │ │ ├── peers.proto │ │ ├── privacy.proto │ │ ├── sequence.proto │ │ ├── stats.proto │ │ ├── types.proto │ │ ├── users.proto │ │ └── weak.proto ├── mtproto │ ├── core │ │ ├── auth_key_manager.cc │ │ ├── auth_key_manager.h │ │ ├── mtproto_api_message_box.h │ │ ├── mtproto_api_message_box2.h │ │ ├── mtproto_message.cc │ │ ├── mtproto_message.h │ │ ├── mtproto_message_register.cc │ │ ├── mtproto_schema.cc │ │ ├── mtproto_schema.h │ │ ├── tl_bool.h │ │ ├── tl_codec_util.cc │ │ ├── tl_codec_util.h │ │ ├── tl_error.h │ │ ├── tl_null.h │ │ ├── tl_object.cc │ │ ├── tl_object.h │ │ ├── tl_types.h │ │ ├── tl_vector.cc │ │ └── tl_vector.h │ ├── schema.tl.cc │ ├── schema.tl.cc.20170708 │ ├── schema.tl.h │ ├── schema.tl.h.20170708 │ ├── schema2.tl.cc │ ├── schema2.tl.h │ ├── schema3.tl.cc │ ├── schema3.tl.h │ └── scheme │ │ ├── a │ │ ├── schema.tl.cc │ │ ├── schema.tl.h │ │ ├── service_impl.cc │ │ ├── service_impl.h │ │ ├── zrpc_messenger_dispatcher.cc │ │ ├── zrpc_messenger_dispatcher.h │ │ ├── zrpc_service.cc │ │ └── zrpc_service.h │ │ ├── b │ │ ├── schema.tl.cc │ │ └── schema.tl.h │ │ ├── gen_dispatcher.py │ │ ├── gen_service.py │ │ ├── gen_service_impl.py │ │ ├── generate.py │ │ ├── scheme.tl │ │ ├── scheme.tl.cc │ │ ├── scheme.tl.h │ │ ├── scheme2.tl.cc │ │ ├── scheme2.tl.h │ │ ├── scheme_auto.cpp │ │ └── scheme_funcs.tl ├── s2s │ ├── cc │ │ ├── presences.pb.cc │ │ ├── presences.pb.h │ │ ├── s2s_method_ids.pb.cc │ │ ├── s2s_method_ids.pb.h │ │ ├── servers.pb.cc │ │ └── servers.pb.h │ └── proto │ │ ├── build.sh │ │ ├── presences.proto │ │ └── servers.proto └── zproto │ ├── cc │ ├── auths.pb.cc │ ├── auths.pb.h │ ├── bases.pb.cc │ ├── bases.pb.h │ ├── biz_servers.pb.cc │ ├── biz_servers.pb.h │ ├── files.pb.cc │ ├── files.pb.h │ ├── groups.pb.cc │ ├── groups.pb.h │ ├── messages.pb.cc │ ├── messages.pb.h │ ├── peers.pb.cc │ ├── peers.pb.h │ ├── presences.pb.cc │ ├── presences.pb.h │ ├── servers.pb.cc │ └── servers.pb.h │ ├── go │ ├── auths.pb.go │ ├── bases.pb.go │ ├── biz_servers.pb.go │ ├── files.pb.go │ ├── groups.pb.go │ ├── messages.pb.go │ ├── peers.pb.go │ ├── presences.pb.go │ └── servers.pb.go │ ├── proto │ ├── auths.proto │ ├── bases.proto │ ├── biz_servers.proto │ ├── build.sh │ ├── check_method_types.py │ ├── files.proto │ ├── groups.proto │ ├── messages.proto │ ├── peers.proto │ ├── presences.proto │ └── servers.proto │ └── zproto_api_message_types.h2 ├── relay ├── CMakeLists.txt ├── README.md ├── relay_server.cc ├── relay_server.h ├── tgvoip_handler.cc └── tgvoip_handler.h └── third_party ├── folly ├── proxygen └── wangle /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | .idea 3 | cmake-build-debug 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nebula 2 | 基于folly、wangle和proxygen的c++14基础库 3 | 4 | ## build 5 | ### 6 | 7 | ```cpp 8 | // 进入nebula目录 9 | mkdir out 10 | cd out 11 | cmake .. -DCATCH_INCLUDE_DIR=.. -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /base/base_zrpc_service.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "base/base_zrpc_service.h" 19 | 20 | #include "nebula/base/logger/glog_util.h" 21 | 22 | bool BaseZRpcService::Initialize(zproto::RpcRequestPtr v) { 23 | if (!v->has_attach_data()) { 24 | LOG(FATAL) << "Initialize - attach_data empty!!! " << v->ToString(); 25 | return false; 26 | } 27 | 28 | if (v->attach_data.options.size() == MAX) { 29 | LOG(ERROR) << "Initialize - attach_data empty!!! " << v->ToString(); 30 | return false; 31 | } 32 | 33 | // TODO(@benqi): 检查附加字段 34 | rpc_request_ = v; 35 | 36 | return false; 37 | } 38 | -------------------------------------------------------------------------------- /base/base_zrpc_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef BASE_BASE_ZRPC_ZRPC_SERVICE_H_ 19 | #define BASE_BASE_ZRPC_ZRPC_SERVICE_H_ 20 | 21 | #include "nebula/net/zproto/zproto_package_data.h" 22 | 23 | class BaseZRpcService { 24 | public: 25 | enum AttachDataType { 26 | APPID = 0, 27 | UID, 28 | // TODO(@benqi): 29 | // 设备信息等 30 | MAX, 31 | }; 32 | 33 | virtual ~BaseZRpcService() = default; 34 | 35 | virtual bool Initialize(zproto::RpcRequestPtr v); 36 | 37 | uint64_t session_id() const { 38 | return rpc_request_->session_id(); 39 | } 40 | 41 | const std::string& uid() const { 42 | return *(rpc_request_->attach_data.options[UID].data.s); 43 | } 44 | 45 | uint32_t app_id() const { 46 | return static_cast(rpc_request_->attach_data.options[APPID].data.n); 47 | } 48 | 49 | uint64_t conn_id() const { 50 | return rpc_request_->birth_conn_id(); 51 | } 52 | 53 | protected: 54 | zproto::RpcRequestPtr rpc_request_; 55 | }; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /cmake/FindDoubleConversion.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Finds libdouble-conversion. 3 | # 4 | # This module defines: 5 | # DOUBLE_CONVERSION_INCLUDE_DIR 6 | # DOUBLE_CONVERSION_LIBRARY 7 | # 8 | 9 | find_path( 10 | DOUBLE_CONVERSION_INCLUDE_DIR 11 | NAMES double-conversion.h 12 | HINTS 13 | /usr/include/double-conversion 14 | /usr/local/include/double-conversion 15 | ) 16 | find_library( 17 | DOUBLE_CONVERSION_LIBRARY 18 | NAMES double-conversion 19 | HINTS 20 | /usr/local/double-conversion 21 | ) 22 | 23 | include(FindPackageHandleStandardArgs) 24 | find_package_handle_standard_args( 25 | DOUBLE_CONVERSION DEFAULT_MSG 26 | DOUBLE_CONVERSION_INCLUDE_DIR DOUBLE_CONVERSION_LIBRARY) 27 | 28 | mark_as_advanced( 29 | DOUBLE_CONVERSION_INCLUDE_DIR 30 | DOUBLE_CONVERSION_LIBRARY 31 | DOUBLE_CONVERSION_FOUND 32 | ) 33 | 34 | if(DOUBLE_CONVERSION_FOUND AND NOT DOUBLE_CONVERSION_FIND_QUIETLY) 35 | message(STATUS "DOUBLE_CONVERSION: ${DOUBLE_CONVERSION_INCLUDE_DIR}") 36 | endif() -------------------------------------------------------------------------------- /cmake/FindFolly.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # - Try to find Facebook folly library 3 | # This will define 4 | # FOLLY_FOUND 5 | # FOLLY_INCLUDE_DIR 6 | # FOLLY_LIBRARIES 7 | # 8 | 9 | find_package(DoubleConversion REQUIRED) 10 | 11 | find_path( 12 | FOLLY_INCLUDE_DIR 13 | NAMES "folly/String.h" 14 | HINTS 15 | "/usr/local/facebook/include" 16 | ) 17 | 18 | find_library( 19 | FOLLY_LIBRARY 20 | NAMES folly 21 | HINTS 22 | "/usr/local/facebook/lib" 23 | ) 24 | 25 | set(FOLLY_LIBRARIES ${FOLLY_LIBRARY} ${DOUBLE_CONVERSION_LIBRARY}) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args( 29 | FOLLY DEFAULT_MSG FOLLY_INCLUDE_DIR FOLLY_LIBRARIES) 30 | 31 | mark_as_advanced(FOLLY_INCLUDE_DIR FOLLY_LIBRARIES FOLLY_FOUND) 32 | 33 | if(FOLLY_FOUND AND NOT FOLLY_FIND_QUIETLY) 34 | message(STATUS "FOLLY: ${FOLLY_INCLUDE_DIR}") 35 | endif() 36 | -------------------------------------------------------------------------------- /cmake/FindGFlags.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # - Try to find GFlags 3 | # This will define 4 | # GFLAGS_FOUND 5 | # GFLAGS_INCLUDE_DIR 6 | # GFLAGS_LIBRARIES 7 | # 8 | 9 | find_path(GFLAGS_INCLUDE_DIR "gflags/gflags.h") 10 | find_library(GFLAGS_LIBRARY gflags) 11 | 12 | set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY}) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args( 16 | GFLAGS DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARIES) 17 | 18 | mark_as_advanced(GFLAGS_INCLUDE_DIR GFLAGS_LIBRARIES GFLAGS_FOUND) 19 | 20 | if(GFLAGS_FOUND AND NOT GFLAGS_FIND_QUIETLY) 21 | message(STATUS "GFLAGS: ${GFLAGS_INCLUDE_DIR}") 22 | endif() -------------------------------------------------------------------------------- /cmake/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Find libglog 3 | # 4 | # LIBGLOG_INCLUDE_DIR - where to find glog/logging.h, etc. 5 | # LIBGLOG_LIBRARY - List of libraries when using libglog. 6 | # LIBGLOG_FOUND - True if libglog found. 7 | # 8 | 9 | find_path(LIBGLOG_INCLUDE_DIR glog/logging.h) 10 | find_library(LIBGLOG_LIBRARY glog) 11 | 12 | set(LIBGLOG_LIBRARIES ${LIBGLOG_LIBRARY}) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args( 16 | LIBGLOG DEFAULT_MSG LIBGLOG_INCLUDE_DIR LIBGLOG_LIBRARIES) 17 | 18 | mark_as_advanced(LIBGLOG_INCLUDE_DIR LIBGLOG_LIBRARIES LIBGLOG_FOUND) 19 | 20 | if(LIBGLOG_FOUND AND NOT LIBGLOG_FIND_QUIETLY) 21 | message(STATUS "LIBGLOG: ${LIBGLOG_INCLUDE_DIR}") 22 | endif() -------------------------------------------------------------------------------- /cmake/FindProxygen.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # - Try to find Facebook proxygen library 3 | # This will define 4 | # PROXYFGEN_FOUND 5 | # PROXYGEN_INCLUDE_DIR 6 | # PROXYGEN_LIBRARIES 7 | # 8 | 9 | find_package(Folly REQUIRED) 10 | find_package(Wangle REQUIRED) 11 | 12 | find_path( 13 | PROXYGEN_INCLUDE_DIR 14 | NAMES "proxygen/httpserver/HTTPServer.h" 15 | HINTS 16 | "/usr/local/facebook/include" 17 | ) 18 | 19 | find_library( 20 | PROXYGEN_LIBRARY 21 | NAMES proxygenlib 22 | HINTS 23 | "/usr/local/facebook/lib" 24 | ) 25 | 26 | find_library( 27 | PROXYGEN_HTTP_SERVER 28 | NAMES proxygenhttpserver 29 | HINTS 30 | "/usr/local/facebook/lib" 31 | ) 32 | 33 | set(PROXYGEN_LIBRARIES 34 | ${PROXYGEN_LIBRARY} 35 | ${PROXYGEN_HTTP_SERVER} 36 | ) 37 | 38 | set(PROXYGEN_LIBRARIES ${PROXYGEN_LIBRARIES} ${FOLLY_LIBRARIES} ${WANGLE_LIBRARIES}) 39 | 40 | include(FindPackageHandleStandardArgs) 41 | find_package_handle_standard_args( 42 | PROXYGEN DEFAULT_MSG PROXYGEN_INCLUDE_DIR PROXYGEN_LIBRARIES) 43 | 44 | mark_as_advanced(PROXYGEN_INCLUDE_DIR PROXYGEN_LIBRARIES PROXYGEN_FOUND) 45 | 46 | if(PROXYGEN_FOUND AND NOT PROXYGEN_FIND_QUIETLY) 47 | message(STATUS "PROXYGEN: ${PROXYGEN_INCLUDE_DIR}") 48 | endif() 49 | -------------------------------------------------------------------------------- /cmake/FindWangle.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # - Try to find Facebook wangle library 3 | # This will define 4 | # WANGLE_FOUND 5 | # WANGLE_INCLUDE_DIR 6 | # WANGLE_LIBRARIES 7 | # 8 | 9 | find_package(Folly REQUIRED) 10 | 11 | find_path( 12 | WANGLE_INCLUDE_DIR 13 | NAMES "wangle/channel/Pipeline.h" 14 | HINTS 15 | "/usr/local/facebook/include" 16 | ) 17 | 18 | find_library( 19 | WANGLE_LIBRARY 20 | NAMES wangle 21 | HINTS 22 | "/usr/local/facebook/lib" 23 | ) 24 | 25 | set(WANGLE_LIBRARIES ${WANGLE_LIBRARY} ${FOLLY_LIBRARIES}) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args( 29 | WANGLE DEFAULT_MSG WANGLE_INCLUDE_DIR WANGLE_LIBRARIES) 30 | 31 | mark_as_advanced(WANGLE_INCLUDE_DIR WANGLE_LIBRARIES WANGLE_FOUND) 32 | 33 | if(WANGLE_FOUND AND NOT WANGLE_FIND_QUIETLY) 34 | message(STATUS "WANGLE: ${WANGLE_INCLUDE_DIR}") 35 | endif() 36 | -------------------------------------------------------------------------------- /cmake/NebulaCompilerOptions.cmake: -------------------------------------------------------------------------------- 1 | set(DARWIN FALSE) 2 | set(FREEBSD FALSE) 3 | set(LINUX FALSE) 4 | set(WINDOWS FALSE) 5 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") 6 | set(FREEBSD TRUE) 7 | endif() 8 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 9 | set(LINUX TRUE) 10 | endif() 11 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 12 | set(DARWIN TRUE) 13 | endif() 14 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") 15 | set(WINDOWS TRUE) 16 | endif() 17 | 18 | #if(NOT LINUX) 19 | # message(FATAL_ERROR "Nebula requires linux right now.") 20 | #endif() 21 | 22 | set(CMAKE_CXX_STANDARD 14) 23 | 24 | #add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") 25 | -------------------------------------------------------------------------------- /frontend/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(. ..) 18 | 19 | set (SRC_LIST 20 | frontend_server.cc 21 | frontend_server.h 22 | frontend_server_handler.cc 23 | frontend_server_handler.h 24 | handshake_handler.cc 25 | handshake_handler.h 26 | auth_client_handler.cc 27 | auth_client_handler.h 28 | messenger_client_handler.cc 29 | messenger_client_handler.h 30 | client_base_handler.cc 31 | client_base_handler.h 32 | ) 33 | 34 | add_executable (frontend ${SRC_LIST}) 35 | target_link_libraries (frontend net base proto) 36 | 37 | -------------------------------------------------------------------------------- /frontend/auth_client_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/imengine 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef FRONTEND_AUTH_CLIENT_HANDLER_H_ 19 | #define FRONTEND_AUTH_CLIENT_HANDLER_H_ 20 | 21 | #include 22 | #include "nebula/net/handler/nebula_base_handler.h" 23 | #include "nebula/net/handler/zproto/zproto_handler.h" 24 | 25 | #include "frontend/client_base_handler.h" 26 | 27 | // frontend->messenger是无状态的,转发数据即可 28 | class AuthClientHandler : public ClientBaseHandler { 29 | public: 30 | 31 | AuthClientHandler() = default; 32 | ~AuthClientHandler() = default; 33 | 34 | /////////////////////////////////////////////////////////////////////////////////////// 35 | int OnNewConnection() override; 36 | int OnDataReceived(std::shared_ptr message_data) override; 37 | int OnConnectionClosed() override; 38 | }; 39 | 40 | #endif // FRONTEND_AUTH_CLIENT_HANDLER_H_ 41 | 42 | -------------------------------------------------------------------------------- /frontend/frontend_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef FRONTEND_FRONTEND_SERVER_H_ 19 | #define FRONTEND_FRONTEND_SERVER_H_ 20 | 21 | #include 22 | 23 | #include "nebula/net/base_server.h" 24 | 25 | class FrontendServer : public nebula::BaseServer { 26 | public: 27 | FrontendServer() = default; 28 | ~FrontendServer() override = default; 29 | 30 | protected: 31 | // From BaseServer 32 | bool Initialize() override; 33 | bool Run() override; 34 | }; 35 | 36 | #endif // 37 | -------------------------------------------------------------------------------- /frontend/messenger_client_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/imengine 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef FRONTEND_MESSENGER_CLIENT_HANDLER_H_ 19 | #define FRONTEND_MESSENGER_CLIENT_HANDLER_H_ 20 | 21 | #include 22 | #include "nebula/net/handler/nebula_base_handler.h" 23 | #include "nebula/net/handler/zproto/zproto_handler.h" 24 | 25 | #include "frontend/client_base_handler.h" 26 | 27 | // frontend->messenger是无状态的,转发数据即可 28 | class MessengerClientHandler : public ClientBaseHandler { 29 | public: 30 | 31 | MessengerClientHandler() = default; 32 | ~MessengerClientHandler() = default; 33 | 34 | /////////////////////////////////////////////////////////////////////////////////////// 35 | int OnNewConnection() override; 36 | int OnDataReceived(std::shared_ptr message_data) override; 37 | int OnConnectionClosed() override; 38 | }; 39 | 40 | #endif // FRONTEND_MESSENGER_CLIENT_HANDLER_H_ 41 | 42 | -------------------------------------------------------------------------------- /nebula/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(base) 2 | #add_subdirectory(storage) 3 | add_subdirectory(net) 4 | #add_subdirectory(mysql_client) 5 | #add_subdirectory(redis_client) 6 | #add_subdirectory(zorm) 7 | #add_subdirectory(scriptengine) 8 | -------------------------------------------------------------------------------- /nebula/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/README.md -------------------------------------------------------------------------------- /nebula/base/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/base/README.md -------------------------------------------------------------------------------- /nebula/base/config/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/base/config/README.md -------------------------------------------------------------------------------- /nebula/base/config/file_data_provider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | #ifndef NEBULA_BASE_CONFIG_FILE_DATA_PROVIDER_H_ 12 | #define NEBULA_BASE_CONFIG_FILE_DATA_PROVIDER_H_ 13 | 14 | #pragma once 15 | 16 | #include 17 | 18 | #include 19 | 20 | // namespace facebook { namespace memcache { namespace mcrouter { 21 | /** 22 | * DataProvider that works with file: loads data from file and checks 23 | * if the file has changed. 24 | */ 25 | class FileDataProvider { 26 | public: 27 | /** 28 | * Registers inotify watch to check for file changes 29 | * 30 | * @param filePath path to file or link 31 | * @throw runtime_error if watch can not be created 32 | */ 33 | explicit FileDataProvider(std::string filePath); 34 | 35 | /** 36 | * @return contents of file 37 | * @throw runtime_error if file can not be opened 38 | */ 39 | std::string load() const; 40 | 41 | /** 42 | * Polls inotify watch to check if file has changed. Also recreates the 43 | * inotify watch in case file link changed/file was deleted and created again. 44 | * 45 | * @return true if file has changed since last hasUpdate call, false otherwise 46 | * @throw runtime_error if inotify watch can not be checked or recreated 47 | */ 48 | bool hasUpdate(); 49 | private: 50 | const std::string filePath_; 51 | folly::File inotify_; 52 | 53 | /** 54 | * Updates the inotify watch. 55 | * Provides strong guarantee: if exception is thrown, state won't change. 56 | */ 57 | void updateInotifyWatch(); 58 | }; 59 | 60 | // }}} // facebook::memcache::mcrouter 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /nebula/base/config/file_observer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | #ifndef NEBULA_BASE_CONFIG_FILE_OBSERVER_H_ 12 | #define NEBULA_BASE_CONFIG_FILE_OBSERVER_H_ 13 | 14 | #pragma once 15 | 16 | #include 17 | #include 18 | 19 | namespace folly { 20 | class EventBase; 21 | } // folly 22 | 23 | // namespace facebook { namespace memcache { namespace mcrouter { 24 | 25 | /** 26 | * Starts a periodic thread that watches the given file path for changes. 27 | * 28 | * @param filePath path to the file to watch (can be a symlink) 29 | * @param pollPeriodMs how much to wait between asking inotify if 30 | * any updates happened 31 | * @param sleepAfterUpdateMs how much to wait before calling onUpdate 32 | * once an inotify event happens (as a crude protection against 33 | * partial writes race condition). 34 | * @param onUpdate callback function to call when there is a update seen 35 | * @param fallbackOnError function to call if inotify calls fails 36 | */ 37 | bool startObservingFile(const std::string& filePath, 38 | folly::EventBase& evb, 39 | uint32_t pollPeriodMs, 40 | uint32_t sleepBeforeUpdateMs, 41 | std::function onUpdate, 42 | std::function fallbackOnError = nullptr); 43 | 44 | // }}} // facebook::memcache::mcrouter 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /nebula/base/config/import_resolver_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | #ifndef NEBULA_BASE_CONFIG_IMPORT_RESOLVER_IF_H_ 12 | #define NEBULA_BASE_CONFIG_IMPORT_RESOLVER_IF_H_ 13 | 14 | #pragma once 15 | 16 | #include 17 | 18 | #include 19 | 20 | // namespace facebook { namespace memcache { 21 | 22 | /** 23 | * Used by ConfigPreprocessor. Implementation should load additional files 24 | * by path passed to @import macro. 25 | */ 26 | class ImportResolverIf { 27 | public: 28 | /** 29 | * @param path parameter passed to @import macro 30 | * 31 | * @return JSON with macros 32 | */ 33 | virtual std::string import(folly::StringPiece path) = 0; 34 | 35 | virtual ~ImportResolverIf() {} 36 | }; 37 | 38 | // }} // facebook::memcache 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /nebula/base/config/rendezvous_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | #ifndef NEBULA_BASE_CONFIG_RENDEZVOUS_HASH_H_ 12 | #define NEBULA_BASE_CONFIG_RENDEZVOUS_HASH_H_ 13 | 14 | #pragma once 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | // namespace facebook { namespace memcache { 23 | 24 | class RendezvousHash { 25 | public: 26 | /** 27 | * @param Iterator input iterator that iterates over pairs 28 | * { , double } 29 | * @throws invalid_argument if weight is less than zero or 30 | * sum of all weights is zero. 31 | */ 32 | template 33 | RendezvousHash(Iterator begin, Iterator end) { 34 | for (auto it = begin; it != end; ++it) { 35 | if (it->second < 0.0) { 36 | throw std::invalid_argument("Weight should be greater than 0"); 37 | } 38 | nodes_.emplace_back(computeHash(it->first), it->second); 39 | } 40 | normalizeWeights(); 41 | } 42 | 43 | /** 44 | * Get node id for given key. 45 | * @return 0 <= id < number of nodes. If nodes are empty, returns 0. 46 | */ 47 | size_t get(uint64_t key) const; 48 | 49 | private: 50 | uint64_t computeHash(folly::StringPiece data) const; 51 | 52 | uint64_t computeHash(uint64_t i) const; 53 | 54 | // { node hash, node weight } 55 | std::vector> nodes_; 56 | 57 | /** 58 | * @throws invalid_argument if sum of weights is too small (< eps) 59 | */ 60 | void normalizeWeights(); 61 | }; 62 | 63 | // }} // facebook::memcache 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /nebula/base/configurable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_CONFIGURABLE_H_ 19 | #define NEBULA_BASE_CONFIGURABLE_H_ 20 | 21 | #include 22 | 23 | namespace nebula { 24 | 25 | // 动态配置框架 26 | struct Configurable { 27 | public: 28 | virtual ~Configurable() = default; 29 | 30 | virtual bool SetConf(const folly::dynamic& conf) { return true; } 31 | virtual bool SetConf(const std::string& conf_name, const folly::dynamic& conf) { return true; } 32 | 33 | static folly::dynamic GetConfigValue(const folly::dynamic& conf, const std::string& k) { 34 | folly::dynamic rv = nullptr; 35 | 36 | // confs为一数组对象 37 | if (conf.isArray()) { 38 | for (auto& v2 : conf) { 39 | // confs 40 | if (!v2.isObject()) continue; 41 | if (0 == v2.count(k)) continue; 42 | rv = v2[k]; 43 | break; 44 | } 45 | } else { 46 | auto tmp = conf.get_ptr(k); 47 | if (tmp) { 48 | rv = *tmp; 49 | } 50 | } 51 | 52 | return rv; 53 | } 54 | 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/auth_key_manager.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/base/crypto_util/auth_key_manager.cc -------------------------------------------------------------------------------- /nebula/base/crypto_util/auth_key_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_CRYPTO_UTIL_AUTH_KEY_MANAGER_H_ 19 | #define NEBULA_BASE_CRYPTO_UTIL_AUTH_KEY_MANAGER_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "" 25 | class AuthKeyManager { 26 | public: 27 | ~AuthKeyManager() = default; 28 | 29 | static AuthKeyManager* GetInstance(); 30 | 31 | const std::shared_ptr FindAuthKey(int64_t auth_key_id) const; 32 | void SetAuthKey(const std::shared_ptr auth_key, int64_t auth_key_id); 33 | 34 | protected: 35 | AuthKeyManager(); 36 | friend class folly::Singleton; 37 | 38 | std::map> auth_key_manager_; 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/base64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | /* 6 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 7 | * All rights reserved. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef NEBULA_BASE_BASE64_H_ 23 | #define NEBULA_BASE_BASE64_H_ 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace nebula { 30 | 31 | // Encodes the input string in base64. The encoding can be done in-place. 32 | void Base64Encode(const folly::StringPiece& input, std::string* output); 33 | 34 | // Decodes the base64 input string. Returns true if successful and false 35 | // otherwise. The output string is only modified if successful. The decoding can 36 | // be done in-place. 37 | bool Base64Decode(const folly::StringPiece& input, std::string* output); 38 | 39 | } // namespace nebula 40 | 41 | #endif // NEBULA_BASE_BASE64_H_ 42 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/base64_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "base/base64.h" 6 | 7 | #include "testing/gtest/include/gtest/gtest.h" 8 | 9 | namespace base { 10 | 11 | TEST(Base64Test, Basic) { 12 | const std::string kText = "hello world"; 13 | const std::string kBase64Text = "aGVsbG8gd29ybGQ="; 14 | 15 | std::string encoded; 16 | std::string decoded; 17 | bool ok; 18 | 19 | Base64Encode(kText, &encoded); 20 | EXPECT_EQ(kBase64Text, encoded); 21 | 22 | ok = Base64Decode(encoded, &decoded); 23 | EXPECT_TRUE(ok); 24 | EXPECT_EQ(kText, decoded); 25 | } 26 | 27 | TEST(Base64Test, InPlace) { 28 | const std::string kText = "hello world"; 29 | const std::string kBase64Text = "aGVsbG8gd29ybGQ="; 30 | std::string text(kText); 31 | 32 | Base64Encode(text, &text); 33 | EXPECT_EQ(kBase64Text, text); 34 | 35 | bool ok = Base64Decode(text, &text); 36 | EXPECT_TRUE(ok); 37 | EXPECT_EQ(text, kText); 38 | } 39 | 40 | } // namespace base 41 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/modp_b64/BUILD.gn: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 | # Use of this source code is governed by a BSD-style license that can be 3 | # found in the LICENSE file. 4 | 5 | static_library("modp_b64") { 6 | sources = [ 7 | "modp_b64.cc", 8 | "modp_b64.h", 9 | "modp_b64_data.h", 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/modp_b64/DEPS: -------------------------------------------------------------------------------- 1 | include_rules = [ 2 | '+build', 3 | ] -------------------------------------------------------------------------------- /nebula/base/crypto_util/modp_b64/LICENSE: -------------------------------------------------------------------------------- 1 | * MODP_B64 - High performance base64 encoder/decoder 2 | * Version 1.3 -- 17-Mar-2006 3 | * http://modp.com/release/base64 4 | * 5 | * Copyright (c) 2005, 2006 Nick Galbreath -- nickg [at] modp [dot] com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are 10 | * met: 11 | * 12 | * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * Neither the name of the modp.com nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/modp_b64/OWNERS: -------------------------------------------------------------------------------- 1 | jschuh@chromium.org 2 | rsleevi@chromium.org 3 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/modp_b64/README.chromium: -------------------------------------------------------------------------------- 1 | Name: modp base64 decoder 2 | Short Name: stringencoders 3 | URL: https://github.com/client9/stringencoders 4 | Version: unknown 5 | License: BSD 6 | Security Critical: yes 7 | 8 | Description: 9 | The modp_b64.c file was modified to remove the inclusion of modp's config.h 10 | and to fix compilation errors that occur under VC8. The file was renamed 11 | modp_b64.cc to force it to be compiled as C++ so that the inclusion of 12 | basictypes.h could be possible. 13 | 14 | The modp_b64.cc and modp_b64.h files were modified to make them safe on 15 | 64-bit systems. 16 | The modp_b64.cc was modified to avoid misaligned read/write on 17 | little-endian hardware. 18 | -------------------------------------------------------------------------------- /nebula/base/crypto_util/sha1.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef BASE_SHA1_H_ 6 | #define BASE_SHA1_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | // #include "base/base_export.h" 13 | 14 | namespace nebula { 15 | 16 | // These functions perform SHA-1 operations. 17 | 18 | static const size_t kSHA1Length = 20; // Length in bytes of a SHA-1 hash. 19 | 20 | // Computes the SHA-1 hash of the input string |str| and returns the full 21 | // hash. 22 | std::string SHA1HashString(const std::string& str); 23 | 24 | // Computes the SHA-1 hash of the |len| bytes in |data| and puts the hash 25 | // in |hash|. |hash| must be kSHA1Length bytes long. 26 | void SHA1HashBytes(const unsigned char* data, size_t len, 27 | unsigned char* hash); 28 | 29 | } // namespace base 30 | 31 | #endif // BASE_SHA1_H_ 32 | -------------------------------------------------------------------------------- /nebula/base/fiber_context_manager.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/fiber_context_manager.h" 19 | -------------------------------------------------------------------------------- /nebula/base/fiber_context_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_FIBER_CONTEXT_MANAGER_H_ 19 | #define NEBULA_BASE_FIBER_CONTEXT_MANAGER_H_ 20 | 21 | class FiberContextManager { 22 | public: 23 | ~FiberContextManager() {} 24 | 25 | 26 | private: 27 | 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /nebula/base/id_util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/snowflake4cxx/id.h" 19 | 20 | 21 | namespace { 22 | 23 | uint16_t g_worker_id = 1; 24 | uint16_t g_data_center_id = 1; 25 | 26 | } 27 | 28 | void InitSnowflakeWorkerID(uint16_t worker_id, uint16_t data_center_id) { 29 | g_worker_id = worker_id; 30 | g_data_center_id = data_center_id; 31 | } 32 | 33 | 34 | uint64_t GetNextIDBySnowflake() { 35 | static snowflake4cxx::IdWorkerThreadSafe g_id_worker(g_worker_id, g_data_center_id); 36 | return g_id_worker.GetNextID(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /nebula/base/id_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_ID_UTIL_H_ 19 | #define NEBULA_BASE_ID_UTIL_H_ 20 | 21 | #include 22 | 23 | void InitSnowflakeWorkerID(uint16_t worker_id, uint16_t data_center_id=1); 24 | 25 | uint64_t GetNextIDBySnowflake(); 26 | 27 | // 非线程安全 28 | // uint64_t GetNextIDBySnowflakeUnSafe(); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /nebula/base/initializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_INITIALIZER_H_ 19 | #define NEBULA_BASE_INITIALIZER_H_ 20 | 21 | namespace nebula { 22 | 23 | void Initializer(int* argc, char*** argv, bool remove_flags = true); 24 | 25 | } 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /nebula/base/iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_ITERATOR_H_ 19 | #define NEBULA_BASE_ITERATOR_H_ 20 | 21 | namespace nebula { 22 | 23 | template 24 | class Iterator { 25 | public: 26 | typedef ElemT element_type; 27 | 28 | Iterator() = default; 29 | virtual ~Iterator(void) = default; 30 | 31 | virtual void Reset() = 0; 32 | virtual bool HasNext() const = 0; 33 | virtual ElemT Next() = 0; 34 | virtual size_t Size() const= 0; 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /nebula/base/json/README.txt: -------------------------------------------------------------------------------- 1 | ## json序列化/反序列化库 2 | > 参考Kapok实现 3 | 4 | ### Kapok: 5 | - 更好的序列化库,纯c++14开发,header-only,简洁高效。 6 | - Kapok---一个更好的序列化/反序列化库 7 | - 可以很方便的将对象序列化和反序列化,序列化后的格式是标准的json格式。 8 | - wiki介绍:https://github.com/qicosmos/Kapok/wiki 社区:http://purecpp.org/ 9 | - https://github.com/qicosmos/Kapok 10 | 11 | ### nebula的实现 12 | nebula是基于folly的,而folly已经自带了json库,基于dynamic实现,而Kapok是基于rapidjson的,nebula的实现里,移除了rapidjson的相关代码,使用dynamic。 13 | 14 | ### 感谢qicosmos,感谢Kapok 15 | 16 | 17 | -------------------------------------------------------------------------------- /nebula/base/json/json.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/json/json.h" 19 | 20 | -------------------------------------------------------------------------------- /nebula/base/json/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_JSON_JSON_H_ 19 | #define NEBULA_BASE_JSON_JSON_H_ 20 | 21 | // #include 22 | // #include 23 | // #if 0 24 | // #define PATCH_BY_BENQI 25 | 26 | #include 27 | #include 28 | #include "nebula/base/reflection_util.h" 29 | #include "nebula/base/json/dynamic_converter.h" 30 | 31 | // using namespace kapok; 32 | 33 | // 使用go语言json接口 34 | template 35 | inline T Unmarshal(const folly::dynamic& root) { 36 | return JsonConvertTo(root); 37 | } 38 | 39 | // 会抛出异常... 40 | template 41 | inline folly::dynamic Marshal(const T& o, const char* key = nullptr) { 42 | if (key == nullptr || key[0] == '\0' ) { 43 | return ToJsonDynamic(o); 44 | } else { 45 | return folly::dynamic::object(key, ToJsonDynamic(o)); 46 | } 47 | } 48 | 49 | inline std::unique_ptr ToJsonIOBuf(const folly::dynamic& d) { 50 | auto&& json = folly::toJson(d); 51 | return folly::IOBuf::copyBuffer(json.c_str(), json.length()); 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /nebula/base/logger/glog_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_GLOG_UTIL_H_ 19 | #define NEBULA_BASE_GLOG_UTIL_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "nebula/base/configurable.h" 25 | 26 | namespace nebula { 27 | 28 | // 配置 29 | struct LogInitializer : public Configurable { 30 | virtual ~LogInitializer() = default; 31 | 32 | static void Initialize(const char* argv0); 33 | 34 | // 配置改变 35 | bool SetConf(const std::string& conf_name, const folly::dynamic& conf) override; 36 | }; 37 | 38 | std::shared_ptr GetLogInitializerSingleton(); 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /nebula/base/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_PLUGIN_H_ 19 | #define NEBULA_BASE_PLUGIN_H_ 20 | 21 | #include 22 | #include 23 | namespace nebula { 24 | 25 | class Plugin { 26 | public: 27 | virtual ~Plugin() = default; 28 | 29 | 30 | virtual const std::string& GetPluginName() const = 0; 31 | virtual void Install(const folly::dynamic& conf) = 0; 32 | 33 | virtual void Initialize() = 0; 34 | virtual void Shutdown() = 0; 35 | 36 | virtual void Uninstall() = 0; 37 | }; 38 | 39 | class PluginFactory { 40 | public: 41 | virtual ~PluginFactory () {} 42 | 43 | virtual const std::string& GetPluginName() const = 0; 44 | virtual Plugin* CreateInstance() = 0; 45 | virtual void DestroyInstance(Plugin* module) = 0; 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /nebula/base/readline_gets.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/readline_gets.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | // #include 29 | 30 | #include 31 | #include 32 | 33 | // http://web.mit.edu/gnu/doc/html/rlman_2.html 34 | /* Read a string, and return a pointer to it. Returns NULL on EOF. */ 35 | std::string ReadlineGets (const char* prompt) { 36 | std::string line; 37 | 38 | /* Get a line from the user. */ 39 | char* g_line_read = readline(prompt); 40 | 41 | /* If the line has any text in it, save it on the history. */ 42 | if (g_line_read) { 43 | if (*g_line_read) { 44 | add_history (g_line_read); 45 | line = g_line_read; 46 | } 47 | 48 | free(g_line_read); 49 | } 50 | 51 | return line; 52 | } 53 | -------------------------------------------------------------------------------- /nebula/base/readline_gets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_BASE_READLINE_GETS_H_ 19 | #define NEBULA_BASE_READLINE_GETS_H_ 20 | 21 | #include 22 | 23 | std::string ReadlineGets(const char* prompt = "nebula> "); 24 | 25 | #endif // NEBULA_BASE_READLINE_GETS_H_ 26 | -------------------------------------------------------------------------------- /nebula/base/snowflake4cxx/id.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/snowflake4cxx 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | #include "nebula/base/snowflake4cxx/id.h" 20 | 21 | #include 22 | 23 | namespace snowflake4cxx { 24 | 25 | namespace { 26 | 27 | // TODO(@benqi): 更高效的gettimeofday实现 28 | inline uint64_t NowInMsec() { 29 | timeval tv; 30 | gettimeofday(&tv, 0); 31 | return uint64_t(tv.tv_sec) * 1000 + tv.tv_usec/1000; 32 | } 33 | 34 | uint64_t WaitUntilNextMillis(uint64_t last_timestamp) { 35 | uint64_t timestamp = NowInMsec(); 36 | while (timestamp <= last_timestamp) { 37 | timestamp = NowInMsec(); 38 | } 39 | return timestamp; 40 | } 41 | 42 | } 43 | 44 | uint64_t IdWorkerUnThreadSafe::GetNextID() { 45 | uint64_t timestamp = NowInMsec(); 46 | 47 | // 在当前秒内 48 | if (last_timestamp_ == timestamp) { 49 | sequence_ = (sequence_ + 1) & 0xFFF; 50 | if (sequence_ == 0) { 51 | timestamp = WaitUntilNextMillis(last_timestamp_); 52 | } 53 | } else { 54 | sequence_ = 0; 55 | } 56 | 57 | last_timestamp_ = timestamp; 58 | return ((timestamp & 0x1FFFFFF) << 22 | 59 | (data_center_id_ & 0x1F) << 17 | 60 | (worker_id_& 0x1F) << 12 | 61 | (sequence_ & 0xFFF)); 62 | 63 | } 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /nebula/base/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(/usr/local/include ../..) 18 | 19 | set (BASE_TEST_LIST 20 | base_test.cc 21 | factory_test.cc 22 | futures_test.cc 23 | json_test.cc 24 | fibers_test.cc 25 | ) 26 | 27 | if(APPLE) 28 | add_executable (base_test ${BASE_TEST_LIST}) 29 | target_link_libraries (base_test net base) 30 | endif() 31 | 32 | -------------------------------------------------------------------------------- /nebula/base/testing/testing_util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/testing/testing_util.h" 19 | 20 | 21 | namespace nebula { 22 | 23 | // 假如这样使用,有问题 24 | /* 25 | static std::list g_testing_funcs; 26 | 27 | TestingFuncManager::TestingFuncManager(VoidFunc func) { 28 | // 在这里有问题 29 | // TODO(@benqi): 找出出问题原因 30 | // 找本编译和链接的书看看为什么会出问题?? 31 | g_testing_funcs.push_back(std::move(func)); 32 | } 33 | 34 | void TestingFuncManager::Testing() { 35 | for (auto f : g_testing_funcs) { 36 | f(); 37 | } 38 | } 39 | */ 40 | // hack如下 41 | std::list& get() { 42 | static std::list g_testing_funcs; 43 | return g_testing_funcs; 44 | } 45 | 46 | TestingFuncManager::TestingFuncManager(VoidFunc func) { 47 | // for (auto f : g_testing_funcs) { 48 | // f(); 49 | // } 50 | auto & funcs = get(); 51 | funcs.push_back(std::move(func)); 52 | } 53 | 54 | void TestingFuncManager::Testing() { 55 | auto & funcs = get(); 56 | for (auto f : funcs) { 57 | f(); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /nebula/base/testing/testing_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NUBULA_BASE_TESTING_UTIL_H_ 19 | #define NUBULA_BASE_TESTING_UTIL_H_ 20 | 21 | #include 22 | #include 23 | 24 | namespace nebula { 25 | 26 | // typedef VoidFunc (void*)(); 27 | 28 | // 简单测试框架 29 | // TODO(@wubenqi): 使用gtest 30 | /* 用例子 31 | static TestingFuncManager g_testing_func([] { 32 | static MessageFactoryManager::RegisterTemplate g_reg1("message1"); 33 | static MessageFactoryManager::RegisterTemplate g_reg2("message2"); 34 | 35 | auto message1 = MessageFactoryManager::CreateSharedInstance("message1"); 36 | auto message2 = MessageFactoryManager::CreateSharedInstance("message2"); 37 | }); 38 | */ 39 | 40 | struct TestingFuncManager { 41 | using VoidFunc = std::function; 42 | TestingFuncManager(VoidFunc func); 43 | 44 | static void Testing(); 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | 51 | // NUBULA_BASE_TEST_BASE_TEST_H_ 52 | -------------------------------------------------------------------------------- /nebula/base/time_util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/base/time_util.h" 19 | 20 | #include 21 | #include 22 | 23 | int64_t NowInMsecTime() { 24 | timeval tv; 25 | gettimeofday(&tv, 0); 26 | return int64_t(tv.tv_sec) * 1000 + tv.tv_usec/1000; 27 | } 28 | 29 | int64_t NowInUsecTime() { 30 | timeval tv; 31 | gettimeofday(&tv, 0); 32 | return int64_t(tv.tv_sec) * 1000000 + tv.tv_usec; 33 | } 34 | 35 | uint32_t Now() { 36 | return time(NULL); 37 | } 38 | -------------------------------------------------------------------------------- /nebula/base/time_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef BASE_TIME_UTIL_H_ 19 | #define BASE_TIME_UTIL_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | // 获取毫秒时间 26 | int64_t NowInMsecTime(); 27 | 28 | // 获取微秒时间 29 | int64_t NowInUsecTime(); 30 | 31 | // 32 | uint32_t Now(); 33 | 34 | /////////////////////////////////////////////////////////////////////////////// 35 | class DiffTimeUtil { 36 | public: 37 | DiffTimeUtil() { 38 | gettimeofday(&now_, nullptr); 39 | } 40 | 41 | void Reset() { 42 | gettimeofday(&now_, nullptr); 43 | } 44 | 45 | uint64_t GetDiffTime() const { 46 | struct timeval t; 47 | gettimeofday(&t, nullptr); 48 | return static_cast((t.tv_sec - now_.tv_sec)*1000) + (t.tv_usec - now_.tv_usec)/1000; 49 | } 50 | 51 | struct timeval now_; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /nebula/base/zlib_util.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/base/zlib_util.cc -------------------------------------------------------------------------------- /nebula/mysql_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | #include_directories(/usr/local/include/mysql /usr/local/include) 18 | 19 | set (SRC_LIST 20 | mysql_client.cc 21 | mysql_client.h 22 | mysql_client_util.cc 23 | mysql_client_util.h 24 | mysql_conn.cc 25 | mysql_conn.h 26 | mysql_conn_pool.cc 27 | mysql_conn_pool.h 28 | mysql_result_set.cc 29 | mysql_result_set.h 30 | mysql_query_util.cc 31 | mysql_query_util.h 32 | ) 33 | 34 | #link_directories( 35 | #/usr/local/lib 36 | #) 37 | 38 | 39 | add_library (mysql_client ${SRC_LIST}) 40 | target_link_libraries (mysql_client /usr/local/mysql/lib/libmysqlclient.a) 41 | 42 | add_subdirectory(test) 43 | 44 | -------------------------------------------------------------------------------- /nebula/mysql_client/dump.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/mysql_client/dump.rdb -------------------------------------------------------------------------------- /nebula/mysql_client/mysql_result_set.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/mysql_client/mysql_result_set.h" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "nebula/base/logger/glog_util.h" 26 | 27 | uint32_t MysqlResultSet::GetIndexByFieldName(const folly::StringPiece& name) const { 28 | uint32_t index = column_count_; 29 | for (uint32_t i=0; i(); 29 | folly::SocketAddress localAddr, peerAddr; 30 | sock->getLocalAddress(&localAddr); 31 | sock->getPeerAddress(&peerAddr); 32 | transportInfo->localAddr = std::make_shared(localAddr); 33 | transportInfo->remoteAddr = std::make_shared(peerAddr); 34 | pipeline->setTransportInfo(transportInfo); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /nebula/net/base/nebula_pipeline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_BASE_NEBULA_PIPELINE_H_ 19 | #define NEBULA_NET_BASE_NEBULA_PIPELINE_H_ 20 | 21 | #include "nebula/base/exception.h" 22 | 23 | #include 24 | 25 | namespace nebula { 26 | 27 | using PipelineBasePtr = std::shared_ptr; 28 | using EchoPipeline = wangle::Pipeline; 29 | using DefaultPipeline = wangle::Pipeline>; 30 | using ZProtoPipeline = wangle::Pipeline>; 31 | using TelegramPipeline = wangle::Pipeline>; 32 | using MTProtoPipeline = wangle::Pipeline>; 33 | 34 | // hack... 35 | template 36 | inline folly::Future write(wangle::PipelineBase* pipeline, W msg) { 37 | // hack,黑科技慎用!!!! 38 | auto pl = dynamic_cast*>(pipeline); 39 | if (!pl) { 40 | THROW_EXCEPTION(RuntimeException, "write(): no cast to wangle::Pipeline"); 41 | } 42 | 43 | return pl->write(std::forward(msg)); 44 | } 45 | 46 | // 客户端连接建立成功后未设置Addr,手动设置 47 | void SetPipelineAddr(wangle::PipelineBase* pipeline, folly::AsyncTransportWrapper* sock); 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /nebula/net/base/service_plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_BASE_SERVICE_PLUGIN_H_ 19 | #define NEBULA_NET_BASE_SERVICE_PLUGIN_H_ 20 | 21 | #include "nebula/base/plugin.h" 22 | 23 | namespace nebula { 24 | 25 | class ServicePlugin : public Plugin { 26 | public: 27 | virtual ~ServicePlugin() = default; 28 | 29 | void Install(const folly::dynamic& conf) override { 30 | service_info_.SetConf("", conf); 31 | } 32 | 33 | protected: 34 | ServiceConfig service_info_; 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /nebula/net/base/tcp_conn_event_callback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_BASE_TCP_CONN_EVENT_CALLBACK_H_ 19 | #define NEBULA_NET_BASE_TCP_CONN_EVENT_CALLBACK_H_ 20 | 21 | #include 22 | 23 | namespace nebula { 24 | 25 | ////////////////////////////////////////////////////////////////////////////// 26 | class TcpConnEventCallback { 27 | public: 28 | virtual ~TcpConnEventCallback() = default; 29 | 30 | // EventBase线程里执行 31 | virtual uint64_t OnNewConnection(wangle::PipelineBase* pipeline) { return 0; } 32 | 33 | // EventBase线程里执行 34 | virtual bool OnConnectionClosed(uint64_t conn_id) { return false; } 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /nebula/net/base_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_BASE_SERVER_H_ 19 | #define NEBULA_NET_BASE_SERVER_H_ 20 | 21 | #include 22 | 23 | #include "nebula/base/base_daemon.h" 24 | #include "nebula/net/base/service_base.h" 25 | #include "nebula/net/thread_group_list_manager.h" 26 | 27 | namespace nebula { 28 | 29 | // 两种情况 30 | // 刚启动时加载配置文件 31 | class BaseServer : public BaseDaemon { 32 | public: 33 | BaseServer(); 34 | ~BaseServer() override = default; 35 | 36 | protected: 37 | // 必须初始化以后才能调用 38 | void RegisterService(const std::string& name, const std::string& type, const std::string& proto) { 39 | // TODO(@benqi): 40 | // 检查是否已经加入 41 | services_.push_back(std::make_tuple(name, type, proto)); 42 | } 43 | 44 | bool LoadConfig(const std::string& config_path) override; 45 | bool Initialize() override; 46 | bool Run() override; 47 | bool Destroy() override; 48 | 49 | virtual void InstallModule(); 50 | 51 | // std::map connected_server_map_; 52 | ServicesConfig services_config_; 53 | 54 | ThreadGroupListOption thread_group_options_; 55 | 56 | typedef std::list> ServiceInstanceList; 57 | ServiceInstanceList services_; 58 | }; 59 | 60 | } 61 | 62 | #endif 63 | 64 | 65 | -------------------------------------------------------------------------------- /nebula/net/benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(/usr/local/include ../..) 18 | 19 | set (SRC_BENCHMARK_LIST 20 | benchmark.cc 21 | ) 22 | 23 | add_executable (benchmark ${SRC_BENCHMARK_LIST}) 24 | target_link_libraries (benchmark folly.a wangle.a boost_context-mt boost_filesystem-mt boost_system-mt double-conversion glog gflags event /usr/local/opt/openssl/lib/libcrypto.a /usr/local/opt/openssl/lib/libssl.a pthread z) 25 | 26 | set (SRC_BENCH_ASIO_LIST 27 | bench_asio.cc 28 | ) 29 | 30 | add_executable (bench_asio ${SRC_BENCH_ASIO_LIST}) 31 | target_link_libraries (bench_asio boost_context-mt boost_filesystem-mt boost_system-mt double-conversion glog gflags event /usr/local/opt/openssl/lib/libcrypto.a /usr/local/opt/openssl/lib/libssl.a pthread z) 32 | -------------------------------------------------------------------------------- /nebula/net/benchmark/bench_asio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace boost; 9 | 10 | //struct noncopyable { 11 | //protected: 12 | // noncopyable() {} 13 | // virtual ~noncopyable() {} 14 | //private: 15 | // noncopyable(const noncopyable&) = delete; 16 | // noncopyable& operator=(const noncopyable&) = delete; 17 | // noncopyable(noncopyable&&) = delete; 18 | // noncopyable& operator=(noncopyable&&) = delete; 19 | //}; 20 | 21 | /// A pool of io_service objects. 22 | class io_service_pool : noncopyable { 23 | public: 24 | /// Construct the io_service pool. 25 | explicit io_service_pool(std::size_t pool_size); 26 | 27 | /// Run all io_service objects in the pool. 28 | void run(); 29 | 30 | /// Stop all io_service objects in the pool. 31 | void stop(); 32 | 33 | /// Get an io_service to use. 34 | asio::io_service& get_io_service(); 35 | 36 | asio::io_service& get_io_service(size_t index); 37 | private: 38 | typedef std::shared_ptr io_service_ptr; 39 | typedef std::shared_ptr work_ptr; 40 | 41 | /// The pool of io_services. 42 | std::vector io_services_; 43 | 44 | /// The work that keeps the io_services running. 45 | std::vector work_; 46 | 47 | /// The next io_service to use for a connection. 48 | std::size_t next_io_service_; 49 | }; 50 | -------------------------------------------------------------------------------- /nebula/net/benchmark/multiple_thread.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | killall benchmark_pingpong_server 4 | timeout=${timeout:-100} 5 | bufsize=${bufsize:-16384} 6 | 7 | for nosessions in 100 1000; do 8 | for nothreads in 2 3 4 6 8; do 9 | sleep 5 10 | echo "Bufsize: $bufsize Threads: $nothreads Sessions: $nosessions" 11 | ./benchmark_pingpong_server 33333 $nothreads & srvpid=$! 12 | sleep 1 13 | ./benchmark_pingpong_client 127.0.0.1 33333 $nothreads $bufsize $nosessions $timeout 14 | kill -9 $srvpid 15 | done 16 | done 17 | -------------------------------------------------------------------------------- /nebula/net/benchmark/single_thread.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | killall benchmark_pingpong_server 6 | timeout=${timeout:-100} 7 | #bufsize=${bufsize:-16384} 8 | nothreads=1 9 | 10 | for bufsize in 1024 2048 4096 8192 16384 81920 409600; do 11 | for nosessions in 1 10 100 1000 10000; do 12 | echo "======================> Bufsize: $bufsize Threads: $nothreads Sessions: $nosessions" 13 | taskset -c 1 ./benchmark_pingpong_server 33333 $nothreads & srvpid=$! 14 | sleep 1 15 | taskset -c 2 ./benchmark_pingpong_client 127.0.0.1 33333 $nothreads $bufsize $nosessions $timeout 16 | sleep 1 17 | taskset -c 2 ./benchmark_pingpong_client_fixed_size 127.0.0.1 33333 $nothreads $bufsize $nosessions $timeout 18 | kill -9 $srvpid 19 | sleep 5 20 | done 21 | done 22 | -------------------------------------------------------------------------------- /nebula/net/engine/http_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEULA_NET_ENGINE_HTTP_SERVER_H_ 19 | #define NEULA_NET_ENGINE_HTTP_SERVER_H_ 20 | 21 | #include "nebula/net/engine/tcp_service_base.h" 22 | #include "nebula/net/http/http_server_lib.h" 23 | 24 | namespace nebula { 25 | 26 | class HttpServer : public ServiceBase { 27 | public: 28 | HttpServer(const ServiceConfig& config, const IOThreadPoolExecutorPtr& io_group) 29 | : ServiceBase(config), 30 | io_group_(io_group) {} 31 | 32 | virtual ~HttpServer() = default; 33 | 34 | // Impl from TcpServiceBase 35 | ServiceModuleType GetModuleType() const override { 36 | return ServiceModuleType::HTTP_SERVER; 37 | } 38 | 39 | bool Start() override; 40 | bool Pause() override; 41 | bool Stop() override; 42 | 43 | private: 44 | IOThreadPoolExecutorPtr io_group_; 45 | std::unique_ptr server_; 46 | }; 47 | 48 | } 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /nebula/net/engine/rpc_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_ENGINE_RPC_CLIENT_H_ 19 | #define NEBULA_NET_ENGINE_RPC_CLIENT_H_ 20 | 21 | #include "nebula/net/engine/tcp_client.h" 22 | 23 | namespace nebula { 24 | 25 | template 26 | class RpcClient : public TcpClient { 27 | public: 28 | RpcClient(const ServiceConfig& config, const IOThreadPoolExecutorPtr& io_group) 29 | : TcpClient(config, io_group) { 30 | } 31 | 32 | virtual ~RpcClient() = default; 33 | 34 | // Impl from TcpServiceBase 35 | ServiceModuleType GetModuleType() const override { 36 | return ServiceModuleType::RPC_CLIENT; 37 | } 38 | }; 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /nebula/net/engine/rpc_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_ENGINE_RPC_SERVER_H_ 19 | #define NEBULA_NET_ENGINE_RPC_SERVER_H_ 20 | 21 | #include "nebula/net/engine/tcp_server.h" 22 | 23 | namespace nebula { 24 | 25 | template 26 | class RpcServer : public TcpServer { 27 | public: 28 | RpcServer(const ServiceConfig& config, const IOThreadPoolExecutorPtr& io_group) 29 | : TcpServer(config, io_group) {} 30 | 31 | virtual ~RpcServer() = default; 32 | 33 | // Impl from TcpServiceBase 34 | ServiceModuleType GetModuleType() const override { 35 | return ServiceModuleType::RPC_SERVER; 36 | } 37 | }; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /nebula/net/engine/tcp_client_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_ENGINE_TCP_CLIENT_POOL_H_ 19 | #define NEBULA_NET_ENGINE_TCP_CLIENT_POOL_H_ 20 | 21 | #include "nebula/net/base/service_base.h" 22 | 23 | namespace nebula { 24 | 25 | //TODO(@benqi): 连接池实现 26 | template 27 | class TcpClientPool { 28 | public: 29 | virtual ~TcpClientPool() = default; 30 | }; 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /nebula/net/engine/tcp_service_base.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/engine/tcp_service_base.h" 19 | 20 | #include "nebula/net/thread_local_conn_manager.h" 21 | 22 | namespace nebula { 23 | 24 | // TODO(@benqi): 不直接使用GetConnManagerByThreadLocal, 通过回调注册来进行调用 25 | uint64_t TcpServiceBase::OnNewConnection(wangle::PipelineBase* pipeline) { 26 | return GetConnManagerByThreadLocal().OnNewConnection(pipeline); 27 | } 28 | 29 | bool TcpServiceBase::OnConnectionClosed(uint64_t conn_id) { 30 | return GetConnManagerByThreadLocal().OnConnectionClosed(conn_id); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /nebula/net/handler/README.md: -------------------------------------------------------------------------------- 1 | # TODO(@benqi): 2 | > handler的plugin加载方式支持 3 | 4 | -------------------------------------------------------------------------------- /nebula/net/handler/echo/udp_echo_handler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/handler/echo/udp_echo_handler.h" 19 | 20 | #include "nebula/base/logger/glog_util.h" 21 | #include "nebula/net/engine/udp_server.h" 22 | 23 | using namespace nebula; 24 | 25 | void ModuleUdpEchoInitialize() { 26 | static ServiceSelfRegisterTemplate g_reg_echo_udp_server(std::make_pair("udp_server", "echo"), 27 | [](const ServiceConfig& service_config, const std::shared_ptr& io_group) -> ServiceBasePtr { 28 | auto service = std::make_shared(service_config, io_group); 29 | auto factory = std::make_shared(service.get()); 30 | service->SetPipeline(factory); 31 | return service; 32 | }); 33 | } 34 | 35 | UdpEchoPipeline::UdpEchoPipeline() { 36 | LOG(INFO) << "UdpEchoPipeline::UdpEchoPipeline()"; 37 | } 38 | 39 | void UdpEchoPipeline::read(Context*, wangle::AcceptPipelineType) { 40 | LOG(INFO) << "UdpEchoPipeline::read()"; 41 | } 42 | 43 | 44 | wangle::AcceptPipeline::Ptr UdpEchoPipelineFactory::newPipeline(wangle::Acceptor*) { 45 | auto pipeline = wangle::AcceptPipeline::create(); 46 | pipeline->addBack(UdpEchoPipeline()); 47 | return pipeline; 48 | } 49 | -------------------------------------------------------------------------------- /nebula/net/handler/echo/udp_echo_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NUBULA_NET_HANDLER_ECHO_UDP_ECHO_HANDLER_H_ 19 | #define NUBULA_NET_HANDLER_ECHO_UDP_ECHO_HANDLER_H_ 20 | 21 | #include 22 | #include "nebula/net/handler/nebula_base_handler.h" 23 | 24 | //template 25 | //class TestHandlerPipelineFactory : public AcceptPipelineFactory { 26 | //public: 27 | // AcceptPipeline::Ptr newPipeline(Acceptor*) override { 28 | // auto pipeline = AcceptPipeline::create(); 29 | // pipeline->addBack(HandlerPipeline()); 30 | // return pipeline; 31 | // } 32 | //}; 33 | 34 | class UdpEchoPipeline : public wangle::InboundHandler { 35 | public: 36 | UdpEchoPipeline(); 37 | void read(Context*, wangle::AcceptPipelineType) override; 38 | }; 39 | 40 | // chains the handlers together to define the response pipeline 41 | class UdpEchoPipelineFactory : public wangle::AcceptPipelineFactory, public nebula::NebulaBasePipelineFactory { 42 | public: 43 | explicit UdpEchoPipelineFactory(nebula::ServiceBase* service) 44 | : NebulaBasePipelineFactory(service) {} 45 | 46 | wangle::AcceptPipeline::Ptr newPipeline(wangle::Acceptor*) override; 47 | }; 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /nebula/net/handler/module_install.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/handler/module_install.h" 19 | 20 | void InstallModule() { 21 | // echo 22 | extern void ModuleEchoInitialize(); 23 | ModuleEchoInitialize(); 24 | 25 | // udp_echo 26 | extern void ModuleUdpEchoInitialize(); 27 | ModuleUdpEchoInitialize(); 28 | 29 | // pingpong 30 | extern void ModulePingpongInitialize(); 31 | ModulePingpongInitialize(); 32 | 33 | // zproto 34 | extern void ModuleZProtoInitialize(); 35 | ModuleZProtoInitialize(); 36 | 37 | // http 38 | extern void ModuleHttpInitialize(); 39 | ModuleHttpInitialize(); 40 | 41 | // rpc 42 | // extern void ModuleZRpcInitialize(); 43 | // ModuleZRpcInitialize(); 44 | 45 | // teamtalk 46 | // extern void ModuleTeamtalkInitialize(); 47 | // ModuleTeamtalkInitialize(); 48 | 49 | // telegram 50 | // extern void ModuleTelegramInitialize(); 51 | // ModuleTelegramInitialize(); 52 | 53 | // mtproto 54 | // extern void ModuleMTProtoInitialize(); 55 | // ModuleMTProtoInitialize(); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /nebula/net/handler/module_install.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_HANDLER_MODULE_INSTALL_H_ 19 | #define NEBULA_NET_HANDLER_MODULE_INSTALL_H_ 20 | 21 | void InstallModule(); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /nebula/net/handler/mtproto/mtproto_pipeline_factory.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/handler/mtproto/mtproto_pipeline_factory.h" 19 | 20 | #include 21 | #include 22 | 23 | #include "nebula/net/thread_local_conn_manager.h" 24 | #include "nebula/net/handler/mtproto/mtproto_transport_handler.h" 25 | 26 | namespace { 27 | 28 | // 设置readBufferSettings_ 29 | const uint64_t kDefaultMinAvailable = 8096; 30 | const uint64_t kDefaultAllocationSize = 16192; 31 | 32 | } 33 | 34 | /////////////////////////////////////////////////////////////////////////////////////////// 35 | nebula::MTProtoPipeline::Ptr MTProtoServerPipelineFactory::newPipeline(std::shared_ptr sock) { 36 | auto pipeline = nebula::MTProtoPipeline::create(); 37 | pipeline->setReadBufferSettings(kDefaultMinAvailable, kDefaultAllocationSize); 38 | pipeline->addBack(wangle::AsyncSocketHandler(sock)); 39 | pipeline->addBack(MTProtoTransportHandler()); 40 | // pipeline->addBack(MTProtoMessageHandler()); 41 | pipeline->addBack(MTProtoHandler(service_)); 42 | pipeline->finalize(); 43 | 44 | return pipeline; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /nebula/net/handler/mtproto/mtproto_pipeline_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_HANDLER_MTPROTO_MTPROTO_PIPELINE_FACTORY_H_ 19 | #define NEBULA_NET_HANDLER_MTPROTO_MTPROTO_PIPELINE_FACTORY_H_ 20 | 21 | #include "nebula/net/base/nebula_pipeline.h" 22 | #include "nebula/net/handler/mtproto/mtproto_handler.h" 23 | 24 | class MTProtoServerPipelineFactory : public wangle::PipelineFactory { 25 | public: 26 | MTProtoServerPipelineFactory(nebula::ServiceBase* service) 27 | : service_(service) {} 28 | 29 | nebula::MTProtoPipeline::Ptr newPipeline(std::shared_ptr sock); 30 | 31 | private: 32 | nebula::ServiceBase* service_{nullptr}; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /nebula/net/handler/nebula_base_handler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/handler/nebula_base_handler.h" 19 | 20 | namespace nebula { 21 | 22 | uint64_t NebulaBaseHandler::OnNewConnection(wangle::PipelineBase* pipeline, const std::string& remote_address) { 23 | // 连接建立 24 | // TODO(@benqi): 检查输入参数以及状态 25 | conn_state_ = ConnState::CONNECTED; 26 | remote_address_ = remote_address; 27 | conn_id_ = service_->OnNewConnection(pipeline); 28 | 29 | return conn_id_; 30 | } 31 | 32 | void NebulaBaseHandler::OnConnectionClosed() { 33 | if (conn_state_ == ConnState::CONNECTED) { 34 | service_->OnConnectionClosed(conn_id_); 35 | conn_state_ = ConnState::CLOSED; 36 | remote_address_.clear(); 37 | conn_id_ = 0; 38 | } else { 39 | // TODO(@benqi): LOG() << 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /nebula/net/handler/nebula_handler_util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/handler/nebula_handler_util.h" 19 | 20 | -------------------------------------------------------------------------------- /nebula/net/handler/telegram/mtproto_codec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NET_TELEGRAM_MTPROTO_CODEC_H_ 19 | #define NET_TELEGRAM_MTPROTO_CODEC_H_ 20 | 21 | #include 22 | #include "nebula/net/telegram/core/mtproto_message.h" 23 | 24 | using BytesToMTProtoMessage = wangle::InboundHandler, std::shared_ptr>; 25 | 26 | class MTProtoDecoder : public BytesToMTProtoMessage { 27 | public: 28 | typedef typename BytesToMTProtoMessage::Context Context; 29 | 30 | MTProtoDecoder() = default; 31 | ~MTProtoDecoder() override = default; 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | void read(Context* ctx, std::unique_ptr msg) override; 35 | 36 | private: 37 | bool DecryptServerResponse(int64_t key_id, uint8_t *key, uint8_t *data, uint32_t length); 38 | 39 | bool loaded_ {false}; 40 | TLInt2048 auth_key_; 41 | int64_t auth_key_id_ {0}; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /nebula/net/handler/telegram/telegram_handshake_handler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Created by wubenqi. 6 | * 7 | */ 8 | 9 | #include "net/telegram/telegram_handshake_handler.h" 10 | 11 | -------------------------------------------------------------------------------- /nebula/net/handler/telegram/telegram_handshake_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Created by wubenqi. 6 | * 7 | */ 8 | 9 | #ifndef NET_TELEGRAM_TELEGRAM_HANDSHAKE_HANDLER_H 10 | #define NET_TELEGRAM_TELEGRAM_HANDSHAKE_HANDLER_H 11 | 12 | class TelegramHandshakeHandler { 13 | public: 14 | virtual ~TelegramHandshakeHandler() = default; 15 | 16 | private: 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /nebula/net/handler/telegram/telegram_rpc_handler.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Created by wubenqi. 6 | * 7 | */ 8 | 9 | #include "net/telegram/telegram_rpc_handler.h" 10 | 11 | -------------------------------------------------------------------------------- /nebula/net/handler/telegram/telegram_rpc_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Created by wubenqi. 6 | * 7 | */ 8 | 9 | #ifndef NET_TELEGRAM_TELEGRAM_RPC_HANDLER_H 10 | #define NET_TELEGRAM_TELEGRAM_RPC_HANDLER_H 11 | 12 | class TelegramRpcHandler { 13 | public: 14 | virtual ~TelegramRpcHandler() = default; 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/README.md: -------------------------------------------------------------------------------- 1 | 1. 网关解压到BasicSyncMessage 2 | 2. 转到逻辑服务器需要通过RPC进行通信 3 | 4 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/authorization_manager.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/net/handler/zproto/authorization_manager.cc -------------------------------------------------------------------------------- /nebula/net/handler/zproto/authorization_manager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/net/handler/zproto/authorization_manager.h -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(/usr/local/include ../..) 18 | 19 | #add_executable (zproto_test zproto_test.cc) 20 | #target_link_libraries (zproto_test net base) 21 | 22 | add_executable (zrpc_client_test zrpc_client_test.cc zrpc_test.pb.cc zrpc_test.pb.h zrpc_test.proto) 23 | target_link_libraries (zrpc_client_test net base protobuf) 24 | 25 | add_executable (zrpc_server_test 26 | zrpc_server_test.cc 27 | zrpc_test_service.cc 28 | zrpc_test_service.h 29 | zrpc_test_service_impl.cc 30 | zrpc_test_service_impl.h 31 | zrpc_test_dispatcher.cc 32 | zrpc_test_dispatcher.h 33 | zrpc_test.pb.cc 34 | zrpc_test.pb.h 35 | zrpc_test.proto 36 | ) 37 | target_link_libraries (zrpc_server_test net base protobuf) 38 | 39 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/build.sh: -------------------------------------------------------------------------------- 1 | protoc -I=./ --cpp_out=./ ./*.proto 2 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_server_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/base_server.h" 19 | 20 | #include "zrpc_test.pb.h" 21 | #include "nebula/net/rpc/zrpc_service_util.h" 22 | 23 | #include "nebula/net/zproto/api_message_box.h" 24 | 25 | ////////////////////////////////////////////////////////////////////////////////////////////// 26 | class ZRpcServerTest : public nebula::BaseServer { 27 | public: 28 | ZRpcServerTest() = default; 29 | ~ZRpcServerTest() override = default; 30 | 31 | protected: 32 | bool Initialize() override { 33 | RegisterService("zrpc_server_test", "rpc_server", "zrpc"); 34 | 35 | // ZRpcUtil::Register("zproto.ZRpcTestReq", DoZRpcTestReq); 36 | 37 | BaseServer::Initialize(); 38 | return true; 39 | } 40 | 41 | bool Run() override { 42 | BaseServer::Run(); 43 | return true; 44 | } 45 | }; 46 | 47 | //////////////////////////////////////////////////////////////////////////// 48 | int main(int argc, char* argv[]) { 49 | return nebula::DoMain(argc, argv); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProto"; 24 | option optimize_for = CODE_SIZE; 25 | 26 | message ZRpcTestReq { 27 | string req_id = 1; 28 | } 29 | 30 | message ZRpcTestRsp { 31 | string rsp_data = 1; 32 | } 33 | 34 | message ZRpcTestPush { 35 | string push_data = 1; 36 | } 37 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_dispatcher.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "zrpc_test_dispatcher.h" 19 | 20 | #include "zrpc_test.pb.h" 21 | #include "nebula/net/rpc/zrpc_service_util.h" 22 | #include "zrpc_test_service_impl.h" 23 | #include "nebula/net/zproto/api_message_box.h" 24 | 25 | static ZRpcTestDispatcher g_rpc_test_dispatcher; 26 | 27 | ZRpcTestDispatcher::ZRpcTestDispatcher() { 28 | ZRpcUtil::Register("zproto.ZRpcTestReq", ZRpcTestDispatcher::OnZRpcTestReq); 29 | } 30 | 31 | ProtoRpcResponsePtr ZRpcTestDispatcher::OnZRpcTestReq(RpcRequestPtr request) { 32 | CAST_RPC_REQUEST(ZRpcTestReq, rpc_test_req); 33 | LOG(INFO) << rpc_test_req.Utf8DebugString(); 34 | zproto::ZRpcTestRsp message_rsp; 35 | 36 | ZRpcTestServiceImpl service_impl; 37 | service_impl.OnZRpcTest(rpc_test_req, &message_rsp); 38 | 39 | return ::MakeRpcOK(message_rsp); 40 | } 41 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_dispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef TEST_ZRPC_TEST_DISPATCHER_H_ 19 | #define TEST_ZRPC_TEST_DISPATCHER_H_ 20 | 21 | #include "nebula/net/zproto/zproto_package_data.h" 22 | 23 | class ZRpcTestDispatcher { 24 | public: 25 | ZRpcTestDispatcher(); 26 | ~ZRpcTestDispatcher() = default; 27 | 28 | static ProtoRpcResponsePtr OnZRpcTestReq(RpcRequestPtr request); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_service.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "zrpc_test_service.h" 19 | 20 | #include "nebula/base/logger/glog_util.h" 21 | 22 | int ZRpcTestService::OnZRpcTest(const zproto::ZRpcTestReq& zrpc_test_req, zproto::ZRpcTestRsp* zrpc_test_rsp) { 23 | LOG(ERROR) << "OnZRpcTest - OnZRpcTest unimplemented"; 24 | return -1; 25 | } 26 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef TEST_ZRPC_TEST_SERVICE_H_ 19 | #define TEST_ZRPC_TEST_SERVICE_H_ 20 | 21 | // #include "nebula/net/base_server.h" 22 | #include "zrpc_test.pb.h" 23 | 24 | class ZRpcTestService { 25 | public: 26 | ZRpcTestService() = default; 27 | virtual ~ZRpcTestService() = default; 28 | 29 | virtual int OnZRpcTest(const zproto::ZRpcTestReq& zrpc_test_req, zproto::ZRpcTestRsp* zrpc_test_rsp); 30 | 31 | protected: 32 | 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_service_impl.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "zrpc_test_service_impl.h" 19 | 20 | int ZRpcTestServiceImpl::OnZRpcTest(const zproto::ZRpcTestReq& zrpc_test_req, 21 | zproto::ZRpcTestRsp* zrpc_test_rsp) { 22 | 23 | zrpc_test_rsp->set_rsp_data("0123456789876543210"); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /nebula/net/handler/zproto/test/zrpc_test_service_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef TEST_ZRPC_TEST_SERVICE_IMPL_H_ 19 | #define TEST_ZRPC_TEST_SERVICE_IMPL_H_ 20 | 21 | #include "zrpc_test_service.h" 22 | 23 | class ZRpcTestServiceImpl : public ZRpcTestService { 24 | public: 25 | ZRpcTestServiceImpl() = default; 26 | ~ZRpcTestServiceImpl() = default; 27 | 28 | int OnZRpcTest(const zproto::ZRpcTestReq& zrpc_test_req, zproto::ZRpcTestRsp* zrpc_test_rsp) override; 29 | 30 | protected: 31 | 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /nebula/net/rpc/README.md: -------------------------------------------------------------------------------- 1 | 1. client调用 2 | 1). 超时情况: 网络问题、业务导致超时 3 | 2). 调用时网络异常 4 | 3). 网络异常,无法调用 5 | -------------------------------------------------------------------------------- /nebula/net/rpc/zrpc_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_RPC_ZRPC_SERVICE_H_ 19 | #define NEBULA_NET_RPC_ZRPC_SERVICE_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "nebula/base/func_factory_manager.h" 25 | #include "nebula/net/zproto/zproto_package_data.h" 26 | 27 | class ZRpcService : public wangle::Service { 28 | public: 29 | virtual folly::Future operator()(zproto::RpcRequestPtr request) override; 30 | }; 31 | 32 | /* 33 | typedef ProtoRpcResponsePtr(*ZRpcServiceFunc(ProtoRpcResponsePtr); 34 | typedef nebula::FuncFactoryManager ZRpcServiceFactory; 35 | 36 | #define REGISTER_HTTP_HANDLER(K, F) \ 37 | static ZRpcServiceFactory::RegisterTemplate g_reg_zrpc_func_##K(K, &F) 38 | */ 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /nebula/net/rpc/zrpc_service_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/zhatalk 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_NET_RPC_ZRPC_SERVICE_UTIL_H_ 19 | #define NEBULA_NET_RPC_ZRPC_SERVICE_UTIL_H_ 20 | 21 | #include 22 | 23 | #include "nebula/net/zproto/zproto_package_data.h" 24 | 25 | // ZRpc帮助类 26 | struct ZRpcUtil { 27 | static ZRpcUtil& GetInstance() { 28 | static ZRpcUtil g_instance; 29 | return g_instance; 30 | } 31 | 32 | using ServiceFunc = std::function; 33 | 34 | static folly::Future DoClientCall(const std::string& service_name, zproto::RpcRequestPtr request); 35 | 36 | static void Register(int method_id, ServiceFunc f); 37 | 38 | // Request名字的crc32值作为method_id 39 | static void Register(const std::string& message_name, ServiceFunc f); 40 | 41 | protected: 42 | friend class ZRpcService; 43 | static zproto::ProtoRpcResponsePtr DoServiceCall(zproto::RpcRequestPtr request); 44 | 45 | // TODO(@benqi): 使用FuncFactoryManager 46 | std::map g_rpc_services; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /nebula/net/test/http_client_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/engine/http_client.h" 19 | 20 | void HttpClientTest(folly::EventBase* evb, const std::string& url) { 21 | HttpClientGet(evb, url, [&] (HttpClientReply& reply) { 22 | switch (reply.result) { 23 | case HttpClientReply::OK: 24 | reply.headers->dumpMessageToSink(nullptr); 25 | std::cout << reply.body->moveToFbString() << std::endl; 26 | // reply.body 27 | break; 28 | case HttpClientReply::INVALID: 29 | LOG(INFO) << "INVALID"; 30 | break; 31 | case HttpClientReply::CONNECT_ERROR: 32 | LOG(INFO) << "CONNECT_ERROR"; 33 | break; 34 | case HttpClientReply::HTTP_ERROR: 35 | LOG(INFO) << "HTTP_ERROR"; 36 | break; 37 | default: 38 | break; 39 | } 40 | }); 41 | } 42 | 43 | 44 | int main(int argc, char* argv[]) { 45 | folly::EventBase main_eb; 46 | 47 | HttpClientTest(&main_eb, "http://www.baidu.com"); 48 | 49 | main_eb.loopForever(); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /nebula/net/test/pingpong_server_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, https://github.com/nebulaim/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/base_server.h" 19 | #include "nebula/net/handler/pingpong/pingpong_handler.h" 20 | 21 | class PingpongServerTest : public nebula::BaseServer { 22 | public: 23 | PingpongServerTest() = default; 24 | virtual ~PingpongServerTest() override = default; 25 | 26 | protected: 27 | bool Initialize() override { 28 | RegisterService("pingpong_server_test", "tcp_server", "pingpong"); 29 | BaseServer::Initialize(); 30 | return true; 31 | } 32 | 33 | bool Run() override { 34 | BaseServer::Run(); 35 | return true; 36 | } 37 | }; 38 | 39 | //////////////////////////////////////////////////////////////////////////// 40 | int main(int argc, char* argv[]) { 41 | return nebula::DoMain(argc, argv); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /nebula/net/test/pingpong_server_test.json: -------------------------------------------------------------------------------- 1 | { 2 | // 全局配置文件 3 | // "system": { 4 | // }, 5 | 6 | "thread_group" : { 7 | "conn" : 1, 8 | }, 9 | 10 | // 日志配置 11 | "logger":{ 12 | // 配置 13 | }, 14 | 15 | // 网络相关 16 | "services":"@import(test_service.json)" 17 | } 18 | -------------------------------------------------------------------------------- /nebula/net/test/test_service.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"zrpc_server_test", 4 | "type":"rpc_server", 5 | "proto":"zrpc", 6 | "hosts":"0.0.0.0", 7 | "port":22345, 8 | }, 9 | { 10 | "name":"zrpc_client_test", 11 | "type":"rpc_client", 12 | "proto":"zrpc", 13 | "hosts":"127.0.0.1", 14 | "port":22345, 15 | }, 16 | { 17 | "name":"udp_echo_server_test", 18 | "type":"udp_server", 19 | "proto":"echo", 20 | "hosts":"0.0.0.0", 21 | "port":22345, 22 | }, 23 | { 24 | "name":"pingpong_server_test", 25 | "type":"tcp_server", 26 | "proto":"pingpong", 27 | "hosts":"0.0.0.0", 28 | "port":33333, 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /nebula/net/test/thread_util_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | #include "nebula/base/config_manager.h" 24 | #include "nebula/net/thread_group_list_manager.h" 25 | 26 | DEFINE_string(json, "", "thread_util_test.json"); 27 | 28 | using namespace nebula; 29 | 30 | int main(int argc, char* argv[]) { 31 | gflags::ParseCommandLineFlags(&argc, &argv, true); 32 | // google::InitGoogleLogging(argv[0]); 33 | // google::InstallFailureSignalHandler(); 34 | 35 | folly::EventBase main_evb; 36 | 37 | ConfigManager* config_manager = ConfigManager::GetInstance(); 38 | 39 | ThreadGroupListOption thread_options; 40 | config_manager->Register("thread_pool", &thread_options); 41 | 42 | std::string config_path = FLAGS_json; 43 | if (FLAGS_json.empty()){ 44 | config_path = "thread_util_test"; //google::ProgramInvocationShortName(); 45 | config_path += ".json"; 46 | } 47 | 48 | config_manager->Initialize(config_path); 49 | ThreadGroupListManager thread_manager(thread_options); 50 | // thread_manager->Initialize(); 51 | 52 | main_evb.loopForever(); 53 | 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /nebula/net/test/udp_echo_client_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import socket 3 | addr=('127.0.0.1', 50001) 4 | s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) 5 | while 1: 6 | data=raw_input() 7 | #print data 8 | if not data: 9 | break 10 | s.sendto(data,addr) 11 | data2,addr=s.recvfrom(2048) 12 | if not data2: 13 | break 14 | # print "got data2 from", addr 15 | print data2 16 | s.close() 17 | -------------------------------------------------------------------------------- /nebula/net/test/udp_echo_server_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/net/base_server.h" 19 | #include "nebula/net/handler/echo/udp_echo_handler.h" 20 | 21 | //using namespace nebula; 22 | 23 | class UdpEchoServerTest : public nebula::BaseServer { 24 | public: 25 | UdpEchoServerTest() = default; 26 | virtual ~UdpEchoServerTest() override = default; 27 | 28 | protected: 29 | bool Initialize() override { 30 | RegisterService("udp_echo_server_test", "udp_server", "echo"); 31 | 32 | BaseServer::Initialize(); 33 | return true; 34 | } 35 | 36 | bool Run() override { 37 | BaseServer::Run(); 38 | return true; 39 | } 40 | }; 41 | 42 | //////////////////////////////////////////////////////////////////////////// 43 | int main(int argc, char* argv[]) { 44 | return nebula::DoMain(argc, argv); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /nebula/net/test/udp_echo_server_test.json: -------------------------------------------------------------------------------- 1 | { 2 | // 全局配置文件 3 | // "system": { 4 | // }, 5 | 6 | "thread_group" : { 7 | "conn" : 1, 8 | }, 9 | 10 | // 日志配置 11 | "logger":{ 12 | // 配置 13 | }, 14 | 15 | // 网络相关 16 | "services":"@import(test_service.json)" 17 | } 18 | -------------------------------------------------------------------------------- /nebula/net/test/udp_server_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import socket 3 | address=('127.0.0.1',22345) 4 | s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) 5 | s.bind(address) 6 | while 1: 7 | data,addr=s.recvfrom(2048) 8 | if not data: 9 | break 10 | print "got data from",addr 11 | print data 12 | s.close() 13 | 14 | -------------------------------------------------------------------------------- /nebula/redis_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | #include_directories(/usr/local/include/mysql /usr/local/include) 18 | 19 | set (SRC_LIST 20 | redis_conn.cc 21 | redis_conn.h 22 | redis_conn_pool.cc 23 | redis_conn_pool.h 24 | redis_client.cc 25 | redis_client.h 26 | ) 27 | 28 | 29 | #link_directories( 30 | #/usr/local/lib 31 | #) 32 | 33 | 34 | add_library (redis_client ${SRC_LIST}) 35 | target_link_libraries (redis_client -lhiredis) 36 | 37 | #add_subdirectory(test) 38 | 39 | -------------------------------------------------------------------------------- /nebula/redis_client/redis.json: -------------------------------------------------------------------------------- 1 | { 2 | "thread": 16, 3 | ////////////////////////////////////////////////////// 4 | // 通用配置redis使用 5 | "im_redis_com": [ 6 | { 7 | "type": "master", 8 | "host": "10.19.22.11", 9 | "port": 11552, 10 | "database": 0 11 | }, 12 | { 13 | "type": "slave", 14 | "host": "10.19.22.16", 15 | "port": 11552, 16 | "database": 0 17 | } 18 | ] 19 | } 20 | 21 | -------------------------------------------------------------------------------- /nebula/redis_client/redis_client.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "nebula/redis_client/redis_client.h" 19 | 20 | bool RedisConnPoolMgr::Initialize(const std::vector& redis_addr_list) { 21 | for (const auto & addr : redis_addr_list) { 22 | auto pool = std::make_shared(); 23 | pool->Initialize(addr); 24 | conn_pools_.insert(std::make_pair(addr.name, pool)); 25 | } 26 | return true; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /nebula/redis_client/redis_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NEBULA_REDIS_CLIENT_REDIS_CLIENT_H_ 19 | #define NEBULA_REDIS_CLIENT_REDIS_CLIENT_H_ 20 | 21 | #include 22 | #include "nebula/redis_client/redis_conn_pool.h" 23 | 24 | class RedisConnPoolMgr { 25 | public: 26 | RedisConnPoolMgr() = default; 27 | ~RedisConnPoolMgr() = default; 28 | 29 | // static std::shared_ptr GetInstance(); 30 | bool Initialize(const std::vector& redis_addr_list); 31 | 32 | RedisConnPool* GetRedisConnPool(const std::string& instance_name) { 33 | // TODO(@benqi): 有问题 34 | auto it = conn_pools_.find(instance_name); 35 | if (it!=conn_pools_.end()) { 36 | return it->second.get(); 37 | } 38 | 39 | return nullptr; 40 | } 41 | 42 | private: 43 | std::map> conn_pools_; 44 | // std::shared_ptr db_thread_pool_; 45 | }; 46 | 47 | #endif // NEBULA_REDIS_CLIENT_REDIS_CLIENT_H_ 48 | -------------------------------------------------------------------------------- /nebula/scriptengine/README.md: -------------------------------------------------------------------------------- 1 | # Lua脚本引擎 2 | 3 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.2.3, released on 11 Nov 2013. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/lua-5.2.3/doc/logo.gif -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | border: solid #a0a0a0 1px ; 7 | border-radius: 20px ; 8 | padding: 26px ; 9 | margin: 16px ; 10 | color: #000000 ; 11 | background-color: #FFFFFF ; 12 | font-family: Helvetica, Arial, sans-serif ; 13 | text-align: justify ; 14 | } 15 | 16 | h1, h2, h3, h4 { 17 | font-family: Verdana, Geneva, sans-serif ; 18 | font-weight: normal ; 19 | font-style: normal ; 20 | } 21 | 22 | h2 { 23 | padding-top: 0.4em ; 24 | padding-bottom: 0.4em ; 25 | padding-left: 0.8em ; 26 | padding-right: 0.8em ; 27 | background-color: #D0D0FF ; 28 | border-radius: 8px ; 29 | border: solid #a0a0a0 1px ; 30 | } 31 | 32 | h3 { 33 | padding-left: 0.5em ; 34 | border-left: solid #D0D0FF 1em ; 35 | } 36 | 37 | table h3 { 38 | padding-left: 0px ; 39 | border-left: none ; 40 | } 41 | 42 | a:link { 43 | color: #000080 ; 44 | background-color: inherit ; 45 | text-decoration: none ; 46 | } 47 | 48 | a:visited { 49 | background-color: inherit ; 50 | text-decoration: none ; 51 | } 52 | 53 | a:link:hover, a:visited:hover { 54 | color: #000080 ; 55 | background-color: #D0D0FF ; 56 | } 57 | 58 | a:link:active, a:visited:active { 59 | color: #FF0000 ; 60 | } 61 | 62 | hr { 63 | border: 0 ; 64 | height: 1px ; 65 | color: #a0a0a0 ; 66 | background-color: #a0a0a0 ; 67 | display: none ; 68 | } 69 | 70 | table hr { 71 | display: block ; 72 | } 73 | 74 | :target { 75 | background-color: #F8F8F8 ; 76 | padding: 8px ; 77 | border: solid #a0a0a0 2px ; 78 | border-radius: 8px ; 79 | } 80 | 81 | .footer { 82 | color: gray ; 83 | font-size: x-small ; 84 | } 85 | 86 | input[type=text] { 87 | border: solid #a0a0a0 2px ; 88 | border-radius: 2em ; 89 | -moz-border-radius: 2em ; 90 | background-image: url('images/search.png') ; 91 | background-repeat: no-repeat; 92 | background-position: 4px center ; 93 | padding-left: 20px ; 94 | height: 2em ; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | font-style: normal ; 20 | padding-top: 0.4em ; 21 | padding-bottom: 0.4em ; 22 | padding-left: 16px ; 23 | margin-left: -16px ; 24 | background-color: #D0D0FF ; 25 | border-radius: 8px ; 26 | border: solid #000080 1px ; 27 | } 28 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/lua-5.2.3/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2); 27 | LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, 28 | const TValue *p2); 29 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 30 | const TValue *p2); 31 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 32 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by `runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 29 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 30 | int pc); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | {LUA_LOADLIBNAME, luaopen_package}, 32 | {LUA_COLIBNAME, luaopen_coroutine}, 33 | {LUA_TABLIBNAME, luaopen_table}, 34 | {LUA_IOLIBNAME, luaopen_io}, 35 | {LUA_OSLIBNAME, luaopen_os}, 36 | {LUA_STRLIBNAME, luaopen_string}, 37 | {LUA_BITLIBNAME, luaopen_bit32}, 38 | {LUA_MATHLIBNAME, luaopen_math}, 39 | {LUA_DBLIBNAME, luaopen_debug}, 40 | {NULL, NULL} 41 | }; 42 | 43 | 44 | /* 45 | ** these libs are preloaded and must be required before used 46 | */ 47 | static const luaL_Reg preloadedlibs[] = { 48 | {NULL, NULL} 49 | }; 50 | 51 | 52 | LUALIB_API void luaL_openlibs (lua_State *L) { 53 | const luaL_Reg *lib; 54 | /* call open functions from 'loadedlibs' and set results to global table */ 55 | for (lib = loadedlibs; lib->func; lib++) { 56 | luaL_requiref(L, lib->name, lib->func, 1); 57 | lua_pop(L, 1); /* remove lib */ 58 | } 59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 60 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 61 | for (lib = preloadedlibs; lib->func; lib++) { 62 | lua_pushcfunction(L, lib->func); 63 | lua_setfield(L, -2, lib->name); 64 | } 65 | lua_pop(L, 1); /* remove _PRELOAD table */ 66 | } 67 | 68 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is 19 | ** always constant. 20 | ** The macro is somewhat complex to avoid warnings: 21 | ** +1 avoids warnings of "comparison has constant result"; 22 | ** cast to 'void' avoids warnings of "value unused". 23 | */ 24 | #define luaM_reallocv(L,b,on,n,e) \ 25 | (cast(void, \ 26 | (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \ 27 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 28 | 29 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 30 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 31 | #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0])) 32 | 33 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 34 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 35 | #define luaM_newvector(L,n,t) \ 36 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 37 | 38 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 39 | 40 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 41 | if ((nelems)+1 > (size)) \ 42 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 43 | 44 | #define luaM_reallocvector(L, v,oldn,n,t) \ 45 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 46 | 47 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 48 | 49 | /* not to be called directly */ 50 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 51 | size_t size); 52 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 53 | size_t size_elem, int limit, 54 | const char *what); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 16 | 17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 18 | 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 20 | (sizeof(s)/sizeof(char))-1)) 21 | 22 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); 40 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define invalidateTMcache(t) ((t)->flags = 0) 19 | 20 | /* returns the key, given the value of a table entry */ 21 | #define keyfromval(v) \ 22 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 23 | 24 | 25 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); 26 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); 27 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 28 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 31 | LUAI_FUNC Table *luaH_new (lua_State *L); 32 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); 33 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 34 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 35 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 36 | LUAI_FUNC int luaH_getn (Table *t); 37 | 38 | 39 | #if defined(LUA_DEBUG) 40 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 41 | LUAI_FUNC int luaH_isdummy (Node *n); 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with `fast' access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_DIV, 29 | TM_MOD, 30 | TM_POW, 31 | TM_UNM, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | #define ttypename(x) luaT_typenames_[(x) + 1] 47 | #define objtypename(x) ttypename(ttypenv(x)) 48 | 49 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 50 | 51 | 52 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 53 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 54 | TMS event); 55 | LUAI_FUNC void luaT_init (lua_State *L); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_BITLIBNAME "bit32" 33 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 34 | 35 | #define LUA_MATHLIBNAME "math" 36 | LUAMOD_API int (luaopen_math) (lua_State *L); 37 | 38 | #define LUA_DBLIBNAME "debug" 39 | LUAMOD_API int (luaopen_debug) (lua_State *L); 40 | 41 | #define LUA_LOADLIBNAME "package" 42 | LUAMOD_API int (luaopen_package) (lua_State *L); 43 | 44 | 45 | /* open all previous libraries */ 46 | LUALIB_API void (luaL_openlibs) (lua_State *L); 47 | 48 | 49 | 50 | #if !defined(lua_assert) 51 | #define lua_assert(x) ((void)0) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (lu_byte* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | /* data to catch conversion errors */ 23 | #define LUAC_TAIL "\x19\x93\r\n\x1a\n" 24 | 25 | /* size in bytes of header of binary files */ 26 | #define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL)) 19 | 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2)) 21 | 22 | #define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2) 23 | 24 | 25 | /* not to called directly */ 26 | LUAI_FUNC int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2); 27 | 28 | 29 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 30 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 31 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 32 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 33 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 34 | StkId val); 35 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 36 | StkId val); 37 | LUAI_FUNC void luaV_finishOp (lua_State *L); 38 | LUAI_FUNC void luaV_execute (lua_State *L); 39 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 40 | LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb, 41 | const TValue *rc, TMS op); 42 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) 29 | return EOZ; 30 | z->n = size - 1; /* discount char being returned */ 31 | z->p = buff; 32 | return cast_uchar(*(z->p++)); 33 | } 34 | 35 | 36 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 37 | z->L = L; 38 | z->reader = reader; 39 | z->data = data; 40 | z->n = 0; 41 | z->p = NULL; 42 | } 43 | 44 | 45 | /* --------------------------------------------------------------- read --- */ 46 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 47 | while (n) { 48 | size_t m; 49 | if (z->n == 0) { /* no bytes in buffer? */ 50 | if (luaZ_fill(z) == EOZ) /* try to read more */ 51 | return n; /* no more input; return number of missing bytes */ 52 | else { 53 | z->n++; /* luaZ_fill consumed first byte; put it back */ 54 | z->p--; 55 | } 56 | } 57 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 58 | memcpy(b, z->p, m); 59 | z->n -= m; 60 | z->p += m; 61 | b = (char *)b + m; 62 | n -= m; 63 | } 64 | return 0; 65 | } 66 | 67 | /* ------------------------------------------------------------------------ */ 68 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 69 | if (n > buff->buffsize) { 70 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 71 | luaZ_resizebuffer(L, buff, n); 72 | } 73 | return buff->buffer; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua-5.2.3/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 36 | 37 | 38 | #define luaZ_resizebuffer(L, buff, size) \ 39 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 40 | (buff)->buffsize = size) 41 | 42 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 43 | 44 | 45 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 46 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 47 | void *data); 48 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 49 | 50 | 51 | 52 | /* --------- Private Part ------------------ */ 53 | 54 | struct Zio { 55 | size_t n; /* bytes still unread */ 56 | const char *p; /* current position in buffer */ 57 | lua_Reader reader; /* reader function */ 58 | void* data; /* additional data */ 59 | lua_State *L; /* Lua state (for reader) */ 60 | }; 61 | 62 | 63 | LUAI_FUNC int luaZ_fill (ZIO *z); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua_include.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // Lua脚本引擎 19 | // 20 | 21 | #ifndef SCRIPTENGINE_LUA_INCLUDE_HPP_ 22 | #define SCRIPTENGINE_LUA_INCLUDE_HPP_ 23 | 24 | //#ifndef LUABIND_CPLUSPLUS_LUA 25 | extern "C" { 26 | //#endif 27 | #include "nebula/scriptengine/lua-5.2.3/src/lua.h" 28 | #include "nebula/scriptengine/lua-5.2.3/src/lauxlib.h" 29 | #include "nebula/scriptengine/lua-5.2.3/src/lualib.h" 30 | // #include "lua.h" 31 | // #include "lauxlib.h" 32 | //#ifndef LUABIND_CPLUSPLUS_LUA 33 | } 34 | //#endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /nebula/scriptengine/lua_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef SCRIPTENGINE_LUA_UTIL_H_ 19 | #define SCRIPTENGINE_LUA_UTIL_H_ 20 | 21 | // Lua脚本引擎 22 | // 23 | 24 | //get rid of the annoying but unavoidable forcing int to bool warning 25 | #pragma warning (disable:4800) 26 | 27 | #include "nebula/scriptengine/lua_include.hpp" 28 | //#include "base/logging.h" 29 | 30 | //这里有一个有用的帮助函数,它dump整个堆栈的内容: 31 | void LuaDumpStackHelper (lua_State* L); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /nebula/scriptengine/luabind_register_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef SCRIPTENGINE_LUABIND_REGISTER_PB_H_ 19 | #define SCRIPTENGINE_LUABIND_REGISTER_PB_H_ 20 | 21 | #include 22 | #include "nebula/base/linked_map.h" 23 | 24 | struct lua_State; 25 | typedef void (*LuabindRegister_Func)(lua_State* L); 26 | 27 | typedef std::vector LuabindRegisterFuncList; 28 | typedef base::linked_map LuabindRegisterFuncListMap; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample1.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample1.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample1.lua -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample2.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample2.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample2.lua -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample3.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample3.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample3.lua -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample4.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample4.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample4.lua -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample5.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample5.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample5.lua -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample6.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample6.cpp -------------------------------------------------------------------------------- /nebula/scriptengine/luatinker/sample6.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/nebula/scriptengine/luatinker/sample6.lua -------------------------------------------------------------------------------- /nebula/scriptengine/scriptengine_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(/usr/local/include ../..) 18 | 19 | set (TEST_LIST 20 | scriptegine_test.cc 21 | ) 22 | 23 | add_executable (scriptegine_test ${TEST_LIST}) 24 | target_link_libraries (scriptegine_test script_engine base) 25 | 26 | -------------------------------------------------------------------------------- /nebula/zorm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(../) 18 | 19 | set (SRC_LIST 20 | zorm_template.cc 21 | zorm_template.h 22 | ) 23 | 24 | add_executable (zorm ${SRC_LIST}) 25 | target_link_libraries (zorm storage base) 26 | 27 | -------------------------------------------------------------------------------- /proto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016, https://github.com/nebula-im/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | set (PROTO_SRC_LIST 18 | mtproto/core/mtproto_message.cc 19 | mtproto/core/mtproto_message.h 20 | mtproto/core/tl_codec_util.cc 21 | mtproto/core/tl_types.h 22 | mtproto/core/tl_codec_util.cc 23 | mtproto/core/tl_codec_util.h 24 | mtproto/core/tl_object.cc 25 | mtproto/core/tl_object.h 26 | mtproto/core/tl_bool.h 27 | mtproto/core/tl_null.h 28 | mtproto/core/tl_error.h 29 | mtproto/core/tl_vector.cc 30 | mtproto/core/tl_vector.h 31 | mtproto/core/mtproto_api_message_box.h 32 | mtproto/core/mtproto_api_message_box2.h 33 | mtproto/core/mtproto_schema.cc 34 | mtproto/core/mtproto_schema.h 35 | mtproto/schema.tl.cc 36 | mtproto/schema.tl.h 37 | mtproto/core/auth_key_manager.cc 38 | mtproto/core/auth_key_manager.h 39 | mtproto/scheme/scheme.tl 40 | mtproto/scheme/generate.py 41 | ) 42 | 43 | add_library(proto STATIC ${PROTO_SRC_LIST}) 44 | target_link_libraries(proto protobuf) 45 | 46 | #add_subdirectory(base/test) 47 | -------------------------------------------------------------------------------- /proto/api/error_codes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_ERROR_CODES_H_ 19 | #define PROTO_ERROR_CODES_H_ 20 | 21 | const int kErrOK = 0; 22 | 23 | const int kErrDBError = 1000; // DB无法连接 24 | const int kErrDBConn = 1001; // DB无法连接 25 | const int kErrDBSql = 1002; // SQL非法 26 | const int kErrDBData = 1003; // QueryAnswer解析有问题 27 | const int kErrDBDup = 1004; // QueryAnswer解析有问题 28 | 29 | const int kErrNotImpl = 1100; // QueryAnswer解析有问题 30 | 31 | /* 32 | 303 33 | 500 34 | 420 35 | 400 36 | 401 37 | */ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /proto/api/proto/README.md: -------------------------------------------------------------------------------- 1 | # api协议 2 | > 参考telegram/actor/teamtalk等协议 3 | 4 | -------------------------------------------------------------------------------- /proto/api/proto/api_method_ids.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoMethodIDs"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | enum ApiMethodIDs { 26 | API_UNKNOWN = 0; 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /proto/api/proto/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | SRC_DIR=./ 3 | DST_DIR=.. 4 | 5 | #C++ 6 | #mkdir -p $DST_DIR/cpp 7 | protoc -I=$SRC_DIR --cpp_out=$DST_DIR/cc/ $SRC_DIR/*.proto 8 | 9 | #JAVA 10 | #mkdir -p $DST_DIR/java 11 | #protoc -I=$SRC_DIR --java_out=$DST_DIR/java/ $SRC_DIR/*.proto 12 | 13 | #PYTHON 14 | #mkdir -p $DST_DIR/python 15 | #protoc -I=$SRC_DIR --python_out=$DST_DIR/python/ $SRC_DIR/*.proto 16 | 17 | -------------------------------------------------------------------------------- /proto/api/proto/check_method_types.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/proto/api/proto/check_method_types.py -------------------------------------------------------------------------------- /proto/api/proto/configs.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoConfigs"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Config sync 26 | 27 | // Parameter Syncronization across devices. Can be used for simple sync 28 | // across devices without rewriting server side code. 29 | 30 | // Syncing Parameter 31 | message Parameter { 32 | string key = 1; // Key of parameter 33 | string value = 2; // Value of parameter 34 | } 35 | 36 | // Getting Parameters 37 | // GetParametersReq --> GetParametersRsp 38 | message GetParametersReq { 39 | // int32 COMMAND_ID = 134; 40 | } 41 | 42 | message GetParametersRsp { 43 | // int32 COMMAND_ID = 135; 44 | repeated Parameter parameters = 1; // Current parameters 45 | } 46 | 47 | // Change parameter value 48 | // EditParameterReq --> SeqRsp 49 | message EditParameterReq { 50 | // int32 COMMAND_ID = 128; 51 | string key = 1; // Key of parameter 52 | string value = 2; // Value of parameter 53 | } 54 | 55 | // SeqRsp 56 | 57 | // Update about parameter change 58 | message ParameterChangedNotify { 59 | // int32 COMMAND_ID = 131; 60 | string key = 1; // Key of parameter 61 | string value = 2; // Value of parameter 62 | } 63 | 64 | -------------------------------------------------------------------------------- /proto/api/proto/counters.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoCounters"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Counters 26 | 27 | // Application Counters, used to display various counters in application 28 | 29 | // Application counters 30 | message AppCounters { 31 | int32 global_counter = 1; // Global unread counter 32 | } 33 | 34 | // Update about counters changed 35 | message CountersChangedNotify { 36 | // int32 COMMAND_ID = 215; 37 | AppCounters counters = 1; // Current Application counters 38 | } 39 | 40 | -------------------------------------------------------------------------------- /proto/api/proto/device.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoDevice"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Device Info 26 | 27 | // Submiting various information about device for providing better experience. 28 | // For example, getting timezone or preffered languages 29 | 30 | // Notifying about device information 31 | // NotifyAboutDeviceInfoReq --> VoidRsp 32 | message NotifyAboutDeviceInfoReq { 33 | // int32 COMMAND_ID = 229; 34 | repeated string preferred_languages = 1; // Preferred languages 35 | string time_zone = 2; // Device Time Zone 36 | } 37 | 38 | // VoidRsp 39 | 40 | -------------------------------------------------------------------------------- /proto/api/proto/files.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoFiles"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Media and Files 26 | 27 | // Location of file on server 28 | message FileLocation { 29 | int64 file_id = 1; // Unique Id of file 30 | int64 access_hash = 2; // Access hash of file 31 | } 32 | 33 | // Avatar Image 34 | message AvatarImage { 35 | FileLocation file_location = 1; // Location of file 36 | int32 width = 2; // Width of avatar image 37 | int32 height = 3; // Height of avatar image 38 | int32 file_size = 4; // Size of file 39 | } 40 | 41 | // Avatar of User or Group 42 | message Avatar { 43 | AvatarImage small_image = 1; // Optional small image of avatar box in 100x100 44 | AvatarImage large_image = 2; // Optional large image of avatar box in 200x200 45 | AvatarImage full_image = 3; // Optional full screen image of avatar 46 | } 47 | -------------------------------------------------------------------------------- /proto/api/proto/invites.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoInvites"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "users.proto"; 26 | import "group_base.proto"; 27 | 28 | // Invites 29 | 30 | // Invite mechanizm 31 | 32 | // Invite state 33 | message InviteState { 34 | string email = 1; // Email of invite 35 | string name = 2; // Name of invited user 36 | int32 uid = 3; // Uid of registered user 37 | int32 tid = 4; // Team id of invite 38 | } 39 | 40 | // Intites list 41 | message InviteListRsp { 42 | // int32 COMMAND_ID = 2564; 43 | repeated InviteState invites = 1; // Intvites 44 | repeated User related_users = 2; // Related users in invites 45 | repeated Group related_groups = 3; // Related groups in invites 46 | } 47 | 48 | // Loading current invite states 49 | // LoadOwnSentInvitesReq --> InviteListRsp 50 | message LoadOwnSentInvitesReq { 51 | // int32 COMMAND_ID = 2563; 52 | } 53 | 54 | // InviteListRsp 55 | 56 | // Sending an email invite 57 | // SendInviteReq --> InviteListRsp 58 | message SendInviteReq { 59 | // int32 COMMAND_ID = 2565; 60 | string email = 1; // Email for invite 61 | string name = 2; // Optional name for invite 62 | } 63 | 64 | // InviteListRsp 65 | 66 | -------------------------------------------------------------------------------- /proto/api/proto/messaging_base.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoMessaging"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "peers.proto"; 26 | import "group_base.proto"; 27 | 28 | // 消息类型 29 | enum MessageType { 30 | TEXT = 0; 31 | AUDIO = 1; 32 | VIDEO = 2; 33 | // ...... 34 | } 35 | 36 | // 消息 37 | message InstantMessage { 38 | MessageType message_type = 1; 39 | bytes message_data = 2; 40 | } 41 | 42 | // MessageState 43 | enum MessageState { 44 | SENT = 0; 45 | RECEIVED = 1; 46 | READ = 2; 47 | } 48 | 49 | // Message from history 50 | message MessageContainer { 51 | string sender_uid = 1; // Sender of mesasge 52 | int64 rid = 2; // Random Id of message 53 | int64 date = 3; // Date of message 54 | InstantMessage message = 5; // Content of message 55 | MessageState state = 6; 56 | } 57 | 58 | // ListLoadMode 59 | enum ListLoadMode { 60 | FORWARD = 0; 61 | BACKWARD = 1; 62 | BOTH = 2; 63 | } 64 | -------------------------------------------------------------------------------- /proto/api/proto/peers.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoPeers"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Peers 26 | 27 | // Peer is an identificator of specific conversation. 28 | 29 | // PeerType 30 | enum PeerType { 31 | PEER_TYPE_PRIVATE = 0; 32 | PEER_TYPE_GROUP = 1; 33 | PEER_TYPE_ENCRYPTED_PRIVATE = 2; 34 | } 35 | 36 | // Peer 37 | message Peer { 38 | PeerType type = 1; // Peer Type 39 | string id = 2; // Peer Id 40 | } 41 | 42 | // Out peer with access hash 43 | message OutPeer { 44 | PeerType type = 1; // Peer Type 45 | string id = 2; // Peer Id 46 | int64 access_hash = 3; // Peer access hash 47 | } 48 | 49 | // User's out peer 50 | message UserOutPeer { 51 | string uid = 1; // User's id 52 | int64 access_hash = 2; // User's access hash 53 | } 54 | 55 | // Group's out peer 56 | message GroupOutPeer { 57 | string group_id = 1; // Group's Id 58 | int64 access_hash = 2; // Group's access hash 59 | } 60 | 61 | -------------------------------------------------------------------------------- /proto/api/proto/privacy.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoPrivacy"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "peers.proto"; 26 | 27 | // Privacy 28 | 29 | // Block User 30 | // BlockUserReq --> SeqRsp 31 | message BlockUserReq { 32 | // int32 COMMAND_ID = 2636; 33 | UserOutPeer peer = 1; // Peer for blocking 34 | } 35 | 36 | // SeqRsp 37 | 38 | // Unblock User 39 | // UnblockUserReq --> SeqRsp 40 | message UnblockUserReq { 41 | // int32 COMMAND_ID = 2637; 42 | UserOutPeer peer = 1; // Peer for unblocking 43 | } 44 | 45 | // SeqRsp 46 | 47 | // Load Blocked Users 48 | // LoadBlockedUsersReq --> LoadBlockedUsersRsp 49 | message LoadBlockedUsersReq { 50 | // int32 COMMAND_ID = 2638; 51 | } 52 | 53 | message LoadBlockedUsersRsp { 54 | // int32 COMMAND_ID = 2639; 55 | repeated UserOutPeer user_peers = 1; // Blocked user peers 56 | } 57 | 58 | // Update about User Blocked 59 | message UserBlockedNotify { 60 | // int32 COMMAND_ID = 2629; 61 | int32 uid = 1; // User Id 62 | } 63 | 64 | // Update about User Unblocked 65 | message UserUnblockedNotify { 66 | // int32 COMMAND_ID = 2630; 67 | int32 uid = 1; // User Id 68 | } 69 | 70 | -------------------------------------------------------------------------------- /proto/api/proto/stats.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoStats"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "types.proto"; 26 | 27 | // Stats 28 | 29 | // Saving statistics information 30 | 31 | // Record for stored event 32 | message EventRecord { 33 | int64 date = 1; 34 | Event event = 2; 35 | } 36 | 37 | message Event { 38 | } 39 | 40 | // Untyped event 41 | message UntypedEvent { 42 | string event_type = 1; // Event type 43 | RawArrayValue params = 2; // optional params for event 44 | } 45 | 46 | // Content view event 47 | message ContentViewChanged { 48 | string content_type = 1; // unique content id 49 | string content_id = 2; 50 | bool visible = 3; // Is content visible 51 | RawArrayValue params = 4; // optional params for content view 52 | } 53 | 54 | // On App Visible event 55 | message AppVisibleChanged { 56 | bool visible = 1; // Is app visible 57 | } 58 | 59 | // Storing events on server 60 | // StoreEventsReq --> VoidRsp 61 | message StoreEventsReq { 62 | // int32 COMMAND_ID = 243; 63 | repeated Event events = 1; // Events for storing 64 | } 65 | 66 | // VoidRsp 67 | 68 | -------------------------------------------------------------------------------- /proto/api/proto/users.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoUsers"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "types.proto"; 26 | import "files.proto"; 27 | 28 | // Users 29 | 30 | // Main user object 31 | message User { 32 | string uid = 1; // uid 33 | int64 access_hash = 2; // user's access hash 34 | } 35 | 36 | message PushUser { 37 | string uid = 1; // uid 38 | int64 access_hash = 2; // user's access hash 39 | 40 | string push_name = 3; // 推送显示名 41 | Avatar push_avatar = 5; // 推送头像 42 | } 43 | 44 | //message User { 45 | // string open_id; // openid 46 | // uint32 access_hash = 2; // acess_hash 47 | //} 48 | 49 | -------------------------------------------------------------------------------- /proto/mtproto/core/auth_key_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_MTPROTO_CORE_AUTH_KEY_MANAGER_H_ 19 | #define PROTO_MTPROTO_CORE_AUTH_KEY_MANAGER_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "proto/mtproto/core/tl_types.h" 25 | 26 | namespace mtproto { 27 | 28 | class AuthKeyManager { 29 | public: 30 | ~AuthKeyManager() = default; 31 | 32 | static std::shared_ptr GetInstance(); 33 | 34 | std::shared_ptr FindAuthKey(int64_t auth_key_id) const; 35 | void SetAuthKey(const std::shared_ptr& auth_key, int64_t auth_key_id); 36 | 37 | protected: 38 | friend class folly::Singleton; 39 | 40 | AuthKeyManager(); 41 | 42 | std::map> auth_key_manager_; 43 | }; 44 | 45 | } 46 | 47 | #endif // PROTO_MTPROTO_CORE_AUTH_KEY_MANAGER_H_ 48 | -------------------------------------------------------------------------------- /proto/mtproto/core/mtproto_message_register.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | #include "proto/telegram/core/mtproto_message_factory.h" 20 | 21 | #include "proto/telegram/schema.tl.h" 22 | 23 | // namespace { 24 | 25 | REGISTER_MTPROTO_MESSAGE(TL_req_pq, 0x60469778); 26 | 27 | // } 28 | 29 | */ 30 | -------------------------------------------------------------------------------- /proto/mtproto/core/tl_codec_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_MTPROTO_CORE_TL_CODEC_UTIL_H 19 | #define PROTO_MTPROTO_CORE_TL_CODEC_UTIL_H 20 | 21 | #include "nebula/base/io_buf_util.h" 22 | 23 | #include "proto/mtproto/core/tl_types.h" 24 | 25 | namespace mtproto { 26 | 27 | template 28 | inline size_t CalcObjSize(const T& t) { 29 | return t.size(); 30 | } 31 | 32 | bool ReadString(IOBufReader& iobr, TLString* data); 33 | bool WriteString(IOBufWriter& iobw, const TLString& data); 34 | template<> size_t CalcObjSize(const TLString& t); 35 | 36 | template 37 | inline bool ReadTLIntN(IOBufReader& iobr, TLIntN* data) { 38 | iobr.pull(data->data, N); 39 | return true; 40 | } 41 | 42 | template 43 | inline bool WriteTLIntN(IOBufWriter& iobw, const TLIntN& data) { 44 | iobw.push(data.data, N); 45 | return true; 46 | } 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /proto/mtproto/core/tl_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_MTPROTO_CORE_TL_BOOL_H 19 | #define PROTO_MTPROTO_CORE_TL_BOOL_H 20 | 21 | #include "proto/mtproto/core/object.h" 22 | 23 | namespace mtproto { 24 | 25 | // True 26 | class Error : public TLObject { 27 | public: 28 | virtual ~Error() override = default; 29 | }; 30 | 31 | // error#c4b9f9bb code:int text:string = Error; 32 | class TL_error: public Error { 33 | public: 34 | enum { 35 | CLASS_ID = 0xc4b9f9bb, 36 | }; 37 | 38 | // static const TLClassID CLASS_ID = 0xc4b9f9bb; 39 | 40 | uint32_t GetClassID() const override { 41 | return CLASS_ID; 42 | } 43 | 44 | std::string ToString() const override { 45 | return "error#c4b9f9bb"; 46 | } 47 | 48 | protected: 49 | bool Decode(IOBufReader& iobr) override { 50 | code_ = iobr.readLE(); 51 | ReadString(iobr, &text_); 52 | return true; 53 | } 54 | 55 | bool Encode(IOBufWriter& iobw) const override { 56 | iobw.writeLE(code_); 57 | WriteString(iobw, text_); 58 | return true; 59 | } 60 | 61 | private: 62 | int32_t code_; 63 | TLString text_; 64 | }; 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /proto/mtproto/core/tl_null.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_MTPROTO_CORE_TL_NULL_H 19 | #define PROTO_MTPROTO_CORE_TL_NULL_H 20 | 21 | #include "proto/mtproto/core/object.h" 22 | 23 | namespace mtproto { 24 | 25 | // True 26 | class Null : public TLObject { 27 | public: 28 | virtual ~Null() override = default; 29 | }; 30 | 31 | // null#56730bcc = Null; 32 | class TL_null: public Null { 33 | public: 34 | enum { 35 | CLASS_ID = 0x56730bcc, 36 | }; 37 | 38 | // static const TLClassID CLASS_ID = 0x56730bcc; 39 | 40 | uint32_t GetClassID() const override { 41 | return CLASS_ID; 42 | } 43 | 44 | std::string ToString() const override { 45 | return "null#56730bcc"; 46 | } 47 | 48 | protected: 49 | bool Decode(IOBufReader& iobr) override { 50 | return true; 51 | } 52 | 53 | bool Encode(IOBufWriter& iobw) const override { 54 | return true; 55 | } 56 | }; 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /proto/mtproto/core/tl_vector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "proto/mtproto/core/tl_vector.h" 19 | 20 | using namespace mtproto; 21 | 22 | void Test() { 23 | class A : public TLObject { 24 | public: 25 | virtual TLClassID GetClassID() const { 26 | return 0; 27 | } 28 | ~A() {} 29 | }; 30 | 31 | // TLObjectVector a; 32 | 33 | TLObjectVector b; 34 | } 35 | -------------------------------------------------------------------------------- /proto/mtproto/scheme/a/service_impl.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /proto/mtproto/scheme/a/service_impl.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /proto/mtproto/scheme/a/zrpc_service.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | int payments_clearSavedInfo(const mtproto::TL_payments_clearSavedInfo& request, std::shared_ptr& response) { 7 | LOG(ERROR) << "payments_clearSavedInfo not impl"; 8 | return kErrNotImpl; 9 | } 10 | 11 | int payments_getPaymentForm(const mtproto::TL_payments_getPaymentForm& request, std::shared_ptr& response) { 12 | LOG(ERROR) << "payments_getPaymentForm not impl"; 13 | return kErrNotImpl; 14 | } 15 | 16 | int payments_getPaymentReceipt(const mtproto::TL_payments_getPaymentReceipt& request, std::shared_ptr& response) { 17 | LOG(ERROR) << "payments_getPaymentReceipt not impl"; 18 | return kErrNotImpl; 19 | } 20 | 21 | int payments_getSavedInfo(const mtproto::TL_payments_getSavedInfo& request, std::shared_ptr& response) { 22 | LOG(ERROR) << "payments_getSavedInfo not impl"; 23 | return kErrNotImpl; 24 | } 25 | 26 | int payments_sendPaymentForm(const mtproto::TL_payments_sendPaymentForm& request, std::shared_ptr& response) { 27 | LOG(ERROR) << "payments_sendPaymentForm not impl"; 28 | return kErrNotImpl; 29 | } 30 | 31 | int payments_validateRequestedInfo(const mtproto::TL_payments_validateRequestedInfo& request, std::shared_ptr& response) { 32 | LOG(ERROR) << "payments_validateRequestedInfo not impl"; 33 | return kErrNotImpl; 34 | } 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /proto/mtproto/scheme/a/zrpc_service.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /proto/s2s/proto/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | SRC_DIR=./ 3 | DST_DIR=.. 4 | 5 | #C++ 6 | #mkdir -p $DST_DIR/cpp 7 | protoc -I=$SRC_DIR --cpp_out=$DST_DIR/cc/ $SRC_DIR/*.proto 8 | 9 | #JAVA 10 | #mkdir -p $DST_DIR/java 11 | #protoc -I=$SRC_DIR --java_out=$DST_DIR/java/ $SRC_DIR/*.proto 12 | 13 | #PYTHON 14 | #mkdir -p $DST_DIR/python 15 | #protoc -I=$SRC_DIR --python_out=$DST_DIR/python/ $SRC_DIR/*.proto 16 | 17 | -------------------------------------------------------------------------------- /proto/s2s/proto/servers.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProtoServers"; 24 | option optimize_for = CODE_SIZE; 25 | 26 | // import "messaging_base.proto"; 27 | // import "misc.proto"; 28 | 29 | /////////////////////////////////////////////////////////////////////// 30 | // server_auth 31 | // SERVER_AUTH_REQ 32 | message ServerAuthReq { 33 | uint32 server_id = 1; 34 | string server_name = 2; 35 | } 36 | 37 | // SERVER_AUTH_RSP 38 | message ServerAuthRsp { 39 | } 40 | 41 | // 42 | message DeliveryDataToUsersReq { 43 | uint64 my_conn_id = 1; 44 | repeated string uid_list = 2; 45 | uint32 raw_data_header = 4; 46 | bytes raw_data = 5; 47 | } 48 | 49 | // VoidRsp 50 | -------------------------------------------------------------------------------- /proto/zproto/go/biz_servers.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: biz_servers.proto 3 | 4 | package zproto 5 | 6 | import proto "github.com/golang/protobuf/proto" 7 | import fmt "fmt" 8 | import math "math" 9 | 10 | // Reference imports to suppress errors if they are not otherwise used. 11 | var _ = proto.Marshal 12 | var _ = fmt.Errorf 13 | var _ = math.Inf 14 | 15 | func init() { proto.RegisterFile("biz_servers.proto", fileDescriptor2) } 16 | 17 | var fileDescriptor2 = []byte{ 18 | // 82 bytes of a gzipped FileDescriptorProto 19 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0xca, 0xac, 0x8a, 20 | 0x2f, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x2a, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xab, 21 | 0x02, 0xd3, 0x4e, 0xca, 0x5c, 0xe2, 0xc9, 0xf9, 0xb9, 0x7a, 0x55, 0xc9, 0x19, 0x89, 0x25, 0x7a, 22 | 0xa9, 0x79, 0xe9, 0x99, 0x79, 0xa9, 0x7a, 0x50, 0x29, 0xb6, 0xa8, 0x00, 0x10, 0xed, 0xc1, 0x94, 23 | 0xc4, 0x06, 0x16, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb4, 0xd3, 0xd7, 0x6d, 0x48, 0x00, 24 | 0x00, 0x00, 25 | } 26 | -------------------------------------------------------------------------------- /proto/zproto/go/files.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: files.proto 3 | 4 | package zproto 5 | 6 | import proto "github.com/golang/protobuf/proto" 7 | import fmt "fmt" 8 | import math "math" 9 | 10 | // Reference imports to suppress errors if they are not otherwise used. 11 | var _ = proto.Marshal 12 | var _ = fmt.Errorf 13 | var _ = math.Inf 14 | 15 | func init() { proto.RegisterFile("files.proto", fileDescriptor3) } 16 | 17 | var fileDescriptor3 = []byte{ 18 | // 76 bytes of a gzipped FileDescriptorProto 19 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0xcb, 0xcc, 0x49, 20 | 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xab, 0x02, 0xd3, 0x4e, 0xca, 0x5c, 0xe2, 21 | 0xc9, 0xf9, 0xb9, 0x7a, 0x55, 0xc9, 0x19, 0x89, 0x25, 0x7a, 0xa9, 0x79, 0xe9, 0x99, 0x79, 0xa9, 22 | 0x7a, 0x50, 0x29, 0xb6, 0xa8, 0x00, 0x10, 0xed, 0xc1, 0x94, 0xc4, 0x06, 0x16, 0x30, 0x06, 0x04, 23 | 0x00, 0x00, 0xff, 0xff, 0x98, 0xe7, 0x9d, 0x74, 0x42, 0x00, 0x00, 0x00, 24 | } 25 | -------------------------------------------------------------------------------- /proto/zproto/proto/auths.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProto"; 24 | option optimize_for = CODE_SIZE; 25 | 26 | message UserTokenAuthReq { 27 | string app_key = 1; 28 | string user_id = 2; 29 | string user_token = 3; 30 | 31 | // uint64 client_time = 4; 32 | } 33 | 34 | // 服务器和客户端对时 35 | message UserTokenAuthRsp { 36 | // uint64 client_time = 1; 37 | // uint64 server_time = 2; 38 | uint32 app_id = 1; 39 | string user_id = 2; 40 | string nick = 3; 41 | string avatar = 4; 42 | } 43 | -------------------------------------------------------------------------------- /proto/zproto/proto/biz_servers.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProto"; 24 | option optimize_for = CODE_SIZE; 25 | 26 | -------------------------------------------------------------------------------- /proto/zproto/proto/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | SRC_DIR=./ 3 | DST_DIR=.. 4 | 5 | #C++ 6 | #mkdir -p $DST_DIR/cpp 7 | protoc -I=$SRC_DIR --cpp_out=$DST_DIR/cc/ $SRC_DIR/*.proto 8 | 9 | #GO 10 | protoc -I=$SRC_DIR --go_out=$DST_DIR/go/ $SRC_DIR/*.proto 11 | 12 | #JAVA 13 | #mkdir -p $DST_DIR/java 14 | #protoc -I=$SRC_DIR --java_out=$DST_DIR/java/ $SRC_DIR/*.proto 15 | 16 | #PYTHON 17 | #mkdir -p $DST_DIR/python 18 | #protoc -I=$SRC_DIR --python_out=$DST_DIR/python/ $SRC_DIR/*.proto 19 | 20 | -------------------------------------------------------------------------------- /proto/zproto/proto/check_method_types.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleke/nebula/aa0ee2e6bd3913f776baad3726e59811f223dee7/proto/zproto/proto/check_method_types.py -------------------------------------------------------------------------------- /proto/zproto/proto/files.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProto"; 24 | option optimize_for = CODE_SIZE; 25 | -------------------------------------------------------------------------------- /proto/zproto/proto/peers.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoPeers"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | // Peers 26 | 27 | // Peer is an identificator of specific conversation. 28 | 29 | // PeerType 30 | enum PeerType { 31 | PRIVATE = 0; 32 | GROUP = 1; 33 | ENCRYPTED_PRIVATE = 2; 34 | } 35 | 36 | // Peer 37 | message Peer { 38 | PeerType type = 1; // Peer Type 39 | string id = 2; // Peer Id 40 | } 41 | 42 | // Out peer with access hash 43 | message OutPeer { 44 | PeerType type = 1; // Peer Type 45 | string id = 2; // Peer Id 46 | uint64 access_hash = 3; // Peer access hash 47 | } 48 | 49 | // User's out peer 50 | message UserOutPeer { 51 | string uid = 1; // User's id 52 | uint64 access_hash = 2; // User's access hash 53 | } 54 | 55 | // Group's out peer 56 | message GroupOutPeer { 57 | string group_id = 1; // Group's Id 58 | uint64 access_hash = 2; // Group's access hash 59 | } 60 | 61 | -------------------------------------------------------------------------------- /proto/zproto/proto/presences.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/wubenqi 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | package zproto; 20 | 21 | option java_package = "com.zchat.engine.zproto"; 22 | option java_outer_classname = "ZProtoPresences"; 23 | option optimize_for = CODE_SIZE; 24 | 25 | import "bases.proto"; 26 | 27 | // Presences 28 | 29 | /////////////////////////////////////////////////////////////////////// 30 | // online 31 | // ClientOnlineReq -> VoidRsp 32 | message ClientOnlineReq { 33 | uint32 server_id = 1; 34 | uint64 conn_id = 2; 35 | uint32 app_id = 3; 36 | string user_id = 4; 37 | uint32 state = 5; 38 | } 39 | 40 | // CLIENT_ONLINE_RSP 41 | message ClientOnlineRsp { 42 | uint64 index_id = 1; 43 | } 44 | 45 | // ClientOfflineReq 46 | message ClientOfflineReq { 47 | uint32 server_id = 1; 48 | uint64 conn_id = 2; 49 | } 50 | 51 | // CLIENT_OFFLINE_RSP 52 | message ClientOfflineRsp { 53 | uint64 index_id = 1; 54 | } 55 | 56 | // 57 | message QueryOnlineUserReq { 58 | repeated UserID user_id_list = 1; 59 | } 60 | 61 | // 62 | message QueryOnlineUserRsp { 63 | repeated OnlineUser online_users = 1; 64 | } 65 | -------------------------------------------------------------------------------- /proto/zproto/proto/servers.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package zproto; 21 | 22 | option java_package = "com.zchat.engine.zproto"; 23 | option java_outer_classname = "ZProto"; 24 | option optimize_for = CODE_SIZE; 25 | 26 | /////////////////////////////////////////////////////////////////////// 27 | // server_auth 28 | // SERVER_AUTH_REQ 29 | message ServerAuthReq { 30 | uint32 server_id = 1; 31 | string server_name = 2; 32 | } 33 | 34 | // SERVER_AUTH_RSP 35 | message ServerAuthRsp { 36 | } 37 | 38 | -------------------------------------------------------------------------------- /proto/zproto/zproto_api_message_types.h2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, https://github.com/nebula-im 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef PROTO_ZPROTO_API_MESSAGE_TYPES_H_ 19 | #define PROTO_ZPROTO_API_MESSAGE_TYPES_H_ 20 | 21 | #include "proto/zproto/cc/auths.pb.h" 22 | #include "proto/zproto/cc/servers.pb.h" 23 | #include "proto/zproto/cc/groups.pb.h" 24 | #include "proto/zproto/cc/messages.pb.h" 25 | #include "proto/zproto/cc/presences.pb.h" 26 | 27 | #include "nebula/net/zproto/api_message_box.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /relay/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, https://github.com/nebulaim/nebula 2 | # All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | include_directories(. ..) 18 | 19 | set (SRC_LIST 20 | relay_server.cc 21 | relay_server.h 22 | tgvoip_handler.cc 23 | tgvoip_handler.h 24 | relay_table.cc 25 | relay_table.h 26 | ) 27 | 28 | add_executable (relay ${SRC_LIST}) 29 | target_link_libraries (relay net base) 30 | -------------------------------------------------------------------------------- /relay/README.md: -------------------------------------------------------------------------------- 1 | # telegram voip relay server. 2 | -------------------------------------------------------------------------------- /relay/relay_server.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, https://github.com/nebulaim/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "relay/relay_server.h" 19 | 20 | #include "nebula/net/base_server.h" 21 | #include "nebula/base/config_manager.h" 22 | #include "nebula/net/net_engine_manager.h" 23 | #include "nebula/net/handler/module_install.h" 24 | 25 | #include "relay/tgvoip_handler.h" 26 | 27 | bool RelayServer::Initialize() { 28 | // 注册服务 29 | // 客户端连接服务 30 | RegisterService("relay_server", "udp_server", "tgvoip"); 31 | return nebula::BaseServer::Initialize(); 32 | } 33 | 34 | bool RelayServer::Run() { 35 | nebula::BaseServer::Run(); 36 | return true; 37 | } 38 | 39 | void RelayServer::InstallModule() { 40 | ModuleUdpTGVoipInitialize(); 41 | } 42 | 43 | ///////////////////////////////////////////////////////////////////////////////////////// 44 | int main(int argc, char* argv[]) { 45 | return nebula::DoMain(argc, argv); 46 | } 47 | -------------------------------------------------------------------------------- /relay/relay_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, https://github.com/nebulaim/nebula 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef RELAY_RELAY_SERVER_H_ 19 | #define RELAY_RELAY_SERVER_H_ 20 | 21 | #include 22 | #include "nebula/net/base_server.h" 23 | 24 | class RelayServer : public nebula::BaseServer { 25 | public: 26 | RelayServer() = default; 27 | ~RelayServer() override = default; 28 | 29 | protected: 30 | // From BaseServer 31 | bool Initialize() override; 32 | bool Run() override; 33 | void InstallModule() override; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /third_party/folly: -------------------------------------------------------------------------------- 1 | /Users/benqi/Desktop/facebook/facebook/folly/folly -------------------------------------------------------------------------------- /third_party/proxygen: -------------------------------------------------------------------------------- 1 | /Users/benqi/Desktop/facebook/facebook/proxygen/proxygen -------------------------------------------------------------------------------- /third_party/wangle: -------------------------------------------------------------------------------- 1 | /Users/benqi/Desktop/facebook/facebook/wangle/wangle --------------------------------------------------------------------------------