1
0
mirror of https://github.com/schollz/croc.git synced 2024-12-29 00:35:10 +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 IsSender bool
Debug bool Debug bool
DontEncrypt bool DontEncrypt bool
Wait bool
bars []*uiprogress.Bar bars []*uiprogress.Bar
rate int rate int
} }
@ -41,6 +42,7 @@ func NewConnection(flags *Flags) *Connection {
c := new(Connection) c := new(Connection)
c.Debug = flags.Debug c.Debug = flags.Debug
c.DontEncrypt = flags.DontEncrypt c.DontEncrypt = flags.DontEncrypt
c.Wait = flags.Wait
c.Server = flags.Server c.Server = flags.Server
c.Code = flags.Code c.Code = flags.Code
c.NumberOfConnections = flags.NumberOfConnections c.NumberOfConnections = flags.NumberOfConnections
@ -160,6 +162,7 @@ func (c *Connection) runClient() error {
} }
gotOK := false gotOK := false
gotResponse := false gotResponse := false
notPresent := false
for id := 0; id < c.NumberOfConnections; id++ { for id := 0; id < c.NumberOfConnections; id++ {
go func(id int) { go func(id int) {
defer wg.Done() defer wg.Done()
@ -182,7 +185,11 @@ func (c *Connection) runClient() error {
sendMessage("s."+c.HashedCode+"."+hex.EncodeToString(encryptedMetaData)+"-"+salt+"-"+iv, connection) sendMessage("s."+c.HashedCode+"."+hex.EncodeToString(encryptedMetaData)+"-"+salt+"-"+iv, connection)
} else { } else {
logger.Debugf("telling relay: %s", "r."+c.Code) logger.Debugf("telling relay: %s", "r."+c.Code)
if c.Wait {
sendMessage("r."+c.HashedCode+".0.0.0", connection) sendMessage("r."+c.HashedCode+".0.0.0", connection)
} else {
sendMessage("c."+c.HashedCode+".0.0.0", connection)
}
} }
if c.IsSender { // this is a sender if c.IsSender { // this is a sender
logger.Debug("waiting for ok from relay") logger.Debug("waiting for ok from relay")
@ -201,6 +208,10 @@ func (c *Connection) runClient() error {
message = receiveMessage(connection) message = receiveMessage(connection)
m := strings.Split(message, "-") m := strings.Split(message, "-")
encryptedData, salt, iv, sendersAddress := m[0], m[1], m[2], m[3] 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) encryptedBytes, err := hex.DecodeString(encryptedData)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -252,6 +263,10 @@ func (c *Connection) runClient() error {
wg.Wait() wg.Wait()
if !c.IsSender { if !c.IsSender {
if notPresent {
fmt.Println("Sender/Code not present")
return nil
}
if !gotOK { if !gotOK {
return errors.New("Transfer interrupted") return errors.New("Transfer interrupted")
} }

View File

@ -15,6 +15,7 @@ var oneGigabytePerSecond = 1000000 // expressed as kbps
type Flags struct { type Flags struct {
Relay bool Relay bool
Debug bool Debug bool
Wait bool
DontEncrypt bool DontEncrypt bool
Server string Server string
File string File string
@ -37,6 +38,7 @@ croc version ` + version + `
flags := new(Flags) flags := new(Flags)
flag.BoolVar(&flags.Relay, "relay", false, "run as relay") flag.BoolVar(&flags.Relay, "relay", false, "run as relay")
flag.BoolVar(&flags.Debug, "debug", false, "debug mode") 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.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")

View File

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