Skip to content

Commit

Permalink
Refactored file transfer code for modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
manforowicz committed Jun 5, 2024
1 parent a21b8d7 commit 1128b4f
Show file tree
Hide file tree
Showing 27 changed files with 673 additions and 292 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ resolver = "2"

members = [
"gday",
"gday_contact_exchange_server",
"gday_server",
"gday_hole_punch",
"gday_encryption",
"gday_contact_exchange_protocol",
"gday_file_offer_protocol",
"gday_file_transfer",
]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Send files directly to anyone.
## Example

<pre>
<b style="color:lime;">mate_1:</b> gday send file1 folder2
<b style="color:lime;">peer_1:</b> gday send msg.txt image.jpg
<i>*Asks for confirmation*</i>
Tell your mate to run "gday receive <b>1.188T.W3H.E</b>".
<b>Transfer complete.</b>
</pre>

<pre>
<b style="color:lime;">mate_2:</b> gday receive <b>1.188T.W3H.E</b>
<i>*Asks which files to accept*</i>
<b style="color:lime;">peer_2:</b> gday receive <b>1.188T.W3H.E</b>
<i>*Asks for confirmation*</i>
<b>Transfer complete.</b>
</pre>

![demo](/gday_demo.webp)
[![asciicast](https://asciinema.org/a/662397.svg)](https://asciinema.org/a/662397)

## Features

Expand Down
6 changes: 5 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Not all of them are desirable or necessary.

- Add explanation in readme, of how this differs from magic wormhole.

- Figure out why gday freezes when server is unresponsive.

- Make additional command line options only show when there's a need for them.

## Abandoned ideas

- Maybe add some versioning to the protocols?
Expand Down Expand Up @@ -38,4 +42,4 @@ For the bash demo:
- `Ctrl+b %` to split screen.
- `Ctrl+b o` to switch pane.
- `export PS1="\033[1;92mpeer 1\n$ \033[0m"` to shorten bash prompt
- `export PATH="<PATH TO GDAY HERE>:$PATH` to get `gday` command.
- `export PATH=<PATH TO GDAY'S DIRECTORY>:$PATH` to get `gday` command.
94 changes: 94 additions & 0 deletions demo/demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{"version": 2, "width": 158, "height": 28, "timestamp": 1717443152, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.003457, "o", "\u001b[?1049h\u001b[22;0;0t\u001b[?1h\u001b=\u001b[H\u001b[2J\u001b[?12l\u001b[?25h\u001b[?1000l\u001b[?1002l\u001b[?1003l\u001b[?1006l\u001b[?1005l\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[?1006l\u001b[?1000l\u001b[?1002l\u001b[?1003l\u001b[?2004l\u001b[1;1H\u001b[1;28r\u001b[>c\u001b[>q\u001b[4;1H"]
[0.003872, "o", "\u001b[?25l\u001b[1;80H\u001b[32m│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[39m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[1;79H\u001b[1K\u001b[Hexport PS1=\"\\033[1;92mpeer 1: \\033[0m\"\u001b[2;79H\u001b[1K\rcd peer_1\u001b[3;79H\u001b[1K\rclear\u001b[4;79H\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\u001b[1;81Hexport PS1=\"\\033[1;92mpeer 2: \\033[0m\"\u001b[K\u001b[2;81Hcd peer_2\u001b[K\u001b[3;81Hclear\u001b[K\u001b[4;81H\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\u001b[30m\u001b[42m\r\n[demo_sess0:bash* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[4;1H"]
[0.003908, "o", "\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[?1006l\u001b[?1000l\u001b[?1002l\u001b[?1003l\u001b[?2004l\u001b[1;1H\u001b[1;28r\u001b[4;1H"]
[0.004091, "o", "\u001b[?25l\u001b[1;80H\u001b[32m│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[39m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[1;79H\u001b[1K\u001b[Hexport PS1=\"\\033[1;92mpeer 1: \\033[0m\"\u001b[2;79H\u001b[1K\rcd peer_1\u001b[3;79H\u001b[1K\rclear\u001b[4;79H\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\u001b[1;81Hexport PS1=\"\\033[1;92mpeer 2: \\033[0m\"\u001b[K\u001b[2;81Hcd peer_2\u001b[K\u001b[3;81Hclear\u001b[K\u001b[4;81H\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\u001b[30m\u001b[42m\r\n[demo_sess0:bash* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[4;1H"]
[0.007334, "o", "\u001b[?7727h"]
[0.186101, "o", "(base) \u001b[35m\u001b[1mmarcin\u001b(B\u001b[m@\u001b[36m\u001b[1mmarcin-laptop-mx\u001b(B\u001b[m:\u001b[32m\u001b[1m~/Documents/gday/demo\r\n$\u001b(B\u001b[m \u001b[?2004h"]
[0.186272, "o", "\u001b[4;40H\"\u001b[39X\r\n\u001b[92m\u001b[1mpeer 1: \u001b(B\u001b[mcd peer_13[1;92mpeer 1: \\033[0m\" \r\n\u001b[?2004l\u001b[92m\u001b[1mpeer 1: \u001b(B\u001b[mclear\r\n"]
[0.187171, "o", "\u001b[1;27r\u001b[2;79H\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\n\u001b[1K\u001b[1d\u001b[1K\u001b[1;28r\u001b[1;1H"]
[0.187282, "o", "\u001b[92m\u001b[1mpeer 1: \u001b[?2004h\u001b(B\u001b[m"]
[0.187471, "o", "\u001b[4;81H(base) \u001b[35m\u001b[1mmarcin\u001b(B\u001b[m@\u001b[36m\u001b[1mmarcin-laptop-mx\u001b(B\u001b[m:\u001b[32m\u001b[1m~/Documents/gday/demo\u001b[1;9H\u001b(B\u001b[m\u001b[5;81H\u001b[32m\u001b[1m$\u001b(B\u001b[m \u001b[1;9H"]
[0.187527, "o", "\u001b[5;83Hexport PS1=\"\\033[1;92mpeer 2: \\033[0m\"\u001b[1;9H"]
[0.187565, "o", "\u001b[6;81H\u001b[92m\u001b[1mpeer 2: \u001b[1;9H\u001b(B\u001b[m"]
[0.187608, "o", "\u001b[6;89Hcd peer_2\u001b[1;9H"]
[0.187651, "o", "\u001b[7;81H\u001b[92m\u001b[1mpeer 2: \u001b[1;9H\u001b(B\u001b[m\u001b[7;89Hclear\u001b[1;9H"]
[0.188342, "o", "\u001b[1;27r\u001b[2;81H\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\n\u001b[K\u001b[1d\u001b[K\u001b[1;28r\u001b[1;9H"]
[0.188418, "o", "\u001b[72C\u001b[92m\u001b[1mpeer 2: \u001b[9G\u001b(B\u001b[m"]
[0.190535, "o", "\u001b[72C\u001b[92m\u001b[1mpeer 2: \u001b(B\u001b[m\u001b[K\u001b[H\u001b[92m\u001b[1mpeer 1: \u001b(B\u001b[m\u001b[71X"]
[0.674003, "o", "g"]
[0.85815, "o", "d"]
[0.944386, "o", "a"]
[1.111559, "o", "y"]
[1.207735, "o", " "]
[1.329879, "o", "s"]
[1.423399, "o", "e"]
[1.5715, "o", "n"]
[1.653048, "o", "d"]
[1.739105, "o", " "]
[1.965748, "o", "m"]
[2.087753, "o", "s"]
[2.181981, "o", "g"]
[2.318552, "o", "."]
[2.452878, "o", "t"]
[2.622832, "o", "x"]
[2.710562, "o", "t"]
[2.780506, "o", " "]
[2.900505, "o", "i"]
[2.947626, "o", "m"]
[3.053141, "o", "a"]
[3.13578, "o", "g"]
[3.211482, "o", "e"]
[3.354374, "o", "."]
[3.587126, "o", "j"]
[3.68871, "o", "p"]
[3.815933, "o", "g"]
[3.937013, "o", "\r\n\u001b[?2004l"]
[3.947995, "o", "\u001b[?25l\u001b[1;80H\u001b[32m│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[39m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[30m\u001b[42m\r\n[demo_sess0:gday* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[2;1H"]
[4.012401, "o", "\u001b[1m2\u001b(B\u001b[m \u001b[1mfiles to send:\r\n\u001b(B\u001b[mmsg.txt (12 B)\r\nimage.jpg (11 B)\u001b[6;1H\u001b[1mTotal size: \u001b(B\u001b[m \u001b[1m23 B\r\n\u001b(B\u001b[mWould you like to send these? (y/n): "]
[4.605983, "o", "y"]
[4.795332, "o", "\r\n"]
[5.445093, "o", "\u001b[?25l\u001b[1;80H│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[32m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[1;89H\u001b[?2004h"]
[5.798947, "o", "\u001b[8;1HTell your mate to run \"gday receive \u001b[1m1.4FBD.ED15.2\u001b(B\u001b[m\"\u001b[1;89H"]
[5.799806, "o", "\u001b[?25l\u001b[9D│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[32m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[30m\u001b[42m\r\n[demo_sess0:bash* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[1;89H"]
[6.086862, "o", "g"]
[6.431002, "o", "d"]
[6.503788, "o", "a"]
[6.601593, "o", "y"]
[6.710416, "o", " "]
[6.79049, "o", "r"]
[6.895468, "o", "e"]
[7.096879, "o", "c"]
[7.269312, "o", "e"]
[7.385552, "o", "i"]
[7.460456, "o", "v"]
[7.538639, "o", "e"]
[7.783294, "o", " "]
[8.067315, "o", "1"]
[8.175665, "o", "."]
[8.866609, "o", "4"]
[9.146886, "o", "f"]
[9.851508, "o", "b"]
[10.017667, "o", "d"]
[10.183992, "o", "."]
[10.581023, "o", "e"]
[11.112281, "o", "d"]
[11.864154, "o", "1"]
[11.928078, "o", "5"]
[12.369622, "o", "."]
[12.742728, "o", "2"]
[12.930025, "o", "\u001b[2;81H\u001b[?2004l"]
[13.582588, "o", "\u001b[9;1HWaiting for your mate to respond to your file offer.\u001b[2;81H\u001b[1mYour mate wants to send you\u001b(B\u001b[m \u001b[1m2\u001b(B\u001b[m \u001b[1mfiles:\u001b[3;81H\u001b(B\u001b[mmsg.txt (12 B)\u001b[4;81Himage.jpg (11 B)\u001b[6;81HSize of all offered files: \u001b[1m23 B\u001b[7;81H\u001b(B\u001b[mSize of files that have a new/changed path or size or were interrupted: \u001b[1m23 B\u001b[8;81HOptions:\u001b[9;81H1. Download only files with new path or size. Resume any interrupted downloads\u001b[10;81H.\u001b[11;81H2. Fully download all files.\u001b[12;81H3. Cancel.\u001b[13;81H\u001b(B\u001b[mNote: gday won't overwrite existing files (it suffixes any new files with the \u001b[14;81Hsame name).\u001b[15;81H\u001b[1mChoose an option (1, 2, or 3):\u001b(B\u001b[m "]
[13.58288, "o", "\u001b[?25l\u001b[1;80H│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[32m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[30m\u001b[42m\r\n[demo_sess0:gday* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[15;112H"]
[15.315006, "o", "1"]
[15.799784, "o", "\u001b[16;81H"]
[15.799952, "o", "\u001b[10;1HYour mate accepted 2/2 files\u001b[16;81Hreceiving msg.txt [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 B/23 B | 0 B/s | eta: 0s\u001b[11;1Hsending msg.txt [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 B/23 B | 0 B/s | eta: 0s\u001b[16;158H"]
[15.800023, "o", "\u001b[11;1Hsending msg.txt [\u001b[62X█████████████░░░░░░░░░░░░░] 12 B/23 B | 143.24 KiB/s | eta: 0s\u001b[16;158H\u001b[11;1Hsending image.jpg [\u001b[60X████████████░░░░░░░░░░░░] 12 B/23 B | 125.27 KiB/s | eta: 0s\u001b[16;158H"]
[15.800063, "o", "\u001b[11;1Hsending image.jpg [\u001b[60X████████████████████████] 23 B/23 B | 147.09 KiB/s | eta: 0s\u001b[16;158H"]
[15.800103, "o", "\u001b[77Dreceiving msg.txt [\u001b[K████████████░░░░░░░░░░░░] 12 B/23 B | 53.24 KiB/s | eta: 0s\u001b[11;1HDone sending! [\u001b[64X████████████████████████████] 23 B/23 B | 121.08 KiB/s | eta: 0s\u001b[16;158H"]
[15.800157, "o", "\u001b[77Dreceiving image.jpg [\u001b[K███████████░░░░░░░░░░░] 12 B/23 B | 49.87 KiB/s | eta: 0s\u001b[16;81Hreceiving image.jpg [\u001b[K██████████████████████] 23 B/23 B | 58.20 KiB/s | eta: 0s"]
[15.800192, "o", "\u001b[16;81HDone downloading! [\u001b[K████████████████████████] 23 B/23 B | 62.49 KiB/s | eta: 0s"]
[15.800413, "o", "\u001b[12;1H\u001b[92m\u001b[1mpeer 1: \u001b[16;158H\u001b(B\u001b[m"]
[15.800539, "o", "\u001b[?2004h"]
[15.800574, "o", "\u001b[17;81H\u001b[92m\u001b[1mpeer 2: \u001b(B\u001b[m"]
[18.673528, "o", "\u001b[?25l\u001b[1;80H│\u001b[2;80H│\u001b[3;80H│\u001b[4;80H│\u001b[5;80H│\u001b[6;80H│\u001b[7;80H│\u001b[8;80H│\u001b[9;80H│\u001b[10;80H│\u001b[11;80H│\u001b[12;80H│\u001b[13;80H│\u001b[14;80H│\u001b[15;80H\u001b[32m│\u001b[16;80H│\u001b[17;80H│\u001b[18;80H│\u001b[19;80H│\u001b[20;80H│\u001b[21;80H│\u001b[22;80H│\u001b[23;80H│\u001b[24;80H│\u001b[25;80H│\u001b[26;80H│\u001b[27;80H│\u001b(B\u001b[m\u001b[30m\u001b[42m\r\n[demo_sess0:bash* \"marcin-laptop-mx\" 12:32 03-Jun-24\u001b(B\u001b[m\u001b[?12l\u001b[?25h\u001b[17;89H"]
31 changes: 31 additions & 0 deletions demo/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Custom script for starting a tmux 2-pane
# asciinema recording.
# Intended for recording gday demos.

# Requires: asciinema, tmux,
# and 2 subdirectories called 'peer_1', 'peer_2'

# Add gday to path using cargo install.

# Use ctrl+b <arrow key> to switch between panes.

# Start a new session detached
tmux new-session -d -s demo_session
tmux split-window -h

# Set both panes to a custom prompt
tmux send-keys -t demo_session:0.0 'export PS1="\033[1;92mpeer 1: \033[0m"' C-m
tmux send-keys -t demo_session:0.0 'cd peer_1' C-m
tmux send-keys -t demo_session:0.0 'clear' C-m

tmux send-keys -t demo_session:0.1 'export PS1="\033[1;92mpeer 2: \033[0m"' C-m
tmux send-keys -t demo_session:0.1 'cd peer_2' C-m
tmux send-keys -t demo_session:0.1 'clear' C-m

# Select the left pane
tmux select-pane -t demo_session:0.0

# Start recording
asciinema rec -c "tmux attach -t demo_session" --overwrite demo.cast
1 change: 1 addition & 0 deletions demo/peer_1/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demo/peer_1/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello there!
1 change: 1 addition & 0 deletions demo/peer_2/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demo/peer_2/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello there!
7 changes: 6 additions & 1 deletion gday/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = "1.0.82"
clap = { version = "4.5.4", features = ["derive"] }
env_logger = "0.11.3"
gday_encryption = { version = "0.1.0", path = "../gday_encryption" }
gday_file_offer_protocol = { version = "0.1.0", path = "../gday_file_offer_protocol" }
gday_file_transfer = { version = "0.1.0", path = "../gday_file_transfer" }
gday_hole_punch = { version = "0.1.0", path = "../gday_hole_punch" }
indicatif = "0.17.8"
log = "0.4.21"
Expand All @@ -22,3 +22,8 @@ postcard = "1.0.8"
rand = "0.8.5"
serde = { version = "1.0.197", features = ["serde_derive"] }
thiserror = "1.0.58"

[dev-dependencies]
assert_cmd = "2.0.14"
gday_server = { version = "0.1.0", path = "../gday_server" }
tempfile = "3.10.1"
10 changes: 4 additions & 6 deletions gday/src/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gday_file_offer_protocol::{FileMeta, FileMetaLocal};
use gday_file_transfer::{FileMeta, FileMetaLocal};
use indicatif::HumanBytes;
use owo_colors::OwoColorize;
use std::{
Expand All @@ -8,14 +8,12 @@ use std::{
path::{Path, PathBuf},
};

use crate::TMP_DOWNLOAD_PREFIX;

/// Asks the user which of these offered `files` to accept.
/// Returns a `Vec<Option<u64>>`, where each
/// - `None` represents rejecting the file at this index,
/// - `Some(0)` represents fully accepting the file at this index,
/// - `Some(x)` represents resuming with the first `x` bytes skipped.
pub fn ask_receive(files: &[FileMeta]) -> std::io::Result<Vec<Option<u64>>> {
pub fn ask_receive(files: &[FileMeta]) -> Result<Vec<Option<u64>>, gday_file_transfer::Error> {
let mut new_files = Vec::<Option<u64>>::with_capacity(files.len());
let mut new_size = 0;
let mut total_size = 0;
Expand Down Expand Up @@ -130,8 +128,8 @@ pub fn ask_send(paths: &[PathBuf]) -> std::io::Result<Vec<FileMetaLocal>> {
/// Checks if there exists a file like `meta`
/// whose download was interrupted.
/// Iff there is an interrupted file, returns Some(size of interrupted file)
fn interrupted_exists(meta: &FileMeta) -> std::io::Result<Option<u64>> {
let local_path = meta.get_prefixed_save_path(TMP_DOWNLOAD_PREFIX.into())?;
fn interrupted_exists(meta: &FileMeta) -> Result<Option<u64>, gday_file_transfer::Error> {
let local_path = meta.get_partial_download_path()?;

// check if the file can be opened
if let Ok(file) = File::open(local_path) {
Expand Down
Loading

0 comments on commit 1128b4f

Please sign in to comment.