proxy.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. ProxyListenPort int `json:"proxy_listen_port"`
  34. IsExtClient bool `json:"is_ext_client"`
  35. Address net.IP `json:"address"`
  36. ExtInternalIp net.IP `json:"ext_internal_ip"`
  37. IsRelayed bool `json:"is_relayed"`
  38. RelayedTo *net.UDPAddr `json:"relayed_to"`
  39. }
  40. // ProxyManagerPayload - struct for proxy manager payload
  41. type ProxyManagerPayload struct {
  42. Action ProxyAction `json:"action"`
  43. InterfaceName string `json:"interface_name"`
  44. Server string `json:"server"`
  45. //WgAddr string `json:"wg_addr"`
  46. Peers []wgtypes.PeerConfig `json:"peers"`
  47. PeerMap map[string]PeerConf `json:"peer_map"`
  48. IsIngress bool `json:"is_ingress"`
  49. IsRelayed bool `json:"is_relayed"`
  50. RelayedTo *net.UDPAddr `json:"relayed_to"`
  51. IsRelay bool `json:"is_relay"`
  52. RelayedPeerConf map[string]RelayedConf `json:"relayed_conf"`
  53. }
  54. // Metric - struct for metric data
  55. type ProxyMetric struct {
  56. NodeConnectionStatus map[string]bool `json:"node_connection_status"`
  57. LastRecordedLatency uint64 `json:"last_recorded_latency"`
  58. TrafficSent int64 `json:"traffic_sent"` // stored in MB
  59. TrafficRecieved int64 `json:"traffic_recieved"` // stored in MB
  60. }