1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 08:02:33 +03:00

use correct local ip if sending locally

This commit is contained in:
Zack Scholl 2018-07-01 18:34:55 -07:00
parent a6bc4973aa
commit 22220e54a7
3 changed files with 12 additions and 1 deletions

View File

@ -96,6 +96,7 @@ func (c *Croc) Send(fname string, codePhrase string) (err error) {
ce.cs.channel.fileMetaData = c.cs.channel.fileMetaData ce.cs.channel.fileMetaData = c.cs.channel.fileMetaData
ce.crocFile = c.crocFile ce.crocFile = c.crocFile
ce.crocFileEncrypted = ce.crocFileEncrypted ce.crocFileEncrypted = ce.crocFileEncrypted
ce.isLocal = true
ce.cs.Unlock() ce.cs.Unlock()
c.cs.Unlock() c.cs.Unlock()
var ri runInfo var ri runInfo
@ -144,6 +145,7 @@ func (c *Croc) Receive(codePhrase string) (err error) {
if connectTimeout == nil { if connectTimeout == nil {
log.Debug("connected") log.Debug("connected")
c.WebsocketAddress = "ws://" + discovered[0].Address + ":8140" c.WebsocketAddress = "ws://" + discovered[0].Address + ":8140"
c.isLocal = true
log.Debug(discovered[0].Address) log.Debug(discovered[0].Address)
codePhrase = string(discovered[0].Payload) codePhrase = string(discovered[0].Payload)
} else { } else {

View File

@ -223,6 +223,9 @@ func (c *Croc) processState(cd channelData) (err error) {
c.cs.channel.Ports = cd.Ports c.cs.channel.Ports = cd.Ports
c.cs.channel.EncryptedFileMetaData = cd.EncryptedFileMetaData c.cs.channel.EncryptedFileMetaData = cd.EncryptedFileMetaData
c.cs.channel.Addresses = cd.Addresses c.cs.channel.Addresses = cd.Addresses
if c.cs.channel.Role == 0 && c.isLocal {
c.cs.channel.Addresses[0] = getLocalIP()
}
c.bothConnected = cd.Addresses[0] != "" && cd.Addresses[1] != "" c.bothConnected = cd.Addresses[0] != "" && cd.Addresses[1] != ""
// update the Pake // update the Pake

View File

@ -39,6 +39,12 @@ type Croc struct {
Stdout bool Stdout bool
// private variables // private variables
// localIP address
localIP string
// is using local relay
isLocal bool
// rs relay state is only for the relay // rs relay state is only for the relay
rs relayState rs relayState
@ -70,7 +76,7 @@ func Init() (c *Croc) {
c.rs.ips = make(map[string]string) c.rs.ips = make(map[string]string)
c.cs.channel = new(channelData) c.cs.channel = new(channelData)
c.rs.Unlock() c.rs.Unlock()
c.localIP = getLocalIP()
return return
} }