update relay address if a peer is found

This commit is contained in:
Zack Scholl 2019-05-01 10:38:31 -06:00
parent 883dff96b8
commit f3e2a260d9
1 changed files with 5 additions and 2 deletions

View File

@ -312,7 +312,8 @@ func (c *Client) Send(options TransferOptions) (err error) {
// Receive will receive a file
func (c *Client) Receive() (err error) {
// look for peers first
// recipient will look for peers first
// and continue if it doesn't find any within 100 ms
if !c.Options.DisableLocal {
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
Limit: 1,
@ -320,7 +321,9 @@ func (c *Client) Receive() (err error) {
Delay: 10 * time.Millisecond,
TimeLimit: 100 * time.Millisecond,
})
_ = err
if err == nil && len(discoveries) > 0 {
c.Options.RelayAddress = fmt.Sprintf("%s:%s", discoveries[0].Address, discoveries[0].Payload)
}
log.Debugf("discoveries: %+v", discoveries)
log.Debug("establishing connection")
}