models.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import (
  3. "context"
  4. "net"
  5. "sync"
  6. "time"
  7. "github.com/gravitl/netmaker/nm-proxy/wg"
  8. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  9. )
  10. const (
  11. NmProxyPort = 51722
  12. DefaultCIDR = "127.0.0.1/8"
  13. )
  14. type ProxyConfig struct {
  15. RemoteKey wgtypes.Key
  16. LocalKey wgtypes.Key
  17. WgInterface *wg.WGIface
  18. IsExtClient bool
  19. PersistentKeepalive *time.Duration
  20. RecieverChan chan []byte
  21. PeerConf *wgtypes.PeerConfig
  22. PeerEndpoint *net.UDPAddr
  23. RemoteConnAddr *net.UDPAddr
  24. LocalConnAddr *net.UDPAddr
  25. }
  26. // Conn is a peer Connection configuration
  27. type Conn struct {
  28. // Key is a public key of a remote peer
  29. Key wgtypes.Key
  30. IsExtClient bool
  31. IsRelayed bool
  32. RelayedEndpoint *net.UDPAddr
  33. IsAttachedExtClient bool
  34. Config ProxyConfig
  35. StopConn func()
  36. ResetConn func()
  37. LocalConn net.Conn
  38. Mutex *sync.RWMutex
  39. }
  40. type RemotePeer struct {
  41. PeerKey string
  42. Interface string
  43. Endpoint *net.UDPAddr
  44. IsExtClient bool
  45. IsAttachedExtClient bool
  46. LocalConn net.Conn
  47. }
  48. type ExtClientPeer struct {
  49. CancelFunc context.CancelFunc
  50. CommChan chan *net.UDPAddr
  51. }
  52. type WgIfaceConf struct {
  53. Iface *wgtypes.Device
  54. IfaceKeyHash string
  55. PeerMap map[string]*Conn
  56. }