package node import ( "net/netip" "sync/atomic" ) type sharedState struct { // Immutable: HubAddress string APIKey string NetName string LocalIP byte LocalPub bool LocalAddr netip.AddrPort PrivKey []byte PrivSignKey []byte // Mutable: Routes [256]*atomic.Pointer[peerRoute] RelayIP *atomic.Pointer[byte] // Messages for supervisor main loop. Messages chan any } func newSharedState( netName, hubAddress, apiKey string, conf localConfig, ) ( ss sharedState, ) { ss.HubAddress = hubAddress ss.APIKey = apiKey ss.NetName = netName ss.LocalIP = conf.PeerIP ip, ok := netip.AddrFromSlice(conf.PublicIP) if ok { ss.LocalPub = true ss.LocalAddr = netip.AddrPortFrom(ip, conf.Port) } ss.PrivKey = conf.PrivKey ss.PrivSignKey = conf.PrivSignKey for i := range ss.Routes { ss.Routes[i] = &atomic.Pointer[peerRoute]{} ss.Routes[i].Store(&peerRoute{}) } ss.RelayIP = &atomic.Pointer[byte]{} ss.Messages = make(chan any, 1024) return }