Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Try to use all discovered addresses instead of only the first one #14

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ class SyncthingClient(private val configuration: Configuration) : Closeable {
.filterNot { connections.map { it.deviceId() }.contains(it.key) }
.filterNot { it.value.isEmpty() }
.forEach { (_, addresses) ->
val bestAddress = addresses.first()
try {
listener(openConnection(bestAddress))
} catch (e: IOException) {
logger.warn("error connecting to device = $bestAddress", e)
} catch (e: KeystoreHandler.CryptoException) {
logger.warn("error connecting to device = $bestAddress", e)
// try to use all addresses

for (address in addresses) {
try {
listener(openConnection(address))

break // it worked, no need to try more
} catch (e: IOException) {
logger.warn("error connecting to device = $address", e)
} catch (e: KeystoreHandler.CryptoException) {
logger.warn("error connecting to device = $address", e)
}
}
}

Expand Down