Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to build http server #648

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions common/fs-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ chunking_worker (gpointer vdata, gpointer user_data)
if (chunk->result < 0)
goto out;

idx = chunk->offset / seaf->http_server->fixed_block_size;
idx = chunk->offset / seaf->fixed_block_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http-server 里面原有的这些字段需要删掉吧。统一为无论是否编译 http server,都用这里的字段。

memcpy (data->blk_sha1s + idx * CHECKSUM_LENGTH, chunk->checksum, CHECKSUM_LENGTH);

out:
Expand Down Expand Up @@ -688,7 +688,7 @@ split_file_to_block (const char *repo_id,
CDCDescriptor *chunk;
int ret = 0;

n_blocks = (file_size + seaf->http_server->fixed_block_size - 1) / seaf->http_server->fixed_block_size;
n_blocks = (file_size + seaf->fixed_block_size - 1) / seaf->fixed_block_size;
block_sha1s = g_new0 (uint8_t, n_blocks * CHECKSUM_LENGTH);
if (!block_sha1s) {
seaf_warning ("Failed to allocate block_sha1s.\n");
Expand All @@ -708,7 +708,7 @@ split_file_to_block (const char *repo_id,
data.finished_tasks = finished_tasks;

tpool = g_thread_pool_new (chunking_worker, &data,
seaf->http_server->max_indexing_threads, FALSE, NULL);
seaf->max_indexing_threads, FALSE, NULL);
if (!tpool) {
seaf_warning ("Failed to allocate thread pool\n");
ret = -1;
Expand All @@ -719,7 +719,7 @@ split_file_to_block (const char *repo_id,
guint64 len;
guint64 left = (guint64)file_size;
while (left > 0) {
len = ((left >= seaf->http_server->fixed_block_size) ? seaf->http_server->fixed_block_size : left);
len = ((left >= seaf->fixed_block_size) ? seaf->fixed_block_size : left);

chunk = g_new0 (CDCDescriptor, 1);
chunk->offset = offset;
Expand All @@ -739,7 +739,7 @@ split_file_to_block (const char *repo_id,
goto out;
}
if (indexed)
*indexed += seaf->http_server->fixed_block_size;
*indexed += seaf->fixed_block_size;

if ((--n_pending) <= 0) {
if (indexed)
Expand Down
2 changes: 2 additions & 0 deletions common/merge-new.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "common.h"

#include "seafile-session.h"
#include "merge-new.h"
#include "vc-common.h"
Expand Down
10 changes: 10 additions & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,23 @@ seafile_web_query_access_token (const char *token, GError **error)
char *
seafile_query_zip_progress (const char *token, GError **error)
{
#ifdef HAVE_EVHTP
return zip_download_mgr_query_zip_progress (seaf->zip_download_mgr,
token, error);
#else
return NULL;
#endif
}

int
seafile_cancel_zip_task (const char *token, GError **error)
{
#ifdef HAVE_EVHTP
return zip_download_mgr_cancel_zip_task (seaf->zip_download_mgr,
token);
#else
return 0;
#endif
}

int
Expand Down Expand Up @@ -3751,7 +3759,9 @@ seafile_delete_repo_tokens_by_peer_id(const char *email,
return -1;
}

#ifdef HAVE_EVHTP
seaf_http_server_invalidate_tokens(seaf->http_server, tokens);
#endif
g_list_free_full (tokens, (GDestroyNotify)g_free);
return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ AC_ARG_WITH(mysql,
[MYSQL_CONFIG=$with_mysql],
[MYSQL_CONFIG="default_mysql_config"])

AC_ARG_ENABLE(httpserver, AC_HELP_STRING([--enable-httpserver], [enable httpserver]),
[compile_httpserver=$enableval],[compile_httpserver="yes"])

AM_CONDITIONAL([COMPILE_TOOLS], [test "${compile_tools}" = "yes"])
AM_CONDITIONAL([COMPILE_PYTHON], [test "${compile_python}" = "yes"])
AM_CONDITIONAL([COMPILE_FUSE], [test "${compile_fuse}" = "yes"])

AM_CONDITIONAL([WIN32], [test "$bwin32" = "true"])
AM_CONDITIONAL([MACOS], [test "$bmac" = "true"])
AM_CONDITIONAL([LINUX], [test "$blinux" = "true"])
Expand Down Expand Up @@ -260,6 +262,10 @@ if test "${compile_ldap}" = "yes"; then

fi

if test "${compile_httpserver}" = "yes"; then
AC_DEFINE([HAVE_EVHTP], [1], [Define to 1 if httpserver is enabled.])
fi

PKG_CHECK_MODULES(CURL, [libcurl >= $CURL_REQUIRED])
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
Expand Down
2 changes: 2 additions & 0 deletions server/access-file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"

#ifdef HAVE_EVHTP
#define DEBUG_FLAG SEAFILE_DEBUG_HTTP
#include "log.h"

Expand Down Expand Up @@ -1546,3 +1547,4 @@ access_file_init (evhtp_t *htp)

return 0;
}
#endif
2 changes: 2 additions & 0 deletions server/access-file.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef ACCESS_FILE_H
#define ACCESS_FILE_H

#ifdef HAVE_EVHTP
int
access_file_init (evhtp_t *htp);
#endif

#endif
6 changes: 4 additions & 2 deletions server/http-server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"

#ifdef HAVE_EVHTP
#include <pthread.h>
#include <string.h>
#include <jansson.h>
Expand Down Expand Up @@ -63,6 +64,7 @@
struct _HttpServer {
evbase_t *evbase;
evhtp_t *evhtp;
event_t *reap_timer;
pthread_t thread_id;

GHashTable *token_cache;
Expand All @@ -74,8 +76,6 @@ struct _HttpServer {
GHashTable *vir_repo_info_cache;
pthread_mutex_t vir_repo_info_cache_lock;

event_t *reap_timer;

GThreadPool *compute_fs_obj_id_pool;

GHashTable *fs_obj_ids;
Expand Down Expand Up @@ -3154,3 +3154,5 @@ seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server,
pthread_mutex_unlock (&htp_server->priv->token_cache_lock);
return 0;
}

#endif
2 changes: 2 additions & 0 deletions server/http-server.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H

#ifdef HAVE_EVHTP
#include <glib.h>

struct _SeafileSession;
Expand Down Expand Up @@ -38,5 +39,6 @@ seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server,

void
send_statistic_msg (const char *repo_id, char *user, char *operation, guint64 bytes);
#endif

#endif
2 changes: 1 addition & 1 deletion server/index-blocks-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ index_blocks_mgr_new (SeafileSession *session)

priv->idx_tpool = g_thread_pool_new (start_index_task,
priv,
session->http_server->max_index_processing_threads,
session->max_index_processing_threads,
FALSE, &error);
if (!priv->idx_tpool) {
if (error) {
Expand Down
2 changes: 2 additions & 0 deletions server/pack-dir.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.h"
#ifdef HAVE_EVHTP

#define DEBUG_FLAG SEAFILE_DEBUG_HTTP
#include "log.h"
Expand Down Expand Up @@ -481,3 +482,4 @@ pack_files (const char *store_id,

return ret;
}
#endif
2 changes: 2 additions & 0 deletions server/pack-dir.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef PACK_DIR_H
#define PACK_DIR_H
#ifdef HAVE_EVHTP

/* Pack a seafile directory to a zipped archive, saved in a temporary file.
Return the path of this temporary file.
Expand All @@ -23,5 +24,6 @@ pack_files (const char *store_id,
SeafileCrypt *crypt,
gboolean is_windows,
Progress *progress);
#endif

#endif
4 changes: 4 additions & 0 deletions server/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,9 @@ seaf_repo_manager_delete_token (SeafRepoManager *mgr,

GList *tokens = NULL;
tokens = g_list_append (tokens, g_strdup(token));
#ifdef HAVE_EVHTP
seaf_http_server_invalidate_tokens (seaf->http_server, tokens);
#endif
g_list_free_full (tokens, (GDestroyNotify)g_free);

return 0;
Expand Down Expand Up @@ -1838,7 +1840,9 @@ seaf_repo_manager_delete_repo_tokens_by_email (SeafRepoManager *mgr,
goto out;
}

#ifdef HAVE_EVHTP
seaf_http_server_invalidate_tokens (seaf->http_server, token_list);
#endif

out:
g_list_free_full (token_list, (GDestroyNotify)g_free);
Expand Down
80 changes: 69 additions & 11 deletions server/seafile-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,67 @@

#define DEFAULT_THREAD_POOL_SIZE 500

#define DEFAULT_FIXED_BLOCK_SIZE ((gint64)1 << 23) /* 8MB */

static void
load_fileserver_config (SeafileSession *session)
{
int web_token_expire_time;
int max_index_processing_threads;
int fixed_block_size_mb;
int max_indexing_threads;

session->go_fileserver = g_key_file_get_boolean (session->config,
"fileserver", "use_go_fileserver",
NULL);
if (session->go_fileserver) {
char *type = NULL;
type = g_key_file_get_string (session->config, "database", "type", NULL);
if (!type || g_strcmp0 (type, "mysql") != 0) {
session->go_fileserver = FALSE;
}
g_free (type);
}

web_token_expire_time = g_key_file_get_integer (session->config,
"fileserver", "web_token_expire_time",
NULL);
if (web_token_expire_time <= 0) {
session->web_token_expire_time = 3600;
} else {
session->web_token_expire_time = web_token_expire_time;
}

max_index_processing_threads = g_key_file_get_integer (session->config,
"fileserver", "max_index_processing_threads",
NULL);
if (max_index_processing_threads <= 0) {
session->max_index_processing_threads = 3;
} else {
session->max_index_processing_threads = max_index_processing_threads;
}

fixed_block_size_mb = g_key_file_get_integer (session->config,
"fileserver", "fixed_block_size",
NULL);
if (fixed_block_size_mb <= 0){
session->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE;
} else {
session->fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20);
}

max_indexing_threads = g_key_file_get_integer (session->config,
"fileserver", "max_indexing_threads",
NULL);
if (max_indexing_threads <= 0) {
session->max_indexing_threads = 1;
} else {
session->max_indexing_threads = max_indexing_threads;
}

return;
}

SeafileSession *
seafile_session_new(const char *central_config_dir,
const char *seafile_dir,
Expand Down Expand Up @@ -115,17 +176,7 @@ seafile_session_new(const char *central_config_dir,
"general", "cloud_mode",
NULL);

session->go_fileserver = g_key_file_get_boolean (config,
"fileserver", "use_go_fileserver",
NULL);
if (session->go_fileserver) {
char *type = NULL;
type = g_key_file_get_string (config, "database", "type", NULL);
if (!type || g_strcmp0 (type, "mysql") != 0) {
session->go_fileserver = FALSE;
}
g_free (type);
}
load_fileserver_config (session);

notif_enabled = g_key_file_get_boolean (config,
"notification", "enabled",
Expand Down Expand Up @@ -201,13 +252,15 @@ seafile_session_new(const char *central_config_dir,
if (!session->mq_mgr)
goto onerror;

#ifdef HAVE_EVHTP
session->http_server = seaf_http_server_new (session);
if (!session->http_server)
goto onerror;

session->zip_download_mgr = zip_download_mgr_new ();
if (!session->zip_download_mgr)
goto onerror;
#endif

session->index_blocks_mgr = index_blocks_mgr_new (session);
if (!session->index_blocks_mgr)
Expand Down Expand Up @@ -324,10 +377,15 @@ seafile_session_start (SeafileSession *session)
}

if (!session->go_fileserver) {
#ifdef HAVE_EVHTP
if (seaf_http_server_start (session->http_server) < 0) {
seaf_warning ("Failed to start http server thread.\n");
return -1;
}
#else
seaf_warning ("Failed to start http server thread, please use go fileserver.\n");
return -1;
#endif
}

return 0;
Expand Down
7 changes: 7 additions & 0 deletions server/seafile-session.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ struct _SeafileSession {

int cloud_mode;

#ifdef HAVE_EVHTP
HttpServerStruct *http_server;
ZipDownloadMgr *zip_download_mgr;
#endif
IndexBlksMgr *index_blocks_mgr;

gboolean create_tables;
gboolean ccnet_create_tables;

gboolean go_fileserver;

int web_token_expire_time;
int max_index_processing_threads;
gint64 fixed_block_size;
int max_indexing_threads;

// For notification server
NotifManager *notif_mgr;
char *private_key;
Expand Down
2 changes: 2 additions & 0 deletions server/upload-file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"

#ifdef HAVE_EVHTP
#define DEBUG_FLAG SEAFILE_DEBUG_HTTP
#include "log.h"

Expand Down Expand Up @@ -2697,3 +2698,4 @@ upload_file_init (evhtp_t *htp, const char *http_temp_dir)

return 0;
}
#endif
2 changes: 2 additions & 0 deletions server/upload-file.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef UPLOAD_FILE_H
#define UPLOAD_FILE_H

#ifdef HAVE_EVHTP
int
upload_file_init (evhtp_t *evhtp, const char *http_temp_dir);
#endif

#endif
Loading
Loading