protocol

package module
v0.0.0-...-b9240f0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

NetTact

NetTact Protocol

English | 简体中文

NetTact Protocol defines the shared data model and wire contract between the Agent, Server, and Desktop. It gives collectors, servers, and embedded runtimes one set of Go types so the same field cannot acquire different meanings in different repositories.

This is a Go library, not an executable service, and does not need to be deployed separately. Most NetTact users consume it indirectly through the Agent, NetTact Server, or Desktop.

What It Solves

  • Shared types for telemetry, events, inventory, configuration delivery, permissions, and enrollment
  • Message frames, acknowledgements, and error semantics for the persistent Agent connection
  • Human-readable JSON and bandwidth-efficient Protobuf encodings
  • Idempotent uploads and disconnection recovery through sequence numbers and acknowledgement watermarks
  • Explicit schema validation that fails early when components are incompatible
  • Standard-library-only core type packages; Protobuf is pulled in only by the optional wire package

Packages

Package Purpose
telemetry Metrics, events, interface snapshots, inventory, incident evidence, and upload packets
config Probe targets, schedules, egress proxies, game collection, and diagnostic requests sent from Server to Agent
enroll Requests, signatures, and credentials used during initial Agent enrollment
permission Capability catalog, local grant policy, and permission reports
gamesense Game runs, frame-time buckets, collection gaps, and host-level per-second data
wire WebSocket frames, JSON/Protobuf codecs, links, and pipe abstractions
wire/pb Generated Go code from the Protobuf schema

Installation

go get github.com/nettact/protocol@latest

Import only the type packages you need:

import (
    "github.com/nettact/protocol/config"
    "github.com/nettact/protocol/permission"
    "github.com/nettact/protocol/telemetry"
)

Import wire only when you need JSON/Protobuf encoding or an Agent transport. Consumers of the core types do not pull in the Protobuf runtime.

Encoding Example

package main

import (
    "fmt"
    "time"

    "github.com/nettact/protocol"
    "github.com/nettact/protocol/telemetry"
    "github.com/nettact/protocol/wire"
)

func main() {
    packet := telemetry.Packet{
        SchemaVersion: protocol.SchemaVersion,
        AgentID:       "agent-01",
        SiteID:        "default",
        Sequence:      42,
        SentAt:        time.Now().UTC(),
        Metrics: []telemetry.Metric{{
            TS:     time.Now().UTC(),
            Kind:   telemetry.ICMPRTTms,
            Target: "gateway",
            Value:  3.8,
            Unit:   "ms",
        }},
    }

    raw, err := wire.MarshalPacket(packet, wire.ContentTypeProtobuf)
    if err != nil {
        panic(err)
    }

    decoded, err := wire.UnmarshalPacket(raw, wire.ContentTypeProtobuf)
    if err != nil {
        panic(err)
    }
    fmt.Println(decoded.AgentID, decoded.Sequence)
}

WebSocket connections can negotiate the nettact.v1.protobuf or nettact.v1.json subprotocol. HTTP uses application/x-protobuf or application/json; JSON is the fallback when Protobuf is not explicitly selected.

Versions and Upgrades

protocol.SchemaVersion is the wire-schema version. The Agent and Server validate it during connection setup and data ingestion. An incompatible peer is rejected explicitly instead of silently losing fields.

Use mutually compatible official releases of the Agent, Server, and Desktop. Custom integrations should set the current SchemaVersion on outgoing data and call protocol.ValidateSchema on incoming data.

Server components may serve an adjacent schema version alongside the current one through an explicit per-version adapter registry (one adapter per schema, selected by exact membership); ValidateSchema itself stays the exact native-schema check and is never relaxed into a range.

Regenerating Protobuf

Regular consumers do not need the Protobuf toolchain because generated code is committed under wire/pb/. Regeneration is required only when the protocol source changes:

cd wire
buf generate

The schema is in wire/proto/telemetry.proto, and generation settings are in wire/buf.gen.yaml. Install Buf and protoc-gen-go first.

Protocol changes must also update wire/convert.go and the codec tests. Never reuse a Protobuf field number that has already been assigned.

Local Development

go test ./...
go build ./...

In the NetTact multi-repository workspace, the root go.work points the Agent, Server, and Desktop at this local source tree.

License

Apache License 2.0

Documentation

Overview

Package protocol defines the shared wire contract used by the agent, the server, and (later) the cloud server. The type packages (telemetry, config, enroll, permission) deliberately have no external dependencies so every consumer can import them without pulling in server or agent code (architecture §15.2-3: one shared protocol, no forks).

The one exception is the opt-in protocol/wire codec, which adds protobuf as a compact alternative to JSON on the telemetry hop. Only consumers that import protocol/wire pull google.golang.org/protobuf; the type packages stay dependency-free.

Index

Constants

View Source
const SchemaVersion = 8

SchemaVersion is the current wire schema version. Bump it for breaking changes; additive changes (new optional fields, new string enum values) keep the same version and must be tolerated by consumers.

3 removed two fields from GameBucket — the whole-adapter telemetry and the busiest logical core — and moved them to a stream of their own keyed by (agent, second), alongside a new collection for the stretches a game produced no frames. Removals are what make it breaking: a peer still speaking 2 sends readings this build has no field for, and expects none of what replaced them.

