wiretracetest

package
v0.165.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wiretracetest builds synthetic wire traces for tests: TL bodies are encoded with gotd and written with wiretrace.Writer, with the same summary fields the tdesktop tracer writes.

Index

Constants

View Source
const (
	MsgInit      uint64 = 0x6000000000000004
	MsgAck       uint64 = 0x6000000000000008
	MsgSignIn    uint64 = 0x600000000000000c
	MsgOutBox    uint64 = 0x6000000000000010
	MsgDelete    uint64 = 0x6000000000000014
	MsgAfter     uint64 = 0x6000000000000018
	MsgSend      uint64 = 0x600000000000001c
	MsgInBox     uint64 = 0x6000000000000001
	MsgInInit    uint64 = 0x6000000000000005
	MsgInSignIn  uint64 = 0x6000000000000009
	MsgInSession uint64 = 0x600000000000000d
	MsgInDelete  uint64 = 0x6000000000000011
	MsgInAfter   uint64 = 0x6000000000000015
	MsgInSend    uint64 = 0x6000000000000019
	MsgInUnknown uint64 = 0x600000000000001d
)

Message ids of Sample.

View Source
const (
	// UIKeyHex is the ui.key of UISample.
	UIKeyHex = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
	// UIUser is the user whose chat UISample opens.
	UIUser int64 = 5
	// UIChannel is the channel UISample restores at startup.
	UIChannel int64 = 7
	// UIMsgHistory is the msg_id of the getHistory message of UISample.
	UIMsgHistory uint64 = 0x6100000000000004
)

Ids of UISample.

View Source
const UnknownID uint32 = 0xdeadbeef

UnknownID is the unknown constructor id used by Sample.

Variables

This section is empty.

Functions

func CauseField

func CauseField(req int64, typ uint32) wiretrace.Field

CauseField returns the "cause" field of an event emitted while the response of req (0: an update) was handled.

func Container

func Container(items ...Item) []byte

Container builds msg_container#73f1f8dc of items.

func Encode

func Encode(t testing.TB, o bin.Encoder) []byte

Encode encodes a TL object.

func GZIP

func GZIP(t testing.TB, data []byte) []byte

GZIP builds gzip_packed#3072cfa1 packed_data:bytes.

func RPCResult

func RPCResult(reqMsgID uint64, result []byte) []byte

RPCResult builds rpc_result#f35c6d01 req_msg_id:long result:Object.

func Redact

func Redact(body []byte) []byte

Redact redacts body like the tdesktop tracer: the bytes after the constructor id become [marker][id][zeros...], keeping the length.

func Redact12

func Redact12(body []byte) []byte

Redact12 redacts the rpc_result result (after the 12-byte rpc_result header), as the tracer does for responses of sensitive requests.

func SchemaFiles

func SchemaFiles() []string

SchemaFiles returns the gotd schema files (_schema/telegram.tl and _schema/mt.tl) matching the tg and mt packages, for decoding traces built by this package.

func Stamp

func Stamp(a uint32, rel string, dt float64) wiretrace.Field

Stamp returns the "ui" field of an event emitted for action a.

func UIHeader

func UIHeader() []wiretrace.Field

UIHeader returns header fields with "ui" (P14) set.

Types

type Item

type Item struct {
	MsgID uint64
	SeqNo uint32
	Body  []byte
	// Method is the innermost method below wrappers (outgoing summary).
	Method uint32
	// Wrap are the wrapper ids (outgoing summary of top-level messages).
	Wrap []uint32
	// Redacted is the "redacted" summary list.
	Redacted []string
}

Item is one message: a top-level message or a container item.

type Trace

type Trace struct {
	Dir string
	W   *wiretrace.Writer

	// Now is the time of the next event, in seconds.
	Now float64
	// Step advances Now after each event.
	Step float64
	// SDC and Session are used for "msg" events.
	SDC     int
	Session int64
	// contains filtered or unexported fields
}

Trace writes a synthetic trace with deterministic time.

func New

func New(t testing.TB, opt wiretrace.WriterOptions) *Trace

New creates a trace in a new temporary directory.

func Sample

func Sample(t testing.TB) *Trace

