mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
parent
a6927a3143
commit
f1102c0062
2 changed files with 13 additions and 1 deletions
10
connect.go
10
connect.go
|
@ -28,6 +28,7 @@ type Connection struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
DontEncrypt bool
|
DontEncrypt bool
|
||||||
bars []*uiprogress.Bar
|
bars []*uiprogress.Bar
|
||||||
|
rate int
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileMetaData struct {
|
type FileMetaData struct {
|
||||||
|
@ -46,6 +47,7 @@ func NewConnection(flags *Flags) *Connection {
|
||||||
c.Server = flags.Server
|
c.Server = flags.Server
|
||||||
c.Code = flags.Code
|
c.Code = flags.Code
|
||||||
c.NumberOfConnections = flags.NumberOfConnections
|
c.NumberOfConnections = flags.NumberOfConnections
|
||||||
|
c.rate = flags.Rate
|
||||||
if len(flags.File) > 0 {
|
if len(flags.File) > 0 {
|
||||||
c.File.Name = flags.File
|
c.File.Name = flags.File
|
||||||
c.IsSender = true
|
c.IsSender = true
|
||||||
|
@ -382,7 +384,13 @@ func (c *Connection) sendFile(id int, connection net.Conn) {
|
||||||
if !c.Debug {
|
if !c.Debug {
|
||||||
c.bars[id] = uiprogress.AddBar(chunksPerWorker).AppendCompleted().PrependElapsed()
|
c.bars[id] = uiprogress.AddBar(chunksPerWorker).AppendCompleted().PrependElapsed()
|
||||||
}
|
}
|
||||||
for {
|
|
||||||
|
bufferSizeInKilobytes := BUFFERSIZE / 1024
|
||||||
|
rate := float64(c.rate) / float64(c.NumberOfConnections*bufferSizeInKilobytes)
|
||||||
|
throttle := time.NewTicker(time.Second / time.Duration(rate))
|
||||||
|
defer throttle.Stop()
|
||||||
|
|
||||||
|
for range throttle.C {
|
||||||
_, err = file.Read(sendBuffer)
|
_, err = file.Read(sendBuffer)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
//End of file reached, break out of for loop
|
//End of file reached, break out of for loop
|
||||||
|
|
4
main.go
4
main.go
|
@ -10,6 +10,8 @@ import (
|
||||||
|
|
||||||
const BUFFERSIZE = 1024
|
const BUFFERSIZE = 1024
|
||||||
|
|
||||||
|
var oneGigabytePerSecond = 1000000 // expressed as kbps
|
||||||
|
|
||||||
type Flags struct {
|
type Flags struct {
|
||||||
Relay bool
|
Relay bool
|
||||||
Debug bool
|
Debug bool
|
||||||
|
@ -17,6 +19,7 @@ type Flags struct {
|
||||||
Server string
|
Server string
|
||||||
File string
|
File string
|
||||||
Code string
|
Code string
|
||||||
|
Rate int
|
||||||
NumberOfConnections int
|
NumberOfConnections int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +40,7 @@ croc version `+version+`
|
||||||
flag.StringVar(&flags.Server, "server", "cowyo.com", "address of relay server")
|
flag.StringVar(&flags.Server, "server", "cowyo.com", "address of relay server")
|
||||||
flag.StringVar(&flags.File, "send", "", "file to send")
|
flag.StringVar(&flags.File, "send", "", "file to send")
|
||||||
flag.StringVar(&flags.Code, "code", "", "use your own code phrase")
|
flag.StringVar(&flags.Code, "code", "", "use your own code phrase")
|
||||||
|
flag.IntVar(&flags.Rate, "rate", oneGigabytePerSecond, "throttle down to speed in kbps")
|
||||||
flag.BoolVar(&flags.DontEncrypt, "no-encrypt", false, "turn off encryption")
|
flag.BoolVar(&flags.DontEncrypt, "no-encrypt", false, "turn off encryption")
|
||||||
flag.IntVar(&flags.NumberOfConnections, "threads", 4, "number of threads to use")
|
flag.IntVar(&flags.NumberOfConnections, "threads", 4, "number of threads to use")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue