代码拉取完成,页面将自动刷新
package wg_core
import (
"gitee.com/carlmax_my/console-core-go/pkg/ip_util"
"golang.zx2c4.com/wireguard/device"
)
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
ReplaceAllowedIPs bool `json:"replace_allowed_ips"` // [Peer], used by uapi
}
func (p *WgPeer) AssignForce(peer *WgPeer) {
p.AgentType = peer.AgentType
p.Address = peer.Address
p.PublicKey = peer.PublicKey
p.PSK = peer.PSK
p.Endpoint = peer.Endpoint
p.AllowedIPs = peer.AllowedIPs
p.Remove = peer.Remove
p.ReplaceAllowedIPs = peer.ReplaceAllowedIPs
}
func (p *WgPeer) ParsePublicKey() (*device.NoisePublicKey, error) {
return ParsePublicKey(p.PublicKey)
}
func (p *WgPeer) PublicKeyToHex() (string, error) {
return PublicKeyToHex(p.PublicKey)
}
func GetWgPeer(allowIps string, publicKey string, psk string, toRemove bool) (peerConfig *WgPeer, err error) {
allowedIPs, err := ip_util.GetAllowedIPsAsStr(allowIps)
if err != nil {
return nil, err
}
peerConfig = &WgPeer{
PublicKey: publicKey,
PSK: psk,
Remove: toRemove,
AllowedIPs: allowedIPs,
ReplaceAllowedIPs: false,
}
return peerConfig, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。