aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorpacien2020-12-09 15:07:01 +0100
committerpacien2020-12-09 15:07:55 +0100
commit83663817f5404073f8de11ace4d75ef1b0bb2029 (patch)
tree437d51e14f8f5a7be3e905f26f34b056509403d0 /app/src/main/java
parent3e3881b162ca83119870c4ce9db4068bbb985f64 (diff)
downloadtincapp-83663817f5404073f8de11ace4d75ef1b0bb2029.tar.gz
ConfigurationAccessService: disable multithreaded FTP and set explicit data port range
The Apache Mina FtpServer library seems to have some issues when handling parallel transfers. This simply disables multithreading in the library to avoid those. The changeset also explicitly define a port range to be used for passive FTP data connections, solving the warnings about unregistered ports. GitHub: see https://github.com/pacien/tincapp/issues/103#issuecomment-741025439
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt25
1 files changed, 21 insertions, 4 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
index b083a83..32f74fc 100644
--- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
@@ -25,6 +25,8 @@ import android.os.IBinder
25import androidx.databinding.ObservableBoolean 25import androidx.databinding.ObservableBoolean
26import ch.qos.logback.classic.Level 26import ch.qos.logback.classic.Level
27import ch.qos.logback.classic.Logger 27import ch.qos.logback.classic.Logger
28import org.apache.ftpserver.ConnectionConfigFactory
29import org.apache.ftpserver.DataConnectionConfigurationFactory
28import org.apache.ftpserver.FtpServer 30import org.apache.ftpserver.FtpServer
29import org.apache.ftpserver.FtpServerFactory 31import org.apache.ftpserver.FtpServerFactory
30import org.apache.ftpserver.ftplet.* 32import org.apache.ftpserver.ftplet.*
@@ -53,6 +55,7 @@ class ConfigurationAccessService : Service() {
53 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN) 55 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN)
54 56
55 const val FTP_PORT = 65521 // tinc port `concat` FTP port 57 const val FTP_PORT = 65521 // tinc port `concat` FTP port
58 val FTP_DATA_PORT_RANGE = FTP_PORT + 1..FTP_PORT + 11
56 const val FTP_USERNAME = "tincapp" 59 const val FTP_USERNAME = "tincapp"
57 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! 60 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!!
58 val FTP_PASSWORD = generateRandomString(8) 61 val FTP_PASSWORD = generateRandomString(8)
@@ -115,12 +118,26 @@ class ConfigurationAccessService : Service() {
115 ) 118 )
116 } 119 }
117 120
118 private fun setupSingleUserServer(ftpUser: User): FtpServer { 121 private fun setupSingleUserServer(ftpUser: User): FtpServer =
119 return FtpServerFactory() 122 FtpServerFactory()
120 .apply { addListener("default", ListenerFactory().apply { port = FTP_PORT }.createListener()) } 123 .apply {
124 addListener("default", ListenerFactory()
125 .apply {
126 connectionConfig = ConnectionConfigFactory()
127 .apply { maxThreads = 1 } // library has issues with multiple threads
128 .createConnectionConfig()
129 }
130 .apply { port = FTP_PORT }
131 .apply {
132 dataConnectionConfiguration = DataConnectionConfigurationFactory()
133 .apply { passivePorts = "${FTP_DATA_PORT_RANGE.first}-${FTP_DATA_PORT_RANGE.last}" }
134 .createDataConnectionConfiguration()
135 }
136 .createListener()
137 )
138 }
121 .apply { userManager = StaticFtpUserManager(listOf(ftpUser)) } 139 .apply { userManager = StaticFtpUserManager(listOf(ftpUser)) }
122 .createServer() 140 .createServer()
123 }
124 141
125 private class StaticFtpUserManager(users: List<User>) : UserManager { 142 private class StaticFtpUserManager(users: List<User>) : UserManager {
126 private val userMap: Map<String, User> = users.map { it.name to it }.toMap() 143 private val userMap: Map<String, User> = users.map { it.name to it }.toMap()