diff options
Diffstat (limited to 'src/org/noreply/fancydress/type3')
4 files changed, 63 insertions, 21 deletions
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); |