mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
communicate tcp port to sender/receiver
This commit is contained in:
parent
384de31c5a
commit
2788a4e742
3 changed files with 10 additions and 11 deletions
|
@ -148,10 +148,9 @@ func (c *Croc) sendReceive(address, websocketPort, tcpPort, fname, codephrase st
|
|||
}
|
||||
|
||||
if isSender {
|
||||
// start peerdiscovery relay server
|
||||
go sender.Send(isLocal, done, sock, fname, codephrase, c.UseCompression, c.UseEncryption)
|
||||
go sender.Send(address, tcpPort, isLocal, done, sock, fname, codephrase, c.UseCompression, c.UseEncryption)
|
||||
} else {
|
||||
go recipient.Receive(isLocal, done, sock, codephrase, c.NoRecipientPrompt, c.Stdout)
|
||||
go recipient.Receive(address, tcpPort, isLocal, done, sock, codephrase, c.NoRecipientPrompt, c.Stdout)
|
||||
}
|
||||
|
||||
for {
|
||||
|
|
|
@ -31,9 +31,9 @@ import (
|
|||
var DebugLevel string
|
||||
|
||||
// Receive is the async operation to receive a file
|
||||
func Receive(isLocal bool, done chan struct{}, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) {
|
||||
func Receive(serverAddress, serverTCP string, isLocal bool, done chan struct{}, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) {
|
||||
logger.SetLogLevel(DebugLevel)
|
||||
err := receive(isLocal, c, codephrase, noPrompt, useStdout)
|
||||
err := receive(serverAddress, serverTCP, isLocal, c, codephrase, noPrompt, useStdout)
|
||||
if err != nil {
|
||||
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||
|
@ -42,7 +42,7 @@ func Receive(isLocal bool, done chan struct{}, c *websocket.Conn, codephrase str
|
|||
done <- struct{}{}
|
||||
}
|
||||
|
||||
func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) (err error) {
|
||||
func receive(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) (err error) {
|
||||
var fstats models.FileStats
|
||||
var sessionKey []byte
|
||||
var transferTime time.Duration
|
||||
|
@ -161,7 +161,7 @@ func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool,
|
|||
|
||||
// connect to TCP to receive file
|
||||
if !isLocal {
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), "localhost:8154")
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), serverAddress+":"+serverTCP)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
|
|
|
@ -30,10 +30,10 @@ import (
|
|||
var DebugLevel string
|
||||
|
||||
// Send is the async call to send data
|
||||
func Send(isLocal bool, done chan struct{}, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) {
|
||||
func Send(serverAddress, serverTCP string, isLocal bool, done chan struct{}, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) {
|
||||
logger.SetLogLevel(DebugLevel)
|
||||
log.Debugf("sending %s", fname)
|
||||
err := send(isLocal, c, fname, codephrase, useCompression, useEncryption)
|
||||
err := send(serverAddress, serverTCP, isLocal, c, fname, codephrase, useCompression, useEncryption)
|
||||
if err != nil {
|
||||
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||
|
@ -43,7 +43,7 @@ func Send(isLocal bool, done chan struct{}, c *websocket.Conn, fname string, cod
|
|||
done <- struct{}{}
|
||||
}
|
||||
|
||||
func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) (err error) {
|
||||
func send(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) (err error) {
|
||||
var f *os.File
|
||||
defer f.Close() // ignore the error if it wasn't opened :(
|
||||
var fstats models.FileStats
|
||||
|
@ -197,7 +197,7 @@ func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useC
|
|||
|
||||
if !isLocal {
|
||||
// connection to TCP
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), "localhost:8154")
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), serverAddress+":"+serverTCP)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue