mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
send local/public status
This commit is contained in:
parent
f3df177ba2
commit
0a0c0bfd32
3 changed files with 13 additions and 13 deletions
|
@ -28,7 +28,7 @@ func (c *Croc) Send(fname, codephrase string) (err error) {
|
|||
if !c.LocalOnly {
|
||||
go func() {
|
||||
// atttempt to connect to public relay
|
||||
errChan <- c.sendReceive(c.WebsocketAddress, fname, codephrase, true)
|
||||
errChan <- c.sendReceive(c.WebsocketAddress, fname, codephrase, true, false)
|
||||
}()
|
||||
} else {
|
||||
waitingFor = 1
|
||||
|
@ -53,7 +53,7 @@ func (c *Croc) Send(fname, codephrase string) (err error) {
|
|||
}()
|
||||
|
||||
// connect to own relay
|
||||
errChan <- c.sendReceive("ws://localhost:"+c.ServerPort, fname, codephrase, true)
|
||||
errChan <- c.sendReceive("ws://localhost:"+c.ServerPort, fname, codephrase, true, true)
|
||||
}()
|
||||
} else {
|
||||
waitingFor = 1
|
||||
|
@ -95,7 +95,7 @@ func (c *Croc) Receive(codephrase string) (err error) {
|
|||
if err == nil {
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
// we connected, so use this
|
||||
return c.sendReceive(fmt.Sprintf("ws://%s:%s", discovered[0].Address, discovered[0].Payload), "", codephrase, false)
|
||||
return c.sendReceive(fmt.Sprintf("ws://%s:%s", discovered[0].Address, discovered[0].Payload), "", codephrase, false, true)
|
||||
}
|
||||
} else {
|
||||
log.Debugf("could not connect: %s", err.Error())
|
||||
|
@ -108,13 +108,13 @@ func (c *Croc) Receive(codephrase string) (err error) {
|
|||
// use public relay
|
||||
if !c.LocalOnly {
|
||||
log.Debug("using public relay")
|
||||
return c.sendReceive(c.WebsocketAddress, "", codephrase, false)
|
||||
return c.sendReceive(c.WebsocketAddress, "", codephrase, false, false)
|
||||
}
|
||||
|
||||
return errors.New("must use local or public relay")
|
||||
}
|
||||
|
||||
func (c *Croc) sendReceive(websocketAddress, fname, codephrase string, isSender bool) (err error) {
|
||||
func (c *Croc) sendReceive(websocketAddress, fname, codephrase string, isSender bool, isLocal bool) (err error) {
|
||||
defer log.Flush()
|
||||
if len(codephrase) < 4 {
|
||||
return fmt.Errorf("codephrase is too short")
|
||||
|
@ -141,9 +141,9 @@ func (c *Croc) sendReceive(websocketAddress, fname, codephrase string, isSender
|
|||
|
||||
if isSender {
|
||||
// start peerdiscovery relay server
|
||||
go sender.Send(done, sock, fname, codephrase, c.UseCompression, c.UseEncryption)
|
||||
go sender.Send(isLocal, done, sock, fname, codephrase, c.UseCompression, c.UseEncryption)
|
||||
} else {
|
||||
go recipient.Receive(done, sock, codephrase, c.NoRecipientPrompt, c.Stdout)
|
||||
go recipient.Receive(isLocal, done, sock, codephrase, c.NoRecipientPrompt, c.Stdout)
|
||||
}
|
||||
|
||||
for {
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
var DebugLevel string
|
||||
|
||||
// Receive is the async operation to receive a file
|
||||
func Receive(done chan struct{}, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) {
|
||||
func Receive(isLocal bool, done chan struct{}, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) {
|
||||
logger.SetLogLevel(DebugLevel)
|
||||
err := receive(c, codephrase, noPrompt, useStdout)
|
||||
err := receive(isLocal, c, codephrase, noPrompt, useStdout)
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||
return
|
||||
|
@ -41,7 +41,7 @@ func Receive(done chan struct{}, c *websocket.Conn, codephrase string, noPrompt
|
|||
done <- struct{}{}
|
||||
}
|
||||
|
||||
func receive(c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) (err error) {
|
||||
func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool, useStdout bool) (err error) {
|
||||
var fstats models.FileStats
|
||||
var sessionKey []byte
|
||||
var transferTime time.Duration
|
||||
|
|
|
@ -28,10 +28,10 @@ import (
|
|||
var DebugLevel string
|
||||
|
||||
// Send is the async call to send data
|
||||
func Send(done chan struct{}, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) {
|
||||
func Send(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(c, fname, codephrase, useCompression, useEncryption)
|
||||
err := send(isLocal, c, fname, codephrase, useCompression, useEncryption)
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||
err = nil
|
||||
|
@ -40,7 +40,7 @@ func Send(done chan struct{}, c *websocket.Conn, fname string, codephrase string
|
|||
done <- struct{}{}
|
||||
}
|
||||
|
||||
func send(c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) (err error) {
|
||||
func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useCompression bool, useEncryption bool) (err error) {
|
||||
var f *os.File
|
||||
var fstats models.FileStats
|
||||
var fileHash []byte
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue