mirror of
https://github.com/jech/galene.git
synced 2024-11-12 19:55:59 +01:00
Improve error handling.
This commit is contained in:
parent
eb6ab8aa1a
commit
75804adc5f
2 changed files with 44 additions and 16 deletions
58
client.go
58
client.go
|
@ -1215,7 +1215,16 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
if down != nil {
|
if down != nil {
|
||||||
err = negotiate(c, down)
|
err = negotiate(c, down)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("Negotiate: %v", err)
|
||||||
|
delDownConn(c, down.id)
|
||||||
|
err = failConnection(
|
||||||
|
c, down.id,
|
||||||
|
"negotiation failed",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case delConnAction:
|
case delConnAction:
|
||||||
|
@ -1241,14 +1250,11 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
case connectionFailedAction:
|
case connectionFailedAction:
|
||||||
found := delUpConn(c, a.id)
|
found := delUpConn(c, a.id)
|
||||||
if found {
|
if found {
|
||||||
c.write(clientMessage{
|
err := failConnection(c, a.id,
|
||||||
Type: "error",
|
"ICE said: connection failed")
|
||||||
Value: "connection failed",
|
if err != nil {
|
||||||
})
|
return err
|
||||||
c.write(clientMessage{
|
}
|
||||||
Type: "abort",
|
|
||||||
Id: a.id,
|
|
||||||
})
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// What should we do if a downstream
|
// What should we do if a downstream
|
||||||
|
@ -1261,11 +1267,13 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
if !c.permissions.Present {
|
if !c.permissions.Present {
|
||||||
ids := getUpConns(c)
|
ids := getUpConns(c)
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
c.write(clientMessage{
|
found := delUpConn(c, id)
|
||||||
Type: "abort",
|
if found {
|
||||||
Id: id,
|
failConnection(
|
||||||
})
|
c, id,
|
||||||
delUpConn(c, id)
|
"permission denied",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case kickAction:
|
case kickAction:
|
||||||
|
@ -1292,6 +1300,25 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func failConnection(c *client, id string, message string) error {
|
||||||
|
if id != "" {
|
||||||
|
err := c.write(clientMessage{
|
||||||
|
Type: "abort",
|
||||||
|
Id: id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if message != "" {
|
||||||
|
err := c.error(userError(message))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func handleClientMessage(c *client, m clientMessage) error {
|
func handleClientMessage(c *client, m clientMessage) error {
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case "request":
|
case "request":
|
||||||
|
@ -1312,7 +1339,8 @@ func handleClientMessage(c *client, m clientMessage) error {
|
||||||
}
|
}
|
||||||
err := gotOffer(c, m.Id, *m.Offer, m.Labels)
|
err := gotOffer(c, m.Id, *m.Offer, m.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("gotOffer: %v", err)
|
||||||
|
return failConnection(c, m.Id, "negotiation failed")
|
||||||
}
|
}
|
||||||
case "answer":
|
case "answer":
|
||||||
if m.Answer == nil {
|
if m.Answer == nil {
|
||||||
|
|
2
group.go
2
group.go
|
@ -344,7 +344,7 @@ func (c *client) error(err error) error {
|
||||||
case userError:
|
case userError:
|
||||||
return c.write(clientMessage{
|
return c.write(clientMessage{
|
||||||
Type: "error",
|
Type: "error",
|
||||||
Value: "The server said: " + string(e),
|
Value: string(e),
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue