mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat: allow to customise WireGuard listen port with --wg-port for machine init/add (#366)
This commit is contained in:
+25
-10
@@ -717,6 +717,12 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve the WireGuard listen port from the request, falling back to the default.
|
||||
wgPort := uint16(req.WireguardPort)
|
||||
if wgPort == 0 {
|
||||
wgPort = network.DefaultWireGuardPort
|
||||
}
|
||||
|
||||
// Use explicitly provided WireGuard endpoints, or use the routable IPs on the machine and its public IP
|
||||
// if not provided. The IPs are auto-detected.
|
||||
var endpoints []*pb.IPPort
|
||||
@@ -736,7 +742,7 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (
|
||||
|
||||
endpoints = make([]*pb.IPPort, len(ips))
|
||||
for i, addr := range ips {
|
||||
addrPort := netip.AddrPortFrom(addr, network.WireGuardPort)
|
||||
addrPort := netip.AddrPortFrom(addr, wgPort)
|
||||
endpoints[i] = pb.NewIPPort(addrPort)
|
||||
}
|
||||
}
|
||||
@@ -773,10 +779,11 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (
|
||||
m.state.ID = addResp.Machine.Id
|
||||
m.state.Name = addResp.Machine.Name
|
||||
m.state.Network = &network.Config{
|
||||
Subnet: subnet,
|
||||
ManagementIP: manageIP,
|
||||
PrivateKey: m.state.Network.PrivateKey,
|
||||
PublicKey: m.state.Network.PublicKey,
|
||||
Subnet: subnet,
|
||||
ManagementIP: manageIP,
|
||||
WireGuardPort: int(wgPort),
|
||||
PrivateKey: m.state.Network.PrivateKey,
|
||||
PublicKey: m.state.Network.PublicKey,
|
||||
}
|
||||
if err = m.state.Save(); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "save machine state: %v", err)
|
||||
@@ -818,13 +825,21 @@ func (m *Machine) JoinCluster(_ context.Context, req *pb.JoinClusterRequest) (*e
|
||||
// Update the machine state with the provided cluster configuration.
|
||||
subnet, _ := req.Machine.Network.Subnet.ToPrefix()
|
||||
manageIP, _ := req.Machine.Network.ManagementIp.ToAddr()
|
||||
|
||||
// Resolve the WireGuard listen port from the request, falling back to the default.
|
||||
wgPort := int(req.WireguardPort)
|
||||
if wgPort == 0 {
|
||||
wgPort = network.DefaultWireGuardPort
|
||||
}
|
||||
|
||||
m.state.ID = req.Machine.Id
|
||||
m.state.Name = req.Machine.Name
|
||||
m.state.Network = &network.Config{
|
||||
Subnet: subnet,
|
||||
ManagementIP: manageIP,
|
||||
PrivateKey: m.state.Network.PrivateKey,
|
||||
PublicKey: m.state.Network.PublicKey,
|
||||
Subnet: subnet,
|
||||
ManagementIP: manageIP,
|
||||
WireGuardPort: wgPort,
|
||||
PrivateKey: m.state.Network.PrivateKey,
|
||||
PublicKey: m.state.Network.PublicKey,
|
||||
}
|
||||
m.state.MinStoreDBVersion = req.MinStoreDbVersion
|
||||
|
||||
@@ -887,7 +902,7 @@ func (m *Machine) Token(_ context.Context, _ *emptypb.Empty) (*pb.TokenResponse,
|
||||
}
|
||||
endpoints := make([]netip.AddrPort, len(ips))
|
||||
for i, ip := range ips {
|
||||
endpoints[i] = netip.AddrPortFrom(ip, network.WireGuardPort)
|
||||
endpoints[i] = netip.AddrPortFrom(ip, uint16(m.state.Network.EffectiveWireGuardPort()))
|
||||
}
|
||||
|
||||
token := NewToken(m.state.Network.PublicKey, publicIP, endpoints)
|
||||
|
||||
Reference in New Issue
Block a user