1
0
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:
Bradley T Lunsford 2017-10-20 14:51:30 -07:00
parent 7ad54dced3
commit eb3af56ccf
3 changed files with 22 additions and 1 deletions

View File

@ -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")
}

View File

@ -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")

View File

@ -156,6 +156,10 @@ func (r *Relay) clientCommuncation(id int, connection net.Conn) {
}
}
r.connections.RUnlock()
if connectionType == "c" {
sendMessage("0-0-0-0.0.0.0", connection)
return
}
time.Sleep(100 * time.Millisecond)
}
// send meta data