From a4c0d3d6d878da55435cb9d9cc8cff6199644199 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 19 Oct 2003 15:08:35 +0000 Subject: Support random path creation --- .../noreply/fancydress/directory/Directory.java | 230 ++++++++++++++++++--- 1 file changed, 199 insertions(+), 31 deletions(-) (limited to 'src/org/noreply/fancydress/directory/Directory.java') diff --git a/src/org/noreply/fancydress/directory/Directory.java b/src/org/noreply/fancydress/directory/Directory.java index f2eda8c..ff0cfdf 100644 --- a/src/org/noreply/fancydress/directory/Directory.java +++ b/src/org/noreply/fancydress/directory/Directory.java @@ -24,6 +24,12 @@ import java.util.*; * @see Server */ public class Directory { + /** + * directory version we understand. + */ + + private static final String DIRECTORY_VERSION = "0.2"; + /** * Hash holding all Servers. * @@ -37,35 +43,27 @@ public class Directory { private Hashtable byName; /** - * Possibly add a new server descriptor to the directory. + * Useable servers. * - * This method adds a server desccriptor to the directory if it - * - conforms to the syntax specified. - * - the server is not yet known or it's identity key matches the key of the already known ServerDescriptor. + * A server is useable if it understands PacketVersions that we understand + * and has a serverdescriptor that is useable right now. + */ + private Server[] useableServers; + + /** + * Recommended servers. + */ + private Server[] recommendedServers; + + /* + * matrix of friends. * - * @param server a DirectoryMessage consisting of one of more sections. At 'Server' section needs to be present. - * @throws Mix3BadServerFormatException if a section is syntactially invalid and the error cannot be ignored. - * @throws Mix3BadServerSignatureException if the server descriptor's signature is invalid. + * (a, b) are friends, if a can send messages to b. */ - private void addServerDescriptor(DirectoryMessage server) throws Mix3BadServerFormatException, Mix3BadServerSignatureException { - try { - ServerDescriptor sd = new ServerDescriptor(server); - String key = sd.getNickname().toLowerCase(); - if (byName.containsKey(key)) { - Server s = (Server) byName.get(key); - try { - s.addDescriptor(sd); - } catch (Mix3BadServerFormatException e) { - System.err.println("Ignoring Descriptor with different identity for "+key); - } - } else { - Server s = new Server(sd); - byName.put(key, s); - } - } catch (Mix3BadServerUnrecognizedVersionException e) { - System.err.println("Ignoring unregonized version"); - } - } + /* + private boolean[][] friends; + */ + /** * Create a directory from an entire DirectoryMessage. @@ -82,11 +80,87 @@ public class Directory { */ public Directory(DirectoryMessage m, boolean checkDirectorySignature) throws Mix3BadDirectorySignatureException, + Mix3BadDirectoryFormatException, Mix3BadServerFormatException, Mix3BadServerSignatureException { byName = new Hashtable(); + + parseDirectory(m, checkDirectorySignature); + + + Collection all = byName.values(); + ArrayList useable = new ArrayList(); + for (Iterator i = all.iterator(); i.hasNext(); ) { + Server s = (Server) i.next(); + if (s.isUseable()) + useable.add(s); + } + useableServers = (Server[]) useable.toArray( new Server[useable.size()] ); + + + ArrayList recommended = new ArrayList(); + for (int i=0; i