Sample writes a synthetic session covering every decoder feature:

  • lifecycle events (conn.start, conn.up, key.set, session.new_id, state, salt.change, conn.reason, conn.restart, config.loaded)
  • an outgoing container of invokeWithLayer(initConnection( help.getNearestDc)), msgs_ack and a redacted auth.signIn
  • an incoming container of rpc_results (one redacted) and new_session_created
  • photos.deletePhotos answered by a top-level bare Vector<long>
  • invokeAfterMsg(help.getConfig) answered by a gzip_packed config
  • messages.sendMessage failing with FLOOD_WAIT_17
  • an update with an unknown constructor
  • request lifecycle (req.new, req.msg, req.caller after the message, req.done, req.fail), causes, storage events and a dropped record.

func UISample

func UISample(t testing.TB) *Trace

UISample writes a synthetic tdesktop session with UI events, following the examples of the P14 event schema:

  • marker #1 "start" (src file) and #3 (src key, labelled) at the end
  • a1, synthetic (src app): restore the last chat → getHistory (sync)
  • req 2 updates.getDifference: background
  • a41 click Dialogs::InnerWidget → ui.chat (deferred) → getHistory and getPeerSettings (deferred), getMessagesReactions (chain ⇐ req 310)
  • req 320 updates.getChannelDifference: update-driven
  • a57 click DocumentOpenClickHandler → media.open document → upload.getFile (deferred) ×1 + ×2 (chain); a70 Escape → media.close
  • a58 scroll up HistoryWidget ×14 → getHistory ×3 (sync); then account.updateStatus (after, dt 1288)
  • a59 typing, a60 Enter → messages.sendMessage (sync)
  • a61 shortcut search, a62 menu pin → messages.updatePinnedMessage (sync)
  • a63 double click, a64 Down with 5 auto-repeats (ui.key.end), a65 Ctrl+K to a QShortcut (ui.key via shortcut, written when the scope ends, after its sync request), a66 tap in a non-main window (no "w")
  • a67 click that opens a modal file dialog: messages.sendMedia inside the nested loop ("after", dt 4200 from the scope open)
  • layer box, group call, session and account records
  • app.state idle, then req 380 account.updateStatus: background

The record shapes follow the tdesktop emitter (branch trace-ui). Peer ids are hashed with UIKeyHex, which is written as ui.key (64 lowercase hex chars and a newline).

func (*Trace) At

func (tr *Trace) At(t float64) *Trace

At sets the time of the next event.

func (*Trace) Click

func (tr *Trace) Click(a uint32, ms float64, path []string, extra ...wiretrace.Field)

Click writes ui.press and ui.click of action a on window 0, ms apart.

func (*Trace) Close

func (tr *Trace) Close()

Close flushes and closes the writer.

func (*Trace) Event

func (tr *Trace) Event(thread, kind string, sdc int, fields ...wiretrace.Field) uint64

Event writes a generic event with dc fields for sdc (if not negative).

func (*Trace) In

func (tr *Trace) In(it Item) uint64

In writes an incoming top-level message.

func (*Trace) InContainer

func (tr *Trace) InContainer(msgID uint64, seqNo uint32, items ...Item) uint64

InContainer writes an incoming msg_container of items.

func (*Trace) Marker

func (tr *Trace) Marker(n int, src, label string) uint64

Marker writes a ui.marker.

func (*Trace) Out

func (tr *Trace) Out(it Item) uint64

Out writes an outgoing top-level message.

func (*Trace) OutContainer

func (tr *Trace) OutContainer(msgID uint64, seqNo uint32, items ...Item) uint64

OutContainer writes an outgoing msg_container of items.

func (*Trace) ReqDone

func (tr *Trace) ReqDone(req int64, method, typ uint32, latMS float64, length int) uint64

ReqDone writes req.done of req.

func (*Trace) ReqNew

func (tr *Trace) ReqNew(req int64, typ uint32, extra ...wiretrace.Field) uint64

ReqNew writes a main-thread req.new of method typ.

func (*Trace) UI

func (tr *Trace) UI(kind string, fields ...wiretrace.Field) uint64

UI writes a UI record on the main thread.

func (*Trace) WriteUIKey

func (tr *Trace) WriteUIKey(key []byte)

WriteUIKey writes key (32 bytes) as the hex ui.key of the run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL