From 31ce8548353addd4be489aa171610144b7b87cd3 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 12 Oct 2019 15:37:40 -0500 Subject: [PATCH 1/2] update session when a search for an existing session finishes --- src/yggdrasil/search.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/yggdrasil/search.go b/src/yggdrasil/search.go index 322131e..6c43cfe 100644 --- a/src/yggdrasil/search.go +++ b/src/yggdrasil/search.go @@ -205,6 +205,8 @@ func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool { panic("This should never happen") } } else { + sess.coords = res.Coords // In case coords have updated + sess.ping(sinfo.searches.router) // In case the remote side needs updating sinfo.callback(nil, errors.New("session already exists")) // Cleanup delete(sinfo.searches.searches, res.Dest) From 3491292599fcd523060cebfb84e04a15d940904b Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 12 Oct 2019 15:46:56 -0500 Subject: [PATCH 2/2] code cleanup --- src/yggdrasil/search.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/yggdrasil/search.go b/src/yggdrasil/search.go index 6c43cfe..caa8df7 100644 --- a/src/yggdrasil/search.go +++ b/src/yggdrasil/search.go @@ -189,34 +189,34 @@ func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool { if themMasked != destMasked { return false } + finishSearch := func(sess *sessionInfo, err error) { + if sess != nil { + // FIXME (!) replay attacks could mess with coords? Give it a handle (tstamp)? + sess.coords = res.Coords + sess.ping(sinfo.searches.router) + } + if err != nil { + sinfo.callback(nil, err) + } else { + sinfo.callback(sess, nil) + } + // Cleanup + delete(sinfo.searches.searches, res.Dest) + } // They match, so create a session and send a sessionRequest + var err error sess, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key) if !isIn { + // Don't already have a session sess = sinfo.searches.router.sessions.createSession(&res.Key) if sess == nil { - // nil if the DHT search finished but the session wasn't allowed - sinfo.callback(nil, errors.New("session not allowed")) - // Cleanup - delete(sinfo.searches.searches, res.Dest) - return true - } - _, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key) - if !isIn { + err = errors.New("session not allowed") + } else if _, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key); !isIn { panic("This should never happen") } } else { - sess.coords = res.Coords // In case coords have updated - sess.ping(sinfo.searches.router) // In case the remote side needs updating - sinfo.callback(nil, errors.New("session already exists")) - // Cleanup - delete(sinfo.searches.searches, res.Dest) - return true + err = errors.New("session already exists") } - // FIXME (!) replay attacks could mess with coords? Give it a handle (tstamp)? - sess.coords = res.Coords - sess.ping(sinfo.searches.router) - sinfo.callback(sess, nil) - // Cleanup - delete(sinfo.searches.searches, res.Dest) + finishSearch(sess, err) return true }