diff options
Diffstat (limited to 'src/org/noreply/fancydress/directory/Server.java')
-rw-r--r-- | src/org/noreply/fancydress/directory/Server.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/org/noreply/fancydress/directory/Server.java b/src/org/noreply/fancydress/directory/Server.java new file mode 100644 index 0000000..e3bb355 --- /dev/null +++ b/src/org/noreply/fancydress/directory/Server.java @@ -0,0 +1,86 @@ +package org.noreply.fancydress.directory; + +import org.noreply.fancydress.misc.Util; +import org.noreply.fancydress.status.*; +import org.noreply.fancydress.crypto.*; +import java.util.*; + +/** + * This class represents a server, pooling one or more server descriptors into one class. + * + * @see ServerDescriptor + */ +public class Server { + /** + * Nickname of the server. + * + * Note that all nickname comparisons need to be done in a case insensitive way. + */ + String nickname; + + /** + * The asn1 representation of the server's identity key. + */ + byte[] identity; + + /** + * The hash of <code>identity</code>, which is the node's keyid + */ + byte[] keyid; + + /** + * A list of one of more server descriptors. + */ + ArrayList descriptors; + + /** + * Construct a Server from a given ServerDescriptor. + * + * @param descriptor a ServerDescriptor. + */ + public Server(ServerDescriptor descriptor) { + nickname = descriptor.getNickname(); + identity = descriptor.getIdentity(); + keyid = CryptoPrimitives.hash(identity); + + descriptors = new ArrayList(); + descriptors.add(descriptor); + } + + /** + * Add a ServerDescriptor to this Server. + * + * @param descriptor a ServerDescriptor to add. + * @throws Mix3BadServerFormatException if the nickname or the identity key do not match this server's nickname or identity key. + */ + public void addDescriptor(ServerDescriptor descriptor) throws Mix3BadServerFormatException { + + if (!nickname.equalsIgnoreCase(descriptor.getNickname())) + /* This indicates an error in whoever called us */ + throw new Error("Nickname does not match."); + + if (!Util.equal(identity, descriptor.getIdentity())) + /* While this might happen. In this case this ServerDesc should be ignored */ + throw new Mix3BadServerFormatException("Identity does not match."); + + descriptors.add(descriptor); + } + + /** + * Get the keyid (hash of the identity key) of this Server. + * + * @return keyid + */ + public byte[] getKeyID() { + return keyid; + } + + /** + * get the first server descriptor (needs fixing). + * + * @return first server descriptor + */ + public ServerDescriptor getDescriptor() { /* FIXME */ + return (ServerDescriptor) descriptors.get(0); + } +} |