mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	code cleanup
This commit is contained in:
		
							parent
							
								
									31ce854835
								
							
						
					
					
						commit
						3491292599
					
				
					 1 changed files with 20 additions and 20 deletions
				
			
		| 
						 | 
					@ -189,34 +189,34 @@ func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool {
 | 
				
			||||||
	if themMasked != destMasked {
 | 
						if themMasked != destMasked {
 | 
				
			||||||
		return false
 | 
							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
 | 
						// They match, so create a session and send a sessionRequest
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
	sess, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key)
 | 
						sess, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key)
 | 
				
			||||||
	if !isIn {
 | 
						if !isIn {
 | 
				
			||||||
 | 
							// Don't already have a session
 | 
				
			||||||
		sess = sinfo.searches.router.sessions.createSession(&res.Key)
 | 
							sess = sinfo.searches.router.sessions.createSession(&res.Key)
 | 
				
			||||||
		if sess == nil {
 | 
							if sess == nil {
 | 
				
			||||||
			// nil if the DHT search finished but the session wasn't allowed
 | 
								err = errors.New("session not allowed")
 | 
				
			||||||
			sinfo.callback(nil, errors.New("session not allowed"))
 | 
							} else if _, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key); !isIn {
 | 
				
			||||||
			// Cleanup
 | 
					 | 
				
			||||||
			delete(sinfo.searches.searches, res.Dest)
 | 
					 | 
				
			||||||
			return true
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		_, isIn := sinfo.searches.router.sessions.getByTheirPerm(&res.Key)
 | 
					 | 
				
			||||||
		if !isIn {
 | 
					 | 
				
			||||||
			panic("This should never happen")
 | 
								panic("This should never happen")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		sess.coords = res.Coords         // In case coords have updated
 | 
							err = errors.New("session already exists")
 | 
				
			||||||
		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
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// FIXME (!) replay attacks could mess with coords? Give it a handle (tstamp)?
 | 
						finishSearch(sess, err)
 | 
				
			||||||
	sess.coords = res.Coords
 | 
					 | 
				
			||||||
	sess.ping(sinfo.searches.router)
 | 
					 | 
				
			||||||
	sinfo.callback(sess, nil)
 | 
					 | 
				
			||||||
	// Cleanup
 | 
					 | 
				
			||||||
	delete(sinfo.searches.searches, res.Dest)
 | 
					 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue