00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include <stdio.h>
00027 #include <openssl/sha.h>
00028 #include <ListenSocket.h>
00029
00030 #include "BTDictionary.h"
00031 #include "BString.h"
00032 #include "PeerHandler.h"
00033 #include "pSocket.h"
00034 #include "MetainfoSocket.h"
00035 #include "StatusSocket.h"
00036 #include "MyLog.h"
00037
00038
00039 int main(int argc,char *argv[])
00040 {
00041 MyLog log;
00042 int port = 6881;
00043 if (argc > 1)
00044 {
00045 port = atoi(argv[1]);
00046 }
00047
00048 {
00049 PeerHandler h(&log);
00050 ListenSocket<MetainfoSocket> l(h);
00051 ListenSocket<pSocket> l2(h);
00052 ListenSocket<StatusSocket> l3(h);
00053
00054
00055 h.SetExternIP("213.199.75.18");
00056 h.SetListenPort( port );
00057 h.SetTorrentDirectory("Torrent");
00058 h.SetChokeTimer(300);
00059 h.SetMinPeers(50);
00060 h.SetMaxPeers(100);
00061 h.SetIgnoreChoke();
00062 h.SetMaxRequestAge(30);
00063 h.SetDownloaders(4);
00064 h.SetOptimistic(1);
00065
00066
00067 while (l2.Bind(port))
00068 {
00069 port++;
00070 }
00071 h.SetListenPort( port );
00072 h.Add(&l2);
00073
00074
00075 l.Bind(16969);
00076 h.Add(&l);
00077
00078
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 }
00103 printf("Shutdown\n");
00104 return 0;
00105 }
00106
00107