- internal/agent: outbound WSS to core with SPKI pin checked inside the TLS handshake, Ed25519 challenge-response, one-shot join secret (dropped from memory and cli.env after the first ready), forwarding of core requests to the local awg-ctrl with an internal token, dead-connection timer on pings, backoff up to a minute (a minute after 4003) - path filter is stricter than the Node one where it relied on WHATWG URL normalisation: backslashes, a leading "//" and %2e dot segments are rejected - tests: end-to-end against a fake TLS core and a fake awg-ctrl; also checked by hand against the real awg-ui/nodes.ts hub - CI: Go build, vet and race tests on GitHub and Gitea
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// awg-control — единый бинарник Forgetting: роли ctrl / ui / agent и команды оператора.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/maeneko/forgetting/internal/agent"
|
|
"github.com/maeneko/forgetting/internal/ctrl"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
fmt.Fprintln(os.Stderr, "usage: awg-control <ctrl|ui|agent|start|stop|restart|status|…>")
|
|
os.Exit(1)
|
|
}
|
|
switch os.Args[1] {
|
|
case "ctrl":
|
|
s, err := ctrl.New()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
if err := s.Run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
case "agent":
|
|
c, err := agent.ConfigFromEnv()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
a, err := agent.New(c)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
a.Run(ctx)
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "awg-control: неизвестная команда %q\n", os.Args[1])
|
|
os.Exit(1)
|
|
}
|
|
}
|