Files
Wireguard-tools.js/wg_addon/addon.go
Matheus Sampaio Queiroga 61dcda8662
Some checks failed
Test / Test Linux (latest) (pull_request) Failing after 1m55s
Test / Test Linux (20.x) (pull_request) Failing after 1m58s
Test / Test Linux (21.x) (pull_request) Failing after 1m55s
Test / Test Linux (18.x) (pull_request) Failing after 1m57s
Refactor: Simplify wgctrl funcs & update napi-go
Change SetInterface and GetInterface to standard Go functions,
removing direct NAPI handling and async logic from wgctrl.go.

Use napi.GoFuncOf for function registration in addon.go.
Update napi-go dependency to v0.1.2 pre-release.
2025-04-28 19:28:10 -03:00

56 lines
1.5 KiB
Go

package wg_addon
import (
"net"
"net/netip"
"time"
_ "unsafe"
"sirherobrine23.com.br/Sirherobrine23/napi-go"
_ "sirherobrine23.com.br/Sirherobrine23/napi-go/entry"
)
//go:linkname wg sirherobrine23.com.br/Sirherobrine23/napi-go/entry.Register
func wg(env napi.EnvType, export *napi.Object) {
getConfig, err := napi.GoFuncOf(env, GetInterface)
if err != nil {
panic(err)
}
export.Set("getConfig", getConfig)
setConfig, err := napi.GoFuncOf(env, SetInterface)
if err != nil {
panic(err)
}
export.Set("setConfig", setConfig)
// deleteInterface, _ := napi.CreateFunction(env, "deleteInterface", DeleteInterface)
// export.Set("deleteInterface", deleteInterface)
}
// Peer info
type Peer struct {
PresharedKey string `napi:"presharedKey"`
KeepInterval int `napi:"keepInterval"`
Endpoint string `napi:"endpoint"`
AllowedIPs []net.IPNet `napi:"allowedIPs"`
RemoveMe bool `napi:"removeMe"`
RxByte int `napi:"rxBytes"`
TxByte int `napi:"txBytes"`
LastHandshake time.Time `napi:"lastHandshake"`
}
// Wireguard interface configs
type Config struct {
Name string `napi:"name"`
PrivateKey string `napi:"privateKey"`
PublicKey string `napi:"publicKey"`
PortListen int `napi:"portListen"`
Fwmark int `napi:"fwmark"`
ReplacePeers bool `napi:"replacePeers"`
Address []netip.Addr `napi:"address"`
Peers map[string]*Peer `napi:"peers"`
}