gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 02/02: sandbox: avoid parallelism


From: gnunet
Subject: [libeufin] 02/02: sandbox: avoid parallelism
Date: Fri, 15 Jul 2022 15:19:45 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit a85bd9f48ae45cb8e2965294fea9c372762c5d0c
Author: MS <ms@taler.net>
AuthorDate: Fri Jul 15 15:19:37 2022 +0200

    sandbox: avoid parallelism
---
 sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt |  2 --
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt   | 21 +++++++++++++++++++--
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt   |  9 ++++++++-
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 27f5d3d0..4ae592ef 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -481,8 +481,6 @@ object BankAccountReportsTable : IntIdTable() {
     val bankAccount = reference("bankAccount", BankAccountsTable)
 }
 
-
-
 fun dbDropTables(dbConnectionString: String) {
     Database.connect(dbConnectionString)
     transaction {
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index a4b1f5c4..fcf2bee8 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -27,11 +27,14 @@ import io.ktor.request.*
 import io.ktor.response.respond
 import io.ktor.response.respondText
 import io.ktor.util.AttributeKey
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
 import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
 import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
 import org.jetbrains.exposed.sql.statements.api.ExposedBlob
+import 
org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.w3c.dom.Document
 import tech.libeufin.util.*
@@ -44,6 +47,7 @@ import tech.libeufin.util.ebics_s001.UserSignatureData
 import java.math.BigDecimal
 import java.security.interfaces.RSAPrivateCrtKey
 import java.security.interfaces.RSAPublicKey
+import java.sql.Connection
 import java.util.*
 import java.util.zip.DeflaterInputStream
 import java.util.zip.InflaterInputStream
@@ -697,6 +701,16 @@ private fun handleCct(paymentRequest: String) {
     logger.debug("Pain.001: $paymentRequest")
     val parseResult = parsePain001(paymentRequest)
     transaction {
+        val maybeExist = BankAccountTransactionEntity.find {
+            BankAccountTransactionsTable.pmtInfId eq parseResult.pmtInfId
+        }.firstOrNull()
+        if (maybeExist != null) {
+            logger.info(
+                "Nexus submitted twice the PAIN: ${maybeExist.pmtInfId}. Not 
taking any action." +
+                        "  Sandbox gave it this reference: 
${maybeExist.accountServicerReference}"
+            )
+            return@transaction
+        }
         try {
             val bankAccount = getBankAccountFromIban(parseResult.debtorIban)
             if (parseResult.currency != bankAccount.demoBank.currency) throw 
EbicsRequestError(
@@ -1002,7 +1016,7 @@ private fun makePartnerInfo(subscriber: 
EbicsSubscriberEntity): EbicsTypes.Partn
                         this.value = bankAccount.iban
                     }
                 )
-                this.currency = "EUR"
+                this.currency = bankAccount.demoBank.currency
                 this.description = "Ordinary Bank Account"
                 this.bankCodeList = listOf(
                     EbicsTypes.GeneralBankCode().apply {
@@ -1265,7 +1279,10 @@ private fun 
handleEbicsUploadTransactionTransmission(requestContext: RequestCont
             }
         }
         if (getOrderTypeFromTransactionId(requestTransactionID) == "CCT") {
-            logger.debug("Attempting a payment.")
+            logger.debug(
+                "Attempting a payment in thread (name/id): " +
+                        
"${Thread.currentThread().name}/${Thread.currentThread().id}"
+            )
             handleCct(unzippedData.toString(Charsets.UTF_8))
         }
         return EbicsResponse.createForUploadTransferPhase(
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index ef97b4df..52ab1556 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -58,6 +58,7 @@ import io.ktor.application.*
 import io.ktor.features.*
 import io.ktor.http.*
 import io.ktor.jackson.*
+import io.ktor.network.sockets.*
 import io.ktor.request.*
 import io.ktor.response.*
 import io.ktor.routing.*
@@ -65,7 +66,10 @@ import io.ktor.server.engine.*
 import io.ktor.server.netty.*
 import io.ktor.util.*
 import io.ktor.util.date.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
 import kotlinx.coroutines.newSingleThreadContext
+import kotlinx.coroutines.withContext
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
 import org.jetbrains.exposed.sql.statements.api.ExposedBlob
@@ -951,7 +955,6 @@ val sandboxApp: Application.() -> Unit = {
             }
             call.respond(EbicsHostsResponse(ebicsHosts))
         }
-
         // Process one EBICS request
         post("/ebicsweb") {
             try {
@@ -1600,6 +1603,10 @@ fun serverMain(port: Int) {
                 this.host = "[::1]"
             }
             module(sandboxApp)
+        },
+        configure = {
+            workerGroupSize = 1
+            callGroupSize = 1
         }
     )
     logger.info("LibEuFin Sandbox running on port $port")

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]