Register: kick out old session when number is taken

When a new session registers with an already-taken number, close the old connection. Prevents two devices from sharing the same number simultaneously.
This commit is contained in:
Niko Marmeladkov 2026-07-01 14:51:04 +03:00
parent 22e33f0e5f
commit ba79f81721

View file

@ -418,6 +418,9 @@ func marshalIdentityResponse(number string, certDER, caCertPEM []byte) []byte {
func (s *Server) Register(sess call.CallSession, number string) {
s.sessionsMu.Lock()
defer s.sessionsMu.Unlock()
if old, ok := s.sessions[number]; ok && old != sess {
old.Conn().CloseWithError(0, "replaced by new session")
}
s.sessions[number] = sess.(*Session)
}