Skip to content

Commit

Permalink
add option to disable compression Fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Sep 3, 2020
1 parent 555ddec commit 87e54ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Run() (err error) {
cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"},
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay"},
Expand Down Expand Up @@ -162,6 +163,7 @@ func send(c *cli.Context) (err error) {
NoMultiplexing: c.Bool("no-multi"),
RelayPassword: determinePass(c),
SendingText: c.String("text") != "",
NoCompress: c.GlobalBool("no-compress"),
}
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
crocOptions.RelayAddress6 = ""
Expand Down
32 changes: 25 additions & 7 deletions src/croc/croc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Options struct {
DisableLocal bool
Ask bool
SendingText bool
NoCompress bool
}

// Client holds the state of the croc transfer
Expand Down Expand Up @@ -140,6 +141,7 @@ type SenderInfo struct {
MachineID string
Ask bool
SendingText bool
NoCompress bool
}

// New establishes a new connection for transferring files between two instances.
Expand Down Expand Up @@ -700,6 +702,10 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
return
}
c.Options.SendingText = senderInfo.SendingText
c.Options.NoCompress = senderInfo.NoCompress
if c.Options.NoCompress {
log.Debug("disabling compression")
}
if c.Options.SendingText {
c.Options.Stdout = true
}
Expand Down Expand Up @@ -960,6 +966,7 @@ func (c *Client) updateIfSenderChannelSecured() (err error) {
MachineID: machID,
Ask: c.Options.Ask,
SendingText: c.Options.SendingText,
NoCompress: c.Options.NoCompress,
})
if err != nil {
log.Error(err)
Expand Down Expand Up @@ -1281,7 +1288,9 @@ func (c *Client) receiveData(i int) {
if err != nil {
panic(err)
}
data = compress.Decompress(data)
if !c.Options.NoCompress {
data = compress.Decompress(data)
}

// get position
var position uint64
Expand Down Expand Up @@ -1366,13 +1375,22 @@ func (c *Client) sendData(i int) {
// log.Debugf("sending chunk %d", pos)
posByte := make([]byte, 8)
binary.LittleEndian.PutUint64(posByte, pos)

dataToSend, err := crypt.Encrypt(
compress.Compress(
var err error
var dataToSend []byte
if c.Options.NoCompress {
dataToSend, err = crypt.Encrypt(
append(posByte, data[:n]...),
),
c.Key,
)
c.Key,
)
} else {

dataToSend, err = crypt.Encrypt(
compress.Compress(
append(posByte, data[:n]...),
),
c.Key,
)
}
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 87e54ac

Please sign in to comment.