diff --git a/airdcpp-core/CMakeLists.txt b/airdcpp-core/CMakeLists.txt index 018fcd2f..8a5b28cf 100644 --- a/airdcpp-core/CMakeLists.txt +++ b/airdcpp-core/CMakeLists.txt @@ -117,12 +117,13 @@ endif(NOT PYTHON_EXECUTABLE) if (NOT CMAKE_BUILD_TYPE STREQUAL Debug OR NOT EXISTS "${PROJECT_SOURCE_DIR}/airdcpp/core/version.inc") find_package (Git) - add_custom_target(version_file ALL DEPENDS + add_custom_target(version ALL DEPENDS COMMAND ${PYTHON_EXECUTABLE} scripts/generate_version.py ./airdcpp/core/version.inc ${VERSION} ${TAG_APPLICATION} ${APPLICATION_ID} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) - - add_dependencies(${PROJECT_NAME} version_file) + + list (PREPEND airdcpp_hdrs ${PROJECT_SOURCE_DIR}/airdcpp/core/version.inc) + add_dependencies(${PROJECT_NAME} version) endif () # Stringdefs @@ -137,7 +138,8 @@ add_custom_command( WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) -list (APPEND airdcpp_srcs ${PROJECT_SOURCE_DIR}/airdcpp/core/localization/StringDefs.cpp) +list (PREPEND airdcpp_srcs ${PROJECT_SOURCE_DIR}/airdcpp/core/localization/StringDefs.cpp) +add_dependencies(${PROJECT_NAME} stringdefs) # GENERIC COMPILING PROPERTIES diff --git a/airdcpp-core/airdcpp.vcxproj b/airdcpp-core/airdcpp.vcxproj deleted file mode 100644 index 805961b1..00000000 --- a/airdcpp-core/airdcpp.vcxproj +++ /dev/null @@ -1,664 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {F8D0E5FE-BABD-4FC8-B3FE-B48978D23FEB} - airdcpp - airdcpp-core - true - 10.0 - - - - StaticLibrary - true - v143 - Unicode - - - StaticLibrary - true - v143 - Unicode - - - StaticLibrary - false - v143 - true - Unicode - - - StaticLibrary - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - $(SolutionDir)compiled/ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)vc14\$(Platform)\$(Configuration)\$(ProjectName)\ - $(IncludePath) - $(IncludePath) - $(IncludePath) - $(SolutionDir)\windows\WTL;$(IncludePath) - false - true - - - true - - - true - - - true - - - true - - - true - - - - Disabled - $(ProjectDir);$(ProjectDir)\airdcpp;$(SolutionDir)\vcpkg_installed\x64-windows-static\x64-windows-static\include\natpmp;%(AdditionalIncludeDirectories) - EnableFastChecks - MultiThreadedDebug - Use - stdinc.h - $(IntDir)airdcpp.pch - Level4 - true - WIN64;HAVE_NATPMP_H;HAVE_WINUPNP_H;_UNICODE;UNICODE;HAS_PCH;%(PreprocessorDefinitions) - false - /permissive- %(AdditionalOptions) - stdcpp17 - - - $(OutDir)$(ProjectName).lib - true - - - - - X64 - - - Disabled - $(ProjectDir);$(ProjectDir)\airdcpp;$(SolutionDir)\vcpkg_installed\x64-windows-static\x64-windows-static\include\natpmp;%(AdditionalIncludeDirectories) - EnableFastChecks - MultiThreadedDebug - Use - stdinc.h - $(IntDir)airdcpp.pch - Level4 - true - WIN64;HAVE_NATPMP_H;HAVE_WINUPNP_H;_UNICODE;UNICODE;HAS_PCH;%(PreprocessorDefinitions) - true - false - /permissive- %(AdditionalOptions) - stdcpp20 - - - $(OutDir)$(ProjectName).lib - true - true - - - Generating revision number... - $(SolutionDir)\scripts\generate-version.bat $(SolutionDir) - - - - - Generating revision number... - $(SolutionDir)scripts\generate-version.bat $(SolutionDir) - - - Full - OnlyExplicitInline - true - Size - false - true - $(ProjectDir);$(ProjectDir)\airdcpp;$(SolutionDir)\vcpkg_installed\x64-windows-static\x64-windows-static\include\natpmp;%(AdditionalIncludeDirectories) - true - Sync - MultiThreaded - false - true - Fast - /permissive- - false - Use - stdinc.h - $(IntDir)airdcpp.pch - - - Level4 - true - ProgramDatabase - true - _UNICODE;UNICODE;HAVE_NATPMP_H;HAVE_WINUPNP_H;HAS_PCH;%(PreprocessorDefinitions) - stdcpp20 - - - $(OutDir)$(ProjectName).lib - true - - - - - Generating revision number... - $(SolutionDir)scripts\generate-version.bat $(SolutionDir) - - - X64 - - - Full - OnlyExplicitInline - true - Speed - false - true - $(ProjectDir);$(ProjectDir)\airdcpp;$(SolutionDir)\vcpkg_installed\x64-windows-static\x64-windows-static\include\natpmp;%(AdditionalIncludeDirectories) - true - Sync - MultiThreaded - false - true - Fast - /permissive- - false - Use - stdinc.h - $(IntDir)airdcpp.pch - - - Level4 - true - ProgramDatabase - true - WIN64;HAVE_NATPMP_H;HAVE_WINUPNP_H;_UNICODE;UNICODE;HAS_PCH;%(PreprocessorDefinitions) - stdcpp20 - - - $(OutDir)$(ProjectName).lib - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create - Create - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Building StringDefs.cpp and Example.xml from StringDefs.h... - python $(ProjectDir)scripts\generate_stringdefs.py "$(ProjectDir)airdcpp/core/localization" --xml_output_path="$(ProjectDir)EN_Example.xml" - $(ProjectDir)airdcpp\core\localization\StringDefs.cpp;%(Outputs) - Building StringDefs.cpp and Example.xml from StringDefs.h... - python $(ProjectDir)scripts\generate_stringdefs.py "$(ProjectDir)airdcpp/core/localization" --xml_output_path="$(ProjectDir)EN_Example.xml" - $(ProjectDir)airdcpp\core\localization\StringDefs.cpp;%(Outputs) - Building StringDefs.cpp and Example.xml from StringDefs.h... - python $(ProjectDir)scripts\generate_stringdefs.py "$(ProjectDir)airdcpp/core/localization" --xml_output_path="$(ProjectDir)EN_Example.xml" - $(ProjectDir)airdcpp\core\localization\StringDefs.cpp;%(Outputs) - Building StringDefs.cpp and Example.xml from StringDefs.h... - python $(ProjectDir)scripts\generate_stringdefs.py "$(ProjectDir)airdcpp/core/localization" --xml_output_path="$(ProjectDir)EN_Example.xml" - $(ProjectDir)airdcpp\core\localization\StringDefs.cpp;%(Outputs) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/airdcpp-core/airdcpp.vcxproj.filters b/airdcpp-core/airdcpp.vcxproj.filters deleted file mode 100644 index 7021c88d..00000000 --- a/airdcpp-core/airdcpp.vcxproj.filters +++ /dev/null @@ -1,1546 +0,0 @@ - - - - - {1a8416af-1321-462c-aea6-1547f6f7ddb4} - cpp;c;cxx;rc;def;r;odl;idl;hpj;bat - - - {f99f14c5-0c4b-4660-86f4-9495d819089b} - h;hpp;hxx;hm;inl - - - {391d5b63-e372-486d-9fd7-8976f665666c} - - - {06fdbb05-0647-49b4-b967-aa6eb0a2b68a} - - - {52e7cd39-5e35-42d3-a99d-e85221e0d216} - - - {8ed7d5bd-bcb9-44cd-a3cf-4e6be3b39b9c} - - - {8b57f712-feeb-44d5-b67b-7329f4c5d74d} - - - {0d4f46b5-d2b3-4c9b-9997-7d9c4f744ee2} - - - {76c9545f-03d4-4aff-a49d-d804c0162ec1} - - - {cb28c3bb-ec62-409f-b728-fb86cc66fcc1} - - - {de960125-aec4-4817-b93c-adf1f7aced38} - - - {1b1cd0f9-b1a3-49f4-adbe-d9806d971e90} - - - {bb8c5af6-4e44-4902-b27c-c52130baf8e7} - - - {cabff32a-a347-4308-9d78-25ef8c1885d7} - - - {a8c91f11-f9b6-4497-823d-93b66fcdd583} - - - {f3278bf8-4a25-4d16-a698-dda468d5e236} - - - {24b8a662-2ff0-4b2d-9e14-87204639ca7e} - - - {9c9cfd59-c364-4af2-8fd2-e5937f48c3be} - - - {fbf2209e-553e-4ba6-b8df-04b68eda6b00} - - - {8efbdcb2-b6bb-4946-b182-da4030f212a3} - - - {242828a7-1d0f-4cf4-a515-f9f3c53c25df} - - - {d4f75934-6d6c-4fe8-bb71-7b57fa2c54a5} - - - {1a4a5636-1bf2-4039-8095-b0644e1e5a7a} - - - {05e94b2a-4f6a-48ce-936f-1e3ce597c631} - - - {db94838f-1782-4938-a579-db4d8ea2ead2} - - - {f5cd3a3f-3ff0-4da4-ad45-1eb766e26c22} - - - {b92a08a7-e67e-425b-9f62-9244b6e64a2c} - - - {8e8a51f8-1019-4835-b370-68a2d0f279d2} - - - {7d48af60-79ce-4518-9e26-d3b4f893b942} - - - {a719b85b-e0fe-4128-bbb6-92d25c13665e} - - - {07382b35-2150-44a3-a705-444e04477cd5} - - - {ef009883-4b86-4e22-a978-3897fdfb27c0} - - - {a405c651-de90-438a-b84f-9aed1a480c00} - - - {622eb479-c392-4c15-8a97-1fc8e38e9a58} - - - {7db4a7ad-fefd-4212-913c-a2669f06460f} - - - {77575de4-1fd3-46b4-ae6d-ab5f9ad73b82} - - - {271f8390-aae1-494c-9c24-429c0e9ca1d8} - - - {21c675fb-ba2a-42c7-9d2e-aaf10c3f82a1} - - - {6c605bda-81da-45b5-9598-1c9d11424867} - - - {737ffd06-114f-4a10-9948-a54710d48a25} - - - {cdf3ab9c-cef2-47b6-9683-af3c26501e9e} - - - {610895c8-401f-4eb4-9689-96d5036f1863} - - - {e2899b71-2721-41ad-bae6-784b407afc74} - - - {d5d1787c-1284-4cd1-a3d7-ad3b286e47be} - - - {a21f0f84-fdf1-4a39-83c0-d057769ef022} - - - {b9c17ea6-6623-422d-8675-7c184aeafefa} - - - {224b1842-3a96-49ef-b223-f16189a969cf} - - - {e3b853e4-e583-471d-acce-9047f4c29d6d} - - - {bda99223-216c-4b22-87c4-8e83722c3dbd} - - - {d20cc018-3484-434e-992a-8cd7f3f1dd19} - - - {bf31b2f0-1fa2-458f-8a0f-64351f01b55e} - - - {d32cba0f-ffd9-4c1d-aba5-b902344c9ed5} - - - {4426ab71-0d71-4410-8209-129251a3bd49} - - - {b40cc261-0174-4dc0-b9f3-2f1ad860a182} - - - {7df5e722-ee44-4ad7-9f63-12a3f322c86a} - - - {523bd438-5a9e-4bf3-8cc3-b86083b386f9} - - - {77053cb2-f8ab-4cd7-b15b-9cb469bcef95} - - - {65447249-dc0a-474a-ad6f-072d8d3cc5d5} - - - {c80be2f2-8d22-4eff-8124-be381b57b673} - - - {5701b590-fffc-4e19-8806-3b1a9808b94d} - - - {a0c945c3-32b1-47d4-9d1c-32f128cc90ad} - - - {232a50b8-04aa-4208-98cc-79fd14c3ffa2} - - - {f61010dc-2294-4df3-94e2-35d9dfe0d0d2} - - - {3d79fb4c-65a6-4eb9-bf6b-4e34b49de880} - - - {dda854a9-ac72-4779-b23f-a7d0f6a7a369} - - - {482a1547-b8d9-4439-b00e-43001411006e} - - - {28abfe7d-9711-4bd8-b2c4-cbf2e42c4669} - - - {3dad1ff1-e945-41cb-a702-bbcbd31995e5} - - - {1312e047-05aa-4e95-b494-15e3c727a321} - - - {9b2257a2-d74d-4914-9579-c5d417174d3c} - - - {55220398-0891-4db3-8f8a-c62dc29e19ee} - - - {43f34640-7d6c-46fb-9ab4-b821f46ab799} - - - {0ecd04ee-4254-42e7-8fef-479d0beee1ac} - - - {7fd022de-bcea-4c7c-8470-f17987a107b9} - - - {25b3156d-3c9c-4acd-8395-8ab0e6c85aa2} - - - {63db3144-5c17-4607-bf58-027a896dae8c} - - - {c92e6428-b271-42eb-9e23-caa033be9039} - - - {2cd8d288-6be0-4d44-a7d3-31da3d704229} - - - {43df8d60-4fb2-48c0-8193-2195ff6735b5} - - - {d91c2a76-32ea-4c35-bbb9-b934ca4fc70c} - - - {a2b412b8-cdce-466d-9f67-32519fd957ae} - - - {09809477-c60f-43ea-b0e2-0d958c7d8b86} - - - {3d33ff82-2613-4273-bc12-e4c6303ad95f} - - - {0a049e08-c86d-4233-8ec9-f5649b0a26f3} - - - {801bbe2d-f796-4fd2-8750-3352e2cb8f46} - - - {49bfe988-b09b-4c52-93e5-f26909f3d2f7} - - - {934469d6-d201-4e0c-8ad3-2fa5db525b05} - - - {3f6f1ab4-d3c0-4b39-bd99-d69308bf7f1d} - - - {d564716a-ca06-4cb9-9458-ad09fb7eb421} - - - {ad177e81-736f-46c0-9622-847f800aa3b8} - - - {f935d56f-b4a4-48c2-812e-945684bd1e16} - - - {56d6a4c7-b8bc-45de-bb40-adccb024a164} - - - {ad6d8473-4170-46ae-8525-6e759b459158} - - - {98c23526-b509-4418-8a59-c44c235ff883} - - - {977f9096-8989-4d93-bb65-f9be3eb54256} - - - {0f3c913e-7b84-4441-8db9-c1d7d524a774} - - - {4317a545-da88-4fe6-9229-01aa9828166c} - - - {2ce9c6dd-2e98-4726-9d87-fff934c035e5} - - - {036fb50e-bfee-49e9-b349-20096db7d62c} - - - {a8cec994-514e-45f4-a45d-7bc5054d234f} - - - {3f6a0a1d-cf77-45d9-a5f5-f13fee83eb83} - - - {f9b8e40b-c17c-4590-a1ea-54d0f2c71611} - - - {4b4f03e4-f27a-4b80-95df-7067c26148ac} - - - - - Source Files - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\modules - - - Source Files\share - - - Source Files\share - - - Source Files\share - - - Source Files\share - - - Source Files\share - - - Source Files\queue - - - Source Files\queue - - - Source Files\queue - - - Source Files\queue - - - Source Files\queue - - - Source Files\hub - - - Source Files\hub - - - Source Files\hub - - - Source Files\hub - - - Source Files\hash - - - Source Files\hash - - - Source Files\hash - - - Source Files\filelist - - - Source Files\filelist - - - Source Files\search - - - Source Files\search - - - Source Files\search - - - Source Files\search - - - Source Files\search - - - Source Files\search - - - Source Files\queue - - - Source Files\queue - - - Source Files\transfer - - - Source Files\transfer - - - Source Files\search - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\util - - - Source Files\favorites - - - Source Files\favorites - - - Source Files\favorites - - - Source Files\favorites - - - Source Files\connectivity - - - Source Files\connectivity - - - Source Files\connectivity - - - Source Files\connection - - - Source Files\connection - - - Source Files\connection\http - - - Source Files\connection\http - - - Source Files\connection\socket - - - Source Files\connection\socket - - - Source Files\connection\socket - - - Source Files\settings - - - Source Files\settings - - - Source Files\settings - - - Source Files\settings - - - Source Files\core\io - - - Source Files\core\io - - - Source Files\core\io - - - Source Files\core\io\compress - - - Source Files\core\io\compress - - - Source Files\core\io\db - - - Source Files\core\io\stream - - - Source Files\core\io\xml - - - Source Files\core\io\xml - - - Source Files\message - - - Source Files\message - - - Source Files\message - - - Source Files\connection - - - Source Files\user - - - Source Files\util\text - - - Source Files\util\text - - - Source Files\util\text - - - Source Files\util\text - - - Source Files\user - - - Source Files\viewed_files - - - Source Files\viewed_files - - - Source Files\private_chat - - - Source Files\private_chat - - - Source Files\hash\value - - - Source Files\hash\value - - - Source Files\hash\value - - - Source Files\user\ignore - - - Source Files\hub\user_command - - - Source Files\hub\user_command - - - Source Files\core\crypto - - - Source Files\core\crypto - - - Source Files\core\localization - - - Source Files\core\localization - - - Source Files\core\localization - - - Source Files\core\update - - - Source Files\recents - - - Source Files\connection - - - Source Files\events - - - Source Files\core\geo - - - Source Files\core\geo - - - Source Files\core\timer - - - Source Files\core\thread - - - Source Files\core\thread - - - Source Files\util\classes - - - Source Files\util\classes - - - Source Files\util\classes - - - Source Files\protocol - - - Source Files\hub\activity - - - Source Files\core\io\compress - - - Source Files\transfer\upload\upload_bundles - - - Source Files\transfer\upload\upload_bundles - - - Source Files\transfer\upload\upload_bundles - - - Source Files\transfer\download - - - Source Files\transfer\download - - - Source Files\transfer\download - - - Source Files\transfer\upload - - - Source Files\transfer\upload - - - Source Files\transfer\upload - - - Source Files\transfer\upload - - - Source Files\share\profiles - - - Source Files\share\profiles - - - Source Files\share\temp_share - - - Source Files\queue\partial_sharing - - - Source Files\queue\partial_sharing - - - Source Files\queue\partial_sharing - - - Source Files\connectivity\mappers - - - Source Files\connectivity\mappers - - - Source Files\connectivity\mappers - - - Source Files - - - Source Files\core - - - Source Files\hub - - - Source Files\core\update\updater - - - Source Files\core\update\updater - - - Source Files\core\update - - - Source Files\core\crypto - - - Source Files\filelist - - - Source Files\filelist - - - Source Files\modules - - - Source Files\modules - - - - - Header Files - - - Header Files - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\modules - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\share - - - Header Files\queue - - - Header Files\queue - - - Header Files\queue - - - Header Files\queue - - - Header Files\queue - - - Header Files\queue - - - Header Files\queue - - - Header Files\hub - - - Header Files\hub - - - Header Files\hub - - - Header Files\hub - - - Header Files\hub - - - Header Files\hub - - - Header Files\filelist - - - Header Files\filelist - - - Header Files\filelist - - - Header Files\filelist - - - Header Files\hash - - - Header Files\hash - - - Header Files\hash - - - Header Files\hash - - - Header Files\hash - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\search - - - Header Files\queue - - - Header Files\queue - - - Header Files\transfer - - - Header Files\transfer - - - Header Files\transfer - - - Header Files\search - - - Header Files\hash - - - Header Files\hash - - - Header Files\search - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\util - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\favorites - - - Header Files\queue - - - Header Files\connectivity - - - Header Files\connectivity - - - Header Files\connectivity - - - Header Files\connection - - - Header Files\connection - - - Header Files\connection - - - Header Files\connection - - - Header Files\connection - - - Header Files\connection\http - - - Header Files\connection\http - - - Header Files\connection\http - - - Header Files\connection\socket - - - Header Files\connection\socket - - - Header Files\connection\socket - - - Header Files\connection\socket - - - Header Files\settings - - - Header Files\settings - - - Header Files\settings - - - Header Files\settings - - - Header Files\settings - - - Header Files\core\io - - - Header Files\core\io - - - Header Files\core\io - - - Header Files\core\io\db - - - Header Files\core\io\db - - - Header Files\core\io\stream - - - Header Files\core\io\stream - - - Header Files\core\io\stream - - - Header Files\core\io\stream - - - Header Files\core\io\xml - - - Header Files\core\io\xml - - - Header Files\core\io\compress - - - Header Files\core\io\compress - - - Header Files\message - - - Header Files\message - - - Header Files\message - - - Header Files\connection - - - Header Files\user - - - Header Files\user - - - Header Files\user - - - Header Files\user - - - Header Files\util\text - - - Header Files\util\text - - - Header Files\util\text - - - Header Files\util\text - - - Header Files\util\text - - - Header Files\user - - - Header Files\user - - - Header Files\viewed_files - - - Header Files\viewed_files - - - Header Files\viewed_files - - - Header Files\private_chat - - - Header Files\private_chat - - - Header Files\private_chat - - - Header Files\private_chat - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\hash\value - - - Header Files\user\ignore - - - Header Files\user\ignore - - - Header Files\hub\user_command - - - Header Files\hub\user_command - - - Header Files\connection\socket - - - Header Files\core\crypto - - - Header Files\core\crypto - - - Header Files\core\crypto - - - Header Files\core\localization - - - Header Files\core\localization - - - Header Files\core\update - - - Header Files\core\update - - - Header Files\filelist - - - Header Files\recents - - - Header Files\recents - - - Header Files\recents - - - Header Files\connection - - - Header Files\events - - - Header Files\events - - - Header Files\core\geo - - - Header Files\core\geo - - - Header Files\core\timer - - - Header Files\core\timer - - - Header Files\core\thread - - - Header Files\core\thread - - - Header Files\core\thread - - - Header Files\core\thread - - - Header Files\util\classes - - - Header Files\util\classes - - - Header Files\util\classes - - - Header Files\util\classes - - - Header Files\util\types - - - Header Files\util\types - - - Header Files\util\types - - - Header Files\util\types - - - Header Files\util\classes - - - Header Files\util\classes - - - Header Files\core\classes - - - Header Files\core\classes - - - Header Files\core\classes - - - Header Files\core\classes - - - Header Files\core\classes - - - Header Files\core\classes - - - Header Files\core - - - Header Files\core - - - Header Files\core - - - Header Files\protocol - - - Header Files\protocol - - - Header Files\protocol - - - Header Files\core\queue - - - Header Files\core\queue - - - Header Files\core\queue - - - Header Files\core\queue - - - Header Files\util\classes - - - Header Files\hub\activity - - - Header Files\core\io\compress - - - Header Files\share - - - Header Files\share - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\upload\upload_bundles - - - Header Files\transfer\download - - - Header Files\transfer\download - - - Header Files\transfer\download - - - Header Files\transfer\download - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\transfer\upload - - - Header Files\share\profiles - - - Header Files\share\profiles - - - Header Files\share\profiles - - - Header Files\share\temp_share - - - Header Files\share\temp_share - - - Header Files\share\temp_share - - - Header Files\queue\partial_sharing - - - Header Files\queue\partial_sharing - - - Header Files\queue\partial_sharing - - - Header Files\connectivity\mappers - - - Header Files\connectivity\mappers - - - Header Files\connectivity\mappers - - - Header Files\core - - - Header Files - - - Header Files\core\header - - - Header Files\core\header - - - Header Files\core\header - - - Header Files\core\header - - - Header Files\core\header - - - Header Files\core\header - - - Header Files\transfer - - - Header Files\core\classes - - - Header Files\hub - - - Header Files\core\update - - - Header Files\core\update - - - Header Files\util - - - Header Files\filelist - - - Header Files\filelist - - - Header Files\modules - - - Header Files\modules - - - Header Files\core\update\updater - - - Header Files\core\update\updater - - - Header Files\core\update - - - - - - scripts - - - scripts - - - - - Header Files\core\localization - - - \ No newline at end of file diff --git a/airdcpp-core/airdcpp/connection/ConnectionManager.cpp b/airdcpp-core/airdcpp/connection/ConnectionManager.cpp index 4039c32f..dab3496a 100644 --- a/airdcpp-core/airdcpp/connection/ConnectionManager.cpp +++ b/airdcpp-core/airdcpp/connection/ConnectionManager.cpp @@ -295,9 +295,19 @@ UserConnection* ConnectionManager::getConnection(bool aNmdc) noexcept { return uc; } -bool ConnectionManager::findUserConnection(const string& aToken, const UserConnectionCallback& aCallback) const noexcept { +bool ConnectionManager::findUserConnection(const string& aConnectToken, const UserConnectionCallback& aCallback) const noexcept { RLock l(cs); - if (auto i = find(userConnections.begin(), userConnections.end(), aToken); i != userConnections.end()) { + if (auto i = find(userConnections.begin(), userConnections.end(), aConnectToken); i != userConnections.end()) { + aCallback(*i); + return true; + } + + return false; +} + +bool ConnectionManager::findUserConnection(UserConnectionToken aToken, const UserConnectionCallback& aCallback) const noexcept { + RLock l(cs); + if (auto i = ranges::find_if(userConnections, [aToken](const UserConnectionPtr& uc) { return uc->getToken() == aToken; }); i != userConnections.end()) { aCallback(*i); return true; } @@ -514,10 +524,10 @@ void ConnectionManager::on(TimerManagerListener::Minute, uint64_t aTick) noexcep if ((j->getLastActivity() + MAX_UC_INACTIVITY_SECONDS * 1000) < aTick) { AdcCommand c(AdcCommand::CMD_PMI); c.addParam("\n"); - j->send(c); + j->sendHooked(c); } } else if ((j->getLastActivity() + MAX_UC_INACTIVITY_SECONDS * 1000) < aTick) { - dcdebug("ConnectionManager::timer: disconnecting an inactive connection %s for user %s\n", j->getToken().c_str(), ClientManager::getInstance()->getFormattedNicks(j->getHintedUser()).c_str()); + dcdebug("ConnectionManager::timer: disconnecting an inactive connection %s for user %s\n", j->getConnectToken().c_str(), ClientManager::getInstance()->getFormattedNicks(j->getHintedUser()).c_str()); j->disconnect(true); } } @@ -648,7 +658,7 @@ void ConnectionManager::nmdcConnect(const string& aServer, const SocketConnectOp return; auto uc = getConnection(true); - uc->setToken(aNick); + uc->setConnectToken(aNick); uc->setHubUrl(aHubUrl); uc->setEncoding(aEncoding); uc->setState(UserConnection::STATE_CONNECT); @@ -673,7 +683,7 @@ void ConnectionManager::adcConnect(const OnlineUser& aUser, const SocketConnectO uc->setEncoding(Text::utf8); uc->setState(UserConnection::STATE_CONNECT); uc->setHubUrl(aUser.getClient()->getHubUrl()); - uc->setToken(aToken); + uc->setConnectToken(aToken); /*if (aUser.getIdentity().isOp()) { uc->setFlag(UserConnection::FLAG_OP); }*/ @@ -742,7 +752,7 @@ void ConnectionManager::on(AdcCommand::SUP, UserConnection* aSource, const AdcCo // TODO: better error if(!baseOk || !tigrOk) { - aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_GENERIC, "Invalid SUP")); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_GENERIC, "Invalid SUP")); aSource->disconnect(); return; } @@ -782,11 +792,11 @@ void ConnectionManager::on(UserConnectionListener::Connected, UserConnection* aS dcassert(aSource->getState() == UserConnection::STATE_CONNECT); if(aSource->isSet(UserConnection::FLAG_NMDC)) { - aSource->myNick(aSource->getToken()); + aSource->myNick(aSource->getConnectToken()); aSource->lock(CryptoManager::getInstance()->getLock(), CryptoManager::getInstance()->getPk() + "Ref=" + aSource->getHubUrl()); } else { aSource->sup(getAdcFeatures()); - aSource->send(AdcCommand(AdcCommand::SEV_SUCCESS, AdcCommand::SUCCESS, Util::emptyString).addParam("RF", aSource->getHubUrl())); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_SUCCESS, AdcCommand::SUCCESS, Util::emptyString).addParam("RF", aSource->getHubUrl())); } aSource->setState(UserConnection::STATE_SUPNICK); } @@ -811,7 +821,7 @@ void ConnectionManager::on(UserConnectionListener::MyNick, UserConnection* aSour putConnection(aSource); return; } - aSource->setToken(myNick); + aSource->setConnectToken(myNick); aSource->setHubUrl(hubUrl); aSource->setEncoding(ClientManager::getInstance()->findNmdcEncoding(hubUrl)); } @@ -851,7 +861,7 @@ void ConnectionManager::on(UserConnectionListener::MyNick, UserConnection* aSour ClientManager::getInstance()->setNmdcIPUser(aSource->getUser(), aSource->getRemoteIp()); if( aSource->isSet(UserConnection::FLAG_INCOMING) ) { - aSource->myNick(aSource->getToken()); + aSource->myNick(aSource->getConnectToken()); aSource->lock(CryptoManager::getInstance()->getLock(), CryptoManager::getInstance()->getPk()); } @@ -920,10 +930,10 @@ void ConnectionManager::addPMConnection(UserConnection* uc) noexcept { auto& container = cqis[CONNECTION_TYPE_PM]; auto i = find(container.begin(), container.end(), uc->getUser()); if (i == container.end()) { - dcassert(!uc->getToken().empty()); + dcassert(!uc->getConnectToken().empty()); uc->setFlag(UserConnection::FLAG_ASSOCIATED); - auto cqi = getCQIUnsafe(uc->getHintedUser(), CONNECTION_TYPE_PM, uc->getToken()); + auto cqi = getCQIUnsafe(uc->getHintedUser(), CONNECTION_TYPE_PM, uc->getConnectToken()); cqi->setState(ConnectionQueueItem::State::ACTIVE); fire(ConnectionManagerListener::Connected(), cqi, uc); @@ -955,7 +965,7 @@ void ConnectionManager::addDownloadConnection(UserConnection* uc) noexcept { cqi->setFlag(ConnectionQueueItem::FLAG_MCN); } - uc->setToken(cqi->getToken()); // sync for NMDC users + uc->setConnectToken(cqi->getToken()); // sync for NMDC users uc->setHubUrl(cqi->getHubUrl()); //set the correct hint for the uc, it might not even have a hint at first. uc->setFlag(UserConnection::FLAG_ASSOCIATED); fire(ConnectionManagerListener::Connected(), cqi, uc); @@ -984,11 +994,11 @@ void ConnectionManager::addUploadConnection(UserConnection* uc) noexcept { } if (allowAdd) { - allowAdd = tokens.addToken(uc->getToken(), CONNECTION_TYPE_UPLOAD); + allowAdd = tokens.addToken(uc->getConnectToken(), CONNECTION_TYPE_UPLOAD); if (allowAdd) { uc->setFlag(UserConnection::FLAG_ASSOCIATED); - auto cqi = getCQIUnsafe(uc->getHintedUser(), CONNECTION_TYPE_UPLOAD, uc->getToken()); + auto cqi = getCQIUnsafe(uc->getHintedUser(), CONNECTION_TYPE_UPLOAD, uc->getConnectToken()); cqi->setState(ConnectionQueueItem::State::ACTIVE); fire(ConnectionManagerListener::Connected(), cqi, uc); } @@ -1017,14 +1027,14 @@ void ConnectionManager::on(UserConnectionListener::Key, UserConnection* aSource, // this will be synced to use CQI's random token addDownloadConnection(aSource); } else { - aSource->setToken(Util::toString(ValueGenerator::rand())); // set a random token instead of using the nick + aSource->setConnectToken(Util::toString(ValueGenerator::rand())); // set a random token instead of using the nick addUploadConnection(aSource); } } void ConnectionManager::on(AdcCommand::INF, UserConnection* aSource, const AdcCommand& cmd) noexcept { if(aSource->getState() != UserConnection::STATE_INF) { - aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_GENERIC, "Expecting INF")); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_GENERIC, "Expecting INF")); aSource->disconnect(true); return; } @@ -1032,18 +1042,18 @@ void ConnectionManager::on(AdcCommand::INF, UserConnection* aSource, const AdcCo string token; auto fail = [&, this](AdcCommand::Error aCode, const string& aStr) { - aSource->send(AdcCommand(AdcCommand::SEV_FATAL, aCode, aStr)); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_FATAL, aCode, aStr)); aSource->disconnect(true); }; if (aSource->isSet(UserConnection::FLAG_INCOMING)) { if (!cmd.getParam("TO", 0, token)) { - aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_GENERIC, "TO missing")); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_GENERIC, "TO missing")); putConnection(aSource); return; } - aSource->setToken(token); + aSource->setConnectToken(token); // Incoming connections aren't associated with any user // Are we expecting this connection? Use the saved CID and hubUrl @@ -1082,7 +1092,7 @@ void ConnectionManager::on(AdcCommand::INF, UserConnection* aSource, const AdcCo } else { dcassert(aSource->getUser()); - token = aSource->getToken(); + token = aSource->getConnectToken(); } if(!checkKeyprint(aSource)) { @@ -1240,7 +1250,7 @@ void ConnectionManager::removeExtraMCNUnsafe(const ConnectionQueueItem* aFailedC ConnectionQueueItem* ConnectionManager::findDownloadUnsafe(const UserConnection* aSource) noexcept { // Token may not be synced for NMDC users - auto i = aSource->isMCN() ? std::find(downloads.begin(), downloads.end(), aSource->getToken()) : std::find(downloads.begin(), downloads.end(), aSource->getUser()); + auto i = aSource->isMCN() ? std::find(downloads.begin(), downloads.end(), aSource->getConnectToken()) : std::find(downloads.begin(), downloads.end(), aSource->getUser()); if (i == downloads.end()) { return nullptr; } @@ -1271,8 +1281,8 @@ ConnectionType toConnectionType(const UserConnection* aSource) { void ConnectionManager::failed(UserConnection* aSource, const string& aError, bool aProtocolError) noexcept { if(aSource->isSet(UserConnection::FLAG_ASSOCIATED)) { if(aSource->isSet(UserConnection::FLAG_DOWNLOAD)) { - failDownload(aSource->getToken(), aError, aProtocolError); - dcdebug("ConnectionManager::failed: download %s failed\n", aSource->getToken().c_str()); + failDownload(aSource->getConnectToken(), aError, aProtocolError); + dcdebug("ConnectionManager::failed: download %s failed\n", aSource->getConnectToken().c_str()); } else { auto type = toConnectionType(aSource); @@ -1280,7 +1290,7 @@ void ConnectionManager::failed(UserConnection* aSource, const string& aError, bo WLock l(cs); auto& container = cqis[type]; auto i = type == CONNECTION_TYPE_PM ? find(container.begin(), container.end(), aSource->getUser()) : - find(container.begin(), container.end(), aSource->getToken()); + find(container.begin(), container.end(), aSource->getConnectToken()); dcassert(i != container.end()); putCQIUnsafe(*i); } diff --git a/airdcpp-core/airdcpp/connection/ConnectionManager.h b/airdcpp-core/airdcpp/connection/ConnectionManager.h index d0f4988f..53bfff5c 100644 --- a/airdcpp-core/airdcpp/connection/ConnectionManager.h +++ b/airdcpp-core/airdcpp/connection/ConnectionManager.h @@ -177,7 +177,8 @@ class ConnectionManager : public Speaker, public Clie using UserConnectionCallback = std::function; - bool findUserConnection(const string& aToken, const UserConnectionCallback& aCallback) const noexcept; + bool findUserConnection(const string& aConnectToken, const UserConnectionCallback& aCallback) const noexcept; + bool findUserConnection(UserConnectionToken aToken, const UserConnectionCallback& aCallback) const noexcept; private: FloodCounter floodCounter; diff --git a/airdcpp-core/airdcpp/connection/UserConnection.cpp b/airdcpp-core/airdcpp/connection/UserConnection.cpp index c25a38e9..fe225ec9 100644 --- a/airdcpp-core/airdcpp/connection/UserConnection.cpp +++ b/airdcpp-core/airdcpp/connection/UserConnection.cpp @@ -22,12 +22,13 @@ #include #include -#include #include #include #include #include #include +#include +#include #include @@ -68,7 +69,7 @@ void UserConnection::on(BufferedSocketListener::Line, const string& aLine) noexc return; } dispatch(aLine, [this](const AdcCommand& aCmd) { - ProtocolCommandManager::getInstance()->fire(ProtocolCommandManagerListener::IncomingTCPCommand (), aCmd, getRemoteIp(), getUser()); + ProtocolCommandManager::getInstance()->fire(ProtocolCommandManagerListener::IncomingTCPCommand (), aCmd, getRemoteIp(), getHintedUser()); }); return; } else if(aLine[0] == '$') { @@ -207,7 +208,7 @@ void UserConnection::maxedOut(size_t qPos /*0*/) { if(sendPos) { cmd.addParam("QP", Util::toString(qPos)); } - send(cmd); + sendHooked(cmd); } } @@ -248,16 +249,16 @@ void UserConnection::inf(bool withToken, int mcnSlots) { if(mcnSlots > 0) c.addParam("CO", Util::toString(mcnSlots)); if(withToken) { - c.addParam("TO", getToken()); + c.addParam("TO", getConnectToken()); } if (isSet(FLAG_PM)) { c.addParam("PM", "1"); } - send(c); + sendHooked(c); } void UserConnection::get(const string& aType, const string& aName, const int64_t aStart, const int64_t aBytes) { - send( + sendHooked( AdcCommand(AdcCommand::CMD_GET) .addParam(aType) .addParam(aName) @@ -267,7 +268,7 @@ void UserConnection::get(const string& aType, const string& aName, const int64_t } void UserConnection::snd(const string& aType, const string& aName, const int64_t aStart, const int64_t aBytes) { - send( + sendHooked( AdcCommand(AdcCommand::CMD_SND) .addParam(aType) .addParam(aName) @@ -276,13 +277,29 @@ void UserConnection::snd(const string& aType, const string& aName, const int64_t ); } -void UserConnection::send(const AdcCommand& c) { +bool UserConnection::sendHooked(const AdcCommand& c, CallerPtr aOwner, string& error_) { + AdcCommand::ParamMap params; auto isNmdc = isSet(FLAG_NMDC); if (!isNmdc) { - ProtocolCommandManager::getInstance()->fire(ProtocolCommandManagerListener::OutgoingTCPCommand(), c, getRemoteIp(), getUser()); + { + try { + auto results = ClientManager::getInstance()->outgoingTcpCommandHook.runHooksDataThrow(aOwner, c, *this); + params = ActionHook::normalizeMap(results); + } catch (const HookRejectException& e) { + error_ = ActionHookRejection::formatError(e.getRejection()); + return false; + } + } + + ProtocolCommandManager::getInstance()->fire(ProtocolCommandManagerListener::OutgoingTCPCommand(), c, *this); } - send(c.toString(0, isNmdc)); + if (!params.empty()) { + send(AdcCommand(c).addParams(params).toString(0, isNmdc)); + } else { + send(c.toString(0, isNmdc)); + } + return true; } bool UserConnection::sendPrivateMessageHooked(const OutgoingChatMessage& aMessage, string& error_) { @@ -302,7 +319,9 @@ bool UserConnection::sendPrivateMessageHooked(const OutgoingChatMessage& aMessag c.addParam("ME", "1"); } - send(c); + if (!sendHooked(c, aMessage.owner, error_)) { + return false; + } // simulate an echo message. callAsync([=, this]{ handlePM(c, true); }); @@ -320,7 +339,7 @@ void UserConnection::handle(AdcCommand::PMI t, const AdcCommand& c) { } -void UserConnection::handlePM(const AdcCommand& c, bool aEcho) noexcept{ +void UserConnection::handlePM(const AdcCommand& c, bool aEcho) noexcept { const string& message = c.getParam(0); auto cm = ClientManager::getInstance(); @@ -359,14 +378,14 @@ void UserConnection::sup(const StringList& features) { AdcCommand c(AdcCommand::CMD_SUP); for(const auto& f: features) c.addParam(f); - send(c); + sendHooked(c); } void UserConnection::sendError(const std::string& msg /*FILE_NOT_AVAILABLE*/, AdcCommand::Error aError /*AdcCommand::ERROR_FILE_NOT_AVAILABLE*/) { if (isSet(FLAG_NMDC)) { send("$Error " + msg + "|"); } else { - send(AdcCommand(AdcCommand::SEV_RECOVERABLE, aError, msg)); + sendHooked(AdcCommand(AdcCommand::SEV_RECOVERABLE, aError, msg)); } } @@ -390,31 +409,31 @@ void UserConnection::handle(AdcCommand::STA t, const AdcCommand& c) { fire(t, this, c); } -void UserConnection::on(Connected) noexcept { +void UserConnection::on(BufferedSocketListener::Connected) noexcept { lastActivity = GET_TICK(); fire(UserConnectionListener::Connected(), this); } -void UserConnection::on(Data, uint8_t* data, size_t len) noexcept { +void UserConnection::on(BufferedSocketListener::Data, uint8_t* data, size_t len) noexcept { lastActivity = GET_TICK(); fire(UserConnectionListener::Data(), this, data, len); } -void UserConnection::on(BytesSent, size_t bytes, size_t actual) noexcept { +void UserConnection::on(BufferedSocketListener::BytesSent, size_t bytes, size_t actual) noexcept { lastActivity = GET_TICK(); fire(UserConnectionListener::BytesSent(), this, bytes, actual); } -void UserConnection::on(ModeChange) noexcept { +void UserConnection::on(BufferedSocketListener::ModeChange) noexcept { lastActivity = GET_TICK(); fire(UserConnectionListener::ModeChange(), this); } -void UserConnection::on(TransmitDone) noexcept { +void UserConnection::on(BufferedSocketListener::TransmitDone) noexcept { fire(UserConnectionListener::TransmitDone(), this); } -void UserConnection::on(Failed, const string& aLine) noexcept { +void UserConnection::on(BufferedSocketListener::Failed, const string& aLine) noexcept { //setState(STATE_UNCONNECTED); // let the listeners to see the old state fire(UserConnectionListener::Failed(), this, aLine); @@ -466,12 +485,12 @@ void UserConnection::send(const string& aString) { socket->write(aString); } -UserConnection::UserConnection() noexcept : encoding(SETTING(NMDC_ENCODING)), download(nullptr) { +UserConnection::UserConnection() noexcept : encoding(SETTING(NMDC_ENCODING)), download(nullptr), token(ValueGenerator::rand()) { } UserConnection::~UserConnection() { BufferedSocket::putSocket(socket); - dcdebug("User connection %s was deleted\n", getToken().c_str()); + dcdebug("User connection %s was deleted\n", getConnectToken().c_str()); } } // namespace dcpp diff --git a/airdcpp-core/airdcpp/connection/UserConnection.h b/airdcpp-core/airdcpp/connection/UserConnection.h index 30c287fd..cf6e9a7f 100644 --- a/airdcpp-core/airdcpp/connection/UserConnection.h +++ b/airdcpp-core/airdcpp/connection/UserConnection.h @@ -124,7 +124,11 @@ class UserConnection : public Speaker, void inf(bool withToken, int mcnSlots = 0); void get(const string& aType, const string& aName, const int64_t aStart, const int64_t aBytes); void snd(const string& aType, const string& aName, const int64_t aStart, const int64_t aBytes); - void send(const AdcCommand& c); + bool sendHooked(const AdcCommand& c, CallerPtr aOwner, string& error_); + bool sendHooked(const AdcCommand& c) { + string error; + return sendHooked(c, this, error); + } void setDataMode(int64_t aBytes = -1) noexcept { dcassert(socket); socket->setDataMode(aBytes); } void setLineMode(size_t rollback) noexcept { dcassert(socket); socket->setLineMode(rollback); } @@ -181,7 +185,7 @@ class UserConnection : public Speaker, bool supportsTrees() const noexcept { return isSet(FLAG_SUPPORTS_TTHL); } GETSET(string, hubUrl, HubUrl); - GETSET(string, token, Token); + GETSET(string, connectToken, ConnectToken); IGETSET(int64_t, speed, Speed, 0); IGETSET(uint64_t, lastActivity, LastActivity, 0); GETSET(string, encoding, Encoding); @@ -215,6 +219,7 @@ class UserConnection : public Speaker, void setUseLimiter(bool aEnabled) noexcept; void setState(States aNewState) noexcept; + UserConnectionToken getToken() const noexcept { return token; } private: void initSocket(); @@ -250,9 +255,11 @@ class UserConnection : public Speaker, void onNmdcLine(const string& aLine) noexcept; AdcSupports supports; + + const UserConnectionToken token; }; -inline bool operator==(const UserConnection* ptr, const string& aToken) { return compare(ptr->getToken(), aToken) == 0; } +inline bool operator==(const UserConnection* ptr, const string& aToken) { return compare(ptr->getConnectToken(), aToken) == 0; } } // namespace dcpp diff --git a/airdcpp-core/airdcpp/connection/socket/BufferedSocket.cpp b/airdcpp-core/airdcpp/connection/socket/BufferedSocket.cpp index 4c5e7b4e..0cdab809 100644 --- a/airdcpp-core/airdcpp/connection/socket/BufferedSocket.cpp +++ b/airdcpp-core/airdcpp/connection/socket/BufferedSocket.cpp @@ -471,9 +471,6 @@ bool BufferedSocket::checkEvents() { if (p.second) static_cast(p.second.get())->f(); return false; - } else if(p.first == ASYNC_CALL) { - static_cast(p.second.get())->f(); - continue; } if(state == STARTING) { @@ -492,6 +489,8 @@ bool BufferedSocket::checkEvents() { threadSendFile(static_cast(p.second.get())->stream); break; } else if(p.first == DISCONNECT) { fail(STRING(DISCONNECTED)); + } else if (p.first == ASYNC_CALL) { + static_cast(p.second.get())->f(); } else { dcdebug("%d unexpected in RUNNING state\n", p.first); } diff --git a/airdcpp-core/airdcpp/core/Speaker.h b/airdcpp-core/airdcpp/core/Speaker.h index bebecaaa..33fea02a 100644 --- a/airdcpp-core/airdcpp/core/Speaker.h +++ b/airdcpp-core/airdcpp/core/Speaker.h @@ -47,6 +47,17 @@ class Speaker { listener->on(std::forward(args)...); } } + + // Fire listeners in a reversed order + // (e.g. during a shutdown sequence the listeners that were added last should be uninitialized first) + template + void fireReversed(ArgT&&... args) noexcept { + Lock l(listenerCS); + tmpListeners = listeners; + for (auto listener : tmpListeners | views::reverse) { + listener->on(std::forward(args)...); + } + } void addListener(Listener* aListener) noexcept { Lock l(listenerCS); diff --git a/airdcpp-core/airdcpp/core/localization/StringDefs.h b/airdcpp-core/airdcpp/core/localization/StringDefs.h index 7fc17a38..bf3a48da 100644 --- a/airdcpp-core/airdcpp/core/localization/StringDefs.h +++ b/airdcpp-core/airdcpp/core/localization/StringDefs.h @@ -720,7 +720,7 @@ enum Strings { // @DontAdd MAINTENANCE, // "Maintenance" MAINTENANCE_STARTED_SETTINGS, // "Database maintenance started. Results are shown in the system log when the operation finishes." MAIN_CHAT, // "Main chat" - MAIN_PERMISSION_DENIED, // "You aren't allowed to send messages to main chat" + HUB_PERMISSION_DENIED, // "Action rejected by the hub" MALFORMED_DATA, // "Malformed data" MANAGE_GROUPS, // "Manage groups" MANDATORY_UPDATE, // "Mandatory update" @@ -998,7 +998,6 @@ enum Strings { // @DontAdd PM_MAGNET_SHARED_WARNING, // "The download destination %1% is a shared directory. Files sent in private chat may contain sensitive information that you or the sender don't want to be made available for other user.\r\n\r\nDo you want to use this destination anyway?" PM_MESSAGE_FILTERED, // "Private chat message filtered from user: " PM_MESSAGE_IGNORED, // "Private chat message from ignored user: " - PM_PERMISSION_DENIED, // "You aren't allowed to send private messages to this user" PM_PREVIEW, // "Show preview of private message on popup" POPUP_BACK_COLOR, // "Back color" POPUP_BALOON, // "Balloon popup" @@ -1890,6 +1889,7 @@ enum Strings { // @DontAdd WEB_CFG_OUTGOING_HUB_COMMAND_HOOK_TIMEOUT, // "Outgoing hub command" WEB_CFG_OUTGOING_UDP_COMMAND_HOOK_TIMEOUT, // "Outgoing UDP command" + WEB_CFG_OUTGOING_TCP_COMMAND_HOOK_TIMEOUT, // "Outgoing TCP command" WEB_CFG_QUEUE_ADD_BUNDLE_FILE_HOOK_TIMEOUT, // "Add bundle file" WEB_CFG_QUEUE_ADD_BUNDLE_HOOK_TIMEOUT, // "Add bundle" diff --git a/airdcpp-core/airdcpp/core/version.h b/airdcpp-core/airdcpp/core/version.h index bb4cd842..dfb998e0 100644 --- a/airdcpp-core/airdcpp/core/version.h +++ b/airdcpp-core/airdcpp/core/version.h @@ -53,7 +53,7 @@ namespace dcpp { //Git commit count for the current git tag #define COMMIT_NUMBER getCommitNumber() -#ifdef NDEBUG +#ifdef _DEBUG # define INST_NAME "{AIRDC-AEE8350A-B49A-4753-AB4B-E55479A48351}" #else # define INST_NAME "{AIRDC-AEE8350A-B49A-4753-AB4B-E55479A48350}" diff --git a/airdcpp-core/airdcpp/forward.h b/airdcpp-core/airdcpp/forward.h index 314fc5bf..3bbb15b6 100644 --- a/airdcpp-core/airdcpp/forward.h +++ b/airdcpp-core/airdcpp/forward.h @@ -232,6 +232,7 @@ class UserCommand; class UserConnection; using UserConnectionPtr = UserConnection *; using UserConnectionList = std::vector; +using UserConnectionToken = uint32_t; class ViewFile; using ViewFilePtr = shared_ptr; diff --git a/airdcpp-core/airdcpp/hub/AdcHub.cpp b/airdcpp-core/airdcpp/hub/AdcHub.cpp index 3a6706ab..afd9133b 100644 --- a/airdcpp-core/airdcpp/hub/AdcHub.cpp +++ b/airdcpp-core/airdcpp/hub/AdcHub.cpp @@ -997,33 +997,32 @@ void AdcHub::connect(const OnlineUser& aUser, const string& aToken, bool aSecure } } -bool AdcHub::hubMessageHooked(const string& aMessage, string& error_, bool aThirdPerson) noexcept { +bool AdcHub::hubMessageHooked(const OutgoingChatMessage& aMessage, string& error_) noexcept { AdcCommand c(AdcCommand::CMD_MSG, AdcCommand::TYPE_BROADCAST); - c.addParam(aMessage); - if (aThirdPerson) + c.addParam(aMessage.text); + if (aMessage.thirdPerson) c.addParam("ME", "1"); - if (!sendHooked(c)) { - error_ = STRING(MAIN_PERMISSION_DENIED); + if (!sendHooked(c, aMessage.owner, error_)) { return false; } return true; } -bool AdcHub::privateMessageHooked(const OnlineUserPtr& aUser, const string& aMessage, string& error_, bool aThirdPerson, bool aEcho) noexcept { +bool AdcHub::privateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept { if(!stateNormal()) { error_ = STRING(CONNECTING_IN_PROGRESS); return false; } AdcCommand c(AdcCommand::CMD_MSG, aUser->getIdentity().getSID(), aEcho ? AdcCommand::TYPE_ECHO : AdcCommand::TYPE_DIRECT); - c.addParam(aMessage); - if(aThirdPerson) + c.addParam(aMessage.text); + if(aMessage.thirdPerson) c.addParam("ME", "1"); c.addParam("PM", getMySID()); - if (!sendHooked(c)) { - error_ = STRING(PM_PERMISSION_DENIED); + + if (!sendHooked(c, aMessage.owner, error_)) { return false; } @@ -1034,21 +1033,23 @@ void AdcHub::sendUserCmd(const UserCommand& aUserCommand, const ParamMap& params if(!stateNormal()) return; - string cmdStr = Util::formatParams(aUserCommand.getCommand(), params, escape); + string userCommandStr = Util::formatParams(aUserCommand.getCommand(), params, escape); if (aUserCommand.isChat()) { - callAsync([aUserCommand, this, cmdStr = std::move(cmdStr)] { + callAsync([aUserCommand, this, userCommandStr = std::move(userCommandStr)] { + // This probably shouldn't trigger the message hooks... string error; + OutgoingChatMessage c(userCommandStr, this, "user_command", false); if (aUserCommand.getTo().empty()) { - hubMessageHooked(cmdStr, error); + hubMessageHooked(c, error); } else { auto ou = findUser(aUserCommand.getTo()); if (ou) { - privateMessageHooked(ou, cmdStr, error, false, false); + privateMessageHooked(ou, c, error, false); } } }); } else { - send(cmdStr); + send(userCommandStr); } } @@ -1480,15 +1481,16 @@ string AdcHub::checkNick(const string& aNick) noexcept { return tmp; } -bool AdcHub::sendHooked(const AdcCommand& cmd) { +bool AdcHub::sendHooked(const AdcCommand& cmd, CallerPtr aOwner, string& error_) { if(!forbiddenCommands.contains(AdcCommand::toFourCC(cmd.getFourCC().c_str()))) { AdcCommand::ParamMap params; // Hooks try { - auto results = ClientManager::getInstance()->outgoingHubCommandHook.runHooksDataThrow(ClientManager::getInstance(), cmd, *this); + auto results = ClientManager::getInstance()->outgoingHubCommandHook.runHooksDataThrow(aOwner, cmd, *this); params = ActionHook::normalizeMap(results); - } catch (const HookRejectException&) { + } catch (const HookRejectException& e) { + error_ = ActionHookRejection::formatError(e.getRejection()); return false; } @@ -1504,6 +1506,8 @@ bool AdcHub::sendHooked(const AdcCommand& cmd) { return true; } + + error_ = STRING(HUB_PERMISSION_DENIED); return false; } diff --git a/airdcpp-core/airdcpp/hub/AdcHub.h b/airdcpp-core/airdcpp/hub/AdcHub.h index a4f3a88b..b81d4b06 100644 --- a/airdcpp-core/airdcpp/hub/AdcHub.h +++ b/airdcpp-core/airdcpp/hub/AdcHub.h @@ -36,8 +36,8 @@ class AdcHub : public Client, public CommandHandler { int connect(const OnlineUser& aUser, const string& aToken, string& lastError_) noexcept override; - bool hubMessageHooked(const string& aMessage, string& error_, bool thirdPerson = false) noexcept override; - bool privateMessageHooked(const OnlineUserPtr& aUser, const string& aMessage, string& error_, bool aThirdPerson, bool aEcho) noexcept override; + bool hubMessageHooked(const OutgoingChatMessage& aMessage, string& error_) noexcept override; + bool privateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept override; void sendUserCmd(const UserCommand& command, const ParamMap& params) override; void search(const SearchPtr& aSearch) noexcept override; bool directSearchHooked(const OnlineUser& user, const SearchPtr& aSearch, string& error_) noexcept override; @@ -48,7 +48,11 @@ class AdcHub : public Client, public CommandHandler { size_t getUserCount() const noexcept override; static string escape(const string& str) noexcept { return AdcCommand::escape(str, false); } - bool sendHooked(const AdcCommand& cmd) override; + bool sendHooked(const AdcCommand& cmd, CallerPtr aOwner, string& error_) override; + bool sendHooked(const AdcCommand& c) { + string error; + return sendHooked(c, this, error); + } string getMySID() const noexcept { return AdcCommand::fromSID(mySID); } diff --git a/airdcpp-core/airdcpp/hub/Client.cpp b/airdcpp-core/airdcpp/hub/Client.cpp index a84e1321..aba53834 100644 --- a/airdcpp-core/airdcpp/hub/Client.cpp +++ b/airdcpp-core/airdcpp/hub/Client.cpp @@ -400,7 +400,7 @@ bool Client::sendMessageHooked(const OutgoingChatMessage& aMessage, string& erro return false; } - return hubMessageHooked(aMessage.text, error_, aMessage.thirdPerson); + return hubMessageHooked(aMessage, error_); } bool Client::sendPrivateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept { @@ -419,7 +419,7 @@ bool Client::sendPrivateMessageHooked(const OnlineUserPtr& aUser, const Outgoing return false; } - return privateMessageHooked(aUser, aMessage.text, error_, aMessage.thirdPerson, aEcho); + return privateMessageHooked(aUser, aMessage, error_, aEcho); } void Client::onPrivateMessage(const ChatMessagePtr& aMessage) noexcept { diff --git a/airdcpp-core/airdcpp/hub/Client.h b/airdcpp-core/airdcpp/hub/Client.h index 59de477a..71ee0629 100644 --- a/airdcpp-core/airdcpp/hub/Client.h +++ b/airdcpp-core/airdcpp/hub/Client.h @@ -49,7 +49,7 @@ class ClientBase virtual string getHubName() const noexcept = 0; virtual bool isOp() const noexcept = 0; virtual int connect(const OnlineUser& user, const string& token, string& lastError_) noexcept = 0; - virtual bool privateMessageHooked(const OnlineUserPtr& aUser, const string& aMessage, string& error_, bool aThirdPerson = false, bool aEcho = true) noexcept = 0; + virtual bool privateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho = true) noexcept = 0; virtual bool directSearchHooked(const OnlineUser&, const SearchPtr&, string&) noexcept { dcassert(0); return false; @@ -86,7 +86,7 @@ class Client : virtual size_t getUserCount() const noexcept = 0; int64_t getTotalShare() const noexcept { return availableBytes; }; - virtual bool sendHooked(const AdcCommand& command) = 0; + virtual bool sendHooked(const AdcCommand& command, CallerPtr aOwner, string& error_) = 0; void callAsync(AsyncF f) noexcept; @@ -205,8 +205,8 @@ class Client : protected: mutable SharedMutex cs; - virtual bool hubMessageHooked(const string& aMessage, string& error_, bool aThirdPerson = false) noexcept = 0; - virtual bool privateMessageHooked(const OnlineUserPtr& aUser, const string& aMessage, string& error_, bool aThirdPerson, bool aEcho) noexcept override = 0; + virtual bool hubMessageHooked(const OutgoingChatMessage& aMessage, string& error_) noexcept = 0; + virtual bool privateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept override = 0; virtual void clearUsers() noexcept = 0; void setConnectState(State aState) noexcept; diff --git a/airdcpp-core/airdcpp/hub/ClientManager.cpp b/airdcpp-core/airdcpp/hub/ClientManager.cpp index d38f8e63..e58da0a4 100644 --- a/airdcpp-core/airdcpp/hub/ClientManager.cpp +++ b/airdcpp-core/airdcpp/hub/ClientManager.cpp @@ -657,28 +657,39 @@ ClientManager::ConnectResult ClientManager::connect(const HintedUser& aUser, con return result; } -bool ClientManager::sendUDPHooked(AdcCommand& cmd, const CID& aCID, bool aNoCID /*false*/, bool aNoPassive /*false*/, const string& aKey /*Util::emptyString*/, const string& aHubUrl /*Util::emptyString*/) noexcept { - auto u = findOnlineUser(aCID, aHubUrl); +bool ClientManager::sendUDPHooked(AdcCommand& cmd, const HintedUser& to, const OutgoingUDPCommandOptions& aOptions, string& error_) noexcept { + auto u = findOnlineUser(to); if (!u) { + error_ = "User missing"; + return false; + } + + if (u->getUser()->isNMDC()) { + error_ = "NMDC user"; return false; } if (cmd.getType() == AdcCommand::TYPE_UDP && !u->getIdentity().isUdpActive()) { - if (u->getUser()->isNMDC() || aNoPassive) { + if (aOptions.noPassive) { + error_ = "The user is passive"; return false; } cmd.setType(AdcCommand::TYPE_DIRECT); cmd.setTo(u->getIdentity().getSID()); - return u->getClient()->sendHooked(cmd); + + return u->getClient()->sendHooked(cmd, aOptions.owner, error_); } else { + auto ipPort = u->getIdentity().getUdpIp() + ":" + u->getIdentity().getUdpPort(); + // Hooks { AdcCommand::ParamMap params; try { - auto results = outgoingUdpCommandHook.runHooksDataThrow(this, cmd, u); + auto results = outgoingUdpCommandHook.runHooksDataThrow(this, cmd, u, ipPort); params = ActionHook::normalizeMap(results); - } catch (const HookRejectException&) { + } catch (const HookRejectException& e) { + error_ = ActionHookRejection::formatError(e.getRejection()); return false; } @@ -686,16 +697,15 @@ bool ClientManager::sendUDPHooked(AdcCommand& cmd, const CID& aCID, bool aNoCID } // Listeners - auto ipPort = u->getIdentity().getUdpIp() + ":" + u->getIdentity().getUdpPort(); ProtocolCommandManager::getInstance()->fire(ProtocolCommandManagerListener::OutgoingUDPCommand(), cmd, ipPort, u); COMMAND_DEBUG(cmd.toString(), ProtocolCommandManager::TYPE_CLIENT_UDP, ProtocolCommandManager::OUTGOING, ipPort); // Send try { - auto cmdStr = aNoCID ? cmd.toString() : cmd.toString(getMyCID()); - if (!aKey.empty() && Encoder::isBase32(aKey.c_str())) { + auto cmdStr = aOptions.noCID ? cmd.toString() : cmd.toString(getMyCID()); + if (!aOptions.encryptionKey.empty() && Encoder::isBase32(aOptions.encryptionKey.c_str())) { uint8_t keyChar[16]; - Encoder::fromBase32(aKey.c_str(), keyChar, 16); + Encoder::fromBase32(aOptions.encryptionKey.c_str(), keyChar, 16); CryptoUtil::encryptSUDP(keyChar, cmdStr); } @@ -703,6 +713,7 @@ bool ClientManager::sendUDPHooked(AdcCommand& cmd, const CID& aCID, bool aNoCID udp->writeTo(u->getIdentity().getUdpIp(), u->getIdentity().getUdpPort(), cmdStr); } catch(const SocketException&) { dcdebug("Socket exception sending ADC UDP command\n"); + error_ = "Socket error"; return false; } } diff --git a/airdcpp-core/airdcpp/hub/ClientManager.h b/airdcpp-core/airdcpp/hub/ClientManager.h index 934a2112..8c01a39d 100644 --- a/airdcpp-core/airdcpp/hub/ClientManager.h +++ b/airdcpp-core/airdcpp/hub/ClientManager.h @@ -51,7 +51,8 @@ class ClientManager : public Speaker, ActionHook outgoingHubMessageHook; ActionHook outgoingHubCommandHook; - ActionHook outgoingUdpCommandHook; + ActionHook outgoingUdpCommandHook; + ActionHook outgoingTcpCommandHook; // MESSAGES @@ -225,7 +226,16 @@ class ClientManager : public Speaker, // CONNECT/PROTOCOL - bool sendUDPHooked(AdcCommand& c, const CID& to, bool aNoCID = false, bool aNoPassive = false, const string& aEncryptionKey = Util::emptyString, const string& aHubUrl = Util::emptyString) noexcept; + struct OutgoingUDPCommandOptions { + OutgoingUDPCommandOptions(CallerPtr aOwner, bool aNoPassive) : noPassive(aNoPassive), owner(aOwner) {} + + string encryptionKey; + bool noPassive; + bool noCID; + CallerPtr owner; + }; + + bool sendUDPHooked(AdcCommand& c, const HintedUser& to, const OutgoingUDPCommandOptions& aOptions, string& error_) noexcept; struct ConnectResult { void onSuccess(const string_view& aHubHint) noexcept { diff --git a/airdcpp-core/airdcpp/hub/NmdcHub.h b/airdcpp-core/airdcpp/hub/NmdcHub.h index 1a17d3f8..71013cf0 100644 --- a/airdcpp-core/airdcpp/hub/NmdcHub.h +++ b/airdcpp-core/airdcpp/hub/NmdcHub.h @@ -36,11 +36,11 @@ class NmdcHub : public Client, private Flags int connect(const OnlineUser& aUser, const string& token, string& lastError_) noexcept override; - bool hubMessageHooked(const string& aMessage, string& /*error_*/, bool aThirdPerson = false) noexcept override { - return hubMessage(aMessage, aThirdPerson); + bool hubMessageHooked(const OutgoingChatMessage& aMessage, string& /*error_*/) noexcept override { + return hubMessage(aMessage.text, aMessage.thirdPerson); } - bool privateMessageHooked(const OnlineUserPtr& aUser, const string& aMessage, string& error_, bool aThirdPerson, bool aEcho) noexcept override { - return privateMessage(aUser, aMessage, error_, aThirdPerson, aEcho); + bool privateMessageHooked(const OnlineUserPtr& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept override { + return privateMessage(aUser, aMessage.text, error_, aMessage.thirdPerson, aEcho); } bool hubMessage(const string& aMessage, bool thirdPerson = false) noexcept; @@ -55,7 +55,7 @@ class NmdcHub : public Client, private Flags static string escape(string const& str) { return validateMessage(str, false); } static string unescape(const string& str) { return validateMessage(str, true); } - bool sendHooked(const AdcCommand&) override { dcassert(0); return false; } + bool sendHooked(const AdcCommand&, CallerPtr, string&) override { dcassert(0); return false; } static string validateMessage(string tmp, bool reverse); void refreshUserList(bool) noexcept override; diff --git a/airdcpp-core/airdcpp/private_chat/PrivateChat.cpp b/airdcpp-core/airdcpp/private_chat/PrivateChat.cpp index 8a87b401..25dffcb5 100644 --- a/airdcpp-core/airdcpp/private_chat/PrivateChat.cpp +++ b/airdcpp-core/airdcpp/private_chat/PrivateChat.cpp @@ -425,7 +425,7 @@ void PrivateChat::sendPMInfo(uint8_t aType) { c.addParam("\n"); } - uc->send(c); + uc->sendHooked(c); } } diff --git a/airdcpp-core/airdcpp/protocol/AdcCommand.h b/airdcpp-core/airdcpp/protocol/AdcCommand.h index b65447e2..957cd5ad 100644 --- a/airdcpp-core/airdcpp/protocol/AdcCommand.h +++ b/airdcpp-core/airdcpp/protocol/AdcCommand.h @@ -34,7 +34,8 @@ class AdcCommand { enum { CMD = T }; }; - typedef multimap ParamMap; + using ParamMap = multimap; + using ParamList = StringList; enum Error { SUCCESS = 0, @@ -149,8 +150,12 @@ class AdcCommand { }; AdcCommand& addFeature(const string& feat, FeatureType aType) noexcept; - StringList& getParameters() noexcept { return parameters; } - const StringList& getParameters() const noexcept { return parameters; } + ParamList& getParameters() noexcept { return parameters; } + const ParamList& getParameters() const noexcept { return parameters; } + AdcCommand& setParams(const ParamList& aParams) noexcept { + parameters = aParams; + return *this; + } string toString() const noexcept; string toString(const CID& aCID) const noexcept; @@ -190,7 +195,7 @@ class AdcCommand { string getHeaderString() const noexcept; string getHeaderString(dcpp::SID sid, bool nmdc) const noexcept; string getParamString(bool nmdc) const noexcept; - StringList parameters; + ParamList parameters; string features; union { char cmdChar[4]; diff --git a/airdcpp-core/airdcpp/protocol/ProtocolCommandManager.h b/airdcpp-core/airdcpp/protocol/ProtocolCommandManager.h index e4883d0f..4bfec727 100644 --- a/airdcpp-core/airdcpp/protocol/ProtocolCommandManager.h +++ b/airdcpp-core/airdcpp/protocol/ProtocolCommandManager.h @@ -43,11 +43,11 @@ template struct X { enum { TYPE = I }; }; virtual void on(IncomingHubCommand, const AdcCommand&, const Client&) noexcept { } virtual void on(IncomingUDPCommand, const AdcCommand&, const string&) noexcept { } - virtual void on(IncomingTCPCommand, const AdcCommand&, const string&, const UserPtr&) noexcept { } + virtual void on(IncomingTCPCommand, const AdcCommand&, const string&, const HintedUser&) noexcept { } virtual void on(OutgoingHubCommand, const AdcCommand&, const Client&) noexcept { } virtual void on(OutgoingUDPCommand, const AdcCommand&, const string&, const OnlineUserPtr&) noexcept { } - virtual void on(OutgoingTCPCommand, const AdcCommand&, const string&, const UserPtr&) noexcept { } + virtual void on(OutgoingTCPCommand, const AdcCommand&, const UserConnection&) noexcept { } }; class ProtocolCommandManager : public Singleton, public Speaker diff --git a/airdcpp-core/airdcpp/queue/partial_sharing/PartialBundleSharingManager.cpp b/airdcpp-core/airdcpp/queue/partial_sharing/PartialBundleSharingManager.cpp index 717618fd..bdebf366 100644 --- a/airdcpp-core/airdcpp/queue/partial_sharing/PartialBundleSharingManager.cpp +++ b/airdcpp-core/airdcpp/queue/partial_sharing/PartialBundleSharingManager.cpp @@ -303,9 +303,12 @@ void PartialBundleSharingManager::onIncomingSearch(const OnlineUserPtr& aUser, c void PartialBundleSharingManager::sendUDP(AdcCommand& aCmd, const UserPtr& aUser, const string& aHubUrl) { SearchManager::getInstance()->getUdpServer().addTask([=, this] { auto cmd = aCmd; - auto success = ClientManager::getInstance()->sendUDPHooked(cmd, aUser->getCID(), false, true, Util::emptyString, aHubUrl); + + ClientManager::OutgoingUDPCommandOptions options(this, true); + string error; + auto success = ClientManager::getInstance()->sendUDPHooked(cmd, HintedUser(aUser, aHubUrl), options, error); if (!success) { - dbgMsg("failed to send UDP message to an user " + aUser->getCID().toBase32(), LogMessage::SEV_WARNING); + dbgMsg("failed to send UDP message to an user " + aUser->getCID().toBase32() + ": " + error, LogMessage::SEV_WARNING); } }); } @@ -315,9 +318,9 @@ void PartialBundleSharingManager::on(ProtocolCommandManagerListener::IncomingUDP return; } - //if (!SETTING(USE_PARTIAL_SHARING)) { - // return; - //} + if (!SETTING(USE_PARTIAL_SHARING)) { + return; + } if (aCmd.getParameters().empty()) return; @@ -331,9 +334,6 @@ void PartialBundleSharingManager::on(ProtocolCommandManagerListener::IncomingUDP return; } - // Remove the CID - // c.getParameters().erase(c.getParameters().begin()); - onPBD(aCmd, user); } diff --git a/airdcpp-core/airdcpp/queue/partial_sharing/PartialFileSharingManager.cpp b/airdcpp-core/airdcpp/queue/partial_sharing/PartialFileSharingManager.cpp index ae2f2731..ec6e7e70 100644 --- a/airdcpp-core/airdcpp/queue/partial_sharing/PartialFileSharingManager.cpp +++ b/airdcpp-core/airdcpp/queue/partial_sharing/PartialFileSharingManager.cpp @@ -414,9 +414,12 @@ void PartialFileSharingManager::on(TimerManagerListener::Minute, uint64_t aTick) void PartialFileSharingManager::sendUDP(AdcCommand& aCmd, const UserPtr& aUser, const string& aHubUrl) const noexcept { SearchManager::getInstance()->getUdpServer().addTask([=, this] { auto cmd = aCmd; - auto success = ClientManager::getInstance()->sendUDPHooked(cmd, aUser->getCID(), false, true, Util::emptyString, aHubUrl); + + ClientManager::OutgoingUDPCommandOptions options(this, true); + string error; + auto success = ClientManager::getInstance()->sendUDPHooked(cmd, HintedUser(aUser, aHubUrl), options, error); if (!success) { - dbgMsg("failed to send UDP message", LogMessage::SEV_WARNING); + dbgMsg("failed to send UDP message: " + error, LogMessage::SEV_WARNING); } }); } diff --git a/airdcpp-core/airdcpp/queue/partial_sharing/PartialSharingManager.cpp b/airdcpp-core/airdcpp/queue/partial_sharing/PartialSharingManager.cpp index 0a3fe3b5..d25d3054 100644 --- a/airdcpp-core/airdcpp/queue/partial_sharing/PartialSharingManager.cpp +++ b/airdcpp-core/airdcpp/queue/partial_sharing/PartialSharingManager.cpp @@ -44,7 +44,7 @@ ActionHookResult PartialSharingManager::onSlotType(const Use if (aUpload.provider == providerName) { auto partialFree = aUserConnection.hasSlotSource(providerName) || (extraPartial < SETTING(EXTRA_PARTIAL_SLOTS)); if (partialFree) { - dcdebug("PartialSharingManager::onSlotType: assign partial slot for %s\n", aUserConnection.getToken().c_str()); + dcdebug("PartialSharingManager::onSlotType: assign partial slot for %s\n", aUserConnection.getConnectToken().c_str()); return aResultGetter.getData(UploadSlot(UploadSlot::Type::FILESLOT, providerName)); } } diff --git a/airdcpp-core/airdcpp/search/SearchManager.cpp b/airdcpp-core/airdcpp/search/SearchManager.cpp index 223c34c7..bddf99ca 100644 --- a/airdcpp-core/airdcpp/search/SearchManager.cpp +++ b/airdcpp-core/airdcpp/search/SearchManager.cpp @@ -403,7 +403,8 @@ void SearchManager::respond(const AdcCommand& adc, Client* aClient, OnlineUser* c.setTo(aUser->getIdentity().getSID()); c.addParam("TO", token); - aUser->getClient()->sendHooked(c); + string error; + aUser->getClient()->sendHooked(c, this, error); } return; } @@ -415,7 +416,11 @@ void SearchManager::respond(const AdcCommand& adc, Client* aClient, OnlineUser* AdcCommand cmd = sr->toRES(AdcCommand::TYPE_UDP); if(!token.empty()) cmd.addParam("TO", token); - ClientManager::getInstance()->sendUDPHooked(cmd, aUser->getUser()->getCID(), false, false, sudpKey, aUser->getHubUrl()); + + string error; + ClientManager::OutgoingUDPCommandOptions options(this, false); + options.encryptionKey = sudpKey; + ClientManager::getInstance()->sendUDPHooked(cmd, aUser->getHintedUser(), options, error); } } @@ -426,7 +431,8 @@ void SearchManager::respond(const AdcCommand& adc, Client* aClient, OnlineUser* c.addParam("TO", token); c.addParam("RC", Util::toString(results.size())); - aUser->getClient()->sendHooked(c); + string error; + aUser->getClient()->sendHooked(c, this, error); } } diff --git a/airdcpp-core/airdcpp/transfer/Transfer.cpp b/airdcpp-core/airdcpp/transfer/Transfer.cpp index f25a97a6..87a12055 100644 --- a/airdcpp-core/airdcpp/transfer/Transfer.cpp +++ b/airdcpp-core/airdcpp/transfer/Transfer.cpp @@ -23,7 +23,6 @@ #include #include #include -#include namespace dcpp { @@ -35,7 +34,12 @@ const string Transfer::USER_LIST_NAME_EXTRACTED = "files.xml"; const string Transfer::USER_LIST_NAME_BZ = "files.xml.bz2"; Transfer::Transfer(UserConnection& conn, const string& path_, const TTHValue& tth_) : path(path_), - segment(0, -1), tth(tth_), userConnection(conn), token(ValueGenerator::rand()) { } + segment(0, -1), tth(tth_), userConnection(conn) { } + + +TransferToken Transfer::getToken() const noexcept { + return userConnection.getToken(); +} void Transfer::tick() noexcept { WLock l(cs); @@ -115,7 +119,7 @@ HintedUser Transfer::getHintedUser() const noexcept { } const string& Transfer::getConnectionToken() const noexcept { - return getUserConnection().getToken(); + return getUserConnection().getConnectToken(); } bool Transfer::isFilelist() const noexcept { diff --git a/airdcpp-core/airdcpp/transfer/Transfer.h b/airdcpp-core/airdcpp/transfer/Transfer.h index 2d7257a4..264e8105 100644 --- a/airdcpp-core/airdcpp/transfer/Transfer.h +++ b/airdcpp-core/airdcpp/transfer/Transfer.h @@ -81,7 +81,7 @@ class Transfer : private boost::noncopyable { UserConnection& getUserConnection() noexcept { return userConnection; } const UserConnection& getUserConnection() const noexcept { return userConnection; } const string& getConnectionToken() const noexcept; - TransferToken getToken() const noexcept { return token; } + TransferToken getToken() const noexcept; GETSET(string, path, Path); GETSET(Segment, segment, Segment); @@ -106,7 +106,6 @@ class Transfer : private boost::noncopyable { int64_t pos = 0; UserConnection& userConnection; - const TransferToken token; }; } // namespace dcpp diff --git a/airdcpp-core/airdcpp/transfer/TransferInfoManager.cpp b/airdcpp-core/airdcpp/transfer/TransferInfoManager.cpp index 9f7792b4..afa8660a 100644 --- a/airdcpp-core/airdcpp/transfer/TransferInfoManager.cpp +++ b/airdcpp-core/airdcpp/transfer/TransferInfoManager.cpp @@ -313,7 +313,7 @@ namespace dcpp { return; } - auto t = findTransfer(aConn->getToken()); + auto t = findTransfer(aConn->getConnectToken()); if (!t) { return; } diff --git a/airdcpp-core/airdcpp/transfer/download/DownloadManager.cpp b/airdcpp-core/airdcpp/transfer/download/DownloadManager.cpp index ce270836..c6d4cb31 100644 --- a/airdcpp-core/airdcpp/transfer/download/DownloadManager.cpp +++ b/airdcpp-core/airdcpp/transfer/download/DownloadManager.cpp @@ -146,8 +146,8 @@ void DownloadManager::on(TimerManagerListener::Second, uint64_t aTick) noexcept bool DownloadManager::checkIdle(const string& aToken) { RLock l(cs); for (auto uc : idlers) { - if (uc->getToken() == aToken) { - uc->callAsync([this, uc] { revive(uc); }); + if (uc->getConnectToken() == aToken) { + uc->callAsync([this, uc] { reviveThreaded(uc); }); return true; } } @@ -162,14 +162,14 @@ bool DownloadManager::checkIdle(const UserPtr& aUser, bool aSmallSlot) { if (aSmallSlot != uc->isSet(UserConnection::FLAG_SMALL_SLOT) && uc->isMCN()) continue; - uc->callAsync([this, uc] { revive(uc); }); + uc->callAsync([this, uc] { reviveThreaded(uc); }); return true; } } return false; } -void DownloadManager::revive(UserConnection* uc) { +void DownloadManager::reviveThreaded(UserConnection* uc) { { WLock l(cs); auto i = find(idlers.begin(), idlers.end(), uc); @@ -186,7 +186,7 @@ void DownloadManager::addConnection(UserConnection* aSource) { // Can't download from these... aSource->getUser()->setFlag(User::OLD_CLIENT); QueueManager::getInstance()->removeSource(aSource->getUser(), QueueItem::Source::FLAG_NO_TTHF); - dcdebug("DownloadManager::addConnection: outdated user (%s)\n", aSource->getToken().c_str()); + dcdebug("DownloadManager::addConnection: outdated user (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); return; } @@ -307,7 +307,7 @@ void DownloadManager::checkDownloads(UserConnection* aConn) { dcassert(aConn->getDownload()); fire(DownloadManagerListener::Requesting(), d, !mySID.empty()); - aConn->send(d->getCommand(aConn->isSet(UserConnection::FLAG_SUPPORTS_ZLIB_GET), mySID)); + aConn->sendHooked(d->getCommand(aConn->isSet(UserConnection::FLAG_SUPPORTS_ZLIB_GET), mySID)); } void DownloadManager::on(AdcCommand::SND, UserConnection* aSource, const AdcCommand& cmd) noexcept { @@ -317,7 +317,7 @@ void DownloadManager::on(AdcCommand::SND, UserConnection* aSource, const AdcComm } if(!aSource->getDownload()) { - dcdebug("DownloadManager::AdcCommand::SND: no download (%s)\n", aSource->getToken().c_str()); + dcdebug("DownloadManager::AdcCommand::SND: no download (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource, true); return; } @@ -331,7 +331,7 @@ void DownloadManager::on(AdcCommand::SND, UserConnection* aSource, const AdcComm if(type != Transfer::names[aSource->getDownload()->getType()]) { // Uhh??? We didn't ask for this... - dcdebug("DownloadManager::AdcCommand::SND: transfer type mismatch (%s)\n", aSource->getToken().c_str()); + dcdebug("DownloadManager::AdcCommand::SND: transfer type mismatch (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); return; } @@ -399,7 +399,7 @@ void DownloadManager::on(UserConnectionListener::Data, UserConnection* aSource, if (!d) { //No download but receiving data?? dcassert(0); - dcdebug("DownloadManager::UserConnectionListener::Data: no download (%s)\n", aSource->getToken().c_str()); + dcdebug("DownloadManager::UserConnectionListener::Data: no download (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource, true); return; } @@ -529,7 +529,7 @@ void DownloadManager::onFailed(UserConnection* aSource, const string& aError) { void DownloadManager::failDownload(UserConnection* aSource, const string& aReason, bool aRotateQueue) { auto d = aSource->getDownload(); if (d) { - dcdebug("DownloadManager::failDownload: %s failed (%s)\n", aSource->getToken().c_str(), aReason.c_str()); + dcdebug("DownloadManager::failDownload: %s failed (%s)\n", aSource->getConnectToken().c_str(), aReason.c_str()); fire(DownloadManagerListener::Failed(), d, aReason); removeDownload(d); QueueManager::getInstance()->putDownloadHooked(d, false, false, aRotateQueue); @@ -547,7 +547,7 @@ void DownloadManager::removeConnection(UserConnectionPtr aConn) { } void DownloadManager::disconnect(UserConnectionPtr aConn, bool aGraceless) const noexcept { - dcdebug("DownloadManager::disconnect: %s (graceless: %s)\n", aConn->getToken().c_str(), aGraceless ? "true" : "false"); + dcdebug("DownloadManager::disconnect: %s (graceless: %s)\n", aConn->getConnectToken().c_str(), aGraceless ? "true" : "false"); aConn->disconnect(aGraceless); } @@ -595,7 +595,7 @@ void DownloadManager::abortDownload(const string& aTarget, const UserPtr& aUser) void DownloadManager::on(UserConnectionListener::FileNotAvailable, UserConnection* aSource) noexcept { if(!aSource->getDownload()) { - dcdebug("DM::FileNotAvailable: no download (%s)\n", aSource->getToken().c_str()); + dcdebug("DM::FileNotAvailable: no download (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource, true); return; } @@ -605,7 +605,7 @@ void DownloadManager::on(UserConnectionListener::FileNotAvailable, UserConnectio /** @todo Handle errors better */ void DownloadManager::on(AdcCommand::STA, UserConnection* aSource, const AdcCommand& cmd) noexcept { if(cmd.getParameters().size() < 2) { - dcdebug("DM::AdcCommand::STA: not enough parameters (%s)\n", aSource->getToken().c_str()); + dcdebug("DM::AdcCommand::STA: not enough parameters (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); return; } @@ -613,14 +613,14 @@ void DownloadManager::on(AdcCommand::STA, UserConnection* aSource, const AdcComm const string& errorCode = cmd.getParam(0); const string& errorMessage = cmd.getParam(1); if(errorCode.length() != 3) { - dcdebug("DM::AdcCommand::STA: invalid error code (%s)\n", aSource->getToken().c_str()); + dcdebug("DM::AdcCommand::STA: invalid error code (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); return; } switch(Util::toInt(errorCode.substr(0, 1))) { case AdcCommand::SEV_FATAL: - dcdebug("DM::AdcCommand::STA: fatal error (%s)\n", aSource->getToken().c_str()); + dcdebug("DM::AdcCommand::STA: fatal error (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); return; [[fallthrough]]; @@ -654,7 +654,7 @@ void DownloadManager::on(AdcCommand::STA, UserConnection* aSource, const AdcComm // ... } - dcdebug("DM::AdcCommand::STA: disconnecting (%s)\n", aSource->getToken().c_str()); + dcdebug("DM::AdcCommand::STA: disconnecting (%s)\n", aSource->getConnectToken().c_str()); disconnect(aSource); } diff --git a/airdcpp-core/airdcpp/transfer/download/DownloadManager.h b/airdcpp-core/airdcpp/transfer/download/DownloadManager.h index f887702e..ce1d885b 100644 --- a/airdcpp-core/airdcpp/transfer/download/DownloadManager.h +++ b/airdcpp-core/airdcpp/transfer/download/DownloadManager.h @@ -100,7 +100,7 @@ class DownloadManager : public Speaker, bool disconnectSlowSpeed(Download* aDownload, uint64_t aTick) const noexcept; void startData(UserConnection* aSource, int64_t start, int64_t newSize, bool z); - void revive(UserConnection* uc); + void reviveThreaded(UserConnection* uc); void endData(UserConnection* aSource); void onFailed(UserConnection* aSource, const string& aError); diff --git a/airdcpp-core/airdcpp/transfer/upload/UploadManager.cpp b/airdcpp-core/airdcpp/transfer/upload/UploadManager.cpp index 31590148..d85339a1 100644 --- a/airdcpp-core/airdcpp/transfer/upload/UploadManager.cpp +++ b/airdcpp-core/airdcpp/transfer/upload/UploadManager.cpp @@ -244,7 +244,7 @@ OptionalUploadSlot UploadManager::parseSlotHookedThrow(const UserConnection& aSo // Existing uploader and no new connections allowed? if (!aParser.usesSmallSlot() && isUploadingMCN(aSource.getUser()) && !allowNewMultiConn(aSource)) { - dcdebug("UploadManager::parseSlotType: new MCN connections not allowed for %s\n", aSource.getToken().c_str()); + dcdebug("UploadManager::parseSlotType: new MCN connections not allowed for %s\n", aSource.getConnectToken().c_str()); return nullopt; } @@ -258,17 +258,17 @@ OptionalUploadSlot UploadManager::parseSlotHookedThrow(const UserConnection& aSo // Could be solved with https://forum.dcbase.org/viewtopic.php?f=55&t=856 (or adding a type flag for all MCN connections) auto smallFree = aSource.hasSlot(UploadSlot::FILESLOT, SLOT_SOURCE_MCN) || smallFileConnections <= 8; if (smallFree) { - dcdebug("UploadManager::parseSlotType: assign small slot for %s\n", aSource.getToken().c_str()); + dcdebug("UploadManager::parseSlotType: assign small slot for %s\n", aSource.getConnectToken().c_str()); return UploadSlot(UploadSlot::FILESLOT, SLOT_SOURCE_MCN); } } // Permanent slot? if (UploadSlot::toType(newSlot) == UploadSlot::USERSLOT) { - dcdebug("UploadManager::parseSlotType: assign permanent slot for %s (%s)\n", aSource.getToken().c_str(), newSlot->source.c_str()); + dcdebug("UploadManager::parseSlotType: assign permanent slot for %s (%s)\n", aSource.getConnectToken().c_str(), newSlot->source.c_str()); return newSlot; } else if (standardSlotsRemaining(aSource.getUser())) { - dcdebug("UploadManager::parseSlotType: assign permanent slot for %s (standard)\n", aSource.getToken().c_str()); + dcdebug("UploadManager::parseSlotType: assign permanent slot for %s (standard)\n", aSource.getConnectToken().c_str()); return UploadSlot(UploadSlot::USERSLOT, SLOT_SOURCE_STANDARD); } @@ -288,13 +288,13 @@ OptionalUploadSlot UploadManager::parseSlotHookedThrow(const UserConnection& aSo auto supportsFree = aSource.isSet(UserConnection::FLAG_SUPPORTS_MINISLOTS); auto allowedFree = aSource.hasSlot(UploadSlot::FILESLOT, SLOT_SOURCE_MINISLOT) || isOP() || getFreeExtraSlots() > 0; if (supportsFree && allowedFree) { - dcdebug("UploadManager::parseSlotType: assign minislot for %s\n", aSource.getToken().c_str()); + dcdebug("UploadManager::parseSlotType: assign minislot for %s\n", aSource.getConnectToken().c_str()); return UploadSlot(UploadSlot::FILESLOT, SLOT_SOURCE_MINISLOT); } } } - dcdebug("UploadManager::parseSlotType: assign slot type %d for %s\n", UploadSlot::toType(newSlot), aSource.getToken().c_str()); + dcdebug("UploadManager::parseSlotType: assign slot type %d for %s\n", UploadSlot::toType(newSlot), aSource.getConnectToken().c_str()); return newSlot; } @@ -645,7 +645,7 @@ void UploadManager::on(AdcCommand::GET, UserConnection* aSource, const AdcComman cmd.addParam("TL1"); } - aSource->send(cmd); + aSource->sendHooked(cmd); startTransfer(u); } @@ -774,7 +774,7 @@ void UploadManager::on(AdcCommand::GFI, UserConnection* aSource, const AdcComman } if (c.getParameters().size() < 2) { - aSource->send(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_PROTOCOL_GENERIC, "Missing parameters")); + aSource->sendHooked(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_PROTOCOL_GENERIC, "Missing parameters")); return; } @@ -784,7 +784,7 @@ void UploadManager::on(AdcCommand::GFI, UserConnection* aSource, const AdcComman if (type == Transfer::names[Transfer::TYPE_FILE]) { try { - aSource->send(ShareManager::getInstance()->getFileInfo(ident, *shareProfile)); + aSource->sendHooked(ShareManager::getInstance()->getFileInfo(ident, *shareProfile)); return; } catch (const ShareException&) { } } diff --git a/airdcpp-core/airdcpp/transfer/upload/UploadQueueManager.cpp b/airdcpp-core/airdcpp/transfer/upload/UploadQueueManager.cpp index 8829aeb1..77e43983 100644 --- a/airdcpp-core/airdcpp/transfer/upload/UploadQueueManager.cpp +++ b/airdcpp-core/airdcpp/transfer/upload/UploadQueueManager.cpp @@ -84,7 +84,7 @@ size_t UploadQueueManager::addFailedUpload(const UserConnection& aSource, const WLock l(cs); auto it = ranges::find_if(uploadQueue, [&](const UserPtr& u) { ++queue_position; return u == aSource.getUser(); }); if (it != uploadQueue.end()) { - it->token = aSource.getToken(); + it->token = aSource.getConnectToken(); for (const auto f: it->files) { if(f->getFile() == aFile) { f->setPos(aPos); @@ -97,7 +97,7 @@ size_t UploadQueueManager::addFailedUpload(const UserConnection& aSource, const if (it == uploadQueue.end()) { ++queue_position; - WaitingUser wu(aSource.getHintedUser(), aSource.getToken()); + WaitingUser wu(aSource.getHintedUser(), aSource.getConnectToken()); wu.files.insert(uqi); uploadQueue.push_back(wu); } else { diff --git a/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.cpp b/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.cpp index 70ea0b2c..dd7549e5 100644 --- a/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.cpp +++ b/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.cpp @@ -155,15 +155,15 @@ void UploadBundleInfoSender::on(DownloadManagerListener::Failed, const Download* void UploadBundleInfoSender::addRunningUserUnsafe(const UBNBundle::Ptr& aBundle, const UserConnection* aSource) noexcept { aBundle->addRunningUser(aSource); - connectionTokenMap[aSource->getToken()] = aBundle; + connectionTokenMap[aSource->getConnectToken()] = aBundle; } void UploadBundleInfoSender::removeRunningUserUnsafe(const UBNBundle::Ptr& aBundle, const UserConnection* aSource, bool aSendRemove) noexcept { if (aBundle->removeRunningUser(aSource, aSendRemove)) { - dbgMsg("removed connection " + aSource->getToken() + " from an info " + aBundle->getBundle()->getName() + " (no bundle connections remaining)", LogMessage::SEV_VERBOSE); + dbgMsg("removed connection " + aSource->getConnectToken() + " from an info " + aBundle->getBundle()->getName() + " (no bundle connections remaining)", LogMessage::SEV_VERBOSE); bundleTokenMap.erase(aBundle->getBundle()->getToken()); } else { - dbgMsg("removed connection " + aSource->getToken() + " from an info " + aBundle->getBundle()->getName() + " (bundle connections remain)", LogMessage::SEV_VERBOSE); + dbgMsg("removed connection " + aSource->getConnectToken() + " from an info " + aBundle->getBundle()->getName() + " (bundle connections remain)", LogMessage::SEV_VERBOSE); } } @@ -172,7 +172,7 @@ void UploadBundleInfoSender::removeRunningUser(const UserConnection* aSource, bo return; } - auto ubnBundle = findInfoByConnectionToken(aSource->getToken()); + auto ubnBundle = findInfoByConnectionToken(aSource->getConnectToken()); if (!ubnBundle) { // Non-bundle download return; @@ -181,7 +181,7 @@ void UploadBundleInfoSender::removeRunningUser(const UserConnection* aSource, bo { WLock l(cs); removeRunningUserUnsafe(ubnBundle, aSource, aSendRemove); - connectionTokenMap.erase(aSource->getToken()); + connectionTokenMap.erase(aSource->getConnectToken()); } } @@ -266,15 +266,15 @@ bool UploadBundleInfoSender::UBNBundle::addRunningUser(const UserConnection* aSo setUserMode(false); } } else { - dcassert(!y->second.contains(aSource->getToken())); + dcassert(!y->second.contains(aSource->getConnectToken())); newBundle = false; } - uploadReports[aSource->getUser()].insert(aSource->getToken()); + uploadReports[aSource->getUser()].insert(aSource->getConnectToken()); // Tell the uploader to connect this token to a correct bundle - auto cmd = getAddCommand(aSource->getToken(), newBundle); - debugMsg("sending add command for info " + bundle->getName() + " (" + string(newBundle ? "complete" : "connect only") + "), connection " + aSource->getToken(), LogMessage::SEV_VERBOSE); + auto cmd = getAddCommand(aSource->getConnectToken(), newBundle); + debugMsg("sending add command for info " + bundle->getName() + " (" + string(newBundle ? "complete" : "connect only") + "), connection " + aSource->getConnectToken(), LogMessage::SEV_VERBOSE); sendUpdate(cmd, aSource->getUser()); if (newBundle) { //add a new upload report @@ -294,8 +294,8 @@ bool UploadBundleInfoSender::UBNBundle::removeRunningUser(const UserConnection* auto y = uploadReports.find(aSource->getUser()); dcassert(y != uploadReports.end()); if (y != uploadReports.end()) { - dcassert(y->second.contains(aSource->getToken())); - y->second.erase(aSource->getToken()); + dcassert(y->second.contains(aSource->getConnectToken())); + y->second.erase(aSource->getConnectToken()); if (y->second.empty()) { uploadReports.erase(aSource->getUser()); if (uploadReports.size() == 1) { @@ -306,8 +306,8 @@ bool UploadBundleInfoSender::UBNBundle::removeRunningUser(const UserConnection* } if (finished || aSendRemove) { - debugMsg("sending " + string(finished ? "finished" : "removal") + " command for info " + bundle->getName() + ", connection " + aSource->getToken(), LogMessage::SEV_VERBOSE); - auto cmd = finished ? getBundleFinishedCommand() : getRemoveCommand(aSource->getToken()); + debugMsg("sending " + string(finished ? "finished" : "removal") + " command for info " + bundle->getName() + ", connection " + aSource->getConnectToken(), LogMessage::SEV_VERBOSE); + auto cmd = finished ? getBundleFinishedCommand() : getRemoveCommand(aSource->getConnectToken()); sendUpdate(cmd, aSource->getUser()); } } @@ -405,9 +405,13 @@ void UploadBundleInfoSender::UBNBundle::setUserMode(bool aSetSingleUser) noexcep void UploadBundleInfoSender::sendUpdate(AdcCommand& aCmd, const UserPtr& aUser) noexcept { // Send in a different thread as most calls are fired from inside a (locked) listener - SearchManager::getInstance()->getUdpServer().addTask([=] { + SearchManager::getInstance()->getUdpServer().addTask([aCmd, this, aUser] { auto cmd = aCmd; - ClientManager::getInstance()->sendUDPHooked(cmd, aUser->getCID(), true, true); + string error; + + ClientManager::OutgoingUDPCommandOptions options(this, true); + options.noCID = true; + ClientManager::getInstance()->sendUDPHooked(cmd, HintedUser(aUser, Util::emptyString), options, error); }); } diff --git a/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.h b/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.h index 4dce93ee..bd021355 100644 --- a/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.h +++ b/airdcpp-core/airdcpp/transfer/upload/upload_bundles/UploadBundleInfoSender.h @@ -106,7 +106,7 @@ class UploadBundleInfoSender: public DownloadManagerListener, public QueueManage void addRunningUserUnsafe(const UBNBundle::Ptr& aBundle, const UserConnection* aSource) noexcept; void removeRunningUserUnsafe(const UBNBundle::Ptr& aBundle, const UserConnection* aSource, bool sendRemove) noexcept; - static void sendUpdate(AdcCommand& aCmd, const UserPtr& aUser) noexcept; + void sendUpdate(AdcCommand& aCmd, const UserPtr& aUser) noexcept; }; }