diff --git a/FednDemo/fedn-client/src/main/java/com/example/fedn_client/FednClient.kt b/FednDemo/fedn-client/src/main/java/com/example/fedn_client/FednClient.kt index 8a5e03f..f27a0ec 100644 --- a/FednDemo/fedn-client/src/main/java/com/example/fedn_client/FednClient.kt +++ b/FednDemo/fedn-client/src/main/java/com/example/fedn_client/FednClient.kt @@ -42,6 +42,7 @@ class FednClient( private val name: String? = null, private val heartbeatInterval: Long = 5000, private val port: Int = 443, + private val secureGrpcConnection: Boolean = true, private val defaultDispatcher: CoroutineDispatcher = Dispatchers.IO, private var _httpHandler: IHttpHandler? = null, private var _grpcHandler: IGrpcHandler? = null @@ -140,7 +141,14 @@ class FednClient( val fqdn = response.fqdn - grpcHandler = GrpcHandler(clientName, fqdn, port, token, response.host) + grpcHandler = GrpcHandler( + clientName, + fqdn, + port, + token, + response.host, + secureGrpcConnection = secureGrpcConnection + ) attached = true diff --git a/FednDemo/fedn-client/src/main/java/com/example/fedn_client/GrpcHandler.kt b/FednDemo/fedn-client/src/main/java/com/example/fedn_client/GrpcHandler.kt index b8cd226..9902e4a 100644 --- a/FednDemo/fedn-client/src/main/java/com/example/fedn_client/GrpcHandler.kt +++ b/FednDemo/fedn-client/src/main/java/com/example/fedn_client/GrpcHandler.kt @@ -15,7 +15,6 @@ import com.google.protobuf.ByteString import io.grpc.ManagedChannel import io.grpc.ManagedChannelBuilder import io.grpc.Metadata -import io.grpc.NameResolver import io.grpc.StatusException import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -29,6 +28,7 @@ const val CHUNK_SIZE: Int = 1024 * 1024 enum class ModelUpdateState { LISTENER_INITIALIZED, SERVER_MODEL_DOWNLOADED, TRAINING_STARTED, TRAINING_COMPLETED, MODEL_UPLOADED, TRAINING_ROUND_FINISHED } + interface IGrpcHandler : Closeable { suspend fun sendHeartbeat() suspend fun listenToModelUpdateRequestStream( @@ -43,7 +43,8 @@ internal class GrpcHandler( private val url: String, private val port: Int, private val token: String, - private val combinerName: String + private val combinerName: String, + private val secureGrpcConnection: Boolean = true ) : IGrpcHandler { private val headers = Metadata().apply { @@ -62,7 +63,10 @@ internal class GrpcHandler( if (_managedChannel == null) { _managedChannel = - ManagedChannelBuilder.forAddress(url, port).useTransportSecurity().build() + if (secureGrpcConnection) + ManagedChannelBuilder.forAddress(url, port).useTransportSecurity().build() + else + ManagedChannelBuilder.forAddress(url, port).usePlaintext().build() } return _managedChannel ?: throw AssertionError("Set to null by another thread") diff --git a/FednKotlin/app/dependencies/fedn-client.jar b/FednKotlin/app/dependencies/fedn-client.jar index 537d932..43b17f1 100644 Binary files a/FednKotlin/app/dependencies/fedn-client.jar and b/FednKotlin/app/dependencies/fedn-client.jar differ diff --git a/FednKotlin/app/src/main/kotlin/fednkotlin/App.kt b/FednKotlin/app/src/main/kotlin/fednkotlin/App.kt index 9409875..721582c 100644 --- a/FednKotlin/app/src/main/kotlin/fednkotlin/App.kt +++ b/FednKotlin/app/src/main/kotlin/fednkotlin/App.kt @@ -5,6 +5,7 @@ package fednkotlin import com.example.fedn_client.FednClient import com.example.fedn_client.IFednClient +import java.util.UUID import kotlinx.coroutines.runBlocking val runTrainingProcess: (ByteArray) -> ByteArray = { modelIn -> @@ -18,18 +19,24 @@ fun main() { runBlocking { val url: String? = System.getenv("FEDN_URL") val token: String? = System.getenv("FEDN_TOKEN") - val name: String? = System.getenv("FEDN_NAME") + var name: String? = System.getenv("FEDN_NAME") - if (url == null || token == null || name == null) { - println("FEDN_URL, FEDN_TOKEN and FEDN_NAME must be set") + if (url == null || token == null) { + println("FEDN_URL and FEDN_TOKEN must be set") return@runBlocking } println("FEDN_URL: $url") println("FEDN_TOKEN: $token") + + if (name == null) { + println("FEDN_NAME not set, using random name") + name = UUID.randomUUID().toString() + } println("FEDN_NAME: $name") - val fednClient: IFednClient = FednClient(url, token, name = name) + val fednClient: IFednClient = + FednClient(url, token, name = name, secureGrpcConnection = false) val result = fednClient.runProcess( @@ -41,7 +48,7 @@ fun main() { timeoutAfterMillis = 60000 ) - println("Result: ${result?.first}") + println("Result: ${result.first}") } println("Program ran to completion")