Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70c91ec858 | ||
|
|
b7c4609c2d | ||
|
|
7f69367666 | ||
|
|
fa17aa1f78 | ||
|
|
7e560b4247 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ nips/
|
|||||||
build/
|
build/
|
||||||
relay.log
|
relay.log
|
||||||
Trash/
|
Trash/
|
||||||
|
src/version.h
|
||||||
|
|||||||
59
Makefile
59
Makefile
@@ -36,19 +36,68 @@ $(NOSTR_CORE_LIB):
|
|||||||
@echo "Building nostr_core_lib..."
|
@echo "Building nostr_core_lib..."
|
||||||
cd nostr_core_lib && ./build.sh
|
cd nostr_core_lib && ./build.sh
|
||||||
|
|
||||||
|
# Generate version.h from git tags
|
||||||
|
src/version.h:
|
||||||
|
@if [ -d .git ]; then \
|
||||||
|
echo "Generating version.h from git tags..."; \
|
||||||
|
VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "unknown"); \
|
||||||
|
if echo "$$VERSION" | grep -q "^v[0-9]"; then \
|
||||||
|
CLEAN_VERSION=$$(echo "$$VERSION" | sed 's/^v//'); \
|
||||||
|
MAJOR=$$(echo "$$CLEAN_VERSION" | cut -d. -f1); \
|
||||||
|
MINOR=$$(echo "$$CLEAN_VERSION" | cut -d. -f2); \
|
||||||
|
PATCH=$$(echo "$$CLEAN_VERSION" | cut -d. -f3 | cut -d- -f1); \
|
||||||
|
else \
|
||||||
|
CLEAN_VERSION="0.0.0-$$VERSION"; \
|
||||||
|
MAJOR=0; MINOR=0; PATCH=0; \
|
||||||
|
fi; \
|
||||||
|
echo "/* Auto-generated version information */" > src/version.h; \
|
||||||
|
echo "#ifndef VERSION_H" >> src/version.h; \
|
||||||
|
echo "#define VERSION_H" >> src/version.h; \
|
||||||
|
echo "" >> src/version.h; \
|
||||||
|
echo "#define VERSION \"$$VERSION\"" >> src/version.h; \
|
||||||
|
echo "#define VERSION_MAJOR $$MAJOR" >> src/version.h; \
|
||||||
|
echo "#define VERSION_MINOR $$MINOR" >> src/version.h; \
|
||||||
|
echo "#define VERSION_PATCH $$PATCH" >> src/version.h; \
|
||||||
|
echo "" >> src/version.h; \
|
||||||
|
echo "#endif /* VERSION_H */" >> src/version.h; \
|
||||||
|
echo "Generated version.h with version: $$VERSION"; \
|
||||||
|
elif [ ! -f src/version.h ]; then \
|
||||||
|
echo "Git not available and version.h missing, creating fallback version.h..."; \
|
||||||
|
VERSION="unknown"; \
|
||||||
|
echo "/* Auto-generated version information */" > src/version.h; \
|
||||||
|
echo "#ifndef VERSION_H" >> src/version.h; \
|
||||||
|
echo "#define VERSION_H" >> src/version.h; \
|
||||||
|
echo "" >> src/version.h; \
|
||||||
|
echo "#define VERSION \"$$VERSION\"" >> src/version.h; \
|
||||||
|
echo "#define VERSION_MAJOR 0" >> src/version.h; \
|
||||||
|
echo "#define VERSION_MINOR 0" >> src/version.h; \
|
||||||
|
echo "#define VERSION_PATCH 0" >> src/version.h; \
|
||||||
|
echo "" >> src/version.h; \
|
||||||
|
echo "#endif /* VERSION_H */" >> src/version.h; \
|
||||||
|
echo "Created fallback version.h with version: $$VERSION"; \
|
||||||
|
else \
|
||||||
|
echo "Git not available, preserving existing version.h"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Force version.h regeneration (useful for development)
|
||||||
|
force-version:
|
||||||
|
@echo "Force regenerating version.h..."
|
||||||
|
@rm -f src/version.h
|
||||||
|
@$(MAKE) src/version.h
|
||||||
|
|
||||||
# Build the relay
|
# Build the relay
|
||||||
$(TARGET): $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
$(TARGET): $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
@echo "Compiling C-Relay for architecture: $(ARCH)"
|
@echo "Compiling C-Relay for architecture: $(ARCH)"
|
||||||
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS)
|
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS)
|
||||||
@echo "Build complete: $(TARGET)"
|
@echo "Build complete: $(TARGET)"
|
||||||
|
|
||||||
# Build for specific architectures
|
# Build for specific architectures
|
||||||
x86: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
x86: $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
@echo "Building C-Relay for x86_64..."
|
@echo "Building C-Relay for x86_64..."
|
||||||
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_x86 $(NOSTR_CORE_LIB) $(LIBS)
|
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_x86 $(NOSTR_CORE_LIB) $(LIBS)
|
||||||
@echo "Build complete: $(BUILD_DIR)/c_relay_x86"
|
@echo "Build complete: $(BUILD_DIR)/c_relay_x86"
|
||||||
|
|
||||||
arm64: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
arm64: $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
@echo "Cross-compiling C-Relay for ARM64..."
|
@echo "Cross-compiling C-Relay for ARM64..."
|
||||||
@if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \
|
@if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \
|
||||||
echo "ERROR: ARM64 cross-compiler not found."; \
|
echo "ERROR: ARM64 cross-compiler not found."; \
|
||||||
@@ -120,6 +169,7 @@ init-db:
|
|||||||
# Clean build artifacts
|
# Clean build artifacts
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
|
rm -f src/version.h
|
||||||
@echo "Clean complete"
|
@echo "Clean complete"
|
||||||
|
|
||||||
# Clean everything including nostr_core_lib
|
# Clean everything including nostr_core_lib
|
||||||
@@ -158,5 +208,6 @@ help:
|
|||||||
@echo " make check-toolchain # Check what compilers are available"
|
@echo " make check-toolchain # Check what compilers are available"
|
||||||
@echo " make test # Run tests"
|
@echo " make test # Run tests"
|
||||||
@echo " make init-db # Set up database"
|
@echo " make init-db # Set up database"
|
||||||
|
@echo " make force-version # Force regenerate version.h from git"
|
||||||
|
|
||||||
.PHONY: all x86 arm64 test init-db clean clean-all install-deps install-cross-tools install-arm64-deps check-toolchain help
|
.PHONY: all x86 arm64 test init-db clean clean-all install-deps install-cross-tools install-arm64-deps check-toolchain help force-version
|
||||||
@@ -139,6 +139,13 @@ compile_project() {
|
|||||||
print_warning "Clean failed or no Makefile found"
|
print_warning "Clean failed or no Makefile found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Force regenerate version.h to pick up new tags
|
||||||
|
if make force-version > /dev/null 2>&1; then
|
||||||
|
print_success "Regenerated version.h"
|
||||||
|
else
|
||||||
|
print_warning "Failed to regenerate version.h"
|
||||||
|
fi
|
||||||
|
|
||||||
# Compile the project
|
# Compile the project
|
||||||
if make > /dev/null 2>&1; then
|
if make > /dev/null 2>&1; then
|
||||||
print_success "C-Relay compiled successfully"
|
print_success "C-Relay compiled successfully"
|
||||||
@@ -229,10 +236,55 @@ git_commit_and_push() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if git push --tags > /dev/null 2>&1; then
|
# Push only the new tag to avoid conflicts with existing tags
|
||||||
print_success "Pushed tags"
|
if git push origin "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
|
print_success "Pushed tag: $NEW_VERSION"
|
||||||
else
|
else
|
||||||
print_warning "Failed to push tags"
|
print_error "Failed to push tag: $NEW_VERSION"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to commit and push changes without creating a tag (tag already created)
|
||||||
|
git_commit_and_push_no_tag() {
|
||||||
|
print_status "Preparing git commit..."
|
||||||
|
|
||||||
|
# Stage all changes
|
||||||
|
if git add . > /dev/null 2>&1; then
|
||||||
|
print_success "Staged all changes"
|
||||||
|
else
|
||||||
|
print_error "Failed to stage changes"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if there are changes to commit
|
||||||
|
if git diff --staged --quiet; then
|
||||||
|
print_warning "No changes to commit"
|
||||||
|
else
|
||||||
|
# Commit changes
|
||||||
|
if git commit -m "$NEW_VERSION - $COMMIT_MESSAGE" > /dev/null 2>&1; then
|
||||||
|
print_success "Committed changes"
|
||||||
|
else
|
||||||
|
print_error "Failed to commit changes"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Push changes and tags
|
||||||
|
print_status "Pushing to remote repository..."
|
||||||
|
if git push > /dev/null 2>&1; then
|
||||||
|
print_success "Pushed changes"
|
||||||
|
else
|
||||||
|
print_error "Failed to push changes"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Push only the new tag to avoid conflicts with existing tags
|
||||||
|
if git push origin "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
|
print_success "Pushed tag: $NEW_VERSION"
|
||||||
|
else
|
||||||
|
print_error "Failed to push tag: $NEW_VERSION"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,14 +404,23 @@ main() {
|
|||||||
# Increment minor version for releases
|
# Increment minor version for releases
|
||||||
increment_version "minor"
|
increment_version "minor"
|
||||||
|
|
||||||
# Compile project first
|
# Create new git tag BEFORE compilation so version.h picks it up
|
||||||
|
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
|
print_success "Created tag: $NEW_VERSION"
|
||||||
|
else
|
||||||
|
print_warning "Tag $NEW_VERSION already exists, removing and recreating..."
|
||||||
|
git tag -d "$NEW_VERSION" > /dev/null 2>&1
|
||||||
|
git tag "$NEW_VERSION" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compile project first (will now pick up the new tag)
|
||||||
compile_project
|
compile_project
|
||||||
|
|
||||||
# Build release binaries
|
# Build release binaries
|
||||||
build_release_binaries
|
build_release_binaries
|
||||||
|
|
||||||
# Commit and push
|
# Commit and push (but skip tag creation since we already did it)
|
||||||
git_commit_and_push
|
git_commit_and_push_no_tag
|
||||||
|
|
||||||
# Create Gitea release with binaries
|
# Create Gitea release with binaries
|
||||||
create_gitea_release
|
create_gitea_release
|
||||||
@@ -376,11 +437,20 @@ main() {
|
|||||||
# Increment patch version for regular commits
|
# Increment patch version for regular commits
|
||||||
increment_version "patch"
|
increment_version "patch"
|
||||||
|
|
||||||
# Compile project
|
# Create new git tag BEFORE compilation so version.h picks it up
|
||||||
|
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
|
print_success "Created tag: $NEW_VERSION"
|
||||||
|
else
|
||||||
|
print_warning "Tag $NEW_VERSION already exists, removing and recreating..."
|
||||||
|
git tag -d "$NEW_VERSION" > /dev/null 2>&1
|
||||||
|
git tag "$NEW_VERSION" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compile project (will now pick up the new tag)
|
||||||
compile_project
|
compile_project
|
||||||
|
|
||||||
# Commit and push
|
# Commit and push (but skip tag creation since we already did it)
|
||||||
git_commit_and_push
|
git_commit_and_push_no_tag
|
||||||
|
|
||||||
print_success "Build and push completed successfully!"
|
print_success "Build and push completed successfully!"
|
||||||
print_status "Version $NEW_VERSION pushed to repository"
|
print_status "Version $NEW_VERSION pushed to repository"
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
=== C Nostr Relay Build and Restart Script ===
|
|
||||||
Removing old configuration file to trigger regeneration...
|
|
||||||
✓ Configuration file removed - will be regenerated with latest database values
|
|
||||||
Building project...
|
|
||||||
rm -rf build
|
|
||||||
Clean complete
|
|
||||||
mkdir -p build
|
|
||||||
Compiling C-Relay for architecture: x86_64
|
|
||||||
gcc -Wall -Wextra -std=c99 -g -O2 -I. -Inostr_core_lib -Inostr_core_lib/nostr_core -Inostr_core_lib/cjson -Inostr_core_lib/nostr_websocket src/main.c src/config.c -o build/c_relay_x86 nostr_core_lib/libnostr_core_x64.a -lsqlite3 -lwebsockets -lz -ldl -lpthread -lm -L/usr/local/lib -lsecp256k1 -lssl -lcrypto -L/usr/local/lib -lcurl
|
|
||||||
Build complete: build/c_relay_x86
|
|
||||||
Build successful. Proceeding with relay restart...
|
|
||||||
Stopping any existing relay servers...
|
|
||||||
No existing relay found
|
|
||||||
Starting relay server...
|
|
||||||
Debug: Current processes: None
|
|
||||||
Started with PID: 786684
|
|
||||||
Relay started successfully!
|
|
||||||
PID: 786684
|
|
||||||
WebSocket endpoint: ws://127.0.0.1:8888
|
|
||||||
Log file: relay.log
|
|
||||||
|
|
||||||
=== Relay server running in background ===
|
|
||||||
To kill relay: pkill -f 'c_relay_'
|
|
||||||
To check status: ps aux | grep c_relay_
|
|
||||||
To view logs: tail -f relay.log
|
|
||||||
Binary: ./build/c_relay_x86
|
|
||||||
Ready for Nostr client connections!
|
|
||||||
|
|
||||||
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"],
|
||||||
|
|||||||
50
relay.log
50
relay.log
@@ -1,50 +0,0 @@
|
|||||||
[34m[1m=== C Nostr Relay Server ===[0m
|
|
||||||
[32m[SUCCESS][0m Database connection established
|
|
||||||
[34m[INFO][0m Initializing configuration system...
|
|
||||||
[34m[INFO][0m Configuration directory: %s
|
|
||||||
/home/teknari/.config/c-relay
|
|
||||||
[34m[INFO][0m Configuration file: %s
|
|
||||||
/home/teknari/.config/c-relay/c_relay_config_event.json
|
|
||||||
[34m[INFO][0m Initializing configuration database statements...
|
|
||||||
[32m[SUCCESS][0m Configuration database statements initialized
|
|
||||||
[34m[INFO][0m Generating missing configuration file...
|
|
||||||
[34m[INFO][0m Using private key from environment variable
|
|
||||||
[34m[INFO][0m Creating configuration Nostr event...
|
|
||||||
[32m[SUCCESS][0m Configuration Nostr event created successfully
|
|
||||||
Event ID: 03021d58b91941a3bb9284ee704e069c50c9ac09a20eb049d8de676757dde83a
|
|
||||||
Public Key: 8d8fbfb027872f13ed09e9e61f1d09473f3bec24bcfa9183e76cc1ceb789eb5e
|
|
||||||
[34m[INFO][0m Stored admin public key in configuration database
|
|
||||||
Admin Public Key: 8d8fbfb027872f13ed09e9e61f1d09473f3bec24bcfa9183e76cc1ceb789eb5e
|
|
||||||
[32m[SUCCESS][0m Configuration file written successfully
|
|
||||||
File: /home/teknari/.config/c-relay/c_relay_config_event.json
|
|
||||||
[32m[SUCCESS][0m Configuration file generated successfully
|
|
||||||
[34m[INFO][0m Loading configuration from all sources...
|
|
||||||
[34m[INFO][0m Configuration file found, attempting to load...
|
|
||||||
[34m[INFO][0m Loading configuration from file...
|
|
||||||
[34m[INFO][0m Validating configuration event...
|
|
||||||
[34m[INFO][0m Configuration event structure validation passed
|
|
||||||
[34m[INFO][0m Configuration tags validation passed (%d tags)
|
|
||||||
Found 27 configuration tags
|
|
||||||
[33m[WARNING][0m Signature verification not yet implemented - accepting event
|
|
||||||
[32m[SUCCESS][0m Applied configuration from file
|
|
||||||
Applied 27 configuration values
|
|
||||||
[32m[SUCCESS][0m Configuration event validation and application completed
|
|
||||||
[32m[SUCCESS][0m Configuration loaded from file successfully
|
|
||||||
[32m[SUCCESS][0m File configuration loaded successfully
|
|
||||||
[34m[INFO][0m Loading configuration from database...
|
|
||||||
[32m[SUCCESS][0m Database configuration validated (%d entries)
|
|
||||||
Found 27 configuration entries
|
|
||||||
[32m[SUCCESS][0m Database configuration loaded
|
|
||||||
[34m[INFO][0m Applying configuration to global variables...
|
|
||||||
[32m[SUCCESS][0m Configuration applied to global variables
|
|
||||||
[32m[SUCCESS][0m Configuration system initialized successfully
|
|
||||||
[32m[SUCCESS][0m Relay information initialized with default values
|
|
||||||
[34m[INFO][0m Initializing NIP-13 Proof of Work configuration
|
|
||||||
[34m[INFO][0m PoW configured in basic validation mode
|
|
||||||
[34m[INFO][0m PoW Configuration: enabled=true, min_difficulty=0, validation_flags=0x1, mode=full
|
|
||||||
[34m[INFO][0m Initializing NIP-40 Expiration Timestamp configuration
|
|
||||||
[34m[INFO][0m Expiration Configuration: enabled=true, strict_mode=true, filter_responses=true, grace_period=300 seconds
|
|
||||||
[34m[INFO][0m Subscription limits: max_per_client=25, max_total=5000
|
|
||||||
[34m[INFO][0m Starting relay server...
|
|
||||||
[34m[INFO][0m Starting libwebsockets-based Nostr relay server...
|
|
||||||
[32m[SUCCESS][0m WebSocket relay started on ws://127.0.0.1:8888
|
|
||||||
11
src/config.c
11
src/config.c
@@ -1,4 +1,5 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "version.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -721,7 +722,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,8 +734,8 @@ 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", VERSION},
|
||||||
|
|
||||||
// NIP-13 Proof of Work
|
// NIP-13 Proof of Work
|
||||||
{"pow_enabled", "true"},
|
{"pow_enabled", "true"},
|
||||||
@@ -776,7 +776,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 +979,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