Skip to content

Commit

Permalink
Make hostname optional since resolving hostname will cause Local Netw…
Browse files Browse the repository at this point in the history
…ork permissions dialog to appear (#69)
  • Loading branch information
rqbacktrace authored Nov 17, 2021
1 parent 02ca106 commit e6701d5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/Features/Attributes/AttributesProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ final class AttributesProvider {
return attributesSources.map(\.immutable).merging()
}()

init() {
init(reportHostName: Bool = false) {
faultInfo = FaultInfo()
attributesSources = [ProcessorInfo(),
attributesSources = [ProcessorInfo(reportHostName: reportHostName),
Device(),
ScreenInfo(),
LocaleInfo(),
Expand Down
10 changes: 8 additions & 2 deletions Sources/Features/Attributes/DefaultAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ final class FaultInfo: AttributesSource {

struct ProcessorInfo: AttributesSource {

private let reportHostName: Bool

init(reportHostName: Bool = false) {
self.reportHostName = reportHostName
}

var mutable: [String: Any?] {
let processor = try? Processor()
let processInfo = ProcessInfo.processInfo
Expand Down Expand Up @@ -55,8 +61,8 @@ struct ProcessorInfo: AttributesSource {
var immutable: [String: Any?] {
return [
"cpu.boottime": try? System.boottime(),
// hostanme
"hostname": ProcessInfo.processInfo.hostName,
// hostname
"hostname": self.reportHostName ? ProcessInfo.processInfo.hostName : "",
// descriptor
"descriptor.count": getdtablesize(),
"process.starttime": try? ProcessInfo.startTime()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Features/Client/BacktraceReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class BacktraceReporter {
credentials: credentials,
repository: try PersistentRepository<BacktraceReport>(settings: dbSettings))
self.repository = try PersistentRepository<BacktraceReport>(settings: dbSettings)
let attributesProvider = AttributesProvider()
let attributesProvider = AttributesProvider(reportHostName: dbSettings.reportHostName)
self.attributesProvider = attributesProvider
self.backtraceOomWatcher = BacktraceOomWatcher(
repository: self.repository,
Expand Down
3 changes: 3 additions & 0 deletions Sources/Public/BacktraceDatabaseSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import Foundation

/// Retry order. Default `RetryOder.queue`.
@objc public var retryOrder: RetryOrder = .queue

/// Enable the hostname to be reported. This will cause the end-user to get the Local Network permissions pop-up.
@objc public var reportHostName: Bool = false

internal var maxDatabaseSizeInBytes: Int {
return maxDatabaseSize * 1024 * 1024
Expand Down
15 changes: 14 additions & 1 deletion Tests/AttributesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ final class AttributesTests: QuickSpec {
expect { attributes.immutable }.toNot(beNil())
}
}


describe("Processor Info") {
it("can disable hostname") {
let attributes = ProcessorInfo()
let hostname = attributes.immutable["hostname"] as? String
expect { hostname }.to(beEmpty())
}
it("can enable hostname") {
let attributes = ProcessorInfo(reportHostName: true)
let hostname = attributes.immutable["hostname"] as? String
expect { hostname }.toNot(beEmpty())
}
}

describe("C API") {
it("sets vm_statistics64 information") {
expect { try Statistics.vmStatistics64() }.toNot(be(vm_statistics64()))
Expand Down

0 comments on commit e6701d5

Please sign in to comment.