From c59372136212a785e9c2415845bde076a83c5a3b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 19 Apr 2019 00:33:54 +0100 Subject: [PATCH] Tweaks --- src/yggdrasil/conn.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/yggdrasil/conn.go b/src/yggdrasil/conn.go index 0ce626c..bcf38ed 100644 --- a/src/yggdrasil/conn.go +++ b/src/yggdrasil/conn.go @@ -27,10 +27,11 @@ func (c *Conn) startSearch() { } if sinfo != nil { c.session = sinfo - c.core.log.Println("Search from API found", hex.EncodeToString(sinfo.theirPermPub[:])) + c.core.log.Println("Search from API succeeded") + c.core.log.Println("Pubkey:", hex.EncodeToString(sinfo.theirPermPub[:])) + c.core.log.Println("Coords:", sinfo.coords) } } - // Try and search for the node on the network doSearch := func() { sinfo, isIn := c.core.searches.searches[*c.nodeID] if !isIn { @@ -43,25 +44,16 @@ func (c *Conn) startSearch() { var isIn bool switch { case !isIn || !sinfo.init: - // No or unintiialized session, so we need to search first doSearch() case time.Since(sinfo.time) > 6*time.Second: if sinfo.time.Before(sinfo.pingTime) && time.Since(sinfo.pingTime) > 6*time.Second { - // We haven't heard from the dest in a while - // We tried pinging but didn't get a response - // They may have changed coords - // Try searching to discover new coords - // Note that search spam is throttled internally doSearch() } else { - // We haven't heard about the dest in a while now := time.Now() if !sinfo.time.Before(sinfo.pingTime) { - // Update pingTime to start the clock for searches (above) sinfo.pingTime = now } if time.Since(sinfo.pingSend) > time.Second { - // Send at most 1 ping per second sinfo.pingSend = now c.core.sessions.sendPingPong(sinfo, false) } @@ -73,6 +65,10 @@ func (c *Conn) Read(b []byte) (int, error) { if c.session == nil { return 0, errors.New("session not open") } + if !c.session.init { + // To prevent blocking forever on a session that isn't initialised + return 0, errors.New("session not initialised") + } p := <-c.session.recv defer util.PutBytes(p.Payload) if !c.session.nonceIsOK(&p.Nonce) {