Compare commits

...

6 Commits

Author SHA1 Message Date
Your Name
2e4ffc0e79 Add force push for updated tags 2025-09-06 05:11:11 -04:00
Your Name
70c91ec858 Fix version.h generation timing in build script 2025-09-06 05:09:35 -04:00
Your Name
b7c4609c2d Fix tag push failure in build script 2025-09-06 05:06:03 -04:00
Your Name
7f69367666 v0.2.5 - Fixed versioning 2025-09-06 05:01:26 -04:00
Your Name
fa17aa1f78 v0.2.4 - Clean up config issues 2025-09-06 04:40:59 -04:00
Your Name
7e560b4247 Remove relay.log from tracking (already in .gitignore) 2025-09-05 19:51:47 -04:00
13 changed files with 166 additions and 103 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ nips/
build/
relay.log
Trash/
src/version.h

View File

@@ -36,19 +36,68 @@ $(NOSTR_CORE_LIB):
@echo "Building nostr_core_lib..."
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
$(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)"
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS)
@echo "Build complete: $(TARGET)"
# 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..."
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_x86 $(NOSTR_CORE_LIB) $(LIBS)
@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..."
@if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \
echo "ERROR: ARM64 cross-compiler not found."; \
@@ -120,6 +169,7 @@ init-db:
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -f src/version.h
@echo "Clean complete"
# Clean everything including nostr_core_lib
@@ -158,5 +208,6 @@ help:
@echo " make check-toolchain # Check what compilers are available"
@echo " make test # Run tests"
@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

View File

