Skip to content

Commit 53db42f

Browse files
committed
update ui
1 parent 2081b4e commit 53db42f

File tree

3 files changed

+60
-61
lines changed

3 files changed

+60
-61
lines changed

README.md

+52-44
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
I hear you asking, *Why another open-source peer-to-peer file transfer utilities?* [There](https://github.com/cowbell/sharedrop) [are](https://github.com/webtorrent/instant.io) [great](https://github.com/kern/filepizza) [tools](https://github.com/warner/magic-wormhole) [that](https://github.com/zerotier/toss) [already](https://github.com/ipfs/go-ipfs) [do](https://github.com/zerotier/toss) [this](https://github.com/nils-werner/zget). But, after review, [I found it was useful to make another](https://schollz.github.io/sending-a-file/). Namely, *croc* has no dependencies (just [download a binary and run](https://github.com/schollz/croc/releases/latest)), it works on any operating system, and its blazingly fast because it does parallel transfer over multiple TCP ports.
1717

18-
# Example
18+
## Example
1919

2020
_These two gifs should run in sync if you force-reload (Ctl+F5)_
2121

@@ -28,86 +28,92 @@ _These two gifs should run in sync if you force-reload (Ctl+F5)_
2828
![receive](https://raw.githubusercontent.com/schollz/croc/master/src/testing_data/recipient.gif)
2929

3030

31-
**Sender:**
31+
## Install
3232

33-
```
34-
$ croc send some-file-or-folder
35-
Sending 1.1 MB file named 'some-file-or-folder'
36-
Code is: fidel-parent-insect
37-
On the other computer please run
33+
[Download the latest release for your system](https://github.com/schollz/croc/releases/latest).
34+
35+
Or, you can [install Go](https://golang.org/dl/) and build from source with `go get github.com/schollz/croc`.
3836

39-
croc fidel-parent-insect
4037

41-
Sending (->[1]63982)..
42-
89% |███████████████████████████████████ | [12s:1s]
43-
Transfer complete.
44-
```
38+
## Usage
4539

46-
**Receiver:**
40+
The basic usage is to just do
4741

4842
```
49-
$ croc
50-
Enter receive code: fidel-parent-insect
51-
Receiving file (1.1 MB) into: some-file-or-folder
52-
ok? (y/N): y
53-
54-
Receiving (<-[1]63975)..
55-
97% |██████████████████████████████████████ | [13s:0s]
56-
Received file written to some-file-or-folder
43+
$ croc send FILE
5744
```
5845

59-
Note, by default, you don't need any arguments for receiving! This makes it possible for you to just double click the executable to run (nice for those of us that aren't computer wizards).
46+
to send and then on the other computer you can just do
6047

61-
## Using *croc* in pipes
48+
```
49+
$ croc [code phrase]
50+
```
6251

63-
You can easily use *croc* in pipes when you need to send data through stdin or get data from stdout.
52+
to receive (you'll be prompted to enter the code phrase). Note, by default, you don't need any arguments for receiving, instead you will be prompted to enter the code phrase. This makes it possible for you to just double click the executable to run (nice for those of us that aren't computer wizards).
6453

65-
**Sender:**
54+
### Custom code phrase
55+
56+
You can send with your own code phrase (must be more than 4 characters).
6657

6758
```
68-
$ cat some_file_or_folder | croc send
59+
$ croc send --code [code phrase] [filename]
6960
```
7061

71-
In this case *croc* will automatically use the stdin data and send and assign a filename like "croc-stdin-123456789".
62+
### Use locally
7263

73-
**Receiver:**
64+
*croc* automatically will attempt to start a local connection on your LAN to transfer the file much faster. It uses [peer discovery](https://github.com/schollz/peerdiscovery), basically broadcasting a message on the local subnet to see if another *croc* user wants to receive the file. *croc* will utilize the first incoming connection from either the local network or the public relay and follow through with PAKE.
65+
66+
You can change this behavior by forcing *croc* to use only local connections (`--local`) or force to use the public relay only (`--no-local`):
7467

7568
```
76-
$ croc --code code-phrase --yes --stdout receive
69+
$ croc --local/--no-local send [filename]
7770
```
7871

79-
Here the receiver specified the code (`--code`) so it will not be prompted, and also specified `--yes` so the file will be automatically accepted. The output goes to stdout when flagged with `--stdout`.
72+
### Using pipes - stdin and stdout
8073

74+
You can easily use *croc* in pipes when you need to send data through stdin or get data from stdout. To send you can just use pipes:
8175

82-
# Install
76+
```
77+
$ cat [filename] | croc send
78+
```
8379

84-
[Download the latest release for your system](https://github.com/schollz/croc/releases/latest).
80+
In this case *croc* will automatically use the stdin data and send and assign a filename like "croc-stdin-123456789". To receive to stdout at you can always just use the `-yes` and `-stdout` flags which will automatically approve the transfer and pipe it out to stdout.
8581

86-
Or, you can [install Go](https://golang.org/dl/) and build from source with `go get github.com/schollz/croc`.
82+
```
83+
$ croc -yes -stdout [code phrase] > out
84+
```
8785

86+
All of the other text printed to the console is going to `stderr` so it will not interfere with the message going to stdout.
8887

88+
### Self-host relay
8989

90-
# How does it work?
90+
The relay is needed to staple the parallel incoming and outgoing connections. The relay temporarily stores connection information and the encrypted meta information. The default uses a public relay at, `wss://croc3.schollz.com`. You can also run your own relay, it is very easy, just run:
9191

92-
*croc* is similar to [magic-wormhole](https://github.com/warner/magic-wormhole#design) in spirit and design. Like *magic-wormhole*, *croc* generates a code phrase for you to share with your friend which allows secure end-to-end transferring of files and folders through a intermediary relay that connects the TCP ports between the two computers. Also like *magic-wormhole*, security is enabled by performing password-authenticated key exchange (PAKE) with the weak code phrase to generate a session key on both machines without passing any private information between the two. The session key is then verified and used to encrypt the content with AES-256. If at any point the PAKE fails, an error will be reported and the file will not be transferred. More details on the PAKE transfer can be found at [github.com/schollz/pake](https://github.com/schollz/pake).
92+
```
93+
$ croc relay
94+
```
9395

94-
## Relay
96+
Make sure to open up TCP ports (see `croc relay --help` for which ports to open). You can also define your own ports with `-tcp` and `-port`. Relays can also be customized to which elliptic curve they will use (default is siec).
9597

96-
*croc* relies on a TCP relay to staple the parallel incoming and outgoing connections. The relay temporarily stores connection information and the encrypted meta information. The default uses a public relay at, `wss://croc3.schollz.com`. You can also run your own relay, it is very easy. On your server, `your-server.com`, just run
98+
You can send files using your relay by entering `-relay` to change the relay that you are using if you want to custom host your own.
9799

98100
```
99-
$ croc relay
101+
$ croc -relay "ws://myrelay.example.com" send [filename]
100102
```
101103

102-
Now, when you use *croc* to send and receive you should add `-server your-server.com` to use your relay server. Make sure to open up TCP ports (see `croc relay --help` for which ports to open).
103104

104-
# Contribute
105105

106-
I am awed by all the [great contributions](#acknowledgements) made! If you feel like contributing, in any way, by all means you can send an Issue, a PR, ask a question, or tweet me ([@yakczar](http://ctt.ec/Rq054)).
107106

107+
## How does it work?
108+
109+
*croc* is similar to [magic-wormhole](https://github.com/warner/magic-wormhole#design) in spirit and design. Like *magic-wormhole*, *croc* generates a code phrase for you to share with your friend which allows secure end-to-end transferring of files and folders through a intermediary relay that connects the TCP ports between the two computers. Also like *magic-wormhole*, security is enabled by performing password-authenticated key exchange (PAKE) with the weak code phrase to generate a session key on both machines without passing any private information between the two. The session key is then verified and used to encrypt the content and meta-data with AES-256. If at any point the PAKE fails, an error will be reported and the file will not be transferred. More details on the PAKE transfer can be found at [github.com/schollz/pake](https://github.com/schollz/pake) and below in the [protocol](#protocol).
110+
111+
The intermediary relay uses websockets to have bidirectional communication with potential senders and recipients. Only one sender and one recipient is allowed in a channel at once. The relay helps to deliver the PAKE information, and once both parties agree, it will staple the connections between the sender and recipient and pipe all incoming TCP data from the sender to the recipient.
108112

113+
When sending a file with *croc*, a local relay is initiated which will try to discover local peers for connection. If a recipient is found locally, then the local connections are used and the public relay is never used. This way, *croc* can be used without a public internet connection (i.e. to transfer files over LAN).
109114

110-
# Protocol
115+
116+
## Protocol
111117

112118
This is an outline of the protocol used here. The basic PAKE protocol is from [Dan Boneh and Victor Shoup's crypto book](https://crypto.stanford.edu/%7Edabo/cryptobook/BonehShoup_0_4.pdf) (pg 789, "PAKE2 protocol).
113119

@@ -189,11 +195,13 @@ The websocket implementation means that each client and relay follows their spec
189195

190196

191197

192-
# License
198+
## License
193199

194200
MIT
195201

196-
# Acknowledgements
202+
## Acknowledgements
203+
204+
I am awed by all the [great contributions](#acknowledgements) made! If you feel like contributing, in any way, by all means you can send an Issue, a PR, ask a question, or tweet me ([@yakczar](http://ctt.ec/Rq054)).
197205

198206
Thanks...
199207

main.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,15 @@ func main() {
3535
Description: "send a file over the relay",
3636
ArgsUsage: "[filename]",
3737
Flags: []cli.Flag{
38-
cli.BoolFlag{Name: "no-compress, o"},
39-
cli.BoolFlag{Name: "no-encrypt, e"},
38+
cli.BoolFlag{Name: "no-compress, o", Usage: "disable compression"},
39+
cli.BoolFlag{Name: "no-encrypt, e", Usage: "disable encryption"},
40+
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
4041
},
4142
HelpName: "croc send",
4243
Action: func(c *cli.Context) error {
4344
return send(c)
4445
},
4546
},
46-
{
47-
Name: "receive",
48-
Usage: "receive a file",
49-
Description: "receve a file over the relay",
50-
HelpName: "croc receive",
51-
Action: func(c *cli.Context) error {
52-
return receive(c)
53-
},
54-
},
5547
{
5648
Name: "relay",
5749
Usage: "start a croc relay",
@@ -69,7 +61,6 @@ func main() {
6961
}
7062
app.Flags = []cli.Flag{
7163
cli.StringFlag{Name: "relay", Value: "wss://croc3.schollz.com"},
72-
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
7364
cli.BoolFlag{Name: "no-local", Usage: "disable local mode"},
7465
cli.BoolFlag{Name: "local", Usage: "use only local mode"},
7566
cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"},
@@ -80,7 +71,7 @@ func main() {
8071
app.HideHelp = false
8172
app.HideVersion = false
8273
app.BashComplete = func(c *cli.Context) {
83-
fmt.Fprintf(c.App.Writer, "lipstick\nkiss\nme\nlipstick\nringo\n")
74+
fmt.Fprintf(c.App.Writer, "send\nreceive\relay")
8475
}
8576
app.Action = func(c *cli.Context) error {
8677
return receive(c)
@@ -116,8 +107,8 @@ func send(c *cli.Context) error {
116107
}
117108
cr.UseCompression = !c.Bool("no-compress")
118109
cr.UseEncryption = !c.Bool("no-encrypt")
119-
if c.GlobalString("code") != "" {
120-
codePhrase = c.GlobalString("code")
110+
if c.String("code") != "" {
111+
codePhrase = c.String("code")
121112
}
122113
return cr.Send(fname, codePhrase)
123114
}

src/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (c *Croc) client(role int, channel string) (err error) {
161161
}
162162
// push to stdout if required
163163
if c.Stdout && !c.cs.channel.fileMetaData.IsDir {
164-
fmt.Fprintf(os.Stderr, "\nReceived %s written to %s. (%2.1f %s)\n", folderOrFile, "stdout", transferRate, transferType)
164+
fmt.Fprintf(os.Stderr, "\nReceived %s written to %s (%2.1f %s)\n", folderOrFile, "stdout", transferRate, transferType)
165165
var bFile []byte
166166
bFile, err = ioutil.ReadFile(c.cs.channel.fileMetaData.Name)
167167
if err != nil {
@@ -170,7 +170,7 @@ func (c *Croc) client(role int, channel string) (err error) {
170170
os.Stdout.Write(bFile)
171171
os.Remove(c.cs.channel.fileMetaData.Name)
172172
} else {
173-
fmt.Fprintf(os.Stderr, "\nReceived %s written to %s. (%2.1f %s)\n", folderOrFile, c.cs.channel.fileMetaData.Name, transferRate, transferType)
173+
fmt.Fprintf(os.Stderr, "\nReceived %s written to %s (%2.1f %s)\n", folderOrFile, c.cs.channel.fileMetaData.Name, transferRate, transferType)
174174
}
175175
}
176176
} else {

0 commit comments

Comments
 (0)