summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-10-12 03:24:56 +0000
committerPeter Palfrader <peter@palfrader.org>2003-10-12 03:24:56 +0000
commit2f848cd91f899fe3de2701085ee720b96ba317c0 (patch)
treed64da47fed0404faa5f21b13eb9ce5eac58618b0 /src
parent85eccff05dc687bab86363aa40b61b0d6ed9f6be (diff)
Allow passing a path to the Path class constructor.
Diffstat (limited to 'src')
-rw-r--r--src/org/noreply/fancydress/directory/IncomingMMTPSection.java10
-rw-r--r--src/org/noreply/fancydress/directory/Server.java20
-rw-r--r--src/org/noreply/fancydress/directory/ServerDescriptor.java59
-rw-r--r--src/org/noreply/fancydress/status/Mix3Exception.java2
-rw-r--r--src/org/noreply/fancydress/type3/HalfPath.java53
-rw-r--r--src/org/noreply/fancydress/type3/Path.java23
-rw-r--r--src/org/noreply/fancydress/type3/routing/RoutingHOST.java4
-rw-r--r--src/org/noreply/fancydress/type3/routing/RoutingIP4.java4
8 files changed, 138 insertions, 37 deletions
diff --git a/src/org/noreply/fancydress/directory/IncomingMMTPSection.java b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
index bd1ec67..92e17d7 100644
--- a/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
+++ b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
@@ -100,4 +100,14 @@ public class IncomingMMTPSection {
protocols = entryProtocols.getValue();
}
+
+ public InetAddress getIP() {
+ return ip;
+ }
+ public String getHostname() {
+ return hostname;
+ }
+ public int getPort() {
+ return port;
+ }
}
diff --git a/src/org/noreply/fancydress/directory/Server.java b/src/org/noreply/fancydress/directory/Server.java
index 53455f4..c4052d9 100644
--- a/src/org/noreply/fancydress/directory/Server.java
+++ b/src/org/noreply/fancydress/directory/Server.java
@@ -77,11 +77,23 @@ public class Server {
}
/**
- * get the first server descriptor (needs fixing).
+ * get the the currently valid server descriptor.
*
- * @return first server descriptor
+ * @return current server descriptor
*/
- public ServerDescriptor getDescriptor() { /* FIXME */
- return (ServerDescriptor) descriptors.get(0);
+ public ServerDescriptor getDescriptor() throws Mix3Exception {
+ ServerDescriptor result = null;
+ Date now = new Date();
+
+ for (int i=0; i<descriptors.size(); i++) {
+ ServerDescriptor desc = (ServerDescriptor) descriptors.get(i);
+ if (now.after( desc.getValidAfter() ) &&
+ now.before( desc.getValidUntil() ) &&
+ ((result == null) || desc.getPublished().after( result.getPublished())))
+ result = desc;
+ }
+ if (result == null)
+ throw new Mix3Exception("No valid server descriptor found.");
+ return result;
}
}
diff --git a/src/org/noreply/fancydress/directory/ServerDescriptor.java b/src/org/noreply/fancydress/directory/ServerDescriptor.java
index 2f076f6..020d31b 100644
--- a/src/org/noreply/fancydress/directory/ServerDescriptor.java
+++ b/src/org/noreply/fancydress/directory/ServerDescriptor.java
@@ -45,11 +45,11 @@ public class ServerDescriptor {
private Boolean secureConfiguration;
private String whyInsecure;
- private IncomingMMTPSection IncomingMMTPSection;
- private Object OutgoingMMTPSection;
- private DeliveryMBOXSection DeliveryMBOXSection;
- private DeliverySMTPSection DeliverySMTPSection;
- private Object DeliveryFragmentedSection;
+ private IncomingMMTPSection incomingMMTPSection;
+ private Object outgoingMMTPSection;
+ private DeliveryMBOXSection deliveryMBOXSection;
+ private DeliverySMTPSection deliverySMTPSection;
+ private Object deliveryFragmentedSection;
/**
@@ -79,17 +79,17 @@ public class ServerDescriptor {
DirectorySection section;
section = m.getSection("Incoming/MMTP");
try {
- IncomingMMTPSection = section == null ? null : new IncomingMMTPSection(section);
+ incomingMMTPSection = section == null ? null : new IncomingMMTPSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
section = m.getSection("Delivery/MBOX");
try {
- DeliveryMBOXSection = section == null ? null : new DeliveryMBOXSection(section);
+ deliveryMBOXSection = section == null ? null : new DeliveryMBOXSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
section = m.getSection("Delivery/SMTP");
try {
- DeliverySMTPSection = section == null ? null : new DeliverySMTPSection(section);
+ deliverySMTPSection = section == null ? null : new DeliverySMTPSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
}
@@ -130,12 +130,12 @@ public class ServerDescriptor {
while ((indexOf = s.indexOf(',', indexFrom)) != -1) {
String v = s.substring(indexFrom, indexOf).trim();
- if (Packet.isPacketVersionSupported(v) || !onlySupported )
+ if (!v.equals("") && (Packet.isPacketVersionSupported(v) || !onlySupported ))
versions.add( v );
indexFrom = indexOf + 1;
}
String v = s.substring(indexFrom).trim();
- if (Packet.isPacketVersionSupported(v) || !onlySupported )
+ if (!v.equals("") && (Packet.isPacketVersionSupported(v) || !onlySupported ))
versions.add( v );
String[] result = new String[versions.size()];
@@ -223,7 +223,7 @@ public class ServerDescriptor {
identity = Base64.decode(entryIdentity.getValue());
digest = Base64.decode(entryDigest.getValue());
signature = Base64.decode(entrySignature.getValue());
- published = Util.parseDate(entryPublished.getValue());
+ published = Util.parseDateTime(entryPublished.getValue());
validAfter = Util.parseDate(entryValidAfter.getValue());
validUntil = Util.parseDate(entryValidUntil.getValue());
packetKey = new RSAPublicKey(Base64.decode(entryPacketKey.getValue()));
@@ -317,4 +317,41 @@ public class ServerDescriptor {
public RSAPublicKey getPacketKey() {
return packetKey;
}
+
+ /**
+ * Get the date after which this server descriptor is valid.
+ *
+ * @return date after which this server descriptor is valid
+ */
+ public Date getValidAfter() {
+ return validAfter;
+ }
+
+ /**
+ * Get the date until which this server descriptor is valid.
+ *
+ * @return date until which this server descriptor is valid
+ */
+ public Date getValidUntil() {
+ return validUntil;
+ }
+
+ /**
+ * Get the date when this server descriptor was published.
+ *
+ * @return date when this server descriptor was published
+ */
+ public Date getPublished() {
+ return published;
+ }
+
+ /**
+ * Get the Incoming/MMTP section.
+ *
+ * @return this server descriptor's Incoming/MMTP section
+ */
+ public IncomingMMTPSection getIncomingMMTPSection() {
+ return incomingMMTPSection;
+ }
+
}
diff --git a/src/org/noreply/fancydress/status/Mix3Exception.java b/src/org/noreply/fancydress/status/Mix3Exception.java
index cf7711b..97cf882 100644
--- a/src/org/noreply/fancydress/status/Mix3Exception.java
+++ b/src/org/noreply/fancydress/status/Mix3Exception.java
@@ -4,7 +4,7 @@ package org.noreply.fancydress.status;
/**
* Base class for other mix3 exceptions.
*/
-public abstract class Mix3Exception extends Exception {
+public class Mix3Exception extends Exception {
public Mix3Exception(String s) {
super(s);
}
diff --git a/src/org/noreply/fancydress/type3/HalfPath.java b/src/org/noreply/fancydress/type3/HalfPath.java
index 3c72b91..14d4af6 100644
--- a/src/org/noreply/fancydress/type3/HalfPath.java
+++ b/src/org/noreply/fancydress/type3/HalfPath.java
@@ -1,11 +1,62 @@
/* $Id$ */
package org.noreply.fancydress.type3;
+import org.noreply.fancydress.directory.*;
+import org.noreply.fancydress.status.*;
+import org.noreply.fancydress.type3.routing.*;
+import java.util.*;
+
public class HalfPath {
private Hop[] hops;
- public HalfPath(Hop[] hops) { /* FIXME */
+ public HalfPath(Hop[] hops) {
this.hops = hops;
}
+
+ private String[] tokenize(String path) throws Mix3Exception {
+ ArrayList nicks = new ArrayList();
+ int indexFrom = 0;
+ int indexOf;
+
+ while ((indexOf = path.indexOf(',', indexFrom)) != -1) {
+ String v = path.substring(indexFrom, indexOf).trim();
+ if (v.equals(""))
+ throw new Mix3Exception("Invalid path.");
+ nicks.add( v );
+ indexFrom = indexOf + 1;
+ }
+ String v = path.substring(indexFrom).trim();
+ if (v.equals(""))
+ throw new Mix3Exception("Invalid path.");
+ nicks.add( v );
+
+ String[] result = new String[nicks.size()];
+ for (int i=0; i<result.length; i++)
+ result[i] = (String) nicks.get(i);
+
+ return result;
+ }
+
+ public HalfPath(Directory dir, String path) throws Mix3Exception {
+ String[] nicks = tokenize(path);
+ hops = new Hop[nicks.length];
+
+ for (int i=0; i<hops.length; i++) {
+ Server server = dir.getServer(nicks[i]);
+ if (server == null)
+ throw new Mix3Exception("Invalid path: "+nicks[i]+" not found");
+ ServerDescriptor desc = server.getDescriptor();
+ IncomingMMTPSection incoming = desc.getIncomingMMTPSection();
+ Routing routing;
+
+ if (incoming.getHostname() != null) { /* FIXME */
+ routing = new RoutingHOST(incoming.getHostname(), incoming.getPort(), server.getKeyID());
+ } else {
+ routing = new RoutingIP4(incoming.getIP(), incoming.getPort(), server.getKeyID());
+ }
+ hops[i] = new Hop(routing, desc.getPacketKey());
+ }
+ }
+
public Hop[] getHops() {
return hops;
}
diff --git a/src/org/noreply/fancydress/type3/Path.java b/src/org/noreply/fancydress/type3/Path.java
index af0a6f3..8f492ec 100644
--- a/src/org/noreply/fancydress/type3/Path.java
+++ b/src/org/noreply/fancydress/type3/Path.java
@@ -2,6 +2,7 @@
package org.noreply.fancydress.type3;
import org.noreply.fancydress.crypto.*;
+import org.noreply.fancydress.status.*;
import org.noreply.fancydress.directory.*;
import org.noreply.fancydress.misc.Util;
import org.noreply.fancydress.type3.routing.*;
@@ -11,23 +12,13 @@ public class Path {
HalfPath first;
HalfPath second;
- public Path(Directory dir) throws Exception {
- Hop[] hops1 = new Hop[4];
- Hop[] hops2 = new Hop[2];
+ public Path(Directory dir, String path) throws Exception {
+ int crossover = path.indexOf(':');
+ if (crossover < 0)
+ throw new Mix3Exception("Path is not a valid path: no crossover point specified.");
- Server test = dir.getServer("test1");
- ServerDescriptor desc = test.getDescriptor();
-
- Routing route1 = new RoutingIP4(InetAddress.getByName("172.22.118.2"), 48099, test.getKeyID());
- hops1[0] = new Hop(route1, desc.getPacketKey());
- hops1[1] = new Hop(route1, desc.getPacketKey());
- hops1[2] = new Hop(route1, desc.getPacketKey());
- hops1[3] = new Hop(route1, desc.getPacketKey());
- hops2[0] = new Hop(route1, desc.getPacketKey());
- hops2[1] = new Hop(route1, desc.getPacketKey());
-
- first = new HalfPath(hops1);
- second = new HalfPath(hops2);
+ first = new HalfPath(dir, path.substring(0, crossover));
+ second = new HalfPath(dir, path.substring(crossover+1));
}
public HalfPath getFirstHalf() {
diff --git a/src/org/noreply/fancydress/type3/routing/RoutingHOST.java b/src/org/noreply/fancydress/type3/routing/RoutingHOST.java
index 2203ac8..933bfec 100644
--- a/src/org/noreply/fancydress/type3/routing/RoutingHOST.java
+++ b/src/org/noreply/fancydress/type3/routing/RoutingHOST.java
@@ -31,7 +31,7 @@ public class RoutingHOST extends RoutingForward {
*
* @param hostname host name of the next hop
* @param port TCP port at which the next hop is listening
- * @param keyid keyid of the packet key
+ * @param keyid keyid of the identity key
* @param boolean if true, have a SWAP-FWD/HOST routing type, FWD/HOST otherwhise
*/
private RoutingHOST(String hostname, int port, byte[] keyid, boolean asSwap) {
@@ -50,7 +50,7 @@ public class RoutingHOST extends RoutingForward {
*
* @param hostname host name of the next hop
* @param port TCP port at which the next hop is listening
- * @param keyid keyid of the packet key
+ * @param keyid keyid of the identity key
*/
public RoutingHOST(String hostname, int port, byte[] keyid) {
this(hostname, port, keyid, false);
diff --git a/src/org/noreply/fancydress/type3/routing/RoutingIP4.java b/src/org/noreply/fancydress/type3/routing/RoutingIP4.java
index 9a98c3a..08e1ce1 100644
--- a/src/org/noreply/fancydress/type3/routing/RoutingIP4.java
+++ b/src/org/noreply/fancydress/type3/routing/RoutingIP4.java
@@ -33,7 +33,7 @@ public class RoutingIP4 extends RoutingForward {
*
* @param ip IP address of the next hop
* @param port TCP port at which the next hop is listening
- * @param keyid keyid of the packet key
+ * @param keyid keyid of the identity key
* @param boolean if true, have a SWAP-FWD/IP4 routing type, FWD/IP4 otherwhise
*/
private RoutingIP4(InetAddress ip, int port, byte[] keyid, boolean asSwap) {
@@ -54,7 +54,7 @@ public class RoutingIP4 extends RoutingForward {
*
* @param ip IP address of the next hop
* @param port TCP port at which the next hop is listening
- * @param keyid keyid of the packet key
+ * @param keyid keyid of the identity key
*/
public RoutingIP4(InetAddress ip, int port, byte[] keyid) {
this(ip, port, keyid, false);