Commits

Daniel Poelzleithner committed dbcf7ae

added missing files

Comments (0)

Files changed (3)

src/CMakeLists.txt

+#TARGET_LINK_LIBRARIES( ${DNET} )
+
+IF (CMAKE_C_FLAGS_DEBUG)
+    add_definitions(-DDEBUG)
+ENDIF (CMAKE_C_FLAGS_DEBUG)
+
+
+add_executable (dssd dssd.c hash.c file_backend.c common.c lua.c uci.c)
+
+add_library(libhash STATIC hash.c lookup3.c)
+add_library(libbackend STATIC file_backend.c tc_backend.c backends.c)
+target_link_libraries(libbackend tokyocabinet pthread uci ucimap)
+
+target_link_libraries(dssd dnet libhash libbackend ${LUA_LIBRARIES})
+/*
+ * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+//#include "config.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/syscall.h>
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <pthread.h>
+
+#include <netinet/in.h>
+
+#include "dnet/packet.h"
+#include "dnet/interface.h"
+
+#include "dssd.h"
+#include "hash.h"
+#include "backends.h"
+#include "common.h"
+
+#ifndef __unused
+#define __unused	__attribute__ ((unused))
+#endif
+
+static int dnet_background(void)
+{
+	pid_t pid;
+
+	pid = fork();
+	if (pid == -1) {
+		fprintf(stderr, "Failed to fork to background: %s.\n", strerror(errno));
+		return -1;
+	}
+
+	if (pid != 0) {
+		printf("Daemon pid: %d.\n", pid);
+		exit(0);
+	}
+
+	setsid();
+
+	close(1);
+	close(2);
+
+	return 0;
+}
+
+static void dnet_usage(char *p)
+{
+	fprintf(stderr, "Usage: %s\n"
+            " -n config            - use config name (dssd by default)\n"
+            " -p path              - path to config files (/etc/config by default)\n"
+			" -l log               - log file. Default: disabled\n"
+			" -m mask              - log events mask\n", p);
+
+
+/*
+			" -a addr:port:family  - creates a node with given network address\n"
+			" -r addr:port:family  - adds a route to the given node\n"
+			" -j <join>            - join the network\n"
+			"                        become a fair node which may store data from the other nodes\n"
+			" -b <BDB>             - use BerkeleyDB (if present) IO storage backend\n"
+			" -t <TokyoCabinet>    - use TokyoCabinet (if present) IO storage backend\n"
+			" -d root              - root directory to load/store the objects\n"
+			" -W file              - write given file to the network storage\n"
+			" -s                   - request stats from all connected nodes\n"
+			" -R file              - read given file from the network into the local storage\n"
+			" -H file              - read a history for given file into the local storage\n"
+			" -T hash              - OpenSSL hash to use as a transformation function\n"
+			" -i id                - node's ID (zero by default)\n"
+			" -I id                - transaction id\n"
+			" -c cmd               - execute given command on the remote node\n"
+			" -L file              - lookup a storage which hosts given file\n"
+			" -w timeout           - wait timeout in seconds used to wait for content sync.\n"
+			" ...                  - parameters can be repeated multiple times\n"
+			"                        each time they correspond to the last added node\n"
+			" -D <daemon>          - go background\n"
+			" -N num               - number of IO threads\n"
+			" -P num               - maximum number of pending write transactions opened by single thread\n"
+			" -O offset            - read/write offset in the file\n"
+			" -S size              - read/write transaction size\n"
+			" -M strategy          - transaction log merge strategy\n"
+			" -u file              - unlink file\n"
+			, p);
+*/
+}
+
+int main(int argc, char *argv[])
+{
+	struct uci_context *ctx;
+	struct uci_package *pkg;
+    struct list_head *p;
+	int rv;
+	int trans_max = 5, trans_num = 0;
+	int ch, err, i, have_remote = 0, daemon = 0, bdb = 0, stat = 0;
+	int tc = 0;
+	struct dnet_node *node = NULL;
+	struct dnet_config cfg, rem;
+	struct dnet_crypto_engine *e, *trans[trans_max];
+    struct uci_basic_config *ucfg;
+	char *logfile = NULL, *readf = NULL, *writef = NULL, *cmd = NULL, *lookup = NULL;
+	char *historyf = NULL, *root = NULL, *removef = NULL, *config_path = NULL;
+    char *config_name = NULL;
+	unsigned char trans_id[DNET_ID_SIZE], *id = NULL;
+	FILE *log = NULL;
+	uint64_t offset, size;
+    pthread_t lua_thread;
+
+	INIT_LIST_HEAD(&dssd_config);
+    INIT_LIST_HEAD(&dssd_config_plugin);
+    INIT_LIST_HEAD(&dssd_config_backend);
+
+	memset(&cfg, 0, sizeof(struct dnet_config));
+
+	cfg.sock_type = SOCK_STREAM;
+	cfg.proto = IPPROTO_TCP;
+	cfg.wait_timeout = 60*60;
+	cfg.log_mask = ~0;
+	cfg.merge_strategy = DNET_MERGE_PREFER_NETWORK;
+
+	ctx = uci_alloc_context();
+	ucimap_init(&dssd_map);
+
+
+	size = offset = 0;
+
+	//memcpy(&rem, &cfg, sizeof(struct dnet_config));
+
+	while ((ch = getopt(argc, argv, "n:p:l:Dh")) != -1) {
+		switch (ch) {
+			case 'n':
+				config_name = optarg;
+				break;
+			case 'p':
+				config_path = optarg;
+				break;
+			case 'l':
+				logfile = optarg;
+				break;
+			case 'm':
+				cfg.log_mask = strtoul(optarg, NULL, 0);
+				break;
+			case 'D':
+				daemon = 1;
+				break;
+			case 'h':
+			default:
+				dnet_usage(argv[0]);
+				return -1;
+		}
+	}
+	
+	if (!logfile)
+		fprintf(stderr, "No log file found, logging will be disabled.\n");
+
+	if (logfile) {
+		log = fopen(logfile, "a");
+		if (!log) {
+			err = -errno;
+			fprintf(stderr, "Failed to open log file %s: %s.\n", logfile, strerror(errno));
+			return err;
+		}
+
+		cfg.log_private = log;
+		cfg.log = dnet_common_log;
+	}
+
+    // load config file
+    if(config_path)
+        uci_set_confdir(ctx, config_path);
+	rv = uci_load(ctx, config_name ? config_name : "dssd", &pkg);
+    if (rv)
+        dssd_fatal("Can't load config\n");
+	ucimap_parse(&dssd_map, pkg);
+
+    // print current configuration
+    print_config();
+
+	//list_for_each(p, &dssd_config);
+	//ucfg = list_entry(p, struct uci_basic_config, list);
+	//list_for_each(p, &dssd_config) {
+	//	ucfg = list_entry(p, struct uci_basic_config, list);
+    //    config_node(&cfg, ucfg);
+    //}
+
+    ucfg = list_first_entry(&dssd_config, struct uci_basic_config, list);
+
+    config_node(&cfg, ucfg);
+    node = dnet_node_create(&cfg);
+	if (!node)
+		return -1;
+
+
+	if (daemon)
+		dnet_background();
+
+
+    start_lua_threads();
+
+    //dnet_give_up_control(node);
+    sleep(1);
+
+	ucimap_cleanup(&dssd_map);
+	uci_free_context(ctx);
+
+	return 0;
+}
+
+
+#include "dnet/packet.h"
+#include "dnet/interface.h"
+#include <ucimap.h>
+#include <lua.h>
+#include <pthread.h>
+
+
+struct list_head dssd_config;
+struct list_head dssd_config_plugin;
+struct list_head dssd_config_backend;
+struct list_head dssd_config_mappings;
+struct list_head dssd_pool_config;
+extern struct uci_map dssd_map;
+void *dssd_log_priv;
+
+
+struct uci_basic_config {
+    struct ucimap_section_data map;
+    struct list_head list;
+	struct list_head mapping;
+    //struct list_head alias;
+    const char *name;
+
+    const char *addr;
+    const char *proto;
+    const char *port;
+
+    // id config
+    const char *suffix;
+    const char *city;
+    const char *pool;
+    const char *region;
+
+    // storage
+    const char *storage_path;
+    const char *storage_backend;
+    int storage_size;
+    int thread_num;
+    int wait_timeout;
+    int merge_strategy;
+
+    struct ucimap_list *mappings;
+};
+
+
+struct uci_plugins_config {
+	struct ucimap_section_data map;
+	struct list_head list;
+    const char *name;
+
+	bool enabled;
+
+    lua_State *lua_state;
+    pthread_t *thread;
+};
+
+struct uci_backend_config {
+	struct ucimap_section_data map;
+	struct list_head list;
+    const char *name;
+
+	bool enabled;
+
+    lua_State *lua_state;
+    pthread_t *thread;
+
+};
+
+
+struct lua_thread_param {
+    lua_State *lua_state;
+    char *lua_file;
+};
+/*
+struct pool_cfg {
+    int pool;
+    int num;
+};
+
+struct pool_config {
+    struct list_head list;
+    char *name;
+	struct list_head pools;
+};
+
+struct uci_mapping {
+	struct ucimap_section_data map;
+	struct list_head list;
+	struct list_head alias;
+
+    struct list_head list;
+	struct ucimap_list *pools;
+};
+*/
+
+struct uci_mapping {
+	struct ucimap_section_data map;
+	struct list_head list;
+    struct list_head alias;
+
+	const char *name;
+    const char *city;
+    int pool;
+    int hash;
+	struct uci_basic_config *server;
+};
+
+
+
+#define dssd_fatal(...) {  \
+    printf(__VA_ARGS__); \
+    exit(1); }
+    
+int config_node(struct dnet_config *cfg, struct uci_basic_config *ucfg);
+
+void dssd_log(int mask, char *format, ...);
+