types.go 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package aerotun
  2. import "time"
  3. const (
  4. ProtocolName = "AeroTUN"
  5. ProtocolVersion = 2
  6. DefaultMTU = 1420
  7. DefaultPort = 51830
  8. MagicHeader = 0xAE70 // "AE"
  9. FlagCompressedLZ4 = 0x01
  10. FlagKeepalive = 0x02
  11. StoragePath = "/etc/debtik/vpn/aerotun_instances.json"
  12. )
  13. // TunnelInstance represents a configured AeroTUN interface and its live status
  14. type TunnelInstance struct {
  15. Backend string `json:"backend,omitempty"`
  16. ConfiguredMTU int `json:"configured_mtu,omitempty"`
  17. DropBreakdown *DropBreakdown `json:"drop_breakdown,omitempty"`
  18. Handshakes uint64 `json:"handshakes,omitempty"`
  19. Protocol int `json:"protocol_version,omitempty"`
  20. PrivateKey string `json:"private_key,omitempty"`
  21. PublicKey string `json:"public_key,omitempty"`
  22. PeerPublicKey string `json:"peer_public_key,omitempty"`
  23. AllowedIPs []string `json:"allowed_ips,omitempty"`
  24. HasPSK bool `json:"has_psk,omitempty"`
  25. HasPrivateKey bool `json:"has_private_key,omitempty"`
  26. ID string `json:"id"`
  27. Name string `json:"name"` // e.g. "aerotun0"
  28. Mode string `json:"mode"` // "server" (listen) or "client" (dial)
  29. ListenPort int `json:"listen_port"` // UDP port to bind
  30. RemoteEndpoint string `json:"remote_endpoint"` // "host:port" (used if client or static peer)
  31. LocalAddress string `json:"local_address"` // CIDR e.g. "10.99.0.1/24"
  32. PeerAddress string `json:"peer_address"` // Peer CIDR e.g. "10.99.0.2/24"
  33. PSK string `json:"psk,omitempty"` // 32-byte hex/base64 pre-shared key
  34. Compression bool `json:"compression"` // Enable adaptive LZ4
  35. MTU int `json:"mtu"` // e.g. 1420
  36. DefaultRoute bool `json:"default_route"` // Route 0.0.0.0/0 via this tunnel
  37. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  38. Comment string `json:"comment,omitempty"`
  39. CreatedAt time.Time `json:"created_at"`
  40. // Runtime state & telemetry
  41. Connected bool `json:"connected"`
  42. LastError string `json:"last_error,omitempty"`
  43. DroppedPackets uint64 `json:"dropped_packets"`
  44. AuthFailures uint64 `json:"auth_failures"`
  45. ReplayDrops uint64 `json:"replay_drops"`
  46. Running bool `json:"running"`
  47. ActivePeerEndpoint string `json:"active_peer_endpoint,omitempty"`
  48. LastHandshake string `json:"last_handshake,omitempty"`
  49. RxBytes uint64 `json:"rx_bytes"`
  50. TxBytes uint64 `json:"tx_bytes"`
  51. RawBytesIn uint64 `json:"raw_bytes_in"` // uncompressed RX payload
  52. RawBytesOut uint64 `json:"raw_bytes_out"` // uncompressed TX payload
  53. WireBytesIn uint64 `json:"wire_bytes_in"` // actual wire RX
  54. WireBytesOut uint64 `json:"wire_bytes_out"` // actual wire TX
  55. SavedBytes uint64 `json:"saved_bytes"` // Bandwidth saved through compression
  56. CompressionRatio string `json:"compression_ratio,omitempty"`
  57. PacketsRx uint64 `json:"packets_rx"`
  58. PacketsTx uint64 `json:"packets_tx"`
  59. CompressedPackets uint64 `json:"compressed_packets"`
  60. RawPackets uint64 `json:"raw_packets"`
  61. }
  62. // SummaryStats aggregates performance across all AeroTUN tunnels
  63. type DropBreakdown struct {
  64. InvalidOutgoing uint64 `json:"invalid_outgoing"`
  65. MissingSession uint64 `json:"missing_session"`
  66. SendFailure uint64 `json:"send_failure"`
  67. InvalidIncoming uint64 `json:"invalid_incoming"`
  68. SourcePolicy uint64 `json:"source_policy"`
  69. InterfaceWrite uint64 `json:"interface_write"`
  70. }
  71. type SummaryStats struct {
  72. TotalTunnels int `json:"total_tunnels"`
  73. ActiveTunnels int `json:"active_tunnels"`
  74. TotalRxBytes uint64 `json:"total_rx_bytes"`
  75. TotalTxBytes uint64 `json:"total_tx_bytes"`
  76. TotalSavedBytes uint64 `json:"total_saved_bytes"`
  77. AverageRatio string `json:"average_ratio"`
  78. AlgorithmCrypto string `json:"algorithm_crypto"`
  79. AlgorithmCompress string `json:"algorithm_compress"`
  80. }