Collaboration diagram for DCPlusPlus.PortCheck:
Public Types | |
enum | Ports { UdpAndTcp, Udp, Tcp, None } |
enumeration of possible open ports combinations More... | |
Public Member Functions | |
void | AbortCheck () |
Abort checking. | |
void | CheckPorts () |
Start checking of open ports. | |
delegate void | CompletedEventHandler (PortCheck ex_ip) |
Prototype for the Completed Event Handler. | |
PortCheck () | |
PortCheck Constructor. | |
delegate void | ProgressChangedEventHandler (PortCheck ex_ip) |
Prototype for the Progress Changed Event Handler. | |
[Test] void | TestCheck () |
Test to see if our port checking method works. | |
[Test] void | TestCheckFailed () |
Test to see if a failed check will not crash the client or throw unexpected exceptions. | |
[Test] void | TestCheckRunningLocalPeers () |
Test to see if our local ports are available to the outside world. | |
delegate void | UnableToFetchEventHandler (PortCheck ex_ip) |
Prototype for the Unable To Fetch Event Handler. | |
Public Attributes | |
event CompletedEventHandler | Completed |
Event handler that gets called when a open ports check was completed. | |
Ports | OpenPorts = Ports.None |
Get the open Ports that the test found. | |
event ProgressChangedEventHandler | ProgressChanged |
Event handler that gets called when the progress of the port check changed. | |
event UnableToFetchEventHandler | UnableToFetch |
Event handler that gets called when the port check was unable to complete. | |
Protected Attributes | |
bool | busy = false |
Connection.ErrorCodes | error_code = Connection.ErrorCodes.NoErrorYet |
string | my_client_name = "c#++" |
string | my_ip |
int | my_tcp_port |
int | my_udp_port |
int | percentage = 0 |
Properties | |
Connection.ErrorCodes | ErrorCode [get] |
Contains the error code if something went wrong with the open ports check. | |
bool | IsBusy [get] |
TRUE if an open ports check if running. | |
string | MyClientName [get, set] |
Get/Set the client name we want to send to the ports checking service. | |
string | MyIP [get, set] |
Get/Set the ip to check the ports for. | |
int | MyTcpPort [get, set] |
Get/set the tcp port to check. | |
int | MyUdpPort [get, set] |
Get/Set the udp port to check. | |
int | Percentage [get] |
Get the progress percentage of the open ports check. | |
Private Member Functions | |
void | DownloadFileCallback (object sender, DownloadDataCompletedEventArgs e) |
Async callback for webclients get file operation ,gets called if the file was retrieved successfully. | |
void | DownloadProgressCallback (object sender, DownloadProgressChangedEventArgs e) |
Async callback for webclients get file operation ,gets called when the progress of the download changes. | |
Private Attributes | |
string | url = "http://connect.majestyc.net/" |
our url to the port checking service we are using | |
WebClient | wc = new WebClient() |
our webclient we use to communicate with the p2p-ports service |
Definition at line 20 of file PortCheck.cs.
DCPlusPlus.PortCheck.PortCheck | ( | ) |
PortCheck Constructor.
Definition at line 168 of file PortCheck.cs.
References DCPlusPlus.PortCheck.DownloadFileCallback(), DCPlusPlus.PortCheck.DownloadProgressCallback(), DCPlusPlus.PortCheck.my_ip, and DCPlusPlus.PortCheck.wc.
Referenced by DCPlusPlus.PortCheck.TestCheck(), DCPlusPlus.PortCheck.TestCheckFailed(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
00169 { 00170 my_ip = ""; 00171 wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); 00172 wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadFileCallback); 00173 00174 }
Here is the call graph for this function:
Here is the caller graph for this function:
void DCPlusPlus.PortCheck.AbortCheck | ( | ) |
Abort checking.
Definition at line 204 of file PortCheck.cs.
References DCPlusPlus.PortCheck.busy, and DCPlusPlus.PortCheck.wc.
00205 { 00206 if (busy) 00207 { 00208 try 00209 { 00210 wc.CancelAsync(); 00211 } 00212 catch (Exception ex) 00213 { 00214 Console.WriteLine("Exception occured during abort: " + ex.Message); 00215 } 00216 System.Threading.Thread.Sleep(10); 00217 //wc.IsBusy 00218 //wc = new WebClient(); 00219 busy = false; 00220 } 00221 }
void DCPlusPlus.PortCheck.CheckPorts | ( | ) |
Start checking of open ports.
Definition at line 182 of file PortCheck.cs.
References DCPlusPlus.PortCheck.busy, DCPlusPlus.PortCheck.my_client_name, DCPlusPlus.PortCheck.my_ip, DCPlusPlus.PortCheck.my_tcp_port, DCPlusPlus.PortCheck.my_udp_port, DCPlusPlus.PortCheck.percentage, DCPlusPlus.PortCheck.ProgressChanged, DCPlusPlus.PortCheck.url, and DCPlusPlus.PortCheck.wc.
Referenced by DCPlusPlus.PortCheck.TestCheck(), DCPlusPlus.PortCheck.TestCheckFailed(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
00183 { 00184 if (!busy) 00185 { 00186 busy = true; 00187 percentage = 0; 00188 if (ProgressChanged != null) 00189 ProgressChanged(this); 00190 try 00191 { 00192 wc.DownloadDataAsync(new Uri(url+"?i="+my_ip+"&t="+my_tcp_port+"&u="+my_udp_port+"&c="+my_client_name)); 00193 } 00194 catch (Exception ex) 00195 { 00196 Console.WriteLine("Exception occured during download: " + ex.Message); 00197 } 00198 } 00199 00200 }
Here is the caller graph for this function:
delegate void DCPlusPlus.PortCheck.CompletedEventHandler | ( | PortCheck | ex_ip | ) |
Prototype for the Completed Event Handler.
ex_ip |
void DCPlusPlus.PortCheck.DownloadFileCallback | ( | object | sender, | |
DownloadDataCompletedEventArgs | e | |||
) | [private] |
Async callback for webclients get file operation ,gets called if the file was retrieved successfully.
sender | event sending webclient instance | |
e | event arguments of the download operation |
Definition at line 228 of file PortCheck.cs.
References DCPlusPlus.PortCheck.busy, DCPlusPlus.PortCheck.Completed, DCPlusPlus.PortCheck.error_code, DCPlusPlus.PortCheck.OpenPorts, and DCPlusPlus.PortCheck.UnableToFetch.
Referenced by DCPlusPlus.PortCheck.PortCheck().
00229 { 00230 try 00231 { 00232 if (e.Cancelled) return; 00233 if (e.Result.Length <= 0) return; 00234 string page_string = ""; 00235 page_string = System.Text.Encoding.Default.GetString(e.Result); 00236 //Console.WriteLine("port page: " + page_string); 00237 int start = page_string.IndexOf("<strong class=\""); 00238 if (start != -1) 00239 { 00240 string temp = page_string.Substring(start + "<strong class=\"".Length); 00241 int end = temp.IndexOf("\""); 00242 if (end != -1) 00243 { 00244 string tcp = temp.Substring(0, end); 00245 if (tcp == "green small") 00246 OpenPorts = Ports.Tcp; 00247 else OpenPorts = Ports.None; 00248 00249 start = temp.IndexOf("<strong class=\""); 00250 if (start != -1) 00251 { 00252 string temp2 = temp.Substring(start + "<strong class=\"".Length); 00253 end = temp2.IndexOf("\""); 00254 if (end != -1) 00255 { 00256 string udp = temp2.Substring(0, end); 00257 if (udp == "green small" && OpenPorts == Ports.None) 00258 OpenPorts = Ports.Udp; 00259 if (udp == "green small" && OpenPorts == Ports.Tcp) 00260 OpenPorts = Ports.UdpAndTcp; 00261 00262 busy = false; 00263 if (Completed != null) 00264 Completed(this); 00265 } 00266 } 00267 } 00268 } 00269 } 00270 catch (Exception out_ex) 00271 { 00272 Console.WriteLine("Exception during download of port page: " + out_ex.Message); 00273 error_code = Connection.ErrorCodes.Exception; 00274 if (UnableToFetch != null) 00275 UnableToFetch(this); 00276 00277 } 00278 }
Here is the caller graph for this function:
void DCPlusPlus.PortCheck.DownloadProgressCallback | ( | object | sender, | |
DownloadProgressChangedEventArgs | e | |||
) | [private] |
Async callback for webclients get file operation ,gets called when the progress of the download changes.
sender | event sending webclient instance | |
e | event arguments of the download operation |
Definition at line 285 of file PortCheck.cs.
References DCPlusPlus.PortCheck.percentage, and DCPlusPlus.PortCheck.ProgressChanged.
Referenced by DCPlusPlus.PortCheck.PortCheck().
00286 { 00287 percentage = e.ProgressPercentage; 00288 if (ProgressChanged != null) 00289 ProgressChanged(this); 00290 }
Here is the caller graph for this function:
delegate void DCPlusPlus.PortCheck.ProgressChangedEventHandler | ( | PortCheck | ex_ip | ) |
Prototype for the Progress Changed Event Handler.
ex_ip |
[Test] void DCPlusPlus.PortCheck.TestCheck | ( | ) |
Test to see if our port checking method works.
Definition at line 296 of file PortCheck.cs.
References DCPlusPlus.PortCheck.CheckPorts(), DCPlusPlus.PortCheck.Completed, DCPlusPlus.ExternalIP.Completed, DCPlusPlus.ExternalIP.FetchIP(), DCPlusPlus.PortCheck.MyIP, DCPlusPlus.ExternalIP.MyIP, DCPlusPlus.PortCheck.MyTcpPort, DCPlusPlus.PortCheck.MyUdpPort, DCPlusPlus.PortCheck.OpenPorts, and DCPlusPlus.PortCheck.PortCheck().
00297 { 00298 Console.WriteLine("Test to check open ports."); 00299 bool wait = true; 00300 00301 //Assert.IsTrue(!string.IsNullOrEmpty(port_check_completed.MyIP), "no ip address fetched"); 00302 ExternalIP ex_ip = new ExternalIP(); 00303 ex_ip.Completed += delegate(ExternalIP ex_ip_completed) 00304 { 00305 wait = true; 00306 Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")"); 00307 PortCheck port_check = new PortCheck(); 00308 port_check.MyIP = ex_ip.MyIP; 00309 port_check.MyTcpPort = 3412; 00310 port_check.MyUdpPort = 3412; 00311 00312 port_check.Completed += delegate(PortCheck port_check_completed) 00313 { 00314 Console.WriteLine(""); 00315 Console.WriteLine("Check Completed (open ports : " + Enum.GetName(typeof(Ports), port_check_completed.OpenPorts) + ")"); 00316 wait = false; 00317 }; 00318 port_check.CheckPorts(); 00319 00320 }; 00321 ex_ip.FetchIP(); 00322 Console.WriteLine("Waiting for data"); 00323 DateTime ip_start = DateTime.Now; 00324 while (wait) 00325 { 00326 if (DateTime.Now - ip_start > new TimeSpan(0, 0, 35)) 00327 { 00328 Console.WriteLine(""); 00329 Console.WriteLine("Operation took too long"); 00330 wait = false; 00331 Assert.Fail("Operation took too long"); 00332 } 00333 Console.Write("."); 00334 Thread.Sleep(250); 00335 } 00336 Console.WriteLine("PortCheck open ports Test successful."); 00337 00338 }
Here is the call graph for this function:
[Test] void DCPlusPlus.PortCheck.TestCheckFailed | ( | ) |
Test to see if a failed check will not crash the client or throw unexpected exceptions.
Definition at line 397 of file PortCheck.cs.
References DCPlusPlus.PortCheck.CheckPorts(), DCPlusPlus.PortCheck.Completed, DCPlusPlus.PortCheck.PortCheck(), DCPlusPlus.PortCheck.UnableToFetch, and DCPlusPlus.PortCheck.url.
00398 { 00399 Console.WriteLine("Test to fail checking open ports."); 00400 bool wait = true; 00401 PortCheck port_check = new PortCheck(); 00402 port_check.url = "http://bogus.url"; 00403 port_check.Completed += delegate(PortCheck port_check_completed) 00404 { 00405 Console.WriteLine(""); 00406 Console.WriteLine("Check Completed."); 00407 Assert.Fail("Failed at failing ;-("); 00408 }; 00409 port_check.UnableToFetch += delegate(PortCheck port_check_unable) 00410 { 00411 Console.WriteLine(""); 00412 Console.WriteLine("Failed to fetch check page."); 00413 wait = false; 00414 00415 }; 00416 00417 port_check.CheckPorts(); 00418 Console.WriteLine("Waiting for data"); 00419 DateTime start = DateTime.Now; 00420 while (wait) 00421 { 00422 if (DateTime.Now - start > new TimeSpan(0, 0, 5)) 00423 { 00424 Console.WriteLine(""); 00425 Console.WriteLine("Operation took too long"); 00426 wait = false; 00427 Assert.Fail("Operation took too long"); 00428 } 00429 Console.Write("."); 00430 Thread.Sleep(250); 00431 } 00432 Console.WriteLine("Failed PortCheck Test successful."); 00433 }
Here is the call graph for this function:
[Test] void DCPlusPlus.PortCheck.TestCheckRunningLocalPeers | ( | ) |
Test to see if our local ports are available to the outside world.
Definition at line 343 of file PortCheck.cs.
References DCPlusPlus.PortCheck.CheckPorts(), DCPlusPlus.PortCheck.Completed, DCPlusPlus.ExternalIP.Completed, DCPlusPlus.ExternalIP.FetchIP(), DCPlusPlus.PortCheck.MyIP, DCPlusPlus.ExternalIP.MyIP, DCPlusPlus.PortCheck.MyTcpPort, DCPlusPlus.PortCheck.MyUdpPort, DCPlusPlus.PortCheck.OpenPorts, DCPlusPlus.PortCheck.PortCheck(), DCPlusPlus.ListeningSockets.TcpPort, DCPlusPlus.ListeningSockets.UdpPort, and DCPlusPlus.ListeningSockets.UpdateConnectionSettings().
00344 { 00345 Console.WriteLine("Test to check running open ports."); 00346 bool wait = true; 00347 ListeningSockets ls = new ListeningSockets(); 00348 ls.TcpPort = 3412; 00349 ls.UdpPort = 3412; 00350 ls.UpdateConnectionSettings(); 00351 00352 //Assert.IsTrue(!string.IsNullOrEmpty(port_check_completed.MyIP), "no ip address fetched"); 00353 ExternalIP ex_ip = new ExternalIP(); 00354 ex_ip.Completed += delegate(ExternalIP ex_ip_completed) 00355 { 00356 wait = true; 00357 Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")"); 00358 PortCheck port_check = new PortCheck(); 00359 port_check.MyIP = ex_ip.MyIP; 00360 port_check.MyTcpPort = 3412; 00361 port_check.MyUdpPort = 3412; 00362 00363 port_check.Completed += delegate(PortCheck port_check_completed) 00364 { 00365 Console.WriteLine(""); 00366 Console.WriteLine("Check Completed (open ports : " + Enum.GetName(typeof(Ports), port_check_completed.OpenPorts) + ")"); 00367 if(port_check_completed.OpenPorts == Ports.None || port_check_completed.OpenPorts == Ports.Udp) 00368 Assert.Fail("Test failed: tcp port not open!"); 00369 wait = false; 00370 }; 00371 port_check.CheckPorts(); 00372 00373 }; 00374 ex_ip.FetchIP(); 00375 Console.WriteLine("Waiting for data"); 00376 DateTime ip_start = DateTime.Now; 00377 while (wait) 00378 { 00379 if (DateTime.Now - ip_start > new TimeSpan(0, 0, 35)) 00380 { 00381 Console.WriteLine(""); 00382 Console.WriteLine("Operation took too long"); 00383 wait = false; 00384 Assert.Fail("Operation took too long"); 00385 } 00386 Console.Write("."); 00387 Thread.Sleep(250); 00388 } 00389 Console.WriteLine("PortCheck running open ports Test successful."); 00390 00391 }
Here is the call graph for this function:
delegate void DCPlusPlus.PortCheck.UnableToFetchEventHandler | ( | PortCheck | ex_ip | ) |
Prototype for the Unable To Fetch Event Handler.
ex_ip |
bool DCPlusPlus.PortCheck.busy = false [protected] |
Definition at line 150 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.AbortCheck(), DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.DownloadFileCallback().
event CompletedEventHandler DCPlusPlus.PortCheck.Completed |
Event handler that gets called when a open ports check was completed.
Definition at line 26 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.DownloadFileCallback(), DCPlusPlus.PortCheck.TestCheck(), DCPlusPlus.PortCheck.TestCheckFailed(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
Connection.ErrorCodes DCPlusPlus.PortCheck.error_code = Connection.ErrorCodes.NoErrorYet [protected] |
Definition at line 52 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.DownloadFileCallback().
string DCPlusPlus.PortCheck.my_client_name = "c#++" [protected] |
string DCPlusPlus.PortCheck.my_ip [protected] |
Definition at line 86 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.PortCheck().
int DCPlusPlus.PortCheck.my_tcp_port [protected] |
int DCPlusPlus.PortCheck.my_udp_port [protected] |
Ports DCPlusPlus.PortCheck.OpenPorts = Ports.None |
Get the open Ports that the test found.
Definition at line 85 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.DownloadFileCallback(), DCPlusPlus.PortCheck.TestCheck(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
int DCPlusPlus.PortCheck.percentage = 0 [protected] |
Definition at line 63 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.DownloadProgressCallback().
event ProgressChangedEventHandler DCPlusPlus.PortCheck.ProgressChanged |
Event handler that gets called when the progress of the port check changed.
Definition at line 31 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.DownloadProgressCallback().
event UnableToFetchEventHandler DCPlusPlus.PortCheck.UnableToFetch |
Event handler that gets called when the port check was unable to complete.
Definition at line 36 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.DownloadFileCallback(), and DCPlusPlus.PortCheck.TestCheckFailed().
string DCPlusPlus.PortCheck.url = "http://connect.majestyc.net/" [private] |
our url to the port checking service we are using
Definition at line 178 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.TestCheckFailed().
WebClient DCPlusPlus.PortCheck.wc = new WebClient() [private] |
our webclient we use to communicate with the p2p-ports service
Definition at line 164 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.AbortCheck(), DCPlusPlus.PortCheck.CheckPorts(), and DCPlusPlus.PortCheck.PortCheck().
Connection.ErrorCodes DCPlusPlus.PortCheck.ErrorCode [get] |
Contains the error code if something went wrong with the open ports check.
Definition at line 57 of file PortCheck.cs.
bool DCPlusPlus.PortCheck.IsBusy [get] |
string DCPlusPlus.PortCheck.MyClientName [get, set] |
Get/Set the client name we want to send to the ports checking service.
Definition at line 107 of file PortCheck.cs.
string DCPlusPlus.PortCheck.MyIP [get, set] |
Get/Set the ip to check the ports for.
Definition at line 91 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.TestCheck(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
int DCPlusPlus.PortCheck.MyTcpPort [get, set] |
Get/set the tcp port to check.
Definition at line 139 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.TestCheck(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
int DCPlusPlus.PortCheck.MyUdpPort [get, set] |
Get/Set the udp port to check.
Definition at line 123 of file PortCheck.cs.
Referenced by DCPlusPlus.PortCheck.TestCheck(), and DCPlusPlus.PortCheck.TestCheckRunningLocalPeers().
int DCPlusPlus.PortCheck.Percentage [get] |