mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
make tcp optional
This commit is contained in:
parent
b7c447473d
commit
975bab61fb
3 changed files with 6 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
|
||||
const WEBSOCKET_BUFFER_SIZE = 1024 * 1024 * 32
|
||||
const TCP_BUFFER_SIZE = 1024 * 1
|
||||
const TCP_BUFFER_SIZE = 1024 * 2
|
||||
|
|
|
@ -160,7 +160,7 @@ func receive(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, c
|
|||
}
|
||||
|
||||
// connect to TCP to receive file
|
||||
if !isLocal {
|
||||
if !isLocal && serverTCP != "" {
|
||||
log.Debugf("connecting to server")
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), serverAddress+":"+serverTCP)
|
||||
if err != nil {
|
||||
|
@ -188,7 +188,7 @@ func receive(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, c
|
|||
var numBytes int
|
||||
var bs []byte
|
||||
for {
|
||||
if isLocal {
|
||||
if isLocal || serverTCP == "" {
|
||||
var messageType int
|
||||
// read from websockets
|
||||
messageType, message, err = c.ReadMessage()
|
||||
|
|
|
@ -195,7 +195,7 @@ func send(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, fnam
|
|||
return errors.New("recipient refused file")
|
||||
}
|
||||
|
||||
if !isLocal {
|
||||
if !isLocal && serverTCP != "" {
|
||||
// connection to TCP
|
||||
tcpConnection, err = connectToTCPServer(utils.SHA256(fmt.Sprintf("%x", sessionKey)), serverAddress+":"+serverTCP)
|
||||
if err != nil {
|
||||
|
@ -208,7 +208,7 @@ func send(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, fnam
|
|||
// send file, compure hash simultaneously
|
||||
startTransfer = time.Now()
|
||||
buffer := make([]byte, models.WEBSOCKET_BUFFER_SIZE/8)
|
||||
if !isLocal {
|
||||
if !isLocal && serverTCP != "" {
|
||||
buffer = make([]byte, models.TCP_BUFFER_SIZE/2)
|
||||
}
|
||||
bar := progressbar.NewOptions(
|
||||
|
@ -236,7 +236,7 @@ func send(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, fnam
|
|||
return err
|
||||
}
|
||||
|
||||
if isLocal {
|
||||
if isLocal || serverTCP == "" {
|
||||
// write data to websockets
|
||||
err = c.WriteMessage(websocket.BinaryMessage, encBytes)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue