mirror of
https://github.com/Rucknium/xmrpeers.git
synced 2024-12-22 19:49:24 +00:00
Bug fixes to ping.peers() and better installation instructions
This commit is contained in:
parent
ec8518a22e
commit
1772101cf3
3 changed files with 29 additions and 9 deletions
25
R/ping.R
25
R/ping.R
|
@ -7,6 +7,7 @@
|
||||||
#' @param output.file Name of the output file. The file will be created in `bitmonero.dir`.
|
#' @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 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 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.
|
#' @return No return value. Executes in a loop until interrupted.
|
||||||
#' @export
|
#' @export
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
#' \dontrun{
|
#' \dontrun{
|
||||||
#' ping.peers()
|
#' 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 <- path.expand(bitmonero.dir)
|
||||||
bitmonero.dir <- gsub("/+$", "", 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).
|
# > (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.
|
# > 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
|
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)
|
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) {
|
if (first.file.line != check.first.file.line) {
|
||||||
first.file.line <- check.first.file.line
|
first.file.line <- check.first.file.line
|
||||||
lines.already.read <- 0
|
lines.already.read <- 0
|
||||||
|
@ -102,12 +114,18 @@ ping.peers <- function(bitmonero.dir = "~/.bitmonero", output.file = "/monero_pe
|
||||||
|
|
||||||
if (nrow(peers) * ping.count > 5) {
|
if (nrow(peers) * ping.count > 5) {
|
||||||
|
|
||||||
|
if (is.null(threads)) {
|
||||||
n.workers <- min(c(floor(nrow(peers) * ping.count / 5), parallelly::availableCores()*4))
|
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
|
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
|
# Most time in thread is waiting for ping to return, so can have
|
||||||
# high number of workers
|
# 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)
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
|
||||||
|
|
||||||
## Installation
|
## 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
|
```R
|
||||||
# install.packages("devtools")
|
install.packages("remotes")
|
||||||
devtools::install_github("Rucknium/xmrpeers")
|
remotes::install_github("Rucknium/xmrpeers")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ ping.peers(
|
||||||
bitmonero.dir = "~/.bitmonero",
|
bitmonero.dir = "~/.bitmonero",
|
||||||
output.file = "/monero_peer_pings.csv",
|
output.file = "/monero_peer_pings.csv",
|
||||||
sleep = 10,
|
sleep = 10,
|
||||||
ping.count = 5
|
ping.count = 5,
|
||||||
|
threads = NULL
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
@ -19,6 +20,8 @@ ping.peers(
|
||||||
\item{sleep}{Number of seconds to sleep between each round of collecting new peer IPs.}
|
\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{ping.count}{Number of times to ping each peer.}
|
||||||
|
|
||||||
|
\item{threads}{Override default number of threads for sending pings.}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
No return value. Executes in a loop until interrupted.
|
No return value. Executes in a loop until interrupted.
|
||||||
|
|
Loading…
Reference in a new issue