blob: 8074484f1977de3803a4ba176f48d5140bf272c3 [file] [log] [blame] [view]
Mark Slee54b7ab92007-03-06 00:06:27 +00001Thrift C++ Software Library
2
Roger Meier6370cfd2014-05-04 22:21:58 +02003# License
Bryan Duxburydef30a62009-04-08 00:19:37 +00004
5Licensed to the Apache Software Foundation (ASF) under one
6or more contributor license agreements. See the NOTICE file
7distributed with this work for additional information
8regarding copyright ownership. The ASF licenses this file
9to you under the Apache License, Version 2.0 (the
10"License"); you may not use this file except in compliance
11with the License. You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing,
16software distributed under the License is distributed on an
17"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18KIND, either express or implied. See the License for the
19specific language governing permissions and limitations
20under the License.
Mark Slee54b7ab92007-03-06 00:06:27 +000021
Roger Meier6370cfd2014-05-04 22:21:58 +020022# Using Thrift with C++
Mark Slee54b7ab92007-03-06 00:06:27 +000023
24The Thrift C++ libraries are built using the GNU tools. Follow the instructions
Roger Meier6370cfd2014-05-04 22:21:58 +020025in the top-level README.md
Mark Slee54b7ab92007-03-06 00:06:27 +000026
Roger Meier6370cfd2014-05-04 22:21:58 +020027In case you do not want to open another README.md file, do this thrift src:
28
29 ./bootstrap.sh
30 ./configure (--with-boost=/usr/local)
31 make
32 sudo make install
Mark Slee54b7ab92007-03-06 00:06:27 +000033
34Thrift is divided into two libraries.
35
James E. King IIIc9ac8d22019-01-07 16:46:45 -050036* libthrift - The core Thrift library contains all the core Thrift code. This requires
37 openssl, pthreads, and librt.
Mark Slee54b7ab92007-03-06 00:06:27 +000038
Roger Meier6370cfd2014-05-04 22:21:58 +020039* libthriftnb - This library contains the Thrift nonblocking server, which uses libevent.
Mark Slee54b7ab92007-03-06 00:06:27 +000040 To link this library you will also need to link libevent.
41
Roger Meier6370cfd2014-05-04 22:21:58 +020042## Linking Against Thrift
Mark Slee54b7ab92007-03-06 00:06:27 +000043
44After you build and install Thrift the libraries are installed to
45/usr/local/lib by default. Make sure this is in your LDPATH.
46
47On Linux, the best way to do this is to ensure that /usr/local/lib is in
48your /etc/ld.so.conf and then run /sbin/ldconfig.
49
50Depending upon whether you are linking dynamically or statically and how
51your build environment it set up, you may need to include additional
52libraries when linking against thrift, such as librt and/or libpthread. If
53you are using libthriftnb you will also need libevent.
54
Roger Meier6370cfd2014-05-04 22:21:58 +020055## Dependencies
Mark Slee54b7ab92007-03-06 00:06:27 +000056
James E. King IIIc9ac8d22019-01-07 16:46:45 -050057C++11 is required at a minimum. C++03/C++98 are not supported after version 0.12.0.
Mark Slee54b7ab92007-03-06 00:06:27 +000058
James E. King IIIc9ac8d22019-01-07 16:46:45 -050059Boost is required to run the C++ unit tests. It is not necessary to link against
60the runtime library.
61
62libevent (for libthriftnb only) - most linux distributions have dev packages for this:
Mark Slee54b7ab92007-03-06 00:06:27 +000063http://monkey.org/~provos/libevent/
Roger Meier6370cfd2014-05-04 22:21:58 +020064
65# Using Thrift with C++ on Windows
66
James E. King, III82ae9572017-08-05 12:23:54 -040067Both the autoconf and cmake build systems are able to automatically detect many
68system configurations without the need to specify library locations, however if
69you run into problems or want to redirect thrift to build and link against your
70own provided third party libraries:
Roger Meier6370cfd2014-05-04 22:21:58 +020071
Roger Meierfaf52db2014-06-09 22:41:06 +020072BOOST_ROOT : For boost, e.g. D:\boost_1_55_0
73OPENSSL_ROOT_DIR : For OpenSSL, e.g. D:\OpenSSL-Win32
74
75only required by libthriftnb:
76
77LIBEVENT_ROOT_DIR : For Libevent e.g. D:\libevent-2.0.21-stable
78
79See /3rdparty.user for more details.
Roger Meier6370cfd2014-05-04 22:21:58 +020080
James E. King, III82ae9572017-08-05 12:23:54 -040081The same linking guidelines described above for libthriftnb apply to windows as well.
Roger Meier6370cfd2014-05-04 22:21:58 +020082
83## Linking Against Thrift
84
85You need to link your project that uses thrift against all the thrift
James E. King IIIc9ac8d22019-01-07 16:46:45 -050086dependencies; in the case of libthrift, openssl, pthreads, and librt and for
Roger Meier6370cfd2014-05-04 22:21:58 +020087libthriftnb, libevent.
88
89In the project properties you must also set HAVE_CONFIG_H as force include
James E. King IIIc9ac8d22019-01-07 16:46:45 -050090the config header: "windows/config.h"
Roger Meier6370cfd2014-05-04 22:21:58 +020091
92## Dependencies
93
Roger Meier6370cfd2014-05-04 22:21:58 +020094libevent (for libthriftnb only)
95http://monkey.org/~provos/libevent/
96
Roger Meier6370cfd2014-05-04 22:21:58 +020097## Windows version compatibility
98
cyyf6460fa2019-01-15 14:30:30 +080099The Thrift library targets Windows 7 or latter versions. The supports for windows XP and Vista are avaiable until 0.12.0.
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500100
JackBoosY829b7d32020-01-16 00:38:15 -0800101## Thrift and the VCPKG Package manager
102
103You can download and install thrift using the
104[vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
105
106 git clone https://github.com/Microsoft/vcpkg.git
107 cd vcpkg
108 ./bootstrap-vcpkg.sh
109 ./vcpkg integrate install
110 ./vcpkg install thrift
111
112The thrift port in vcpkg is kept up to date by Microsoft team members
113and community contributors. The Apache Thrift project is *not* responsible
114for the vcpkg port. Therefore, if the version is out of date, please
115[create an issue or pull request](https://github.com/Microsoft/vcpkg)
116on the vcpkg repository.
117
118
Roger Meier6370cfd2014-05-04 22:21:58 +0200119## Named Pipes
120
121Named Pipe transport has been added in the TPipe and TPipeServer classes. This
122is currently Windows-only. Named pipe transport for *NIX has not been
123implemented. Domain sockets are a better choice for local IPC under non-Windows
124OS's. *NIX named pipes only support 1:1 client-server connection.
125
126# Thrift/SSL
127
Roger Meier4fba9d22014-05-04 22:34:44 +0200128## Scope
Roger Meier6370cfd2014-05-04 22:21:58 +0200129
Roger Meier4fba9d22014-05-04 22:34:44 +0200130This SSL only supports blocking mode socket I/O. It can only be used with
131TSimpleServer, TThreadedServer, and TThreadPoolServer.
Roger Meier6370cfd2014-05-04 22:21:58 +0200132
Roger Meier4fba9d22014-05-04 22:34:44 +0200133## Implementation
Roger Meier6370cfd2014-05-04 22:21:58 +0200134
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500135There are two main classes TSSLSocketFactory and TSSLSocket. Instances of
Roger Meier4fba9d22014-05-04 22:34:44 +0200136TSSLSocket are always created from TSSLSocketFactory.
Roger Meier6370cfd2014-05-04 22:21:58 +0200137
Roger Meier4fba9d22014-05-04 22:34:44 +0200138## How to use SSL APIs
Roger Meier6370cfd2014-05-04 22:21:58 +0200139
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500140See the TestClient.cpp and TestServer.cpp files for examples.
Roger Meier6370cfd2014-05-04 22:21:58 +0200141
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500142### AccessManager (certificate validation)
Roger Meier4fba9d22014-05-04 22:34:44 +0200143
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500144An example of certificate validation can be found in TestServer.cpp.
Roger Meier6370cfd2014-05-04 22:21:58 +0200145
Roger Meier4fba9d22014-05-04 22:34:44 +0200146AccessManager defines a callback interface. It has three callback methods:
Roger Meier6370cfd2014-05-04 22:21:58 +0200147
Roger Meier4fba9d22014-05-04 22:34:44 +0200148(a) Decision verify(const sockaddr_storage& sa);
Roger Meier6370cfd2014-05-04 22:21:58 +0200149
Roger Meier4fba9d22014-05-04 22:34:44 +0200150(b) Decision verify(const string& host, const char* name, int size);
Roger Meier6370cfd2014-05-04 22:21:58 +0200151
Roger Meier4fba9d22014-05-04 22:34:44 +0200152(c) Decision verify(const sockaddr_storage& sa, const char* data, int size);
Roger Meier6370cfd2014-05-04 22:21:58 +0200153
Roger Meier4fba9d22014-05-04 22:34:44 +0200154After SSL handshake completes, additional checks are conducted. Application
155is given the chance to decide whether or not to continue the conversation
156with the remote. Application is queried through the above three "verify"
157method. They are called at different points of the verification process.
Roger Meier6370cfd2014-05-04 22:21:58 +0200158
Roger Meier4fba9d22014-05-04 22:34:44 +0200159Decisions can be one of ALLOW, DENY, and SKIP. ALLOW and DENY means the
160conversation should be continued or disconnected, respectively. ALLOW and
161DENY decision stops the verification process. SKIP means there's no decision
162based on the given input, continue the verification process.
Roger Meier6370cfd2014-05-04 22:21:58 +0200163
Roger Meier4fba9d22014-05-04 22:34:44 +0200164First, (a) is called with the remote IP. It is called once at the beginning.
165"sa" is the IP address of the remote peer.
Roger Meier6370cfd2014-05-04 22:21:58 +0200166
Roger Meier4fba9d22014-05-04 22:34:44 +0200167Then, the certificate of remote peer is loaded. SubjectAltName extensions
168are extracted and sent to application for verification. When a DNS
169subjectAltName field is extracted, (b) is called. When an IP subjectAltName
170field is extracted, (c) is called.
Roger Meier6370cfd2014-05-04 22:21:58 +0200171
Roger Meier4fba9d22014-05-04 22:34:44 +0200172The "host" in (b) is the value from TSocket::getHost() if this is a client
173side socket, or TSocket::getPeerHost() if this is a server side socket. The
174reason is client side socket initiates the connection. TSocket::getHost()
175is the remote host name. On server side, the remote host name is unknown
176unless it's retrieved through TSocket::getPeerHost(). Either way, "host"
177should be the remote host name. Keep in mind, if TSocket::getPeerHost()
178failed, it would return the remote host name in numeric format.
Roger Meier6370cfd2014-05-04 22:21:58 +0200179
Roger Meier4fba9d22014-05-04 22:34:44 +0200180If all subjectAltName extensions were "skipped", the common name field would
181be checked. It is sent to application through (c), where "sa" is the remote
182IP address. "data" is the IP address extracted from subjectAltName IP
183extension, and "size" is the length of the extension data.
Roger Meier6370cfd2014-05-04 22:21:58 +0200184
Roger Meier4fba9d22014-05-04 22:34:44 +0200185If any of the above "verify" methods returned a decision ALLOW or DENY, the
186verification process would be stopped.
Roger Meier6370cfd2014-05-04 22:21:58 +0200187
Roger Meier4fba9d22014-05-04 22:34:44 +0200188If any of the above "verify" methods returned SKIP, that decision would be
189ignored and the verification process would move on till the last item is
190examined. At that point, if there's still no decision, the connection is
191terminated.
Roger Meier6370cfd2014-05-04 22:21:58 +0200192
Roger Meier4fba9d22014-05-04 22:34:44 +0200193Thread safety, an access manager should not store state information if it's
194to be used by many SSL sockets.
Roger Meier6370cfd2014-05-04 22:21:58 +0200195
Roger Meier4fba9d22014-05-04 22:34:44 +0200196## SIGPIPE signal
Roger Meier6370cfd2014-05-04 22:21:58 +0200197
Roger Meier4fba9d22014-05-04 22:34:44 +0200198Applications running OpenSSL over network connections may crash if SIGPIPE
199is not ignored. This happens when they receive a connection reset by remote
200peer exception, which somehow triggers a SIGPIPE signal. If not handled,
201this signal would kill the application.
Roger Meier6370cfd2014-05-04 22:21:58 +0200202
Roger Meier4fba9d22014-05-04 22:34:44 +0200203## How to run test client/server in SSL mode
Roger Meier6370cfd2014-05-04 22:21:58 +0200204
Roger Meier4fba9d22014-05-04 22:34:44 +0200205The server and client expects the followings from the directory /test/
Roger Meier6370cfd2014-05-04 22:21:58 +0200206
Roger Meier4fba9d22014-05-04 22:34:44 +0200207- keys/server.crt
208- keys/server.key
209- keys/CA.pem
Roger Meier6370cfd2014-05-04 22:21:58 +0200210
Roger Meier4fba9d22014-05-04 22:34:44 +0200211The file names are hard coded in the source code. You need to create these
212certificates before you can run the test code in SSL mode. Make sure at least
213one of the followings is included in "keys/server.crt",
Roger Meier6370cfd2014-05-04 22:21:58 +0200214
Roger Meier4fba9d22014-05-04 22:34:44 +0200215- subjectAltName, DNS localhost
216- subjectAltName, IP 127.0.0.1
217- common name, localhost
Roger Meier6370cfd2014-05-04 22:21:58 +0200218
Roger Meier4fba9d22014-05-04 22:34:44 +0200219Run within /test/ folder,
Roger Meier6370cfd2014-05-04 22:21:58 +0200220
Roger Meier4fba9d22014-05-04 22:34:44 +0200221 ./cpp/TestServer --ssl &
222 ./cpp/TestClient --ssl
Roger Meier6370cfd2014-05-04 22:21:58 +0200223
Roger Meier4fba9d22014-05-04 22:34:44 +0200224If "-h <host>" is used to run client, the above "localhost" in the above
225keys/server.crt has to be replaced with that host name.
226
227## TSSLSocketFactory::randomize()
228
229The default implementation of OpenSSLSocketFactory::randomize() simply calls
230OpenSSL's RAND_poll() when OpenSSL library is first initialized.
231
232The PRNG seed is key to the application security. This method should be
233overridden if it's not strong enough for you.
James E. King, III7bc94312017-03-31 21:25:20 -0400234
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500235# Deprecations
236
237## 0.12.0
238
239Support for C++03/C++98 was deprecated.
240Support for Boost at runtime was deprecated.
241
James E. King, III7bc94312017-03-31 21:25:20 -0400242# Breaking Changes
243
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500244## 1.0.0
245
James E. King III17355422019-01-11 23:06:08 -0500246THRIFT-4720:
cyyf6460fa2019-01-15 14:30:30 +0800247The classes Monitor and TimerManager now use std::chrono::milliseconds for timeout, the methods and functions involving THRIFT_TIMESPEC and timeval have been removed, the related tests have been modified.
248
249Support for Windows XP/Vista has been dropped.
250
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500251Support for C++03/C++98 has been dropped. Use version 0.12.0 to support that
252language level. As a consequence, boost is no longer required as a runtime
253library depenedency, but is is still required to build the runtime library
254and to run the unit tests. We will work towards removing boost as a
255build dependency for folks who just want to build the runtime and not
256run the tests. This means the header thrift/stdcxx.h has been removed and
257anything that relied on it has been changed to directly use C++11 concepts.
258
James E. King III17355422019-01-11 23:06:08 -0500259THRIFT-4730:
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500260The classes BoostThreadFactory, PosixThreadFactory, StdThreadFactory, and
James E. King III278528c2019-01-11 12:17:44 -0500261PlatformThreadFactory have been removed, and we will use a ThreadFactory
262based on C++11 (essentially StdThreadFactory was renamed ThreadFactory).
263
James E. King III17355422019-01-11 23:06:08 -0500264THRIFT-4732:
James E. King III278528c2019-01-11 12:17:44 -0500265The CMake build options WITH_SHARED_LIBS and WITH_STATIC_LIBS are deprecated.
266The project no longer performs a side-by-side static and shared build; you
267tell CMake through BUILD_SHARED_LIBS whether to make shared or static
268libraries now. This is CMake standard behavior.
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500269
James E. King III17355422019-01-11 23:06:08 -0500270THRIFT-4735:
271Qt4 support was removed.
272
Sebastian Zenker042580f2019-01-29 15:48:12 +0100273THRIFT-4762:
274Added `const` specifier to `TTransport::getOrigin()`. This changes its function signature.
275It's recommended to add the `override` specifier in implementations derived from `TTransport`.
276
James E. King, III7bc94312017-03-31 21:25:20 -0400277## 0.11.0
278
James E. King, III82ae9572017-08-05 12:23:54 -0400279Older versions of thrift depended on the <boost/smart_ptr.hpp> classes which
280were used in thrift headers to define interfaces. Thrift now detects C++11
281at build time and will prefer to use <memory> classes from C++11 instead.
282You can force the library to build with boost memory classes by defining the
283preprocessor macro `FORCE_BOOST_SMART_PTR`. (THRIFT-2221)
284
James E. King, III7bc94312017-03-31 21:25:20 -0400285In the pthread mutex implementation, the contention profiling code was enabled
286by default in all builds. This changed to be disabled by default. (THRIFT-4151)
James E. King, III7f5a8c22017-04-04 09:36:38 -0400287
288In older releases, if a TSSLSocketFactory's lifetime was not at least as long
289as the TSSLSockets it created, we silently reverted openssl to unsafe multithread behavior
290and so the results were undefined. Changes were made in 0.11.0 that cause either an
291assertion or a core instead of undefined behavior. The lifetime of a TSSLSocketFactory
292*must* be longer than any TSSLSocket that it creates, otherwise openssl will be cleaned
293up too early. If the static boolean is set to disable openssl initialization and
294cleanup and leave it up to the consuming application, this requirement is not needed.
295(THRIFT-4164)
296