fixed SSL thread safety problem

This commit is contained in:
Fufu Fang 2018-07-24 22:16:13 +01:00
parent d0cbd8b3ed
commit 6c77e2049b
2 changed files with 14 additions and 8 deletions

View File

@ -5,7 +5,19 @@ Have you ever wanted to mount those HTTP directory listings as if it was a parti
The performance of the program is excellent, due to the use of curl-multi interface. HTTP connections are reused, and HTTP pipelining is used when available. I haven't benchmarked it, but I feel this is faster than ``rclone mount``. The FUSE component itself also runs in multithreaded mode.
## Compilation
This program was developed under Debian Stretch. If you are using the same operation system as me, you need ``libgumbo-dev``, ``libfuse-dev`` and ``libcurl4-openssl-dev``.
This program was developed under Debian Stretch. If you are using the same operation system as me, you need ``libgumbo-dev``, ``libfuse-dev``, ``libssl1.0-dev`` and ``libcurl4-openssl-dev``.
If you run Debian Stretch and get warnings that look like this:
network.c:70:22: warning: thread_id defined but not used [-Wunused-function]
static unsigned long thread_id(void)
^~~~~~~~~
network.c:57:13: warning: lock_callback defined but not used [-Wunused-function]
static void lock_callback(int mode, int type, char *file, int line)
^~~~~~~~~~~~~
/usr/bin/ld: warning: libcrypto.so.1.0.2, needed by /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libcurl.so, may conflict with libcrypto.so.1.1
Then you need to check if ``libssl1.0-dev`` had been installed properly. If you get these compilation warnings, this program will ocassionally crash if you connect to HTTPS website. This is because OpenSSL 1.0.2 needs those functions for thread safety, whereas OpenSSL 1.1 does not. If you have ``libssl-dev`` rather than ``libssl1.0-dev`` installed, those call back functions will not be linked properly.
## Usage
@ -21,8 +33,6 @@ The SSL engine version string looks something like this:
libcurl SSL engine: OpenSSL/1.0.2l
Finally SSL support seems to be unstable right now, if you mount a HTTPS website, it might randomly crash. Non-HTTPS website seems to have better performance as well.
## The Technical Details
I noticed that most HTTP directory listings don't provide the file size for the web page itself. I suppose this makes perfect sense, as they are generated on the fly. Whereas the actual files have got file sizes. So the listing pages can be treated as folders, and the rest are files.

View File

@ -11,7 +11,6 @@
#include <stdio.h>
#include <unistd.h>
#define HTTP_OK 200
#define HTTP_PARTIAL_CONTENT 206
#define HTTP_RANGE_NOT_SATISFIABLE 416
@ -53,10 +52,8 @@ static pthread_mutex_t *crypto_lockarray;
static pthread_mutex_t curl_lock;
/* -------------------------- Functions ---------------------------------- */
#pragma GCC diagnostic ignored "-Wunused-function"
static void lock_callback(int mode, int type, char *file, int line)
{
#pragma GCC diagnostic pop
(void)file;
(void)line;
if(mode & CRYPTO_LOCK) {
@ -66,10 +63,9 @@ static void lock_callback(int mode, int type, char *file, int line)
pthread_mutex_unlock(&(crypto_lockarray[type]));
}
}
#pragma GCC diagnostic ignored "-Wunused-function"
static unsigned long thread_id(void)
{
#pragma GCC diagnostic pop
unsigned long ret;
ret = (unsigned long)pthread_self();