wg-portal/internal/app/eventbus.go

85 lines
2.8 KiB
Go

package app
// region misc-events
const TopicAuthLogin = "auth:login"
const TopicRouteUpdate = "route:update"
const TopicRouteRemove = "route:remove"
// endregion misc-events
// region user-events
const TopicUserCreated = "user:created"
const TopicUserDeleted = "user:deleted"
const TopicUserUpdated = "user:updated"
const TopicUserApiEnabled = "user:api:enabled"
const TopicUserApiDisabled = "user:api:disabled"
const TopicUserRegistered = "user:registered"
const TopicUserDisabled = "user:disabled"
const TopicUserEnabled = "user:enabled"
// endregion user-events
// region interface-events
const TopicInterfaceCreated = "interface:created"
const TopicInterfaceUpdated = "interface:updated"
const TopicInterfaceDeleted = "interface:deleted"
// endregion interface-events
// region peer-events
const TopicPeerCreated = "peer:created"
const TopicPeerDeleted = "peer:deleted"
const TopicPeerUpdated = "peer:updated"
const TopicPeerInterfaceUpdated = "peer:interface:updated"
const TopicPeerIdentifierUpdated = "peer:identifier:updated"
const TopicPeerStateChanged = "peer:state:changed"
const TopicPeersExpiredRemoved = "peers:expired-removed" // Published when expired peers are deleted (batch operation)
// Event-driven sync topics - contain only peer ID for cross-node synchronization
// Nodes subscribe to these events and fetch individual peers from database instead of full sync
const TopicPeerCreatedSync = "peer:created:sync" // Contains domain.PeerIdentifier (string)
const TopicPeerUpdatedSync = "peer:updated:sync" // Contains domain.PeerIdentifier (string)
const TopicPeerDeletedSync = "peer:deleted:sync" // Contains domain.PeerIdentifier (string)
// Local sync topics - for HTTP endpoint to trigger local WireGuard sync without triggering fanout
// These are NOT fanned out to other nodes (fanout doesn't subscribe to these)
// They only trigger local WireGuard manager to sync the peer
const TopicPeerSyncedLocal = "peer:synced:local" // HTTP endpoint publishes this after fanout calls it, prevents loop
// endregion peer-events
// region audit-events
const TopicAuditLoginSuccess = "audit:login:success"
const TopicAuditLoginFailed = "audit:login:failed"
const TopicAuditInterfaceChanged = "audit:interface:changed"
const TopicAuditPeerChanged = "audit:peer:changed"
const TopicFanPeersUpdated = "peers.updated"
const TopicFanPeerSave = "peer.save"
const TopicFanPeerDelete = "peer.delete"
const TopicFanInterfaceSave = "interface.save"
const TopicFanInterfaceUpdated = "interface.updated"
// endregion audit-events
type EventPublisher interface {
Publish(topic string, args ...any)
}
type EventSubscriber interface {
Subscribe(topic string, fn interface{}) error
}
type EventBus interface {
EventPublisher
EventSubscriber
}
// Removed the SubscribeToPeerDelete function as it has been moved to peer_metrics_subscriber.go.