-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolicy.go
More file actions
60 lines (47 loc) · 1.61 KB
/
Copy pathpolicy.go
File metadata and controls
60 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: AGPL-3.0-or-later
package runtime
import (
"github.com/pilot-protocol/common/daemonapi"
"github.com/pilot-protocol/policy"
)
// 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 daemonapi.Daemon }
// NewPolicyRuntime returns a policy.Runtime backed by d.
func NewPolicyRuntime(d daemonapi.Daemon) policy.Runtime {
return PolicyRuntime{d: d}
}
func (r PolicyRuntime) NodeID() uint32 { return r.d.NodeID() }
func (r PolicyRuntime) PublishEvent(topic string, payload map[string]any) {
r.d.PublishEvent(topic, payload)
}
func (r PolicyRuntime) AdminToken() string { return r.d.AdminToken() }
func (r PolicyRuntime) ListNodes(netID uint16, token string) (map[string]any, error) {
return r.d.RegConnListNodes(netID, token)
}
func (r PolicyRuntime) SetMemberTags(netID uint16, tags []string) {
r.d.SetMemberTags(netID, tags)
}
func (r PolicyRuntime) TrustedPeers() []policy.TrustRecord {
src := r.d.TrustedPeers()
out := make([]policy.TrustRecord, 0, len(src))
for _, t := range src {
out = append(out, policy.TrustRecord{
NodeID: t.NodeID,
PublicKey: t.PublicKey,
ApprovedAt: t.ApprovedAt,
Mutual: t.Mutual,
Network: t.Network,
})
}
return out
}
func (r PolicyRuntime) RevokeTrust(nodeID uint32) error {
return r.d.HandshakeRevokeTrust(nodeID)
}
func (r PolicyRuntime) SendHandshakeRequest(nodeID uint32, reason string) error {
return r.d.HandshakeSendRequest(nodeID, reason)
}
// Compile-time guard.
var _ policy.Runtime = PolicyRuntime{}