-
Notifications
You must be signed in to change notification settings - Fork 12
/
plugin_relayer.go
68 lines (50 loc) · 2.08 KB
/
plugin_relayer.go
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
61
62
63
64
65
66
67
68
package loop
import (
"context"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/net"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/relayer"
looptypes "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)
// PluginRelayerName is the name for [types.PluginRelayer]/[NewGRPCPluginRelayer].
const PluginRelayerName = "relayer"
type PluginRelayer = looptypes.PluginRelayer
func PluginRelayerHandshakeConfig() plugin.HandshakeConfig {
return plugin.HandshakeConfig{
MagicCookieKey: "CL_PLUGIN_RELAYER_MAGIC_COOKIE",
MagicCookieValue: "dae753d4542311b33cf041b930db0150647e806175c2818a0c88a9ab745e45aa",
}
}
// Deprecated
type Keystore = core.Keystore
type Relayer = looptypes.Relayer
type BrokerConfig = net.BrokerConfig
var _ plugin.GRPCPlugin = (*GRPCPluginRelayer)(nil)
// GRPCPluginRelayer implements [plugin.GRPCPlugin] for [types.PluginRelayer].
type GRPCPluginRelayer struct {
plugin.NetRPCUnsupportedPlugin
BrokerConfig
PluginServer PluginRelayer
pluginClient *relayer.PluginRelayerClient
}
func (p *GRPCPluginRelayer) GRPCServer(broker *plugin.GRPCBroker, server *grpc.Server) error {
return relayer.RegisterPluginRelayerServer(server, broker, p.BrokerConfig, p.PluginServer)
}
// GRPCClient implements [plugin.GRPCPlugin] and returns the pluginClient [types.PluginRelayer], updated with the new broker and conn.
func (p *GRPCPluginRelayer) GRPCClient(_ context.Context, broker *plugin.GRPCBroker, conn *grpc.ClientConn) (interface{}, error) {
if p.pluginClient == nil {
p.pluginClient = relayer.NewPluginRelayerClient(broker, p.BrokerConfig, conn)
} else {
p.pluginClient.Refresh(broker, conn)
}
return PluginRelayer(p.pluginClient), nil
}
func (p *GRPCPluginRelayer) ClientConfig() *plugin.ClientConfig {
c := &plugin.ClientConfig{
HandshakeConfig: PluginRelayerHandshakeConfig(),
Plugins: map[string]plugin.Plugin{PluginRelayerName: p},
}
return ManagedGRPCClientConfig(c, p.BrokerConfig)
}