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