mirror of
https://github.com/cbeuw/Cloak.git
synced 2024-11-17 15:25:30 +00:00
Allow an terminal message to be set as a session terminates
This commit is contained in:
parent
299f08270c
commit
9b552f55a4
@ -186,7 +186,7 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
|
||||
newStream, err := sesh.Accept()
|
||||
if err != nil {
|
||||
if err == mux.ErrBrokenSession {
|
||||
log.Printf("Session closed for UID:%v, sessionID:%v\n", b64.EncodeToString(UID), sessionID)
|
||||
log.Printf("Session closed for UID:%v, sessionID:%v, reason:%v\n", b64.EncodeToString(UID), sessionID, sesh.TerminalMsg())
|
||||
user.DelSession(sessionID)
|
||||
return
|
||||
} else {
|
||||
|
@ -41,6 +41,8 @@ type Session struct {
|
||||
broken uint32
|
||||
die chan struct{}
|
||||
suicide sync.Once
|
||||
|
||||
terminalMsg atomic.Value
|
||||
}
|
||||
|
||||
func MakeSession(id uint32, valve *Valve, obfs Obfser, deobfs Deobfser, obfsedRead func(net.Conn, []byte) (int, error)) *Session {
|
||||
@ -124,6 +126,19 @@ func (sesh *Session) getStream(id uint32, closingFrame bool) *Stream {
|
||||
}
|
||||
}
|
||||
|
||||
func (sesh *Session) SetTerminalMsg(msg string) {
|
||||
sesh.terminalMsg.Store(msg)
|
||||
}
|
||||
|
||||
func (sesh *Session) TerminalMsg() string {
|
||||
msg := sesh.terminalMsg.Load()
|
||||
if msg != nil {
|
||||
return msg.(string)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (sesh *Session) Close() error {
|
||||
// Because closing a closed channel causes panic
|
||||
sesh.suicide.Do(func() { close(sesh.die) })
|
||||
|
Loading…
Reference in New Issue
Block a user