Files
piik/internal/server/route/debug.go
T
AAA 1332473513 feat: rename product and runtime to Piik
Rename the active product, Go module, binaries, configuration, protocols and documentation to Piik while retaining the TV mascot and existing media/room behavior.

Use one current private contract without old-name aliases. Preserve SQLite authority and copy compatible local settings once; other settings start fresh. Git-message cleanup and the infrastructure name cutover are coordinated with this phase, with original history and deployment data archived externally.

Validated locally with Web and Go checks, Windows capture compilation, matched Client/Server builds, packaged Client control handshake and history-rewrite integrity checks. Skip duplicate hosted CI for this owner-authorized local release.

[skip ci]
2026-09-10 11:10:12 +08:00

73 lines
1.9 KiB
Go

package route
import (
"context"
"log/slog"
"os"
"strconv"
"strings"
"github.com/TNTcraftHIM/Piik/internal/server/protocol"
)
func debugEnabled() bool {
return routeDebugEnabled(os.Getenv("PIIK_DEBUG")) ||
slog.Default().Enabled(context.Background(), slog.LevelDebug)
}
func routeDebugEnabled(value string) bool {
for _, section := range strings.Split(value, ",") {
if strings.TrimSpace(section) == "route" {
return true
}
}
return false
}
// debugCandidate is the `{route, transition}` item of "operation-started".
type debugCandidate struct {
Route string
Transition TransitionKind
}
// debug emits one sanitized event with a diagnostic room ID and current facts.
// Never pass raw peer IDs, session IDs or connection IDs; use debugPeer and
// debugTuple. The environment or diagnostic logger enables these Info events.
func (c *Controller) debug(event string, details ...any) {
if !debugEnabled() || c.debugRoomID == "" {
return
}
args := make([]any, 0, 8+len(details))
args = append(args,
"event", event,
"roomId", c.debugRoomID,
"revision", c.revision,
"factVersion", c.factVersion)
args = append(args, details...)
slog.Info("piik-route", args...)
}
// debugPeer ports 4895: "host", "viewer-<joinOrder>" or "viewer-unknown".
func (c *Controller) debugPeer(peerID string) string {
current, _ := c.participants.Get(peerID)
if peerID == c.hostPeerID || (current != nil && current.role == protocol.RoleHost) {
return "host"
}
if current == nil {
return "viewer-unknown"
}
return "viewer-" + strconv.FormatInt(current.joinOrder, 10)
}
// debugTuple ports 4903: "p2p:<label>[:regenerate]" or "sfu:<publication>".
func (c *Controller) debugTuple(tuple CandidateTuple) string {
if tuple.Kind == UpstreamPeer {
label := "p2p:" + c.debugPeer(tuple.ParentPeerID)
if tuple.Regenerate {
label += ":regenerate"
}
return label
}
return "sfu:" + string(tuple.Publication)
}