Skip to content

feat(nip66): add RelayMonitorWorker cluster worker and probe scheduler - #724

Merged
Ferryx349 merged 4 commits into
mainfrom
nip66_worker
Aug 16, 2026
Merged

feat(nip66): add RelayMonitorWorker cluster worker and probe scheduler#724
Ferryx349 merged 4 commits into
mainfrom
nip66_worker

Conversation

@Ferryx349

@Ferryx349Ferryx349 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR:-

Related Issue

Closes#695

Motivation and Context

How Has This Been Tested?

  • Set nip66.enabled: true in settings and confirm 1 relay-monitor worker started in logs
  • Confirm Redis key nip66:snapshot:latest is populated after probe interval
  • Set nip66.enabled: false and confirm no relay-monitor worker is forked
  • Configure custom nip66.targets and verify those URLs are probed

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

@changeset-bot

changeset-botBot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8466288

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
nostreamMinor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls

coveralls commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 70.013% (+0.07%) from 69.944% — nip66_worker into main

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the NIP-66 relay monitoring foundation to Nostream by introducing a dedicated relay-monitor cluster worker that schedules periodic relay probes, persists the latest probe snapshot to Redis, and wires new nip66.* settings into defaults and documentation.

Changes:

  • Add WORKER_TYPE=relay-monitor cluster worker (RelayMonitorWorker) that schedules and runs NIP-66 probes and stores the latest snapshot in Redis.
  • Introduce a shared relay probe engine (DNS/TLS/WS RTT/NIP-11) plus target resolution and snapshot storage utilities.
  • Add nip66.* settings types, defaults, documentation, and unit tests covering settings/targets/probing/snapshot persistence.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
test/unit/utils/settings.spec.tsAdds unit coverage for nip66.* default-settings and merge behavior.
test/unit/utils/relay-probe-targets.spec.tsTests probe target resolution and validation/filtering.
test/unit/utils/relay-probe-target.spec.tsTests probe target parsing, network type detection, and safety helpers.
test/unit/utils/relay-probe-snapshot.spec.tsTests Redis snapshot store read/write and status derivation.
test/unit/utils/relay-probe-run.spec.tsTests end-to-end probe runner behavior (timeouts, cache, error surfacing).
test/unit/utils/relay-probe-dns.spec.tsTests DNS record collection behavior.
test/unit/app/relay-monitor-worker.spec.tsTests scheduler behavior, overlap-skipping, interval minimum, and shutdown handling.
src/utils/relay-probe/ws-rtt-probe.tsImplements WS handshake RTT probing via ws.
src/utils/relay-probe/types.tsAdds probe engine types and defaults (timeouts, DNS cache TTL).
src/utils/relay-probe/tls-probe.tsImplements TLS certificate probing via tls.connect.
src/utils/relay-probe/target.tsAdds relay URL parsing and network-type helpers (clearnet/tor/i2p).
src/utils/relay-probe/run-probe.tsImplements the orchestrated probe run across DNS/TLS/WS/NIP-11.
src/utils/relay-probe/nip11-probe.tsImplements NIP-11 fetching with redirect/SSRF safeguards and schema parsing.
src/utils/relay-probe/index.tsExposes the probe engine public API surface.
src/utils/relay-probe/dns-probe.tsImplements DNS resolution with A/AAAA/CNAME collection and error handling.
src/utils/relay-probe/dns-cache.tsAdds in-memory DNS cache with TTL support.
src/utils/relay-probe-targets.tsAdds settings-driven probe target selection and validation helpers.
src/utils/relay-probe-snapshot.tsAdds Redis snapshot storage and run status derivation.
src/index.tsRegisters relay-monitor in worker runner selection.
src/factories/relay-monitor-worker-factory.tsWires RelayMonitorWorker with Redis-backed snapshot store and settings.
src/app/relay-monitor-worker.tsAdds the relay-monitor scheduler worker implementation.
src/app/app.tsForks the relay-monitor worker when nip66.enabled is true.
src/@types/settings.tsAdds Nip66Settings to the Settings model.
src/@types/relay-probe-snapshot.tsAdds typed snapshot contract used for Redis persistence/downstream APIs.
resources/default-settings.yamlAdds nip66 configuration block with defaults.
CONFIGURATION.mdDocuments nip66.* settings in the configuration reference.
.knip.jsonUpdates knip ignore list to account for new probe module usage patterns.
.env.exampleAdds reserved monitor identity env var example.
.changeset/nip66-settings-foundation.mdChangeset entry for settings foundation.
.changeset/nip66-relay-monitor-worker.mdChangeset entry for the new worker/scheduler.
.changeset/nip66-probe-engine.mdChangeset entry for the shared probe engine.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threadsrc/utils/relay-probe/nip11-probe.ts Outdated
Comment threadsrc/@types/relay-probe-snapshot.ts
Add WORKER_TYPE=relay-monitor to schedule NIP-66 probes on a configurable
interval, persist the latest snapshot in Redis, and fork the worker when
nip66.enabled is true.
Reject unbracketed IPv6 hostnames in isNip11FetchTargetSafe and introduce
StoredProbeResult so Redis snapshots accurately use ISO date strings.
@Ferryx349

Copy link
Copy Markdown
CollaboratorAuthor

I have rebased this branch, ready to review now.


if (host.startsWith('[') && host.endsWith(']')) {
// IPv6 literal: URL.hostname is unbracketed (e.g. "::1"); NIP-11 fetch targets should not be IP literals.
if (host.includes(':')) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is correct for IPv6. Doesn't zod have something for this? If not okay we can leave as-is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zod doesn’t have a built-in for this in our stack. Happy to switch to net.isIP() in a follow-up.

@Ferryx349
Ferryx349 merged commit d14b1e9 into mainAug 16, 2026
18 of 19 checks passed
@Ferryx349
Ferryx349 deleted the nip66_worker branch August 16, 2026 17:09
@cameri

Copy link
Copy Markdown
Owner

thank you @Ferryx349 !

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(nip66): add RelayMonitorWorker cluster worker and probe scheduler

4 participants

@Ferryx349@coveralls@cameri