|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. 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, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#ifndef BRPC_POLICY_RDMA_HANDSHAKE_PROTOCOL_H |
| 19 | +#define BRPC_POLICY_RDMA_HANDSHAKE_PROTOCOL_H |
| 20 | + |
| 21 | +// NOTE: This file is intentionally INDEPENDENT of BRPC_WITH_RDMA. A server may |
| 22 | +// run in TCP mode either because it was built without RDMA, or because RDMA was |
| 23 | +// not enabled at runtime. In both cases an RDMA client that connects to it will |
| 24 | +// send an RDMA handshake magic ("RDMA" for v2, "RDM3" for v3) first. Without |
| 25 | +// special handling the server treats those bytes as an unknown protocol and |
| 26 | +// closes the connection, so the client (blocked reading the server hello) only |
| 27 | +// sees EOF and cannot fall back to TCP. |
| 28 | +// |
| 29 | +// To let the client fall back on the SAME connection, the server recognizes the |
| 30 | +// RDMA handshake as a "first-class" protocol (magic in the first 4 bytes, |
| 31 | +// PROTOCOL_RDMA_HANDSHAKE is ordered before PROTOCOL_HTTP), replies a hello with |
| 32 | +// an incompatible version so the client rejects it and downgrades to TCP, then |
| 33 | +// drains the client's subsequent ACK and lets normal RPC parsing continue. |
| 34 | + |
| 35 | +#include "butil/iobuf.h" |
| 36 | +#include "brpc/input_message_base.h" |
| 37 | +#include "brpc/parse_result.h" |
| 38 | +#include "brpc/socket.h" |
| 39 | + |
| 40 | +namespace brpc { |
| 41 | +namespace policy { |
| 42 | + |
| 43 | +// Parse binary format of rdma handshake. |
| 44 | +ParseResult ParseRdmaHandshake(butil::IOBuf* source, Socket* socket, |
| 45 | + bool read_eof, const void* arg); |
| 46 | + |
| 47 | +// Actions to a rdma handshake request, which is left unimplemented. |
| 48 | +// All requests are processed in the parsing process. This function |
| 49 | +// must be declared since server only enables redis as a server-side |
| 50 | +// protocol when this function is declared. |
| 51 | +void ProcessRdmaHandshake(InputMessageBase* msg); |
| 52 | + |
| 53 | +} // namespace policy |
| 54 | +} // namespace brpc |
| 55 | + |
| 56 | +#endif // BRPC_POLICY_RDMA_HANDSHAKE_PROTOCOL_H |
0 commit comments