@@ -139,6 +139,13 @@ compile_project() {
print_warning "Clean failed or no Makefile found"
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
if make > /dev/null 2>&1; then
print_success "C-Relay compiled successfully"
@@ -229,10 +236,65 @@ git_commit_and_push() {
exit 1
fi
if git push --tags > /dev/null 2>&1; then
print_success "Pushed tags"
# 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_warning "Failed to push tags"
print_warning "Tag push failed, trying force push..."
if git push --force origin "$NEW_VERSION" > /dev/null 2>&1; then
print_success "Force-pushed updated tag: $NEW_VERSION"
else
print_error "Failed to push tag: $NEW_VERSION"
exit 1
fi
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_warning "Tag push failed, trying force push..."
if git push --force origin "$NEW_VERSION" > /dev/null 2>&1; then
print_success "Force-pushed updated tag: $NEW_VERSION"
else
print_error "Failed to push tag: $NEW_VERSION"
exit 1
fi
fi
}
@@ -352,14 +414,23 @@ main() {
# Increment minor version for releases
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
# Build release binaries
build_release_binaries
# Commit and push
git_commit_and_push
# Commit and push (but skip tag creation since we already did it)
git_commit_and_push_no_tag
# Create Gitea release with binaries
create_gitea_release
@@ -376,11 +447,20 @@ main() {
# Increment patch version for regular commits
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
# Commit and push
git_commit_and_push
# Commit and push (but skip tag creation since we already did it)
git_commit_and_push_no_tag
print_success "Build and push completed successfully!"
print_status "Version $NEW_VERSION pushed to repository"

View File

@@ -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.

View File

@@ -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_contact', '', 'Contact information', '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),
-- NIP-13 Proof of Work

View File

@@ -66,7 +66,7 @@ The configuration file contains a signed Nostr event (kind 33334) with relay con
["relay_contact", ""],
["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"],
["max_event_tags", "100"],

View File

@@ -1,50 +0,0 @@
=== C Nostr Relay Server ===
[SUCCESS] Database connection established
[INFO] Initializing configuration system...
[INFO] Configuration directory: %s
/home/teknari/.config/c-relay
[INFO] Configuration file: %s
/home/teknari/.config/c-relay/c_relay_config_event.json
[INFO] Initializing configuration database statements...
[SUCCESS] Configuration database statements initialized
[INFO] Generating missing configuration file...
[INFO] Using private key from environment variable
[INFO] Creating configuration Nostr event...
[SUCCESS] Configuration Nostr event created successfully
Event ID: 03021d58b91941a3bb9284ee704e069c50c9ac09a20eb049d8de676757dde83a
Public Key: 8d8fbfb027872f13ed09e9e61f1d09473f3bec24bcfa9183e76cc1ceb789eb5e
[INFO] Stored admin public key in configuration database
Admin Public Key: 8d8fbfb027872f13ed09e9e61f1d09473f3bec24bcfa9183e76cc1ceb789eb5e
[SUCCESS] Configuration file written successfully
File: /home/teknari/.config/c-relay/c_relay_config_event.json
[SUCCESS] Configuration file generated successfully
[INFO] Loading configuration from all sources...
[INFO] Configuration file found, attempting to load...
[INFO] Loading configuration from file...
[INFO] Validating configuration event...
[INFO] Configuration event structure validation passed
[INFO] Configuration tags validation passed (%d tags)
Found 27 configuration tags
[WARNING] Signature verification not yet implemented - accepting event
[SUCCESS] Applied configuration from file
Applied 27 configuration values
[SUCCESS] Configuration event validation and application completed
[SUCCESS] Configuration loaded from file successfully
[SUCCESS] File configuration loaded successfully
[INFO] Loading configuration from database...
[SUCCESS] Database configuration validated (%d entries)
Found 27 configuration entries
[SUCCESS] Database configuration loaded
[INFO] Applying configuration to global variables...
[SUCCESS] Configuration applied to global variables
[SUCCESS] Configuration system initialized successfully
[SUCCESS] Relay information initialized with default values
[INFO] Initializing NIP-13 Proof of Work configuration
[INFO] PoW configured in basic validation mode
[INFO] PoW Configuration: enabled=true, min_difficulty=0, validation_flags=0x1, mode=full
[INFO] Initializing NIP-40 Expiration Timestamp configuration
[INFO] Expiration Configuration: enabled=true, strict_mode=true, filter_responses=true, grace_period=300 seconds
[INFO] Subscription limits: max_per_client=25, max_total=5000
[INFO] Starting relay server...
[INFO] Starting libwebsockets-based Nostr relay server...
[SUCCESS] WebSocket relay started on ws://127.0.0.1:8888

View File

@@ -1 +1 @@
793733
871512

View File

@@ -1,4 +1,5 @@
#include "config.h"
#include "version.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -721,7 +722,6 @@ cJSON* create_config_nostr_event(const char* privkey_hex) {
static const default_config_t defaults[] = {
// Administrative settings
{"admin_pubkey", ""},
{"admin_enabled", "false"},
// 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_contact", ""},
{"relay_pubkey", ""},
{"relay_software", "https://github.com/teknari/c-relay"},
{"relay_version", "0.2.0"},
{"relay_software", "https://git.laantungir.net/laantungir/c-relay.git"},
{"relay_version", VERSION},
// NIP-13 Proof of Work
{"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* 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_AddItemToArray(tag, cJSON_CreateString(key));
cJSON_AddItemToArray(tag, cJSON_CreateString(value));
@@ -978,7 +979,7 @@ int generate_config_file_if_missing(void) {
cJSON* pubkey_obj = cJSON_GetObjectItem(event, "pubkey");
if (pubkey_obj && cJSON_IsString(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");
printf(" Admin Public Key: %s\n", admin_pubkey);
} else {

View File

@@ -26,9 +26,9 @@
#define RELAY_URL_MAX_LENGTH 256
#define RELAY_CONTACT_MAX_LENGTH 128
#define RELAY_PUBKEY_MAX_LENGTH 65
#define DATABASE_PATH "db/c_nostr_relay.db"
// 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_HOST "127.0.0.1"
#define MAX_CLIENTS 100

View File

@@ -1306,7 +1306,7 @@ void init_relay_info() {
if (relay_software) {
strncpy(g_relay_info.software, relay_software, sizeof(g_relay_info.software) - 1);
} 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");
@@ -1940,13 +1940,21 @@ int validate_event_expiration(cJSON* event, char* error_message, size_t error_si
// Initialize database connection
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) {
log_error("Cannot open database");
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;
}