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