peerline 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +211 -0
- package/README.md +149 -0
- package/npm/peerline.js +324 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Copyright 2026 BackRunner
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including the
|
|
63
|
+
original version of the Work and any modifications or additions to
|
|
64
|
+
that Work or Derivative Works thereof, that is intentionally submitted
|
|
65
|
+
to Licensor for inclusion in the Work by the copyright owner or by an
|
|
66
|
+
individual or Legal Entity authorized to submit on behalf of the
|
|
67
|
+
copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable by
|
|
93
|
+
such Contributor that are necessarily infringed by their Contribution(s)
|
|
94
|
+
alone or by combination of their Contribution(s) with the Work to which
|
|
95
|
+
such Contribution(s) was submitted. If You institute patent litigation
|
|
96
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
97
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
98
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
99
|
+
licenses granted to You under this License for that Work shall terminate
|
|
100
|
+
as of the date such litigation is filed.
|
|
101
|
+
|
|
102
|
+
4. Redistribution. You may reproduce and distribute copies of the Work
|
|
103
|
+
or Derivative Works thereof in any medium, with or without modifications,
|
|
104
|
+
and in Source or Object form, provided that You meet the following
|
|
105
|
+
conditions:
|
|
106
|
+
|
|
107
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
108
|
+
a copy of this License; and
|
|
109
|
+
|
|
110
|
+
(b) You must cause any modified files to carry prominent notices stating
|
|
111
|
+
that You changed the files; and
|
|
112
|
+
|
|
113
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
114
|
+
distribute, all copyright, patent, trademark, and attribution notices
|
|
115
|
+
from the Source form of the Work, excluding those notices that do not
|
|
116
|
+
pertain to any part of the Derivative Works; and
|
|
117
|
+
|
|
118
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
119
|
+
then any Derivative Works that You distribute must include a readable
|
|
120
|
+
copy of the attribution notices contained within such NOTICE file,
|
|
121
|
+
excluding those notices that do not pertain to any part of the
|
|
122
|
+
Derivative Works, in at least one of the following places: within a
|
|
123
|
+
NOTICE text file distributed as part of the Derivative Works; within
|
|
124
|
+
the Source form or documentation, if provided along with the Derivative
|
|
125
|
+
Works; or, within a display generated by the Derivative Works, if and
|
|
126
|
+
wherever such third-party notices normally appear. The contents of the
|
|
127
|
+
NOTICE file are for informational purposes only and do not modify the
|
|
128
|
+
License. You may add Your own attribution notices within Derivative
|
|
129
|
+
Works that You distribute, alongside or as an addendum to the NOTICE
|
|
130
|
+
text from the Work, provided that such additional attribution notices
|
|
131
|
+
cannot be construed as modifying the License.
|
|
132
|
+
|
|
133
|
+
You may add Your own copyright statement to Your modifications and may
|
|
134
|
+
provide additional or different license terms and conditions for use,
|
|
135
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
136
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
137
|
+
distribution of the Work otherwise complies with the conditions stated
|
|
138
|
+
in this License.
|
|
139
|
+
|
|
140
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
141
|
+
any Contribution intentionally submitted for inclusion in the Work by
|
|
142
|
+
You to the Licensor shall be under the terms and conditions of this
|
|
143
|
+
License, without any additional terms or conditions. Notwithstanding
|
|
144
|
+
the above, nothing herein shall supersede or modify the terms of any
|
|
145
|
+
separate license agreement you may have executed with Licensor
|
|
146
|
+
regarding such Contributions.
|
|
147
|
+
|
|
148
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
149
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
150
|
+
except as required for reasonable and customary use in describing the
|
|
151
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
152
|
+
|
|
153
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
154
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
155
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
156
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including, without
|
|
157
|
+
limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
|
158
|
+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
|
|
159
|
+
responsible for determining the appropriateness of using or
|
|
160
|
+
redistributing the Work and assume any risks associated with Your
|
|
161
|
+
exercise of permissions under this License.
|
|
162
|
+
|
|
163
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
164
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
165
|
+
unless required by applicable law (such as deliberate and grossly
|
|
166
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
167
|
+
liable to You for damages, including any direct, indirect, special,
|
|
168
|
+
incidental, or consequential damages of any character arising as a
|
|
169
|
+
result of this License or out of the use or inability to use the Work
|
|
170
|
+
(including but not limited to damages for loss of goodwill, work
|
|
171
|
+
stoppage, computer failure or malfunction, or any and all other
|
|
172
|
+
commercial damages or losses), even if such Contributor has been
|
|
173
|
+
advised of the possibility of such damages.
|
|
174
|
+
|
|
175
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
176
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
177
|
+
charge a fee for, acceptance of support, warranty, indemnity, or other
|
|
178
|
+
liability obligations and/or rights consistent with this License.
|
|
179
|
+
However, in accepting such obligations, You may act only on Your own
|
|
180
|
+
behalf and on Your sole responsibility, not on behalf of any other
|
|
181
|
+
Contributor, and only if You agree to indemnify, defend, and hold each
|
|
182
|
+
Contributor harmless for any liability incurred by, or claims asserted
|
|
183
|
+
against, such Contributor by reason of your accepting any such warranty
|
|
184
|
+
or additional liability.
|
|
185
|
+
|
|
186
|
+
END OF TERMS AND CONDITIONS
|
|
187
|
+
|
|
188
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
189
|
+
|
|
190
|
+
To apply the Apache License to your work, attach the following
|
|
191
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
192
|
+
replaced with your own identifying information. (Don't include
|
|
193
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
194
|
+
comment syntax for the file format. We also recommend that a
|
|
195
|
+
file or class name and description of purpose be included on the
|
|
196
|
+
same "printed page" as the copyright notice for easier
|
|
197
|
+
identification within third-party archives.
|
|
198
|
+
|
|
199
|
+
Copyright {yyyy} {name of copyright owner}
|
|
200
|
+
|
|
201
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
202
|
+
you may not use this file except in compliance with the License.
|
|
203
|
+
You may obtain a copy of the License at
|
|
204
|
+
|
|
205
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
206
|
+
|
|
207
|
+
Unless required by applicable law or agreed to in writing, software
|
|
208
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
209
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
210
|
+
See the License for the specific language governing permissions and
|
|
211
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Peerline
|
|
2
|
+
|
|
3
|
+
Peerline is a terminal-first peer-to-peer file transfer tool.
|
|
4
|
+
|
|
5
|
+
It is built for the moments when you want to move files, folders, logs, build artifacts, or project snapshots directly between two machines without first uploading them to a cloud drive. One side opens a receive session, shares a human-friendly name and code, and the other side sends one or more paths. Peerline then tries to find the best route between the two peers and transfers the data with application-layer end-to-end encryption.
|
|
6
|
+
|
|
7
|
+
Peerline is not a sync service and it does not keep a permanent hosted copy of your files. It is closer to a one-shot terminal copy workflow: start a receiver, send the paths, verify the transfer, and exit.
|
|
8
|
+
|
|
9
|
+
## Why Peerline Exists
|
|
10
|
+
|
|
11
|
+
- Direct handoff: transfer files and folders from one machine to another without using shared storage as the normal path.
|
|
12
|
+
- Human-friendly pairing: use readable names and codes instead of asking people to exchange long keys or machine identifiers.
|
|
13
|
+
- Flexible networking: prefer direct TCP, discover peers through libp2p, and use fallback routes when direct paths are unavailable.
|
|
14
|
+
- Encrypted by default: authenticate the transfer with the shared code and encrypt file contents at the application layer.
|
|
15
|
+
- Safe file handling: archive multiple inputs with safe relative paths, BLAKE3 integrity checks, and non-overwriting output by default.
|
|
16
|
+
|
|
17
|
+
## How It Works
|
|
18
|
+
|
|
19
|
+
Peerline has two roles:
|
|
20
|
+
|
|
21
|
+
- Receiver: runs `peerline recv`, listens for one incoming transfer, and prints a `name`, `code`, and direct endpoint.
|
|
22
|
+
- Sender: runs `peerline send`, points at the receiver by name/code or IP/code, and provides the files or folders to send.
|
|
23
|
+
|
|
24
|
+
For named transfers, the receiver publishes a short-lived descriptor keyed by the shared name and code. The sender derives the same lookup key, discovers candidate routes, and tries them in order. Peerline prefers direct LAN or public TCP endpoints first, then libp2p routes such as DCUtR and WebRTC TURN. Relay data fallback is available only when explicitly enabled.
|
|
25
|
+
|
|
26
|
+
Peerline also probes HTTP rendezvous first, with a default endpoint at `https://peerline.pwp.sh`, then falls back to DHT and mDNS. Official builds use a private mTLS-protected rendezvous endpoint; set `PEERLINE_RENDEZVOUS_CLIENT_IDENTITY_PATH` or `PEERLINE_RENDEZVOUS_CLIENT_IDENTITY_PEM` to a PEM bundle with the client certificate and private key, or set `PEERLINE_RENDEZVOUS_URLS` / `PEERLINE_RENDEZVOUS_URL` to point at another compatible rendezvous service. Use `PEERLINE_RENDEZVOUS_TOKEN` only when the rendezvous service expects a shared secret.
|
|
27
|
+
|
|
28
|
+
For direct transfers, the sender can skip discovery and dial an IP address or `host:port` directly. This is useful on the same network, over VPNs, or whenever the receiver already knows which address the sender should use. If you only provide an IP, Peerline probes the default direct window `43117-43121`.
|
|
29
|
+
|
|
30
|
+
During a transfer, Peerline scans the requested paths into a manifest, preserves directories with safe relative paths, compresses when useful, and streams the archive to the receiver. The receiver verifies file sizes and BLAKE3 hashes before writing files into the current directory. Existing files are kept by default; conflicting names receive a non-overwriting suffix unless `--overwrite` is used.
|
|
31
|
+
|
|
32
|
+
The secure session combines the shared code with OPAQUE PAKE, X25519, ML-KEM, HKDF, and ChaCha20-Poly1305. Discovery and transport routes can vary, but file contents stay encrypted by Peerline itself.
|
|
33
|
+
|
|
34
|
+
## Install And Run
|
|
35
|
+
|
|
36
|
+
Use the npm package without installing it globally:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npx peerline@alpha --help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Install it globally through npm:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install -g peerline@alpha
|
|
46
|
+
peerline --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The npm package is a small launcher. It runs a local `target/debug/peerline` or `target/release/peerline` during development; installed packages download the matching macOS, Linux, or Windows binary from the corresponding GitHub Release on first use and cache it locally.
|
|
50
|
+
|
|
51
|
+
Run from source:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
cargo run -p peerline-cli -- --help
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Build a local binary:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
cargo build --release -p peerline-cli
|
|
61
|
+
./target/release/peerline --help
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Basic Usage
|
|
65
|
+
|
|
66
|
+
Start a receiver:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
peerline recv
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The receiver prints values like:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
peerline recv
|
|
76
|
+
name: frost-827
|
|
77
|
+
code: fig-mint-1234-5678
|
|
78
|
+
direct: 0.0.0.0:43117
|
|
79
|
+
waiting for one transfer over direct TCP or libp2p...
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Send a file, multiple files, or a folder by name and code:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
peerline send frost-827 fig-mint-1234-5678 ./file.txt
|
|
86
|
+
peerline send frost-827 fig-mint-1234-5678 ./file.txt ./notes.md ./photos
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Receive with a saved name:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
peerline set name frost-827
|
|
93
|
+
peerline recv
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
After a name is saved, you can receive with only a fresh code:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
peerline recv fig-mint-1234-5678
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Use a direct IP address when discovery is not needed:
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
peerline send 192.168.1.23:43117 ./file.txt --code=fig-mint-1234-5678
|
|
106
|
+
peerline send 192.168.1.23 ./folder --code=fig-mint-1234-5678
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
When the port is omitted, Peerline probes the default direct window `43117-43121`.
|
|
110
|
+
|
|
111
|
+
## Common Options
|
|
112
|
+
|
|
113
|
+
Receiver options:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
peerline recv [NAME_OR_CODE] [CODE] --port 43117
|
|
117
|
+
peerline recv [NAME_OR_CODE] [CODE] --overwrite
|
|
118
|
+
peerline recv [NAME_OR_CODE] [CODE] --no-tui
|
|
119
|
+
peerline recv [NAME_OR_CODE] [CODE] --allow-relay-fallback
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`--port` starts the 5-port direct window; Peerline will try that port and the next four.
|
|
123
|
+
|
|
124
|
+
Sender options:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
peerline send <name> <code> <path...> --compression auto
|
|
128
|
+
peerline send <name> <code> <path...> --compression none
|
|
129
|
+
peerline send <name> <code> <path...> --compression zstd
|
|
130
|
+
peerline send <name> <code> <path...> --compression lzma
|
|
131
|
+
peerline send <name> <code> <path...> --allow-relay-fallback
|
|
132
|
+
peerline send --name <name> --code <code> <path...>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Relay fallback must be enabled on both sides when you want Peerline to use relay data paths. Direct and hole-punched routes are attempted before relay fallback.
|
|
136
|
+
|
|
137
|
+
## Current Status
|
|
138
|
+
|
|
139
|
+
- Direct IP send and receive works.
|
|
140
|
+
- Named discovery now uses HTTP rendezvous first, then Kademlia provider records, mDNS, DCUtR, relay fallback, and libp2p-webrtc's built-in ICE servers.
|
|
141
|
+
- Files, multiple files, and folders are archived with safe relative paths, BLAKE3 integrity checks, and streaming zstd/lzma compression support.
|
|
142
|
+
- Conflicts default to non-overwrite behavior, with TUI-driven handling in the receiver flow.
|
|
143
|
+
- The receive side includes a modern terminal UI for identity, route state, and transfer progress.
|
|
144
|
+
- The workspace test suite and E2E coverage are in place.
|
|
145
|
+
- The repository also includes a private Cloudflare Worker rendezvous service in `services/peerline-rendezvous`.
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
Apache-2.0.
|
package/npm/peerline.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require("node:child_process");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const https = require("node:https");
|
|
7
|
+
const os = require("node:os");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
|
|
10
|
+
function detectLibc(reportGetter = () => process.report?.getReport?.()) {
|
|
11
|
+
if (process.platform !== "linux") {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const report = reportGetter();
|
|
17
|
+
return report?.header?.glibcVersionRuntime ? "gnu" : "musl";
|
|
18
|
+
} catch {
|
|
19
|
+
return "gnu";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function packageName(platform = process.platform, arch = process.arch, libc = detectLibc()) {
|
|
24
|
+
if (platform === "darwin" && arch === "arm64") return "peerline-darwin-arm64";
|
|
25
|
+
if (platform === "darwin" && arch === "x64") return "peerline-darwin-x64";
|
|
26
|
+
if (platform === "linux" && arch === "x64") return `peerline-linux-x64-${libc === "musl" ? "musl" : "gnu"}`;
|
|
27
|
+
if (platform === "linux" && arch === "arm64") return `peerline-linux-arm64-${libc === "musl" ? "musl" : "gnu"}`;
|
|
28
|
+
if (platform === "win32" && arch === "x64") return "peerline-win32-x64-msvc";
|
|
29
|
+
throw new Error(`unsupported platform: ${platform} ${arch}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function binaryName() {
|
|
33
|
+
return process.platform === "win32" ? "peerline.exe" : "peerline";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function releaseAssetName(platformPackage = packageName(), binary = binaryName()) {
|
|
37
|
+
return binary.endsWith(".exe") ? `${platformPackage}.exe` : platformPackage;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function packageVersion(fsImpl = fs) {
|
|
41
|
+
const pkg = JSON.parse(fsImpl.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
42
|
+
return pkg.version;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function cacheRoot(env = process.env, osImpl = os) {
|
|
46
|
+
if (env.PEERLINE_BINARY_CACHE) return env.PEERLINE_BINARY_CACHE;
|
|
47
|
+
if (process.platform === "win32" && env.LOCALAPPDATA) return path.join(env.LOCALAPPDATA, "peerline");
|
|
48
|
+
if (process.platform === "darwin") return path.join(osImpl.homedir(), "Library", "Caches", "peerline");
|
|
49
|
+
return path.join(env.XDG_CACHE_HOME || path.join(osImpl.homedir(), ".cache"), "peerline");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function releaseDownloadBaseUrl(version = packageVersion(), env = process.env) {
|
|
53
|
+
return (env.PEERLINE_DOWNLOAD_BASE_URL || `https://github.com/backrunner/peerline/releases/download/v${version}`).replace(
|
|
54
|
+
/\/+$/,
|
|
55
|
+
""
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function releaseAssetUrl(version = packageVersion(), env = process.env) {
|
|
60
|
+
return `${releaseDownloadBaseUrl(version, env)}/${releaseAssetName()}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function cachedBinaryPath(version = packageVersion(), env = process.env, osImpl = os) {
|
|
64
|
+
return path.join(cacheRoot(env, osImpl), version, releaseAssetName());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function ensureExecutable(binaryPath, fsImpl = fs) {
|
|
68
|
+
if (process.platform === "win32") {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
fsImpl.accessSync(binaryPath, fs.constants.X_OK);
|
|
74
|
+
return;
|
|
75
|
+
} catch {
|
|
76
|
+
// Fall through and repair the mode bits below.
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const stat = fsImpl.statSync(binaryPath);
|
|
81
|
+
fsImpl.chmodSync(binaryPath, stat.mode | 0o111);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error && (error.code === "EACCES" || error.code === "EPERM" || error.code === "EROFS")) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isRetryableExecutionError(error) {
|
|
91
|
+
return Boolean(error && (error.code === "EACCES" || error.code === "ENOEXEC"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function copyBinaryToTemporaryLocation(binaryPath, fsImpl = fs, osImpl = os) {
|
|
95
|
+
const tempDir = fsImpl.mkdtempSync(path.join(osImpl.tmpdir(), "peerline-exec-"));
|
|
96
|
+
const tempBinary = path.join(tempDir, binaryName());
|
|
97
|
+
|
|
98
|
+
fsImpl.copyFileSync(binaryPath, tempBinary);
|
|
99
|
+
fsImpl.chmodSync(tempBinary, 0o755);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
binaryPath: tempBinary,
|
|
103
|
+
cleanup() {
|
|
104
|
+
fsImpl.rmSync(tempDir, { recursive: true, force: true });
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function formatExecutionFallbackError(binaryPath, primaryCode, fallbackCode, fallbackPath) {
|
|
110
|
+
return [
|
|
111
|
+
`peerline could not execute its bundled binary from ${binaryPath}.`,
|
|
112
|
+
`Primary error: ${primaryCode}.`,
|
|
113
|
+
fallbackPath
|
|
114
|
+
? `Temporary copy at ${fallbackPath} also failed with ${fallbackCode}.`
|
|
115
|
+
: `Creating a temporary executable copy also failed with ${fallbackCode}.`,
|
|
116
|
+
"This usually means the package cache or temporary directory cannot execute files.",
|
|
117
|
+
].join(" ");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function resolvePackagedBinary(fsImpl = fs) {
|
|
121
|
+
const localRelease = path.join(__dirname, "..", "target", "release", binaryName());
|
|
122
|
+
if (fsImpl.existsSync(localRelease)) return localRelease;
|
|
123
|
+
|
|
124
|
+
const localDebug = path.join(__dirname, "..", "target", "debug", binaryName());
|
|
125
|
+
if (fsImpl.existsSync(localDebug)) return localDebug;
|
|
126
|
+
|
|
127
|
+
const pkg = packageName();
|
|
128
|
+
let pkgJson;
|
|
129
|
+
try {
|
|
130
|
+
pkgJson = require.resolve(`${pkg}/package.json`, { paths: [__dirname] });
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error && error.code === "MODULE_NOT_FOUND") {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
const candidate = path.join(path.dirname(pkgJson), "bin", binaryName());
|
|
138
|
+
if (!fsImpl.existsSync(candidate)) {
|
|
139
|
+
throw new Error(`missing peerline binary in ${pkg}`);
|
|
140
|
+
}
|
|
141
|
+
return candidate;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function downloadToFile(url, destination, deps = {}, redirects = 0) {
|
|
145
|
+
const httpsImpl = deps.https ?? https;
|
|
146
|
+
const fsImpl = deps.fs ?? fs;
|
|
147
|
+
if (redirects > 5) {
|
|
148
|
+
return Promise.reject(new Error(`too many redirects while downloading ${url}`));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return new Promise((resolve, reject) => {
|
|
152
|
+
const request = httpsImpl.get(
|
|
153
|
+
url,
|
|
154
|
+
{
|
|
155
|
+
headers: {
|
|
156
|
+
"User-Agent": `peerline-npm/${packageVersion(fsImpl)}`,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
(response) => {
|
|
160
|
+
if (
|
|
161
|
+
response.statusCode >= 300 &&
|
|
162
|
+
response.statusCode < 400 &&
|
|
163
|
+
response.headers.location
|
|
164
|
+
) {
|
|
165
|
+
response.resume();
|
|
166
|
+
downloadToFile(new URL(response.headers.location, url).toString(), destination, deps, redirects + 1)
|
|
167
|
+
.then(resolve, reject);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (response.statusCode !== 200) {
|
|
172
|
+
response.resume();
|
|
173
|
+
reject(new Error(`download failed with HTTP ${response.statusCode}: ${url}`));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const output = fsImpl.createWriteStream(destination, { mode: 0o755 });
|
|
178
|
+
output.on("error", reject);
|
|
179
|
+
response.on("error", reject);
|
|
180
|
+
output.on("finish", () => output.close(resolve));
|
|
181
|
+
response.pipe(output);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
request.on("error", reject);
|
|
185
|
+
request.setTimeout(60_000, () => {
|
|
186
|
+
request.destroy(new Error(`timed out downloading ${url}`));
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function downloadReleaseBinary(deps = {}) {
|
|
192
|
+
const fsImpl = deps.fs ?? fs;
|
|
193
|
+
const osImpl = deps.os ?? os;
|
|
194
|
+
const env = deps.env ?? process.env;
|
|
195
|
+
const version = packageVersion(fsImpl);
|
|
196
|
+
const binaryPath = cachedBinaryPath(version, env, osImpl);
|
|
197
|
+
|
|
198
|
+
if (fsImpl.existsSync(binaryPath)) {
|
|
199
|
+
ensureExecutable(binaryPath, fsImpl);
|
|
200
|
+
return binaryPath;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const dir = path.dirname(binaryPath);
|
|
204
|
+
fsImpl.mkdirSync(dir, { recursive: true });
|
|
205
|
+
const tempPath = path.join(dir, `.download-${process.pid}-${Date.now()}`);
|
|
206
|
+
const url = releaseAssetUrl(version, env);
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
await downloadToFile(url, tempPath, deps);
|
|
210
|
+
if (process.platform !== "win32") {
|
|
211
|
+
fsImpl.chmodSync(tempPath, 0o755);
|
|
212
|
+
}
|
|
213
|
+
fsImpl.renameSync(tempPath, binaryPath);
|
|
214
|
+
ensureExecutable(binaryPath, fsImpl);
|
|
215
|
+
return binaryPath;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
try {
|
|
218
|
+
fsImpl.rmSync(tempPath, { force: true });
|
|
219
|
+
} catch {
|
|
220
|
+
// Ignore cleanup failures; the download error below is the useful one.
|
|
221
|
+
}
|
|
222
|
+
throw new Error(
|
|
223
|
+
[
|
|
224
|
+
`missing local peerline binary and could not download ${releaseAssetName()} from ${url}.`,
|
|
225
|
+
error.message,
|
|
226
|
+
"Install from source with cargo, or retry when the GitHub release asset is available.",
|
|
227
|
+
].join(" ")
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function resolveBinary(deps = {}) {
|
|
233
|
+
return resolvePackagedBinary(deps.fs ?? fs) || downloadReleaseBinary(deps);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function executeBinary(binaryPath, argv = process.argv.slice(2), deps = {}) {
|
|
237
|
+
const spawnImpl = deps.spawnSync ?? spawnSync;
|
|
238
|
+
const fsImpl = deps.fs ?? fs;
|
|
239
|
+
const osImpl = deps.os ?? os;
|
|
240
|
+
const spawnOptions = {
|
|
241
|
+
stdio: "inherit",
|
|
242
|
+
...(deps.spawnOptions ?? {}),
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
ensureExecutable(binaryPath, fsImpl);
|
|
246
|
+
|
|
247
|
+
const primaryResult = spawnImpl(binaryPath, argv, spawnOptions);
|
|
248
|
+
if (!primaryResult.error) {
|
|
249
|
+
return primaryResult;
|
|
250
|
+
}
|
|
251
|
+
if (!isRetryableExecutionError(primaryResult.error)) {
|
|
252
|
+
throw primaryResult.error;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let tempBinary;
|
|
256
|
+
try {
|
|
257
|
+
try {
|
|
258
|
+
tempBinary = copyBinaryToTemporaryLocation(binaryPath, fsImpl, osImpl);
|
|
259
|
+
} catch (copyError) {
|
|
260
|
+
const error = new Error(
|
|
261
|
+
formatExecutionFallbackError(binaryPath, primaryResult.error.code ?? "unknown", copyError.code ?? "unknown")
|
|
262
|
+
);
|
|
263
|
+
error.cause = copyError;
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const retryResult = spawnImpl(tempBinary.binaryPath, argv, spawnOptions);
|
|
268
|
+
if (!retryResult.error) {
|
|
269
|
+
return retryResult;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const error = new Error(
|
|
273
|
+
formatExecutionFallbackError(
|
|
274
|
+
binaryPath,
|
|
275
|
+
primaryResult.error.code ?? "unknown",
|
|
276
|
+
retryResult.error.code ?? "unknown",
|
|
277
|
+
tempBinary.binaryPath
|
|
278
|
+
)
|
|
279
|
+
);
|
|
280
|
+
error.cause = retryResult.error;
|
|
281
|
+
throw error;
|
|
282
|
+
} finally {
|
|
283
|
+
if (tempBinary) {
|
|
284
|
+
try {
|
|
285
|
+
tempBinary.cleanup();
|
|
286
|
+
} catch {
|
|
287
|
+
// Ignore cleanup failures; execution has already finished or failed.
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function main(argv = process.argv.slice(2), deps = {}) {
|
|
294
|
+
const result = executeBinary(await resolveBinary(deps), argv, deps);
|
|
295
|
+
process.exit(result.status ?? 1);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (require.main === module) {
|
|
299
|
+
main().catch((error) => {
|
|
300
|
+
console.error(error.message);
|
|
301
|
+
process.exit(1);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
module.exports = {
|
|
306
|
+
binaryName,
|
|
307
|
+
cachedBinaryPath,
|
|
308
|
+
cacheRoot,
|
|
309
|
+
detectLibc,
|
|
310
|
+
downloadReleaseBinary,
|
|
311
|
+
ensureExecutable,
|
|
312
|
+
executeBinary,
|
|
313
|
+
copyBinaryToTemporaryLocation,
|
|
314
|
+
formatExecutionFallbackError,
|
|
315
|
+
isRetryableExecutionError,
|
|
316
|
+
main,
|
|
317
|
+
packageName,
|
|
318
|
+
packageVersion,
|
|
319
|
+
releaseAssetName,
|
|
320
|
+
releaseAssetUrl,
|
|
321
|
+
releaseDownloadBaseUrl,
|
|
322
|
+
resolvePackagedBinary,
|
|
323
|
+
resolveBinary,
|
|
324
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peerline",
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
|
+
"description": "P2P post-quantum encrypted file transfer CLI",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/backrunner/peerline"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"peerline": "npm/peerline.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"npm/peerline.js",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "cargo build --release -p peerline-cli",
|
|
19
|
+
"build:platform-asset": "node npm/build-platform-asset.js",
|
|
20
|
+
"lint": "cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && node --check npm/peerline.js && node --check npm/release.js && node --check npm/release-alpha.js && node --check npm/build-platform-asset.js && node --check npm/prepack.js && node --check npm/peerline.test.js && node --check npm/release.test.js",
|
|
21
|
+
"prepack": "node npm/prepack.js",
|
|
22
|
+
"release:alpha": "node npm/release.js --channel=alpha",
|
|
23
|
+
"release:beta": "node npm/release.js --channel=beta",
|
|
24
|
+
"release:stable": "node npm/release.js --channel=stable",
|
|
25
|
+
"release": "node npm/release.js --channel=stable",
|
|
26
|
+
"test": "npm run test:rust && npm run test:node",
|
|
27
|
+
"test:node": "node --test npm/peerline.test.js npm/release.test.js",
|
|
28
|
+
"test:rust": "cargo test --workspace -- --test-threads=1",
|
|
29
|
+
"smoke": "node npm/peerline.js --version"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"license": "Apache-2.0"
|
|
35
|
+
}
|