implemented 127.x.x.x address translation to MNH server address for local client

git-svn-id: svn://anubis/gvsu@61 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-03-09 22:09:17 +00:00
parent 3fdc401fca
commit 816b148600

View File

@ -192,7 +192,7 @@ public class KaZaServer implements Runnable
if (tokens.hasMoreTokens()) if (tokens.hasMoreTokens())
{ {
String query = tokens.nextToken(); String query = tokens.nextToken();
String searchResults = performSearch(depth, query); String searchResults = performSearch(depth, query, m_socket);
os.writeBytes(searchResults); os.writeBytes(searchResults);
os.writeBytes(".\n"); os.writeBytes(".\n");
// System.out.println("Got SRCH for " + query + // System.out.println("Got SRCH for " + query +
@ -227,11 +227,13 @@ public class KaZaServer implements Runnable
} }
} }
private String performSearch(int depth, String query) private String performSearch(int depth, String query, Socket clientSocket)
{ {
String results = ""; String results = "";
String querylc = query.toLowerCase(); String querylc = query.toLowerCase();
/* don't perform a search that we are already performing
* (avoid duplicate results */
synchronized (m_currentSearches) synchronized (m_currentSearches)
{ {
if (m_currentSearches.containsKey(querylc)) if (m_currentSearches.containsKey(querylc))
@ -276,7 +278,17 @@ public class KaZaServer implements Runnable
if ( (fnamelc.indexOf(querylc) >= 0) || if ( (fnamelc.indexOf(querylc) >= 0) ||
(files.get(fileName).toLowerCase().indexOf(querylc) >= 0) ) (files.get(fileName).toLowerCase().indexOf(querylc) >= 0) )
{ {
results += clientIP + "|" + /* clientIPToReturn will hold our MNH server's opinion
* of the client IP address which has the file being
* searched for *unless* it starts with "127.", in which
* case it is a local connection and the client performing
* the search should receive back whichever IP it is using
* to talk to the MNH server */
String clientIPToReturn =
clientIP.startsWith("127.")
? clientSocket.getLocalAddress().getHostAddress()
: clientIP;
results += clientIPToReturn + "|" +
m_clientData.get(clientIP).userName + "|" + m_clientData.get(clientIP).userName + "|" +
m_clientData.get(clientIP).speed + "|" + m_clientData.get(clientIP).speed + "|" +
fileName + "|" + fileName + "|" +