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 all 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
70 changes: 4 additions & 66 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 @@ -150,11 +150,7 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
char *host = NULL;
int port = 0;
int worker_threads;
int web_token_expire_time;
int fixed_block_size_mb;
char *encoding;
int max_indexing_threads;
int max_index_processing_threads;
char *cluster_shared_temp_file_mode = NULL;

host = fileserver_config_get_string (session->config, HOST, &error);
Expand Down Expand Up @@ -198,66 +194,6 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
}
seaf_message ("fileserver: worker_threads = %d\n", htp_server->worker_threads);

fixed_block_size_mb = fileserver_config_get_integer (session->config,
"fixed_block_size",
&error);
if (error){
htp_server->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE;
g_clear_error(&error);
} else {
if (fixed_block_size_mb <= 0)
htp_server->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE;
else
htp_server->fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20);
}
seaf_message ("fileserver: fixed_block_size = %"G_GINT64_FORMAT"\n",
htp_server->fixed_block_size);

web_token_expire_time = fileserver_config_get_integer (session->config,
"web_token_expire_time",
&error);
if (error){
htp_server->web_token_expire_time = 3600; /* default 3600s */
g_clear_error(&error);
} else {
if (web_token_expire_time <= 0)
htp_server->web_token_expire_time = 3600; /* default 3600s */
else
htp_server->web_token_expire_time = web_token_expire_time;
}
seaf_message ("fileserver: web_token_expire_time = %d\n",
htp_server->web_token_expire_time);

max_indexing_threads = fileserver_config_get_integer (session->config,
"max_indexing_threads",
&error);
if (error) {
htp_server->max_indexing_threads = DEFAULT_MAX_INDEXING_THREADS;
g_clear_error (&error);
} else {
if (max_indexing_threads <= 0)
htp_server->max_indexing_threads = DEFAULT_MAX_INDEXING_THREADS;
else
htp_server->max_indexing_threads = max_indexing_threads;
}
seaf_message ("fileserver: max_indexing_threads = %d\n",
htp_server->max_indexing_threads);

max_index_processing_threads = fileserver_config_get_integer (session->config,
"max_index_processing_threads",
&error);
if (error) {
htp_server->max_index_processing_threads = DEFAULT_MAX_INDEX_PROCESSING_THREADS;
g_clear_error (&error);
} else {
if (max_index_processing_threads <= 0)
htp_server->max_index_processing_threads = DEFAULT_MAX_INDEX_PROCESSING_THREADS;
else
htp_server->max_index_processing_threads = max_index_processing_threads;
}
seaf_message ("fileserver: max_index_processing_threads= %d\n",
htp_server->max_index_processing_threads);

cluster_shared_temp_file_mode = fileserver_config_get_string (session->config,
"cluster_shared_temp_file_mode",
&error);
Expand Down Expand Up @@ -3154,3 +3090,5 @@ seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server,
pthread_mutex_unlock (&htp_server->priv->token_cache_lock);
return 0;
}

#endif
6 changes: 2 additions & 4 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 All @@ -16,11 +17,7 @@ struct _HttpServerStruct {
int bind_port;
char *http_temp_dir; /* temp dir for file upload */
char *windows_encoding;
gint64 fixed_block_size;
int web_token_expire_time;
int max_indexing_threads;
int worker_threads;
int max_index_processing_threads;
int cluster_shared_temp_file_mode;
};

Expand All @@ -38,5 +35,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
Loading
Loading