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

View File

@ -223,6 +223,9 @@ func (c *Croc) processState(cd channelData) (err error) {
c.cs.channel.Ports = cd.Ports
c.cs.channel.EncryptedFileMetaData = cd.EncryptedFileMetaData
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] != ""
// update the Pake

View File

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