proxy.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package models
  2. import (
  3. "net"
  4. "time"
  5. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  6. )
  7. // ProxyAction - type for proxy action
  8. type ProxyAction string
  9. const (
  10. // default proxy port
  11. NmProxyPort = 51722
  12. // PersistentKeepaliveInterval - default keepalive for wg peer
  13. DefaultPersistentKeepaliveInterval = time.Duration(time.Second * 20)
  14. // ProxyUpdate - constant for proxy update action
  15. ProxyUpdate ProxyAction = "PROXY_UPDATE"
  16. // ProxyDeletePeers - constant for proxy delete peers action
  17. ProxyDeletePeers ProxyAction = "PROXY_DELETE"
  18. // ProxyDeleteAllPeers - constant for proxy delete all peers action
  19. ProxyDeleteAllPeers ProxyAction = "PROXY_DELETE_ALL"
  20. // NoProxy - constant for no ProxyAction
  21. NoProxy ProxyAction = "NO_PROXY"
  22. )
  23. // RelayedConf - struct relayed peers config
  24. type RelayedConf struct {
  25. RelayedPeerEndpoint *net.UDPAddr `json:"relayed_peer_endpoint"`
  26. RelayedPeerPubKey string `json:"relayed_peer_pub_key"`
  27. Peers []wgtypes.PeerConfig `json:"relayed_peers"`
  28. }
  29. // PeerConf - struct for peer config in the network
  30. type PeerConf struct {
  31. Proxy bool `json:"proxy"`
  32. PublicListenPort int32 `json:"public_listen_port"`
  33. IsExtClient bool `json:"is_ext_client"`
  34. Address net.IP `json:"address"`
  35. ExtInternalIp net.IP `json:"ext_internal_ip"`
  36. IsRelayed bool `json:"is_relayed"`
  37. RelayedTo *net.UDPAddr `json:"relayed_to"`
  38. }
  39. // ProxyManagerPayload - struct for proxy manager payload
  40. type ProxyManagerPayload struct {
  41. Action ProxyAction `json:"action"`
  42. InterfaceName string `json:"interface_name"`
  43. Server string `json:"server"`
  44. //WgAddr string `json:"wg_addr"`
  45. Peers []wgtypes.PeerConfig `json:"peers"`
  46. PeerMap map[string]PeerConf `json:"peer_map"`
  47. IsIngress bool `json:"is_ingress"`
  48. IsRelayed bool `json:"is_relayed"`
  49. RelayedTo *net.UDPAddr `json:"relayed_to"`
  50. IsRelay bool `json:"is_relay"`
  51. RelayedPeerConf map[string]RelayedConf `json:"relayed_conf"`
  52. }
  53. // Metric - struct for metric data
  54. type ProxyMetric struct {
  55. NodeConnectionStatus map[string]bool `json:"node_connection_status"`
  56. LastRecordedLatency uint64 `json:"last_recorded_latency"`
  57. TrafficSent int64 `json:"traffic_sent"` // stored in MB
  58. TrafficRecieved int64 `json:"traffic_recieved"` // stored in MB
  59. }