newpeer.cpp File Reference#include <stdio.h> #include <openssl/sha.h> #include <ListenSocket.h> #include "BTDictionary.h" #include "BString.h" #include "PeerHandler.h" #include "pSocket.h" #include "MetainfoSocket.h" #include "StatusSocket.h" #include "MyLog.h" Include dependency graph for newpeer.cpp: Go to the source code of this file.
Function Documentation
File ......... newpeer.cpp Published .... 2005-06-14 Author ....... grymse@alhem.net Definition at line 39 of file newpeer.cpp. References PeerHandler::Quit(), PeerHandler::Save(), PeerHandler::SetChokeTimer(), PeerHandler::SetDownloaders(), PeerHandler::SetExternIP(), PeerHandler::SetIgnoreChoke(), PeerHandler::SetListenPort(), PeerHandler::SetMaxPeers(), PeerHandler::SetMaxRequestAge(), PeerHandler::SetMinPeers(), PeerHandler::SetOptimistic(), PeerHandler::SetTorrentDirectory(), PeerHandler::Show(), and PeerHandler::Tick(). 00040 { 00041 MyLog log; 00042 int port = 6881; 00043 if (argc > 1) 00044 { 00045 port = atoi(argv[1]); 00046 } 00047 // PeerHandler scope 00048 { 00049 PeerHandler h(&log); 00050 ListenSocket<MetainfoSocket> l(h); 00051 ListenSocket<pSocket> l2(h); 00052 ListenSocket<StatusSocket> l3(h); 00053 00054 // settings 00055 h.SetExternIP("213.199.75.18"); 00056 h.SetListenPort( port ); 00057 h.SetTorrentDirectory("Torrent"); 00058 h.SetChokeTimer(300); // seconds 00059 h.SetMinPeers(50); 00060 h.SetMaxPeers(100); 00061 h.SetIgnoreChoke(); 00062 h.SetMaxRequestAge(30); 00063 h.SetDownloaders(4); // keep the X best 00064 h.SetOptimistic(1); // drop Y worst 00065 00066 // peer 00067 while (l2.Bind(port)) // increase until found free 00068 { 00069 port++; 00070 } 00071 h.SetListenPort( port ); 00072 h.Add(&l2); 00073 00074 // inject 00075 l.Bind(16969); 00076 h.Add(&l); 00077 00078 // status 00079 l3.Bind(8008); 00080 h.Add(&l3); 00081 00082 h.Select(1,0); 00083 time_t t0 = time(NULL); 00084 time_t ts = time(NULL); 00085 while (!h.Quit()) 00086 { 00087 h.Select(1,0); 00088 time_t t = time(NULL); 00089 if (t != t0) 00090 { 00091 h.Tick(t); 00092 t0 = t; 00093 } 00094 if (t - ts > 60) 00095 { 00096 h.Save(); 00097 h.Show(); 00098 ts = t; 00099 } 00100 } 00101 h.Save(); 00102 } // SocketHandler scope 00103 printf("Shutdown\n"); 00104 return 0; 00105 }
|