feat: store a wglink endpoint string
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
c9b5e56f14
commit
78b61aede4
@ -138,6 +138,13 @@ func createCliApp() *cli.App {
|
||||
}
|
||||
app.Flags = append(app.Flags, &wgInterfaceName)
|
||||
|
||||
wgEndpoint := cli.StringFlag{
|
||||
Name: "endpoint",
|
||||
Usage: "Wireguard endpoint domain or address without the port",
|
||||
Value: "domain.name.notset",
|
||||
}
|
||||
app.Flags = append(app.Flags, &wgEndpoint)
|
||||
|
||||
wgPort := cli.IntFlag{
|
||||
Name: "port",
|
||||
Usage: "UDP Port for wireguard device",
|
||||
@ -171,7 +178,7 @@ func createCliApp() *cli.App {
|
||||
|
||||
|
||||
app.Action = func(ctx *cli.Context) error {
|
||||
err := setup()
|
||||
err := setup(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -182,7 +189,7 @@ func createCliApp() *cli.App {
|
||||
return app
|
||||
}
|
||||
|
||||
func setup() error {
|
||||
func setup(ctx *cli.Context) error {
|
||||
slog.Debug("Starting setup()")
|
||||
uid := os.Getuid()
|
||||
if uid == -1 {
|
||||
@ -225,6 +232,7 @@ func setup() error {
|
||||
InterfaceName,
|
||||
&privateKey,
|
||||
WgPort,
|
||||
ctx.String("endpoint"),
|
||||
)
|
||||
if err != nil {
|
||||
slog.Warn("Error while initlizing Wireguard netlink and device!")
|
||||
|
@ -31,6 +31,7 @@ func HandleGetNodeInfo(wgLink *WGLink) http.HandlerFunc {
|
||||
proto.NodePublicInfo{
|
||||
PublicKey: dev.PublicKey.String(),
|
||||
UDPPort: dev.ListenPort,
|
||||
Endpoint: wgLink.Endpoint,
|
||||
// TODO: Send endpoint for clients to connect
|
||||
},
|
||||
)
|
||||
|
5
link.go
5
link.go
@ -21,14 +21,15 @@ type WGLink struct {
|
||||
*netlink.LinkAttrs
|
||||
*wgctrl.Client
|
||||
IPPool
|
||||
Endpoint string // Endpoint for clients to use when connecting to this link. Has no effect.
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
// Retruns an existing or create a WGLink
|
||||
func InitWGLink(ifName string, privateKey *wgtypes.Key, port int) (*WGLink, error){
|
||||
func InitWGLink(ifName string, privateKey *wgtypes.Key, port int, endpoint string) (*WGLink, error){
|
||||
attrs := netlink.NewLinkAttrs()
|
||||
attrs.Name = ifName
|
||||
wg := WGLink{LinkAttrs: &attrs}
|
||||
wg := WGLink{LinkAttrs: &attrs, Endpoint: endpoint}
|
||||
link, err := netlink.LinkByName(ifName)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user