Logo
~Apps~
~Projects~
~Contact~


newpeer.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2005  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         // 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 }
00106 
00107 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4