Documentation
¶
Overview ¶
Package grpcplugin holds the go-plugin wire wiring shared by the core host adapter and the plugin SDK: the handshake and the dispense key.
Index ¶
- Constants
- Variables
- func Bridge(a, b io.ReadWriteCloser)
- func DecodeManifest(data []byte) (plugin.Manifest, []plugin.Route, error)
- func DialConn(broker *goplugin.GRPCBroker, id uint32) (net.Conn, error)
- func EncodeManifest(m plugin.Manifest, routes []plugin.Route) ([]byte, error)
- func ErrorFromStatus(err error) error
- func NewConnBridge(target net.Conn) pluginv1.ConnServer
- func NewHTTPProxyBridge(baseURL string, rt http.RoundTripper) (pluginv1.ConnServer, error)
- func NewPipeServer(handle func(ctx context.Context, conn net.Conn) error) pluginv1.ConnServer
- func Plugins(impl plugin.Plugin) goplugin.PluginSet
- func ServeConn(broker *goplugin.GRPCBroker, srv pluginv1.ConnServer) uint32
- func StatusFromError(err error) error
- type Client
- type GoPlugin
Constants ¶
const PluginName = "plugin"
PluginName is the dispense key under which the Plugin service is served.
const ProtocolVersion = 1
ProtocolVersion is the plugin wire-contract version. Bump it on any breaking change to the proto or the manifest JSON shape; the host refuses a mismatch.
Variables ¶
var Handshake = goplugin.HandshakeConfig{ ProtocolVersion: ProtocolVersion, MagicCookieKey: "SHELLCN_PLUGIN", MagicCookieValue: "shellcn-plugin-handshake", }
Handshake is the magic-cookie handshake both ends share. It is not a security boundary — it only makes go-plugin refuse an unrelated executable with a clear error instead of a confusing protocol failure.
Functions ¶
func Bridge ¶
func Bridge(a, b io.ReadWriteCloser)
Bridge copies bytes both ways between two conns until either side ends, then closes both (closes are idempotent for brokered conns).
func DecodeManifest ¶
DecodeManifest reverses EncodeManifest. The returned routes carry no handlers.
func EncodeManifest ¶
EncodeManifest marshals a plugin's manifest and routes for the wire.
func ErrorFromStatus ¶
ErrorFromStatus maps a gRPC error back to the matching plugin sentinel so the host's error handling behaves as it does for a built-in plugin.
func NewConnBridge ¶
func NewConnBridge(target net.Conn) pluginv1.ConnServer
NewConnBridge serves a real conn over a brokered Conn.Pipe stream.
func NewHTTPProxyBridge ¶
func NewHTTPProxyBridge(baseURL string, rt http.RoundTripper) (pluginv1.ConnServer, error)
NewHTTPProxyBridge serves the core's L7 transport over a brokered conn: each brokered conn carries one HTTP connection, reverse-proxied to baseURL via rt (which injects auth, e.g. agent http_proxy).
func NewPipeServer ¶
NewPipeServer serves handle over a brokered Conn.Pipe (one call per conn).
func ServeConn ¶
func ServeConn(broker *goplugin.GRPCBroker, srv pluginv1.ConnServer) uint32
ServeConn registers srv on a fresh brokered id and returns it for the peer to Dial.
func StatusFromError ¶
StatusFromError maps a plugin sentinel to a gRPC status for the serve side.
Types ¶
type Client ¶
type Client struct {
Plugin pluginv1.PluginClient
Broker *goplugin.GRPCBroker
}
Client is what the host dispenses: the plugin client plus the broker used to serve the per-connection Host service and bridge target conns.
type GoPlugin ¶
type GoPlugin struct {
goplugin.NetRPCUnsupportedPlugin
Impl plugin.Plugin
}
GoPlugin bridges the ShellCN plugin contract to go-plugin's gRPC plugin. Impl is set on the serve (plugin) side only; the host uses GRPCClient.
func (*GoPlugin) GRPCClient ¶
func (g *GoPlugin) GRPCClient(_ context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (any, error)