tons of cursor-shit cleaning, finished implementing cnxId in observer
This commit is contained in:
+18
-42
@@ -14,10 +14,11 @@ export class gpsServer {
|
||||
|
||||
constructor(configHelper, allRediscnx, debug) {
|
||||
this.configHelper = configHelper
|
||||
this.gpsConfig = configHelper.config
|
||||
this.rootConfig = configHelper.config
|
||||
this.gpsConfig = configHelper.config.gps ?? {}
|
||||
this.allRediscnx = allRediscnx
|
||||
this.debug = debug
|
||||
this.accessRights = new AccesRights(this.gpsConfig, debug)
|
||||
this.accessRights = new AccesRights(this.rootConfig, debug)
|
||||
this.agents = new Map()
|
||||
this.registry = new CollisionRegistry()
|
||||
this.arenaCnx = null
|
||||
@@ -33,33 +34,6 @@ export class gpsServer {
|
||||
this.ignoredChangeCount = 0
|
||||
}
|
||||
|
||||
getGpsSettings() {
|
||||
const gps = this.gpsConfig.gps ?? {}
|
||||
return({
|
||||
nearMissDistance: gps.nearMissDistance ?? 1,
|
||||
prismTimeHeight: gps.prismTimeHeight ?? 60,
|
||||
collisionTickMs: gps.collisionTickMs ?? 100,
|
||||
prismRefreshLeadSeconds: gps.prismRefreshLeadSeconds ?? 1,
|
||||
})
|
||||
}
|
||||
|
||||
getLifecycleSettings() {
|
||||
const gps = this.gpsConfig.gps ?? {}
|
||||
return({
|
||||
arenaChannel: gps.lifecycle?.arenaChannel ?? 'arena:lifecycle',
|
||||
godsReadyChannel: gps.lifecycle?.godsReadyChannel ?? 'arena:gods:ready',
|
||||
senderId: gps.senderId ?? 'gps',
|
||||
})
|
||||
}
|
||||
|
||||
getArenaStorageSettings() {
|
||||
const gps = this.gpsConfig.gps ?? {}
|
||||
return({
|
||||
agentHashKey: gps.arenaStorage?.agentHashKey ?? 'arena:agents:[UID]',
|
||||
agentsIndexKey: gps.arenaStorage?.agentsIndexKey ?? 'arena:agents',
|
||||
})
|
||||
}
|
||||
|
||||
isLive() {
|
||||
return(this.state === SimState.LIVE)
|
||||
}
|
||||
@@ -103,7 +77,7 @@ export class gpsServer {
|
||||
}
|
||||
|
||||
initAgentStore() {
|
||||
const gpsStorage = this.gpsConfig.gps?.GPSstorage
|
||||
const gpsStorage = this.gpsConfig.GPSstorage
|
||||
if(gpsStorage && this.systemCnx) {
|
||||
this.agentStore = new AgentStore(this.systemCnx, gpsStorage, this.debug)
|
||||
}
|
||||
@@ -114,7 +88,10 @@ export class gpsServer {
|
||||
this.arenaCnxs.push(cnx)
|
||||
if(!this.arenaCnx || cnx.redisConfig.role === 'primary') {
|
||||
this.arenaCnx = cnx
|
||||
this.arenaLoader = new ArenaAgentLoader(cnx, this.getArenaStorageSettings(), this.debug)
|
||||
const arenaStorage = this.gpsConfig.arenaStorage
|
||||
if(arenaStorage) {
|
||||
this.arenaLoader = new ArenaAgentLoader(cnx, arenaStorage, this.debug)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +171,7 @@ export class gpsServer {
|
||||
}
|
||||
|
||||
runInitialPairScan() {
|
||||
const { nearMissDistance, prismTimeHeight } = this.getGpsSettings()
|
||||
const { nearMissDistance, prismTimeHeight } = this.gpsConfig
|
||||
const ids = [...this.agents.keys()]
|
||||
for(let i = 0; i < ids.length; i++) {
|
||||
for(let j = i + 1; j < ids.length; j++) {
|
||||
@@ -213,10 +190,9 @@ export class gpsServer {
|
||||
|
||||
async publishReadyToStart(result) {
|
||||
if(!this.arenaCnx) return
|
||||
const { godsReadyChannel, senderId } = this.getLifecycleSettings()
|
||||
await this.arenaCnx.redisPublish(godsReadyChannel, {
|
||||
await this.arenaCnx.redisPublish(this.gpsConfig.lifecycle.godsReadyChannel, {
|
||||
eventType: 'readyToStart',
|
||||
sender: senderId,
|
||||
sender: this.gpsConfig.senderId,
|
||||
payload: {
|
||||
success: result.success,
|
||||
simulationId: this.simulationId,
|
||||
@@ -370,7 +346,7 @@ export class gpsServer {
|
||||
const agent = this.agents.get(agentId)
|
||||
if(!agent) return(false)
|
||||
|
||||
const { prismTimeHeight, prismRefreshLeadSeconds } = this.getGpsSettings()
|
||||
const { prismTimeHeight, prismRefreshLeadSeconds } = this.gpsConfig
|
||||
const now = this.now()
|
||||
if(!needsPrismRefresh(agent, now, prismTimeHeight, prismRefreshLeadSeconds)) return(false)
|
||||
|
||||
@@ -390,7 +366,7 @@ export class gpsServer {
|
||||
const changed = this.agents.get(changedAgentId)
|
||||
if(!changed) return([])
|
||||
|
||||
const { nearMissDistance, prismTimeHeight } = this.getGpsSettings()
|
||||
const { nearMissDistance, prismTimeHeight } = this.gpsConfig
|
||||
const now = this.now()
|
||||
const hits = []
|
||||
for(const [otherId, other] of this.agents) {
|
||||
@@ -459,14 +435,14 @@ export class gpsServer {
|
||||
|
||||
async publishProximityBatch(targetAgentId, pairs) {
|
||||
if(!this.arenaCnx || !pairs.length) return
|
||||
const chan = this.arenaCnx.config.gps.collisionsChannel.replace(/\[UID\]/g, targetAgentId)
|
||||
const chan = this.gpsConfig.collisionsChannel.replace(/\[UID\]/g, targetAgentId)
|
||||
await this.arenaCnx.redisPublish(chan, {
|
||||
eventType: 'proximity',
|
||||
payload: {
|
||||
pairs,
|
||||
simulationId: this.simulationId,
|
||||
},
|
||||
sender: this.getLifecycleSettings().senderId,
|
||||
sender: this.gpsConfig.senderId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -491,12 +467,12 @@ export class gpsServer {
|
||||
|
||||
async reloadAccessRights() {
|
||||
await this.configHelper.refreshAccessRights()
|
||||
this.gpsConfig.accessRights = this.configHelper.config.accessRights
|
||||
this.accessRights.refreshAccessRights(this.gpsConfig)
|
||||
this.rootConfig.accessRights = this.configHelper.config.accessRights
|
||||
this.accessRights.refreshAccessRights(this.rootConfig)
|
||||
}
|
||||
|
||||
getAccessRights() {
|
||||
return(this.gpsConfig.accessRights)
|
||||
return(this.rootConfig.accessRights)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
export const eventHandlers = {
|
||||
'arena:agents:*': {
|
||||
change(msg, chan) {
|
||||
change(msg, chan, sender, cnxId) {
|
||||
const agentId = msg.sender
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
console.warn(`[${this.redisId}] Agent event without sender`)
|
||||
@@ -15,7 +15,7 @@ export const eventHandlers = {
|
||||
const newPosition = msg.payload?.newPosition ?? null
|
||||
this.gpsSrv?.onVectorChange(agentId, newVector, newPosition)
|
||||
},
|
||||
remove(msg, chan) {
|
||||
remove(msg, chan, sender, cnxId) {
|
||||
const agentId = msg.sender
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
console.warn(`[${this.redisId}] Agent event without sender`)
|
||||
|
||||
@@ -10,7 +10,7 @@ export const dispatchMessage = createDispatchMessage({
|
||||
eventHandlers,
|
||||
actionRules(redisCnx) {
|
||||
const gps = redisCnx.config.gps ?? {}
|
||||
const arenaChannel = gps.bus?.arena?.actionsChannel
|
||||
const arenaChannel = gps.arenaActionsChannel
|
||||
return({
|
||||
channels: arenaChannel ? [arenaChannel] : [],
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
export function construct(redisCnx) {
|
||||
const tickMs = redisCnx.gpsSrv?.getGpsSettings().collisionTickMs ?? 100
|
||||
const tickMs = redisCnx.gpsSrv?.gpsConfig.collisionTickMs ?? 100
|
||||
setInterval(() => {
|
||||
redisCnx.gpsSrv?.tickArena()
|
||||
}, tickMs)
|
||||
@@ -8,7 +8,7 @@ export function construct(redisCnx) {
|
||||
|
||||
export const eventHandlers = {
|
||||
'arena:lifecycle': {
|
||||
onYourMarks(msg, chan) {
|
||||
onYourMarks(msg, chan, sender, cnxId) {
|
||||
const srv = this.gpsSrv
|
||||
if(!srv) return
|
||||
srv.onYourMarks(msg.payload ?? {}).catch(err => {
|
||||
@@ -16,16 +16,16 @@ export const eventHandlers = {
|
||||
srv.publishReadyToStart({ success: false, err: err.message ?? 'onYourMarks failed' })
|
||||
})
|
||||
},
|
||||
bigBang(msg, chan) {
|
||||
bigBang(msg, chan, sender, cnxId) {
|
||||
this.gpsSrv?.onBigBang(msg.payload ?? {})
|
||||
},
|
||||
simulationPaused(msg, chan) {
|
||||
simulationPaused(msg, chan, sender, cnxId) {
|
||||
this.gpsSrv?.onSimulationPaused(msg.payload ?? {})
|
||||
},
|
||||
simulationResumed(msg, chan) {
|
||||
simulationResumed(msg, chan, sender, cnxId) {
|
||||
this.gpsSrv?.onSimulationResumed(msg.payload ?? {})
|
||||
},
|
||||
simulationStopped(msg, chan) {
|
||||
simulationStopped(msg, chan, sender, cnxId) {
|
||||
const srv = this.gpsSrv
|
||||
if(!srv) return
|
||||
srv.onSimulationStopped(msg.payload ?? {}).catch(err => {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const dispatchMessage = createDispatchMessage({
|
||||
actionRules(redisCnx) {
|
||||
const gps = redisCnx.config.gps ?? {}
|
||||
return({
|
||||
channels: [gps.gpsActionsChannel].filter(Boolean),
|
||||
channels: [gps.ActionsChannel].filter(Boolean),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -2,11 +2,12 @@ import { replyToAction } from '../../../bus/publishActionReply.js'
|
||||
|
||||
export const actions = {
|
||||
|
||||
async action_TIME(action, payload, reqid, sender, roles) {
|
||||
async action_TIME(action, payload, reqid, sender, cnxId, roles) {
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: {
|
||||
gpsTime: new Date().toISOString(),
|
||||
@@ -15,16 +16,17 @@ export const actions = {
|
||||
})
|
||||
},
|
||||
|
||||
async action_RELOADCONFIG(action, payload, reqid, sender, roles) {
|
||||
async action_RELOADCONFIG(action, payload, reqid, sender, cnxId, roles) {
|
||||
this.reloadAccessRights()
|
||||
replyToAction(this, { action, reqid, sender, success: true })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: true })
|
||||
},
|
||||
|
||||
async action_GETCONFIG(action, payload, reqid, sender, roles) {
|
||||
async action_GETCONFIG(action, payload, reqid, sender, cnxId, roles) {
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: this.getAccessRights(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user