diff options
Diffstat (limited to 'src/papod.go')
-rw-r--r-- | src/papod.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/papod.go b/src/papod.go index 710c87c..77721d6 100644 --- a/src/papod.go +++ b/src/papod.go @@ -249,13 +249,30 @@ type metricsT struct{ sentReply func(...any) } +type stateMutableT struct{ + connected func(*connectionT) + disconnect func(*connectionT) + authenticated func(*connectionT) + subscribe func(string, []string) + members func(string) []string + connections func(string) []guuid.UUID + connection func(guuid.UUID) *connectionT +} + +// TODO: key for members should be the channelID, not its name +type stateMutableDataT struct{ + connections map[guuid.UUID]*connectionT + users map[string][]guuid.UUID + members map[string]map[string][]guuid.UUID +} + type papodT struct{ auth cracha.IAuth queue fiinha.IQueue queries queriesT listeners listenersT consumers []consumerT - state stateT + stateMutable stateMutableT metrics metricsT // logger g.Logger } @@ -3511,32 +3528,15 @@ func initListeners( }, nil } -type stateT struct{ - connected func(*connectionT) - disconnect func(*connectionT) - authenticated func(*connectionT) - subscribe func(string, []string) - members func(string) []string - connections func(string) []guuid.UUID - connection func(guuid.UUID) *connectionT -} - -// TODO: key for members should be the channelID, not its name -type stateDataT struct{ - connections map[guuid.UUID]*connectionT - users map[string][]guuid.UUID - members map[string]map[string][]guuid.UUID -} - // TODO: lock is global, should be by network -func newState() stateT { +func newStateMutable() stateMutableT { var rwmutex sync.RWMutex - state := stateDataT{ + state := stateMutableDataT{ connections: map[guuid.UUID]*connectionT{}, users: map[string][]guuid.UUID{}, members: map[string]map[string][]guuid.UUID{}, } - return stateT{ + return stateMutableT{ connected: func(connection *connectionT) { rwmutex.Lock() defer rwmutex.Unlock() @@ -3677,7 +3677,7 @@ func NewWithPrefix( } consumers := buildConsumers(prefix) - state := newState() + stateMutable := newStateMutable() // receivers := makeReceivers() metrics := buildMetrics(prefix) // logger := g.NewLogger("prefix", prefix, "program", "papod") @@ -3688,7 +3688,7 @@ func NewWithPrefix( queries: queries, listeners: listeners, consumers: consumers, - state: state, + stateMutable: stateMutable, // receivers: receivers, metrics: metrics, // logger: logger, @@ -4102,9 +4102,9 @@ func handlePRIVMSG( go broadcastMessage( msg, msg.params[0], - papod.state.members, - papod.state.connections, - papod.state.connection, + papod.stateMutable.members, + papod.stateMutable.connections, + papod.stateMutable.connection, ) return []replyT{}, false, nil } @@ -4128,7 +4128,7 @@ func handleJOIN( ) ([]replyT, bool, error) { // FIXME: add to database channels := strings.FieldsFunc(msg.params[0], splitCommas) - papod.state.subscribe(connection.user.username, channels) + papod.stateMutable.subscribe(connection.user.username, channels) return []replyT{ _RPL_NOTOPIC (connection, msg), @@ -4402,12 +4402,12 @@ func processMessage( ) } - papod.state.disconnect(connection) + papod.stateMutable.disconnect(connection) return } if shouldClose { - papod.state.disconnect(connection) + papod.stateMutable.disconnect(connection) } } |