]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jstun-src-0.7.1/de/javawi/jstun/test/DiscoveryInfo.java
remove mediastreamer2 and add it as a submodule instead.
[linphone] / p2pproxy / dependencies-src / jstun-src-0.7.1 / de / javawi / jstun / test / DiscoveryInfo.java
1 /*
2  * This file is part of JSTUN. 
3  * 
4  * Copyright (c) 2005 Thomas King <king@t-king.de> - All rights
5  * reserved.
6  * 
7  * This software is licensed under either the GNU Public License (GPL),
8  * or the Apache 2.0 license. Copies of both license agreements are
9  * included in this distribution.
10  */
11
12 package de.javawi.jstun.test;
13
14 import java.net.*;
15
16 public class DiscoveryInfo {
17         private InetAddress testIP;
18         private boolean error = false;
19         private int errorResponseCode = 0;
20         private String errorReason;
21         private boolean openAccess = false;
22         private boolean blockedUDP = false;
23         private boolean fullCone = false;
24         private boolean restrictedCone = false;
25         private boolean portRestrictedCone = false;
26         private boolean symmetric = false;
27         private boolean symmetricUDPFirewall = false;
28         private InetAddress publicIP;
29         
30         public DiscoveryInfo(InetAddress testIP) {
31                 this.testIP = testIP;
32         }
33         
34         public boolean isError() {
35                 return error;
36         }
37         
38         public void setError(int responseCode, String reason) {
39                 this.error = true;
40                 this.errorResponseCode = responseCode;
41                 this.errorReason = reason;
42         }
43         
44         public boolean isOpenAccess() {
45                 if (error) return false;
46                 return openAccess;
47         }
48
49         public void setOpenAccess() {
50                 this.openAccess = true;
51         }
52
53         public boolean isBlockedUDP() {
54                 if (error) return false;
55                 return blockedUDP;
56         }
57
58         public void setBlockedUDP() {
59                 this.blockedUDP = true;
60         }
61         
62         public boolean isFullCone() {
63                 if (error) return false;
64                 return fullCone;
65         }
66
67         public void setFullCone() {
68                 this.fullCone = true;
69         }
70
71         public boolean isPortRestrictedCone() {
72                 if (error) return false;
73                 return portRestrictedCone;
74         }
75
76         public void setPortRestrictedCone() {
77                 this.portRestrictedCone = true;
78         }
79
80         public boolean isRestrictedCone() {
81                 if (error) return false;
82                 return restrictedCone;
83         }
84
85         public void setRestrictedCone() {
86                 this.restrictedCone = true;
87         }
88
89         public boolean isSymmetric() {
90                 if (error) return false;
91                 return symmetric;
92         }
93
94         public void setSymmetric() {
95                 this.symmetric = true;
96         }
97
98         public boolean isSymmetricUDPFirewall() {
99                 if (error) return false;
100                 return symmetricUDPFirewall;
101         }
102
103         public void setSymmetricUDPFirewall() {
104                 this.symmetricUDPFirewall = true;
105         }
106         
107         public InetAddress getPublicIP() {
108                 return publicIP;
109         }
110         
111         public InetAddress getLocalIP() {
112                 return testIP;
113         }
114         
115         public void setPublicIP(InetAddress publicIP) {
116                 this.publicIP = publicIP;
117         }
118         
119         public String toString() {
120                 StringBuffer sb = new StringBuffer();
121                 sb.append("Network interface: ");
122                 try {
123                         sb.append(NetworkInterface.getByInetAddress(testIP).getName());
124                 } catch (SocketException se) {
125                         sb.append("unknown");
126                 }
127                 sb.append("\n");
128                 sb.append("Local IP address: ");
129                 sb.append(testIP.getHostAddress());
130                 sb.append("\n");
131                 if (error) {
132                         sb.append(errorReason + " - Responsecode: " + errorResponseCode);
133                         return sb.toString();
134                 }
135                 sb.append("Result: ");
136                 if (openAccess) sb.append("Open access to the Internet.\n");
137                 if (blockedUDP) sb.append("Firewall blocks UDP.\n");
138                 if (fullCone) sb.append("Full Cone NAT handles connections.\n");
139                 if (restrictedCone) sb.append("Restricted Cone NAT handles connections.\n");
140                 if (portRestrictedCone) sb.append("Port restricted Cone NAT handles connections.\n");
141                 if (symmetric) sb.append("Symmetric Cone NAT handles connections.\n");
142                 if (symmetricUDPFirewall) sb.append ("Symmetric UDP Firewall handles connections.\n");
143                 if (!openAccess && !blockedUDP && !fullCone && !restrictedCone && !portRestrictedCone && !symmetric && !symmetricUDPFirewall) sb.append("unkown\n");
144                 sb.append("Public IP address: ");
145                 if (publicIP != null) {
146                         sb.append(publicIP.getHostAddress());
147                 } else {
148                         sb.append("unknown");
149                 }
150                 sb.append("\n");
151                 return sb.toString();
152         }       
153 }