mirror of
https://github.com/schollz/croc.git
synced 2024-12-27 15:55:41 +03:00
adding wait funtionality: if waiting, will send a different identification to the server
This commit is contained in:
parent
7ad54dced3
commit
eb3af56ccf
17
connect.go
17
connect.go
@ -27,6 +27,7 @@ type Connection struct {
|
||||
IsSender bool
|
||||
Debug bool
|
||||
DontEncrypt bool
|
||||
Wait bool
|
||||
bars []*uiprogress.Bar
|
||||
rate int
|
||||
}
|
||||
@ -41,6 +42,7 @@ func NewConnection(flags *Flags) *Connection {
|
||||
c := new(Connection)
|
||||
c.Debug = flags.Debug
|
||||
c.DontEncrypt = flags.DontEncrypt
|
||||
c.Wait = flags.Wait
|
||||
c.Server = flags.Server
|
||||
c.Code = flags.Code
|
||||
c.NumberOfConnections = flags.NumberOfConnections
|
||||
@ -160,6 +162,7 @@ func (c *Connection) runClient() error {
|
||||
}
|
||||
gotOK := false
|
||||
gotResponse := false
|
||||
notPresent := false
|
||||
for id := 0; id < c.NumberOfConnections; id++ {
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
@ -182,7 +185,11 @@ func (c *Connection) runClient() error {
|
||||
sendMessage("s."+c.HashedCode+"."+hex.EncodeToString(encryptedMetaData)+"-"+salt+"-"+iv, connection)
|
||||
} else {
|
||||
logger.Debugf("telling relay: %s", "r."+c.Code)
|
||||
sendMessage("r."+c.HashedCode+".0.0.0", connection)
|
||||
if c.Wait {
|
||||
sendMessage("r."+c.HashedCode+".0.0.0", connection)
|
||||
} else {
|
||||
sendMessage("c."+c.HashedCode+".0.0.0", connection)
|
||||
}
|
||||
}
|
||||
if c.IsSender { // this is a sender
|
||||
logger.Debug("waiting for ok from relay")
|
||||
@ -201,6 +208,10 @@ func (c *Connection) runClient() error {
|
||||
message = receiveMessage(connection)
|
||||
m := strings.Split(message, "-")
|
||||
encryptedData, salt, iv, sendersAddress := m[0], m[1], m[2], m[3]
|
||||
if sendersAddress == "0.0.0.0" {
|
||||
notPresent = true
|
||||
return
|
||||
}
|
||||
encryptedBytes, err := hex.DecodeString(encryptedData)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@ -252,6 +263,10 @@ func (c *Connection) runClient() error {
|
||||
wg.Wait()
|
||||
|
||||
if !c.IsSender {
|
||||
if notPresent {
|
||||
fmt.Println("Sender/Code not present")
|
||||
return nil
|
||||
}
|
||||
if !gotOK {
|
||||
return errors.New("Transfer interrupted")
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -15,6 +15,7 @@ var oneGigabytePerSecond = 1000000 // expressed as kbps
|
||||
type Flags struct {
|
||||
Relay bool
|
||||
Debug bool
|
||||
Wait bool
|
||||
DontEncrypt bool
|
||||
Server string
|
||||
File string
|
||||
@ -37,6 +38,7 @@ croc version ` + version + `
|
||||
flags := new(Flags)
|
||||
flag.BoolVar(&flags.Relay, "relay", false, "run as relay")
|
||||
flag.BoolVar(&flags.Debug, "debug", false, "debug mode")
|
||||
flag.BoolVar(&flags.Wait, "wait", false, "wait for code to be sent")
|
||||
flag.StringVar(&flags.Server, "server", "cowyo.com", "address of relay server")
|
||||
flag.StringVar(&flags.File, "send", "", "file to send")
|
||||
flag.StringVar(&flags.Code, "code", "", "use your own code phrase")
|
||||
|
Loading…
Reference in New Issue
Block a user