1syntax = "proto3"; 2 3package pb; 4 5// Version of schema 6message Version { 7 uint32 version = 1; 8} 9// ResultCounter is a monotonically increasing counter that reports an ok/err breakdown of the total. 10message ResultCounter { 11 uint32 total = 1; 12 uint32 ok = 2; 13 uint32 err = 3; 14} 15 16// Moving totals over sliding time windows. Models sensible time windows, 17// we don't have to populate them all at once. 18// 19// Graphical example: 20// 21// time past -> present an event 16 min ago 22// ======================================================X================>> 23// | | 1m 24// | |---| 5m 25// | |-------------| 15m 26// |------------X---------------| 30m 27// |------------------------------------------X---------------| 60m 28message SlidingCounter { 29 uint32 over_1m = 1; 30 uint32 over_5m = 2; 31 uint32 over_15m = 3; 32 uint32 over_30m = 4; 33 uint32 over_1hr = 5; 34 uint32 over_2hr = 6; 35 uint32 over_4hr = 7; 36 uint32 over_8hr = 8; 37 uint32 over_12hr = 9; 38 uint32 over_24hr = 10; 39} 40 41// DataGauge reports stats for data traffic in a given direction. 42message DataGauge { 43 // Cumulative bytes. 44 uint64 cum_bytes = 1; 45 // Cumulative packets. 46 uint64 cum_packets = 2; 47 // Instantaneous bandwidth measurement (bytes/second). 48 uint64 inst_bw = 3; 49} 50 51// describes a type of event 52message EventType { 53 // metadata about content types in event's top-level content JSON 54 message EventProperty { 55 // tells client how to sort, filter or display known content properties 56 enum PropertyType { 57 // for properties to treat as a simple primitive 58 STRING = 0; // default 59 NUMBER = 1; 60 // for properties with special human-readable formatting 61 TIME = 10; 62 PEERID = 11; 63 MULTIADDR = 12; 64 // for complex structures like nested arrays, object trees etc 65 JSON = 90; 66 } 67 // property name of content e.g. openTs 68 string name = 1; 69 // type to interpret content value as 70 PropertyType type = 2; 71 // if true, expect an array of values of `type`; else, singular 72 bool has_multiple = 3; 73 } 74 75 // name of event type, e.g. PeerConnecting 76 string name = 1; 77 // for runtime, send property_types for all events already seen in events list 78 // for events, only send property_types in the first event of a type not in runtime 79 repeated EventProperty property_types = 2; 80} 81 82// Runtime encapsulates runtime info about a node. 83message Runtime { 84 // e.g. go-libp2p, js-libp2p, rust-libp2p, etc. 85 string implementation = 1; 86 // e.g. 1.2.3. 87 string version = 2; 88 // e.g. Windows, Unix, macOS, Chrome, Mozilla, etc. 89 string platform = 3; 90 // our peer id - the peer id of the host system 91 string peer_id = 4; 92 // metadata describing configured event types 93 repeated EventType event_types = 7; 94} 95 96// EndpointPair is a pair of multiaddrs. 97message EndpointPair { 98 // the source multiaddr. 99 string src_multiaddr = 1; 100 // the destination multiaddr. 101 string dst_multiaddr = 2; 102} 103 104// The status of a connection or stream. 105enum Status { 106 ACTIVE = 0; 107 CLOSED = 1; 108 OPENING = 2; 109 CLOSING = 3; 110 ERROR = 4; 111} 112 113// Our role in a connection or stream. 114enum Role { 115 INITIATOR = 0; 116 RESPONDER = 1; 117} 118 119// Traffic encloses data transfer statistics. 120message Traffic { 121 // snapshot of the data in metrics. 122 DataGauge traffic_in = 1; 123 // snapshot of the data out metrics. 124 DataGauge traffic_out = 2; 125} 126 127// a list of streams, by reference or inlined. 128message StreamList { 129 // NOTE: only one of the next 2 fields can appear, but proto3 130 // doesn't support combining oneof and repeated. 131 // 132 // streams within this connection by reference. 133 repeated bytes stream_ids = 1; 134 // streams within this connection by inlining. 135 repeated Stream streams = 2; 136} 137 138// Connection reports metrics and state of a libp2p connection. 139message Connection { 140 // Timeline contains the timestamps (ms since epoch) of the well-known milestones of a connection. 141 message Timeline { 142 // the instant when a connection was opened on the wire. 143 uint64 open_ts = 1; 144 // the instant when the upgrade process (handshake, security, multiplexing) finished. 145 uint64 upgraded_ts = 2; 146 // the instant when this connection was terminated. 147 uint64 close_ts = 3; 148 } 149 150 // Attributes encapsulates the attributes of this connection. 151 message Attributes { 152 // the multiplexer being used. 153 string multiplexer = 1; 154 // the encryption method being used. 155 string encryption = 2; 156 } 157 158 // the id of this connection, not to be shown in user tooling, 159 // used for (cross)referencing connections (e.g. relay). 160 bytes id = 1; 161 // the peer id of the other party. 162 string peer_id = 2; 163 // the status of this connection. 164 Status status = 3; 165 // a reference to the transport managing this connection. 166 bytes transport_id = 4; 167 // the endpoints participating in this connection. 168 EndpointPair endpoints = 5; 169 // the timeline of the connection, see Connection.Timeline. 170 Timeline timeline = 6; 171 // our role in this connection. 172 Role role = 7; 173 // traffic statistics. 174 Traffic traffic = 8; 175 // properties of this connection. 176 Attributes attribs = 9; 177 // the instantaneous latency of this connection in nanoseconds. 178 uint64 latency_ns = 10; 179 // streams within this connection. 180 StreamList streams = 11; 181 182 reserved 12 to 15; 183 184 // if this is a relayed connection, this points to the relaying connection. 185 // a default value here (empty bytes) indicates this is not a relayed connection. 186 oneof relayed_over { 187 bytes conn_id = 16; 188 Connection conn = 17; 189 } 190 // user provided tags. 191 repeated string user_provided_tags = 99; 192} 193 194// Stream reports metrics and state of a libp2p stream. 195message Stream { 196 message ConnectionRef { 197 oneof connection { 198 // the parent connection inlined. 199 Connection conn = 1; 200 // the parent connection by reference. 201 bytes conn_id = 2; 202 } 203 } 204 205 // Timeline contains the timestamps (ms since epoch) of the well-known milestones of a stream. 206 message Timeline { 207 // the instant when the stream was opened. 208 uint64 open_ts = 1; 209 // the instant when the stream was terminated. 210 uint64 close_ts = 2; 211 } 212 213 // the id of this stream, not to be shown in user tooling, 214 // used for (cross)referencing streams. 215 bytes id = 1; 216 // the protocol pinned to this stream. 217 string protocol = 2; 218 // our role in this stream. 219 Role role = 3; 220 // traffic statistics. 221 Traffic traffic = 4; 222 // the connection this stream is hosted under. 223 ConnectionRef conn = 5; 224 // the timeline of the stream, see Stream.Timeline. 225 Timeline timeline = 6; 226 // the status of this stream. 227 Status status = 7; 228 229 // the instantaneous latency of this stream in nanoseconds. 230 // TODO: this is hard to calculate. 231 uint64 latency_ns = 16; 232 // user provided tags. 233 repeated string user_provided_tags = 99; 234} 235 236// DHT metrics and state. 237message DHT { 238 message Params { 239 // routing table bucket size. 240 uint64 k = 1; 241 // concurrency of asynchronous requests. 242 uint64 alpha = 2; 243 // number of disjoint paths to use. 244 uint64 disjoint_paths = 3; 245 // number of peers closest to a target that must have responded 246 // in order for a given query path to complete 247 uint64 beta = 4; 248 } 249 250 // Peer in DHT 251 message PeerInDHT { 252 // The DHT's relationship with this peer 253 enum Status { 254 // Connected, in a bucket, ready to send/receive queries 255 ACTIVE = 0; 256 // Not currently connected, still "in" a bucket (e.g. temporarily disconnected) 257 MISSING = 1; 258 // Removed from a bucket or candidate list (e.g. connection lost or too slow) 259 REJECTED = 2; 260 // Was reachable when last checked, waiting to join a currently-full bucket 261 CANDIDATE = 3; 262 } 263 // the peer id of the host system 264 string peer_id = 1; 265 // the peer's status when data snapshot is taken 266 Status status = 2; 267 // age in bucket (ms) 268 uint32 age_in_bucket = 3; 269 } 270 271 // A "k-bucket" containing peers of a certain kadamelia distance 272 message Bucket { 273 // CPL (Common Prefix Length) is the length of the common prefix 274 // between the ids of every peer in this bucket and the DHT peer id 275 uint32 cpl = 1; 276 // Peers associated with this bucket 277 repeated PeerInDHT peers = 2; 278 // Bucket may need more fields depending on WIP remodeling 279 } 280 281 // Counters of query events, by status 282 message QueryGauge { 283 // Cumulative counter of queries with "SUCCESS" status 284 uint64 success = 1; 285 // Cumulative counter of queries with "ERROR" status 286 uint64 error = 2; 287 // Cumulative counter of queries with "TIMEOUT" status 288 uint64 timeout = 3; 289 } 290 291 // DHT protocol name 292 string protocol = 1; 293 // protocol enabled. 294 bool enabled = 2; 295 // timestamp (ms since epoch) of start up. 296 uint64 start_ts = 3; 297 // params of the dht. 298 Params params = 4; 299 // existing, intantiated buckets and their contents 300 repeated Bucket buckets = 5; 301 // counts inbound queries received from other peers 302 QueryGauge incoming_queries = 6; 303 // counts outbound queries dispatched by this peer 304 QueryGauge outgoing_queries = 7; 305} 306 307// Subsystems encapsulates all instrumented subsystems for a libp2p host. 308message Subsystems { 309 // connections data, source agnostic but currently only supports the Swarm subsystem 310 repeated Connection connections = 1; 311 // the DHT subsystem. 312 DHT dht = 2; 313} 314 315// Connections and streams output for a time interval is one of these. 316message State { 317 // list of connections 318 Subsystems subsystems = 1; 319 // overall traffic for this peer 320 Traffic traffic = 2; 321 // moment this data snapshot and instantaneous values were taken 322 uint64 instant_ts = 3; 323 // start of included data collection (cumulative values counted from here) 324 uint64 start_ts = 4; 325 // length of time up to instant_ts covered by this data snapshot 326 uint32 snapshot_duration_ms = 5; 327} 328 329// Event 330message Event { 331 // definition of event type, containing only `name` unless this is first encounter of novel event 332 EventType type = 1; 333 // time this event occurred (ms since epoch) 334 uint64 ts = 2; 335 // stringified json; top-level keys and value types match EventProperty definitions 336 string content = 3; 337} 338 339// ServerMessage wraps messages to be sent to clients to allow extension 340// based on new types of data sources 341message ServerMessage { 342 // Version of this protobuf. 343 Version version = 1; 344 // The payload this message contains. 345 oneof payload { 346 State state = 2; 347 Runtime runtime = 3; 348 Event event = 4; 349 350 CommandResponse response = 5; 351 ServerNotice notice = 6; 352 } 353} 354 355// Configuration encapsulates configuration fields for the protocol and commands. 356message Configuration { 357 uint64 retention_period_ms = 1; 358 uint64 state_snapshot_interval_ms = 2; 359} 360 361// ClientCommand is a command sent from the client to the server. 362message ClientCommand { 363 enum Source { 364 STATE = 0; // full state snapshot. 365 RUNTIME = 1; // runtime data message. 366 EVENTS = 2; // eventbus events. 367 } 368 369 enum Command { 370 // HELLO is the first command that a client must send to greet the server. 371 // Connections that do not respect this invariant will be terminated. 372 HELLO = 0; 373 374 // REQUEST is applicable to STATE and RUNTIME sources. 375 REQUEST = 1; 376 377 // PUSH streams can only be started for STATE and EVENTS sources. 378 PUSH_ENABLE = 2; // enables pushing for a given source. 379 PUSH_DISABLE = 3; // disables pushing for a given source. 380 PUSH_PAUSE = 4; // pauses pushing for all sources. 381 PUSH_RESUME = 5; // resumes pushing for all sources. 382 383 // UPDATE_CONFIG requests a configuration update. The config field is 384 // compulsory. 385 // 386 // The server reserves the right to override the requested values, and 387 // will return the effective configuration in the response. 388 UPDATE_CONFIG = 7; 389 } 390 391 Version version = 1; 392 uint64 id = 2; // a unique ID for this request. 393 Command command = 3; 394 Source source = 4; 395 Configuration config = 5; 396} 397 398// CommandResponse is a response to a command sent by the client. 399message CommandResponse { 400 enum Result { 401 OK = 0; 402 ERR = 1; 403 } 404 405 uint64 id = 1; // for correlation with the request. 406 Result result = 2; 407 string error = 3; 408 409 // effective_config is the effective configuration the server holds for 410 // this connection. It is returned in response to HELLO and UPDATE_CONFIG 411 // commands. 412 Configuration effective_config = 4; 413} 414 415// ServerNotice represents a NOTICE sent from the server to the client. 416message ServerNotice { 417 enum Kind { 418 DISCARDING_EVENTS = 0; 419 } 420 Kind kind = 1; 421}