diff --git a/db.c b/db.c
index f2f1ced..720f4e9 100644
--- a/db.c
+++ b/db.c
@@ -121,8 +121,6 @@ int ZTLF_DB_open(struct ZTLF_DB *db,const char *path)
goto exit_with_error;
if ((e = sqlite3_prepare_v2(db->dbc,"SELECT doff,dlen,goff,ts,exp,owner FROM record WHERE id = ? GROUP BY owner ORDER BY ts ASC",-1,&db->sGetRecordsById,NULL)) != SQLITE_OK)
goto exit_with_error;
- if ((e = sqlite3_prepare_v2(db->dbc,"SELECT doff,dlen,MAX(ts),exp,owner FROM record WHERE id = ? GROUP BY owner",-1,&db->sGetAllLatestRecordsById,NULL)) != SQLITE_OK)
- goto exit_with_error;
if ((e = sqlite3_prepare_v2(db->dbc,"SELECT COUNT(1) FROM record",-1,&db->sGetRecordCount,NULL)) != SQLITE_OK)
goto exit_with_error;
if ((e = sqlite3_prepare_v2(db->dbc,"SELECT doff,goff FROM record WHERE hash = ?",-1,&db->sGetRecordInfoByHash,NULL)) != SQLITE_OK)
@@ -183,7 +181,6 @@ void ZTLF_DB_close(struct ZTLF_DB *db)
if (db->sAddRecord) sqlite3_finalize(db->sAddRecord);
if (db->sGetLatestRecordTimestamp) sqlite3_finalize(db->sGetLatestRecordTimestamp);
if (db->sGetRecordsById) sqlite3_finalize(db->sGetRecordsById);
- if (db->sGetAllLatestRecordsById) sqlite3_finalize(db->sGetAllLatestRecordsById);
if (db->sGetRecordCount) sqlite3_finalize(db->sGetRecordCount);
if (db->sGetRecordInfoByHash) sqlite3_finalize(db->sGetRecordInfoByHash);
if (db->sGetDanglingLinks) sqlite3_finalize(db->sGetDanglingLinks);
@@ -276,7 +273,7 @@ int ZTLF_putRecord(struct ZTLF_DB *db,struct ZTLF_Record *const r,const unsigned
int e = 0,result = 0;
struct ZTLF_Vector_i64 graphTraversalQueue;
- ZTLF_Vector_i64_init(&graphTraversalQueue,8388608);
+ ZTLF_Vector_i64_init(&graphTraversalQueue,2097152);
uint64_t hash[4];
struct ZTLF_RecordInfo ri;
@@ -404,10 +401,10 @@ int ZTLF_putRecord(struct ZTLF_DB *db,struct ZTLF_Record *const r,const unsigned
}
}
- /* Every 16m iterations compact the queue and yield the lock so any other
+ /* Every 1m iterations compact the queue and yield the lock so any other
* threads can do things with the database. Addition is commutative so other
* threads adding to total weights during this loop won't hurt anything. */
- if (i >= 16777216) {
+ if (i >= 1048576) {
pthread_mutex_unlock(&db->lock);
memmove(graphTraversalQueue.v,graphTraversalQueue.v + i,sizeof(int64_t) * (graphTraversalQueue.size -= i));
i = 0;
diff --git a/db.h b/db.h
index 2941e18..9eb11fc 100644
--- a/db.h
+++ b/db.h
@@ -51,7 +51,6 @@ struct ZTLF_DB
sqlite3_stmt *sAddRecord;
sqlite3_stmt *sGetLatestRecordTimestamp;
sqlite3_stmt *sGetRecordsById;
- sqlite3_stmt *sGetAllLatestRecordsById;
sqlite3_stmt *sGetRecordCount;
sqlite3_stmt *sGetRecordInfoByHash;
sqlite3_stmt *sGetDanglingLinks;
diff --git a/lf.c b/lf.c
new file mode 100644
index 0000000..df76bfe
--- /dev/null
+++ b/lf.c
@@ -0,0 +1,55 @@
+/*
+ * LF: Global Fully Replicated Key/Value Store
+ * Copyright (C) 2018 ZeroTier, Inc. https://www.zerotier.com/
+ *
+ * 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 3 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * --
+ *
+ * You can be released from the requirements of the license by purchasing
+ * a commercial license. Buying such a license is mandatory as soon as you
+ * develop commercial closed-source software that incorporates or links
+ * directly against ZeroTier software without disclosing the source code
+ * of your own application.
+ */
+
+#include "common.h"
+#include "node.h"
+
+static struct ZTLF_Node node;
+
+static void printHelp()
+{
+}
+
+static void exitSignal(int sig)
+{
+}
+
+int main(int argc,char **argv)
+{
+#ifndef __WINDOWS__
+ signal(SIGPIPE,SIG_IGN);
+ signal(SIGUSR1,SIG_IGN);
+ signal(SIGUSR2,SIG_IGN);
+ signal(SIGCHLD,SIG_IGN);
+ signal(SIGHUP,SIG_IGN);
+ signal(SIGALRM,SIG_IGN);
+ signal(SIGINT,&exitSignal);
+ signal(SIGTERM,&exitSignal);
+ signal(SIGQUIT,&exitSignal);
+#endif
+
+ return 0;
+}
diff --git a/node.h b/node.h
new file mode 100644
index 0000000..5022b04
--- /dev/null
+++ b/node.h
@@ -0,0 +1,71 @@
+/*
+ * LF: Global Fully Replicated Key/Value Store
+ * Copyright (C) 2018 ZeroTier, Inc. https://www.zerotier.com/
+ *
+ * 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 3 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * --
+ *
+ * You can be released from the requirements of the license by purchasing
+ * a commercial license. Buying such a license is mandatory as soon as you
+ * develop commercial closed-source software that incorporates or links
+ * directly against ZeroTier software without disclosing the source code
+ * of your own application.
+ */
+
+#ifndef ZTLF_NODE_H
+#define ZTLF_NODE_H
+
+#include "common.h"
+#include "db.h"
+#include "record.h"
+#include "config.h"
+#include "aes.h"
+#include "thirdparty/sandbird/sandbird.h"
+
+struct ZTLF_Node_PeerConnection
+{
+ uint8_t remotePublicKey[32];
+ ZTLF_AES256CFB encryptor;
+ ZTLF_AES256CFB decryptor;
+
+ struct sockaddr_storage remoteAddress;
+
+ uint64_t connectTime;
+ uint64_t lastReceiveTime;
+ uint64_t lastSendTime;
+
+ pthread_t receiveThread;
+
+ pthread_mutex_t sendLock;
+ int sock;
+
+ bool incoming;
+};
+
+struct ZTLF_Node
+{
+ struct ZTLF_DB db;
+ struct ZTLF_Config config;
+
+ int p2pListenSocket;
+ sb_Server *httpServer;
+
+ struct ZTLF_Node_PeerConnection *conn;
+ unsigned long connCount;
+ unsigned long connCapacity;
+ pthread_mutex_t connLock;
+};
+
+#endif
diff --git a/record.h b/record.h
index 6f4a538..035fdf3 100644
--- a/record.h
+++ b/record.h
@@ -32,6 +32,11 @@
#include "wharrgarbl.h"
#include "ed25519.h"
+/**
+ * Minimum size of a record (simply size of header)
+ */
+#define ZTLF_RECORD_MIN_SIZE sizeof(struct ZTLF_Record)
+
/**
* Overall maximum record size (cannot be changed)
*/
@@ -45,18 +50,13 @@
/**
* Maximum number of CA signature fields (sanity limit)
*/
-#define ZTLF_RECORD_MAX_CA_SIGNATURES 8
+#define ZTLF_RECORD_MAX_CA_SIGNATURES 16
/**
* Number of links from one record to others (cannot be changed)
*/
#define ZTLF_RECORD_LINK_COUNT 3
-/**
- * Minimum size of a record (simply size of header)
- */
-#define ZTLF_RECORD_MIN_SIZE sizeof(struct ZTLF_Record)
-
/**
* Unit for TTL in seconds (cannot be changed)
*/