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

Use gzip compression for data sent from agent #329

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.versions.plugin)
alias(libs.plugins.talaiot.base)
alias(libs.plugins.liquibase.gradle)
id("com.louiscad.complete-kotlin") version "1.1.0"
}

val profile = properties.getOrDefault("save.profile", "dev") as String
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
ktor-client-serialization = { module = "io.ktor:ktor-client-serialization", version.ref = "ktor" }
ktor-client-encoding = { module = "io.ktor:ktor-client-encoding", version.ref = "ktor" }
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }

# database
Expand Down
1 change: 1 addition & 0 deletions save-agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kotlin {
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.curl)
implementation(libs.ktor.client.serialization)
implementation(libs.ktor.client.encoding)
implementation(libs.kotlinx.serialization.properties)
implementation(libs.okio)
implementation(libs.kotlinx.datetime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.cqfn.save.core.logging.logType
import generated.SAVE_CLOUD_VERSION
import io.ktor.client.HttpClient
import io.ktor.client.features.HttpTimeout
import io.ktor.client.features.compression.ContentEncoding
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import platform.posix.SIGTERM
Expand Down Expand Up @@ -61,6 +62,9 @@ fun main() {
install(HttpTimeout) {
requestTimeoutMillis = config.requestTimeoutMillis
}
install(ContentEncoding) {
gzip()
}
}
val saveAgent = SaveAgent(config, httpClient)
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ package org.cqfn.save.agent.utils
import okio.FileNotFoundException
import okio.FileSystem
import okio.Path.Companion.toPath
import platform.zlib.*

import kotlinx.cinterop.UByteVar
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.cValuesOf
import kotlinx.cinterop.cstr
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.pointed
import kotlinx.cinterop.ptr
import kotlinx.cinterop.readBytes
import kotlinx.cinterop.reinterpret
import kotlinx.cinterop.value

/**
* @param s
* @return
*/
fun deflate(s: String): ByteArray = memScoped {
// val defstream: z_stream = z_stream()
// defstream.zalloc = Z_NULL
// defstream.zfree = Z_NULL
// defstream.avail_in = s.length.toUInt() // size of input
// defstream.next_in = UByteVarOf<UByte>(s.cstr.ptr.rawValue).ptr
// defstream.avail_in = s.length.toUInt() // size of input
val out = allocArray<UByteVar>(s.length)
// defstream.next_out = UByteVarOf<UByte>(out.rawValue).ptr
// deflateInit(defstream.ptr, Z_BEST_COMPRESSION)
// platform.zlib.deflate(defstream.ptr, Z_FINISH)
// deflateEnd(defstream.ptr)
val destLen = cValuesOf(s.length).ptr
compress(
out,
destLen.reinterpret(),
s.cstr.ptr.reinterpret(),
s.length.toULong()
)
return@memScoped out.readBytes(destLen.pointed.value)
}

/**
* Read file as a list of strings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cqfn.save.utils

/**
* @param default
* @return
*/
fun String?.ifNullOrEmpty(default: () -> String) = (this ?: "").ifBlank(default)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cqfn.save.orchestrator.filters

import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebFilter
import org.springframework.web.server.WebFilterChain
import reactor.core.publisher.Mono

class GzipDecodingFilter : WebFilter {
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
TODO("Not yet implemented")
}
}