Fixup code style
This commit is contained in:
1 parent
525131dbaf
commit
bdbc5438aa
2 files changed
+50
-71
No files matched your search
@@ -1,24 +1,8 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.client
|
||||
|
||||
import com.hippo.ehviewer.Settings
|
||||
import okhttp3.Dns
|
||||
import java.net.InetAddress
|
||||
import java.net.UnknownHostException
|
||||
|
||||
private typealias HostsMap = MutableMap<String, List<InetAddress>>
|
||||
private fun hostsDsl(builder: HostsMap.() -> Unit): HostsMap = mutableMapOf<String, List<InetAddress>>().apply(builder)
|
||||
@@ -37,61 +21,56 @@ private fun HostsMap.hosts(vararg hosts: String, builder: HostMapBuilder.() -> U
|
||||
}
|
||||
|
||||
object EhDns : Dns {
|
||||
private val builtInHosts = hostsDsl {
|
||||
// ip: String!, blockedByCCP: Boolean!
|
||||
hosts("ehgt.org", "gt0.ehgt.org", "gt1.ehgt.org", "gt2.ehgt.org", "gt3.ehgt.org") {
|
||||
"37.48.89.44" blockedInCN false
|
||||
"81.171.10.48" blockedInCN false
|
||||
"178.162.139.24" blockedInCN false
|
||||
"178.162.140.212" blockedInCN false
|
||||
"2001:1af8:4700:a062:8::47de" blockedInCN false
|
||||
"2001:1af8:4700:a062:9::47de" blockedInCN true
|
||||
"2001:1af8:4700:a0c9:4::47de" blockedInCN false
|
||||
"2001:1af8:4700:a0c9:3::47de" blockedInCN true
|
||||
}
|
||||
hosts("e-hentai.org") {
|
||||
"104.20.134.21" blockedInCN false
|
||||
"104.20.135.21" blockedInCN false
|
||||
"172.67.0.127" blockedInCN false
|
||||
}
|
||||
hosts("exhentai.org") {
|
||||
"178.175.128.252" blockedInCN false
|
||||
"178.175.129.252" blockedInCN false
|
||||
"178.175.129.254" blockedInCN false
|
||||
"178.175.128.254" blockedInCN false
|
||||
"178.175.132.20" blockedInCN false
|
||||
"178.175.132.22" blockedInCN false
|
||||
}
|
||||
hosts("s.exhentai.org") {
|
||||
"178.175.129.254" blockedInCN false
|
||||
"178.175.128.254" blockedInCN false
|
||||
"178.175.132.22" blockedInCN false
|
||||
}
|
||||
hosts("repo.e-hentai.org") {
|
||||
"94.100.28.57" blockedInCN true
|
||||
"94.100.29.73" blockedInCN true
|
||||
}
|
||||
hosts("forums.e-hentai.org") {
|
||||
"94.100.18.243" blockedInCN false
|
||||
}
|
||||
hosts("ul.ehgt.org") {
|
||||
"94.100.24.82" blockedInCN true
|
||||
"94.100.24.72" blockedInCN true
|
||||
}
|
||||
hosts("raw.githubusercontent.com") {
|
||||
"151.101.0.133" blockedInCN true
|
||||
"151.101.64.133" blockedInCN false
|
||||
"151.101.128.133" blockedInCN false
|
||||
"151.101.192.133" blockedInCN false
|
||||
}
|
||||
}
|
||||
override fun lookup(hostname: String): List<InetAddress> = builtInHosts[hostname].takeIf { Settings.builtInHosts } ?: Dns.SYSTEM.lookup(hostname)
|
||||
|
||||
@Throws(UnknownHostException::class)
|
||||
override fun lookup(hostname: String): List<InetAddress> {
|
||||
return builtInHosts[hostname].takeIf { Settings.builtInHosts } ?: Dns.SYSTEM.lookup(hostname)
|
||||
}
|
||||
operator fun contains(hostname: String) = builtInHosts.contains(hostname) && Settings.builtInHosts
|
||||
}
|
||||
|
||||
fun isInHosts(hostname: String): Boolean {
|
||||
return builtInHosts.contains(hostname) && Settings.builtInHosts
|
||||
private val builtInHosts = hostsDsl {
|
||||
// ip: String!, blockedByCCP: Boolean!
|
||||
hosts("ehgt.org", "gt0.ehgt.org", "gt1.ehgt.org", "gt2.ehgt.org", "gt3.ehgt.org") {
|
||||
"37.48.89.44" blockedInCN false
|
||||
"81.171.10.48" blockedInCN false
|
||||
"178.162.139.24" blockedInCN false
|
||||
"178.162.140.212" blockedInCN false
|
||||
"2001:1af8:4700:a062:8::47de" blockedInCN false
|
||||
"2001:1af8:4700:a062:9::47de" blockedInCN true
|
||||
"2001:1af8:4700:a0c9:4::47de" blockedInCN false
|
||||
"2001:1af8:4700:a0c9:3::47de" blockedInCN true
|
||||
}
|
||||
hosts("e-hentai.org") {
|
||||
"104.20.134.21" blockedInCN false
|
||||
"104.20.135.21" blockedInCN false
|
||||
"172.67.0.127" blockedInCN false
|
||||
}
|
||||
hosts("exhentai.org") {
|
||||
"178.175.128.252" blockedInCN false
|
||||
"178.175.129.252" blockedInCN false
|
||||
"178.175.129.254" blockedInCN false
|
||||
"178.175.128.254" blockedInCN false
|
||||
"178.175.132.20" blockedInCN false
|
||||
"178.175.132.22" blockedInCN false
|
||||
}
|
||||
hosts("s.exhentai.org") {
|
||||
"178.175.129.254" blockedInCN false
|
||||
"178.175.128.254" blockedInCN false
|
||||
"178.175.132.22" blockedInCN false
|
||||
}
|
||||
hosts("repo.e-hentai.org") {
|
||||
"94.100.28.57" blockedInCN true
|
||||
"94.100.29.73" blockedInCN true
|
||||
}
|
||||
hosts("forums.e-hentai.org") {
|
||||
"94.100.18.243" blockedInCN false
|
||||
}
|
||||
hosts("ul.ehgt.org") {
|
||||
"94.100.24.82" blockedInCN true
|
||||
"94.100.24.72" blockedInCN true
|
||||
}
|
||||
hosts("raw.githubusercontent.com") {
|
||||
"151.101.0.133" blockedInCN false
|
||||
"151.101.64.133" blockedInCN false
|
||||
"151.101.128.133" blockedInCN false
|
||||
"151.101.192.133" blockedInCN false
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ object EhSSLSocketFactory : SSLSocketFactory() {
|
||||
}
|
||||
|
||||
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
|
||||
val address = s.inetAddress.hostAddress.takeIf { EhDns.isInHosts(host) || EXCEPTIONAL_DOMAIN in host }
|
||||
val address = s.inetAddress.hostAddress.takeIf { host in EhDns || EXCEPTIONAL_DOMAIN in host }
|
||||
val socket = sslSocketFactory.createSocket(s, address ?: host, port, autoClose) as SSLSocket
|
||||
val sslSession = socket.session
|
||||
Log.d(
|
||||
|
||||
Reference in new issue
Block a user