mirror of https://github.com/schollz/croc.git
connect to tcp in parallel
This commit is contained in:
parent
edc206e73e
commit
08c84e9f85
|
@ -8,6 +8,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -22,6 +23,7 @@ var Version string
|
|||
var cr *croc.Croc
|
||||
|
||||
func Run() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
app := cli.NewApp()
|
||||
app.Name = "croc"
|
||||
if Version == "" {
|
||||
|
|
|
@ -172,17 +172,23 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
|||
if !useWebsockets {
|
||||
log.Debugf("connecting to server")
|
||||
tcpConnections = make([]comm.Comm, len(tcpPorts))
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(tcpPorts))
|
||||
for i, tcpPort := range tcpPorts {
|
||||
log.Debugf("connecting to %d", i)
|
||||
var message string
|
||||
tcpConnections[i], message, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%d%x", i, sessionKey)), serverAddress+":"+tcpPort)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if message != "recipient" {
|
||||
log.Errorf("got wrong message: %s", message)
|
||||
}
|
||||
go func(i int, tcpPort string) {
|
||||
defer wg.Done()
|
||||
log.Debugf("connecting to %d", i)
|
||||
var message string
|
||||
tcpConnections[i], message, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%d%x", i, sessionKey)), serverAddress+":"+tcpPort)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if message != "recipient" {
|
||||
log.Errorf("got wrong message: %s", message)
|
||||
}
|
||||
}(i, tcpPort)
|
||||
}
|
||||
wg.Wait()
|
||||
log.Debugf("fully connected")
|
||||
}
|
||||
isConnectedIfUsingTCP <- true
|
||||
|
|
|
@ -284,17 +284,23 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
|
|||
go func() {
|
||||
if !useWebsockets {
|
||||
log.Debugf("connecting to server")
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(tcpPorts))
|
||||
for i, tcpPort := range tcpPorts {
|
||||
log.Debugf("connecting to %s on connection %d", tcpPort, i)
|
||||
var message string
|
||||
tcpConnections[i], message, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%d%x", i, sessionKey)), serverAddress+":"+tcpPort)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if message != "sender" {
|
||||
log.Errorf("got wrong message: %s", message)
|
||||
}
|
||||
go func(i int, tcpPort string) {
|
||||
defer wg.Done()
|
||||
log.Debugf("connecting to %s on connection %d", tcpPort, i)
|
||||
var message string
|
||||
tcpConnections[i], message, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%d%x", i, sessionKey)), serverAddress+":"+tcpPort)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if message != "sender" {
|
||||
log.Errorf("got wrong message: %s", message)
|
||||
}
|
||||
}(i, tcpPort)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
isConnectedIfUsingTCP <- true
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue