Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement-208] Add an option to send multiple times the same files #628

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9d949ed
add id to connections
RCL98 Oct 10, 2023
bf70494
add multiple file transfers and tiemout options in cli
RCL98 Oct 10, 2023
e838fb8
allow tcp server to keep room for multiple transfers
RCL98 Oct 10, 2023
3351d2d
prepare croc for multiple transfers
RCL98 Oct 10, 2023
2352dcb
allow multiple transfers from croc
RCL98 Oct 13, 2023
976c4c5
multiple transfers work
RCL98 Oct 27, 2023
edd2db8
fix multiple transfers
RCL98 Oct 28, 2023
4711d9e
added wait and transfer conclusions messages
RCL98 Oct 28, 2023
3c3ed98
small clean up
RCL98 Oct 28, 2023
fec1d3c
refactor tcp
RCL98 Oct 28, 2023
1c7e72d
cli final from for timelimit and multiple
RCL98 Oct 29, 2023
8f7e7f7
update tcp test and fix sender gone problems
RCL98 Oct 31, 2023
51427f0
update message test
RCL98 Oct 31, 2023
3946752
update croc unit test and fix tcp and crocs bugs
RCL98 Nov 6, 2023
15960a6
update comm test
RCL98 Nov 6, 2023
26144d6
allow multiple transfers on local connection
RCL98 Nov 6, 2023
c5ecc78
Merge remote-tracking branch 'upstream/main' into enhancement_208
RCL98 Nov 6, 2023
6f8039b
update readme and cli
RCL98 Nov 7, 2023
20fb6ce
fix build problem
RCL98 Nov 11, 2023
cb5da0c
allow both sender and receiver to reserve a room
RCL98 Nov 11, 2023
990d3fb
fix croc ignore git unit test
RCL98 Nov 11, 2023
0018a2a
Merge branch 'main' into enhancement_208
RCL98 Nov 11, 2023
0dd5142
clean up
RCL98 Nov 11, 2023
5a541d7
more clean up
RCL98 Nov 11, 2023
345f46a
more clean up
RCL98 Nov 11, 2023
671bad1
Merge branch 'enhancement_208' of https://github.com/RCL98/croc into …
RCL98 Nov 11, 2023
e5ba8c5
fix remove receivers from queue
RCL98 Nov 11, 2023
ee927bd
allow only one sender to connect
RCL98 Nov 13, 2023
9a76162
fix unit test
RCL98 Nov 13, 2023
25ee1eb
small clean up
RCL98 Nov 13, 2023
0318794
give receiver time to lock mutex
RCL98 Nov 13, 2023
ffe4d7e
fix spelling mistakes
RCL98 Dec 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Status"></a>
- provides **end-to-end encryption** (using PAKE)
- enables easy **cross-platform** transfers (Windows, Linux, Mac)
- allows **multiple file** transfers
- allows **multiple sequential** transfers
- allows **resuming transfers** that are interrupted
- local server or port-forwarding **not needed**
- **ipv6-first** with ipv4 fallback
Expand Down Expand Up @@ -134,6 +135,33 @@ The code phrase is used to establish password-authenticated key agreement ([PAKE

There are a number of configurable options (see `--help`). A set of options (like custom relay, ports, and code phrase) can be set using `--remember`.

### Transfer on LAN only

You can transfer files using only local connections.

```
croc --local send [file(s)-or-folder]
```

### Allow multiple sequential transfers

By default, after a transfer is done, the program stops.
You can allow more than one transfer to happen (one after another) by using the `--multiple` flag, which requires a value >= 1.

```
croc send --multiple [nr-of-transfers] [file(s)-or-folder]
```

After all `[nr-of-transfers]` were done, the program will stop. To prevent keeping the program running forever if not all transfers
possibilities are used, a timeout is set on the connection with the relay. By default, this `timeout` is set to `30 seconds`, which is
likely not enough. If you want to keep the connection alive for more time you can use the `--timeout` flag like this:

```
croc send --timeout [nr-of-seconds] (--multiple [nr-of-transfers]) [file(s)-or-folder]
```

*NOTE*: You can't keep the connection alive for more than `1 hour`.

### Custom code phrase

You can send with your own code phrase (must be more than 6 characters).
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.1
github.com/magisterquis/connectproxy v0.0.0-20200725203833-3582e84f0c9b
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/kalafut/imohash v1.0.2 h1:j/cUPa15YvXv7abJlM+kdJIycbBMpmO7WqhPl4YB76I=
github.com/kalafut/imohash v1.0.2/go.mod h1:PjHBF0vpo1q7zMqiTn0qwSTQU2wDn5QIe8S8sFQuZS8=
Expand Down
25 changes: 24 additions & 1 deletion src/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Run() (err error) {
app.UsageText = `Send a file:
croc send file.txt

-git to respect your .gitignore
-git to respect your .gitignore
Send multiple files:
croc send file1.txt file2.txt file3.txt
or
Expand All @@ -66,6 +66,8 @@ func Run() (err error) {
ArgsUsage: "[filename(s) or folder]",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "zip", Usage: "zip folder before sending"},
&cli.IntFlag{Name: "timelimit", Value: 30, Usage: "timelimit in secods for sender to allow all transfers"},
&cli.IntFlag{Name: "multiple", Value: 1, Usage: "maximum number of transfers"},
&cli.StringFlag{Name: "code", Aliases: []string{"c"}, Usage: "codephrase used to connect to relay"},
&cli.StringFlag{Name: "hash", Value: "xxhash", Usage: "hash algorithm (xxhash, imohash, md5)"},
&cli.StringFlag{Name: "text", Aliases: []string{"t"}, Usage: "send some text"},
Expand Down Expand Up @@ -181,6 +183,8 @@ func send(c *cli.Context) (err error) {
crocOptions := croc.Options{
SharedSecret: c.String("code"),
IsSender: true,
TimeLimit: c.Int("timelimit"),
MaxTransfers: c.Int("multiple"),
Debug: c.Bool("debug"),
NoPrompt: c.Bool("yes"),
RelayAddress: c.String("relay"),
Expand All @@ -202,11 +206,30 @@ func send(c *cli.Context) (err error) {
ZipFolder: c.Bool("zip"),
GitIgnore: c.Bool("git"),
}

if crocOptions.TimeLimit <= 0 {
fmt.Println("timelimit must be greater than 0. Defaulting to 30 seconds.")
crocOptions.TimeLimit = 30
} else if crocOptions.TimeLimit > 3600 {
fmt.Println("timelimit must be less than 3600. Defaulting to 30 seconds.")
crocOptions.TimeLimit = 30
}

if crocOptions.MaxTransfers <= 0 {
fmt.Println("multiple must be greater than 0. Defaulting to 1 transfers.")
crocOptions.MaxTransfers = 1
} else if crocOptions.MaxTransfers > 1 {
fmt.Println("Allowing multiple transfers.")
fmt.Println("The connection will stay open until all transfers are complete, or the timelimit is reached.")
fmt.Printf("The current timelimit is %d seconds.\n", crocOptions.TimeLimit)
}

if crocOptions.RelayAddress != models.DEFAULT_RELAY {
crocOptions.RelayAddress6 = ""
} else if crocOptions.RelayAddress6 != models.DEFAULT_RELAY6 {
crocOptions.RelayAddress = ""
}

b, errOpen := os.ReadFile(getConfigFile())
if errOpen == nil && !c.Bool("remember") {
var rememberedOptions croc.Options
Expand Down
7 changes: 7 additions & 0 deletions src/comm/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/google/uuid"
"github.com/magisterquis/connectproxy"
"github.com/schollz/croc/v9/src/utils"
log "github.com/schollz/logger"
Expand All @@ -23,6 +24,7 @@ var MAGIC_BYTES = []byte("croc")

// Comm is some basic TCP communication
type Comm struct {
id string
connection net.Conn
}

Expand Down Expand Up @@ -100,6 +102,7 @@ func New(c net.Conn) *Comm {
log.Errorf("error setting write deadline: %v", err)
}
comm := new(Comm)
comm.id = uuid.New().String()
comm.connection = c
return comm
}
Expand All @@ -109,6 +112,10 @@ func (c *Comm) Connection() net.Conn {
return c.connection
}

func (c *Comm) ID() string {
return c.id
}

// Close closes the connection
func (c *Comm) Close() {
if err := c.connection.Close(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions src/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestComm(t *testing.T) {
time.Sleep(300 * time.Millisecond)
a, err := NewConnection("127.0.0.1:"+port, 10*time.Minute)
assert.Nil(t, err)
assert.NotNil(t, a.id)
data, err := a.Receive()
assert.Equal(t, []byte("hello, world"), data)
assert.Nil(t, err)
Expand Down
Loading
Loading