netmaker/nm-proxy/models/models.go

66 lines
1.4 KiB
Go
Raw Normal View History

2022-11-27 22:11:07 +08:00
package models
import (
"context"
"net"
2022-12-01 13:09:43 +08:00
"sync"
"time"
2022-11-27 22:11:07 +08:00
2022-12-01 13:09:43 +08:00
"github.com/gravitl/netmaker/nm-proxy/wg"
2022-11-27 22:11:07 +08:00
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
const (
NmProxyPort = 51722
DefaultCIDR = "127.0.0.1/8"
)
2022-12-01 13:09:43 +08:00
type ProxyConfig struct {
RemoteKey wgtypes.Key
LocalKey wgtypes.Key
WgInterface *wg.WGIface
IsExtClient bool
PersistentKeepalive *time.Duration
RecieverChan chan []byte
PeerConf *wgtypes.PeerConfig
PeerEndpoint *net.UDPAddr
RemoteConnAddr *net.UDPAddr
LocalConnAddr *net.UDPAddr
}
// Conn is a peer Connection configuration
type Conn struct {
2022-11-27 22:11:07 +08:00
// Key is a public key of a remote peer
2022-11-29 02:55:42 +08:00
Key wgtypes.Key
2022-11-27 22:11:07 +08:00
IsExtClient bool
IsRelayed bool
RelayedEndpoint *net.UDPAddr
IsAttachedExtClient bool
2022-12-01 13:09:43 +08:00
Config ProxyConfig
StopConn func()
ResetConn func()
2022-12-01 13:09:43 +08:00
LocalConn net.Conn
Mutex *sync.RWMutex
2022-11-27 22:11:07 +08:00
}
type RemotePeer struct {
PeerKey string
Interface string
Endpoint *net.UDPAddr
IsExtClient bool
IsAttachedExtClient bool
2022-12-01 13:09:43 +08:00
LocalConn net.Conn
2022-11-27 22:11:07 +08:00
}
type ExtClientPeer struct {
CancelFunc context.CancelFunc
CommChan chan *net.UDPAddr
}
type WgIfaceConf struct {
Iface *wgtypes.Device
IfaceKeyHash string
2022-12-01 13:09:43 +08:00
PeerMap map[string]*Conn
2022-11-27 22:11:07 +08:00
}