Removed maxConnections limit

This commit is contained in:
Felix Ableitner 2016-09-19 06:00:35 +09:00
parent 69066c6744
commit 5bb97a1460
5 changed files with 8 additions and 15 deletions

View file

@ -37,7 +37,7 @@ class ChatService extends Service {
lazy val database = new Database(getDatabasePath("database"), settingsWrapper, callbackHandler)
private lazy val connectionHandler =
new ConnectionHandler(settingsWrapper, database, callbackHandler, ChatService.newCrypto(this), 1)
new ConnectionHandler(settingsWrapper, database, callbackHandler, ChatService.newCrypto(this))
private val networkReceiver = new NetworkChangedReceiver()

View file

@ -17,13 +17,9 @@ import scala.concurrent.Future
/**
* High-level handling of all message transfers and callbacks.
*
* @param maxInternetConnections Maximum number of concurrent connections that should be opened by
* [[InternetInterface]].
*/
final class ConnectionHandler(settings: SettingsInterface, database: Database,
callbacks: CallbackInterface, crypto: Crypto,
maxInternetConnections: Int,
port: Int = InternetInterface.DefaultPort) {
private val logger = Logger(this.getClass)
@ -68,7 +64,7 @@ final class ConnectionHandler(settings: SettingsInterface, database: Database,
logger.info("Local user is " + settings.get(SettingsInterface.KeyUserName, "none") +
" with status '" + settings.get(SettingsInterface.KeyUserStatus, "") + "'")
transmissionInterfaces +=
new InternetInterface(this, crypto, settings, maxInternetConnections, port)
new InternetInterface(this, crypto, settings, port)
transmissionInterfaces.foreach(_.create())
database.getUnconfirmedMessages.foreach { m =>
val encrypted = crypto.encryptAndSign(m)

View file

@ -23,11 +23,9 @@ private[core] object InternetInterface {
/**
* Handles all Internet connectivity.
*
* @param maxConnections Maximum number of concurrent connections that should be opened.
*/
private[core] class InternetInterface(connectionHandler: ConnectionHandler, crypto: Crypto,
settings: SettingsInterface, maxConnections: Int, port: Int)
settings: SettingsInterface, port: Int)
extends TransmissionInterface {
private val logger = Logger(this.getClass)
@ -48,7 +46,7 @@ private[core] class InternetInterface(connectionHandler: ConnectionHandler, cryp
settings.put(SettingsInterface.KeyAddresses, servers)
serverThread.start()
openAllConnections(maxConnections)
openAllConnections()
}
/**
@ -59,14 +57,13 @@ private[core] class InternetInterface(connectionHandler: ConnectionHandler, cryp
connections.foreach(_.close())
}
private def openAllConnections(maxConnections: Int): Unit = {
private def openAllConnections(): Unit = {
val addresses = settings.get(SettingsInterface.KeyAddresses, SettingsInterface.DefaultAddresses)
.split(",")
.map(_.trim())
.filterNot(_.isEmpty)
Random.shuffle(addresses.toList)
.take(maxConnections)
.foreach(openConnection)
}
@ -148,7 +145,7 @@ private[core] class InternetInterface(connectionHandler: ConnectionHandler, cryp
FutureHelper {
logger.info("Network has changed. Closing all connections and connecting to bootstrap nodes again")
connections.foreach(_.close())
openAllConnections(maxConnections)
openAllConnections()
}
}

View file

@ -54,7 +54,7 @@ class LocalNode(val index: Int, configFolder: File) extends CallbackInterface {
val crypto = new Crypto(settings, keyFolder)
val database = new Database(databaseFile, settings, this)
val connectionHandler = new ConnectionHandler(settings, database, this, crypto, 0, port)
val connectionHandler = new ConnectionHandler(settings, database, this, crypto, port)
val eventQueue = new FifoStream[(EventType.EventType, Option[Message])]()
configFolder.mkdirs()

View file

@ -24,7 +24,7 @@ object Main extends App with CallbackInterface {
private lazy val settings = new Settings(ConfigFile)
private lazy val crypto = new Crypto(settings, KeyFolder)
private lazy val database = new Database(DatabaseFile, settings, this)
private lazy val connectionHandler = new ConnectionHandler(settings, database, this, crypto, 7)
private lazy val connectionHandler = new ConnectionHandler(settings, database, this, crypto)
init()