mirror of
https://github.com/mollyim/mollyim-insider-android.git
synced 2025-05-13 05:40:53 +01:00
Remove unused 'tools' module from build-logic
This commit is contained in:
parent
194892e885
commit
4a90efe47a
5 changed files with 0 additions and 180 deletions
|
@ -21,7 +21,6 @@ dependencies {
|
|||
implementation(libs.kotlin.gradle.plugin)
|
||||
implementation(libs.android.library)
|
||||
implementation(libs.android.application)
|
||||
implementation(project(":tools"))
|
||||
|
||||
// These allow us to reference the dependency catalog inside of our compiled plugins
|
||||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
|
|
|
@ -18,6 +18,5 @@ dependencyResolutionManagement {
|
|||
rootProject.name = "build-logic"
|
||||
|
||||
include(":plugins")
|
||||
include(":tools")
|
||||
|
||||
apply(from = "../dependencies.gradle.kts")
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
plugins {
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("java-library")
|
||||
}
|
||||
|
||||
val signalJavaVersion: JavaVersion by rootProject.extra
|
||||
|
||||
java {
|
||||
sourceCompatibility = signalJavaVersion
|
||||
targetCompatibility = signalJavaVersion
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(gradleApi())
|
||||
|
||||
implementation(libs.dnsjava)
|
||||
testImplementation(testLibs.junit.junit)
|
||||
testImplementation(testLibs.mockk)
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package org.signal.buildtools
|
||||
|
||||
import org.xbill.DNS.ARecord
|
||||
import org.xbill.DNS.Lookup
|
||||
import org.xbill.DNS.Record
|
||||
import org.xbill.DNS.SimpleResolver
|
||||
import org.xbill.DNS.Type
|
||||
import java.net.UnknownHostException
|
||||
import kotlin.streams.toList
|
||||
|
||||
/**
|
||||
* A tool to resolve hostname to static IPs.
|
||||
* Feeds into our custom DNS resolver to provide a static IP fallback for our services.
|
||||
*/
|
||||
class StaticIpResolver @JvmOverloads constructor(
|
||||
private val recordFetcher: RecordFetcher = RealRecordFetcher
|
||||
) {
|
||||
|
||||
/**
|
||||
* Resolves a hostname to a list of IPs, represented as a Java array declaration. e.g.
|
||||
*
|
||||
* ```java
|
||||
* new String[]{"192.168.1.1", "192.168.1.2"}
|
||||
* ```
|
||||
*
|
||||
* This is intended to be injected as a BuildConfig.
|
||||
*/
|
||||
fun resolveToBuildConfig(hostName: String): String {
|
||||
val ips: List<String> = resolve(hostName)
|
||||
val builder = StringBuilder()
|
||||
|
||||
builder.append("new String[]{")
|
||||
|
||||
ips.forEachIndexed { i, ip ->
|
||||
builder.append("\"").append(ip).append("\"")
|
||||
|
||||
if (i < ips.size - 1) {
|
||||
builder.append(",")
|
||||
}
|
||||
}
|
||||
|
||||
return builder.append("}").toString()
|
||||
}
|
||||
|
||||
private fun resolve(hostname: String): List<String> {
|
||||
val ips: MutableSet<String> = mutableSetOf()
|
||||
|
||||
// Run several resolves to mitigate DNS round robin
|
||||
for (i in 1..10) {
|
||||
ips.addAll(resolveOnce(hostname))
|
||||
}
|
||||
|
||||
return ips.stream().sorted().toList()
|
||||
}
|
||||
|
||||
private fun resolveOnce(hostName: String): List<String> {
|
||||
try {
|
||||
val records = recordFetcher.fetchRecords(hostName)
|
||||
if (records != null) {
|
||||
return records
|
||||
.filter { it.type == Type.A }
|
||||
.map { it as ARecord }
|
||||
.map { it.address }
|
||||
.map { it.hostAddress }
|
||||
.filterNotNull()
|
||||
} else {
|
||||
throw IllegalStateException("Failed to resolve host! Lookup did not return any records.. $hostName")
|
||||
}
|
||||
} catch (e: UnknownHostException) {
|
||||
throw IllegalStateException("Failed to resolve host! $hostName", e)
|
||||
}
|
||||
}
|
||||
|
||||
interface RecordFetcher {
|
||||
fun fetchRecords(hostName: String): Array<Record>?
|
||||
}
|
||||
|
||||
private object RealRecordFetcher : RecordFetcher {
|
||||
override fun fetchRecords(hostName: String): Array<Record>? {
|
||||
val resolver = SimpleResolver("1.1.1.1")
|
||||
|
||||
resolver.setTCP(true)
|
||||
|
||||
val lookup: Lookup = doLookup(hostName)
|
||||
|
||||
lookup.setResolver(resolver)
|
||||
|
||||
return lookup.run()
|
||||
}
|
||||
|
||||
@Throws(UnknownHostException::class)
|
||||
private fun doLookup(hostname: String): Lookup {
|
||||
try {
|
||||
return Lookup(hostname)
|
||||
} catch (e: Throwable) {
|
||||
throw UnknownHostException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package org.signal.buildtools
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.xbill.DNS.ARecord
|
||||
import org.xbill.DNS.DClass
|
||||
import org.xbill.DNS.Name
|
||||
import org.xbill.DNS.Record
|
||||
import java.net.Inet4Address
|
||||
|
||||
class StaticIpResolverTest {
|
||||
|
||||
companion object {
|
||||
const val SIGNAL_DOT_ORG = "www.signal.org"
|
||||
val SIGNAL_IP = byteArrayOf(123, 45, 67, 89)
|
||||
val STRINGIFIED_IP = SIGNAL_IP.joinToString(".")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a hostname with records, when I resolveToBuildConfig, then I expect a matching IP`() {
|
||||
val staticIpResolver = StaticIpResolver(
|
||||
FakeRecordFetcher(
|
||||
mapOf(
|
||||
SIGNAL_DOT_ORG to arrayOf(
|
||||
ARecord(
|
||||
Name.fromString("www."),
|
||||
DClass.ANY,
|
||||
0L,
|
||||
mockk<Inet4Address> {
|
||||
every { address } returns SIGNAL_IP
|
||||
every { hostAddress } returns STRINGIFIED_IP
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
val actual = staticIpResolver.resolveToBuildConfig(SIGNAL_DOT_ORG)
|
||||
val expected = """
|
||||
new String[]{"$STRINGIFIED_IP"}
|
||||
""".trimIndent()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun `Given a hostname without records, when I resolveToBuildConfig, then I expect`() {
|
||||
val staticIpResolver = StaticIpResolver(FakeRecordFetcher(emptyMap()))
|
||||
staticIpResolver.resolveToBuildConfig(SIGNAL_DOT_ORG)
|
||||
}
|
||||
|
||||
private class FakeRecordFetcher(private val recordMap: Map<String, Array<Record>?>) : StaticIpResolver.RecordFetcher {
|
||||
override fun fetchRecords(hostName: String): Array<Record>? {
|
||||
return recordMap[hostName]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue