Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PcapWriter's output directory configurable. #2103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package org.jitsi.nlj.transform.node

import org.jitsi.config.JitsiConfig
import org.jitsi.metaconfig.config
import org.jitsi.metaconfig.from
import org.jitsi.nlj.PacketInfo
import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.logging2.cinfo
Expand All @@ -32,12 +35,16 @@ import org.pcap4j.packet.namednumber.IpVersion
import org.pcap4j.packet.namednumber.UdpPort
import org.pcap4j.util.MacAddress
import java.net.Inet4Address
import java.nio.file.Path
import java.util.Random
import kotlin.io.path.Path

class PcapWriter(
parentLogger: Logger,
filePath: String = "/tmp/${Random().nextLong()}.pcap"
filePath: Path = Path(directory, "${Random().nextLong()}.pcap")
) : ObserverNode("PCAP writer") {
constructor(parentLogger: Logger, filePath: String) : this(parentLogger, Path(filePath))

private val logger = createChildLogger(parentLogger)
private val lazyHandle = lazy {
Pcaps.openDead(DataLinkType.EN10MB, 65536)
Expand All @@ -46,13 +53,14 @@ class PcapWriter(

private val lazyWriter = lazy {
logger.cinfo { "Pcap writer writing to file $filePath" }
handle.dumpOpen(filePath)
handle.dumpOpen(filePath.toString())
}

private val writer by lazyWriter

companion object {
private val localhost = Inet4Address.getByName("127.0.0.1") as Inet4Address
val directory: String by config("jmt.debug.pcap.directory".from(JitsiConfig.newConfig))
}

override fun observe(packetInfo: PacketInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jitsi.metaconfig.from
import org.jitsi.nlj.PacketInfo
import org.jitsi.utils.logging2.Logger
import java.util.Date
import kotlin.io.path.Path

class ToggleablePcapWriter(
private val parentLogger: Logger,
Expand All @@ -36,7 +37,7 @@ class ToggleablePcapWriter(

synchronized(pcapLock) {
if (pcapWriter == null) {
pcapWriter = PcapWriter(parentLogger, "/tmp/$prefix-${Date().toInstant()}.pcap")
pcapWriter = PcapWriter(parentLogger, Path(PcapWriter.directory, "$prefix-${Date().toInstant()}.pcap"))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions jitsi-media-transform/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ jmt {
// Whether to permit the API to dynamically enable the capture of
// unencrypted PCAP files of media traffic.
enabled=false
// The directory in which to place captured PCAP files.
directory="/tmp"
}
packet-loss {
// Artificial loss to introduce in the receive pipeline.
Expand Down
Loading