Removed maxConnections limit
This commit is contained in:
parent
69066c6744
commit
5bb97a1460
5 changed files with 8 additions and 15 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Reference in a new issue