package route import ( "strconv" "github.com/TNTcraftHIM/Piik/internal/server/protocol" ) // debugCandidate is the `{route, transition}` item of "operation-started". type debugCandidate struct { Route string Transition TransitionKind } func (c *Controller) debugEnabled() bool { return c.debugLog != nil && c.debugRoomID != "" } // 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 effect layer injects the sink and owns its enabling policy. func (c *Controller) debug(event string, details ...any) { if !c.debugEnabled() { 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...) c.debugLog("piik-route", args...) } func (c *Controller) debugOperation(event string, op *operation, nowMs *int64, details ...any) { if !c.debugEnabled() { return } fields := []any{"child", c.debugPeer(op.childPeerID), "operationReason", op.reason, "cursor", op.cursor, "candidateCount", len(op.candidates)} if nowMs != nil { fields = append(fields, "remainingMs", op.deadlineAtMs-*nowMs) } if att := op.current; att != nil { fields = append(fields, "candidate", c.debugTuple(att.tuple), "candidateRevision", att.revision, "transportConnected", att.transportConnected) if nowMs != nil { fields = append(fields, "elapsedMs", *nowMs-att.startedAtMs) } } c.debug(event, append(fields, details...)...) } // debugPeer returns "host", "viewer-" 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 returns "p2p: