1
0
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-11-17 00:22:32 +01:00

Report proper hostname

This commit is contained in:
carbotaniuman 2020-07-03 16:22:40 -05:00
parent cfc942f674
commit 307b28e13c
3 changed files with 28 additions and 19 deletions

View File

@ -17,7 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [2020-06-28] Added `pasued` field in ServerSettings [@carbotaniuman].
- [2020-06-28] Hopefully fixed connection leaks [@carbotaniuman].
- [2020-07-02] Minor fixes and changes to data handling in web interface [@RedMatriz].
- [2020-07-02] Renamed loaclstorage keys in web interface [@RedMatriz].
- [2020-07-02] Renamed localstorage keys in web interface [@RedMatriz].
- [2020-06-28] Actually report custom `client_hostname` [@carbotaniuman].
### Deprecated

View File

@ -39,27 +39,27 @@ private val LOGGER = LoggerFactory.getLogger("Application")
fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSettings: ClientSettings, statistics: AtomicReference<Statistics>, isHandled: AtomicBoolean): Http4kServer {
val database = Database.connect("jdbc:sqlite:cache/data.db", "org.sqlite.JDBC")
val imageServer = ImageServer(cache, statistics, serverSettings, database, isHandled)
val imageServer = ImageServer(cache, statistics, serverSettings, database, clientSettings.clientHostname, isHandled)
return timeRequest()
.then(catchAllHideDetails())
.then(ServerFilters.CatchLensFailure)
.then(addCommonHeaders())
.then(
routes(
"/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = false),
"/data-saver/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = true),
"/{token}/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(
dataSaver = false,
tokenized = true
),
"/{token}/data-saver/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(
dataSaver = true,
tokenized = true
)
.then(catchAllHideDetails())
.then(ServerFilters.CatchLensFailure)
.then(addCommonHeaders())
.then(
routes(
"/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = false),
"/data-saver/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(dataSaver = true),
"/{token}/data/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(
dataSaver = false,
tokenized = true
),
"/{token}/data-saver/{chapterHash}/{fileName}" bind Method.GET to imageServer.handler(
dataSaver = true,
tokenized = true
)
)
.asServer(Netty(serverSettings.tls!!, clientSettings, statistics))
)
.asServer(Netty(serverSettings.tls!!, clientSettings, statistics))
}
fun timeRequest(): Filter {

View File

@ -31,6 +31,7 @@ import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.File
import java.io.InputStream
import java.net.InetAddress
import java.security.MessageDigest
import java.time.Clock
import java.time.OffsetDateTime
@ -66,7 +67,7 @@ import org.slf4j.LoggerFactory
private const val THREADS_TO_ALLOCATE = 262144 // 2**18
class ImageServer(private val cache: DiskLruCache, private val statistics: AtomicReference<Statistics>, private val serverSettings: ServerSettings, private val database: Database, private val handled: AtomicBoolean) {
class ImageServer(private val cache: DiskLruCache, private val statistics: AtomicReference<Statistics>, private val serverSettings: ServerSettings, private val database: Database, private val clientHostname: String, private val handled: AtomicBoolean) {
init {
transaction(database) {
SchemaUtils.create(ImageData)
@ -81,6 +82,13 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
.setConnectTimeout(3000)
.setSocketTimeout(3000)
.setConnectionRequestTimeout(3000)
.setLocalAddress(
if (clientHostname != "0.0.0.0") {
InetAddress.getByName(clientHostname)
} else {
InetAddress.getLocalHost()
}
)
.build())
.setMaxConnTotal(THREADS_TO_ALLOCATE)
.setMaxConnPerRoute(THREADS_TO_ALLOCATE)