types.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package aerotun
  2. import "time"
  3. const (
  4. ProtocolName = "AeroTUN"
  5. ProtocolVersion = 1
  6. DefaultMTU = 1420
  7. DefaultPort = 51830
  8. MagicHeader = 0xAE70 // "AE"
  9. FlagCompressedLZ4 = 0x01
  10. FlagKeepalive = 0x02
  11. StoragePath = "/etc/proxmox-router/vpn/aerotun_instances.json"
  12. )
  13. // TunnelInstance represents a configured AeroTUN interface and its live status
  14. type TunnelInstance struct {
  15. ID string `json:"id"`
  16. Name string `json:"name"` // e.g. "aerotun0"
  17. Mode string `json:"mode"` // "server" (listen) or "client" (dial)
  18. ListenPort int `json:"listen_port"` // UDP port to bind
  19. RemoteEndpoint string `json:"remote_endpoint"` // "host:port" (used if client or static peer)
  20. LocalAddress string `json:"local_address"` // CIDR e.g. "10.99.0.1/24"
  21. PeerAddress string `json:"peer_address"` // Peer CIDR e.g. "10.99.0.2/24"
  22. PSK string `json:"psk"` // 32-byte hex/base64 pre-shared key
  23. Compression bool `json:"compression"` // Enable adaptive LZ4
  24. MTU int `json:"mtu"` // e.g. 1420
  25. DefaultRoute bool `json:"default_route"` // Route 0.0.0.0/0 via this tunnel
  26. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  27. Comment string `json:"comment,omitempty"`
  28. CreatedAt time.Time `json:"created_at"`
  29. // Runtime state & telemetry
  30. Running bool `json:"running"`
  31. ActivePeerEndpoint string `json:"active_peer_endpoint,omitempty"`
  32. LastHandshake string `json:"last_handshake,omitempty"`
  33. RxBytes uint64 `json:"rx_bytes"`
  34. TxBytes uint64 `json:"tx_bytes"`
  35. RawBytesIn uint64 `json:"raw_bytes_in"` // uncompressed RX payload
  36. RawBytesOut uint64 `json:"raw_bytes_out"` // uncompressed TX payload
  37. WireBytesIn uint64 `json:"wire_bytes_in"` // actual wire RX
  38. WireBytesOut uint64 `json:"wire_bytes_out"`// actual wire TX
  39. SavedBytes uint64 `json:"saved_bytes"` // Bandwidth saved through compression
  40. CompressionRatio string `json:"compression_ratio,omitempty"`
  41. PacketsRx uint64 `json:"packets_rx"`
  42. PacketsTx uint64 `json:"packets_tx"`
  43. CompressedPackets uint64 `json:"compressed_packets"`
  44. RawPackets uint64 `json:"raw_packets"`
  45. }
  46. // SummaryStats aggregates performance across all AeroTUN tunnels
  47. type SummaryStats struct {
  48. TotalTunnels int `json:"total_tunnels"`
  49. ActiveTunnels int `json:"active_tunnels"`
  50. TotalRxBytes uint64 `json:"total_rx_bytes"`
  51. TotalTxBytes uint64 `json:"total_tx_bytes"`
  52. TotalSavedBytes uint64 `json:"total_saved_bytes"`
  53. AverageRatio string `json:"average_ratio"`
  54. AlgorithmCrypto string `json:"algorithm_crypto"`
  55. AlgorithmCompress string `json:"algorithm_compress"`
  56. }