Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ package runtime

import (
"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
)

// daemonEventBus adapts daemon's in-process bus to coreapi.EventBus
// for plugin Deps. Publish forwards through Daemon.PublishEvent;
// Subscribe wraps the bus channel with type conversion daemon.Event
// Subscribe wraps the bus channel with type conversion daemonapi.Event
// → coreapi.Event.

type daemonEventBus struct{ d *daemon.Daemon }
type daemonEventBus struct{ d daemonapi.Daemon }

func (b daemonEventBus) Publish(topic string, payload map[string]any) {
if b.d == nil {
Expand Down
12 changes: 10 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ module github.com/pilot-protocol/runtime
go 1.25.10

require (
github.com/TeoSlayer/pilotprotocol v0.0.0
github.com/TeoSlayer/pilotprotocol v1.10.5
github.com/pilot-protocol/common v0.4.0
github.com/pilot-protocol/handshake v0.1.0
github.com/pilot-protocol/policy v0.1.0
)

require (
github.com/coder/websocket v1.8.14 // indirect
github.com/expr-lang/expr v1.17.8 // indirect
github.com/pilot-protocol/common v0.2.0 // indirect
github.com/pilot-protocol/trustedagents v0.1.0 // indirect
)

replace github.com/TeoSlayer/pilotprotocol => ../web4

replace github.com/pilot-protocol/common => ../common

replace github.com/pilot-protocol/handshake => ../handshake

replace github.com/pilot-protocol/policy => ../policy

replace github.com/pilot-protocol/trustedagents => ../trustedagents

replace github.com/pilot-protocol/rendezvous => ../rendezvous
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,3 @@ github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/pilot-protocol/common v0.1.0 h1:m8mZZATgeBiFoqhWXPnskw2u0lNkWxHp0IagZK35V1g=
github.com/pilot-protocol/common v0.1.0/go.mod h1:4YZWHK5nhM+4RLmYTspLxxAFbyBII7yzQDAHq3Ul2ck=
github.com/pilot-protocol/handshake v0.1.0 h1:TmqIglsimTynKtE5hLpCt/SZmmBYs8OCn4qn755fmew=
github.com/pilot-protocol/handshake v0.1.0/go.mod h1:FIIMTgRcMIMEim/1d7F5f6YenJC+3xl53QMEmnnJY+0=
github.com/pilot-protocol/policy v0.1.0 h1:Eh0CfCZDEX8UCkMPi2MrNrhCe8c15a/Bqf4eaKUhyis=
github.com/pilot-protocol/policy v0.1.0/go.mod h1:IMVm7IQhgLtH/iXow2AWFuLl+sKrxJ4mGs4EKLoHop8=
github.com/pilot-protocol/rendezvous v0.1.0 h1:vOBD7CnRY8uU8vma0Vfcr0aPSQ54qNuxppNUiljzk9Y=
github.com/pilot-protocol/rendezvous v0.1.0/go.mod h1:g3/IYBykbU5m9jeprSCrmuoDpaqROO4Lu/+ecKVIF3A=
github.com/pilot-protocol/trustedagents v0.1.0 h1:rCX0IQxfZ84Q4dSgw01WJgjHUODRnI3iAon1t+NuFGE=
github.com/pilot-protocol/trustedagents v0.1.0/go.mod h1:uVySmuMPb6N7AOCnvLHN2I9C9ggqEpfBmAZwVuP5Xaw=
28 changes: 14 additions & 14 deletions handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
"github.com/pilot-protocol/common/protocol"
registryclient "github.com/pilot-protocol/common/registry/client"
"github.com/pilot-protocol/handshake"
Expand All @@ -17,13 +17,13 @@ import (
// handshakeCloseDelay matches plugins/handshake.HandshakeCloseDelay.
const handshakeCloseDelay = 500 * time.Millisecond

// HandshakeRuntime adapts *daemon.Daemon to the handshake.Runtime
// HandshakeRuntime adapts daemonapi.Daemon to the handshake.Runtime
// interface. Lives here (L12 composition root) so plugins/handshake
// stays free of pkg/daemon.
type HandshakeRuntime struct{ d *daemon.Daemon }
type HandshakeRuntime struct{ d daemonapi.Daemon }

// NewHandshakeRuntime returns a handshake.Runtime backed by d.
func NewHandshakeRuntime(d *daemon.Daemon) handshake.Runtime {
func NewHandshakeRuntime(d daemonapi.Daemon) handshake.Runtime {
return HandshakeRuntime{d: d}
}

Expand Down Expand Up @@ -95,22 +95,22 @@ func (r HandshakeRuntime) Registry() handshake.RegistryClient {
}

// handshakeServiceAdapter converts between plugins/handshake types and
// the daemon-local daemon.HandshakeService mirror types.
// the daemon-local daemonapi.HandshakeService mirror types.
type handshakeServiceAdapter struct{ m *handshake.Manager }

// NewHandshakeServiceAdapter wraps a *handshake.Service so it satisfies
// daemon.HandshakeService.
func NewHandshakeServiceAdapter(svc *handshake.Service) daemon.HandshakeService {
// daemonapi.HandshakeService.
func NewHandshakeServiceAdapter(svc *handshake.Service) daemonapi.HandshakeService {
return handshakeServiceAdapter{m: svc.Manager()}
}

func (a handshakeServiceAdapter) IsTrusted(nodeID uint32) bool { return a.m.IsTrusted(nodeID) }

func (a handshakeServiceAdapter) TrustedPeers() []daemon.HandshakeTrustRecord {
func (a handshakeServiceAdapter) TrustedPeers() []daemonapi.HandshakeTrustRecord {
src := a.m.TrustedPeers()
out := make([]daemon.HandshakeTrustRecord, len(src))
out := make([]daemonapi.HandshakeTrustRecord, len(src))
for i, r := range src {
out[i] = daemon.HandshakeTrustRecord{
out[i] = daemonapi.HandshakeTrustRecord{
NodeID: r.NodeID,
PublicKey: r.PublicKey,
ApprovedAt: r.ApprovedAt,
Expand All @@ -121,11 +121,11 @@ func (a handshakeServiceAdapter) TrustedPeers() []daemon.HandshakeTrustRecord {
return out
}

func (a handshakeServiceAdapter) PendingRequests() []daemon.HandshakePendingRecord {
func (a handshakeServiceAdapter) PendingRequests() []daemonapi.HandshakePendingRecord {
src := a.m.PendingRequests()
out := make([]daemon.HandshakePendingRecord, len(src))
out := make([]daemonapi.HandshakePendingRecord, len(src))
for i, p := range src {
out[i] = daemon.HandshakePendingRecord{
out[i] = daemonapi.HandshakePendingRecord{
NodeID: p.NodeID,
PublicKey: p.PublicKey,
Justification: p.Justification,
Expand Down Expand Up @@ -174,6 +174,6 @@ func (a handshakeServiceAdapter) Stop() { a.m.Stop() }
// Compile-time guards.
var (
_ handshake.Runtime = HandshakeRuntime{}
_ daemon.HandshakeService = handshakeServiceAdapter{}
_ daemonapi.HandshakeService = handshakeServiceAdapter{}
_ handshake.RegistryClient = (*registryclient.Client)(nil)
)
4 changes: 2 additions & 2 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"errors"

"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
)

// daemonIdentity adapts daemon's identity state to coreapi.Identity
// for plugin Deps. Methods that need the underlying *crypto.Identity
// (PublicKey, Sign) go through Daemon.Identity().

type daemonIdentity struct{ d *daemon.Daemon }
type daemonIdentity struct{ d daemonapi.Daemon }

func (i daemonIdentity) NodeID() uint32 { return i.d.NodeID() }
func (i daemonIdentity) Address() coreapi.Addr { return i.d.Addr() }
Expand Down
8 changes: 4 additions & 4 deletions policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
package runtime

import (
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
"github.com/pilot-protocol/policy"
)

// PolicyRuntime adapts *daemon.Daemon to the policy.Runtime interface.
// PolicyRuntime adapts daemonapi.Daemon to the policy.Runtime interface.
// Lives here (L12 composition root) so plugins/policy stays free of
// pkg/daemon.
type PolicyRuntime struct{ d *daemon.Daemon }
type PolicyRuntime struct{ d daemonapi.Daemon }

// NewPolicyRuntime returns a policy.Runtime backed by d.
func NewPolicyRuntime(d *daemon.Daemon) policy.Runtime {
func NewPolicyRuntime(d daemonapi.Daemon) policy.Runtime {
return PolicyRuntime{d: d}
}

Expand Down
18 changes: 9 additions & 9 deletions policy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package runtime

import (
"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
)

// AsDaemonPolicyManager adapts a coreapi.PolicyManager (returned by
// plugins/policy.Service.Manager()) to daemon.PolicyManager. The two
// plugins/policy.Service.Manager()) to daemonapi.PolicyManager. The two
// interfaces have identical method shapes; the adapter does the
// PolicyRunner element-type conversion on All() and Get().
func AsDaemonPolicyManager(pm coreapi.PolicyManager) daemon.PolicyManager {
func AsDaemonPolicyManager(pm coreapi.PolicyManager) daemonapi.PolicyManager {
if pm == nil {
return nil
}
Expand All @@ -20,7 +20,7 @@ func AsDaemonPolicyManager(pm coreapi.PolicyManager) daemon.PolicyManager {

type policyManagerAdapter struct{ inner coreapi.PolicyManager }

func (a policyManagerAdapter) Start(netID uint16, policyJSON []byte) (daemon.PolicyRunner, error) {
func (a policyManagerAdapter) Start(netID uint16, policyJSON []byte) (daemonapi.PolicyRunner, error) {
pr, err := a.inner.Start(netID, policyJSON)
if err != nil {
return nil, err
Expand All @@ -30,13 +30,13 @@ func (a policyManagerAdapter) Start(netID uint16, policyJSON []byte) (daemon.Pol

func (a policyManagerAdapter) Stop(netID uint16) { a.inner.Stop(netID) }

func (a policyManagerAdapter) Get(netID uint16) daemon.PolicyRunner {
func (a policyManagerAdapter) Get(netID uint16) daemonapi.PolicyRunner {
return wrapRunner(a.inner.Get(netID))
}

func (a policyManagerAdapter) All() []daemon.PolicyRunner {
func (a policyManagerAdapter) All() []daemonapi.PolicyRunner {
src := a.inner.All()
out := make([]daemon.PolicyRunner, 0, len(src))
out := make([]daemonapi.PolicyRunner, 0, len(src))
for _, pr := range src {
out = append(out, wrapRunner(pr))
}
Expand All @@ -46,11 +46,11 @@ func (a policyManagerAdapter) All() []daemon.PolicyRunner {
func (a policyManagerAdapter) StopAll() { a.inner.StopAll() }
func (a policyManagerAdapter) LoadPersisted() error { return a.inner.LoadPersisted() }

// wrapRunner converts a coreapi.PolicyRunner to a daemon.PolicyRunner.
// wrapRunner converts a coreapi.PolicyRunner to a daemonapi.PolicyRunner.
// The methods are structurally compatible (PolicyEventType is a type
// alias to string), but Go's named-interface typing requires an
// explicit shim.
func wrapRunner(pr coreapi.PolicyRunner) daemon.PolicyRunner {
func wrapRunner(pr coreapi.PolicyRunner) daemonapi.PolicyRunner {
if pr == nil {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ import (
"context"

"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
)

// Runtime owns the plugin-side glue for a single daemon. cmd/daemon
// constructs one, registers L11 services, then calls StartPlugins
// after Daemon.Start (so regConn etc. are wired) and StopPlugins
// before Daemon.Stop.
type Runtime struct {
d *daemon.Daemon
d daemonapi.Daemon
registry *coreapi.ServiceRegistry
}

// New returns a Runtime bound to the given daemon. Safe to call
// before d.Start.
func New(d *daemon.Daemon) *Runtime {
func New(d daemonapi.Daemon) *Runtime {
return &Runtime{d: d, registry: &coreapi.ServiceRegistry{}}
}

// Daemon returns the underlying daemon (test access).
func (r *Runtime) Daemon() *daemon.Daemon { return r.d }
func (r *Runtime) Daemon() daemonapi.Daemon { return r.d }

// Register adds a service to the registry. Mirrors the old
// daemon.RegisterPlugin. Must be called before StartPlugins.
Expand All @@ -60,18 +60,18 @@ func (r *Runtime) StopPlugins(ctx context.Context) error {
return r.registry.StopAll(ctx)
}

// asCoreapiTrust adapts a daemon.TrustChecker (primitives) to the
// asCoreapiTrust adapts a daemonapi.TrustChecker (primitives) to the
// coreapi.TrustChecker plugins expect. Structurally identical
// signatures, but Go's interface-typing requires an explicit bridge
// when the named types differ. nil → nil (no plugin → no auto-accept).
func asCoreapiTrust(t daemon.TrustChecker) coreapi.TrustChecker {
func asCoreapiTrust(t daemonapi.TrustChecker) coreapi.TrustChecker {
if t == nil {
return nil
}
return trustAdapter{inner: t}
}

type trustAdapter struct{ inner daemon.TrustChecker }
type trustAdapter struct{ inner daemonapi.TrustChecker }

func (a trustAdapter) IsTrusted(nodeID uint32) (string, bool) {
return a.inner.IsTrusted(nodeID)
Expand Down
32 changes: 16 additions & 16 deletions streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"errors"

"github.com/pilot-protocol/common/coreapi"
"github.com/TeoSlayer/pilotprotocol/pkg/daemon"
"github.com/pilot-protocol/common/daemonapi"
)

// daemonStreams is the in-process implementation of coreapi.Streams.
// Lives here (plugins/runtime) so daemon doesn't carry the L10 import.

type daemonStreams struct{ d *daemon.Daemon }
type daemonStreams struct{ d daemonapi.Daemon }

func (s daemonStreams) Listen(port uint16) (coreapi.Listener, error) {
ln, err := s.d.Ports().Bind(port)
Expand All @@ -36,46 +36,46 @@ func (s daemonStreams) SendDatagram(ctx context.Context, dst coreapi.Addr, port
}

type daemonListener struct {
inner *daemon.Listener
d *daemon.Daemon
inner daemonapi.Listener
d daemonapi.Daemon
}

func (l *daemonListener) Accept() (coreapi.Stream, error) {
conn, ok := <-l.inner.AcceptCh
conn, ok := l.inner.Accept()
if !ok {
return nil, errors.New("listener closed")
}
return newStreamAdapter(l.d, conn), nil
}

func (l *daemonListener) Close() error {
l.d.Ports().Unbind(l.inner.Port)
l.d.Ports().Unbind(l.inner.Port())
return nil
}

func (l *daemonListener) Addr() coreapi.Addr { return l.d.Addr() }
func (l *daemonListener) Port() uint16 { return l.inner.Port }
func (l *daemonListener) Port() uint16 { return l.inner.Port() }

// streamAdapter wraps *daemon.Connection so it satisfies coreapi.Stream.
// streamAdapter wraps daemonapi.Connection so it satisfies coreapi.Stream.
// Daemon exposes a connAdapter via Daemon.NewConnAdapter for this.
type streamAdapter struct {
d *daemon.Daemon
conn *daemon.Connection
rw daemon.ConnReadWriter
d daemonapi.Daemon
conn daemonapi.Connection
rw daemonapi.ConnReadWriter
}

func newStreamAdapter(d *daemon.Daemon, conn *daemon.Connection) *streamAdapter {
func newStreamAdapter(d daemonapi.Daemon, conn daemonapi.Connection) *streamAdapter {
return &streamAdapter{d: d, conn: conn, rw: d.NewConnReadWriter(conn)}
}

func (s *streamAdapter) Read(p []byte) (int, error) { return s.rw.Read(p) }
func (s *streamAdapter) Write(p []byte) (int, error) { return s.rw.Write(p) }
func (s *streamAdapter) Close() error { return s.rw.Close() }

func (s *streamAdapter) LocalAddr() coreapi.Addr { return s.conn.LocalAddr }
func (s *streamAdapter) LocalPort() uint16 { return s.conn.LocalPort }
func (s *streamAdapter) RemoteAddr() coreapi.Addr { return s.conn.RemoteAddr }
func (s *streamAdapter) RemotePort() uint16 { return s.conn.RemotePort }
func (s *streamAdapter) LocalAddr() coreapi.Addr { return s.conn.Info().LocalAddr }
func (s *streamAdapter) LocalPort() uint16 { return s.conn.Info().LocalPort }
func (s *streamAdapter) RemoteAddr() coreapi.Addr { return s.conn.Info().RemoteAddr }
func (s *streamAdapter) RemotePort() uint16 { return s.conn.Info().RemotePort }



Expand Down
Loading