Documentation
¶
Overview ¶
Package services holds the ipc services shared by the duplex examples (examples/duplex on the desktop, examples/duplex-mobile on iOS).
Index ¶
- Constants
- Variables
- func BenchRoute(next http.Handler) http.Handler
- func CountMessage(m string)
- func CountUp(p []byte)
- func Register(r *ipc.Router)
- func RegisterSelftestReport(r *ipc.Router, report func(kind, result string))
- func SelftestRoute(next http.Handler) http.Handler
- func SetBenchDone(fn func())
- func TestRoutes(next http.Handler) http.Handler
- type Sample
- type Stats
Constants ¶
const CSPBlocked = "default-src 'self' 'unsafe-inline'; connect-src https://example.invalid"
CSPBlocked is the Content-Security-Policy of /csp.html: the page's own scripts and inline styles run, but fetch may only reach a host that does not exist, so no request to the asset origin (lanes included) is allowed.
Variables ¶
var Probe = sync.OnceValue(func() bool { return os.Getenv("TANGO_SCHEME_PROBE") == "1" })
Probe reports whether the test hooks are on (TANGO_SCHEME_PROBE=1).
var TraceEnabled = sync.OnceValue(downq.TraceEnabled)
TraceEnabled reports whether the development pipeline trace is requested.
Functions ¶
func BenchRoute ¶
BenchRoute returns next with GET /bench.js, the benchmark script that examples/duplex and examples/duplex-mobile share, in front of it.
func CountMessage ¶
func CountMessage(m string)
CountMessage counts m in Debug.Stats if it is a runtime hello. The duplex examples call it from OnMessage; it does nothing unless the test hooks are on.
func CountUp ¶
func CountUp(p []byte)
CountUp counts an upstream fast lane packet in Debug.Stats. The duplex examples call it from OnBinary before handing p to the router; it does nothing unless the test hooks are on.
func Register ¶
Register registers the platform-independent services of the duplex examples on r. examples/duplex adds its local shell ("Term") on top; examples/duplex-mobile uses these as they are:
- "Echo" (duplex): writes back every frame as received, JSON or bytes.
- "Upload" (duplex, [name, size]): byte frames go to a temporary file; {"received":n} every further MiB, {"path":p,"bytes":n} after the end.
- "Sink" (duplex): reads every frame, then replies {"bytes":n}.
- "Source" (stream, [frames, size, mod?, add?]): writes frames byte frames of size bytes each. Without mod every frame holds byte(i) at offset i; with mod > 0, byte j of the whole stream (counted across frames) is (j + add) % mod.
- "SourceJSON" (stream, [frames]): writes frames JSON frames of about 2.3 KB each, shaped like MinCode's AI / database chunks (jsonChunk).
- "Bench.Report" (call): prints its argument as one JSON line on stdout.
- "Debug.Stats" (call), only with TANGO_SCHEME_PROBE=1: Go-side counters for the platform tests (Stats, testroutes.go).
- "Debug.Sample" [ms, stepMs] and "Debug.Samples" (calls), only with TANGO_SCHEME_PROBE=1: sample goroutines and open poll requests in the background (testroutes.go), across page reloads.
func RegisterSelftestReport ¶
RegisterSelftestReport forwards the page's result as compact JSON.
func SelftestRoute ¶
SelftestRoute serves the script shared by the two duplex examples.
func SetBenchDone ¶
func SetBenchDone(fn func())
SetBenchDone sets the function Bench.Report runs after printing its line.
func TestRoutes ¶
TestRoutes returns next unchanged unless the test hooks are on; then it adds, in front of next:
- GET /__test/big: 3 MiB, byte i = i % 251, application/octet-stream, with Content-Length (http.ServeContent).
- GET /__test/redirect: 302 to /index.html (the core follows it).
- POST /__test/echo: the request body back, application/octet-stream.
- GET /__test/panic: the handler panics before writing anything.
- GET /__test/stream: never ends on its own: a 1 KiB chunk every 50 ms, flushed, until the request context is done; each return counts in Debug.Stats' handlerExits.
- GET /__test/lanetests.js: the IPC fast lane scenarios (lanetests.js, window.laneTests) shared by the macOS lane tests and the iOS self-test.
- GET /csp.html: the app's index.html under CSPBlocked.
Types ¶
type Sample ¶
type Sample struct {
At int64 `json:"at"` // wall clock, Unix ms
Goroutines int `json:"goroutines"`
DownOpen int64 `json:"downOpen"`
}
Sample is one Debug.Sample measurement.
type Stats ¶
type Stats struct {
// Goroutines is runtime.NumGoroutine() at the time of the call.
Goroutines int `json:"goroutines"`
// HandlerExits counts returns of the /__test/stream handler (the
// request context ended, i.e. the backend cancelled the request).
HandlerExits int64 `json:"handlerExits"`
// Hellos counts runtime hellos that reached the app's OnMessage
// (CountMessage).
Hellos int64 `json:"hellos"`
// UpPackets, UpFrames and UpBytes count the fast lane packets that
// reached the app's OnBinary, their frames and the frames' payload bytes
// (CountUp).
UpPackets int64 `json:"upPackets"`
UpFrames int64 `json:"upFrames"`
UpBytes int64 `json:"upBytes"`
// The backend's scheme handler counters (darwin.LaneDownStats,
// ios.LaneDownStats; zero on other platforms, and on macOS in builds
// without -tags tango_dev): lane requests it saw and
// how they were answered.
DownRequests int64 `json:"downRequests"` // GET /__tango/lane/poll (macOS; /__tango/lane/down on iOS)
DownConns int64 `json:"downConns"` // of them answered 200
DownActive int64 `json:"downActive"` // answered 200 and still open
DownWrites int64 `json:"downWrites"` // data blocks handed to WebKit on those answered 200
DownRefused int64 `json:"downRefused"` // of them answered 403 (macOS only)
DownOpen int64 `json:"downOpen"` // of them not finished yet, held ones included (macOS only)
DownResponseNanos int64 `json:"downResponseNanos,omitempty"`
DownDataNanos int64 `json:"downDataNanos,omitempty"`
DownFinishNanos int64 `json:"downFinishNanos,omitempty"`
DownDataCalls int64 `json:"downDataCalls,omitempty"`
UpRequests int64 `json:"upRequests"` // POST /__tango/lane/up
UpAccepted int64 `json:"upAccepted"` // of them answered 2xx
UpActive int64 `json:"upActive"` // started and not yet finished or stopped
// Main-thread time the macOS scheme handler spent on up requests
// before their handler goroutine started (summed, largest), and their
// body bytes; zero on iOS and elsewhere.
UpMainNanos int64 `json:"upMainNanos"`
UpMainMaxNanos int64 `json:"upMainMaxNanos"`
UpBodyBytes int64 `json:"upBodyBytes"`
// The Android lane counters (android.LaneStatsSnapshot, tango_dev and
// tango_selftest builds; zero elsewhere). On Android upRequests,
// upAccepted and downWrites above are filled from them too
// (lanestats_android.go).
LaneUpProbes int64 `json:"laneUpProbes"` // valid probes
LaneUpBadToken int64 `json:"laneUpBadToken"` // dropped: token or origin mismatch
LaneUpRefused int64 `json:"laneUpRefused"` // refused by the core (answered [1])
LaneDownDropped int64 `json:"laneDownDropped"` // down packets dropped (other generation, no proxy)
LaneDownQueued int64 `json:"laneDownQueued"` // down packets queued now
// IpcTraceEnabled is true only for a tango_dev run with TANGO_IPC_TRACE=1.
IpcTraceEnabled bool `json:"ipcTraceEnabled,omitempty"`
IpcTrace []downq.TraceBatch `json:"ipcTrace,omitempty"`
}
Stats is the result of Debug.Stats. Later counters are added as fields; the page reads them by name.