13 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, must_haves
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01-capture-and-classification | 04 | execute | 3 |
|
|
false |
|
|
Purpose: This is the final integration that makes netsynth a runnable tool. It connects capture -> classify -> aggregate stages via channels, handles Ctrl+C gracefully, and prints the exit summary. All Phase 1 success criteria become observable here.
Output: Working netsynth binary with -i, --list-interfaces, --verbose flags. Checkpoint for manual smoke test.
<execution_context> @$HOME/.claude/get-shit-done/workflows/execute-plan.md @$HOME/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/phases/01-capture-and-classification/01-CONTEXT.md @.planning/phases/01-capture-and-classification/01-RESEARCH.md @.planning/phases/01-capture-and-classification/01-01-SUMMARY.md @.planning/phases/01-capture-and-classification/01-02-SUMMARY.md @.planning/phases/01-capture-and-classification/01-03-SUMMARY.md ```go func ListInterfaces() ([]net.Interface, error) func OpenCapture(ctx context.Context, iface string) (*pcap.Handle, error) func StartCapture(ctx context.Context, iface string) (<-chan gopacket.Packet, *int64, error) ```type TrafficClass string // 11 constants
type ClassifiedPacket struct { Class TrafficClass; SrcPort, DstPort uint16; Protocol string; Length int }
type WindowSnapshot struct { Counts map[TrafficClass]int64; TotalPackets int64; WindowIndex int }
type Classifier struct { ... }
func NewClassifier(rules []Rule) *Classifier
func (c *Classifier) Classify(pkt gopacket.Packet) ClassifiedPacket
var DefaultRules []Rule
const DefaultWindowMs = 500
func Aggregate(done <-chan struct{}, events <-chan classify.ClassifiedPacket, windowMs int, onSnapshot func(classify.WindowSnapshot)) <-chan classify.WindowSnapshot
func PrintSummary(w io.Writer, totals map[classify.TrafficClass]int64)
func PrintWindowLine(w io.Writer, snap classify.WindowSnapshot)
func AccumulateTotals(totals map[classify.TrafficClass]int64, snap classify.WindowSnapshot)
package main
import (
"context"
"fmt"
"os"
"os/signal"
"strings"
"sync/atomic"
"syscall"
"github.com/spf13/cobra"
"github.com/netsynth/netsynth/aggregate"
"github.com/netsynth/netsynth/capture"
"github.com/netsynth/netsynth/classify"
)
var (
ifaceName string
listIfaces bool
verbose bool
)
func main() {
rootCmd := &cobra.Command{
Use: "netsynth",
Short: "Sonify live network traffic into ambient audio",
Long: "NetSynth captures network traffic, classifies it by protocol, and (in future phases) synthesizes an ambient MP3 soundscape.",
RunE: run,
}
rootCmd.Flags().StringVarP(&ifaceName, "interface", "i", "", "Network interface to capture on (required unless --list-interfaces)")
rootCmd.Flags().BoolVar(&listIfaces, "list-interfaces", false, "List available network interfaces and exit")
rootCmd.Flags().BoolVar(&verbose, "verbose", false, "Print per-window protocol activity to stderr")
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func run(cmd *cobra.Command, args []string) error {
// --list-interfaces mode (CAPT-02)
if listIfaces {
return runListInterfaces()
}
// Require -i flag
if ifaceName == "" {
return fmt.Errorf("interface required: use -i <interface> or --list-interfaces to see available interfaces")
}
// Set up signal handling (Ctrl+C)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
// Stage 1: Capture (CAPT-01)
fmt.Fprintf(os.Stderr, "Starting capture on %s... (press Ctrl+C to stop)\n", ifaceName)
packets, droppedPtr, err := capture.StartCapture(ctx, ifaceName)
if err != nil {
return err // CAPT-04: permission error already has platform-specific message
}
// Stage 2: Classify (CLAS-01)
classifier := classify.NewClassifier(classify.DefaultRules)
classified := make(chan classify.ClassifiedPacket, 1024)
go func() {
defer close(classified)
for pkt := range packets {
classified <- classifier.Classify(pkt)
}
}()
// Stage 3: Aggregate with optional verbose callback (CLAS-04)
var onSnapshot func(classify.WindowSnapshot)
if verbose {
onSnapshot = func(snap classify.WindowSnapshot) {
aggregate.PrintWindowLine(os.Stderr, snap) // CLAS-04: --verbose output
}
}
snapshots := aggregate.Aggregate(ctx.Done(), classified, aggregate.DefaultWindowMs, onSnapshot)
// Consume snapshots and accumulate totals
totals := make(map[classify.TrafficClass]int64)
for snap := range snapshots {
aggregate.AccumulateTotals(totals, snap)
}
// Print exit summary (CLAS-03)
dropped := atomic.LoadInt64(droppedPtr)
if dropped > 0 {
fmt.Fprintf(os.Stderr, "\nWarning: %d packets dropped (channel buffer full)\n", dropped)
}
aggregate.PrintSummary(os.Stderr, totals)
return nil
}
func runListInterfaces() error {
ifaces, err := capture.ListInterfaces()
if err != nil {
return fmt.Errorf("error listing interfaces: %w", err)
}
if len(ifaces) == 0 {
fmt.Fprintln(os.Stderr, "No interfaces found. If interfaces are missing, run with sudo.")
return nil
}
fmt.Fprintln(os.Stderr, "Available interfaces:")
for _, iface := range ifaces {
addrs, _ := iface.Addrs()
addrStrs := make([]string, len(addrs))
for i, a := range addrs {
addrStrs[i] = a.String()
}
fmt.Fprintf(os.Stderr, " %-15s flags=%s addrs=%s\n",
iface.Name, iface.Flags, strings.Join(addrStrs, ", "))
}
return nil
}
-
Create cmd/netsynth/main_test.go with:
- TestListInterfacesFlag: Execute rootCmd with
--list-interfaces, verify it exits 0 (integration-lite test) - TestMissingInterfaceFlag: Execute rootCmd with no flags, verify error message contains "interface required"
- TestHelpOutput: Execute rootCmd with
--help, verify output contains "-i", "--list-interfaces", "--verbose"
- TestListInterfacesFlag: Execute rootCmd with
-
Build the binary:
CGO_ENABLED=0 go build -o netsynth ./cmd/netsynth- Verify:
./netsynth --helpshows usage - Verify:
./netsynth --list-interfacesshows interfaces - Verify:
./netsynth -i eth0without root shows permission error with sudo hint
-
Run full test suite:
go test -v -race ./...cd /home/dev/workspace/yoloyolo && CGO_ENABLED=0 go build -o netsynth ./cmd/netsynth && ./netsynth --list-interfaces 2>&1 | grep -q "flags=" && go test -v -count=1 ./... <acceptance_criteria>- cmd/netsynth/main.go contains
rootCmd.Flags().StringVarP(&ifaceName, "interface", "i" - cmd/netsynth/main.go contains
rootCmd.Flags().BoolVar(&listIfaces, "list-interfaces" - cmd/netsynth/main.go contains
rootCmd.Flags().BoolVar(&verbose, "verbose" - cmd/netsynth/main.go contains
signal.NotifyContext - cmd/netsynth/main.go contains
capture.StartCapture - cmd/netsynth/main.go contains
classify.NewClassifier(classify.DefaultRules) - cmd/netsynth/main.go contains
aggregate.Aggregate( - cmd/netsynth/main.go contains
aggregate.PrintSummary(os.Stderr - cmd/netsynth/main.go contains
aggregate.PrintWindowLine(os.Stderr CGO_ENABLED=0 go build -o netsynth ./cmd/netsynthexits 0./netsynth --list-interfacesoutput contains interface names and "flags="./netsynth 2>&1(no flags) output contains "interface required"go test -v -count=1 ./...exits 0 (all unit tests pass) </acceptance_criteria> netsynth binary builds and runs. --list-interfaces shows interfaces. Missing -i shows clear error. Signal handling wires Ctrl+C to clean pipeline shutdown. Exit summary prints per-protocol counts. All tests pass.
- cmd/netsynth/main.go contains
<success_criteria>
- netsynth binary builds with CGO_ENABLED=0 (no CGo needed for Phase 1)
- -i flag accepted, --list-interfaces works, --verbose works
- Permission error shows platform-specific sudo hint
- Live capture classifies packets and prints verbose lines (when --verbose)
- Ctrl+C produces clean exit with per-protocol summary
- All unit tests pass across classify/, capture/, aggregate/, and cmd/netsynth/ </success_criteria>