4 redefined what probe.icmp.loss_pct is a ratio OF. It used to be the target's configured packet count; it is now the echoes the agent actually sent, which it reports alongside as probe.icmp.sent. The field did not move and no field was removed, which is exactly why this needs the version: nothing about the wire shape betrays the change, so a 3 server would read a 4 agent's rounds happily and read them wrong. It would take a round truncated by the agent's probe-concurrency budget — one echo of five, reporting 100% because the one was lost — as a full round's 100% and confirm an outage, which is the precise false fault the sent count was added to prevent. Bumping refuses that pairing at the handshake instead.

5 moved traceroute from a server-issued command to an agent-local trigger. Two frame variants went away (trace_request, trace_result), the result now rides Packet as a self-describing record, and DesiredState gained the policy block that governs the agent's own trigger. A 4 server paired with a 5 agent would push commands nothing listens for and would drop the results arriving inside packets it otherwise parses perfectly — a mismatch whose only symptom is a diagnostic feature that silently never produces anything.

6 removed reported_config_version from Hello and Packet (Hello field 6, Packet field 9 — both reserved, never to be reused). The server stored it and nothing ever read it back; the live "what config has the agent applied" signal is the MonitorStatus frame's config-version echo. The removal is what makes it breaking: a 5 agent still stamps the field on every packet and a 6 server has no slot for it — both codecs would skip it silently (encoding/json ignores unknown fields, and protobuf skips unknown field numbers), and a silent skip is exactly the ambiguity an exact-match handshake exists to refuse.

7 did to the incident scene what 5 did to traceroute. Two more frame variants went away (incident_snapshot_request, incident_snapshot — Frame fields 8 and 10, reserved), and the scene now rides Packet as a self-describing SceneReport the agent collects on its own fault edges. The pairing has to be refused rather than tolerated in either direction: a 6 server would push scene requests nothing answers and would drop the reports arriving inside packets it otherwise parses, while a 6 agent would answer on a frame the 7 server no longer accepts. Either way the symptom is an evidence feature that silently produces nothing, in exactly the outages it exists for.

8 added the protocol's first negotiation-and-recovery state machines: capability negotiation, the pre-claim sequence-floor barrier, and the controlled credential/epoch rotation. Hello carries the wire capabilities the agent speaks and the enrollment epoch of the credential it presents; five new control frames (sequence_floor, sequence_floor_applied, epoch_rotation_challenge, epoch_rotation_request, epoch_rotation_result) ride the Frame envelope. What makes it breaking is the state machine a peer must run, not a wire-shape removal: a 7 server would skip the new frames as unknown fields — the floor barrier would never establish and the agent would claim sequences the server cannot safely fence against a reset allocator — and a 7 agent declares no capabilities and cannot perform the rotation an 8 server depends on for conflict recovery. Both directions fail loudly at the handshake instead of limping along half-negotiated.

Variables

This section is empty.

Functions

func ValidateSchema

func ValidateSchema(v int) error

ValidateSchema reports whether v is a schema version this build understands. The server calls this at ingress, and the agent on the reply, so a mismatched pair fails loudly at the handshake instead of quietly at the data.

Why this is an exact match and not a range

It used to accept 1..SchemaVersion, which is the shape a system with deployed agents needs. Self-hosted builds have none: every agent and server binary in one install speaks the same schema, so a range here would not buy tolerance, it would buy silence: a peer speaking 2 would be admitted and every field 3 moved would be dropped on the floor with nothing anywhere saying so. That is the failure mode the version exists to prevent, and it is worse than a refused connection, which at least names the half of the install that needs upgrading. Deployments that must accept several schema versions side by side (a cloud gateway behind a rolling agent fleet) do so through an explicit per-version adapter registry — this function stays the exact "native schema of this build" check, and a range is never the mechanism.

Types

This section is empty.

Directories

Path Synopsis
Package config defines the DesiredState the server pushes down to an agent over the persistent WebSocket channel.
Package config defines the DesiredState the server pushes down to an agent over the persistent WebSocket channel.
Package enroll defines the agent enrollment handshake (architecture §11).
Package enroll defines the agent enrollment handshake (architecture §11).
Package gamesense defines the contract for game presentation data: the line-delimited JSON a sensor component writes on its stdout, the single config line the agent writes back on its stdin, and the run / second-bucket records the agent uploads from it.
Package gamesense defines the contract for game presentation data: the line-delimited JSON a sensor component writes on its stdout, the single config line the agent writes back on its stdin, and the run / second-bucket records the agent uploads from it.
Package permission is the typed, immutable local-permission model shared by the agent (enforcement), the server (ingestion, pre-check, remediation), and the desktop trust-boundary exception.
Package permission is the typed, immutable local-permission model shared by the agent (enforcement), the server (ingestion, pre-check, remediation), and the desktop trust-boundary exception.
Package telemetry defines the batched data packet an agent uploads to the server, matching the shape in the architecture doc §5.1.
Package telemetry defines the batched data packet an agent uploads to the server, matching the shape in the architecture doc §5.1.
Package wire is the opt-in serialization codec for the NetTact agent <-> server WebSocket channel.
Package wire is the opt-in serialization codec for the NetTact agent <-> server WebSocket channel.
pb

Jump to

Keyboard shortcuts

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