feat(daemonapi): runtime plugin registry + Daemon contract#3
Merged
Conversation
Adds the dependency-free contract layer that breaks the
web4 ↔ daemon-plugin cycle. Plugins import only common/daemonapi;
the concrete *daemon.Daemon in web4/pkg/daemon satisfies the
interfaces via Go's structural typing — neither side imports the
other.
Files:
daemonapi/doc.go package overview + the 'not static'
wiring story.
daemonapi/plugin.go Plugin interface + Factory.
daemonapi/registry.go RegisterPlugin / LoadAll / ShutdownAll.
Process-global append-only map; plugin
packages register from init(); the
daemon iterates whatever's there.
Same mechanism works for compile-time
blank-imports and for runtime plugin.Open
of .so files.
daemonapi/daemon.go Daemon interface — the union of what
handshake, runtime, and libpilot actually
call. Return types: common-package
concrete types (*crypto.Identity,
*registry.Client, protocol.Addr) where
available; opaque marker interfaces
(Connection, PortAllocator, TunnelRegistry)
where the concrete return type lives
inside the daemon engine.
daemonapi/connection.go Connection (opaque marker) +
ConnReadWriter (read/write adapter) +
PortAllocator + TunnelRegistry.
daemonapi/event.go Event struct + EventBus interface.
daemonapi/services.go Copy of pkg/daemon/contract.go: TrustChecker,
HandshakeService, PolicyRunner, PolicyManager,
WebhookManager, and the *Record value types
they exchange.
Smoke-tested:
- RegisterPlugin + LoadAll wires plugins in sorted order
- Duplicate registration panics in init()
- LoadAll stops on first Init error and returns partial-loaded list
- ShutdownAll runs in reverse-of-load order
Next: web4/pkg/daemon adds an interface-conformance assertion
(var _ daemonapi.Daemon = (*Daemon)(nil)) so the compiler enforces
the contract. Then handshake, runtime, libpilot migrate off the
direct web4 imports.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a dependency-free contract layer that breaks the web4 ↔ daemon-plugin cycle.
common/daemonapicontains:Plugininterface (Name,Init(Daemon),Shutdown(ctx)) +FactorytypeRegisterPlugin/LoadAll/ShutdownAll— process-global, append-only. Plugins register frominit(); daemon engine iterates.TrustChecker,HandshakeService,PolicyManager,PolicyRunner,WebhookManager(copied fromweb4/pkg/daemon/contract.go— already primitive-only)Connection,PortAllocator,TunnelRegistryfor engine-internal types plugins treat as tokensEventstruct +EventBusinterface (Publish/Subscribe)Why this unblocks 'not static'
LoadAlliterates the registry.plugin.Open.sofiles.Tests
4 tests pass:
TestRegisterAndLoadAll— registers two factories, verifies sorted Init order + daemon flow-throughTestRegisterDuplicatePanics— duplicate name is a programming errorTestLoadAllStopsOnFirstError— partial-load list returned, no further Init attemptsTestShutdownAllReverseOrder— reverse of load orderNext PRs
TeoSlayer/pilotprotocol: addvar _ daemonapi.Daemon = (*Daemon)(nil)assertion in pkg/daemon. Compiler verifies the contract.*daemon.Daemonreferences withdaemonapi.Daemon. Drop the web4 require.🤖 Generated with Claude Code