grpcplugin

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

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

View Source
const PluginName = "plugin"

PluginName is the dispense key under which the Plugin service is served.

View Source
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

View Source
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

func DecodeManifest(data []byte) (plugin.Manifest, []plugin.Route, error)

DecodeManifest reverses EncodeManifest. The returned routes carry no handlers.

func DialConn

func DialConn(broker *goplugin.GRPCBroker, id uint32) (net.Conn, error)

DialConn dials a brokered Conn served under id and presents it as a net.Conn.

func EncodeManifest

func EncodeManifest(m plugin.Manifest, routes []plugin.Route) ([]byte, error)

EncodeManifest marshals a plugin's manifest and routes for the wire.

func ErrorFromStatus

func ErrorFromStatus(err error) error

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

func NewPipeServer(handle func(ctx context.Context, conn net.Conn) error) pluginv1.ConnServer

NewPipeServer serves handle over a brokered Conn.Pipe (one call per conn).

func Plugins

func Plugins(impl plugin.Plugin) goplugin.PluginSet

Plugins is the go-plugin set served and consumed under PluginName.

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

func StatusFromError(err error) error

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)

func (*GoPlugin) GRPCServer

func (g *GoPlugin) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL