From 8bc493fcd952b07de69df25bd21201d619dc5627 Mon Sep 17 00:00:00 2001 From: bgrozev Date: Tue, 10 Dec 2024 14:52:08 -0600 Subject: [PATCH] feat: Update jigasi detection (#1200) * fix: Require trusted domain for jigasi. * ref: Remove the "robot" flag. --- .../jitsi/jicofo/xmpp/muc/ChatRoomMember.kt | 1 - .../jicofo/xmpp/muc/ChatRoomMemberImpl.kt | 55 +++++++------------ .../jicofo/xmpp/muc/ChatRoomRoleManager.kt | 4 +- .../jitsi/jicofo/jibri/JibriDetectorTest.kt | 1 - 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMember.kt b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMember.kt index 0dd156b2a5..924ef0a892 100644 --- a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMember.kt +++ b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMember.kt @@ -53,7 +53,6 @@ interface ChatRoomMember { /** The last [Presence] packet received for this member (or null it if no presence has been received yet) */ val presence: Presence? - val isRobot: Boolean val isJigasi: Boolean val isTranscriber: Boolean val isJibri: Boolean diff --git a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMemberImpl.kt b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMemberImpl.kt index b4c54c8427..49aa6b4233 100644 --- a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMemberImpl.kt +++ b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomMemberImpl.kt @@ -32,7 +32,6 @@ import org.jitsi.xmpp.extensions.jitsimeet.JitsiParticipantRegionPacketExtension import org.jitsi.xmpp.extensions.jitsimeet.StartMutedPacketExtension import org.jitsi.xmpp.extensions.jitsimeet.StatsId import org.jitsi.xmpp.extensions.jitsimeet.TranscriptionStatusExtension -import org.jitsi.xmpp.extensions.jitsimeet.UserInfoPacketExt import org.jitsi.xmpp.extensions.jitsimeet.VideoMutedExtension import org.jivesoftware.smack.packet.Presence import org.jivesoftware.smack.packet.StandardExtensionElement @@ -98,13 +97,6 @@ class ChatRoomMemberImpl( } private set - private var robot = false - override val isRobot: Boolean - get() { - // Jigasi and Jibri do not use the "robot" signaling, but semantically they should be considered "robots". - return robot || isJigasi || isJibri - } - private fun updateSourceInfo(presence: Presence) { val sourceInfo = presence.getExtension("SourceInfo", "jabber:client") if (sourceInfo == null) { @@ -156,13 +148,6 @@ class ChatRoomMemberImpl( val firstPresence = (this.presence == null) this.presence = presence - presence.getExtension(UserInfoPacketExt::class.java)?.let { - val newStatus = it.isRobot - if (newStatus != null && robot != newStatus) { - logger.debug { "robot: $robot" } - robot = newStatus - } - } presence.getExtension(CapsExtension::class.java)?.let { capsNodeVer = "${it.node}#${it.ver}" @@ -173,17 +158,25 @@ class ChatRoomMemberImpl( // We recognize jigasi by the existence of a "feature" extension in its presence. val features = presence.getExtension(FeaturesExtension::class.java) if (features != null) { - isJigasi = features.featureExtensions.any { it.`var` == "http://jitsi.org/protocol/jigasi" } - if (features.featureExtensions.any { it.`var` == "http://jitsi.org/protocol/jibri" }) { - isJibri = isJidTrusted().also { - if (!it) { - val domain = jid?.asDomainBareJid() - logger.warn( - "Jibri signaled from a non-trusted domain ($domain). The domain can be " + - "configured as trusted with the jicofo.xmpp.trusted-domains property." - ) - } - } + val domain = jid?.asDomainBareJid() + val jidTrusted = domain != null && XmppConfig.config.trustedDomains.contains(domain) + val jibriSignaled = features.featureExtensions.any { it.`var` == "http://jitsi.org/protocol/jibri" } + val jigasiSignaled = features.featureExtensions.any { it.`var` == "http://jitsi.org/protocol/jigasi" } + + isJibri = jibriSignaled && jidTrusted + isJigasi = jigasiSignaled && jidTrusted + + if (jibriSignaled && !jidTrusted) { + logger.warn( + "Jibri signaled from a non-trusted domain ($domain). The domain can be " + + "configured as trusted with the jicofo.xmpp.trusted-domains property." + ) + } + if (jigasiSignaled && !jidTrusted) { + logger.warn( + "Jigasi signaled from a non-trusted domain ($domain). The domain can be " + + "configured as trusted with the jicofo.xmpp.trusted-domains property." + ) } } else { isJigasi = false @@ -248,14 +241,6 @@ class ChatRoomMemberImpl( } } - /** - * Whether this member is a trusted entity (logged in to one of the pre-configured trusted domains). - */ - private fun isJidTrusted() = jid?.let { XmppConfig.config.trustedDomains.contains(it.asDomainBareJid()) } ?: false - - /** - * {@inheritDoc} - */ override fun toString() = "ChatMember[id=$name role=$role]" override val features: Set by lazy { @@ -273,9 +258,9 @@ class ChatRoomMemberImpl( this["region"] = region.toString() this["occupant_jid"] = occupantJid.toString() this["jid"] = jid.toString() - this["robot"] = robot this["is_jibri"] = isJibri this["is_jigasi"] = isJigasi + this["is_transcriber"] = isTranscriber this["role"] = role.toString() this["video_codecs"] = JSONArray().apply { videoCodecs?.let { addAll(it) } } this["stats_id"] = statsId.toString() diff --git a/jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomRoleManager.kt b/jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomRoleManager.kt index 6506e5b5db..0b0f96ccca 100644 --- a/jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomRoleManager.kt +++ b/jicofo/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomRoleManager.kt @@ -91,12 +91,12 @@ class AutoOwnerRoleManager(chatRoom: ChatRoom) : ChatRoomRoleManager(chatRoom) { return@add } - owner = chatRoom.members.find { !it.isRobot && it.role.hasOwnerRights() } + owner = chatRoom.members.find { !(it.isJibri || it.isJigasi) && it.role.hasOwnerRights() } if (owner != null) { return@add } - val newOwner = chatRoom.members.find { !it.isRobot && it.role != MemberRole.VISITOR } + val newOwner = chatRoom.members.find { !(it.isJibri || it.isJigasi) && it.role != MemberRole.VISITOR } if (newOwner != null) { logger.info("Electing new owner: $newOwner") chatRoom.grantOwnership(newOwner) diff --git a/jicofo/src/test/kotlin/org/jitsi/jicofo/jibri/JibriDetectorTest.kt b/jicofo/src/test/kotlin/org/jitsi/jicofo/jibri/JibriDetectorTest.kt index 820e4f0550..8ba99b0c26 100644 --- a/jicofo/src/test/kotlin/org/jitsi/jicofo/jibri/JibriDetectorTest.kt +++ b/jicofo/src/test/kotlin/org/jitsi/jicofo/jibri/JibriDetectorTest.kt @@ -136,7 +136,6 @@ class JibriChatRoomMember( override val name: String get() = TODO("Not yet implemented") override val jid: Jid? get() = TODO("Not yet implemented") override val sourceInfos: Set get() = TODO("Not yet implemented") - override val isRobot: Boolean get() = TODO("Not yet implemented") override val isJigasi: Boolean get() = TODO("Not yet implemented") override val isTranscriber: Boolean get() = TODO("Not yet implemented") override val isJibri: Boolean get() = TODO("Not yet implemented")