Documentation
¶
Overview ¶
Package pluginapi defines the constants and handshake line format of the Kryspal Media plugin handshake, shared by the host and the SDK.
See PROTOCOL.md for the full specification. The gRPC services are defined in the subpackage v1 (pluginv1); Go plugin authors use the subpackage sdk. This package depends only on the standard library.
Index ¶
Constants ¶
const ( // EnvCookie must equal CookieValue; otherwise the plugin should refuse to start, because it was not started by the host. EnvCookie = "KRYSPAL_PLUGIN_COOKIE" // EnvProtocols holds the protocol major versions the host supports, as comma-separated decimal numbers, e.g. "1" or "1,2". EnvProtocols = "KRYSPAL_PLUGIN_PROTOCOLS" // EnvSocketDir is the 0700 directory the host created for this plugin; the plugin creates its Unix socket in it. EnvSocketDir = "KRYSPAL_PLUGIN_SOCKET_DIR" // EnvHostSocket and EnvHostToken are the Unix socket path and one-time token of the service the host offers to plugins // (Host, change 0103). They differ on every process start; older hosts do not set them, in which case the SDK's Host() // returns ErrHostUnavailable and the plugin should degrade gracefully. EnvHostSocket = "KRYSPAL_HOST_SOCKET" EnvHostToken = "KRYSPAL_HOST_TOKEN" )
Environment variables for the handshake. The host starts a plugin with a clean environment, passing only these three variables plus PATH, TMPDIR and HOME, and SSL_CERT_FILE and SSL_CERT_DIR when the host has them set.
const ( NetworkUnix = "unix" // NetworkTCP is reserved for future plugins that run over the network; the first host version does not accept it. NetworkTCP = "tcp" )
Network types in the handshake line.
const CookieValue = "7f3a9c52-kryspal-plugin"
CookieValue is the fixed magic value of EnvCookie. It is not a secret; it only keeps users from running a plugin directly.
const MaxHandshakeLine = 1024
MaxHandshakeLine is the maximum length in bytes of the handshake line (excluding the newline). The host treats a longer line as a failed handshake.
const SocketName = "plugin.sock"
SocketName is the socket file name the SDK creates in EnvSocketDir. Plugins in other languages may choose their own name, but the full path must not exceed the Unix socket limit (107 bytes on Linux).
Variables ¶
var ErrHandshake = errors.New("plugin handshake")
ErrHandshake reports a malformed handshake line or handshake environment variable.
Functions ¶
func FormatProtocols ¶
FormatProtocols formats a list of major versions as the value of EnvProtocols.
func NegotiateProtocol ¶
NegotiateProtocol returns the highest major version both sides support, or ErrHandshake when there is none.
func ParseProtocols ¶
ParseProtocols parses the value of EnvProtocols and returns the major versions sorted ascending without duplicates.
Types ¶
type Handshake ¶
type Handshake struct {
Protocol int // protocol major version chosen by the plugin
Network string // NetworkUnix or NetworkTCP
Address string // absolute socket path for unix; host:port for tcp
}
Handshake is the handshake line a plugin prints on stdout: <major version>|<network>|<address>.
func ParseHandshake ¶
ParseHandshake parses a handshake line (a trailing \n or \r\n is allowed). It checks only the format, not whether the host accepts the network and version.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
minimal
command
Command minimal is the smallest useful plugin: a movie metadata provider with no configuration that knows one title.
|
Command minimal is the smallest useful plugin: a movie metadata provider with no configuration that knows one title. |
|
static
command
Command static is the minimal example plugin: a metadata provider that returns fixed data (plus three demo services for images, subtitles and user sync, see services.go).
|
Command static is the minimal example plugin: a metadata provider that returns fixed data (plus three demo services for images, subtitles and user sync, see services.go). |
|
Package hanconv converts text between Simplified and Traditional Chinese with the dictionaries of OpenCC (Open Chinese Convert, Apache License 2.0; see NOTICE).
|
Package hanconv converts text between Simplified and Traditional Chinese with the dictionaries of OpenCC (Open Chinese Convert, Apache License 2.0; see NOTICE). |
|
Package i18n is a localization helper for plugin authors (change 0057): it picks a string table by the BCP 47 language tag the host sends, and when that language is missing it looks strings up along a fixed fallback chain that always ends in English.
|
Package i18n is a localization helper for plugin authors (change 0057): it picks a string table by the BCP 47 language tag the host sends, and when that language is missing it looks strings up along a fixed fallback chain that always ends in English. |
|
Package plugintest is the conformance suite for Kryspal Media plugins (change 0098 §4.4).
|
Package plugintest is the conformance suite for Kryspal Media plugins (change 0098 §4.4). |
|
Package pluginv1 holds the gRPC definitions of the Kryspal Media Plugin protocol v1 (generated from plugin.proto, metadata.proto, image.proto, subtitle.proto, usersync.proto, recognize.proto, segments.proto, danmaku.proto and host.proto) and the protocol constants.
|
Package pluginv1 holds the gRPC definitions of the Kryspal Media Plugin protocol v1 (generated from plugin.proto, metadata.proto, image.proto, subtitle.proto, usersync.proto, recognize.proto, segments.proto, danmaku.proto and host.proto) and the protocol constants. |
|
Package sdk is the Kryspal Media Plugin SDK for Go plugin authors: it performs the handshake, creates the Unix socket, starts the gRPC server (including the standard health check), and shuts down gracefully on SIGTERM.
|
Package sdk is the Kryspal Media Plugin SDK for Go plugin authors: it performs the handshake, creates the Unix socket, starts the gRPC server (including the standard health check), and shuts down gracefully on SIGTERM. |