-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigByeFuncs.go
43 lines (37 loc) · 1007 Bytes
/
configByeFuncs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package shoset
import (
// "fmt"
"github.com/ditrit/shoset/msg"
)
// GetConfigBye :
func GetConfigBye(c *ShosetConn) (msg.Message, error) {
var cfg msg.ConfigProtocol
err := c.ReadMessage(&cfg)
return cfg, err
}
// HandleConfigBye :
func HandleConfigBye(c *ShosetConn, message msg.Message) error {
cfg := message.(msg.ConfigProtocol) // compute config from message
ch := c.GetCh()
dir := c.GetDir()
remoteAddress := cfg.GetAddress()
switch cfg.GetCommandName() {
case "bye":
if dir == "in" {
cfgNewDelete := msg.NewCfg(remoteAddress, ch.GetLogicalName(), ch.GetShosetType(), "delete")
ch.ConnsByName.IterateAll(
func(address string, bro *ShosetConn) {
if address != remoteAddress {
bro.SendMessage(cfgNewDelete)
}
},
)
c.SetIsValid(false)
}
case "delete":
ch.LnamesByProtocol.Set("bye", cfg.GetLogicalName())
ch.LnamesByType.Set(cfg.GetShosetType(), cfg.GetLogicalName())
ch.deleteConn(cfg.GetAddress(), cfg.GetLogicalName())
}
return nil
}