Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ca459593c | ||
|
|
ee4208cc19 | ||
|
|
f6330e4bb8 | ||
|
|
4f3cf10a5c | ||
|
|
aa1954e81e | ||
|
|
482597bd0e | ||
|
|
d4b90e681c | ||
|
|
fcf9e43c4c | ||
|
|
b8d8cd19d3 | ||
|
|
536c2d966c | ||
|
|
f49cb0a5ac | ||
|
|
cef6bb2340 | ||
|
|
4c03253b30 | ||
|
|
ed09bb7370 | ||
|
|
5c46a25173 | ||
|
|
d1538f00df | ||
|
|
afa4acbbfb | ||
|
|
d9a530485f | ||
|
|
b2ad70b028 | ||
|
|
f49aae8ab0 | ||
|
|
f6debcf799 | ||
|
|
edbc4f1359 |
65
NOSTR_RELEASE.md
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# Relay
|
||||||
|
|
||||||
|
I am releasing the code for the nostr relay that I wrote use myself. The code is free for anyone to use in any way that they wish.
|
||||||
|
|
||||||
|
Some of the features of this relay are conventional, and some are unconventional.
|
||||||
|
|
||||||
|
## The conventional
|
||||||
|
|
||||||
|
This relay is written in C99 with a sqlite database.
|
||||||
|
|
||||||
|
It implements the following NIPs.
|
||||||
|
|
||||||
|
- [x] NIP-01: Basic protocol flow implementation
|
||||||
|
- [x] NIP-09: Event deletion
|
||||||
|
- [x] NIP-11: Relay information document
|
||||||
|
- [x] NIP-13: Proof of Work
|
||||||
|
- [x] NIP-15: End of Stored Events Notice
|
||||||
|
- [x] NIP-20: Command Results
|
||||||
|
- [x] NIP-33: Parameterized Replaceable Events
|
||||||
|
- [x] NIP-40: Expiration Timestamp
|
||||||
|
- [x] NIP-42: Authentication of clients to relays
|
||||||
|
- [x] NIP-45: Counting results
|
||||||
|
- [x] NIP-50: Keywords filter
|
||||||
|
- [x] NIP-70: Protected Events
|
||||||
|
|
||||||
|
## The unconventional
|
||||||
|
|
||||||
|
### The binaries are fully self contained.
|
||||||
|
|
||||||
|
It should just run in linux without having to worry about what you have on your system. I want to download and run. No docker. No dependency hell.
|
||||||
|
|
||||||
|
I'm not bothering with other operating systems.
|
||||||
|
|
||||||
|
### The relay is a full nostr citizen with it's own public and private keys.
|
||||||
|
|
||||||
|
For example, you can see my relay's profile (wss://relay.laantungir.net) running here:
|
||||||
|
|
||||||
|
[Primal link](https://primal.net/p/nprofile1qqswn2jsmm8lq8evas0v9vhqkdpn9nuujt90mtz60nqgsxndy66es4qjjnhr7)
|
||||||
|
|
||||||
|
What this means in practice is that when you start the relay, it generates keys for itself, and for it's administrator (You can specify these if you wish)
|
||||||
|
|
||||||
|
Now the program and the administrator can have verifed communication between the two, simply by using nostr events. For example, the administrator can send DMs to the relay, asking it's status, and changing it's configuration through any client that can handle nip17 DMs. The relay can also send notifications to the administrator about it's current status, or it can publish it's status on a regular schedule directly to NOSTR as kind-1 notes.
|
||||||
|
|
||||||
|
Also included is a more standard administrative web front end. This front end communicates to the relay using an extensive api, which again is nostr events signed by the administrator. You can completely control the relay through signed nostr events.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|

|
||||||
|
Main page with real time updates.
|
||||||
|
|
||||||
|

|
||||||
|
Set your configuration preferences.
|
||||||
|
|
||||||
|

|
||||||
|
View current subscriptions
|
||||||
|
|
||||||
|

|
||||||
|
Add npubs to white or black lists.
|
||||||
|
|
||||||
|

|
||||||
|
Run sql queries on the database.
|
||||||
|
|
||||||
|

|
||||||
|
Light mode.
|
||||||
|
|
||||||
@@ -1261,3 +1261,50 @@ body.dark-mode .sql-results-table tbody tr:nth-child(even) {
|
|||||||
.header-title.clickable:hover {
|
.header-title.clickable:hover {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================
|
||||||
|
SUBSCRIPTION TABLE COLLAPSIBLE GROUPS
|
||||||
|
================================ */
|
||||||
|
|
||||||
|
/* Subscription group header styles */
|
||||||
|
.subscription-group-header {
|
||||||
|
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subscription-group-header:hover {
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.expand-icon {
|
||||||
|
display: inline-block;
|
||||||
|
width: 20px;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detail row styles */
|
||||||
|
.subscription-detail-row {
|
||||||
|
/* background-color: var(--secondary-color); */
|
||||||
|
}
|
||||||
|
|
||||||
|
.subscription-detail-row:hover {
|
||||||
|
background-color: var(--muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detail row cell styles */
|
||||||
|
.subscription-detail-prefix {
|
||||||
|
padding-left: 30px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.subscription-detail-id {
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,18 +212,9 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="config-table-container">
|
<div class="config-table-container">
|
||||||
<table class="config-table" id="subscription-details-table">
|
<table class="config-table" id="subscription-details-table">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Subscription ID</th>
|
|
||||||
<th>Client IP</th>
|
|
||||||
<th>WSI Pointer</th>
|
|
||||||
<th>Duration</th>
|
|
||||||
<th>Filters</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="subscription-details-table-body">
|
<tbody id="subscription-details-table-body">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5" style="text-align: center; font-style: italic;">No subscriptions active</td>
|
<td colspan="4" style="text-align: center; font-style: italic;">No subscriptions active</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
273
api/index.js
@@ -93,10 +93,11 @@ function log(message, type = 'INFO') {
|
|||||||
|
|
||||||
|
|
||||||
// NIP-59 helper: randomize created_at to thwart time-analysis (past 2 days)
|
// NIP-59 helper: randomize created_at to thwart time-analysis (past 2 days)
|
||||||
|
// TEMPORARILY DISABLED: Using current timestamp for debugging
|
||||||
function randomNow() {
|
function randomNow() {
|
||||||
const TWO_DAYS = 2 * 24 * 60 * 60; // 172800 seconds
|
// const TWO_DAYS = 2 * 24 * 60 * 60; // 172800 seconds
|
||||||
const now = Math.round(Date.now() / 1000);
|
const now = Math.round(Date.now() / 1000);
|
||||||
return Math.round(now - Math.random() * TWO_DAYS);
|
return now; // Math.round(now - Math.random() * TWO_DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safe JSON parse with error handling
|
// Safe JSON parse with error handling
|
||||||
@@ -1250,7 +1251,7 @@ async function processAdminResponse(event) {
|
|||||||
throw new Error('Failed to decrypt admin response content');
|
throw new Error('Failed to decrypt admin response content');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Decrypted admin response:', decryptedContent);
|
// console.log('Decrypted admin response:', decryptedContent);
|
||||||
|
|
||||||
// Try to parse as JSON first, if it fails treat as plain text
|
// Try to parse as JSON first, if it fails treat as plain text
|
||||||
let responseData;
|
let responseData;
|
||||||
@@ -4033,9 +4034,9 @@ function updateStatsFromTimeMonitoringEvent(monitoringData) {
|
|||||||
|
|
||||||
// Extract values from periods array
|
// Extract values from periods array
|
||||||
monitoringData.periods.forEach(period => {
|
monitoringData.periods.forEach(period => {
|
||||||
if (period.period === '24h') timeStats.last_24h = period.count;
|
if (period.period === 'last_24h') timeStats.last_24h = period.count;
|
||||||
else if (period.period === '7d') timeStats.last_7d = period.count;
|
else if (period.period === 'last_7d') timeStats.last_7d = period.count;
|
||||||
else if (period.period === '30d') timeStats.last_30d = period.count;
|
else if (period.period === 'last_30d') timeStats.last_30d = period.count;
|
||||||
});
|
});
|
||||||
|
|
||||||
populateStatsTime({ time_stats: timeStats });
|
populateStatsTime({ time_stats: timeStats });
|
||||||
@@ -4069,7 +4070,7 @@ function updateStatsFromTopPubkeysMonitoringEvent(monitoringData) {
|
|||||||
function updateStatsFromSubscriptionDetailsMonitoringEvent(monitoringData) {
|
function updateStatsFromSubscriptionDetailsMonitoringEvent(monitoringData) {
|
||||||
try {
|
try {
|
||||||
// DEBUG: Log every subscription_details event that arrives at the webpage
|
// DEBUG: Log every subscription_details event that arrives at the webpage
|
||||||
console.log('subscription_details', JSON.stringify(monitoringData, null, 2));
|
// console.log('subscription_details', JSON.stringify(monitoringData, null, 2));
|
||||||
console.log('subscription_details decoded:', monitoringData);
|
console.log('subscription_details decoded:', monitoringData);
|
||||||
|
|
||||||
if (monitoringData.data_type !== 'subscription_details') {
|
if (monitoringData.data_type !== 'subscription_details') {
|
||||||
@@ -4278,101 +4279,185 @@ function populateSubscriptionDetailsTable(subscriptionsData) {
|
|||||||
const tableBody = document.getElementById('subscription-details-table-body');
|
const tableBody = document.getElementById('subscription-details-table-body');
|
||||||
if (!tableBody || !subscriptionsData || !Array.isArray(subscriptionsData)) return;
|
if (!tableBody || !subscriptionsData || !Array.isArray(subscriptionsData)) return;
|
||||||
|
|
||||||
|
// Store current expand/collapse state before rebuilding
|
||||||
|
const expandedGroups = new Set();
|
||||||
|
const headerRows = tableBody.querySelectorAll('.subscription-group-header');
|
||||||
|
headerRows.forEach(header => {
|
||||||
|
const wsiPointer = header.getAttribute('data-wsi-pointer');
|
||||||
|
const isExpanded = header.getAttribute('data-expanded') === 'true';
|
||||||
|
if (isExpanded) {
|
||||||
|
expandedGroups.add(wsiPointer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
tableBody.innerHTML = '';
|
tableBody.innerHTML = '';
|
||||||
|
|
||||||
if (subscriptionsData.length === 0) {
|
if (subscriptionsData.length === 0) {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.innerHTML = '<td colspan="5" style="text-align: center; font-style: italic;">No active subscriptions</td>';
|
row.innerHTML = '<td colspan="4" style="text-align: center; font-style: italic;">No active subscriptions</td>';
|
||||||
tableBody.appendChild(row);
|
tableBody.appendChild(row);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriptionsData.forEach((subscription, index) => {
|
// Sort subscriptions by wsi_pointer to group them together
|
||||||
const row = document.createElement('tr');
|
subscriptionsData.sort((a, b) => {
|
||||||
|
const wsiA = a.wsi_pointer || '';
|
||||||
// Calculate duration
|
const wsiB = b.wsi_pointer || '';
|
||||||
const now = Math.floor(Date.now() / 1000);
|
return wsiA.localeCompare(wsiB);
|
||||||
const duration = now - subscription.created_at;
|
|
||||||
const durationStr = formatDuration(duration);
|
|
||||||
|
|
||||||
// Format client IP (show full IP for admin view)
|
|
||||||
const clientIP = subscription.client_ip || 'unknown';
|
|
||||||
|
|
||||||
// Format wsi_pointer (show full pointer)
|
|
||||||
const wsiPointer = subscription.wsi_pointer || 'N/A';
|
|
||||||
|
|
||||||
// Format filters (show actual filter details)
|
|
||||||
let filtersDisplay = 'None';
|
|
||||||
if (subscription.filters && subscription.filters.length > 0) {
|
|
||||||
const filterDetails = [];
|
|
||||||
subscription.filters.forEach((filter, index) => {
|
|
||||||
const parts = [];
|
|
||||||
|
|
||||||
// Add kinds if present
|
|
||||||
if (filter.kinds && Array.isArray(filter.kinds) && filter.kinds.length > 0) {
|
|
||||||
parts.push(`kinds:[${filter.kinds.join(',')}]`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add authors if present (truncate for display)
|
|
||||||
if (filter.authors && Array.isArray(filter.authors) && filter.authors.length > 0) {
|
|
||||||
const authorCount = filter.authors.length;
|
|
||||||
if (authorCount === 1) {
|
|
||||||
const shortPubkey = filter.authors[0].substring(0, 8) + '...';
|
|
||||||
parts.push(`authors:[${shortPubkey}]`);
|
|
||||||
} else {
|
|
||||||
parts.push(`authors:[${authorCount} pubkeys]`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add ids if present
|
|
||||||
if (filter.ids && Array.isArray(filter.ids) && filter.ids.length > 0) {
|
|
||||||
const idCount = filter.ids.length;
|
|
||||||
parts.push(`ids:[${idCount} event${idCount > 1 ? 's' : ''}]`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add time range if present
|
|
||||||
const timeParts = [];
|
|
||||||
if (filter.since && filter.since > 0) {
|
|
||||||
const sinceDate = new Date(filter.since * 1000).toLocaleString();
|
|
||||||
timeParts.push(`since:${sinceDate}`);
|
|
||||||
}
|
|
||||||
if (filter.until && filter.until > 0) {
|
|
||||||
const untilDate = new Date(filter.until * 1000).toLocaleString();
|
|
||||||
timeParts.push(`until:${untilDate}`);
|
|
||||||
}
|
|
||||||
if (timeParts.length > 0) {
|
|
||||||
parts.push(timeParts.join(', '));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add limit if present
|
|
||||||
if (filter.limit && filter.limit > 0) {
|
|
||||||
parts.push(`limit:${filter.limit}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add tag filters if present
|
|
||||||
if (filter.tag_filters && Array.isArray(filter.tag_filters) && filter.tag_filters.length > 0) {
|
|
||||||
parts.push(`tags:[${filter.tag_filters.length} filter${filter.tag_filters.length > 1 ? 's' : ''}]`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parts.length > 0) {
|
|
||||||
filterDetails.push(parts.join(', '));
|
|
||||||
} else {
|
|
||||||
filterDetails.push('empty filter');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
filtersDisplay = filterDetails.join(' | ');
|
|
||||||
}
|
|
||||||
|
|
||||||
row.innerHTML = `
|
|
||||||
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${subscription.id || 'N/A'}</td>
|
|
||||||
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${clientIP}</td>
|
|
||||||
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${wsiPointer}</td>
|
|
||||||
<td>${durationStr}</td>
|
|
||||||
<td>${filtersDisplay}</td>
|
|
||||||
`;
|
|
||||||
tableBody.appendChild(row);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Group subscriptions by wsi_pointer
|
||||||
|
const groupedSubscriptions = {};
|
||||||
|
subscriptionsData.forEach(sub => {
|
||||||
|
const wsiKey = sub.wsi_pointer || 'N/A';
|
||||||
|
if (!groupedSubscriptions[wsiKey]) {
|
||||||
|
groupedSubscriptions[wsiKey] = [];
|
||||||
|
}
|
||||||
|
groupedSubscriptions[wsiKey].push(sub);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create rows for each group
|
||||||
|
Object.entries(groupedSubscriptions).forEach(([wsiPointer, subscriptions]) => {
|
||||||
|
// Calculate group summary
|
||||||
|
const subCount = subscriptions.length;
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
const oldestDuration = Math.max(...subscriptions.map(s => now - s.created_at));
|
||||||
|
const oldestDurationStr = formatDuration(oldestDuration);
|
||||||
|
|
||||||
|
// Create header row (summary)
|
||||||
|
const headerRow = document.createElement('tr');
|
||||||
|
headerRow.className = 'subscription-group-header';
|
||||||
|
headerRow.setAttribute('data-wsi-pointer', wsiPointer);
|
||||||
|
const wasExpanded = expandedGroups.has(wsiPointer);
|
||||||
|
headerRow.setAttribute('data-expanded', wasExpanded ? 'true' : 'false');
|
||||||
|
|
||||||
|
headerRow.innerHTML = `
|
||||||
|
<td colspan="4" style="padding: 8px;">
|
||||||
|
<span class="expand-icon" style="display: inline-block; width: 20px; transition: transform 0.2s;">▶</span>
|
||||||
|
<strong style="font-family: 'Courier New', monospace; font-size: 12px;">Websocket: ${wsiPointer}</strong>
|
||||||
|
<span style="color: #666; margin-left: 15px;">
|
||||||
|
Subscriptions: ${subCount} | Oldest: ${oldestDurationStr}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Add click handler to toggle expansion
|
||||||
|
headerRow.addEventListener('click', () => toggleSubscriptionGroup(wsiPointer));
|
||||||
|
|
||||||
|
tableBody.appendChild(headerRow);
|
||||||
|
|
||||||
|
// Create detail rows (initially hidden)
|
||||||
|
subscriptions.forEach((subscription, index) => {
|
||||||
|
const detailRow = document.createElement('tr');
|
||||||
|
detailRow.className = 'subscription-detail-row';
|
||||||
|
detailRow.setAttribute('data-wsi-group', wsiPointer);
|
||||||
|
detailRow.style.display = 'none';
|
||||||
|
|
||||||
|
// Calculate duration
|
||||||
|
const duration = now - subscription.created_at;
|
||||||
|
const durationStr = formatDuration(duration);
|
||||||
|
|
||||||
|
// Format filters
|
||||||
|
let filtersDisplay = 'None';
|
||||||
|
if (subscription.filters && subscription.filters.length > 0) {
|
||||||
|
const filterDetails = [];
|
||||||
|
subscription.filters.forEach((filter) => {
|
||||||
|
const parts = [];
|
||||||
|
|
||||||
|
if (filter.kinds && Array.isArray(filter.kinds) && filter.kinds.length > 0) {
|
||||||
|
parts.push(`kinds:[${filter.kinds.join(',')}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.authors && Array.isArray(filter.authors) && filter.authors.length > 0) {
|
||||||
|
const authorCount = filter.authors.length;
|
||||||
|
if (authorCount === 1) {
|
||||||
|
const shortPubkey = filter.authors[0].substring(0, 8) + '...';
|
||||||
|
parts.push(`authors:[${shortPubkey}]`);
|
||||||
|
} else {
|
||||||
|
parts.push(`authors:[${authorCount} pubkeys]`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ids && Array.isArray(filter.ids) && filter.ids.length > 0) {
|
||||||
|
const idCount = filter.ids.length;
|
||||||
|
parts.push(`ids:[${idCount} event${idCount > 1 ? 's' : ''}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeParts = [];
|
||||||
|
if (filter.since && filter.since > 0) {
|
||||||
|
const sinceDate = new Date(filter.since * 1000).toLocaleString();
|
||||||
|
timeParts.push(`since:${sinceDate}`);
|
||||||
|
}
|
||||||
|
if (filter.until && filter.until > 0) {
|
||||||
|
const untilDate = new Date(filter.until * 1000).toLocaleString();
|
||||||
|
timeParts.push(`until:${untilDate}`);
|
||||||
|
}
|
||||||
|
if (timeParts.length > 0) {
|
||||||
|
parts.push(timeParts.join(', '));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.limit && filter.limit > 0) {
|
||||||
|
parts.push(`limit:${filter.limit}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.tag_filters && Array.isArray(filter.tag_filters) && filter.tag_filters.length > 0) {
|
||||||
|
parts.push(`tags:[${filter.tag_filters.length} filter${filter.tag_filters.length > 1 ? 's' : ''}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.length > 0) {
|
||||||
|
filterDetails.push(parts.join(', '));
|
||||||
|
} else {
|
||||||
|
filterDetails.push('empty filter');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filtersDisplay = filterDetails.join(' | ');
|
||||||
|
}
|
||||||
|
|
||||||
|
detailRow.innerHTML = `
|
||||||
|
<td class="subscription-detail-prefix">└─</td>
|
||||||
|
<td class="subscription-detail-id">${subscription.id || 'N/A'}</td>
|
||||||
|
<td class="subscription-detail-duration">${durationStr}</td>
|
||||||
|
<td class="subscription-detail-filters">${filtersDisplay}</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
tableBody.appendChild(detailRow);
|
||||||
|
|
||||||
|
// Restore expand/collapse state after adding all rows
|
||||||
|
if (wasExpanded) {
|
||||||
|
const detailRows = tableBody.querySelectorAll(`.subscription-detail-row[data-wsi-group="${wsiPointer}"]`);
|
||||||
|
detailRows.forEach(row => row.style.display = 'table-row');
|
||||||
|
const expandIcon = headerRow.querySelector('.expand-icon');
|
||||||
|
if (expandIcon) {
|
||||||
|
expandIcon.textContent = '▼';
|
||||||
|
expandIcon.style.transform = 'rotate(90deg)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle function for expanding/collapsing groups
|
||||||
|
function toggleSubscriptionGroup(wsiPointer) {
|
||||||
|
const headerRow = document.querySelector(`.subscription-group-header[data-wsi-pointer="${wsiPointer}"]`);
|
||||||
|
const detailRows = document.querySelectorAll(`.subscription-detail-row[data-wsi-group="${wsiPointer}"]`);
|
||||||
|
const expandIcon = headerRow.querySelector('.expand-icon');
|
||||||
|
|
||||||
|
const isExpanded = headerRow.getAttribute('data-expanded') === 'true';
|
||||||
|
|
||||||
|
if (isExpanded) {
|
||||||
|
// Collapse
|
||||||
|
detailRows.forEach(row => row.style.display = 'none');
|
||||||
|
expandIcon.textContent = '▶';
|
||||||
|
expandIcon.style.transform = 'rotate(0deg)';
|
||||||
|
headerRow.setAttribute('data-expanded', 'false');
|
||||||
|
} else {
|
||||||
|
// Expand
|
||||||
|
detailRows.forEach(row => row.style.display = 'table-row');
|
||||||
|
expandIcon.textContent = '▼';
|
||||||
|
expandIcon.style.transform = 'rotate(90deg)';
|
||||||
|
headerRow.setAttribute('data-expanded', 'true');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to format duration in human-readable format
|
// Helper function to format duration in human-readable format
|
||||||
@@ -4779,7 +4864,7 @@ const SQL_QUERY_TEMPLATES = {
|
|||||||
subscriptions: "SELECT * FROM active_subscriptions_log ORDER BY created_at DESC",
|
subscriptions: "SELECT * FROM active_subscriptions_log ORDER BY created_at DESC",
|
||||||
top_pubkeys: "SELECT * FROM top_pubkeys_view",
|
top_pubkeys: "SELECT * FROM top_pubkeys_view",
|
||||||
event_kinds: "SELECT * FROM event_kinds_view ORDER BY count DESC",
|
event_kinds: "SELECT * FROM event_kinds_view ORDER BY count DESC",
|
||||||
time_stats: "SELECT * FROM time_stats_view"
|
time_stats: "SELECT 'total' as period, COUNT(*) as total_events, COUNT(DISTINCT pubkey) as unique_pubkeys, MIN(created_at) as oldest_event, MAX(created_at) as newest_event FROM events UNION ALL SELECT '24h' as period, COUNT(*) as total_events, COUNT(DISTINCT pubkey) as unique_pubkeys, MIN(created_at) as oldest_event, MAX(created_at) as newest_event FROM events WHERE created_at >= (strftime('%s', 'now') - 86400) UNION ALL SELECT '7d' as period, COUNT(*) as total_events, COUNT(DISTINCT pubkey) as unique_pubkeys, MIN(created_at) as oldest_event, MAX(created_at) as newest_event FROM events WHERE created_at >= (strftime('%s', 'now') - 604800) UNION ALL SELECT '30d' as period, COUNT(*) as total_events, COUNT(DISTINCT pubkey) as unique_pubkeys, MIN(created_at) as oldest_event, MAX(created_at) as newest_event FROM events WHERE created_at >= (strftime('%s', 'now') - 2592000)"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Query history management (localStorage)
|
// Query history management (localStorage)
|
||||||
|
|||||||
BIN
c-relay-1.0.0.tar.gz
Normal file
BIN
c-relay-2.0.0.tar.gz
Normal file
BIN
c-relay-3.0.0.tar.gz
Normal file
BIN
c-relay-4.0.0.tar.gz
Normal file
BIN
c-relay-5.0.0.tar.gz
Normal file
BIN
c-relay-6.0.0.tar.gz
Normal file
BIN
c-relay-7.0.0.tar.gz
Normal file
24
debug.log
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
=== NOSTR WebSocket Debug Log Started ===
|
|
||||||
[14:16:28.243] SEND localhost:8888: ["EVENT", {
|
|
||||||
"pubkey": "193279d1459ba1399aadb954422bf8595aa77367dccf482c682f5f208e435844",
|
|
||||||
"created_at": 1761499411,
|
|
||||||
"kind": 1059,
|
|
||||||
"tags": [["p", "4f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa"]],
|
|
||||||
"content": "AmWNi4P5J126kk69XH2o5mYvGj+69+Fjfr/nZx892I2z8edkwtp2IH7XAnPUqdGPu7x1xiZF1sNfr21VKThOhE54K/uQHLFydZN3acgUfX13sCeWhrvnQD0EvjvZC6QzW9DfFayYoYl+rEPYcra1/N68a+N1R7XnNcf1K/ZFh5Grcnln0H5YdXKRBhQI9aai4iFp1VGy2V0IR+6gDJGbJ7TbAbD3wgGWv1i77C03skH3RgzH+f2b7VBtm+vjKX6q7v6v8j3w1lRFE5Qh0Tqgedh3+UsnwqQta7OCzF9OyAVPK7EqKQBss5LzYSRUpcCE1vw5b7I7yeBFwU9WfnGLUW+uZxMJ2C3P4NBBrVO8UFIkBrPL2cqkoD5c8DgMLJjXGmc4EWfB4ZWb3KjbfLbgi6DVQ++cDjBbnCOPhX+/4qOnWq+gI28e/xk3cBvQtgUOkvWX3oGl3/Q33u4UGtxkFEXGfzdKHVDkR86kqf7RMZjIwTjLGpx4uov0cNmzj07hYEdoG/lJ4yA1v/GyF7viJdnnz3tE0hCZaViqSCev0rfUHWRDDMXJzJ9SS+OwpVswSG4NKvYsDhDM89BjhFs08HshTFdIh2AY45jR/16CsZM9JudH5BwqcX23wToYdZ+lrerOA0EkYb0DJUzGVe4lMpdJZoB8qXLHxMAKwKu0UEWEkeBnnZbvTGwCRbfGorxwPrnyqUCy9tzJx0GOLhRIzBmt6lki607VLDYjK97VIz0dff3fyWPAfy/yBlO2nHhVubUgpPaAjcaYNkO/iZwuP8oJkClWWmKwAQoNoxt+Ly2llrkz+Ne8oXMQdJSq416x6MLHo2JbKH8uwjx0yKG0oldLyWaz3A8OHYkJuxOi7HPVTlOOJrsjG4kMn2g97rVUXLs5v9F/StOjzxtiQWmCBtCsvK2LEEK/DzfavcJstEMxQztJjhiYRO3MJanL7lN2zu1ZHO149FJrgqGV6RQ8DDXf55yuabqHilBuUSDKpI0gl0+Efuor1my+L9J7MjJQ83aSwGizX7uXedMsGQRcvU3++Uvbw7sd2l67fb7IoYU04TPGZkIm120qwf7GAUpnDL7Lhulu/9LFMFs3UnGl9cLzY6EAJtDANHjMAoXbGbYclnoSiNW4yr3X9PBHO5o2YhIxfpTyEgLebJLOkzoziuCTpX8/MdhOhFtlIyo5B8Mbt5GDOHh4x1ZMKOl02J00Vvgui0hLw4Vri8Lz/ErPIRSlrEOB+8K5zPzJy/bD8XrOKlOwSbF5j9dsqs+8uCTC/v9YNQ0cC9wP7gVAxErQ3suJVeV7pzY+eGR051AcW7ppTs1gShhxDDaSaKdMlrkBdFDZcCJ+tomSgW56bOi45erpmk8Lcv4RrBzjBtq1hz+XSaTBAtEnGtHNH2uOn7KP/NNaD38dYkpb3N1VR3zuV67RcuPZeB+5WR9jhnLoSMGox2s=",
|
|
||||||
"id": "c6c18d902744fc0aaa4ca9172b3bcd0dde3fd7d943b41b2a39a16927ede67804",
|
|
||||||
"sig": "d67e0e914aa361c528510efd216548b6734a5fa68c46426571fbc87626bf19a9ec46e16883e7fad700f4fee5cfffd9bba03c3c08e57938fbca77a28b30a32bb7"
|
|
||||||
}]
|
|
||||||
[14:16:28.256] RECV localhost:8888: ["OK", "c6c18d902744fc0aaa4ca9172b3bcd0dde3fd7d943b41b2a39a16927ede67804", true, ""]
|
|
||||||
|
|
||||||
=== NOSTR WebSocket Debug Log Started ===
|
|
||||||
[15:01:18.592] SEND localhost:8888: ["EVENT", {
|
|
||||||
"pubkey": "ec9578ade9e74358ed35d8091d41bfa277e86d649614a8865e3725e38ebe5bc9",
|
|
||||||
"created_at": 1761502101,
|
|
||||||
"kind": 1059,
|
|
||||||
"tags": [["p", "4f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa"]],
|
|
||||||
"content": "AlgLnVwti8Dk2nu0e4bMrXeZiR/u+RPnA85kpts2svaFGfMByS4iap7xqdiSrXpSQPjQsix6jP9Qiy1a6rrvC6MutqTi3JfsMexLR61/ZKTK41sWTXNDTT3keH543vx3fVQH1mq+LgG4mjNzkPe0RqkYFvC8R0nxyAcCecHDxZUlmXQmAGiB5JB2GvstA4eoZLP1OI3fcLA3qaITLNRJOwRUoTYKqUkENHwz74CW0TnYDrKRZVe9zKNWQBLmtsgVoGd5CXNAVgXwmm2h0eCNIcRGnFqDHzpegpEGO+A7tvB0KJwlj4j/GmRgmnWO4pkrM2fmsTdlb5KNqe7NPuTVgYfdvld70zWpenp7jF/0psaEQEl8R7FbG2rNCv8fXtH+womvJQj4S0eUBxfvsUU1wWYmhusEzvyTfpV/nw0Er+pmAUZ2eGk7LEB2GMsJrkT+G5oohm0n+5c72iWJqW9A1eAzjR6Z21FkH4kAEJOl70fw9Xeig+s9rYk3GcKlMvj42zf7DepMXHPy62TbqUeclcm5W/semyasGP521GBuw152IN+dS67OVVmEvEJ89xhwiTeIty78enR4Gq7d1eNK+rqStdtJ7FN6kD/8gv4sFojUXyi0sIxzaSPrwI3ohOqbpEK1dTs6fmTUiyT/Buq++IhD9UwsZgz/kYpZfm1NVnWx+yTEv4I1H80FDxmMzbYnTHuIdRJFeh/NJRy9h+gXoZlZnteHkbwm1w2AejTkVnGs2Pz7aUZgC+1Za8fhtXq3Z9N3R8f8gtVFnnjRzApg5U89QrXUBS0R6F9dTqINk4qti94JWO4dYcPuudCutME5hfCYBoo+LHuRmdPKry7vSK1WgLYQsHuG+r313Ak8DhZYNbL+0d5UJ9kDFlFKaP3xLahSbEc/7u+AyuN68IyM1NwEehllxqVUsX8dsD4bZ2yW5rVjAQm9tT8Ypm73kJEb+DYVqT0WjFx88ee+HX89a9NgszWf1HE1KNQ9gWjn4eH6xbwrOkS4/v2O2tQoAd00vyPKAWly3Zlrz2cRnrSnxTZ5Lt7HtwAt6Err8MhD/w5rMLXHTBCMrroG1VfMo1OgL1YPafKDZmwVcHWacqtZiB0heRx742WipmTonqMjCOTNufdwxQcRPLLio0mtqiIrzgJqqIQenBXSa1jaG6Lvb5PCUKThbg4sSFfgssoUNKM7ytmBAe+PPmOVe11/gGaFWoQeUordbvmiCtzIPUYiKsuhfeK4I3jKvEofQU37hOam8ZxUczXvX6dgOOto002EWyCVfAzFgyey6wI+FGEbhXqlw7nB+azpqLQMJnHg7pfb1stXk3d8rjgVrRsVRJe/5KrXyZ5cd7ftJuJLxpTYmfFu6CKoUE0L5eRxXiwa16Pi0BehxOLaZteiTzttyfj+ClMKs2J/2/T1BVya1oGUW2Wg6ri/qS8oXv8bqiXBZ1/BwfI=",
|
|
||||||
"id": "ea5bb419a8efea8ee86bb8696406a70a0387a7d0ac6e60760026d1aea28b427f",
|
|
||||||
"sig": "0ffde3fd0d83c80693aa656668f2553807f8d474738ff3d9676090a5b8748a8e8e0c75a1d64963e4604046e18a806c4371a9cf2af2fd72f9db50f15bc78a4e25"
|
|
||||||
}]
|
|
||||||
[15:01:18.604] RECV localhost:8888: ["OK", "ea5bb419a8efea8ee86bb8696406a70a0387a7d0ac6e60760026d1aea28b427f", true, ""]
|
|
||||||
@@ -4,16 +4,16 @@
|
|||||||
cp build/c_relay_x86 ~/Storage/c_relay/crelay
|
cp build/c_relay_x86 ~/Storage/c_relay/crelay
|
||||||
|
|
||||||
# Copy the local service file to systemd
|
# Copy the local service file to systemd
|
||||||
sudo cp systemd/c-relay-local.service /etc/systemd/system/
|
# sudo cp systemd/c-relay-local.service /etc/systemd/system/
|
||||||
|
|
||||||
# Reload systemd daemon to pick up the new service
|
# Reload systemd daemon to pick up the new service
|
||||||
sudo systemctl daemon-reload
|
# sudo systemctl daemon-reload
|
||||||
|
|
||||||
# Enable the service (if not already enabled)
|
# Enable the service (if not already enabled)
|
||||||
sudo systemctl enable c-relay-local.service
|
# sudo systemctl enable c-relay-local.service
|
||||||
|
|
||||||
# Restart the service
|
# Restart the service
|
||||||
sudo systemctl restart c-relay-local.service
|
# sudo systemctl restart c-relay-local.service
|
||||||
|
|
||||||
# Show service status
|
# Show service status
|
||||||
sudo systemctl status c-relay-local.service --no-pager -l
|
# sudo systemctl status c-relay-local.service --no-pager -l
|
||||||
|
|||||||
@@ -175,6 +175,18 @@ Configuration events follow the standard Nostr event format with kind 33334:
|
|||||||
- **Impact**: Allows some flexibility in expiration timing
|
- **Impact**: Allows some flexibility in expiration timing
|
||||||
- **Example**: `"600"` (10 minute grace period)
|
- **Example**: `"600"` (10 minute grace period)
|
||||||
|
|
||||||
|
### NIP-59 Gift Wrap Timestamp Configuration
|
||||||
|
|
||||||
|
#### `nip59_timestamp_max_delay_sec`
|
||||||
|
- **Description**: Controls timestamp randomization for NIP-59 gift wraps
|
||||||
|
- **Default**: `"0"` (no randomization)
|
||||||
|
- **Range**: `0` to `604800` (7 days)
|
||||||
|
- **Impact**: Affects compatibility with other Nostr clients for direct messaging
|
||||||
|
- **Values**:
|
||||||
|
- `"0"`: No randomization (maximum compatibility)
|
||||||
|
- `"1-604800"`: Random timestamp between now and N seconds ago
|
||||||
|
- **Example**: `"172800"` (2 days randomization for privacy)
|
||||||
|
|
||||||
## Configuration Examples
|
## Configuration Examples
|
||||||
|
|
||||||
### Basic Relay Setup
|
### Basic Relay Setup
|
||||||
|
|||||||
517
docs/nip59_timestamp_configuration_plan.md
Normal file
@@ -0,0 +1,517 @@
|
|||||||
|
# NIP-59 Timestamp Configuration Implementation Plan
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
Add configurable timestamp randomization for NIP-59 gift wraps to improve compatibility with Nostr apps that don't implement timestamp randomization.
|
||||||
|
|
||||||
|
## Problem Statement
|
||||||
|
The NIP-59 protocol specifies that timestamps on gift wraps should have randomness to prevent time-analysis attacks. However, some Nostr platforms don't implement this, causing compatibility issues with direct messaging (NIP-17).
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
Add a configuration parameter `nip59_timestamp_max_delay_sec` that controls the maximum random delay applied to timestamps:
|
||||||
|
- **Value = 0**: Use current timestamp (no randomization) for maximum compatibility
|
||||||
|
- **Value > 0**: Use random timestamp between now and N seconds ago
|
||||||
|
- **Default = 0**: Maximum compatibility mode (no randomization)
|
||||||
|
|
||||||
|
## Implementation Approach: Option B (Direct Parameter Addition)
|
||||||
|
We chose Option B because:
|
||||||
|
1. Explicit and stateless - value flows through call chain
|
||||||
|
2. Thread-safe by design
|
||||||
|
3. No global state needed in nostr_core_lib
|
||||||
|
4. DMs are sent rarely, so database query per call is acceptable
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Detailed Implementation Steps
|
||||||
|
|
||||||
|
### Phase 1: Configuration Setup in c-relay
|
||||||
|
|
||||||
|
#### 1.1 Add Configuration Parameter
|
||||||
|
**File:** `src/default_config_event.h`
|
||||||
|
**Location:** Line 82 (after `trust_proxy_headers`)
|
||||||
|
|
||||||
|
```c
|
||||||
|
// NIP-59 Gift Wrap Timestamp Configuration
|
||||||
|
{"nip59_timestamp_max_delay_sec", "0"} // Default: 0 (no randomization for compatibility)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Rationale:**
|
||||||
|
- Default of 0 seconds (no randomization) for maximum compatibility
|
||||||
|
- Placed after proxy settings, before closing brace
|
||||||
|
- Follows existing naming convention
|
||||||
|
|
||||||
|
#### 1.2 Add Configuration Validation
|
||||||
|
**File:** `src/config.c`
|
||||||
|
**Function:** `validate_config_field()` (around line 923)
|
||||||
|
|
||||||
|
Add validation case:
|
||||||
|
```c
|
||||||
|
else if (strcmp(key, "nip59_timestamp_max_delay_sec") == 0) {
|
||||||
|
long value = strtol(value_str, NULL, 10);
|
||||||
|
if (value < 0 || value > 604800) { // Max 7 days
|
||||||
|
snprintf(error_msg, error_size,
|
||||||
|
"nip59_timestamp_max_delay_sec must be between 0 and 604800 (7 days)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Rationale:**
|
||||||
|
- 0 = no randomization (compatibility mode)
|
||||||
|
- 604800 = 7 days maximum (reasonable upper bound)
|
||||||
|
- Prevents negative values or excessive delays
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 2: Modify nostr_core_lib Functions
|
||||||
|
|
||||||
|
#### 2.1 Update random_past_timestamp() Function
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip059.c`
|
||||||
|
**Current Location:** Lines 31-36
|
||||||
|
|
||||||
|
**Current Code:**
|
||||||
|
```c
|
||||||
|
static time_t random_past_timestamp(void) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
// Random time up to 2 days (172800 seconds) in the past
|
||||||
|
long random_offset = (long)(rand() % 172800);
|
||||||
|
return now - random_offset;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**New Code:**
|
||||||
|
```c
|
||||||
|
static time_t random_past_timestamp(long max_delay_sec) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
// If max_delay_sec is 0, return current timestamp (no randomization)
|
||||||
|
if (max_delay_sec == 0) {
|
||||||
|
return now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Random time up to max_delay_sec in the past
|
||||||
|
long random_offset = (long)(rand() % max_delay_sec);
|
||||||
|
return now - random_offset;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Changes:**
|
||||||
|
- Add `long max_delay_sec` parameter
|
||||||
|
- Handle special case: `max_delay_sec == 0` returns current time
|
||||||
|
- Use `max_delay_sec` instead of hardcoded 172800
|
||||||
|
|
||||||
|
#### 2.2 Update nostr_nip59_create_seal() Function
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip059.c`
|
||||||
|
**Current Location:** Lines 144-215
|
||||||
|
|
||||||
|
**Function Signature Change:**
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* nostr_nip59_create_seal(cJSON* rumor,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
const unsigned char* recipient_public_key);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* nostr_nip59_create_seal(cJSON* rumor,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
const unsigned char* recipient_public_key,
|
||||||
|
long max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Code Change at Line 181:**
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
time_t seal_time = random_past_timestamp();
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
time_t seal_time = random_past_timestamp(max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2.3 Update nostr_nip59_create_gift_wrap() Function
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip059.c`
|
||||||
|
**Current Location:** Lines 220-323
|
||||||
|
|
||||||
|
**Function Signature Change:**
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* nostr_nip59_create_gift_wrap(cJSON* seal,
|
||||||
|
const char* recipient_public_key_hex);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* nostr_nip59_create_gift_wrap(cJSON* seal,
|
||||||
|
const char* recipient_public_key_hex,
|
||||||
|
long max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Code Change at Line 275:**
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
time_t wrap_time = random_past_timestamp();
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
time_t wrap_time = random_past_timestamp(max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2.4 Update nip059.h Header
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip059.h`
|
||||||
|
**Locations:** Lines 38-39 and 48
|
||||||
|
|
||||||
|
**Update Function Declarations:**
|
||||||
|
```c
|
||||||
|
// Line 38-39: Update nostr_nip59_create_seal
|
||||||
|
cJSON* nostr_nip59_create_seal(cJSON* rumor,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
const unsigned char* recipient_public_key,
|
||||||
|
long max_delay_sec);
|
||||||
|
|
||||||
|
// Line 48: Update nostr_nip59_create_gift_wrap
|
||||||
|
cJSON* nostr_nip59_create_gift_wrap(cJSON* seal,
|
||||||
|
const char* recipient_public_key_hex,
|
||||||
|
long max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Update Documentation Comments:**
|
||||||
|
```c
|
||||||
|
/**
|
||||||
|
* NIP-59: Create a seal (kind 13) wrapping a rumor
|
||||||
|
*
|
||||||
|
* @param rumor The rumor event to seal (cJSON object)
|
||||||
|
* @param sender_private_key 32-byte sender private key
|
||||||
|
* @param recipient_public_key 32-byte recipient public key (x-only)
|
||||||
|
* @param max_delay_sec Maximum random delay in seconds (0 = no randomization)
|
||||||
|
* @return cJSON object representing the seal event, or NULL on error
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NIP-59: Create a gift wrap (kind 1059) wrapping a seal
|
||||||
|
*
|
||||||
|
* @param seal The seal event to wrap (cJSON object)
|
||||||
|
* @param recipient_public_key_hex Recipient's public key in hex format
|
||||||
|
* @param max_delay_sec Maximum random delay in seconds (0 = no randomization)
|
||||||
|
* @return cJSON object representing the gift wrap event, or NULL on error
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 3: Update NIP-17 Integration
|
||||||
|
|
||||||
|
#### 3.1 Update nostr_nip17_send_dm() Function
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip017.c`
|
||||||
|
**Current Location:** Lines 260-320
|
||||||
|
|
||||||
|
**Function Signature Change:**
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
int nostr_nip17_send_dm(cJSON* dm_event,
|
||||||
|
const char** recipient_pubkeys,
|
||||||
|
int num_recipients,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
cJSON** gift_wraps_out,
|
||||||
|
int max_gift_wraps);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
int nostr_nip17_send_dm(cJSON* dm_event,
|
||||||
|
const char** recipient_pubkeys,
|
||||||
|
int num_recipients,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
cJSON** gift_wraps_out,
|
||||||
|
int max_gift_wraps,
|
||||||
|
long max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Code Changes:**
|
||||||
|
|
||||||
|
At line 281 (seal creation):
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* seal = nostr_nip59_create_seal(dm_event, sender_private_key, recipient_public_key);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* seal = nostr_nip59_create_seal(dm_event, sender_private_key, recipient_public_key, max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
At line 287 (gift wrap creation):
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* gift_wrap = nostr_nip59_create_gift_wrap(seal, recipient_pubkeys[i]);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* gift_wrap = nostr_nip59_create_gift_wrap(seal, recipient_pubkeys[i], max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
At line 306 (sender seal creation):
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* sender_seal = nostr_nip59_create_seal(dm_event, sender_private_key, sender_public_key);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* sender_seal = nostr_nip59_create_seal(dm_event, sender_private_key, sender_public_key, max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
At line 309 (sender gift wrap creation):
|
||||||
|
```c
|
||||||
|
// OLD:
|
||||||
|
cJSON* sender_gift_wrap = nostr_nip59_create_gift_wrap(sender_seal, sender_pubkey_hex);
|
||||||
|
|
||||||
|
// NEW:
|
||||||
|
cJSON* sender_gift_wrap = nostr_nip59_create_gift_wrap(sender_seal, sender_pubkey_hex, max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3.2 Update nip017.h Header
|
||||||
|
**File:** `nostr_core_lib/nostr_core/nip017.h`
|
||||||
|
**Location:** Lines 102-107
|
||||||
|
|
||||||
|
**Update Function Declaration:**
|
||||||
|
```c
|
||||||
|
int nostr_nip17_send_dm(cJSON* dm_event,
|
||||||
|
const char** recipient_pubkeys,
|
||||||
|
int num_recipients,
|
||||||
|
const unsigned char* sender_private_key,
|
||||||
|
cJSON** gift_wraps_out,
|
||||||
|
int max_gift_wraps,
|
||||||
|
long max_delay_sec);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Update Documentation Comment (lines 88-100):**
|
||||||
|
```c
|
||||||
|
/**
|
||||||
|
* NIP-17: Send a direct message to recipients
|
||||||
|
*
|
||||||
|
* This function creates the appropriate rumor, seals it, gift wraps it,
|
||||||
|
* and returns the final gift wrap events ready for publishing.
|
||||||
|
*
|
||||||
|
* @param dm_event The unsigned DM event (kind 14 or 15)
|
||||||
|
* @param recipient_pubkeys Array of recipient public keys (hex strings)
|
||||||
|
* @param num_recipients Number of recipients
|
||||||
|
* @param sender_private_key 32-byte sender private key
|
||||||
|
* @param gift_wraps_out Array to store resulting gift wrap events (caller must free)
|
||||||
|
* @param max_gift_wraps Maximum number of gift wraps to create
|
||||||
|
* @param max_delay_sec Maximum random timestamp delay in seconds (0 = no randomization)
|
||||||
|
* @return Number of gift wrap events created, or -1 on error
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 4: Update c-relay Call Sites
|
||||||
|
|
||||||
|
#### 4.1 Update src/api.c
|
||||||
|
**Location:** Line 1319
|
||||||
|
|
||||||
|
**Current Code:**
|
||||||
|
```c
|
||||||
|
int send_result = nostr_nip17_send_dm(
|
||||||
|
dm_response, // dm_event
|
||||||
|
recipient_pubkeys, // recipient_pubkeys
|
||||||
|
1, // num_recipients
|
||||||
|
relay_privkey, // sender_private_key
|
||||||
|
gift_wraps, // gift_wraps_out
|
||||||
|
1 // max_gift_wraps
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
**New Code:**
|
||||||
|
```c
|
||||||
|
// Get timestamp delay configuration
|
||||||
|
long max_delay_sec = get_config_int("nip59_timestamp_max_delay_sec", 0);
|
||||||
|
|
||||||
|
int send_result = nostr_nip17_send_dm(
|
||||||
|
dm_response, // dm_event
|
||||||
|
recipient_pubkeys, // recipient_pubkeys
|
||||||
|
1, // num_recipients
|
||||||
|
relay_privkey, // sender_private_key
|
||||||
|
gift_wraps, // gift_wraps_out
|
||||||
|
1, // max_gift_wraps
|
||||||
|
max_delay_sec // max_delay_sec
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4.2 Update src/dm_admin.c
|
||||||
|
**Location:** Line 371
|
||||||
|
|
||||||
|
**Current Code:**
|
||||||
|
```c
|
||||||
|
int send_result = nostr_nip17_send_dm(
|
||||||
|
success_dm, // dm_event
|
||||||
|
sender_pubkey_array, // recipient_pubkeys
|
||||||
|
1, // num_recipients
|
||||||
|
relay_privkey, // sender_private_key
|
||||||
|
success_gift_wraps, // gift_wraps_out
|
||||||
|
1 // max_gift_wraps
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
**New Code:**
|
||||||
|
```c
|
||||||
|
// Get timestamp delay configuration
|
||||||
|
long max_delay_sec = get_config_int("nip59_timestamp_max_delay_sec", 0);
|
||||||
|
|
||||||
|
int send_result = nostr_nip17_send_dm(
|
||||||
|
success_dm, // dm_event
|
||||||
|
sender_pubkey_array, // recipient_pubkeys
|
||||||
|
1, // num_recipients
|
||||||
|
relay_privkey, // sender_private_key
|
||||||
|
success_gift_wraps, // gift_wraps_out
|
||||||
|
1, // max_gift_wraps
|
||||||
|
max_delay_sec // max_delay_sec
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Both files already include `config.h`, so `get_config_int()` is available.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Testing Plan
|
||||||
|
|
||||||
|
### Test Case 1: No Randomization (Compatibility Mode)
|
||||||
|
**Configuration:** `nip59_timestamp_max_delay_sec = 0`
|
||||||
|
|
||||||
|
**Expected Behavior:**
|
||||||
|
- Gift wrap timestamps should equal current time
|
||||||
|
- Seal timestamps should equal current time
|
||||||
|
- No random delay applied
|
||||||
|
|
||||||
|
**Test Command:**
|
||||||
|
```bash
|
||||||
|
# Set config via admin API
|
||||||
|
# Send test DM
|
||||||
|
# Verify timestamps are current (within 1 second of send time)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Case 2: Custom Delay
|
||||||
|
**Configuration:** `nip59_timestamp_max_delay_sec = 1000`
|
||||||
|
|
||||||
|
**Expected Behavior:**
|
||||||
|
- Gift wrap timestamps should be between now and 1000 seconds ago
|
||||||
|
- Seal timestamps should be between now and 1000 seconds ago
|
||||||
|
- Random delay applied within specified range
|
||||||
|
|
||||||
|
**Test Command:**
|
||||||
|
```bash
|
||||||
|
# Set config via admin API
|
||||||
|
# Send test DM
|
||||||
|
# Verify timestamps are in past but within 1000 seconds
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Case 3: Default Behavior
|
||||||
|
**Configuration:** `nip59_timestamp_max_delay_sec = 0` (default)
|
||||||
|
|
||||||
|
**Expected Behavior:**
|
||||||
|
- Gift wrap timestamps should equal current time
|
||||||
|
- Seal timestamps should equal current time
|
||||||
|
- No randomization (maximum compatibility)
|
||||||
|
|
||||||
|
**Test Command:**
|
||||||
|
```bash
|
||||||
|
# Use default config
|
||||||
|
# Send test DM
|
||||||
|
# Verify timestamps are current (within 1 second of send time)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Case 4: Configuration Validation
|
||||||
|
**Test Invalid Values:**
|
||||||
|
- Negative value: Should be rejected
|
||||||
|
- Value > 604800: Should be rejected
|
||||||
|
- Valid boundary values (0, 604800): Should be accepted
|
||||||
|
|
||||||
|
### Test Case 5: Interoperability
|
||||||
|
**Test with Other Nostr Clients:**
|
||||||
|
- Send DM with `max_delay_sec = 0` to clients that don't randomize
|
||||||
|
- Send DM with `max_delay_sec = 172800` to clients that do randomize
|
||||||
|
- Verify both scenarios work correctly
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Documentation Updates
|
||||||
|
|
||||||
|
### Update docs/configuration_guide.md
|
||||||
|
|
||||||
|
Add new section:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
### NIP-59 Gift Wrap Timestamp Configuration
|
||||||
|
|
||||||
|
#### nip59_timestamp_max_delay_sec
|
||||||
|
- **Type:** Integer
|
||||||
|
- **Default:** 0 (no randomization)
|
||||||
|
- **Range:** 0 to 604800 (7 days)
|
||||||
|
- **Description:** Controls timestamp randomization for NIP-59 gift wraps
|
||||||
|
|
||||||
|
The NIP-59 protocol recommends randomizing timestamps on gift wraps to prevent
|
||||||
|
time-analysis attacks. However, some Nostr platforms don't implement this,
|
||||||
|
causing compatibility issues.
|
||||||
|
|
||||||
|
**Values:**
|
||||||
|
- `0` (default): No randomization - uses current timestamp (maximum compatibility)
|
||||||
|
- `1-604800`: Random timestamp between now and N seconds ago
|
||||||
|
|
||||||
|
**Use Cases:**
|
||||||
|
- Keep default `0` for maximum compatibility with clients that don't randomize
|
||||||
|
- Set to `172800` for privacy per NIP-59 specification (2 days randomization)
|
||||||
|
- Set to custom value (e.g., `3600`) for 1-hour randomization window
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
```json
|
||||||
|
["nip59_timestamp_max_delay_sec", "0"] // Default: compatibility mode
|
||||||
|
["nip59_timestamp_max_delay_sec", "3600"] // 1 hour randomization
|
||||||
|
["nip59_timestamp_max_delay_sec", "172800"] // 2 days randomization
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Implementation Checklist
|
||||||
|
|
||||||
|
### nostr_core_lib Changes
|
||||||
|
- [ ] Modify `random_past_timestamp()` to accept `max_delay_sec` parameter
|
||||||
|
- [ ] Update `nostr_nip59_create_seal()` signature and implementation
|
||||||
|
- [ ] Update `nostr_nip59_create_gift_wrap()` signature and implementation
|
||||||
|
- [ ] Update `nip059.h` function declarations and documentation
|
||||||
|
- [ ] Update `nostr_nip17_send_dm()` signature and implementation
|
||||||
|
- [ ] Update `nip017.h` function declaration and documentation
|
||||||
|
|
||||||
|
### c-relay Changes
|
||||||
|
- [ ] Add `nip59_timestamp_max_delay_sec` to `default_config_event.h`
|
||||||
|
- [ ] Add validation in `config.c` for new parameter
|
||||||
|
- [ ] Update `src/api.c` call site to pass `max_delay_sec`
|
||||||
|
- [ ] Update `src/dm_admin.c` call site to pass `max_delay_sec`
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
- [ ] Test with `max_delay_sec = 0` (no randomization)
|
||||||
|
- [ ] Test with `max_delay_sec = 1000` (custom delay)
|
||||||
|
- [ ] Test with `max_delay_sec = 172800` (default behavior)
|
||||||
|
- [ ] Test configuration validation (invalid values)
|
||||||
|
- [ ] Test interoperability with other Nostr clients
|
||||||
|
|
||||||
|
### Documentation
|
||||||
|
- [ ] Update `docs/configuration_guide.md`
|
||||||
|
- [ ] Add this implementation plan to docs
|
||||||
|
- [ ] Update README if needed
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Rollback Plan
|
||||||
|
|
||||||
|
If issues arise:
|
||||||
|
1. Revert nostr_core_lib changes (git revert in submodule)
|
||||||
|
2. Revert c-relay changes
|
||||||
|
3. Configuration parameter will be ignored if not used
|
||||||
|
4. Default behavior (0) provides maximum compatibility
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- The configuration is read on each DM send, allowing runtime changes
|
||||||
|
- No restart required when changing `nip59_timestamp_max_delay_sec`
|
||||||
|
- Thread-safe by design (no global state)
|
||||||
|
- Default value of 0 provides maximum compatibility with other Nostr clients
|
||||||
|
- Can be changed to 172800 or other values for NIP-59 privacy features
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [NIP-59: Gift Wrap](https://github.com/nostr-protocol/nips/blob/master/59.md)
|
||||||
|
- [NIP-17: Private Direct Messages](https://github.com/nostr-protocol/nips/blob/master/17.md)
|
||||||
|
- [NIP-44: Versioned Encryption](https://github.com/nostr-protocol/nips/blob/master/44.md)
|
||||||
358
docs/subscription_table_collapse_plan.md
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
# Subscription Table Collapsible Groups Implementation Plan
|
||||||
|
|
||||||
|
## Objective
|
||||||
|
Add collapsible/expandable functionality to subscription groups, where:
|
||||||
|
1. Each WSI Pointer group starts collapsed, showing only a summary row
|
||||||
|
2. Clicking the summary row expands to show all subscription details for that WSI Pointer
|
||||||
|
3. Clicking again collapses the group back to the summary row
|
||||||
|
|
||||||
|
## Current Behavior
|
||||||
|
- All subscriptions are displayed in a flat list
|
||||||
|
- WSI Pointer value shown only on first row of each group
|
||||||
|
- No interaction or collapse functionality
|
||||||
|
|
||||||
|
## Desired Behavior
|
||||||
|
- **Collapsed state**: One row per WSI Pointer showing summary information
|
||||||
|
- **Expanded state**: Header row + detail rows for each subscription in that group
|
||||||
|
- **Toggle**: Click on header row to expand/collapse
|
||||||
|
- **Visual indicator**: Arrow or icon showing expand/collapse state
|
||||||
|
|
||||||
|
## Design Approach
|
||||||
|
|
||||||
|
### Option 1: Summary Row + Detail Rows (Recommended)
|
||||||
|
```
|
||||||
|
[▶] WSI Pointer: 0x12345678 | Subscriptions: 3 | Total Duration: 15m
|
||||||
|
(detail rows hidden)
|
||||||
|
|
||||||
|
When clicked:
|
||||||
|
[▼] WSI Pointer: 0x12345678 | Subscriptions: 3 | Total Duration: 15m
|
||||||
|
| sub-001 | 5m 30s | kinds:[1]
|
||||||
|
| sub-002 | 3m 15s | kinds:[3]
|
||||||
|
| sub-003 | 6m 15s | kinds:[1,3]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 2: First Row as Header (Alternative)
|
||||||
|
```
|
||||||
|
[▶] 0x12345678 | sub-001 | 5m 30s | kinds:[1] (+ 2 more)
|
||||||
|
|
||||||
|
When clicked:
|
||||||
|
[▼] 0x12345678 | sub-001 | 5m 30s | kinds:[1]
|
||||||
|
| sub-002 | 3m 15s | kinds:[3]
|
||||||
|
| sub-003 | 6m 15s | kinds:[1,3]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Recommendation**: Option 1 provides clearer UX and better summary information.
|
||||||
|
|
||||||
|
## Implementation Details
|
||||||
|
|
||||||
|
### Files to Modify
|
||||||
|
1. `api/index.js` - Function `populateSubscriptionDetailsTable()` (lines 4277-4384)
|
||||||
|
2. `api/index.css` - Add styles for collapsible rows
|
||||||
|
|
||||||
|
### Data Structure Changes
|
||||||
|
|
||||||
|
Need to group subscriptions by WSI Pointer first:
|
||||||
|
```javascript
|
||||||
|
// Group subscriptions by wsi_pointer
|
||||||
|
const groupedSubscriptions = {};
|
||||||
|
subscriptionsData.forEach(sub => {
|
||||||
|
const wsiKey = sub.wsi_pointer || 'N/A';
|
||||||
|
if (!groupedSubscriptions[wsiKey]) {
|
||||||
|
groupedSubscriptions[wsiKey] = [];
|
||||||
|
}
|
||||||
|
groupedSubscriptions[wsiKey].push(sub);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTML Structure
|
||||||
|
|
||||||
|
#### Summary Row (Header)
|
||||||
|
```html
|
||||||
|
<tr class="subscription-group-header" data-wsi-pointer="0x12345678" data-expanded="false">
|
||||||
|
<td colspan="4" style="cursor: pointer; user-select: none;">
|
||||||
|
<span class="expand-icon">▶</span>
|
||||||
|
<strong>WSI Pointer:</strong> 0x12345678
|
||||||
|
<span class="group-summary">
|
||||||
|
| Subscriptions: 3 | Oldest: 15m 30s
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Detail Rows (Initially Hidden)
|
||||||
|
```html
|
||||||
|
<tr class="subscription-detail-row" data-wsi-group="0x12345678" style="display: none;">
|
||||||
|
<td style="padding-left: 30px;"><!-- Empty for WSI Pointer --></td>
|
||||||
|
<td>sub-001</td>
|
||||||
|
<td>5m 30s</td>
|
||||||
|
<td>kinds:[1]</td>
|
||||||
|
</tr>
|
||||||
|
```
|
||||||
|
|
||||||
|
### JavaScript Implementation
|
||||||
|
|
||||||
|
#### Modified populateSubscriptionDetailsTable Function
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function populateSubscriptionDetailsTable(subscriptionsData) {
|
||||||
|
const tableBody = document.getElementById('subscription-details-table-body');
|
||||||
|
if (!tableBody || !subscriptionsData || !Array.isArray(subscriptionsData)) return;
|
||||||
|
|
||||||
|
tableBody.innerHTML = '';
|
||||||
|
|
||||||
|
if (subscriptionsData.length === 0) {
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
row.innerHTML = '<td colspan="4" style="text-align: center; font-style: italic;">No active subscriptions</td>';
|
||||||
|
tableBody.appendChild(row);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort subscriptions by wsi_pointer to group them together
|
||||||
|
subscriptionsData.sort((a, b) => {
|
||||||
|
const wsiA = a.wsi_pointer || '';
|
||||||
|
const wsiB = b.wsi_pointer || '';
|
||||||
|
return wsiA.localeCompare(wsiB);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Group subscriptions by wsi_pointer
|
||||||
|
const groupedSubscriptions = {};
|
||||||
|
subscriptionsData.forEach(sub => {
|
||||||
|
const wsiKey = sub.wsi_pointer || 'N/A';
|
||||||
|
if (!groupedSubscriptions[wsiKey]) {
|
||||||
|
groupedSubscriptions[wsiKey] = [];
|
||||||
|
}
|
||||||
|
groupedSubscriptions[wsiKey].push(sub);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create rows for each group
|
||||||
|
Object.entries(groupedSubscriptions).forEach(([wsiPointer, subscriptions]) => {
|
||||||
|
// Calculate group summary
|
||||||
|
const subCount = subscriptions.length;
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
const oldestDuration = Math.max(...subscriptions.map(s => now - s.created_at));
|
||||||
|
const oldestDurationStr = formatDuration(oldestDuration);
|
||||||
|
|
||||||
|
// Create header row (summary)
|
||||||
|
const headerRow = document.createElement('tr');
|
||||||
|
headerRow.className = 'subscription-group-header';
|
||||||
|
headerRow.setAttribute('data-wsi-pointer', wsiPointer);
|
||||||
|
headerRow.setAttribute('data-expanded', 'false');
|
||||||
|
headerRow.style.cursor = 'pointer';
|
||||||
|
headerRow.style.userSelect = 'none';
|
||||||
|
headerRow.style.backgroundColor = 'var(--hover-color, #f5f5f5)';
|
||||||
|
|
||||||
|
headerRow.innerHTML = `
|
||||||
|
<td colspan="4" style="padding: 8px;">
|
||||||
|
<span class="expand-icon" style="display: inline-block; width: 20px; transition: transform 0.2s;">▶</span>
|
||||||
|
<strong style="font-family: 'Courier New', monospace; font-size: 12px;">WSI: ${wsiPointer}</strong>
|
||||||
|
<span style="color: #666; margin-left: 15px;">
|
||||||
|
Subscriptions: ${subCount} | Oldest: ${oldestDurationStr}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Add click handler to toggle expansion
|
||||||
|
headerRow.addEventListener('click', () => toggleSubscriptionGroup(wsiPointer));
|
||||||
|
|
||||||
|
tableBody.appendChild(headerRow);
|
||||||
|
|
||||||
|
// Create detail rows (initially hidden)
|
||||||
|
subscriptions.forEach((subscription, index) => {
|
||||||
|
const detailRow = document.createElement('tr');
|
||||||
|
detailRow.className = 'subscription-detail-row';
|
||||||
|
detailRow.setAttribute('data-wsi-group', wsiPointer);
|
||||||
|
detailRow.style.display = 'none';
|
||||||
|
|
||||||
|
// Calculate duration
|
||||||
|
const duration = now - subscription.created_at;
|
||||||
|
const durationStr = formatDuration(duration);
|
||||||
|
|
||||||
|
// Format filters
|
||||||
|
let filtersDisplay = 'None';
|
||||||
|
if (subscription.filters && subscription.filters.length > 0) {
|
||||||
|
const filterDetails = [];
|
||||||
|
subscription.filters.forEach((filter) => {
|
||||||
|
const parts = [];
|
||||||
|
|
||||||
|
if (filter.kinds && Array.isArray(filter.kinds) && filter.kinds.length > 0) {
|
||||||
|
parts.push(`kinds:[${filter.kinds.join(',')}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.authors && Array.isArray(filter.authors) && filter.authors.length > 0) {
|
||||||
|
const authorCount = filter.authors.length;
|
||||||
|
if (authorCount === 1) {
|
||||||
|
const shortPubkey = filter.authors[0].substring(0, 8) + '...';
|
||||||
|
parts.push(`authors:[${shortPubkey}]`);
|
||||||
|
} else {
|
||||||
|
parts.push(`authors:[${authorCount} pubkeys]`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.ids && Array.isArray(filter.ids) && filter.ids.length > 0) {
|
||||||
|
const idCount = filter.ids.length;
|
||||||
|
parts.push(`ids:[${idCount} event${idCount > 1 ? 's' : ''}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeParts = [];
|
||||||
|
if (filter.since && filter.since > 0) {
|
||||||
|
const sinceDate = new Date(filter.since * 1000).toLocaleString();
|
||||||
|
timeParts.push(`since:${sinceDate}`);
|
||||||
|
}
|
||||||
|
if (filter.until && filter.until > 0) {
|
||||||
|
const untilDate = new Date(filter.until * 1000).toLocaleString();
|
||||||
|
timeParts.push(`until:${untilDate}`);
|
||||||
|
}
|
||||||
|
if (timeParts.length > 0) {
|
||||||
|
parts.push(timeParts.join(', '));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.limit && filter.limit > 0) {
|
||||||
|
parts.push(`limit:${filter.limit}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter.tag_filters && Array.isArray(filter.tag_filters) && filter.tag_filters.length > 0) {
|
||||||
|
parts.push(`tags:[${filter.tag_filters.length} filter${filter.tag_filters.length > 1 ? 's' : ''}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.length > 0) {
|
||||||
|
filterDetails.push(parts.join(', '));
|
||||||
|
} else {
|
||||||
|
filterDetails.push('empty filter');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filtersDisplay = filterDetails.join(' | ');
|
||||||
|
}
|
||||||
|
|
||||||
|
detailRow.innerHTML = `
|
||||||
|
<td style="padding-left: 30px; font-family: 'Courier New', monospace; font-size: 11px; color: #999;">└─</td>
|
||||||
|
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${subscription.id || 'N/A'}</td>
|
||||||
|
<td>${durationStr}</td>
|
||||||
|
<td>${filtersDisplay}</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
tableBody.appendChild(detailRow);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle function for expanding/collapsing groups
|
||||||
|
function toggleSubscriptionGroup(wsiPointer) {
|
||||||
|
const headerRow = document.querySelector(`.subscription-group-header[data-wsi-pointer="${wsiPointer}"]`);
|
||||||
|
const detailRows = document.querySelectorAll(`.subscription-detail-row[data-wsi-group="${wsiPointer}"]`);
|
||||||
|
const expandIcon = headerRow.querySelector('.expand-icon');
|
||||||
|
|
||||||
|
const isExpanded = headerRow.getAttribute('data-expanded') === 'true';
|
||||||
|
|
||||||
|
if (isExpanded) {
|
||||||
|
// Collapse
|
||||||
|
detailRows.forEach(row => row.style.display = 'none');
|
||||||
|
expandIcon.textContent = '▶';
|
||||||
|
expandIcon.style.transform = 'rotate(0deg)';
|
||||||
|
headerRow.setAttribute('data-expanded', 'false');
|
||||||
|
} else {
|
||||||
|
// Expand
|
||||||
|
detailRows.forEach(row => row.style.display = 'table-row');
|
||||||
|
expandIcon.textContent = '▼';
|
||||||
|
expandIcon.style.transform = 'rotate(90deg)';
|
||||||
|
headerRow.setAttribute('data-expanded', 'true');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### CSS Additions (api/index.css)
|
||||||
|
|
||||||
|
```css
|
||||||
|
/* Subscription group header styles */
|
||||||
|
.subscription-group-header {
|
||||||
|
background-color: var(--hover-color, #f5f5f5);
|
||||||
|
font-weight: 500;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subscription-group-header:hover {
|
||||||
|
background-color: var(--primary-color-light, #e8e8e8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.expand-icon {
|
||||||
|
display: inline-block;
|
||||||
|
width: 20px;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detail row styles */
|
||||||
|
.subscription-detail-row {
|
||||||
|
background-color: var(--background-color, #ffffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
.subscription-detail-row:hover {
|
||||||
|
background-color: var(--hover-color-light, #fafafa);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dark mode support */
|
||||||
|
.dark-mode .subscription-group-header {
|
||||||
|
background-color: var(--hover-color-dark, #2a2a2a);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode .subscription-group-header:hover {
|
||||||
|
background-color: var(--primary-color-dark, #333333);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode .subscription-detail-row {
|
||||||
|
background-color: var(--background-color-dark, #1a1a1a);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode .subscription-detail-row:hover {
|
||||||
|
background-color: var(--hover-color-dark, #252525);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features Included
|
||||||
|
|
||||||
|
1. ✅ **Collapsible groups**: Each WSI Pointer group can be collapsed/expanded
|
||||||
|
2. ✅ **Visual indicator**: Arrow icon (▶/▼) shows current state
|
||||||
|
3. ✅ **Summary information**: Shows subscription count and oldest duration
|
||||||
|
4. ✅ **Smooth transitions**: Icon rotation animation
|
||||||
|
5. ✅ **Hover effects**: Visual feedback on header rows
|
||||||
|
6. ✅ **Tree structure**: Detail rows indented with └─ character
|
||||||
|
7. ✅ **Dark mode support**: Proper styling for both themes
|
||||||
|
8. ✅ **Keyboard accessible**: Can be enhanced with keyboard navigation
|
||||||
|
|
||||||
|
## User Experience Flow
|
||||||
|
|
||||||
|
1. **Initial load**: All groups collapsed, showing summary rows only
|
||||||
|
2. **Click header**: Group expands, showing all subscription details
|
||||||
|
3. **Click again**: Group collapses back to summary
|
||||||
|
4. **Multiple groups**: Each group can be independently expanded/collapsed
|
||||||
|
5. **Visual feedback**: Hover effects and smooth animations
|
||||||
|
|
||||||
|
## Testing Checklist
|
||||||
|
|
||||||
|
1. ✅ Verify groups start collapsed by default
|
||||||
|
2. ✅ Verify clicking header expands group
|
||||||
|
3. ✅ Verify clicking again collapses group
|
||||||
|
4. ✅ Verify multiple groups can be expanded simultaneously
|
||||||
|
5. ✅ Verify summary information is accurate
|
||||||
|
6. ✅ Verify detail rows display correctly when expanded
|
||||||
|
7. ✅ Verify styling works in both light and dark modes
|
||||||
|
8. ✅ Verify no console errors
|
||||||
|
9. ✅ Verify performance with many subscriptions
|
||||||
|
|
||||||
|
## Optional Enhancements
|
||||||
|
|
||||||
|
1. **Expand/Collapse All**: Add buttons to expand or collapse all groups at once
|
||||||
|
2. **Remember State**: Store expansion state in localStorage
|
||||||
|
3. **Keyboard Navigation**: Add keyboard shortcuts (Space/Enter to toggle)
|
||||||
|
4. **Animation**: Add slide-down/up animation for detail rows
|
||||||
|
5. **Search/Filter**: Add ability to search within subscriptions
|
||||||
|
6. **Export**: Add ability to export subscription data
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
1. Review this plan
|
||||||
|
2. Switch to Code mode
|
||||||
|
3. Implement the changes in `api/index.js`
|
||||||
|
4. Add CSS styles in `api/index.css`
|
||||||
|
5. Test the collapsible functionality
|
||||||
|
6. Verify all edge cases work correctly
|
||||||
155
docs/subscription_table_grouping_plan.md
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
# Subscription Table WSI Pointer Grouping Implementation Plan
|
||||||
|
|
||||||
|
## Objective
|
||||||
|
Modify the subscription details table to show the WSI Pointer value only once per group - on the first row of each WSI Pointer group, leaving it blank for subsequent rows with the same WSI Pointer.
|
||||||
|
|
||||||
|
## Current Behavior
|
||||||
|
- All rows show the WSI Pointer value
|
||||||
|
- Rows are sorted by WSI Pointer (grouping is working)
|
||||||
|
- Visual grouping is not clear
|
||||||
|
|
||||||
|
## Desired Behavior
|
||||||
|
- First row of each WSI Pointer group shows the full WSI Pointer value
|
||||||
|
- Subsequent rows in the same group have an empty cell for WSI Pointer
|
||||||
|
- This creates a clear visual grouping effect
|
||||||
|
|
||||||
|
## Implementation Details
|
||||||
|
|
||||||
|
### File to Modify
|
||||||
|
`api/index.js` - Function `populateSubscriptionDetailsTable()` (lines 4277-4384)
|
||||||
|
|
||||||
|
### Code Changes Required
|
||||||
|
|
||||||
|
#### Current Code (lines 4291-4383):
|
||||||
|
```javascript
|
||||||
|
// Sort subscriptions by wsi_pointer to group them together
|
||||||
|
subscriptionsData.sort((a, b) => {
|
||||||
|
const wsiA = a.wsi_pointer || '';
|
||||||
|
const wsiB = b.wsi_pointer || '';
|
||||||
|
return wsiA.localeCompare(wsiB);
|
||||||
|
});
|
||||||
|
|
||||||
|
subscriptionsData.forEach((subscription, index) => {
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
|
||||||
|
// Calculate duration
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
const duration = now - subscription.created_at;
|
||||||
|
const durationStr = formatDuration(duration);
|
||||||
|
|
||||||
|
// Format client IP (show full IP for admin view)
|
||||||
|
const clientIP = subscription.client_ip || 'unknown';
|
||||||
|
|
||||||
|
// Format wsi_pointer (show full pointer)
|
||||||
|
const wsiPointer = subscription.wsi_pointer || 'N/A';
|
||||||
|
|
||||||
|
// Format filters (show actual filter details)
|
||||||
|
let filtersDisplay = 'None';
|
||||||
|
// ... filter formatting code ...
|
||||||
|
|
||||||
|
row.innerHTML = `
|
||||||
|
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${wsiPointer}</td>
|
||||||
|
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${subscription.id || 'N/A'}</td>
|
||||||
|
<!-- <td style="font-family: 'Courier New', monospace; font-size: 12px;">${clientIP}</td> -->
|
||||||
|
<td>${durationStr}</td>
|
||||||
|
<td>${filtersDisplay}</td>
|
||||||
|
`;
|
||||||
|
tableBody.appendChild(row);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Modified Code:
|
||||||
|
```javascript
|
||||||
|
// Sort subscriptions by wsi_pointer to group them together
|
||||||
|
subscriptionsData.sort((a, b) => {
|
||||||
|
const wsiA = a.wsi_pointer || '';
|
||||||
|
const wsiB = b.wsi_pointer || '';
|
||||||
|
return wsiA.localeCompare(wsiB);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track previous WSI Pointer to detect group changes
|
||||||
|
let previousWsiPointer = null;
|
||||||
|
|
||||||
|
subscriptionsData.forEach((subscription, index) => {
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
|
||||||
|
// Calculate duration
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
const duration = now - subscription.created_at;
|
||||||
|
const durationStr = formatDuration(duration);
|
||||||
|
|
||||||
|
// Format client IP (show full IP for admin view)
|
||||||
|
const clientIP = subscription.client_ip || 'unknown';
|
||||||
|
|
||||||
|
// Format wsi_pointer - only show if it's different from previous row
|
||||||
|
const currentWsiPointer = subscription.wsi_pointer || 'N/A';
|
||||||
|
let wsiPointerDisplay = '';
|
||||||
|
|
||||||
|
if (currentWsiPointer !== previousWsiPointer) {
|
||||||
|
// This is the first row of a new group - show the WSI Pointer
|
||||||
|
wsiPointerDisplay = currentWsiPointer;
|
||||||
|
previousWsiPointer = currentWsiPointer;
|
||||||
|
} else {
|
||||||
|
// This is a continuation of the same group - leave blank
|
||||||
|
wsiPointerDisplay = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format filters (show actual filter details)
|
||||||
|
let filtersDisplay = 'None';
|
||||||
|
// ... filter formatting code remains the same ...
|
||||||
|
|
||||||
|
row.innerHTML = `
|
||||||
|
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${wsiPointerDisplay}</td>
|
||||||
|
<td style="font-family: 'Courier New', monospace; font-size: 12px;">${subscription.id || 'N/A'}</td>
|
||||||
|
<!-- <td style="font-family: 'Courier New', monospace; font-size: 12px;">${clientIP}</td> -->
|
||||||
|
<td>${durationStr}</td>
|
||||||
|
<td>${filtersDisplay}</td>
|
||||||
|
`;
|
||||||
|
tableBody.appendChild(row);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key Changes Explained
|
||||||
|
|
||||||
|
1. **Add tracking variable**: `let previousWsiPointer = null;` before the forEach loop
|
||||||
|
2. **Store current WSI Pointer**: `const currentWsiPointer = subscription.wsi_pointer || 'N/A';`
|
||||||
|
3. **Compare with previous**: Check if `currentWsiPointer !== previousWsiPointer`
|
||||||
|
4. **Conditional display**:
|
||||||
|
- If different: Show the WSI Pointer value and update `previousWsiPointer`
|
||||||
|
- If same: Show empty string (blank cell)
|
||||||
|
5. **Use display variable**: Replace `${wsiPointer}` with `${wsiPointerDisplay}` in the row HTML
|
||||||
|
|
||||||
|
### Visual Result
|
||||||
|
|
||||||
|
**Before:**
|
||||||
|
```
|
||||||
|
WSI Pointer | Subscription ID | Duration | Filters
|
||||||
|
0x12345678 | sub-001 | 5m 30s | kinds:[1]
|
||||||
|
0x12345678 | sub-002 | 3m 15s | kinds:[3]
|
||||||
|
0x87654321 | sub-003 | 1m 45s | kinds:[1,3]
|
||||||
|
```
|
||||||
|
|
||||||
|
**After:**
|
||||||
|
```
|
||||||
|
WSI Pointer | Subscription ID | Duration | Filters
|
||||||
|
0x12345678 | sub-001 | 5m 30s | kinds:[1]
|
||||||
|
| sub-002 | 3m 15s | kinds:[3]
|
||||||
|
0x87654321 | sub-003 | 1m 45s | kinds:[1,3]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing Checklist
|
||||||
|
|
||||||
|
1. ✅ Verify first row of each group shows WSI Pointer
|
||||||
|
2. ✅ Verify subsequent rows in same group are blank
|
||||||
|
3. ✅ Verify grouping works with multiple subscriptions per WSI Pointer
|
||||||
|
4. ✅ Verify single subscription per WSI Pointer still shows the value
|
||||||
|
5. ✅ Verify empty/null WSI Pointers are handled correctly
|
||||||
|
6. ✅ Verify table still displays correctly when no subscriptions exist
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
1. Review this plan
|
||||||
|
2. Switch to Code mode
|
||||||
|
3. Implement the changes in `api/index.js`
|
||||||
|
4. Test the implementation
|
||||||
|
5. Verify the visual grouping effect
|
||||||
@@ -8,36 +8,59 @@ YELLOW='\033[1;33m'
|
|||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
print_status() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
print_status() { echo -e "${BLUE}[INFO]${NC} $1" >&2; }
|
||||||
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" >&2; }
|
||||||
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" >&2; }
|
||||||
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
print_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
COMMIT_MESSAGE=""
|
COMMIT_MESSAGE=""
|
||||||
RELEASE_MODE=false
|
RELEASE_MODE=false
|
||||||
|
VERSION_INCREMENT_TYPE="patch" # "patch", "minor", or "major"
|
||||||
|
|
||||||
show_usage() {
|
show_usage() {
|
||||||
echo "C-Relay Increment and Push Script"
|
echo "C-Relay Increment and Push Script"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Usage:"
|
echo "USAGE:"
|
||||||
echo " $0 \"commit message\" - Default: increment patch, commit & push"
|
echo " $0 [OPTIONS] \"commit message\""
|
||||||
echo " $0 -r \"commit message\" - Release: increment minor, create release"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "COMMANDS:"
|
||||||
|
echo " $0 \"commit message\" Default: increment patch, commit & push"
|
||||||
|
echo " $0 -p \"commit message\" Increment patch version"
|
||||||
|
echo " $0 -m \"commit message\" Increment minor version"
|
||||||
|
echo " $0 -M \"commit message\" Increment major version"
|
||||||
|
echo " $0 -r \"commit message\" Create release with assets (no version increment)"
|
||||||
|
echo " $0 -r -m \"commit message\" Create release with minor version increment"
|
||||||
|
echo " $0 -h Show this help message"
|
||||||
|
echo ""
|
||||||
|
echo "OPTIONS:"
|
||||||
|
echo " -p, --patch Increment patch version (default)"
|
||||||
|
echo " -m, --minor Increment minor version"
|
||||||
|
echo " -M, --major Increment major version"
|
||||||
|
echo " -r, --release Create release with assets"
|
||||||
|
echo " -h, --help Show this help message"
|
||||||
|
echo ""
|
||||||
|
echo "EXAMPLES:"
|
||||||
echo " $0 \"Fixed event validation bug\""
|
echo " $0 \"Fixed event validation bug\""
|
||||||
echo " $0 --release \"Major release with new features\""
|
echo " $0 -m \"Added new features\""
|
||||||
|
echo " $0 -M \"Breaking API changes\""
|
||||||
|
echo " $0 -r \"Release current version\""
|
||||||
|
echo " $0 -r -m \"Release with minor increment\""
|
||||||
echo ""
|
echo ""
|
||||||
echo "Default Mode (patch increment):"
|
echo "VERSION INCREMENT MODES:"
|
||||||
echo " - Increment patch version (v1.2.3 → v1.2.4)"
|
echo " -p, --patch (default): Increment patch version (v1.2.3 → v1.2.4)"
|
||||||
echo " - Git add, commit with message, and push"
|
echo " -m, --minor: Increment minor version, zero patch (v1.2.3 → v1.3.0)"
|
||||||
|
echo " -M, --major: Increment major version, zero minor+patch (v1.2.3 → v2.0.0)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Release Mode (-r flag):"
|
echo "RELEASE MODE (-r flag):"
|
||||||
echo " - Increment minor version, zero patch (v1.2.3 → v1.3.0)"
|
echo " - Build static binary using build_static.sh"
|
||||||
echo " - Git add, commit, push, and create Gitea release"
|
echo " - Create source tarball"
|
||||||
|
echo " - Git add, commit, push, and create Gitea release with assets"
|
||||||
|
echo " - Can be combined with version increment flags"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Requirements for Release Mode:"
|
echo "REQUIREMENTS FOR RELEASE MODE:"
|
||||||
echo " - Gitea token in ~/.gitea_token for release uploads"
|
echo " - Gitea token in ~/.gitea_token for release uploads"
|
||||||
|
echo " - Docker installed for static binary builds"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
@@ -47,6 +70,18 @@ while [[ $# -gt 0 ]]; do
|
|||||||
RELEASE_MODE=true
|
RELEASE_MODE=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-p|--patch)
|
||||||
|
VERSION_INCREMENT_TYPE="patch"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-m|--minor)
|
||||||
|
VERSION_INCREMENT_TYPE="minor"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-M|--major)
|
||||||
|
VERSION_INCREMENT_TYPE="major"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
show_usage
|
show_usage
|
||||||
exit 0
|
exit 0
|
||||||
@@ -79,7 +114,7 @@ check_git_repo() {
|
|||||||
|
|
||||||
# Function to get current version and increment appropriately
|
# Function to get current version and increment appropriately
|
||||||
increment_version() {
|
increment_version() {
|
||||||
local increment_type="$1" # "patch" or "minor"
|
local increment_type="$1" # "patch", "minor", or "major"
|
||||||
|
|
||||||
print_status "Getting current version..."
|
print_status "Getting current version..."
|
||||||
|
|
||||||
@@ -105,24 +140,34 @@ increment_version() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Increment version based on type
|
# Increment version based on type
|
||||||
if [[ "$increment_type" == "minor" ]]; then
|
if [[ "$increment_type" == "major" ]]; then
|
||||||
|
# Major release: increment major, zero minor and patch
|
||||||
|
NEW_MAJOR=$((MAJOR + 1))
|
||||||
|
NEW_MINOR=0
|
||||||
|
NEW_PATCH=0
|
||||||
|
NEW_VERSION="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||||||
|
print_status "Major version increment: incrementing major version"
|
||||||
|
elif [[ "$increment_type" == "minor" ]]; then
|
||||||
# Minor release: increment minor, zero patch
|
# Minor release: increment minor, zero patch
|
||||||
|
NEW_MAJOR=$MAJOR
|
||||||
NEW_MINOR=$((MINOR + 1))
|
NEW_MINOR=$((MINOR + 1))
|
||||||
NEW_PATCH=0
|
NEW_PATCH=0
|
||||||
NEW_VERSION="v${MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
NEW_VERSION="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||||||
print_status "Release mode: incrementing minor version"
|
print_status "Minor version increment: incrementing minor version"
|
||||||
else
|
else
|
||||||
# Default: increment patch
|
# Default: increment patch
|
||||||
|
NEW_MAJOR=$MAJOR
|
||||||
|
NEW_MINOR=$MINOR
|
||||||
NEW_PATCH=$((PATCH + 1))
|
NEW_PATCH=$((PATCH + 1))
|
||||||
NEW_VERSION="v${MAJOR}.${MINOR}.${NEW_PATCH}"
|
NEW_VERSION="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||||||
print_status "Default mode: incrementing patch version"
|
print_status "Patch version increment: incrementing patch version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Current version: $LATEST_TAG"
|
print_status "Current version: $LATEST_TAG"
|
||||||
print_status "New version: $NEW_VERSION"
|
print_status "New version: $NEW_VERSION"
|
||||||
|
|
||||||
# Update version in src/main.h
|
# Update version in src/main.h
|
||||||
update_version_in_header "$NEW_VERSION" "$MAJOR" "${NEW_MINOR:-$MINOR}" "${NEW_PATCH:-$PATCH}"
|
update_version_in_header "$NEW_VERSION" "$NEW_MAJOR" "$NEW_MINOR" "$NEW_PATCH"
|
||||||
|
|
||||||
# Export for use in other functions
|
# Export for use in other functions
|
||||||
export NEW_VERSION
|
export NEW_VERSION
|
||||||
@@ -261,6 +306,115 @@ git_commit_and_push_no_tag() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to build release binary
|
||||||
|
build_release_binary() {
|
||||||
|
print_status "Building release binary..."
|
||||||
|
|
||||||
|
# Check if build_static.sh exists
|
||||||
|
if [[ ! -f "build_static.sh" ]]; then
|
||||||
|
print_error "build_static.sh not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the static build script
|
||||||
|
if ./build_static.sh > /dev/null 2>&1; then
|
||||||
|
print_success "Built static binary successfully"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_error "Failed to build static binary"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to create source tarball
|
||||||
|
create_source_tarball() {
|
||||||
|
print_status "Creating source tarball..."
|
||||||
|
|
||||||
|
local tarball_name="c-relay-${NEW_VERSION#v}.tar.gz"
|
||||||
|
|
||||||
|
# Create tarball excluding build artifacts and git files
|
||||||
|
if tar -czf "$tarball_name" \
|
||||||
|
--exclude='build/*' \
|
||||||
|
--exclude='.git*' \
|
||||||
|
--exclude='*.db' \
|
||||||
|
--exclude='*.db-*' \
|
||||||
|
--exclude='*.log' \
|
||||||
|
--exclude='*.tar.gz' \
|
||||||
|
. > /dev/null 2>&1; then
|
||||||
|
print_success "Created source tarball: $tarball_name"
|
||||||
|
echo "$tarball_name"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_error "Failed to create source tarball"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to upload release assets to Gitea
|
||||||
|
upload_release_assets() {
|
||||||
|
local release_id="$1"
|
||||||
|
local binary_path="$2"
|
||||||
|
local tarball_path="$3"
|
||||||
|
|
||||||
|
print_status "Uploading release assets..."
|
||||||
|
|
||||||
|
# Check for Gitea token
|
||||||
|
if [[ ! -f "$HOME/.gitea_token" ]]; then
|
||||||
|
print_warning "No ~/.gitea_token found. Skipping asset uploads."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local token=$(cat "$HOME/.gitea_token" | tr -d '\n\r')
|
||||||
|
local api_url="https://git.laantungir.net/api/v1/repos/laantungir/c-relay"
|
||||||
|
local assets_url="$api_url/releases/$release_id/assets"
|
||||||
|
print_status "Assets URL: $assets_url"
|
||||||
|
|
||||||
|
# Upload binary
|
||||||
|
if [[ -f "$binary_path" ]]; then
|
||||||
|
print_status "Uploading binary: $(basename "$binary_path")"
|
||||||
|
|
||||||
|
# Retry loop for eventual consistency
|
||||||
|
local max_attempts=3
|
||||||
|
local attempt=1
|
||||||
|
while [[ $attempt -le $max_attempts ]]; do
|
||||||
|
print_status "Upload attempt $attempt/$max_attempts"
|
||||||
|
local binary_response=$(curl -fS -X POST "$assets_url" \
|
||||||
|
-H "Authorization: token $token" \
|
||||||
|
-F "attachment=@$binary_path;filename=$(basename "$binary_path")" \
|
||||||
|
-F "name=$(basename "$binary_path")")
|
||||||
|
|
||||||
|
if echo "$binary_response" | grep -q '"id"'; then
|
||||||
|
print_success "Uploaded binary successfully"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
print_warning "Upload attempt $attempt failed"
|
||||||
|
if [[ $attempt -lt $max_attempts ]]; then
|
||||||
|
print_status "Retrying in 2 seconds..."
|
||||||
|
sleep 2
|
||||||
|
else
|
||||||
|
print_error "Failed to upload binary after $max_attempts attempts"
|
||||||
|
print_error "Response: $binary_response"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
((attempt++))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upload source tarball
|
||||||
|
if [[ -f "$tarball_path" ]]; then
|
||||||
|
print_status "Uploading source tarball: $(basename "$tarball_path")"
|
||||||
|
local tarball_response=$(curl -s -X POST "$api_url/releases/$release_id/assets" \
|
||||||
|
-H "Authorization: token $token" \
|
||||||
|
-F "attachment=@$tarball_path;filename=$(basename "$tarball_path")")
|
||||||
|
|
||||||
|
if echo "$tarball_response" | grep -q '"id"'; then
|
||||||
|
print_success "Uploaded source tarball successfully"
|
||||||
|
else
|
||||||
|
print_warning "Failed to upload source tarball: $tarball_response"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Function to create Gitea release
|
# Function to create Gitea release
|
||||||
create_gitea_release() {
|
create_gitea_release() {
|
||||||
print_status "Creating Gitea release..."
|
print_status "Creating Gitea release..."
|
||||||
@@ -278,16 +432,27 @@ create_gitea_release() {
|
|||||||
# Create release
|
# Create release
|
||||||
print_status "Creating release $NEW_VERSION..."
|
print_status "Creating release $NEW_VERSION..."
|
||||||
local response=$(curl -s -X POST "$api_url/releases" \
|
local response=$(curl -s -X POST "$api_url/releases" \
|
||||||
-H "Authorization: token $token" \
|
-H "Authorization: token $token" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\": \"$NEW_VERSION\", \"name\": \"$NEW_VERSION\", \"body\": \"$COMMIT_MESSAGE\"}")
|
-d "{\"tag_name\": \"$NEW_VERSION\", \"name\": \"$NEW_VERSION\", \"body\": \"$COMMIT_MESSAGE\"}")
|
||||||
|
|
||||||
if echo "$response" | grep -q '"id"'; then
|
if echo "$response" | grep -q '"id"'; then
|
||||||
print_success "Created release $NEW_VERSION"
|
print_success "Created release $NEW_VERSION"
|
||||||
return 0
|
# Extract release ID for asset uploads
|
||||||
|
local release_id=$(echo "$response" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
echo $release_id
|
||||||
elif echo "$response" | grep -q "already exists"; then
|
elif echo "$response" | grep -q "already exists"; then
|
||||||
print_warning "Release $NEW_VERSION already exists"
|
print_warning "Release $NEW_VERSION already exists"
|
||||||
return 0
|
# Try to get existing release ID
|
||||||
|
local check_response=$(curl -s -H "Authorization: token $token" "$api_url/releases/tags/$NEW_VERSION")
|
||||||
|
if echo "$check_response" | grep -q '"id"'; then
|
||||||
|
local release_id=$(echo "$check_response" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
print_status "Using existing release ID: $release_id"
|
||||||
|
echo $release_id
|
||||||
|
else
|
||||||
|
print_error "Could not find existing release ID"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_error "Failed to create release $NEW_VERSION"
|
print_error "Failed to create release $NEW_VERSION"
|
||||||
print_error "Response: $response"
|
print_error "Response: $response"
|
||||||
@@ -297,7 +462,8 @@ create_gitea_release() {
|
|||||||
local check_response=$(curl -s -H "Authorization: token $token" "$api_url/releases/tags/$NEW_VERSION")
|
local check_response=$(curl -s -H "Authorization: token $token" "$api_url/releases/tags/$NEW_VERSION")
|
||||||
if echo "$check_response" | grep -q '"id"'; then
|
if echo "$check_response" | grep -q '"id"'; then
|
||||||
print_warning "Release exists but creation response was unexpected"
|
print_warning "Release exists but creation response was unexpected"
|
||||||
return 0
|
local release_id=$(echo "$check_response" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
echo $release_id
|
||||||
else
|
else
|
||||||
print_error "Release does not exist and creation failed"
|
print_error "Release does not exist and creation failed"
|
||||||
return 1
|
return 1
|
||||||
@@ -315,8 +481,15 @@ main() {
|
|||||||
if [[ "$RELEASE_MODE" == true ]]; then
|
if [[ "$RELEASE_MODE" == true ]]; then
|
||||||
print_status "=== RELEASE MODE ==="
|
print_status "=== RELEASE MODE ==="
|
||||||
|
|
||||||
# Increment minor version for releases
|
# Only increment version if explicitly requested (not just because of -r flag)
|
||||||
increment_version "minor"
|
if [[ "$VERSION_INCREMENT_TYPE" != "patch" ]]; then
|
||||||
|
increment_version "$VERSION_INCREMENT_TYPE"
|
||||||
|
else
|
||||||
|
# In release mode without version increment, get current version
|
||||||
|
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n 1 || echo "v0.0.0")
|
||||||
|
NEW_VERSION="$LATEST_TAG"
|
||||||
|
export NEW_VERSION
|
||||||
|
fi
|
||||||
|
|
||||||
# Create new git tag BEFORE compilation so version.h picks it up
|
# Create new git tag BEFORE compilation so version.h picks it up
|
||||||
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
@@ -330,9 +503,42 @@ main() {
|
|||||||
# Commit and push (but skip tag creation since we already did it)
|
# Commit and push (but skip tag creation since we already did it)
|
||||||
git_commit_and_push_no_tag
|
git_commit_and_push_no_tag
|
||||||
|
|
||||||
|
# Build release binary
|
||||||
|
if build_release_binary; then
|
||||||
|
local binary_path="build/c_relay_static_x86_64"
|
||||||
|
else
|
||||||
|
print_warning "Binary build failed, continuing with release creation"
|
||||||
|
# Check if binary exists from previous build
|
||||||
|
if [[ -f "build/c_relay_static_x86_64" ]]; then
|
||||||
|
print_status "Using existing binary from previous build"
|
||||||
|
binary_path="build/c_relay_static_x86_64"
|
||||||
|
else
|
||||||
|
binary_path=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create source tarball
|
||||||
|
local tarball_path=""
|
||||||
|
if tarball_path=$(create_source_tarball); then
|
||||||
|
: # tarball_path is set by the function
|
||||||
|
else
|
||||||
|
print_warning "Source tarball creation failed, continuing with release creation"
|
||||||
|
fi
|
||||||
|
|
||||||
# Create Gitea release
|
# Create Gitea release
|
||||||
if create_gitea_release; then
|
local release_id=""
|
||||||
print_success "Release $NEW_VERSION completed successfully!"
|
if release_id=$(create_gitea_release); then
|
||||||
|
# Validate release_id is numeric
|
||||||
|
if [[ "$release_id" =~ ^[0-9]+$ ]]; then
|
||||||
|
# Upload assets if we have a release ID and assets
|
||||||
|
if [[ -n "$release_id" && (-n "$binary_path" || -n "$tarball_path") ]]; then
|
||||||
|
upload_release_assets "$release_id" "$binary_path" "$tarball_path"
|
||||||
|
fi
|
||||||
|
print_success "Release $NEW_VERSION completed successfully!"
|
||||||
|
else
|
||||||
|
print_error "Invalid release_id: $release_id"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_error "Release creation failed"
|
print_error "Release creation failed"
|
||||||
fi
|
fi
|
||||||
@@ -340,8 +546,8 @@ main() {
|
|||||||
else
|
else
|
||||||
print_status "=== DEFAULT MODE ==="
|
print_status "=== DEFAULT MODE ==="
|
||||||
|
|
||||||
# Increment patch version for regular commits
|
# Increment version based on type (default to patch)
|
||||||
increment_version "patch"
|
increment_version "$VERSION_INCREMENT_TYPE"
|
||||||
|
|
||||||
# Create new git tag BEFORE compilation so version.h picks it up
|
# Create new git tag BEFORE compilation so version.h picks it up
|
||||||
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
if git tag "$NEW_VERSION" > /dev/null 2>&1; then
|
||||||
|
|||||||
BIN
screenshots/2025-10-29_15-33.png
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
BIN
screenshots/2025-10-29_15-35.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
screenshots/2025-10-29_15-35_1.png
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
BIN
screenshots/2025-10-29_16-04.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
screenshots/DM.png
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
screenshots/ProfileEvents.png
Normal file
|
After Width: | Height: | Size: 105 KiB |
BIN
screenshots/config.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
screenshots/light-mode.png
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
screenshots/main-light.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
screenshots/main.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
screenshots/sqlQuery.png
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
screenshots/subscriptions.png
Normal file
|
After Width: | Height: | Size: 157 KiB |
BIN
screenshots/white-blacklists.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
243
src/api.c
@@ -271,6 +271,7 @@ cJSON* query_subscription_details(void) {
|
|||||||
long long events_sent = sqlite3_column_int64(stmt, 3);
|
long long events_sent = sqlite3_column_int64(stmt, 3);
|
||||||
long long created_at = sqlite3_column_int64(stmt, 4);
|
long long created_at = sqlite3_column_int64(stmt, 4);
|
||||||
long long duration_seconds = sqlite3_column_int64(stmt, 5);
|
long long duration_seconds = sqlite3_column_int64(stmt, 5);
|
||||||
|
const char* wsi_pointer = (const char*)sqlite3_column_text(stmt, 6);
|
||||||
|
|
||||||
// DEBUG: Log each subscription found
|
// DEBUG: Log each subscription found
|
||||||
DEBUG_LOG("Row %d: sub_id=%s, client_ip=%s, events_sent=%lld, created_at=%lld",
|
DEBUG_LOG("Row %d: sub_id=%s, client_ip=%s, events_sent=%lld, created_at=%lld",
|
||||||
@@ -284,6 +285,7 @@ cJSON* query_subscription_details(void) {
|
|||||||
cJSON_AddNumberToObject(sub_obj, "duration_seconds", (double)duration_seconds);
|
cJSON_AddNumberToObject(sub_obj, "duration_seconds", (double)duration_seconds);
|
||||||
cJSON_AddNumberToObject(sub_obj, "events_sent", events_sent);
|
cJSON_AddNumberToObject(sub_obj, "events_sent", events_sent);
|
||||||
cJSON_AddBoolToObject(sub_obj, "active", 1); // All from this view are active
|
cJSON_AddBoolToObject(sub_obj, "active", 1); // All from this view are active
|
||||||
|
cJSON_AddStringToObject(sub_obj, "wsi_pointer", wsi_pointer ? wsi_pointer : "N/A");
|
||||||
|
|
||||||
// Parse and add filter JSON if available
|
// Parse and add filter JSON if available
|
||||||
if (filter_json) {
|
if (filter_json) {
|
||||||
@@ -499,6 +501,76 @@ void monitoring_on_subscription_change(void) {
|
|||||||
generate_subscription_driven_monitoring();
|
generate_subscription_driven_monitoring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate and post a kind 1 status event with relay statistics
|
||||||
|
* Called periodically from main event loop based on configuration
|
||||||
|
* Returns: 0 on success, -1 on error
|
||||||
|
*/
|
||||||
|
int generate_and_post_status_event(void) {
|
||||||
|
// Check if feature is enabled
|
||||||
|
int hours_interval = get_config_int("kind_1_status_posts_hours", 0);
|
||||||
|
if (hours_interval <= 0) {
|
||||||
|
return 0; // Feature disabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate statistics text content using existing function
|
||||||
|
char* stats_text = generate_stats_text();
|
||||||
|
if (!stats_text) {
|
||||||
|
DEBUG_ERROR("Failed to generate statistics text for status post");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get relay private key
|
||||||
|
char* relay_privkey_hex = get_relay_private_key();
|
||||||
|
if (!relay_privkey_hex) {
|
||||||
|
DEBUG_ERROR("Failed to get relay private key for status post");
|
||||||
|
free(stats_text);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert hex private key to bytes
|
||||||
|
unsigned char relay_privkey_bytes[32];
|
||||||
|
if (nostr_hex_to_bytes(relay_privkey_hex, relay_privkey_bytes, 32) != 0) {
|
||||||
|
DEBUG_ERROR("Failed to convert relay private key to bytes");
|
||||||
|
free(stats_text);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create empty tags array (kind 1 doesn't require special tags)
|
||||||
|
cJSON* tags = cJSON_CreateArray();
|
||||||
|
|
||||||
|
// Create and sign the kind 1 event
|
||||||
|
cJSON* signed_event = nostr_create_and_sign_event(
|
||||||
|
1, // kind 1 = text note
|
||||||
|
stats_text, // content = statistics
|
||||||
|
tags, // empty tags
|
||||||
|
relay_privkey_bytes, // relay's private key
|
||||||
|
time(NULL) // current timestamp
|
||||||
|
);
|
||||||
|
|
||||||
|
free(stats_text);
|
||||||
|
|
||||||
|
if (!signed_event) {
|
||||||
|
DEBUG_ERROR("Failed to create and sign status event");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store event in database (kind 1 events MUST be stored)
|
||||||
|
if (store_event(signed_event) != 0) {
|
||||||
|
DEBUG_ERROR("Failed to store status event in database");
|
||||||
|
cJSON_Delete(signed_event);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Broadcast event to subscriptions
|
||||||
|
broadcast_event_to_subscriptions(signed_event);
|
||||||
|
|
||||||
|
DEBUG_LOG("Successfully posted kind 1 status event");
|
||||||
|
cJSON_Delete(signed_event);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Forward declaration for known_configs (defined in config.c)
|
// Forward declaration for known_configs (defined in config.c)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* key;
|
const char* key;
|
||||||
@@ -565,6 +637,9 @@ static const config_definition_t known_configs[] = {
|
|||||||
{"relay_privkey", "string", 0, 65},
|
{"relay_privkey", "string", 0, 65},
|
||||||
{"admin_pubkey", "string", 0, 65},
|
{"admin_pubkey", "string", 0, 65},
|
||||||
|
|
||||||
|
// Kind 1 Status Posts
|
||||||
|
{"kind_1_status_posts_hours", "int", 0, 8760},
|
||||||
|
|
||||||
// Sentinel
|
// Sentinel
|
||||||
{NULL, NULL, 0, 0}
|
{NULL, NULL, 0, 0}
|
||||||
};
|
};
|
||||||
@@ -1314,6 +1389,9 @@ int send_nip17_response(const char* sender_pubkey, const char* response_content,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get timestamp delay configuration
|
||||||
|
long max_delay_sec = get_config_int("nip59_timestamp_max_delay_sec", 0);
|
||||||
|
|
||||||
// Create and sign gift wrap using library function
|
// Create and sign gift wrap using library function
|
||||||
cJSON* gift_wraps[1];
|
cJSON* gift_wraps[1];
|
||||||
int send_result = nostr_nip17_send_dm(
|
int send_result = nostr_nip17_send_dm(
|
||||||
@@ -1322,7 +1400,8 @@ int send_nip17_response(const char* sender_pubkey, const char* response_content,
|
|||||||
1, // num_recipients
|
1, // num_recipients
|
||||||
relay_privkey, // sender_private_key
|
relay_privkey, // sender_private_key
|
||||||
gift_wraps, // gift_wraps_out
|
gift_wraps, // gift_wraps_out
|
||||||
1 // max_gift_wraps
|
1, // max_gift_wraps
|
||||||
|
max_delay_sec // max_delay_sec
|
||||||
);
|
);
|
||||||
|
|
||||||
cJSON_Delete(dm_response);
|
cJSON_Delete(dm_response);
|
||||||
@@ -1419,12 +1498,37 @@ char* generate_config_text(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Footer
|
// Footer
|
||||||
offset += snprintf(config_text + offset, 8192 - offset,
|
offset += snprintf(config_text + offset, 8192 - offset, "\n");
|
||||||
"\n✅ Configuration retrieved successfully");
|
|
||||||
|
|
||||||
return config_text;
|
return config_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to format numbers with commas
|
||||||
|
void format_number_with_commas(long long num, char* buffer, size_t buffer_size) {
|
||||||
|
char temp[32];
|
||||||
|
int len = snprintf(temp, sizeof(temp), "%lld", num);
|
||||||
|
int comma_count = (len - 1) / 3;
|
||||||
|
int result_len = len + comma_count;
|
||||||
|
|
||||||
|
if (result_len >= (int)buffer_size) {
|
||||||
|
buffer[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int j = result_len - 1;
|
||||||
|
int k = len - 1;
|
||||||
|
int comma_pos = 0;
|
||||||
|
|
||||||
|
while (k >= 0) {
|
||||||
|
buffer[j--] = temp[k--];
|
||||||
|
comma_pos++;
|
||||||
|
if (comma_pos % 3 == 0 && k >= 0) {
|
||||||
|
buffer[j--] = ',';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer[result_len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
// Generate human-readable stats text
|
// Generate human-readable stats text
|
||||||
char* generate_stats_text(void) {
|
char* generate_stats_text(void) {
|
||||||
char* stats_json = generate_stats_json();
|
char* stats_json = generate_stats_json();
|
||||||
@@ -1450,7 +1554,7 @@ char* generate_stats_text(void) {
|
|||||||
cJSON* newest_event = cJSON_GetObjectItem(stats_obj, "latest_event_at");
|
cJSON* newest_event = cJSON_GetObjectItem(stats_obj, "latest_event_at");
|
||||||
cJSON* time_stats = cJSON_GetObjectItem(stats_obj, "time_stats");
|
cJSON* time_stats = cJSON_GetObjectItem(stats_obj, "time_stats");
|
||||||
cJSON* event_kinds = cJSON_GetObjectItem(stats_obj, "event_kinds");
|
cJSON* event_kinds = cJSON_GetObjectItem(stats_obj, "event_kinds");
|
||||||
cJSON* top_pubkeys = cJSON_GetObjectItem(stats_obj, "top_pubkeys");
|
// cJSON* top_pubkeys = cJSON_GetObjectItem(stats_obj, "top_pubkeys");
|
||||||
|
|
||||||
long long total = total_events ? (long long)cJSON_GetNumberValue(total_events) : 0;
|
long long total = total_events ? (long long)cJSON_GetNumberValue(total_events) : 0;
|
||||||
long long db_bytes = db_size ? (long long)cJSON_GetNumberValue(db_size) : 0;
|
long long db_bytes = db_size ? (long long)cJSON_GetNumberValue(db_size) : 0;
|
||||||
@@ -1491,25 +1595,23 @@ char* generate_stats_text(void) {
|
|||||||
|
|
||||||
// Header
|
// Header
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"📊 Relay Statistics\n"
|
"\nRelay Statistics\n"
|
||||||
"━━━━━━━━━━━━━━━━━━━━\n");
|
"━━━━━━━━━━━━━━━━━━━━\n");
|
||||||
|
|
||||||
// Database Overview section
|
// Database Overview section
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"Database Overview:\n"
|
|
||||||
"Metric\tValue\tDescription\n"
|
"Database Size %.2f MB (%lld bytes)\n"
|
||||||
"Database Size\t%.2f MB (%lld bytes)\tCurrent database file size\n"
|
"Total Events %lld\n"
|
||||||
"Total Events\t%lld\tTotal number of events stored\n"
|
"Active Subscriptions %d\n"
|
||||||
"Active Subscriptions\t%d\tCurrent active WebSocket subscriptions\n"
|
"Oldest Event %s\n"
|
||||||
"Oldest Event\t%s\tTimestamp of oldest event\n"
|
"Newest Event %s\n"
|
||||||
"Newest Event\t%s\tTimestamp of newest event\n"
|
"\n",
|
||||||
"\n",
|
db_mb, db_bytes, total, active_subs, oldest_str, newest_str);
|
||||||
db_mb, db_bytes, total, active_subs, oldest_str, newest_str);
|
|
||||||
|
|
||||||
// Event Kind Distribution section
|
// Event Kind Distribution section
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"Event Kind Distribution:\n"
|
"Event_Kind_Distribution:\n");
|
||||||
"Event Kind\tCount\tPercentage\n");
|
|
||||||
|
|
||||||
if (event_kinds && cJSON_IsArray(event_kinds)) {
|
if (event_kinds && cJSON_IsArray(event_kinds)) {
|
||||||
cJSON* kind_item = NULL;
|
cJSON* kind_item = NULL;
|
||||||
@@ -1519,11 +1621,45 @@ char* generate_stats_text(void) {
|
|||||||
cJSON* percentage = cJSON_GetObjectItem(kind_item, "percentage");
|
cJSON* percentage = cJSON_GetObjectItem(kind_item, "percentage");
|
||||||
|
|
||||||
if (kind && count && percentage) {
|
if (kind && count && percentage) {
|
||||||
|
// Format event kind (right-justified, minimum 5 chars wide with underscores)
|
||||||
|
char kind_str[16];
|
||||||
|
int kind_val = (int)cJSON_GetNumberValue(kind);
|
||||||
|
char temp_kind[16];
|
||||||
|
snprintf(temp_kind, sizeof(temp_kind), "%d", kind_val);
|
||||||
|
|
||||||
|
// Calculate padding needed (minimum 5 chars, but more if kind is longer)
|
||||||
|
int kind_len = strlen(temp_kind);
|
||||||
|
int min_width = 5;
|
||||||
|
int total_width = (kind_len > min_width) ? kind_len : min_width;
|
||||||
|
int padding = total_width - kind_len;
|
||||||
|
|
||||||
|
// Create padded string with underscores
|
||||||
|
memset(kind_str, '_', padding);
|
||||||
|
strcpy(kind_str + padding, temp_kind);
|
||||||
|
|
||||||
|
// Format count with commas (right-justified, 11 chars wide with underscores)
|
||||||
|
char count_str[16];
|
||||||
|
format_number_with_commas((long long)cJSON_GetNumberValue(count), count_str, sizeof(count_str));
|
||||||
|
char count_formatted[16];
|
||||||
|
snprintf(count_formatted, sizeof(count_formatted), "%11s", count_str);
|
||||||
|
// Replace spaces with underscores for alignment
|
||||||
|
for (int i = 0; count_formatted[i]; i++) {
|
||||||
|
if (count_formatted[i] == ' ') count_formatted[i] = '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format percentage (right-justified, 7 chars wide including %, with underscores)
|
||||||
|
double pct = cJSON_GetNumberValue(percentage);
|
||||||
|
char pct_str[8];
|
||||||
|
snprintf(pct_str, sizeof(pct_str), "%.1f%%", pct);
|
||||||
|
// Pad with underscores to make 7 chars total (right-justified)
|
||||||
|
char pct_formatted[8];
|
||||||
|
int pct_len = strlen(pct_str);
|
||||||
|
int underscores_needed = 7 - pct_len;
|
||||||
|
memset(pct_formatted, '_', underscores_needed);
|
||||||
|
strcpy(pct_formatted + underscores_needed, pct_str);
|
||||||
|
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"%lld\t%lld\t%.1f%%\n",
|
"%s%s_%s\n", kind_str, count_formatted, pct_formatted);
|
||||||
(long long)cJSON_GetNumberValue(kind),
|
|
||||||
(long long)cJSON_GetNumberValue(count),
|
|
||||||
cJSON_GetNumberValue(percentage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1536,49 +1672,48 @@ char* generate_stats_text(void) {
|
|||||||
// Time-based Statistics section
|
// Time-based Statistics section
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"Time-based Statistics:\n"
|
"Time-based Statistics:\n"
|
||||||
"Period\tEvents\tDescription\n"
|
|
||||||
"Last 24 Hours\t%lld\tEvents in the last day\n"
|
"%lld\tEvents in the last day\n"
|
||||||
"Last 7 Days\t%lld\tEvents in the last week\n"
|
"%lld\tEvents in the last week\n"
|
||||||
"Last 30 Days\t%lld\tEvents in the last month\n"
|
"%lld\tEvents in the last month\n"
|
||||||
"\n",
|
"\n",
|
||||||
last_24h, last_7d, last_30d);
|
last_24h, last_7d, last_30d);
|
||||||
|
|
||||||
// Top Pubkeys section
|
// Top Pubkeys section
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
// offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"Top Pubkeys by Event Count:\n"
|
// "Top Pubkeys by Event Count:\n"
|
||||||
"Rank\tPubkey\tEvent Count\tPercentage\n");
|
// "Rank\tPubkey\tEvent Count\tPercentage\n");
|
||||||
|
|
||||||
if (top_pubkeys && cJSON_IsArray(top_pubkeys)) {
|
// if (top_pubkeys && cJSON_IsArray(top_pubkeys)) {
|
||||||
int rank = 1;
|
// int rank = 1;
|
||||||
cJSON* pubkey_item = NULL;
|
// cJSON* pubkey_item = NULL;
|
||||||
cJSON_ArrayForEach(pubkey_item, top_pubkeys) {
|
// cJSON_ArrayForEach(pubkey_item, top_pubkeys) {
|
||||||
cJSON* pubkey = cJSON_GetObjectItem(pubkey_item, "pubkey");
|
// cJSON* pubkey = cJSON_GetObjectItem(pubkey_item, "pubkey");
|
||||||
cJSON* event_count = cJSON_GetObjectItem(pubkey_item, "event_count");
|
// cJSON* event_count = cJSON_GetObjectItem(pubkey_item, "event_count");
|
||||||
cJSON* percentage = cJSON_GetObjectItem(pubkey_item, "percentage");
|
// cJSON* percentage = cJSON_GetObjectItem(pubkey_item, "percentage");
|
||||||
|
|
||||||
if (pubkey && event_count && percentage) {
|
// if (pubkey && event_count && percentage) {
|
||||||
const char* pubkey_str = cJSON_GetStringValue(pubkey);
|
// const char* pubkey_str = cJSON_GetStringValue(pubkey);
|
||||||
char short_pubkey[20] = "...";
|
// char short_pubkey[20] = "...";
|
||||||
if (pubkey_str && strlen(pubkey_str) >= 16) {
|
// if (pubkey_str && strlen(pubkey_str) >= 16) {
|
||||||
snprintf(short_pubkey, sizeof(short_pubkey), "%.16s...", pubkey_str);
|
// snprintf(short_pubkey, sizeof(short_pubkey), "%.16s...", pubkey_str);
|
||||||
}
|
// }
|
||||||
|
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
// offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"%d\t%s\t%lld\t%.1f%%\n",
|
// "%d\t%s\t%lld\t%.1f%%\n",
|
||||||
rank++,
|
// rank++,
|
||||||
short_pubkey,
|
// short_pubkey,
|
||||||
(long long)cJSON_GetNumberValue(event_count),
|
// (long long)cJSON_GetNumberValue(event_count),
|
||||||
cJSON_GetNumberValue(percentage));
|
// cJSON_GetNumberValue(percentage));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
// offset += snprintf(stats_text + offset, 16384 - offset,
|
||||||
"No pubkey data available\n");
|
// "No pubkey data available\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Footer
|
// Footer
|
||||||
offset += snprintf(stats_text + offset, 16384 - offset,
|
offset += snprintf(stats_text + offset, 16384 - offset, "\n");
|
||||||
"\n✅ Statistics retrieved successfully");
|
|
||||||
|
|
||||||
cJSON_Delete(stats_obj);
|
cJSON_Delete(stats_obj);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -64,4 +64,7 @@ void monitoring_on_event_stored(void);
|
|||||||
void monitoring_on_subscription_change(void);
|
void monitoring_on_subscription_change(void);
|
||||||
int get_monitoring_throttle_seconds(void);
|
int get_monitoring_throttle_seconds(void);
|
||||||
|
|
||||||
|
// Kind 1 status posts
|
||||||
|
int generate_and_post_status_event(void);
|
||||||
|
|
||||||
#endif // API_H
|
#endif // API_H
|
||||||
16
src/config.c
@@ -1144,6 +1144,20 @@ static int validate_config_field(const char* key, const char* value, char* error
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NIP-59 Gift Wrap Timestamp Configuration
|
||||||
|
if (strcmp(key, "nip59_timestamp_max_delay_sec") == 0) {
|
||||||
|
if (!is_valid_non_negative_integer(value)) {
|
||||||
|
snprintf(error_msg, error_size, "invalid nip59_timestamp_max_delay_sec '%s' (must be non-negative integer)", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
long val = strtol(value, NULL, 10);
|
||||||
|
if (val > 604800) { // Max 7 days
|
||||||
|
snprintf(error_msg, error_size, "nip59_timestamp_max_delay_sec '%s' too large (max 604800 seconds = 7 days)", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(key, "nip42_auth_required_kinds") == 0) {
|
if (strcmp(key, "nip42_auth_required_kinds") == 0) {
|
||||||
// Validate comma-separated list of kind numbers
|
// Validate comma-separated list of kind numbers
|
||||||
@@ -2538,7 +2552,7 @@ int handle_kind_23456_unified(cJSON* event, char* error_message, size_t error_si
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform NIP-44 decryption (relay as recipient, admin as sender)
|
// Perform NIP-44 decryption (relay as recipient, admin as sender)
|
||||||
char decrypted_text[4096]; // Buffer for decrypted content
|
char decrypted_text[16384]; // Buffer for decrypted content (16KB)
|
||||||
int decrypt_result = nostr_nip44_decrypt(relay_privkey_bytes, sender_pubkey_bytes, content, decrypted_text, sizeof(decrypted_text));
|
int decrypt_result = nostr_nip44_decrypt(relay_privkey_bytes, sender_pubkey_bytes, content, decrypted_text, sizeof(decrypted_text));
|
||||||
|
|
||||||
// Clean up private key immediately after use
|
// Clean up private key immediately after use
|
||||||
|
|||||||
@@ -78,7 +78,13 @@ static const struct {
|
|||||||
// Trust proxy headers (X-Forwarded-For, X-Real-IP) for accurate client IP detection
|
// Trust proxy headers (X-Forwarded-For, X-Real-IP) for accurate client IP detection
|
||||||
// Safe for informational/debugging use. Only becomes a security concern if you implement
|
// Safe for informational/debugging use. Only becomes a security concern if you implement
|
||||||
// IP-based rate limiting or access control (which would require firewall protection anyway)
|
// IP-based rate limiting or access control (which would require firewall protection anyway)
|
||||||
{"trust_proxy_headers", "true"}
|
{"trust_proxy_headers", "true"},
|
||||||
|
|
||||||
|
// NIP-59 Gift Wrap Timestamp Configuration
|
||||||
|
{"nip59_timestamp_max_delay_sec", "0"},
|
||||||
|
|
||||||
|
// Kind 1 Status Posts
|
||||||
|
{"kind_1_status_posts_hours", "1"}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Number of default configuration values
|
// Number of default configuration values
|
||||||
|
|||||||
BIN
src/default_config_event.h.gch
Normal file
@@ -368,13 +368,17 @@ cJSON* process_nip17_admin_message(cJSON* gift_wrap_event, char* error_message,
|
|||||||
|
|
||||||
if (success_dm) {
|
if (success_dm) {
|
||||||
cJSON* success_gift_wraps[1];
|
cJSON* success_gift_wraps[1];
|
||||||
|
// Get timestamp delay configuration
|
||||||
|
long max_delay_sec = get_config_int("nip59_timestamp_max_delay_sec", 0);
|
||||||
|
|
||||||
int send_result = nostr_nip17_send_dm(
|
int send_result = nostr_nip17_send_dm(
|
||||||
success_dm, // dm_event
|
success_dm, // dm_event
|
||||||
(const char**)&sender_pubkey, // recipient_pubkeys
|
(const char**)&sender_pubkey, // recipient_pubkeys
|
||||||
1, // num_recipients
|
1, // num_recipients
|
||||||
relay_privkey, // sender_private_key
|
relay_privkey, // sender_private_key
|
||||||
success_gift_wraps, // gift_wraps_out
|
success_gift_wraps, // gift_wraps_out
|
||||||
1 // max_gift_wraps
|
1, // max_gift_wraps
|
||||||
|
max_delay_sec // max_delay_sec
|
||||||
);
|
);
|
||||||
|
|
||||||
cJSON_Delete(success_dm);
|
cJSON_Delete(success_dm);
|
||||||
@@ -565,6 +569,35 @@ int process_nip17_admin_command(cJSON* dm_event, char* error_message, size_t err
|
|||||||
DEBUG_INFO("DM_ADMIN: Config command processed successfully");
|
DEBUG_INFO("DM_ADMIN: Config command processed successfully");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// Check for status commands
|
||||||
|
else if (strstr(content_lower, "status") != NULL) {
|
||||||
|
DEBUG_INFO("DM_ADMIN: Processing status command");
|
||||||
|
|
||||||
|
// Create synthetic event for system_command handler
|
||||||
|
cJSON* synthetic_event = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(synthetic_event, "kind", 23456);
|
||||||
|
cJSON_AddStringToObject(synthetic_event, "pubkey", sender_pubkey);
|
||||||
|
|
||||||
|
// Create tags array with system_command
|
||||||
|
cJSON* tags = cJSON_CreateArray();
|
||||||
|
cJSON* cmd_tag = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToArray(cmd_tag, cJSON_CreateString("system_command"));
|
||||||
|
cJSON_AddItemToArray(cmd_tag, cJSON_CreateString("system_status"));
|
||||||
|
cJSON_AddItemToArray(tags, cmd_tag);
|
||||||
|
cJSON_AddItemToObject(synthetic_event, "tags", tags);
|
||||||
|
|
||||||
|
char error_msg[256];
|
||||||
|
int result = handle_system_command_unified(synthetic_event, "system_status", error_msg, sizeof(error_msg), wsi);
|
||||||
|
cJSON_Delete(synthetic_event);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
DEBUG_ERROR(error_msg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_INFO("DM_ADMIN: Status command processed successfully");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG_INFO("DM_ADMIN: Checking for confirmation or config change requests");
|
DEBUG_INFO("DM_ADMIN: Checking for confirmation or config change requests");
|
||||||
// Check if it's a confirmation response (yes/no)
|
// Check if it's a confirmation response (yes/no)
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
// Version information (auto-updated by build system)
|
// Version information (auto-updated by build system)
|
||||||
#define VERSION "v0.7.42"
|
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 7
|
#define VERSION_MINOR 8
|
||||||
#define VERSION_PATCH 42
|
#define VERSION_PATCH 6
|
||||||
|
#define VERSION "v0.8.6"
|
||||||
|
|
||||||
// Relay metadata (authoritative source for NIP-11 information)
|
// Relay metadata (authoritative source for NIP-11 information)
|
||||||
#define RELAY_NAME "C-Relay"
|
#define RELAY_NAME "C-Relay"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/* Embedded SQL Schema for C Nostr Relay
|
/* Embedded SQL Schema for C Nostr Relay
|
||||||
* Generated from db/schema.sql - Do not edit manually
|
|
||||||
* Schema Version: 8
|
* Schema Version: 8
|
||||||
*/
|
*/
|
||||||
#ifndef SQL_SCHEMA_H
|
#ifndef SQL_SCHEMA_H
|
||||||
@@ -242,7 +241,8 @@ SELECT\n\
|
|||||||
s.filter_json,\n\
|
s.filter_json,\n\
|
||||||
s.events_sent,\n\
|
s.events_sent,\n\
|
||||||
s.created_at,\n\
|
s.created_at,\n\
|
||||||
(strftime('%s', 'now') - s.created_at) as duration_seconds\n\
|
(strftime('%s', 'now') - s.created_at) as duration_seconds,\n\
|
||||||
|
s.wsi_pointer\n\
|
||||||
FROM subscriptions s\n\
|
FROM subscriptions s\n\
|
||||||
WHERE s.event_type = 'created'\n\
|
WHERE s.event_type = 'created'\n\
|
||||||
AND NOT EXISTS (\n\
|
AND NOT EXISTS (\n\
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ void send_nip42_auth_challenge(struct lws* wsi, struct per_session_data* pss);
|
|||||||
void handle_nip42_auth_signed_event(struct lws* wsi, struct per_session_data* pss, cJSON* auth_event);
|
void handle_nip42_auth_signed_event(struct lws* wsi, struct per_session_data* pss, cJSON* auth_event);
|
||||||
void handle_nip42_auth_challenge_response(struct lws* wsi, struct per_session_data* pss, const char* challenge);
|
void handle_nip42_auth_challenge_response(struct lws* wsi, struct per_session_data* pss, const char* challenge);
|
||||||
|
|
||||||
|
// Forward declaration for status posts
|
||||||
|
int generate_and_post_status_event(void);
|
||||||
|
|
||||||
// Forward declarations for NIP-11 relay information handling
|
// Forward declarations for NIP-11 relay information handling
|
||||||
int handle_nip11_http_request(struct lws* wsi, const char* accept_header);
|
int handle_nip11_http_request(struct lws* wsi, const char* accept_header);
|
||||||
|
|
||||||
@@ -282,7 +285,19 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
|
|||||||
|
|
||||||
// Check if this is a GET request to the root path
|
// Check if this is a GET request to the root path
|
||||||
if (strcmp(requested_uri, "/") == 0) {
|
if (strcmp(requested_uri, "/") == 0) {
|
||||||
// Get Accept header
|
// Check if this is a WebSocket upgrade request
|
||||||
|
char upgrade_header[64] = {0};
|
||||||
|
int upgrade_len = lws_hdr_copy(wsi, upgrade_header, sizeof(upgrade_header) - 1, WSI_TOKEN_UPGRADE);
|
||||||
|
|
||||||
|
if (upgrade_len > 0) {
|
||||||
|
upgrade_header[upgrade_len] = '\0';
|
||||||
|
if (strstr(upgrade_header, "websocket") != NULL) {
|
||||||
|
DEBUG_LOG("WebSocket upgrade request - allowing connection");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not a WebSocket upgrade, check for NIP-11 request
|
||||||
char accept_header[256] = {0};
|
char accept_header[256] = {0};
|
||||||
int header_len = lws_hdr_copy(wsi, accept_header, sizeof(accept_header) - 1, WSI_TOKEN_HTTP_ACCEPT);
|
int header_len = lws_hdr_copy(wsi, accept_header, sizeof(accept_header) - 1, WSI_TOKEN_HTTP_ACCEPT);
|
||||||
|
|
||||||
@@ -300,7 +315,8 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root path without NIP-11 Accept header - return 404
|
// Root path without NIP-11 Accept header and not WebSocket - return 404
|
||||||
|
DEBUG_WARN("Rejecting root path request - not WebSocket upgrade and not NIP-11");
|
||||||
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1404,6 +1420,9 @@ int start_websocket_relay(int port_override, int strict_port) {
|
|||||||
snprintf(startup_msg, sizeof(startup_msg), "WebSocket relay started on ws://127.0.0.1:%d", actual_port);
|
snprintf(startup_msg, sizeof(startup_msg), "WebSocket relay started on ws://127.0.0.1:%d", actual_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static variable for status post timing (initialize to 0 for immediate first post)
|
||||||
|
static time_t last_status_post_time = 0;
|
||||||
|
|
||||||
// Main event loop with proper signal handling
|
// Main event loop with proper signal handling
|
||||||
while (g_server_running && !g_shutdown_flag) {
|
while (g_server_running && !g_shutdown_flag) {
|
||||||
int result = lws_service(ws_context, 1000);
|
int result = lws_service(ws_context, 1000);
|
||||||
@@ -1412,6 +1431,19 @@ int start_websocket_relay(int port_override, int strict_port) {
|
|||||||
DEBUG_ERROR("libwebsockets service error");
|
DEBUG_ERROR("libwebsockets service error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if it's time to post status update
|
||||||
|
time_t current_time = time(NULL);
|
||||||
|
int status_post_hours = get_config_int("kind_1_status_posts_hours", 0);
|
||||||
|
|
||||||
|
if (status_post_hours > 0) {
|
||||||
|
int seconds_interval = status_post_hours * 3600; // Convert hours to seconds
|
||||||
|
|
||||||
|
if (current_time - last_status_post_time >= seconds_interval) {
|
||||||
|
last_status_post_time = current_time;
|
||||||
|
generate_and_post_status_event();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lws_context_destroy(ws_context);
|
lws_context_destroy(ws_context);
|
||||||
@@ -1512,7 +1544,7 @@ int process_dm_stats_command(cJSON* dm_event, char* error_message, size_t error_
|
|||||||
const char* encrypted_content = cJSON_GetStringValue(content_obj);
|
const char* encrypted_content = cJSON_GetStringValue(content_obj);
|
||||||
|
|
||||||
// Decrypt content
|
// Decrypt content
|
||||||
char decrypted_content[4096];
|
char decrypted_content[16384];
|
||||||
int decrypt_result = nostr_nip44_decrypt(relay_privkey, sender_pubkey_bytes,
|
int decrypt_result = nostr_nip44_decrypt(relay_privkey, sender_pubkey_bytes,
|
||||||
encrypted_content, decrypted_content, sizeof(decrypted_content));
|
encrypted_content, decrypted_content, sizeof(decrypted_content));
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=C Nostr Relay Server (Local Development)
|
|
||||||
Documentation=https://github.com/your-repo/c-relay
|
|
||||||
After=network.target
|
|
||||||
Wants=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=teknari
|
|
||||||
WorkingDirectory=/home/teknari/Storage/c_relay
|
|
||||||
Environment=DEBUG_LEVEL=0
|
|
||||||
ExecStart=/home/teknari/Storage/c_relay/crelay --port 7777 --debug-level=$DEBUG_LEVEL
|
|
||||||
Restart=always
|
|
||||||
RestartSec=5
|
|
||||||
StandardOutput=journal
|
|
||||||
StandardError=journal
|
|
||||||
SyslogIdentifier=c-relay-local
|
|
||||||
|
|
||||||
# Security settings (relaxed for local development)
|
|
||||||
NoNewPrivileges=true
|
|
||||||
ProtectSystem=strict
|
|
||||||
ProtectHome=true
|
|
||||||
ReadWritePaths=/home/teknari/Storage/c_relay
|
|
||||||
PrivateTmp=true
|
|
||||||
|
|
||||||
# Network security
|
|
||||||
PrivateNetwork=false
|
|
||||||
RestrictAddressFamilies=AF_INET AF_INET6
|
|
||||||
|
|
||||||
# Resource limits
|
|
||||||
LimitNOFILE=65536
|
|
||||||
LimitNPROC=4096
|
|
||||||
|
|
||||||
# Event-based configuration system
|
|
||||||
# No environment variables needed - all configuration is stored as Nostr events
|
|
||||||
# Database files (<relay_pubkey>.db) are created automatically in WorkingDirectory
|
|
||||||
# Admin keys are generated and displayed only during first startup
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||