aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/netaddr/FirewallDescriptor.java
blob: 1f332dd3073ba64d9bfd1e30d71b8f233771f790 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package net.java.sip.communicator.impl.netaddr;

import java.net.*;

import net.java.sip.communicator.util.*;

/**
 * todo: add a type for the open internet
 *
 *
 * @author Emil Ivov
 */
public class FirewallDescriptor
{
    private static final Logger logger =
        Logger.getLogger(FirewallDescriptor.class);

    /**
     * The amount of preference points that a firewall corresponding to this
     * descriptor should remove from the address preference.
     */
    private AddressPreference preferenceSubtrahend =
        new AddressPreference(AddressPreference.MIN_PREF);


    /**
     * Means no firewall or nat. In the case of a privvate IPv4 address this
     * would meand no internet connectivity through this address. The same
     * applies to IPv6 link local addresses. In the case of a public (IPv4 or
     * IPv6) address this means that there is unlimited connectivity.
     */
    public static final int TYPE_OPEN_INTERNET = 1;

    /**
     * Full cone NAT or firewall.
     */
    public static final int TYPE_FULL_CONE = 2;

    /**
     * Restricted cone NAT or firewall.
     */
    public static final int TYPE_RESTRICTED_CONE = 3;

    /**
     * Port restricted cone NAT or firewall.
     */
    public static final int TYPE_PORT_RESTRICTED_CONE = 4;

    /**
     * Symmetric NAT or firewall.
     */
    public static final int TYPE_SYMMETRIC = 5;

    /**
     * Determines firewall type. Could be one of symmetric, full cone,
     * restricted cone, port restricted cone.
     */
    private int type = -1;

    /**
     * The time (in seconds) that address port bindings remain active on this
     * firewall without the node sendind any packets. Bindings may and most
     * probably will change during runtime. They are initially set to be equal
     * to net.java.sip.communicator.service.netaddr.INITIAL_BINDINGS_LIFETIME.
     */
    private int bindingsLifetime = 30;

    /**
     * Indicates whether or not the firewall corresponding to this descriptor
     * is also acting as NAT (are we using a globally routable ip address or
     * not).
     */
    private boolean isTranslatingAddresses = false;

    /**
     * The public IP address of the firewall. In the case of a NAT this is
     * the address that other would have to use to contact us.
     */
    private InetAddress publicAddress = null;

    /**
     * Constructs an empty firewall descirptor
     */
    FirewallDescriptor()
    {
        super();
    }

    /**
     * Set the type of this firewall.
     * @param type the type of the firewall referenced by this descriptor.
     */
    void setType(int type)
    {
        this.type = type;
    }

    /**
     * Returns the type of the firewall referenced by this desciptor
     * @return the type of the firewall referenced by this desciptor. One of the
     * TYPE_XXX fields of this class.
     */
    public int getType()
    {
        return this.type;
    }

    /**
     * Sets the address preference subtrahend corresponding to the firewall
     * referenced by this descriptor. The subtrahend is a value that is
     * subtracted from AddressPreference-s of addresses behind this firewall.
     *
     * @param subtrahend the amount of address preference points that need to
     * be subtracted from address preferences of oaddresses behind this
     * firewall.
     */
    void setPreferenceSubtrahend(AddressPreference subtrahend)
    {
        this.preferenceSubtrahend = subtrahend;
    }

    /**
     * Returns the address preference subtrahend corresponding to the firewall
     * referenced by this descriptor. The subtrahend is a value that is
     * subtracted from AddressPreference-s of addresses behind this firewall.
     *
     * @return the amount of address preference points that need to
     * be subtracted from address preferences of oaddresses behind this
     * firewall.
     */
    public AddressPreference getAddressPreferenceSubtrahend()
    {
        return this.preferenceSubtrahend;
    }

    /**
     * Sets the public IP address of the firewall. In the case of a NAT this is
     * the address that others would have to use to contact us.
     *
     * @param address the ip address of the nat
     */
    void setPublicAddress(InetAddress address)
    {
        this.publicAddress = address;
    }

    /**
     * Returns the public IP address of the firewall. In the case of a NAT this
     * is the address that others would have to use to contact us.
     *
     * @return the ip address of the nat
     */
    public InetAddress getPublicAddress()
    {
        return this.publicAddress;
    }

    /**
     * Sets the time (in seconds) that address port bindings remain active on
     * this firewall without the node sendind any packets. Bindings may and most
     * probably will change during runtime. They are initially set to be equal
     * to net.java.sip.communicator.service.netaddr.INITIAL_BINDINGS_LIFETIME.
     *
     * @param lifetime the number of seconds that bindings on this firewall
     * remain active
     */
    void setBindingsLifetime(int lifetime)
    {
        this.bindingsLifetime = lifetime;
    }

    /**
     * Returns the time (in seconds) that address port bindings remain active on
     * this firewall without the node sendind any packets. Bindings may and most
     * probably will change during runtime. They are initially set to be equal
     * to net.java.sip.communicator.service.netaddr.INITIAL_BINDINGS_LIFETIME.
     *
     * @return lifetime the number of seconds that bindings on this firewall
     * remain active
     */
    public int getBindingsLifetime()
    {
        return this.bindingsLifetime;
    }

    /**
     * Specifies whether this is an address translating firewall (NAT) or not.
     * @param isNAT a boolean specifying whether the firewall referenced by this
     * descriptor is a NAT.
     */
    void setTranslatingAddresses(boolean isNAT)
    {
        this.isTranslatingAddresses = isNAT;
    }

    /**
     * Determines whether this is an address translating firewall (NAT) or not.
     * @return true if the firewall referenced by this descriptor is a NAT and
     * false otherwise.
     */
    public boolean isTranslatingAddresses()
    {
        return isTranslatingAddresses;
    }
}