v0.2.4 - Clean up config issues
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -142,7 +142,7 @@ INSERT OR IGNORE INTO server_config (key, value, description, config_type, data_
|
|||||||
('relay_description', 'High-performance C Nostr relay with SQLite storage', 'Relay description', 'user', 'string', 0),
|
('relay_description', 'High-performance C Nostr relay with SQLite storage', 'Relay description', 'user', 'string', 0),
|
||||||
('relay_contact', '', 'Contact information', 'user', 'string', 0),
|
('relay_contact', '', 'Contact information', 'user', 'string', 0),
|
||||||
('relay_pubkey', '', 'Relay public key', 'user', 'string', 0),
|
('relay_pubkey', '', 'Relay public key', 'user', 'string', 0),
|
||||||
('relay_software', 'https://github.com/laantungir/c-relay', 'Software URL', 'user', 'string', 0),
|
('relay_software', 'https://git.laantungir.net/laantungir/c-relay.git', 'Software URL', 'user', 'string', 0),
|
||||||
('relay_version', '0.2.0', 'Software version', 'user', 'string', 0),
|
('relay_version', '0.2.0', 'Software version', 'user', 'string', 0),
|
||||||
|
|
||||||
-- NIP-13 Proof of Work
|
-- NIP-13 Proof of Work
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ The configuration file contains a signed Nostr event (kind 33334) with relay con
|
|||||||
|
|
||||||
["relay_contact", ""],
|
["relay_contact", ""],
|
||||||
["relay_pubkey", ""],
|
["relay_pubkey", ""],
|
||||||
["relay_software", "https://github.com/laantungir/c-relay"],
|
["relay_software", "https://git.laantungir.net/laantungir/c-relay.git"],
|
||||||
["relay_version", "0.2.0"],
|
["relay_version", "0.2.0"],
|
||||||
|
|
||||||
["max_event_tags", "100"],
|
["max_event_tags", "100"],
|
||||||
|
|||||||
@@ -721,7 +721,6 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
|||||||
|
|
||||||
static const default_config_t defaults[] = {
|
static const default_config_t defaults[] = {
|
||||||
// Administrative settings
|
// Administrative settings
|
||||||
{"admin_pubkey", ""},
|
|
||||||
{"admin_enabled", "false"},
|
{"admin_enabled", "false"},
|
||||||
|
|
||||||
// Server core settings
|
// Server core settings
|
||||||
@@ -734,7 +733,7 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
|||||||
{"relay_description", "High-performance C Nostr relay with SQLite storage"},
|
{"relay_description", "High-performance C Nostr relay with SQLite storage"},
|
||||||
{"relay_contact", ""},
|
{"relay_contact", ""},
|
||||||
{"relay_pubkey", ""},
|
{"relay_pubkey", ""},
|
||||||
{"relay_software", "https://github.com/teknari/c-relay"},
|
{"relay_software", "https://git.laantungir.net/laantungir/c-relay.git"},
|
||||||
{"relay_version", "0.2.0"},
|
{"relay_version", "0.2.0"},
|
||||||
|
|
||||||
// NIP-13 Proof of Work
|
// NIP-13 Proof of Work
|
||||||
@@ -776,7 +775,8 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
|
|||||||
const char* key = (const char*)sqlite3_column_text(stmt, 0);
|
const char* key = (const char*)sqlite3_column_text(stmt, 0);
|
||||||
const char* value = (const char*)sqlite3_column_text(stmt, 1);
|
const char* value = (const char*)sqlite3_column_text(stmt, 1);
|
||||||
|
|
||||||
if (key && value) {
|
// Skip admin_pubkey since it's redundant (already in event.pubkey)
|
||||||
|
if (key && value && strcmp(key, "admin_pubkey") != 0) {
|
||||||
cJSON* tag = cJSON_CreateArray();
|
cJSON* tag = cJSON_CreateArray();
|
||||||
cJSON_AddItemToArray(tag, cJSON_CreateString(key));
|
cJSON_AddItemToArray(tag, cJSON_CreateString(key));
|
||||||
cJSON_AddItemToArray(tag, cJSON_CreateString(value));
|
cJSON_AddItemToArray(tag, cJSON_CreateString(value));
|
||||||
@@ -978,7 +978,7 @@ int generate_config_file_if_missing(void) {
|
|||||||
cJSON* pubkey_obj = cJSON_GetObjectItem(event, "pubkey");
|
cJSON* pubkey_obj = cJSON_GetObjectItem(event, "pubkey");
|
||||||
if (pubkey_obj && cJSON_IsString(pubkey_obj)) {
|
if (pubkey_obj && cJSON_IsString(pubkey_obj)) {
|
||||||
const char* admin_pubkey = cJSON_GetStringValue(pubkey_obj);
|
const char* admin_pubkey = cJSON_GetStringValue(pubkey_obj);
|
||||||
if (set_database_config("relay_admin_pubkey", admin_pubkey, "system") == 0) {
|
if (set_database_config("admin_pubkey", admin_pubkey, "system") == 0) {
|
||||||
log_info("Stored admin public key in configuration database");
|
log_info("Stored admin public key in configuration database");
|
||||||
printf(" Admin Public Key: %s\n", admin_pubkey);
|
printf(" Admin Public Key: %s\n", admin_pubkey);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,9 +26,9 @@
|
|||||||
#define RELAY_URL_MAX_LENGTH 256
|
#define RELAY_URL_MAX_LENGTH 256
|
||||||
#define RELAY_CONTACT_MAX_LENGTH 128
|
#define RELAY_CONTACT_MAX_LENGTH 128
|
||||||
#define RELAY_PUBKEY_MAX_LENGTH 65
|
#define RELAY_PUBKEY_MAX_LENGTH 65
|
||||||
#define DATABASE_PATH "db/c_nostr_relay.db"
|
|
||||||
|
|
||||||
// Default configuration values (used as fallbacks if database config fails)
|
// Default configuration values (used as fallbacks if database config fails)
|
||||||
|
#define DEFAULT_DATABASE_PATH "db/c_nostr_relay.db"
|
||||||
#define DEFAULT_PORT 8888
|
#define DEFAULT_PORT 8888
|
||||||
#define DEFAULT_HOST "127.0.0.1"
|
#define DEFAULT_HOST "127.0.0.1"
|
||||||
#define MAX_CLIENTS 100
|
#define MAX_CLIENTS 100
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@@ -1306,7 +1306,7 @@ void init_relay_info() {
|
|||||||
if (relay_software) {
|
if (relay_software) {
|
||||||
strncpy(g_relay_info.software, relay_software, sizeof(g_relay_info.software) - 1);
|
strncpy(g_relay_info.software, relay_software, sizeof(g_relay_info.software) - 1);
|
||||||
} else {
|
} else {
|
||||||
strncpy(g_relay_info.software, "https://github.com/laantungir/c-relay", sizeof(g_relay_info.software) - 1);
|
strncpy(g_relay_info.software, "https://git.laantungir.net/laantungir/c-relay.git", sizeof(g_relay_info.software) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* relay_version = get_config_value("relay_version");
|
const char* relay_version = get_config_value("relay_version");
|
||||||
@@ -1940,13 +1940,21 @@ int validate_event_expiration(cJSON* event, char* error_message, size_t error_si
|
|||||||
|
|
||||||
// Initialize database connection
|
// Initialize database connection
|
||||||
int init_database() {
|
int init_database() {
|
||||||
int rc = sqlite3_open(DATABASE_PATH, &g_db);
|
// Use configurable database path, falling back to default
|
||||||
|
const char* db_path = get_config_value("database_path");
|
||||||
|
if (!db_path) {
|
||||||
|
db_path = DEFAULT_DATABASE_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = sqlite3_open(db_path, &g_db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
log_error("Cannot open database");
|
log_error("Cannot open database");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_success("Database connection established");
|
char success_msg[256];
|
||||||
|
snprintf(success_msg, sizeof(success_msg), "Database connection established: %s", db_path);
|
||||||
|
log_success(success_msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user