mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-12 17:10:54 +00:00
Merge pull request #230 from riking/singleflight
Add debug prints for hello failures
This commit is contained in:
commit
18aa5855d5
4 changed files with 37 additions and 13 deletions
|
@ -110,44 +110,62 @@ func callHandler(handler CommandHandler, conn *websocket.Conn, client *ClientInf
|
||||||
return handler(conn, client, cmsg)
|
return handler(conn, client, cmsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DebugHello = ""
|
||||||
|
|
||||||
// C2SHello implements the `hello` C2S Command.
|
// C2SHello implements the `hello` C2S Command.
|
||||||
// It calls SubscribeGlobal() and SubscribeDefaults() with the client, and fills out ClientInfo.Version and ClientInfo.ClientID.
|
// It calls SubscribeGlobal() and SubscribeDefaults() with the client, and fills out ClientInfo.Version and ClientInfo.ClientID.
|
||||||
func C2SHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
func C2SHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||||
ary, ok := msg.Arguments.([]interface{})
|
ary, ok := msg.Arguments.([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if DebugHello != "" {
|
||||||
|
fmt.Println("Hello error: was not an array:", ary)
|
||||||
|
}
|
||||||
err = ErrExpectedTwoStrings
|
err = ErrExpectedTwoStrings
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(ary) != 2 {
|
if len(ary) != 2 {
|
||||||
|
if DebugHello != "" {
|
||||||
|
fmt.Println("Hello error: array wrong length:", ary)
|
||||||
|
}
|
||||||
err = ErrExpectedTwoStrings
|
err = ErrExpectedTwoStrings
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
version, ok := ary[0].(string)
|
version, ok := ary[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if DebugHello != "" {
|
||||||
|
fmt.Println("Hello error: version not a string:", ary)
|
||||||
|
}
|
||||||
err = ErrExpectedTwoStrings
|
err = ErrExpectedTwoStrings
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client.VersionString = copyString(version)
|
var clientID uuid.UUID
|
||||||
client.Version = VersionFromString(version)
|
|
||||||
|
|
||||||
if clientIDStr, ok := ary[1].(string); ok {
|
if clientIDStr, ok := ary[1].(string); ok {
|
||||||
client.ClientID = uuid.FromStringOrNil(clientIDStr)
|
clientID = uuid.FromStringOrNil(clientIDStr)
|
||||||
if client.ClientID == uuid.Nil {
|
if clientID == uuid.Nil {
|
||||||
client.ClientID = uuid.NewV4()
|
clientID = uuid.NewV4()
|
||||||
}
|
}
|
||||||
} else if _, ok := ary[1].(bool); ok {
|
} else if _, ok := ary[1].(bool); ok {
|
||||||
// opt out
|
// opt out
|
||||||
client.ClientID = AnonymousClientID
|
clientID = AnonymousClientID
|
||||||
} else if ary[1] == nil {
|
} else if ary[1] == nil {
|
||||||
client.ClientID = uuid.NewV4()
|
clientID = uuid.NewV4()
|
||||||
} else {
|
} else {
|
||||||
|
if DebugHello != "" {
|
||||||
|
fmt.Println("Hello error: client id not acceptable:", ary)
|
||||||
|
}
|
||||||
err = ErrExpectedTwoStrings
|
err = ErrExpectedTwoStrings
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueUserChannel <- client.ClientID
|
client.Mutex.Lock()
|
||||||
|
client.ClientID = clientID
|
||||||
|
client.VersionString = copyString(version)
|
||||||
|
client.Version = VersionFromString(version)
|
||||||
|
client.HelloOK = true
|
||||||
|
client.Mutex.Unlock()
|
||||||
|
|
||||||
|
uniqueUserChannel <- client.ClientID
|
||||||
SubscribeGlobal(client)
|
SubscribeGlobal(client)
|
||||||
|
|
||||||
jsTime := float64(time.Now().UnixNano()/1000) / 1000
|
jsTime := float64(time.Now().UnixNano()/1000) / 1000
|
||||||
|
|
|
@ -336,7 +336,9 @@ func RunSocketConnection(conn *websocket.Conn) {
|
||||||
|
|
||||||
conn.SetPongHandler(func(pongBody string) error {
|
conn.SetPongHandler(func(pongBody string) error {
|
||||||
client.Mutex.Lock()
|
client.Mutex.Lock()
|
||||||
client.pingCount = 0
|
if client.HelloOK { // do not accept PONGs until hello sent
|
||||||
|
client.pingCount = 0
|
||||||
|
}
|
||||||
client.Mutex.Unlock()
|
client.Mutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -430,7 +432,7 @@ func runSocketWriter(conn *websocket.Conn, client *ClientInfo, errorChan <-chan
|
||||||
}
|
}
|
||||||
|
|
||||||
case msg := <-clientChan:
|
case msg := <-clientChan:
|
||||||
if client.VersionString == "" && msg.Command != HelloCommand {
|
if !client.HelloOK && msg.Command != HelloCommand {
|
||||||
return CloseFirstMessageNotHello
|
return CloseFirstMessageNotHello
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ type StatsData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentClientCount uint64
|
CurrentClientCount uint64
|
||||||
|
LiveClientCount uint64
|
||||||
|
|
||||||
PubSubChannelCount int
|
PubSubChannelCount int
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ func commandCounter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatsDataVersion is the version of the StatsData struct.
|
// StatsDataVersion is the version of the StatsData struct.
|
||||||
const StatsDataVersion = 6
|
const StatsDataVersion = 7
|
||||||
const pageSize = 4096
|
const pageSize = 4096
|
||||||
|
|
||||||
var cpuUsage struct {
|
var cpuUsage struct {
|
||||||
|
@ -152,7 +153,7 @@ func updatePeriodicStats() {
|
||||||
|
|
||||||
GlobalSubscriptionLock.RLock()
|
GlobalSubscriptionLock.RLock()
|
||||||
|
|
||||||
Statistics.CurrentClientCount = uint64(len(GlobalSubscriptionInfo))
|
Statistics.LiveClientCount = uint64(len(GlobalSubscriptionInfo))
|
||||||
versions := make(map[string]uint64)
|
versions := make(map[string]uint64)
|
||||||
for _, v := range GlobalSubscriptionInfo {
|
for _, v := range GlobalSubscriptionInfo {
|
||||||
versions[v.VersionString]++
|
versions[v.VersionString]++
|
||||||
|
|
|
@ -89,6 +89,9 @@ type ClientInfo struct {
|
||||||
|
|
||||||
Version ClientVersion
|
Version ClientVersion
|
||||||
|
|
||||||
|
// Set after a successful hello message.
|
||||||
|
HelloOK bool
|
||||||
|
|
||||||
// This mutex protects writable data in this struct.
|
// This mutex protects writable data in this struct.
|
||||||
// If it seems to be a performance problem, we can split this.
|
// If it seems to be a performance problem, we can split this.
|
||||||
Mutex sync.Mutex
|
Mutex sync.Mutex
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue