summaryrefslogtreecommitdiffstats
blob: 546a41a408132f7e68e2a35d2e49cbf7d85b83c1 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * Copyright (c) 2011-2015 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */
/*
 * Copyright (c) 2015 Tarun Gupta.
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

package com.isode.stroke.elements;

import com.isode.stroke.elements.JingleTransportPayload;
import com.isode.stroke.elements.Bytestreams;
import com.isode.stroke.network.HostAddressPort;
import com.isode.stroke.jid.JID;
import com.isode.stroke.base.NotNull;
import java.util.Vector;
import java.util.Comparator;

public class JingleS5BTransportPayload extends JingleTransportPayload {

	public enum Mode {
		TCPMode, // default case
		UDPMode
	};

	public static class Candidate {

		public enum Type {
			DirectType, // default case
			AssistedType,
			TunnelType,
			ProxyType
		};

		public String cid = "";
		public JID jid = new JID();
		public HostAddressPort hostPort;
		public int priority;
		public Type type;

		public Candidate() {
			this.priority = 0;
			this.type = Type.DirectType;
		}
	}

	public static class CompareCandidate implements Comparator<JingleS5BTransportPayload.Candidate> {
		public int compare(JingleS5BTransportPayload.Candidate c1, JingleS5BTransportPayload.Candidate c2) {
			if (c1.priority == c2.priority) { return 0; }
			else if (c1.priority < c2.priority) { return -1; }
			else  { return 1; }
		}

		public boolean equals(Object c) {
			if(!(c instanceof JingleS5BTransportPayload.Candidate)) {
				return false;
			}
			else {
				return this.equals(c);
			}
		}
	}

	private Mode mode;
	private Vector<Candidate> candidates = new Vector<Candidate>();

	private String candidateUsedCID = "";
	private String activatedCID = "";
	private String dstAddr = "";
	private boolean candidateError;
	private boolean proxyError;

	public JingleS5BTransportPayload() {
		this.mode = Mode.TCPMode;
		this.candidateError = false;
		this.proxyError = false;
	}

	/**
	* @return mode, Not Null.
	*/
	public Mode getMode() {
		return mode;
	}

	/**
	* @param mode, Not Null.
	*/
	public void setMode(Mode mode) {
		NotNull.exceptIfNull(mode, "mode");
		this.mode = mode;
	}

	/**
	* @return candidates, Not Null.
	*/
	public Vector<Candidate> getCandidates() {
		return candidates;
	}

	/**
	* @param candidate, NotNull.
	*/
	public void addCandidate(Candidate candidate) {
		NotNull.exceptIfNull(candidate, "candidate");
		candidates.add(candidate);
	}

	/**
	* @param cid, NotNull.
	*/
	public void setCandidateUsed(String cid) {
		NotNull.exceptIfNull(cid, "cid");
		candidateUsedCID = cid;
	}

	/**
	* @return candidateUsedCID, Not Null.
	*/
	public String getCandidateUsed() {
		return candidateUsedCID;
	}

	/**
	* @param cid, NotNull.
	*/
	public void setActivated(String cid) {
		NotNull.exceptIfNull(cid, "cid");
		activatedCID = cid;
	}

	/**
	* @return activatedCID, Not Null.
	*/
	public String getActivated() {
		return activatedCID;
	}

	/**
	* @param addr, NotNull.
	*/
	public void setDstAddr(String addr) {
		NotNull.exceptIfNull(addr, "addr");
		dstAddr = addr;
	}

	/**
	* @return dstAddr, Not Null.
	*/
	public String getDstAddr() {
		return dstAddr;
	}

	/**
	* @param candidateError.
	*/
	public void setCandidateError(boolean hasError) {
		candidateError = hasError;
	}

	/**
	* @return candidateError.
	*/
	public boolean hasCandidateError() {
		return candidateError;
	}

	/**
	* @param proxyError.
	*/
	public void setProxyError(boolean hasError) {
		proxyError = hasError;
	}

	/**
	* @return proxyError.
	*/
	public boolean hasProxyError() {
		return proxyError;
	}
}