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
- func CauseField(req int64, typ uint32) wiretrace.Field
- func Container(items ...Item) []byte
- func Encode(t testing.TB, o bin.Encoder) []byte
- func GZIP(t testing.TB, data []byte) []byte
- func RPCResult(reqMsgID uint64, result []byte) []byte
- func Redact(body []byte) []byte
- func Redact12(body []byte) []byte
- func SchemaFiles() []string
- func Stamp(a uint32, rel string, dt float64) wiretrace.Field
- func UIHeader() []wiretrace.Field
- type Item
- type Trace
- func (tr *Trace) At(t float64) *Trace
- func (tr *Trace) Click(a uint32, ms float64, path []string, extra ...wiretrace.Field)
- func (tr *Trace) Close()
- func (tr *Trace) Event(thread, kind string, sdc int, fields ...wiretrace.Field) uint64
- func (tr *Trace) In(it Item) uint64
- func (tr *Trace) InContainer(msgID uint64, seqNo uint32, items ...Item) uint64
- func (tr *Trace) Marker(n int, src, label string) uint64
- func (tr *Trace) Out(it Item) uint64
- func (tr *Trace) OutContainer(msgID uint64, seqNo uint32, items ...Item) uint64
- func (tr *Trace) ReqDone(req int64, method, typ uint32, latMS float64, length int) uint64
- func (tr *Trace) ReqNew(req int64, typ uint32, extra ...wiretrace.Field) uint64
- func (tr *Trace) UI(kind string, fields ...wiretrace.Field) uint64
- func (tr *Trace) WriteUIKey(key []byte)
Constants ¶
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.
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.
const UnknownID uint32 = 0xdeadbeef
UnknownID is the unknown constructor id used by Sample.
Variables ¶
This section is empty.
Functions ¶
func CauseField ¶
CauseField returns the "cause" field of an event emitted while the response of req (0: an update) was handled.
func Redact ¶
Redact redacts body like the tdesktop tracer: the bytes after the constructor id become [marker][id][zeros...], keeping the length.
func Redact12 ¶
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.
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 ¶
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 ¶
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) InContainer ¶
InContainer writes an incoming msg_container of items.
func (*Trace) OutContainer ¶
OutContainer writes an outgoing msg_container of items.
func (*Trace) WriteUIKey ¶
WriteUIKey writes key (32 bytes) as the hex ui.key of the run.