summaryrefslogtreecommitdiff
path: root/src/org/noreply/fancydress/type3/Hop.java
blob: 9c61b2d114816206668a29cacaf6f944c66c07f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* $Id$ */
package org.noreply.fancydress.type3;

import org.noreply.fancydress.type3.routing.*;
import org.noreply.fancydress.crypto.*;
import org.noreply.fancydress.status.*;
import org.noreply.fancydress.directory.*;

public class Hop {
	private Routing routing;
	private RSAPublicKey pubKey;
	private String[] packetVersions;
	private String nickname;

	public Hop(Routing routing, RSAPublicKey pubKey, String[] packetVersions, String nickname) {
		this.routing = routing;
		this.pubKey = pubKey;
		this.packetVersions = packetVersions;
		this.nickname = nickname;
	}

	public Hop(Server server) throws Mix3PathProblemException {
		if (!server.isUseable())
			throw new Mix3PathProblemException("Invalid path: '"+server.getNickname()+"' is not useable");
		ServerDescriptor desc;
		try {
			desc = server.getDescriptor();
		} catch (Mix3NoServerDescriptorException e) {
			throw new Error ("We should have a server descriptor at that point");
		}
		IncomingMMTPSection incoming = desc.getIncomingMMTPSection();

		if (incoming.getHostname() != null)
			this.routing = new RoutingHOST(incoming.getHostname(), incoming.getPort(), server.getKeyID());
		else
			this.routing = new RoutingIP4(incoming.getIP(), incoming.getPort(), server.getKeyID()); /* FIXME */
		this.pubKey = desc.getPacketKey();
		this.packetVersions = desc.getPacketVersions();
		this.nickname = server.getNickname();
	}

	public Routing getRouting() {
		return routing;
	}

	public RSAPublicKey getPubKey() {
		return pubKey;
	}

	public boolean supportsPacketVersion(String v) {
		for (int i=0; i<packetVersions.length; i++)
			if (v.equals(packetVersions[i]))
				return true;
		return false;
	}
	
	public String getNickname() {
		return nickname;
	};
}