mirror of
https://github.com/schollz/croc.git
synced 2024-12-26 15:24:38 +03:00
Break from for loop if time exceeds an hour
This commit is contained in:
parent
550bd9a8e6
commit
416e0f110a
15
connect.go
15
connect.go
@ -166,6 +166,7 @@ func (c *Connection) runClient() error {
|
||||
if !c.Debug {
|
||||
c.bars = make([]*uiprogress.Bar, c.NumberOfConnections)
|
||||
}
|
||||
gotTimeout := false
|
||||
gotOK := false
|
||||
gotResponse := false
|
||||
gotConnectionInUse := false
|
||||
@ -201,8 +202,13 @@ func (c *Connection) runClient() error {
|
||||
if c.IsSender { // this is a sender
|
||||
logger.Debug("waiting for ok from relay")
|
||||
message = receiveMessage(connection)
|
||||
if message == "timeout" {
|
||||
gotTimeout = true
|
||||
fmt.Println("You've just exceeded limit waiting time.")
|
||||
return
|
||||
}
|
||||
if message == "no" {
|
||||
if id == 0 {
|
||||
if id == 0 {
|
||||
fmt.Println("The specifed code is already in use by a sender.")
|
||||
}
|
||||
gotConnectionInUse = true
|
||||
@ -223,7 +229,7 @@ func (c *Connection) runClient() error {
|
||||
logger.Debug("waiting for meta data from sender")
|
||||
message = receiveMessage(connection)
|
||||
if message == "no" {
|
||||
if id == 0 {
|
||||
if id == 0 {
|
||||
fmt.Println("The specifed code is already in use by a sender.")
|
||||
}
|
||||
gotConnectionInUse = true
|
||||
@ -291,7 +297,10 @@ func (c *Connection) runClient() error {
|
||||
}
|
||||
|
||||
if c.IsSender {
|
||||
// TODO: Add confirmation
|
||||
if gotTimeout {
|
||||
fmt.Println("Timeout waiting for receiver")
|
||||
return nil
|
||||
}
|
||||
fmt.Println("\nFile sent.")
|
||||
} else { // Is a Receiver
|
||||
if notPresent {
|
||||
|
7
relay.go
7
relay.go
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const MAX_NUMBER_THREADS = 8
|
||||
const CONNECTION_TIMEOUT = time.Hour
|
||||
|
||||
type connectionMap struct {
|
||||
receiver map[string]net.Conn
|
||||
@ -135,7 +136,12 @@ func (r *Relay) clientCommuncation(id int, connection net.Conn) {
|
||||
r.connections.Unlock()
|
||||
// wait for receiver
|
||||
receiversAddress := ""
|
||||
isTimeout := time.Duration(0)
|
||||
for {
|
||||
if CONNECTION_TIMEOUT <= isTimeout {
|
||||
sendMessage("timeout", connection)
|
||||
break
|
||||
}
|
||||
r.connections.RLock()
|
||||
if _, ok := r.connections.receiver[key]; ok {
|
||||
receiversAddress = r.connections.receiver[key].RemoteAddr().String()
|
||||
@ -145,6 +151,7 @@ func (r *Relay) clientCommuncation(id int, connection net.Conn) {
|
||||
}
|
||||
r.connections.RUnlock()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
isTimeout += 100 * time.Millisecond
|
||||
}
|
||||
logger.Debug("telling sender ok")
|
||||
sendMessage(receiversAddress, connection)
|
||||
|
Loading…
Reference in New Issue
Block a user