mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-27 13:08:30 +00:00
change global sub to ClientInfo, remove ip output
This commit is contained in:
parent
3802dea35c
commit
00175cad39
4 changed files with 57 additions and 18 deletions
|
@ -353,13 +353,16 @@ func getDeadline() time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseConnection(conn *websocket.Conn, closeMsg websocket.CloseError) {
|
func CloseConnection(conn *websocket.Conn, closeMsg websocket.CloseError) {
|
||||||
Statistics.DisconnectCodes[strconv.Itoa(closeMsg.Code)]++
|
|
||||||
closeTxt := closeMsg.Text
|
closeTxt := closeMsg.Text
|
||||||
if strings.Contains(closeTxt, "read: connection reset by peer") {
|
if strings.Contains(closeTxt, "read: connection reset by peer") {
|
||||||
closeTxt = "read: connection reset by peer"
|
closeTxt = "read: connection reset by peer"
|
||||||
|
} else if strings.Contains(closeTxt, "use of closed network connection") {
|
||||||
|
closeTxt = "read: use of closed network connection"
|
||||||
} else if closeMsg.Code == 1001 {
|
} else if closeMsg.Code == 1001 {
|
||||||
closeTxt = "clean shutdown"
|
closeTxt = "clean shutdown"
|
||||||
}
|
}
|
||||||
|
// todo kibana cannot analyze these
|
||||||
|
Statistics.DisconnectCodes[strconv.Itoa(closeMsg.Code)]++
|
||||||
Statistics.DisconnectReasons[closeTxt]++
|
Statistics.DisconnectReasons[closeTxt]++
|
||||||
|
|
||||||
conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(closeMsg.Code, closeMsg.Text), getDeadline())
|
conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(closeMsg.Code, closeMsg.Text), getDeadline())
|
||||||
|
|
|
@ -119,9 +119,9 @@ func updatePeriodicStats() {
|
||||||
Statistics.PubSubChannelCount = len(ChatSubscriptionInfo)
|
Statistics.PubSubChannelCount = len(ChatSubscriptionInfo)
|
||||||
ChatSubscriptionLock.RUnlock()
|
ChatSubscriptionLock.RUnlock()
|
||||||
|
|
||||||
GlobalSubscriptionInfo.RLock()
|
GlobalSubscriptionLock.RLock()
|
||||||
Statistics.CurrentClientCount = uint64(len(GlobalSubscriptionInfo.Members))
|
Statistics.CurrentClientCount = uint64(len(GlobalSubscriptionInfo))
|
||||||
GlobalSubscriptionInfo.RUnlock()
|
GlobalSubscriptionLock.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,8 @@ type SubscriberList struct {
|
||||||
|
|
||||||
var ChatSubscriptionInfo map[string]*SubscriberList = make(map[string]*SubscriberList)
|
var ChatSubscriptionInfo map[string]*SubscriberList = make(map[string]*SubscriberList)
|
||||||
var ChatSubscriptionLock sync.RWMutex
|
var ChatSubscriptionLock sync.RWMutex
|
||||||
var GlobalSubscriptionInfo SubscriberList
|
var GlobalSubscriptionInfo []*ClientInfo
|
||||||
|
var GlobalSubscriptionLock sync.RWMutex
|
||||||
|
|
||||||
func SubscribeChannel(client *ClientInfo, channelName string) {
|
func SubscribeChannel(client *ClientInfo, channelName string) {
|
||||||
ChatSubscriptionLock.RLock()
|
ChatSubscriptionLock.RLock()
|
||||||
|
@ -29,9 +30,9 @@ func SubscribeDefaults(client *ClientInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubscribeGlobal(client *ClientInfo) {
|
func SubscribeGlobal(client *ClientInfo) {
|
||||||
GlobalSubscriptionInfo.Lock()
|
GlobalSubscriptionLock.Lock()
|
||||||
AddToSliceC(&GlobalSubscriptionInfo.Members, client.MessageChannel)
|
AddToSliceCl(&GlobalSubscriptionInfo, client)
|
||||||
GlobalSubscriptionInfo.Unlock()
|
GlobalSubscriptionLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishToChannel(channel string, msg ClientMessage) (count int) {
|
func PublishToChannel(channel string, msg ClientMessage) (count int) {
|
||||||
|
@ -75,12 +76,15 @@ func PublishToMultiple(channels []string, msg ClientMessage) (count int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishToAll(msg ClientMessage) (count int) {
|
func PublishToAll(msg ClientMessage) (count int) {
|
||||||
GlobalSubscriptionInfo.RLock()
|
GlobalSubscriptionLock.RLock()
|
||||||
for _, msgChan := range GlobalSubscriptionInfo.Members {
|
for _, client := range GlobalSubscriptionInfo {
|
||||||
msgChan <- msg
|
select {
|
||||||
|
case client.MessageChannel <- msg:
|
||||||
|
case <-client.MsgChannelIsDone:
|
||||||
|
}
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
GlobalSubscriptionInfo.RUnlock()
|
GlobalSubscriptionLock.RUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +110,9 @@ func UnsubscribeAll(client *ClientInfo) {
|
||||||
client.PendingSubscriptionsBacklog = nil
|
client.PendingSubscriptionsBacklog = nil
|
||||||
client.Mutex.Unlock()
|
client.Mutex.Unlock()
|
||||||
|
|
||||||
GlobalSubscriptionInfo.Lock()
|
GlobalSubscriptionLock.Lock()
|
||||||
RemoveFromSliceC(&GlobalSubscriptionInfo.Members, client.MessageChannel)
|
RemoveFromSliceCl(&GlobalSubscriptionInfo, client)
|
||||||
GlobalSubscriptionInfo.Unlock()
|
GlobalSubscriptionLock.Unlock()
|
||||||
|
|
||||||
ChatSubscriptionLock.RLock()
|
ChatSubscriptionLock.RLock()
|
||||||
client.Mutex.Lock()
|
client.Mutex.Lock()
|
||||||
|
@ -126,9 +130,9 @@ func UnsubscribeAll(client *ClientInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsubscribeAllClients() {
|
func unsubscribeAllClients() {
|
||||||
GlobalSubscriptionInfo.Lock()
|
GlobalSubscriptionLock.Lock()
|
||||||
GlobalSubscriptionInfo.Members = nil
|
GlobalSubscriptionInfo = nil
|
||||||
GlobalSubscriptionInfo.Unlock()
|
GlobalSubscriptionLock.Unlock()
|
||||||
ChatSubscriptionLock.Lock()
|
ChatSubscriptionLock.Lock()
|
||||||
ChatSubscriptionInfo = make(map[string]*SubscriberList)
|
ChatSubscriptionInfo = make(map[string]*SubscriberList)
|
||||||
ChatSubscriptionLock.Unlock()
|
ChatSubscriptionLock.Unlock()
|
||||||
|
|
|
@ -160,6 +160,38 @@ func RemoveFromSliceC(ary *[]chan<- ClientMessage, val chan<- ClientMessage) boo
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddToSliceCl(ary *[]*ClientInfo, val *ClientInfo) bool {
|
||||||
|
slice := *ary
|
||||||
|
for _, v := range slice {
|
||||||
|
if v == val {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slice = append(slice, val)
|
||||||
|
*ary = slice
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveFromSliceCl(ary *[]*ClientInfo, val *ClientInfo) bool {
|
||||||
|
slice := *ary
|
||||||
|
var idx int = -1
|
||||||
|
for i, v := range slice {
|
||||||
|
if v == val {
|
||||||
|
idx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if idx == -1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
slice[idx] = slice[len(slice)-1]
|
||||||
|
slice = slice[:len(slice)-1]
|
||||||
|
*ary = slice
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func AddToSliceB(ary *[]bunchSubscriber, client *ClientInfo, mid int) bool {
|
func AddToSliceB(ary *[]bunchSubscriber, client *ClientInfo, mid int) bool {
|
||||||
newSub := bunchSubscriber{Client: client, MessageID: mid}
|
newSub := bunchSubscriber{Client: client, MessageID: mid}
|
||||||
slice := *ary
|
slice := *ary
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue