mirror of https://github.com/jetkvm/kvm.git
chore(public-ip): use interface state to set public IP ready state
This commit is contained in:
parent
1097deeaf8
commit
e9df46baec
17
network.go
17
network.go
|
|
@ -110,6 +110,13 @@ func triggerTimeSyncOnNetworkStateChange() {
|
|||
}()
|
||||
}
|
||||
|
||||
func setPublicIPReadyState(ipv4Ready, ipv6Ready bool) {
|
||||
if publicIPState == nil {
|
||||
return
|
||||
}
|
||||
publicIPState.SetIPv4AndIPv6(ipv4Ready, ipv6Ready)
|
||||
}
|
||||
|
||||
func networkStateChanged(_ string, state types.InterfaceState) {
|
||||
// do not block the main thread
|
||||
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
|
||||
|
|
@ -121,16 +128,10 @@ func networkStateChanged(_ string, state types.InterfaceState) {
|
|||
if state.Online {
|
||||
networkLogger.Info().Msg("network state changed to online, triggering time sync")
|
||||
triggerTimeSyncOnNetworkStateChange()
|
||||
|
||||
if publicIPState != nil {
|
||||
publicIPState.SetIPv4AndIPv6(state.IPv4Ready, state.IPv6Ready)
|
||||
}
|
||||
} else {
|
||||
if publicIPState != nil {
|
||||
publicIPState.SetIPv4AndIPv6(false, false)
|
||||
}
|
||||
}
|
||||
|
||||
setPublicIPReadyState(state.IPv4Ready, state.IPv6Ready)
|
||||
|
||||
// always restart mDNS when the network state changes
|
||||
if mDNS != nil {
|
||||
restartMdns()
|
||||
|
|
|
|||
|
|
@ -92,22 +92,6 @@ func (ps *PublicIPState) SetIPv4AndIPv6(ipv4, ipv6 bool) {
|
|||
ps.ipv6 = ipv6
|
||||
}
|
||||
|
||||
// SetIPv4 sets if we need to track IPv4 public IP addresses
|
||||
func (ps *PublicIPState) SetIPv4(ipv4 bool) {
|
||||
ps.mu.Lock()
|
||||
defer ps.mu.Unlock()
|
||||
|
||||
ps.ipv4 = ipv4
|
||||
}
|
||||
|
||||
// SetIPv6 sets if we need to track IPv6 public IP addresses
|
||||
func (ps *PublicIPState) SetIPv6(ipv6 bool) {
|
||||
ps.mu.Lock()
|
||||
defer ps.mu.Unlock()
|
||||
|
||||
ps.ipv6 = ipv6
|
||||
}
|
||||
|
||||
// SetCloudflareEndpoint sets the Cloudflare endpoint
|
||||
func (ps *PublicIPState) SetCloudflareEndpoint(endpoint string) {
|
||||
ps.mu.Lock()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ export default function PublicIPCard() {
|
|||
return;
|
||||
}
|
||||
const publicIPs = resp.result as PublicIP[];
|
||||
// sort the public IPs by IP address
|
||||
// IPv6 addresses are sorted after IPv4 addresses
|
||||
setPublicIPs(publicIPs.sort(({ ip: aIp }, { ip: bIp }) => {
|
||||
const aIsIPv6 = aIp.includes(":");
|
||||
const bIsIPv6 = bIp.includes(":");
|
||||
|
|
|
|||
Loading…
Reference in New Issue