mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 16:02:32 +00:00
Writing a plugin in Go means writing the vtables and const-pointer shims cgo cannot express, handle allocation, panic recovery, the two-pass get_last_error protocol and address encoding -- once per plugin, by hand. leaf-abi-go holds all of it once, so a plugin is a package that registers engines and implements them over byte slices: tls-cabi-go is 143 lines, trojan-cabi-go 321. ConnEngine is the other half. crypto/tls insists on a blocking net.Conn, which the ABI forbids an engine call from being, so it runs the implementation on goroutines over an in-memory pipe and reports BLOCKED with a wake while those are what it waits on. A codec needing none of that implements StreamEngine directly, as trojan does. The SDK revokes its host handle once Destroy returns, so a goroutine outliving its engine drops a log line rather than calling into memory the host has reclaimed, and it masks BLOCKED off when the host offered no wake callback. Register runs from Go's init and calls out to C; it cannot go the other way, since entering Go binds a thread to the Go runtime for good and the thread that loads a plugin is the host's. The descriptor declares that these plugins embed a language runtime, so the host never unmaps them.
8 lines
136 B
AMPL
8 lines
136 B
AMPL
module leaf-plugins/tls-cabi-go
|
|
|
|
go 1.26.0
|
|
|
|
require leaf-plugins/leaf-abi-go v0.0.0
|
|
|
|
replace leaf-plugins/leaf-abi-go => ../leaf-abi-go
|