Skip to content

Commit

Permalink
Add tasks to app status
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Nov 19, 2019
1 parent f122e15 commit 2fdd93e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class BitcoinCore(
val statusInfo = LinkedHashMap<String, Any>()

statusInfo["Synced Until"] = lastBlockInfo?.timestamp?.let { Date(it) } ?: "N/A"
statusInfo["Syncing Peer"] = initialBlockDownload.syncPeer?.host ?: "N/A"
statusInfo["Errors"] = errorStorage.errors
statusInfo["Last Block Height"] = lastBlockInfo?.height ?: "N/A"

Expand All @@ -485,6 +486,18 @@ class BitcoinCore(
peerStatus["Host"] = peer.host
peerStatus["Best Block"] = peer.announcedLastBlockHeight

peer.tasks.let { peerTasks ->
if (peerTasks.isEmpty()) {
peerStatus["tasks"] = "no tasks"
} else {
val tasks = LinkedHashMap<String, Any>()
peerTasks.forEach { task ->
tasks[task.javaClass.simpleName] = "[${task.state}]"
}
peerStatus["tasks"] = tasks
}
}

peers["Peer ${index + 1}"] = peerStatus
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InitialBlockDownload(
private val peerSwitchMinimumRatio = 1.5

@Volatile
private var syncPeer: Peer? = null
var syncPeer: Peer? = null
private var selectNewPeer = false
private val peersQueue = Executors.newSingleThreadExecutor()
private val logger = Logger.getLogger("IBD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class Peer(
var synced = false
var connected = false
var connectionTime: Long = 1000
private var connectStartTime: Long? = null
var tasks = mutableListOf<PeerTask>()

private var connectStartTime: Long? = null
private val peerConnection = PeerConnection(host, network, this, executorService, networkMessageParser, networkMessageSerializer)
private var tasks = mutableListOf<PeerTask>()
private val timer = PeerTimer()

val ready: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class GetBlockHashesTask(private val blockLocatorHashes: List<ByteArray>, expect
allowedIdleTime = Math.max(minAllowedIdleTime, resolvedAllowedIdleTime.toLong())
}

override val state: String
get() = "expectedHashesMinCount: $expectedHashesMinCount; allowedIdleTime: $allowedIdleTime"

override fun start() {
requester?.let { it.send(GetBlocksMessage(blockLocatorHashes, it.protocolVersion, ByteArray(32))) }
resetTimer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class GetMerkleBlocksTask(
private var maxWarningCount = 10
private var firstResponseReceived = false

override val state: String
get() = "minMerkleBlocksCount: ${minMerkleBlocks.roundToInt()}; minTransactionsCount: ${minTransactions.roundToInt()}; minTransactionsSize: ${minTransactions.roundToInt()}"

override fun start() {
val items = blockHashes.map { hash ->
InventoryItem(InventoryItem.MSG_FILTERED_BLOCK, hash.headerHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ open class PeerTask {

var requester: Requester? = null
var listener: Listener? = null
open val state: String = ""

protected var lastActiveTime: Long? = null
protected var allowedIdleTime: Long? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class RequestTransactionsTask(hashes: List<ByteArray>) : PeerTask() {
val hashes = hashes.toMutableList()
var transactions = mutableListOf<FullTransaction>()

override val state: String
get() =
"hashesCount: ${hashes.size}; receivedTransactionsCount: ${transactions.size}"

override fun start() {
val items = hashes.map { hash ->
InventoryItem(InventoryItem.MSG_TX, hash)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.horizontalsystems.bitcoincore.network.peer.task

import io.horizontalsystems.bitcoincore.extensions.toReversedHex
import io.horizontalsystems.bitcoincore.models.InventoryItem
import io.horizontalsystems.bitcoincore.network.messages.GetDataMessage
import io.horizontalsystems.bitcoincore.network.messages.IMessage
Expand All @@ -8,6 +9,10 @@ import io.horizontalsystems.bitcoincore.network.messages.TransactionMessage
import io.horizontalsystems.bitcoincore.storage.FullTransaction

class SendTransactionTask(val transaction: FullTransaction) : PeerTask() {

override val state: String
get() = "transaction: ${transaction.header.hash.toReversedHex()}"

override fun start() {
requester?.send(InvMessage(InventoryItem.MSG_TX, transaction.header.hash))
}
Expand Down

0 comments on commit 2fdd93e

Please sign in to comment.