wg_core

package
v0.0.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WG_AGENT_TYPE_POP       uint8 = 1
	WG_AGENT_TYPE_CONNECTOR uint8 = 2
	WG_AGENT_TYPE_CLIENT    uint8 = 3
)

Variables

This section is empty.

Functions

func GenerateKeyPair

func GenerateKeyPair() (privateKey, publicKey string, err error)

func GenerateKeyPairByPath

func GenerateKeyPairByPath(keyFile string) (privateKey, publicKey string, err error)

func IsWgInstalled added in v0.0.19

func IsWgInstalled() bool

func IsWgToolInstalled added in v0.0.19

func IsWgToolInstalled() bool

func ParsePrivateKey

func ParsePrivateKey(privateKey string) (*device.NoisePrivateKey, error)

privateKey is base64 encoded

func ParsePublicKey

func ParsePublicKey(publicKey string) (*device.NoisePublicKey, error)

publicKey is base64 encoded

func PrivateKeyToHex

func PrivateKeyToHex(privateKey string) (string, error)

privateKey is base64 encoded

func PublicKeyToHex

func PublicKeyToHex(publicKey string) (string, error)

publicKey is base64 encoded

func ReadPrivateKey

func ReadPrivateKey(keyFile string) (*wgtypes.Key, error)

Types

type ConnState

type ConnState int8
const (
	ConnStateError      ConnState = -1
	ConnStateReady      ConnState = 0
	ConnStateConnecting ConnState = 1
	ConnStateConnected  ConnState = 2
)

type WgInterface

type WgInterface struct {
	Interface  string `json:"interface"`   // WireGuard interface, wg0/wg1/wg2...
	ListenPort int    `json:"listen_port"` // [Interface]if this is server side(pop), then need this,
	PrivateKey string `json:"private_key"` // [Interface][optional],base64 encoded, if empty then use client's
	IP         string `json:"ip"`          // [Interface]self ip, get from controller
	Network    string `json:"network"`     // [Interface]pop's network, cidr format
	DNS        string `json:"dns"`         // [Interface][optional],
	PublicKey  string `json:"public_key"`  // [自己的公钥]base64 encoded, 自己的公钥,和PrivateKey是一对, 不需要写在conf文件里,是给对方用的,对方用在自己的conf的peer里
	PSK        string `json:"psk"`         // [同PublicKey]
	Endpoint   string `json:"endpoint"`    // [同PublicKey][used in [Peer] peer is client who connect to here];[for server-side it self,this is useless]
	AllowIps   string `json:"allow_ips"`   // [同PublicKey][used in [Peer] peer is client who connect to here];for peer, if use single allow-ip mode, then each ip of each peer is a single ip:1.1.1.1/32

	ConfFile string `json:"conf_file"` // if empty, default value is {Interface}.conf
	EthName  string `json:"eth_name"`  // default value is eth0, used in pop/connector, in PostUp/PostDown
	Forward  *bool  `json:"forward"`   // use forward, used in pop/connector

	AgentType uint8    `json:"agent_type"` // [NOT A CONFIG],
	Peers     []WgPeer `json:"peers"`      // ...

}

used's in clients(pop/connector/client), wg0's conf,

func (*WgInterface) Assign

func (i *WgInterface) Assign(cfg *WgInterface)

func (*WgInterface) AssignForce

func (i *WgInterface) AssignForce(cfg *WgInterface)

func (*WgInterface) FirstPeer

func (c *WgInterface) FirstPeer() *WgPeer

func (*WgInterface) GetIpCidr

func (i *WgInterface) GetIpCidr() string

func (*WgInterface) GetIpWithoutCidr

func (i *WgInterface) GetIpWithoutCidr() string

func (*WgInterface) GetWgTypesKeyBytes

func (p *WgInterface) GetWgTypesKeyBytes(encodedKey string) (*wgtypes.Key, error)

func (*WgInterface) GetWgTypesPrivateKeyBytes

func (p *WgInterface) GetWgTypesPrivateKeyBytes() (*wgtypes.Key, error)

func (*WgInterface) ParsePrivateKey

func (i *WgInterface) ParsePrivateKey() (*device.NoisePrivateKey, error)

func (*WgInterface) PrivateKeyToHex

func (i *WgInterface) PrivateKeyToHex() (string, error)

type WgPeer

type WgPeer struct {
	AgentType  uint8  `json:"agent_type"`  // [NOT A CONFIG],
	Address    string `json:"address"`     // [NOT A CONFIG],peer's ip address, if client want to ping connected pop, then need to provide this
	PublicKey  string `json:"public_key"`  // [Peer][required],base64 encoded, 对方的公钥
	PSK        string `json:"psk"`         // [Peer][optional],base64 encoded, 对方的
	Endpoint   string `json:"endpoint"`    // [Peer][optional],对方的IP地址和端口号,用于建立连接, for pop, endpoint is other pop, if single pop, then del this;for connector/client,endpoint is pop
	AllowedIPs string `json:"allowed_ips"` // [Peer][optional],指定允许对方使用的IP范围
	// not by response
	Remove            bool `json:"remove"`              // [Peer], used by uapi/raw api..., means peer is offline/session timeout/kickoff
	ReplaceAllowedIPs bool `json:"replace_allowed_ips"` // [Peer], used by uapi
}

func GetWgPeer

func GetWgPeer(allowIps string, publicKey string, psk string, toRemove bool) (peerConfig *WgPeer, err error)

func (*WgPeer) AssignForce

func (p *WgPeer) AssignForce(peer *WgPeer)

func (*WgPeer) GetWgTypesKeyBytes

func (p *WgPeer) GetWgTypesKeyBytes(encodedKey string) (*wgtypes.Key, error)

func (*WgPeer) GetWgTypesPSKeyBytes

func (p *WgPeer) GetWgTypesPSKeyBytes() (*wgtypes.Key, error)

func (*WgPeer) GetWgTypesPublicKeyBytes

func (p *WgPeer) GetWgTypesPublicKeyBytes() (*wgtypes.Key, error)

func (*WgPeer) ParsePublicKey

func (p *WgPeer) ParsePublicKey() (*device.NoisePublicKey, error)

func (*WgPeer) PublicKeyToHex

func (p *WgPeer) PublicKeyToHex() (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL