From 1772101cf36ff2c7298b6f1ea2ffc16207fe75f4 Mon Sep 17 00:00:00 2001 From: Rucknium Date: Mon, 15 Apr 2024 16:31:20 +0000 Subject: [PATCH] Bug fixes to ping.peers() and better installation instructions --- R/ping.R | 27 ++++++++++++++++++++++----- README.md | 6 +++--- man/ping.peers.Rd | 5 ++++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/R/ping.R b/R/ping.R index c75ce6f..cf255a1 100644 --- a/R/ping.R +++ b/R/ping.R @@ -7,6 +7,7 @@ #' @param output.file Name of the output file. The file will be created in `bitmonero.dir`. #' @param sleep Number of seconds to sleep between each round of collecting new peer IPs. #' @param ping.count Number of times to ping each peer. +#' @param threads Override default number of threads for sending pings. #' #' @return No return value. Executes in a loop until interrupted. #' @export @@ -15,7 +16,7 @@ #' \dontrun{ #' ping.peers() #' } -ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_peer_pings.csv", sleep = 10, ping.count = 5) { +ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_peer_pings.csv", sleep = 10, ping.count = 5, threads = NULL) { bitmonero.dir <- path.expand(bitmonero.dir) bitmonero.dir <- gsub("/+$", "", bitmonero.dir) @@ -34,7 +35,11 @@ ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_pe # > (something which is not recorded on most Unix-alike file systems). # > What is meant by ‘file access’ and hence the ‘last access time’ is system-dependent. - + while (length(first.file.line) == 0) { + Sys.sleep(sleep) + first.file.line <- readr::read_lines(log.file, n_max = 1) + # If the log file is empty, sleep until it has at least one line. + } lines.already.read <- 0 @@ -42,6 +47,13 @@ ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_pe check.first.file.line <- readr::read_lines(log.file, n_max = 1) + if (length(check.first.file.line) == 0) { + lines.already.read <- 0 + Sys.sleep(sleep) + next + # If the log file is empty, sleep until it has at least one line. + } + if (first.file.line != check.first.file.line) { first.file.line <- check.first.file.line lines.already.read <- 0 @@ -102,12 +114,18 @@ ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_pe if (nrow(peers) * ping.count > 5) { - n.workers <- min(c(floor(nrow(peers) * ping.count / 5), parallelly::availableCores()*4)) + if (is.null(threads)) { + n.workers <- min(c(floor(nrow(peers) * ping.count / 5), parallelly::availableCores()*4)) + } options(parallelly.maxWorkers.localhost = 4) # This means number of CPU cores times 4 # Most time in thread is waiting for ping to return, so can have # high number of workers - future::plan(future::multisession(workers = n.workers)) + future::plan(future::multisession, workers = n.workers) + # Must have this instead of + # future::plan(future::multisession(workers = n.workers)) + # since the latter fails with" object 'n.workers' not found" + # because of a strange scoping reason. ping.data <- future.apply::future_apply(peers, MARGIN = 1, get.ping.data, future.seed = TRUE) @@ -134,7 +152,6 @@ ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_pe } - } diff --git a/README.md b/README.md index b498b8e..5ffd76c 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h ## Installation -You can install the development version of xmrpeers from [GitHub](https://github.com/) with: +You can install the development version of xmrpeers from [GitHub](https://github.com/) if you have `git` and `curl` installed on your system with: ```R -# install.packages("devtools") -devtools::install_github("Rucknium/xmrpeers") +install.packages("remotes") +remotes::install_github("Rucknium/xmrpeers") ``` diff --git a/man/ping.peers.Rd b/man/ping.peers.Rd index aa67cb3..51e6618 100644 --- a/man/ping.peers.Rd +++ b/man/ping.peers.Rd @@ -8,7 +8,8 @@ ping.peers( bitmonero.dir = "~/.bitmonero", output.file = "/monero_peer_pings.csv", sleep = 10, - ping.count = 5 + ping.count = 5, + threads = NULL ) } \arguments{ @@ -19,6 +20,8 @@ ping.peers( \item{sleep}{Number of seconds to sleep between each round of collecting new peer IPs.} \item{ping.count}{Number of times to ping each peer.} + +\item{threads}{Override default number of threads for sending pings.} } \value{ No return value. Executes in a loop until interrupted.