wwbmmm opened a new pull request, #3766: URL: https://github.com/apache/brpc/pull/3766
### What problem does this PR solve? Issue Number: resolve N/A Problem Summary: `IsPossiblyRtmp` claimed any connection whose first byte is 0x03 (the rtmp C0 version). RTMP is sniffed before thrift/http/redis/nshead and `ParseRtmpMessage` permanently binds the parsing context once it matches, so a frame of another protocol co-hosted on the same port that happens to start with 0x03 (for example a thrift request) was captured by the rtmp handshake state machine and the connection was broken. ### What is changed and the side effects? Changed: - `IsPossiblyRtmp` now requires the whole 1537-byte C0+C1 before claiming the connection and validates the version field of C1: zero for the simple handshake, `adobe_hs::FP_VERSION` or `adobe_hs::FMS_VERSION` for the complex one. Fewer bytes return NOT_ENOUGH_DATA and an unsupported version returns TRY_OTHERS, so the other protocols sharing the port get a chance. - Simplified rtmp (C0 followed by the "BDMS" magic number) is still recognized from the first 5 bytes, because it carries no C1. - Reordering the sniff list was not chosen: another protocol would then be able to capture a real rtmp handshake, and validating the content keeps the decision local to the rtmp parser. - The handshake path itself (`adobe_hs::C1::Load` and the fallback to simple handshaking) is untouched. Side effects: - Performance effects: negligible. Only the first 9 bytes are inspected, and when the first byte is 0x03 the parser waits for 1537 buffered bytes before it either claims or rejects the connection. - Breaking backward compatibility: none. Client and server keeps working with simple, complex and simplified handshaking. --- ### Check List: - Please make sure your changes are compilable. - When providing us with a new feature, it is best to add related tests. - Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md). Tests: - `cmake -S . -B build -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=OFF -DBRPC_SYSTEM_GTEST_SOURCE_DIR=/usr/src/googletest && make -j6 brpc_rtmp_unittest` - `./test/brpc_rtmp_unittest` (36 cases, all passed). New cases: `payload_starting_with_c0_version_tries_others`, `simple_handshake_accepted_after_c0c1_complete`, `complex_handshake_c1_is_accepted`. --- 🤖 This PR was automatically created by brpc-oncall -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
