Skip to content

Commit dd6c3a4

Browse files
Using new 'ssh pico.sh user' endpoint to infer username; my feature request via IRC mid-July 2025
1 parent b295a65 commit dd6c3a4

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: future.p2p
22
Title: A Peer-to-Peer Compute Cluster via Futureverse
3-
Version: 0.2.0-9000
3+
Version: 0.2.0-9001
44
Description: Implementation of the 'Future' API <doi:10.32614/RJ-2021-048> that resolves futures on a peer-to-peer ('P2P') compute environment. By using this future backend, you and your friends can share your spare compute resources with each other.
55
Depends:
66
future (>= 1.67.0)

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Version (development version)
22

3-
* ...
3+
## Miscellaneous
4+
5+
* Pico username is now inferred using the new `ssh pico.sh user`
6+
endpoint.
47

58

69
# Version 0.2.0 [2025-08-13]

R/pico_username.R

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,41 @@
1111
pico_username <- local({
1212
username <- NULL
1313

14-
function(host = "pipe.pico.sh", ssh_args = NULL, timeout = 10.0) {
14+
function(host = "pico.sh", ssh_args = NULL, timeout = 10.0) {
1515
if (is.null(username)) {
16-
## (1) Launch a temporary pico pipe with a random name
17-
topic <- session_uuid()
18-
p_pipe <- pico_pipe(topic, command = "pipe", args = "-r", host = host, ssh_args = ssh_args)
19-
on.exit(tryCatch(pico_terminate(p_pipe), error = identity))
20-
p <- p_pipe$process
21-
msg <- sprintf("msg=%s", topic)
22-
23-
## (2) Wait for pico pipe to be up
24-
t_max <- proc.time()[3] + timeout
25-
pico_send_message(p_pipe, message = msg)
26-
repeat {
27-
bfr <- pico_receive_message(p_pipe)
28-
if (length(bfr) > 0L) {
29-
if (any(bfr == msg)) break
30-
}
31-
if (proc.time()[3] > t_max) {
32-
stop("Failed to identity pico.sh username - echo failed")
33-
}
34-
Sys.sleep(0.1)
16+
debug <- isTRUE(getOption("future.p2p.debug"))
17+
if (debug) {
18+
mdebug_push("pico_username() ...")
19+
mdebugf("Host: %s", sQuote(host))
20+
mdebugf("Timeout: %s seconds", timeout)
21+
mstr(list(ssh_args = ssh_args))
22+
mstr(list(ssh_args = ssh_args))
23+
on.exit({
24+
mdebug_pop()
25+
})
3526
}
36-
37-
## (3) Get info pico pipe
38-
t_max <- proc.time()[3] + timeout
39-
pattern <- sprintf(".*[[:blank:]]([^/]+)/%s:.*", topic)
40-
while (is.null(username)) local({
41-
p_ls <- pico_pipe(command = "ls", host = host, ssh_args = ssh_args)
42-
on.exit(tryCatch(pico_terminate(p_ls), error = identity))
43-
p <- p_ls$process
44-
if (length(bfr <- p$read_all_output_lines()) > 1L) {
45-
line <- grep(pattern, bfr, value = TRUE)
46-
if (length(line) == 1L) {
47-
username <<- gsub(pattern, "\\1", line)
48-
return(username)
49-
}
50-
}
51-
if (proc.time()[3] > t_max) {
52-
stop("Failed to identity pico.sh username - ls failed")
53-
}
54-
Sys.sleep(0.1)
55-
})
27+
28+
ssh_config <- list(options = ssh_args, host = host)
29+
args <- c(ssh_config[["options"]], ssh_config[["host"]], "user")
30+
if (debug) {
31+
mdebug("SSH call:")
32+
mstr(list(args = args))
33+
}
34+
35+
out <- system2("ssh", args = args, stdout = TRUE, stderr = TRUE, timeout = timeout)
36+
if (debug) {
37+
mdebug("SSH result:")
38+
mstr(list(out = out))
39+
}
40+
status <- attr(out, "status")
41+
if (!is.null(status)) {
42+
stop(sprintf("Failed to infer pico.sh username. Exit code %s", status))
43+
}
44+
stopifnot(length(out) >= 3)
45+
username <<- structure(out[1], id = out[2], created_on = as.POSIXct(sub("T", " ", out[3])), class = "pico_username")
5646
}
5747

58-
structure(username, class = "pico_username")
48+
username
5949
}
6050
})
6151

man/pico_username.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)